diff --git a/.asf.yaml b/.asf.yaml index 8ce43df00b25..4d979a188335 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -51,14 +51,15 @@ github: collaborators: - acs-robot - - kiranchavala - rajujith - - alexandremattioli - - vishesh92 - GaOrtiga - SadiJr - winterhazel - - rp- + - gpordeus + - hsato03 + - bernardodemarco + - abh1sar + - FelipeM525 protected_branches: ~ diff --git a/.github/linters/.flake8 b/.github/linters/.flake8 index f250719ca198..3364ad14f290 100644 --- a/.github/linters/.flake8 +++ b/.github/linters/.flake8 @@ -22,8 +22,11 @@ # E224 Tab after operator # E227 Missing whitespace around bitwise or shift operator # E242 Tab after ',' +# E271 Multiple spaces after keyword +# E272 Multiple spaces before keyword # E273 Tab after keyword # E274 Tab before keyword +# E713 Test for membership should be 'not in' # E742 Do not define classes named 'I', 'O', or 'l' # E743 Do not define functions named 'I', 'O', or 'l' # E901 SyntaxError or IndentationError @@ -37,4 +40,4 @@ exclude = .git, venv -select = E112,E113,E133,E223,E224,E227,E242,E273,E274,E742,E743,E901,E902,W291,W292,W293,W391 +select = E112,E113,E133,E223,E224,E227,E242,E271,E272,E273,E274,E713,E742,E743,E901,E902,W291,W292,W293,W391 diff --git a/.github/linters/.markdown-lint.yml b/.github/linters/.markdown-lint.yml new file mode 100644 index 000000000000..df1b1a2825e3 --- /dev/null +++ b/.github/linters/.markdown-lint.yml @@ -0,0 +1,100 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# MD001/heading-increment Heading levels should only increment by one level at a time +MD001: false + +# MD003/heading-style Heading style +MD003: false + +# MD004/ul-style Unordered list style +MD004: false + +# MD007/ul-indent Unordered list indentation +MD007: false + +# MD009/no-trailing-spaces Trailing spaces +MD009: false + +# MD010/no-hard-tabs Hard tabs +MD010: false + +# MD012/no-multiple-blanks Multiple consecutive blank lines +MD012: false + +# MD013/line-length Line length +MD013: false + +# MD014/commands-show-output Dollar signs used before commands without showing output +MD014: false + +# MD018/no-missing-space-atx No space after hash on atx style heading +MD018: false + +# MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading +MD019: false + +# MD022/blanks-around-headings Headings should be surrounded by blank lines +MD022: false + +# MD023/heading-start-left Headings must start at the beginning of the line +MD023: false + +# MD024/no-duplicate-heading Multiple headings with the same content +MD024: false + +# MD025/single-title/single-h1 Multiple top-level headings in the same document +MD025: false + +# MD026/no-trailing-punctuation Trailing punctuation in heading +MD026: false + +# MD028/no-blanks-blockquote Blank line inside blockquote +MD028: false + +# MD029/ol-prefix Ordered list item prefix +MD029: false + +# MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines +MD031: false + +# MD032/blanks-around-lists Lists should be surrounded by blank lines +MD032: false + +# MD033/no-inline-html Inline HTML +MD033: false + +# MD034/no-bare-urls Bare URL used +MD034: false + +# MD036/no-emphasis-as-heading Emphasis used instead of a heading +MD036: false + +# MD037/no-space-in-emphasis Spaces inside emphasis markers +MD037: false + +# MD040/fenced-code-language Fenced code blocks should have a language specified +MD040: false + +# MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading +MD041: false + +# MD046/code-block-style Code block style +MD046: false + +# MD052/reference-links-images Reference links and images should use a label that is defined +MD052: false diff --git a/.github/linters/codespell.txt b/.github/linters/codespell.txt new file mode 100644 index 000000000000..37b3e6de1cbe --- /dev/null +++ b/.github/linters/codespell.txt @@ -0,0 +1,526 @@ +accouns +acheived +acount +actuall +acuiring +acumulate +addreess +addtion +adminstrator +afer +afrer +afterall +againt +ags +aktive +algoritm +allo +alloacate +allocted +alocation +alogrithm +alpha-numeric +alue +ammended +ammount +ans +anull +apche +aplication +apllication +applicatio +apporpriate +appropritate +aqcuire +aqcuired +aquire +aquiring +assiciate +assigne +assoication +assosiate +asssert +astroid +asynchroniously +asyncronous +atleast +atomation +attache +attch +attches +authenciation +authenitcation +authenitication +availiability +avialable +bais +beacause +beacuse +becase +becasue +becaues +behviour +birdge +bject +boardcast +bootstraper +bu +cant +capabilites +capablity +capcity +carrefully +cavaet +chaing +checkd +childs +choosen +chould +clenup +cliente +clinet +cluser +cna +collison +comman +commited +comparision +comparisions +complient +concious +conectix +confg +configruation +configuable +conneciton +connexion +constrait +constraits +containg +contex +continuesly +contro +controler +controles +controll +convienient +convinience +coputer +correcponding +correspoding +correspoonds +cosole +coudl +couldnt +craete +craeted +crate +crated +createa +createing +credentail +cros +crresponding +curren +currentl +datas +decalared +declatory +decocdes +decypher +defalut +defaut +defered +definiton +deleteable +dependancy +dependant +dependend +deployement +deply +deplying +dervied +descktop +descrption +deserialzed +desination +detination +detroy +detroying +dettach +dettached +dettaching +diabling +diasbled +dictonary +didnt +differnet +differnt +direcotry +directroy +disale +disbale +discrepency +disover +dissapper +dissassociated +divice +doesn' +doesnot +doesnt +dont' +doubleclick +dows +eanbled +earch +ect +elemnt +eles +elments +emmited +enble +encryted +enebled +enmpty +entires +enviornment +environmnet +equivalant +erro +erronous +everthing +everytime +excetion +excption +excute +execept +execption +execut +executeable +exeeded +exisitng +exisits +existin +existsing +exitting +expcted +expection +explaination +explicitely +faield +faild +failes +falied +fasion +feild +filenname +fillled +findout +fisrt +fo +folowing +fowarding +frist +fro +frontent +fuctionality +genarate +generallly +gernerate +get's +gloabal +gorry +gracefull +gradiant +handeling +hanling +happend +hasing +hasnt +hda +hostanme +hould +hsould +hte +identifers +identifyer +identifyers +igoring +immediatley +implememented +implementor +implementors +implemnt +implict +implmeneted +implmentation +incase +includeing +incosistency +indecates +indien +infor +informations +informaton +infrastrcuture +ingore +inital +initalize +initator +initilization +inspite +instace +instal +instnace +intefaces +intepret +intereface +interfer +interpretted +intialize +intializes +intializing +invlaid +invokation +isnt +ist +klunky +lable +leve +lief +limite +linke +listner +lokal +lokales +maintainence +maintenace +maintenence +mamagement +mambers +manaully +manuel +maxium +mehtod +mergable +mesage +messge +metatdata +milisecond +minumum +mis +modifers +mor +mot +mulitply +multipl +multple +mutliple +nast +nd +neccessary +necesary +netowrk +nin +nodel +nome +noone +nowe +numbe +numer +occured +occurence +occuring +offfering +ofthe +omited +onother +opeation +optin +orginal +otherwse +outter +overriden +overwritting +paramater +paramemeter +paramenter +paramete +parametrs +pararmeter +parms +parralels +particualr +passowrd +perfromed +permissble +physcial +plugable +pluging +polcies +policys +poluting +possiblity +potenial +prefered +preffered +pressenter +previleges +primay +priviledged +procuct +programatically +progres +properites +propertie +propertys +propogate +provison +psudo +pyhsical +readabilty +readd +reccuring +recevied +recieved +recursivelly +redunant +refference +releease +relese +remaning +remore +remvoing +renabling +repeatly +reponse +reqest +reqiured +requieres +requried +reserv +reserverd +reseted +reseting +resorce +responser +resposne +resturns +retreive +retreiving +retrive +retrived +retriving +retrun +retuned +returing +re-use +rever +rocessor +runing +runnign +sate +scalled +scipt +scirpt +scrip +seconadry +seconday +seesion +sepcified +sepcify +seprated +ser +servies +seting +settig +sevices +shoul +shoule +sie +signle +simplier +singature +skiping +snaphsot +snpashot +specied +specifed +specifiy +splitted +spped +standy +statics +stickyness +stil +stip +storeage +strat +streched +strutural +succesfull +successfull +suceessful +suces +sucessfully +suiteable +suppots +suppport +syncronous +syste +tage +te +tempdate +testng +tha +thats +ther +therefor +theres +theses +thi +thorugh +throught +ths +tipically +transction +tring +trough +tyoe +ue +ues +unavailibility +uncommited +uncompressible +uneccessarily +unexepected +unexpect +unknow +unkonw +unkown +unneccessary +unparseable +unrecoginized +unsupport +unxpected +updat +uptodate +usera +usign +usin +utlization +vaidate +valiate +valule +valus +varibles +verfy +verfying +verifing +virutal +visable +wakup +wil +wit +wll +wth diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc2bd9db2bda..fd3c8f8ac67d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,9 +41,9 @@ jobs: cache: maven - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.10' architecture: 'x64' - name: Install Build Dependencies diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d369916f712e..ceffb42c79bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,7 +87,9 @@ jobs: smoke/test_migration smoke/test_multipleips_per_nic smoke/test_nested_virtualization - smoke/test_set_sourcenat", + smoke/test_set_sourcenat + smoke/test_webhook_lifecycle + smoke/test_purge_expunged_vms", "smoke/test_network smoke/test_network_acl smoke/test_network_ipv6 @@ -133,6 +135,7 @@ jobs: smoke/test_usage smoke/test_usage_events smoke/test_vm_deployment_planner + smoke/test_vm_strict_host_tags smoke/test_vm_schedule smoke/test_vm_life_cycle smoke/test_vm_lifecycle_unmanage_import @@ -181,7 +184,8 @@ jobs: "component/test_project_usage component/test_protocol_number_security_group component/test_public_ip - component/test_resource_limits", + component/test_resource_limits + component/test_resource_limit_tags", "component/test_regions_accounts component/test_routers component/test_snapshots @@ -220,9 +224,9 @@ jobs: cache: maven - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.10' architecture: 'x64' - name: Install Build Dependencies @@ -280,7 +284,7 @@ jobs: - name: Start CloudStack Management Server with Simulator run: | - export MAVEN_OPTS="-Xmx4096m -XX:MaxPermSize=800m -Djava.security.egd=file:/dev/urandom -javaagent:jacoco/lib/jacocoagent.jar=address=*,port=36320,output=tcpserver" + export MAVEN_OPTS="-Xmx4096m -XX:MaxMetaspaceSize=800m -Djava.security.egd=file:/dev/urandom -javaagent:jacoco/lib/jacocoagent.jar=address=*,port=36320,output=tcpserver --add-opens=java.base/java.lang=ALL-UNNAMED --add-exports=java.base/sun.security.x509=ALL-UNNAMED --add-opens=java.base/jdk.internal.reflect=ALL-UNNAMED" echo -e "\nStarting simulator" set +e mvn -Dsimulator -Dorg.eclipse.jetty.annotations.maxWait=120 -pl :cloud-client-ui jetty:run 2>&1 > /tmp/jetty-log || true & diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index a8f923d708d4..c77783746ca1 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -36,11 +36,11 @@ jobs: with: fetch-depth: 0 - - name: Set up JDK11 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '11' + java-version: '17' cache: 'maven' - name: Build CloudStack with Quality Checks diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 784df0cf03ca..b6c814a36f4c 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -39,7 +39,7 @@ jobs: pip install pre-commit - name: Set PY run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/.cache/pre-commit key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} diff --git a/.github/workflows/main-sonar-check.yml b/.github/workflows/main-sonar-check.yml index 66bb1093e040..8248e48022a3 100644 --- a/.github/workflows/main-sonar-check.yml +++ b/.github/workflows/main-sonar-check.yml @@ -36,22 +36,22 @@ jobs: with: fetch-depth: 0 - - name: Set up JDK11 + - name: Set up JDK17 uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '11' + java-version: '17' cache: 'maven' - name: Cache SonarCloud packages - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Cache local Maven repository - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/rat.yml b/.github/workflows/rat.yml index b8f83de81940..52ce343841ba 100644 --- a/.github/workflows/rat.yml +++ b/.github/workflows/rat.yml @@ -31,10 +31,10 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v4 with: - java-version: '11' + java-version: '17' distribution: 'adopt' architecture: x64 cache: maven diff --git a/.github/workflows/sonar-check.yml b/.github/workflows/sonar-check.yml index 2ebcf1fb2db7..c36bceb2b901 100644 --- a/.github/workflows/sonar-check.yml +++ b/.github/workflows/sonar-check.yml @@ -38,22 +38,22 @@ jobs: ref: "refs/pull/${{ github.event.number }}/merge" fetch-depth: 0 - - name: Set up JDK11 + - name: Set up JDK17 uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: '11' + java-version: '17' cache: 'maven' - name: Cache SonarCloud packages - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Cache local Maven repository - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/ui.yml b/.github/workflows/ui.yml index 476526aff32c..56f757133b71 100644 --- a/.github/workflows/ui.yml +++ b/.github/workflows/ui.yml @@ -36,7 +36,7 @@ jobs: - name: Set up Node uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 16 - name: Env details run: | diff --git a/.gitignore b/.gitignore index e638a09ae210..648b93b06965 100644 --- a/.gitignore +++ b/.gitignore @@ -15,92 +15,92 @@ # specific language governing permissions and limitations # under the License. -build/build.number -.lock-wscript -.waf-* -waf-* -target/ -override/ -.metadata -dist/ *~ +*_flymake.js *.bak -cloud-*.tar.bz2 -*.log -*.pyc -*.patch +*.css.map *.egginfo/ *.egg-info/ -*.prefs -build.number -*.log.* -cloud.log.*.* -unittest -deps/cloud.userlibraries -.DS_Store -.idea *.iml -git-remote-https.exe.stackdump -*.swp -tools/devcloud/devcloudbox/.vagrant -tools/cli/cloudmonkey/marvin/ -tools/cli/cloudmonkey/precache.py -tools/marvin/marvin/cloudstackAPI/ -tools/marvin/build/ -tools/cli/build/ -tools/appliance/systemvmtemplate/packer_cache/ +*.iso *.jar -*.war +*.log +*.log.* *.mar -*.iso +*.orig +*.patch +*.prefs +*.pyc +*.qcow2 +*.raw +*.swp *.tar.gz *.tgz *.vscode -*.css.map - -# this ignores _all files starting with '.'. Don't do that! -#.* - -target-eclipse -!.gitignore +*.war +.DS_Store +.checkstyle .classpath +.idea +.lock-wscript +.metadata +.pmd +.pmdruleset.xml +.project +.pydevproject +.reviewboardrc .settings.xml .settings/ -db.properties.override -replace.properties.override -tools/marvin/marvin/cloudstackAPI/* -docs/tmp -docs/publish -docs/runbook/tmp -docs/runbook/publish -.project +.vscode +.waf-* Gemfile.lock -debian/tmp -debian/files -debian/cloudstack-*/* -debian/*.substvars -debian/*.debhelper -replace.properties.tmp +build/build.number +build.number build-indep-stamp +cloud.log.*.* +cloud-*.tar.bz2 configure-stamp -*_flymake.js +db.properties.override +debian/*.debhelper +debian/*.substvars +debian/cloudstack-*/* +debian/files +debian/tmp +deps/cloud.userlibraries +dist/ +docs/publish +docs/runbook/publish +docs/runbook/tmp +docs/tmp engine/storage/integration-test/test-output -tools/apidoc/log/ +git-remote-https.exe.stackdump +node_modules +override/ +plugins/hypervisors/kvm/.pydevproject plugins/network-elements/juniper-contrail/logs/ +replace.properties.override +replace.properties.tmp +scripts/.pydevproject scripts/vm/hypervisor/xenserver/vhd-util -*.orig -tools/appliance/box/ -.reviewboardrc -.checkstyle -.pmd -.pmdruleset.xml -.pydevproject systemvm/.pydevproject +target/ +target-eclipse test/.pydevprojec -plugins/hypervisors/kvm/.pydevproject -scripts/.pydevproject -*.qcow2 -*.raw +tools/apidoc/log/ +tools/appliance/box/ +tools/appliance/systemvmtemplate/packer_cache/ +tools/cli/build/ +tools/cli/cloudmonkey/marvin/ +tools/cli/cloudmonkey/precache.py +tools/devcloud/devcloudbox/.vagrant +tools/marvin/build/ +tools/marvin/marvin/cloudstackAPI/ +tools/marvin/marvin/cloudstackAPI/* +unittest venv -node_modules -.vscode +waf-* + +# this ignores _all files starting with '.'. Don't do that! +#.* + +!.gitignore diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0848a1247945..e8f3c6093a9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: - id: identity - id: check-hooks-apply - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: #- id: check-added-large-files - id: check-case-conflict @@ -36,6 +36,8 @@ repos: - id: check-vcs-permalinks #- id: check-yaml - id: destroyed-symlinks + - id: detect-aws-credentials + args: [--allow-missing-credentials] - id: detect-private-key exclude: > (?x) @@ -53,11 +55,23 @@ repos: - id: end-of-file-fixer exclude: \.vhd$ #- id: fix-byte-order-marker + - id: forbid-submodules - id: mixed-line-ending exclude: \.(cs|xml)$ - # - id: trailing-whitespace + - id: trailing-whitespace + files: \.(header|in|java|md|properties|py|rb|sh|sql|txt|vue|xml|yaml|yml)$ + args: [--markdown-linebreak-ext=md] + exclude: ^services/console-proxy/rdpconsole/src/test/doc/freerdp-debug-log\.txt$ + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + name: run codespell + description: Check spelling with codespell + args: [--ignore-words=.github/linters/codespell.txt] + exclude: ^ui/package\.json$|^ui/package-lock\.json$|^ui/public/js/less\.min\.js$|^ui/public/locales/.*[^n].*\.json$ - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8 args: [--config, .github/linters/.flake8] @@ -72,3 +86,12 @@ repos: ^scripts/vm/hypervisor/xenserver/vmopspremium$| ^setup/bindir/cloud-setup-encryption\.in$| ^venv/.*$ + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.40.0 + hooks: + - id: markdownlint + name: run markdownlint + description: check Markdown files with markdownlint + args: [--config=.github/linters/.markdown-lint.yml] + types: [markdown] + files: \.(md|mdown|markdown)$ diff --git a/CHANGES.md b/CHANGES.md index ef498f8edf0b..9544fc014c75 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -430,11 +430,11 @@ Bug ID | Description [CLOUDSTACK-6099](https://issues.apache.org/jira/browse/CLOUDSTACK-6099) | live migration is failing for vm deployed using dynamic compute offerings with NPE [CLOUDSTACK-7528](https://issues.apache.org/jira/browse/CLOUDSTACK-7528) | More verbose logging when sending alert fails [CLOUDSTACK-6624](https://issues.apache.org/jira/browse/CLOUDSTACK-6624) | set specifyIpRanges to true if specifyVlan is set to true -[CLOUDSTACK-7404](https://issues.apache.org/jira/browse/CLOUDSTACK-7404) | Failed to start an instance when originating template has been deleted +[CLOUDSTACK-7404](https://issues.apache.org/jira/browse/CLOUDSTACK-7404) | Failed to start an instance when originating template has been deleted [CLOUDSTACK-6531](https://issues.apache.org/jira/browse/CLOUDSTACK-6531) | Stopping the router in case of command failures [CLOUDSTACK-6115](https://issues.apache.org/jira/browse/CLOUDSTACK-6115) | TravisCI configuration [CLOUDSTACK-7405](https://issues.apache.org/jira/browse/CLOUDSTACK-7405) | allowing VR meta-data to be accessed without trailing slash -[CLOUDSTACK-7260](https://issues.apache.org/jira/browse/CLOUDSTACK-7260) | Management server not responding after some time for Vmware due to Oom +[CLOUDSTACK-7260](https://issues.apache.org/jira/browse/CLOUDSTACK-7260) | Management server not responding after some time for Vmware due to Oom [CLOUDSTACK-7038](https://issues.apache.org/jira/browse/CLOUDSTACK-7038) | Add mysql client dependency for mgmt server pkg for debian [CLOUDSTACK-6892](https://issues.apache.org/jira/browse/CLOUDSTACK-6892) | Create separate package for the mysql HA component [CLOUDSTACK-7038](https://issues.apache.org/jira/browse/CLOUDSTACK-7038) | Add mysql client dependency for mgmt server/rpms @@ -449,12 +449,12 @@ Bug ID | Description [CLOUDSTACK-7006](https://issues.apache.org/jira/browse/CLOUDSTACK-7006) | Restore template ID in ROOT volume usages [CLOUDSTACK-6747](https://issues.apache.org/jira/browse/CLOUDSTACK-6747) | test to allow all cidrs on other end of vpc [CLOUDSTACK-6272](https://issues.apache.org/jira/browse/CLOUDSTACK-6272) | Fix recover/restore VM actions -[CLOUDSTACK-6927](https://issues.apache.org/jira/browse/CLOUDSTACK-6927) | store virsh list in list instead of querying libvirt +[CLOUDSTACK-6927](https://issues.apache.org/jira/browse/CLOUDSTACK-6927) | store virsh list in list instead of querying libvirt [CLOUDSTACK-6317](https://issues.apache.org/jira/browse/CLOUDSTACK-6317) | [VMware] Tagged VLAN support broken for Management/Control/Storage traffic [CLOUDSTACK-5891](https://issues.apache.org/jira/browse/CLOUDSTACK-5891) | [VMware] If a template has been registered and "cpu.corespersocket=X" , [CLOUDSTACK-6478](https://issues.apache.org/jira/browse/CLOUDSTACK-6478) | Failed to download Template when having 3 SSVM's in one [CLOUDSTACK-6464](https://issues.apache.org/jira/browse/CLOUDSTACK-6464) | if guest network type is vlan://untagged, and traffic label is used -[CLOUDSTACK-6816](https://issues.apache.org/jira/browse/CLOUDSTACK-6816) | bugfix: cloudstack-setup-management make /root directory's permission 0777 +[CLOUDSTACK-6816](https://issues.apache.org/jira/browse/CLOUDSTACK-6816) | bugfix: cloudstack-setup-management make /root directory's permission 0777 [CLOUDSTACK-6204](https://issues.apache.org/jira/browse/CLOUDSTACK-6204) | applying missed patch [CLOUDSTACK-6472](https://issues.apache.org/jira/browse/CLOUDSTACK-6472) | (4.3 specific) listUsageRecords: Pull information from removed items as well [CLOUDSTACK-5976](https://issues.apache.org/jira/browse/CLOUDSTACK-5976) | Typo in "ssh_keypairs" table's foreign key constraints on the Upgraded Setup @@ -657,11 +657,11 @@ Version 4.1.0 ------------- This is the second major release of CloudStack from within the Apache Software Foundation, and the -first major release as a Top-Level Project (TLP). +first major release as a Top-Level Project (TLP). Build Tool Changes: - * The project now uses Maven 3 exclusively to build. + * The project now uses Maven 3 exclusively to build. New Features: * CLOUDSTACK-101: OVS support in KVM @@ -976,14 +976,14 @@ Issues fixed in this release: * CLOUDSTACK-1845: KVM - storage migration often fails * CLOUDSTACK-1846: KVM - storage pools can silently fail to be unregistered, leading to failure to register later * CLOUDSTACK-2003: Deleting domain while deleted account is cleaning up leaves VMs expunging forever due to 'Failed to update resource count' -* CLOUDSTACK-2090: Upgrade from version 4.0.1 to version 4.0.2 triggers the 4.0.0 to 4.0.1. +* CLOUDSTACK-2090: Upgrade from version 4.0.1 to version 4.0.2 triggers the 4.0.0 to 4.0.1. * CLOUDSTACK-2091: Error in API documentation for 4.0.x. Version 4.0.1-incubating ------------------------ -This is a bugfix release for Apache CloudStack 4.0.0-incubating, with no new features. +This is a bugfix release for Apache CloudStack 4.0.0-incubating, with no new features. Security Fixes: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cdfbfe77b7ed..bb84e4e91fb3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,7 +3,7 @@ Contributing to Apache CloudStack (ACS) Summary ------- -This document covers how to contribute to the ACS project. ACS uses GitHub PRs to manage code contributions. +This document covers how to contribute to the ACS project. ACS uses GitHub PRs to manage code contributions. These instructions assume you have a GitHub.com account, so if you don't have one you will have to create one. Your proposed code changes will be published to your own fork of the ACS project and you will submit a Pull Request for your changes to be added. _Lets get started!!!_ @@ -11,17 +11,17 @@ _Lets get started!!!_ Bug fixes --------- -It's very important that we can easily track bug fix commits, so their hashes should remain the same in all branches. -Therefore, a pull request (PR) that fixes a bug, should be sent against a release branch. -This can be either the "current release" or the "previous release", depending on which ones are maintained. +It's very important that we can easily track bug fix commits, so their hashes should remain the same in all branches. +Therefore, a pull request (PR) that fixes a bug, should be sent against a release branch. +This can be either the "current release" or the "previous release", depending on which ones are maintained. Since the goal is a stable main, bug fixes should be "merged forward" to the next branch in order: "previous release" -> "current release" -> main (in other words: old to new) Developing new features ----------------------- -Development should be done in a feature branch, branched off of main. -Send a PR(steps below) to get it into main (2x LGTM applies). -PR will only be merged when main is open, will be held otherwise until main is open again. +Development should be done in a feature branch, branched off of main. +Send a PR(steps below) to get it into main (2x LGTM applies). +PR will only be merged when main is open, will be held otherwise until main is open again. No back porting / cherry-picking features to existing branches! PendingReleaseNotes file @@ -33,7 +33,7 @@ When adding information to the PendingReleaseNotes file make sure that you write Updating the PendingReleaseNotes file is preferably a part of the original Pull Request, but that is up to the developers' discretion. -Fork the code +Fork the code ------------- In your browser, navigate to: [https://github.com/apache/cloudstack](https://github.com/apache/cloudstack) @@ -136,4 +136,4 @@ $ git push origin :feature_x Release Principles ------------------ -Detailed information about ACS release principles is available at https://cwiki.apache.org/confluence/display/CLOUDSTACK/Release+principles+for+Apache+CloudStack+4.6+and+up +Detailed information about ACS release principles is available at https://cwiki.apache.org/confluence/display/CLOUDSTACK/Release+principles+for+Apache+CloudStack+4.6+and+up diff --git a/INSTALL.md b/INSTALL.md index 620fc1833a82..e133e7d7b91b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -15,7 +15,7 @@ was tested against a CentOS 7 x86_64 setup. Install tools and dependencies used for development: - # yum -y install git java-11-openjdk java-11-openjdk-devel \ + # yum -y install git java-17-openjdk java-17-openjdk-devel \ mysql mysql-server mkisofs git gcc python MySQL-python openssh-clients wget Set up Maven (3.6.0): @@ -78,7 +78,7 @@ Clear old database (if any) and deploy the database schema: Export the following variable if you need to run and debug the management server: - $ export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=500m -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n" + $ export MAVEN_OPTS="-Xmx1024m -XX:MaxMetaspaceSize=500m -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n" Start the management server: diff --git a/README.md b/README.md index e193913612f1..f66a4dc6f975 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ This distribution includes cryptographic software. The country in which you curr reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and -re-export of encryption software, to see if this is permitted. See [The Wassenaar Arrangement](http://www.wassenaar.org/) +re-export of encryption software, to see if this is permitted. See [The Wassenaar Arrangement](http://www.wassenaar.org/) for more information. The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has diff --git a/agent/bindir/cloud-setup-agent.in b/agent/bindir/cloud-setup-agent.in index 53c6c2f56aa4..18de64089ed0 100755 --- a/agent/bindir/cloud-setup-agent.in +++ b/agent/bindir/cloud-setup-agent.in @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/agent/bindir/cloud-ssh.in b/agent/bindir/cloud-ssh.in index e4b3c141a975..a5ea975c2f3a 100644 --- a/agent/bindir/cloud-ssh.in +++ b/agent/bindir/cloud-ssh.in @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/agent/conf/agent.properties b/agent/conf/agent.properties index e600e8f8f201..3b6a7b7de292 100644 --- a/agent/conf/agent.properties +++ b/agent/conf/agent.properties @@ -430,3 +430,6 @@ iscsi.session.cleanup.enabled=false # If set to "true", the agent will register for libvirt domain events, allowing for immediate updates on crashed or # unexpectedly stopped. Experimental, requires agent restart. # libvirt.events.enabled=false + +# Implicit host tags managed by agent.properties +# host.tags= diff --git a/agent/conf/cloudstack-agent.logrotate.in b/agent/conf/cloudstack-agent.logrotate.in index 2b3dc87f2532..9f22b4bab868 100644 --- a/agent/conf/cloudstack-agent.logrotate.in +++ b/agent/conf/cloudstack-agent.logrotate.in @@ -15,11 +15,13 @@ # specific language governing permissions and limitations # under the License. -/var/log/cloudstack/agent/security_group.log /var/log/cloudstack/agent/resizevolume.log /var/log/cloudstack/agent/rolling-maintenance.log { +/var/log/cloudstack/agent/security_group.log /var/log/cloudstack/agent/resizevolume.log /var/log/cloudstack/agent/rolling-maintenance.log /var/log/cloudstack/agent/agent.out /var/log/cloudstack/agent/agent.err { copytruncate daily rotate 5 compress missingok size 10M + dateext + dateformat -%Y-%m-%d } diff --git a/agent/conf/environment.properties.in b/agent/conf/environment.properties.in index 514161a13fc5..b6cc5bbd9879 100644 --- a/agent/conf/environment.properties.in +++ b/agent/conf/environment.properties.in @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/agent/conf/log4j-cloud.xml.in b/agent/conf/log4j-cloud.xml.in index 9ed43e083e03..84957edca032 100644 --- a/agent/conf/log4j-cloud.xml.in +++ b/agent/conf/log4j-cloud.xml.in @@ -17,91 +17,60 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/agent/pom.xml b/agent/pom.xml index d2a9f5b38398..9caa6d992c80 100644 --- a/agent/pom.xml +++ b/agent/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT diff --git a/agent/src/main/java/com/cloud/agent/Agent.java b/agent/src/main/java/com/cloud/agent/Agent.java index e73a26beea15..15f010808aca 100644 --- a/agent/src/main/java/com/cloud/agent/Agent.java +++ b/agent/src/main/java/com/cloud/agent/Agent.java @@ -55,9 +55,10 @@ import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; -import org.apache.log4j.MDC; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.AgentControlAnswer; import com.cloud.agent.api.AgentControlCommand; @@ -89,6 +90,7 @@ import com.cloud.utils.nio.Task; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; +import org.apache.logging.log4j.ThreadContext; /** * @config @@ -104,7 +106,7 @@ * **/ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater { - protected static Logger s_logger = Logger.getLogger(Agent.class); + protected Logger logger = LogManager.getLogger(getClass()); public enum ExitStatus { Normal(0), // Normal status = 0. @@ -181,7 +183,7 @@ public Agent(final IAgentShell shell, final int localAgentId, final ServerResour final String value = _shell.getPersistentProperty(getResourceName(), "id"); _id = value != null ? Long.parseLong(value) : null; - s_logger.info("id is " + (_id != null ? _id : "")); + logger.info("id is {}", ObjectUtils.defaultIfNull(_id, "")); final Map params = new HashMap<>(); @@ -199,7 +201,7 @@ public Agent(final IAgentShell shell, final int localAgentId, final ServerResour // ((NioClient)_connection).setBindAddress(_shell.getPrivateIp()); - s_logger.debug("Adding shutdown hook"); + logger.debug("Adding shutdown hook"); Runtime.getRuntime().addShutdownHook(_shutdownThread); _ugentTaskPool = @@ -210,8 +212,8 @@ public Agent(final IAgentShell shell, final int localAgentId, final ServerResour new ThreadPoolExecutor(_shell.getWorkers(), 5 * _shell.getWorkers(), 1, TimeUnit.DAYS, new LinkedBlockingQueue(), new NamedThreadFactory( "agentRequest-Handler")); - s_logger.info("Agent [id = " + (_id != null ? _id : "new") + " : type = " + getResourceName() + " : zone = " + _shell.getZone() + " : pod = " + _shell.getPod() + - " : workers = " + _shell.getWorkers() + " : host = " + host + " : port = " + _shell.getPort()); + logger.info("Agent [id = {} : type = {} : zone = {} : pod = {} : workers = {} : host = {} : port = {}", ObjectUtils.defaultIfNull(_id, "new"), getResourceName(), + _shell.getZone(), _shell.getPod(), _shell.getWorkers(), host, _shell.getPort()); } public String getVersion() { @@ -268,7 +270,7 @@ public void run() { public void start() { if (!_resource.start()) { - s_logger.error("Unable to start the resource: " + _resource.getName()); + logger.error("Unable to start the resource: {}", _resource.getName()); throw new CloudRuntimeException("Unable to start the resource: " + _resource.getName()); } @@ -285,14 +287,13 @@ public void start() { try { _connection.start(); } catch (final NioConnectionException e) { - s_logger.warn("NIO Connection Exception " + e); - s_logger.info("Attempted to connect to the server, but received an unexpected exception, trying again..."); + logger.warn("Attempt to connect to server generated NIO Connection Exception {}, trying again", e.getLocalizedMessage()); } while (!_connection.isStartup()) { final String host = _shell.getNextHost(); _shell.getBackoffAlgorithm().waitBeforeRetry(); _connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this); - s_logger.info("Connecting to host:" + host); + logger.info("Connecting to host:{}", host); try { _connection.start(); } catch (final NioConnectionException e) { @@ -300,9 +301,9 @@ public void start() { try { _connection.cleanUp(); } catch (final IOException ex) { - s_logger.warn("Fail to clean up old connection. " + ex); + logger.warn("Fail to clean up old connection. {}", ex); } - s_logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...", e); + logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...", e); } } _shell.updateConnectedHost(); @@ -311,7 +312,7 @@ public void start() { } public void stop(final String reason, final String detail) { - s_logger.info("Stopping the agent: Reason = " + reason + (detail != null ? ": Detail = " + detail : "")); + logger.info("Stopping the agent: Reason = {} {}", reason, ": Detail = " + ObjectUtils.defaultIfNull(detail, "")); _reconnectAllowed = false; if (_connection != null) { final ShutdownCommand cmd = new ShutdownCommand(reason, detail); @@ -321,15 +322,15 @@ public void stop(final String reason, final String detail) { _link.send(req.toBytes()); } } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send: " + cmd.toString()); + logger.warn("Unable to send: {}", cmd.toString()); } catch (final Exception e) { - s_logger.warn("Unable to send: " + cmd.toString() + " due to exception: ", e); + logger.warn("Unable to send: {} due to exception: {}", cmd.toString(), e); } - s_logger.debug("Sending shutdown to management server"); + logger.debug("Sending shutdown to management server"); try { Thread.sleep(1000); } catch (final InterruptedException e) { - s_logger.debug("Who the heck interrupted me here?"); + logger.debug("Who the heck interrupted me here?"); } _connection.stop(); _connection = null; @@ -376,7 +377,7 @@ public Long getId() { } public void setId(final Long id) { - s_logger.info("Set agent id " + id); + logger.debug("Set agent id {}", id); _id = id; _shell.setPersistentProperty(getResourceName(), "id", Long.toString(id)); } @@ -395,7 +396,7 @@ private synchronized void scheduleHostLBCheckerTask(final long checkInterval) { hostLBTimer.cancel(); } if (checkInterval > 0L) { - s_logger.info("Scheduling preferred host timer task with host.lb.interval=" + checkInterval + "ms"); + logger.info("Scheduling preferred host timer task with host.lb.interval={}ms", checkInterval); hostLBTimer = new Timer("Host LB Timer"); hostLBTimer.scheduleAtFixedRate(new PreferredHostCheckerTask(), checkInterval, checkInterval); } @@ -403,9 +404,8 @@ private synchronized void scheduleHostLBCheckerTask(final long checkInterval) { public void scheduleWatch(final Link link, final Request request, final long delay, final long period) { synchronized (_watchList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Adding a watch list"); - } + logger.debug("Adding task with request: {} to watch list", request.toString()); + final WatchTask task = new WatchTask(link, request, this); _timer.schedule(task, 0, period); _watchList.add(task); @@ -415,14 +415,14 @@ public void scheduleWatch(final Link link, final Request request, final long del public void triggerUpdate() { PingCommand command = _resource.getCurrentStatus(getId()); command.setOutOfBand(true); - s_logger.debug("Sending out of band ping"); + logger.debug("Sending out of band ping"); final Request request = new Request(_id, -1, command, false); request.setSequence(getNextSequence()); try { _link.send(request.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send ping update: " + request.toString()); + logger.warn("Unable to send ping update: {}", request.toString()); } } @@ -431,9 +431,7 @@ protected void cancelTasks() { for (final WatchTask task : _watchList) { task.cancel(); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Clearing watch list: " + _watchList.size()); - } + logger.debug("Clearing {} tasks of watch list", _watchList.size()); _watchList.clear(); } } @@ -469,14 +467,12 @@ public void sendStartup(final Link link) { final Request request = new Request(_id != null ? _id : -1, -1, commands, false, false); request.setSequence(getNextSequence()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending Startup: " + request.toString()); - } + logger.debug("Sending Startup: {}", request.toString()); lockStartupTask(link); try { link.send(request.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send request: " + request.toString()); + logger.warn("Unable to send request: {}", request.toString()); } if (_resource instanceof ResourceStatusUpdater) { @@ -490,11 +486,11 @@ protected void setupStartupCommand(final StartupCommand startup) { try { addr = InetAddress.getLocalHost(); } catch (final UnknownHostException e) { - s_logger.warn("unknown host? ", e); + logger.warn("unknown host? ", e); throw new CloudRuntimeException("Cannot get local IP address"); } - final Script command = new Script("hostname", 500, s_logger); + final Script command = new Script("hostname", 500, logger); final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); final String result = command.execute(parser); final String hostname = result == null ? parser.getLine() : addr.toString(); @@ -508,6 +504,13 @@ protected void setupStartupCommand(final StartupCommand startup) { startup.setGuid(getResourceGuid()); startup.setResourceName(getResourceName()); startup.setVersion(getVersion()); + startup.setArch(getAgentArch()); + } + + protected String getAgentArch() { + final Script command = new Script("/usr/bin/arch", 500, logger); + final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); + return command.execute(parser); } @Override @@ -536,14 +539,14 @@ protected void reconnect(final Link link) { _resource.disconnected(); - s_logger.info("Lost connection to host: " + _shell.getConnectedHost() + ". Attempting reconnection while we still have " + _inProgress.get() + " commands in progress."); + logger.info("Lost connection to host: {}. Attempting reconnection while we still have {} commands in progress.", _shell.getConnectedHost(), _inProgress.get()); _connection.stop(); try { _connection.cleanUp(); } catch (final IOException e) { - s_logger.warn("Fail to clean up old connection. " + e); + logger.warn("Fail to clean up old connection. {}", e); } while (_connection.isStartup()) { @@ -553,22 +556,22 @@ protected void reconnect(final Link link) { do { final String host = _shell.getNextHost(); _connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this); - s_logger.info("Reconnecting to host:" + host); + logger.info("Reconnecting to host:{}", host); try { _connection.start(); } catch (final NioConnectionException e) { - s_logger.info("Attempted to re-connect to the server, but received an unexpected exception, trying again...", e); + logger.info("Attempted to re-connect to the server, but received an unexpected exception, trying again...", e); _connection.stop(); try { _connection.cleanUp(); } catch (final IOException ex) { - s_logger.warn("Fail to clean up old connection. " + ex); + logger.warn("Fail to clean up old connection. {}", ex); } } _shell.getBackoffAlgorithm().waitBeforeRetry(); } while (!_connection.isStartup()); _shell.updateConnectedHost(); - s_logger.info("Connected to the host: " + _shell.getConnectedHost()); + logger.info("Connected to the host: {}", _shell.getConnectedHost()); } public void processStartupAnswer(final Answer answer, final Response response, final Link link) { @@ -583,15 +586,15 @@ public void processStartupAnswer(final Answer answer, final Response response, f } final StartupAnswer startup = (StartupAnswer)answer; if (!startup.getResult()) { - s_logger.error("Not allowed to connect to the server: " + answer.getDetails()); + logger.error("Not allowed to connect to the server: {}", answer.getDetails()); System.exit(1); } if (cancelled) { - s_logger.warn("Threw away a startup answer because we're reconnecting."); + logger.warn("Threw away a startup answer because we're reconnecting."); return; } - s_logger.info("Process agent startup answer, agent id = " + startup.getHostId()); + logger.info("Process agent startup answer, agent id = {}", startup.getHostId()); setId(startup.getHostId()); _pingInterval = (long)startup.getPingInterval() * 1000; // change to ms. @@ -601,7 +604,7 @@ public void processStartupAnswer(final Answer answer, final Response response, f _ugentTaskPool.setKeepAliveTime(2 * _pingInterval, TimeUnit.MILLISECONDS); - s_logger.info("Startup Response Received: agent id = " + getId()); + logger.info("Startup Response Received: agent id = {}", getId()); } protected void processRequest(final Request request, final Link link) { @@ -616,18 +619,18 @@ protected void processRequest(final Request request, final Link link) { Answer answer; try { if (cmd.getContextParam("logid") != null) { - MDC.put("logcontextid", cmd.getContextParam("logid")); + ThreadContext.put("logcontextid", cmd.getContextParam("logid")); } - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (!requestLogged) // ensures request is logged only once per method call { final String requestMsg = request.toString(); if (requestMsg != null) { - s_logger.debug("Request:" + requestMsg); + logger.debug("Request:{}",requestMsg); } requestLogged = true; } - s_logger.debug("Processing command: " + cmd.toString()); + logger.debug("Processing command: {}", cmd.toString()); } if (cmd instanceof CronCommand) { @@ -636,7 +639,7 @@ protected void processRequest(final Request request, final Link link) { answer = new Answer(cmd, true, null); } else if (cmd instanceof ShutdownCommand) { final ShutdownCommand shutdown = (ShutdownCommand)cmd; - s_logger.debug("Received shutdownCommand, due to: " + shutdown.getReason()); + logger.debug("Received shutdownCommand, due to: {}", shutdown.getReason()); cancelTasks(); if (shutdown.isRemoveHost()) { cleanupAgentZoneProperties(); @@ -644,11 +647,11 @@ protected void processRequest(final Request request, final Link link) { _reconnectAllowed = false; answer = new Answer(cmd, true, null); } else if (cmd instanceof ReadyCommand && ((ReadyCommand)cmd).getDetails() != null) { - s_logger.debug("Not ready to connect to mgt server: " + ((ReadyCommand)cmd).getDetails()); + logger.debug("Not ready to connect to mgt server: {}", ((ReadyCommand)cmd).getDetails()); System.exit(1); return; } else if (cmd instanceof MaintainCommand) { - s_logger.debug("Received maintainCommand, do not cancel current tasks"); + logger.debug("Received maintainCommand, do not cancel current tasks"); answer = new MaintainAnswer((MaintainCommand)cmd); } else if (cmd instanceof AgentControlCommand) { answer = null; @@ -662,7 +665,7 @@ protected void processRequest(final Request request, final Link link) { } if (answer == null) { - s_logger.warn("No handler found to process cmd: " + cmd.toString()); + logger.warn("No handler found to process cmd: {}", cmd.toString()); answer = new AgentControlAnswer(cmd); } } else if (cmd instanceof SetupKeyStoreCommand && ((SetupKeyStoreCommand) cmd).isHandleByAgent()) { @@ -685,12 +688,12 @@ protected void processRequest(final Request request, final Link link) { _inProgress.decrementAndGet(); } if (answer == null) { - s_logger.debug("Response: unsupported command" + cmd.toString()); + logger.debug("Response: unsupported command {}", cmd.toString()); answer = Answer.createUnsupportedCommandAnswer(cmd); } } } catch (final Throwable th) { - s_logger.warn("Caught: ", th); + logger.warn("Caught: ", th); final StringWriter writer = new StringWriter(); th.printStackTrace(new PrintWriter(writer)); answer = new Answer(cmd, false, writer.toString()); @@ -706,10 +709,10 @@ protected void processRequest(final Request request, final Link link) { } response = new Response(request, answers); } finally { - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { final String responseMsg = response.toString(); if (responseMsg != null) { - s_logger.debug(response.toString()); + logger.debug(response.toString()); } } @@ -717,7 +720,7 @@ protected void processRequest(final Request request, final Link link) { try { link.send(response.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send response: " + response.toString()); + logger.warn("Unable to send response: {}", response.toString()); } } } @@ -727,7 +730,7 @@ public Answer setupAgentKeystore(final SetupKeyStoreCommand cmd) { final String keyStorePassword = cmd.getKeystorePassword(); final long validityDays = cmd.getValidityDays(); - s_logger.debug("Setting up agent keystore file and generating CSR"); + logger.debug("Setting up agent keystore file and generating CSR"); final File agentFile = PropertiesUtil.findConfigFile("agent.properties"); if (agentFile == null) { @@ -742,7 +745,7 @@ public Answer setupAgentKeystore(final SetupKeyStoreCommand cmd) { _shell.setPersistentProperty(null, KeyStoreUtils.KS_PASSPHRASE_PROPERTY, storedPassword); } - Script script = new Script(_keystoreSetupPath, 300000, s_logger); + Script script = new Script(_keystoreSetupPath, 300000, logger); script.add(agentFile.getAbsolutePath()); script.add(keyStoreFile); script.add(storedPassword); @@ -767,7 +770,7 @@ private Answer setupAgentCertificate(final SetupCertificateCommand cmd) { final String privateKey = cmd.getPrivateKey(); final String caCertificates = cmd.getCaCertificates(); - s_logger.debug("Importing received certificate to agent's keystore"); + logger.debug("Importing received certificate to agent's keystore"); final File agentFile = PropertiesUtil.findConfigFile("agent.properties"); if (agentFile == null) { @@ -781,13 +784,13 @@ private Answer setupAgentCertificate(final SetupCertificateCommand cmd) { try { FileUtils.writeStringToFile(new File(certFile), certificate, Charset.defaultCharset()); FileUtils.writeStringToFile(new File(caCertFile), caCertificates, Charset.defaultCharset()); - s_logger.debug("Saved received client certificate to: " + certFile); + logger.debug("Saved received client certificate to: {}", certFile); } catch (IOException e) { throw new CloudRuntimeException("Unable to save received agent client and ca certificates", e); } String ksPassphrase = _shell.getPersistentProperty(null, KeyStoreUtils.KS_PASSPHRASE_PROPERTY); - Script script = new Script(_keystoreCertImportPath, 300000, s_logger); + Script script = new Script(_keystoreCertImportPath, 300000, logger); script.add(agentFile.getAbsolutePath()); script.add(ksPassphrase); script.add(keyStoreFile); @@ -812,7 +815,7 @@ private void processManagementServerList(final List msList, final String _shell.setPersistentProperty(null, "host", newMSHosts); _shell.setHosts(newMSHosts); _shell.resetHostCounter(); - s_logger.info("Processed new management server list: " + newMSHosts); + logger.info("Processed new management server list: {}", newMSHosts); } catch (final Exception e) { throw new CloudRuntimeException("Could not persist received management servers list", e); } @@ -831,9 +834,7 @@ private Answer setupManagementServerList(final SetupMSListCommand cmd) { public void processResponse(final Response response, final Link link) { final Answer answer = response.getAnswer(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Received response: " + response.toString()); - } + logger.debug("Received response: {}", response.toString()); if (answer instanceof StartupAnswer) { processStartupAnswer(answer, response, link); } else if (answer instanceof AgentControlAnswer) { @@ -844,7 +845,7 @@ public void processResponse(final Response response, final Link link) { } } } else if (answer instanceof PingAnswer && (((PingAnswer) answer).isSendStartup()) && _reconnectAllowed) { - s_logger.info("Management server requested startup command to reinitialize the agent"); + logger.info("Management server requested startup command to reinitialize the agent"); sendStartup(link); } else { setLastPingResponseTime(); @@ -859,44 +860,52 @@ public void processReadyCommand(final Command cmd) { NumbersUtil.enableHumanReadableSizes = humanReadable; } - s_logger.info("Processing agent ready command, agent id = " + ready.getHostId()); + logger.info("Processing agent ready command, agent id = {}", ready.getHostId()); if (ready.getHostId() != null) { setId(ready.getHostId()); } + verifyAgentArch(ready.getArch()); processManagementServerList(ready.getMsHostList(), ready.getLbAlgorithm(), ready.getLbCheckInterval()); - s_logger.info("Ready command is processed for agent id = " + getId()); + logger.info("Ready command is processed for agent id = {}", getId()); + } + + private void verifyAgentArch(String arch) { + if (StringUtils.isNotBlank(arch)) { + String agentArch = getAgentArch(); + if (!arch.equals(agentArch)) { + logger.error("Unexpected arch {}, expected {}", agentArch, arch); + } + } } public void processOtherTask(final Task task) { final Object obj = task.get(); if (obj instanceof Response) { if (System.currentTimeMillis() - _lastPingResponseTime > _pingInterval * _shell.getPingRetries()) { - s_logger.error("Ping Interval has gone past " + _pingInterval * _shell.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive"); + logger.error("Ping Interval has gone past {}. Won't reconnect to mgt server, as connection is still alive", _pingInterval * _shell.getPingRetries()); return; } final PingCommand ping = _resource.getCurrentStatus(getId()); final Request request = new Request(_id, -1, ping, false); request.setSequence(getNextSequence()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending ping: " + request.toString()); - } + logger.debug("Sending ping: {}", request.toString()); try { task.getLink().send(request.toBytes()); //if i can send pingcommand out, means the link is ok setLastPingResponseTime(); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send request: " + request.toString()); + logger.warn("Unable to send request: {}", request.toString()); } } else if (obj instanceof Request) { final Request req = (Request)obj; final Command command = req.getCommand(); if (command.getContextParam("logid") != null) { - MDC.put("logcontextid", command.getContextParam("logid")); + ThreadContext.put("logcontextid", command.getContextParam("logid")); } Answer answer = null; _inProgress.incrementAndGet(); @@ -908,17 +917,15 @@ public void processOtherTask(final Task task) { if (answer != null) { final Response response = new Response(req, answer); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Watch Sent: " + response.toString()); - } + logger.debug("Watch Sent: {}", response.toString()); try { task.getLink().send(response.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send response: " + response.toString()); + logger.warn("Unable to send response: {}", response.toString()); } } } else { - s_logger.warn("Ignoring an unknown task"); + logger.warn("Ignoring an unknown task"); } } @@ -958,7 +965,7 @@ public AgentControlAnswer sendRequest(final AgentControlCommand cmd, final int t try { listener.wait(timeoutInMilliseconds); } catch (final InterruptedException e) { - s_logger.warn("sendRequest is interrupted, exit waiting"); + logger.warn("sendRequest is interrupted, exit waiting"); } } @@ -980,7 +987,7 @@ private void postRequest(final Request request) throws AgentControlChannelExcept try { _link.send(request.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to post agent control request: " + request.toString()); + logger.warn("Unable to post agent control request: {}", request.toString()); throw new AgentControlChannelException("Unable to post agent control request due to " + e.getMessage()); } } else { @@ -1044,9 +1051,7 @@ public WatchTask(final Link link, final Request request, final Agent agent) { @Override protected void runInContext() { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Scheduling " + (_request instanceof Response ? "Ping" : "Watch Task")); - } + logger.trace("Scheduling {}", (_request instanceof Response ? "Ping" : "Watch Task")); try { if (_request instanceof Response) { _ugentTaskPool.submit(new ServerHandler(Task.Type.OTHER, _link, _request)); @@ -1054,7 +1059,7 @@ protected void runInContext() { _link.schedule(new ServerHandler(Task.Type.OTHER, _link, _request)); } } catch (final ClosedChannelException e) { - s_logger.warn("Unable to schedule task because channel is closed"); + logger.warn("Unable to schedule task because channel is closed"); } } } @@ -1064,7 +1069,7 @@ public class StartupTask extends ManagedContextTimerTask { protected volatile boolean cancelled = false; public StartupTask(final Link link) { - s_logger.debug("Startup task created"); + logger.debug("Startup task created"); _link = link; } @@ -1074,7 +1079,7 @@ public synchronized boolean cancel() { if (!cancelled) { cancelled = true; _startupWait = _startupWaitDefault; - s_logger.debug("Startup task cancelled"); + logger.debug("Startup task cancelled"); return super.cancel(); } return true; @@ -1083,9 +1088,7 @@ public synchronized boolean cancel() { @Override protected synchronized void runInContext() { if (!cancelled) { - if (s_logger.isInfoEnabled()) { - s_logger.info("The startup command is now cancelled"); - } + logger.info("The startup command is now cancelled"); cancelled = true; _startup = null; _startupWait = _startupWaitDefault * 2; @@ -1136,9 +1139,9 @@ public void doTask(final Task task) throws TaskExecutionException { _executor.submit(new AgentRequestHandler(getType(), getLink(), request)); } } catch (final ClassNotFoundException e) { - s_logger.error("Unable to find this request "); + logger.error("Unable to find this request "); } catch (final Exception e) { - s_logger.error("Error parsing task", e); + logger.error("Error parsing task", e); } } else if (task.getType() == Task.Type.DISCONNECT) { try { @@ -1172,7 +1175,7 @@ protected void runInContext() { while (true) { try { if (_inProgress.get() == 0) { - s_logger.debug("Running post certificate renewal task to restart services."); + logger.debug("Running post certificate renewal task to restart services."); // Let the resource perform any post certificate renewal cleanups _resource.executeRequest(new PostCertificateRenewalCommand()); @@ -1197,12 +1200,11 @@ protected void runInContext() { shell.launchNewAgent(resource); return; } - if (s_logger.isTraceEnabled()) { - s_logger.debug("Other tasks are in progress, will retry post certificate renewal command after few seconds"); - } + logger.debug("Other tasks are in progress, will retry post certificate renewal command after few seconds"); + Thread.sleep(5000); } catch (final Exception e) { - s_logger.warn("Failed to execute post certificate renewal command:", e); + logger.warn("Failed to execute post certificate renewal command:", e); break; } } @@ -1220,29 +1222,26 @@ protected void runInContext() { } final String preferredHost = msList[0]; final String connectedHost = _shell.getConnectedHost(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Running preferred host checker task, connected host=" + connectedHost + ", preferred host=" + preferredHost); - } + logger.trace("Running preferred host checker task, connected host={}, preferred host={}", connectedHost, preferredHost); + if (preferredHost != null && !preferredHost.equals(connectedHost) && _link != null) { boolean isHostUp = true; try (final Socket socket = new Socket()) { socket.connect(new InetSocketAddress(preferredHost, _shell.getPort()), 5000); } catch (final IOException e) { isHostUp = false; - if (s_logger.isTraceEnabled()) { - s_logger.trace("Host: " + preferredHost + " is not reachable"); - } + logger.trace("Host: {} is not reachable", preferredHost); + } if (isHostUp && _link != null && _inProgress.get() == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Preferred host " + preferredHost + " is found to be reachable, trying to reconnect"); - } + logger.debug("Preferred host {} is found to be reachable, trying to reconnect", preferredHost); + _shell.resetHostCounter(); reconnect(_link); } } } catch (Throwable t) { - s_logger.error("Error caught while attempting to connect to preferred host", t); + logger.error("Error caught while attempting to connect to preferred host", t); } } diff --git a/agent/src/main/java/com/cloud/agent/AgentShell.java b/agent/src/main/java/com/cloud/agent/AgentShell.java index ef042496a372..0699e00250bb 100644 --- a/agent/src/main/java/com/cloud/agent/AgentShell.java +++ b/agent/src/main/java/com/cloud/agent/AgentShell.java @@ -34,8 +34,9 @@ import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.config.Configurator; import javax.naming.ConfigurationException; import java.io.File; @@ -53,7 +54,7 @@ import java.util.UUID; public class AgentShell implements IAgentShell, Daemon { - private static final Logger s_logger = Logger.getLogger(AgentShell.class.getName()); + protected static Logger LOGGER = LogManager.getLogger(AgentShell.class); private final Properties _properties = new Properties(); private final Map _cmdLineProperties = new HashMap(); @@ -221,7 +222,7 @@ void loadProperties() throws ConfigurationException { throw new ConfigurationException("Unable to find agent.properties."); } - s_logger.info("agent.properties found at " + file.getAbsolutePath()); + LOGGER.info("agent.properties found at {}", file.getAbsolutePath()); try { PropertiesUtil.loadFromFile(_properties, file); @@ -349,7 +350,7 @@ protected int getPortOrWorkers(String portOrWorkers, AgentProperties.Property c = this.getClass(); @@ -381,19 +382,19 @@ public void init(String[] args) throws ConfigurationException { if (_version == null) { throw new CloudRuntimeException("Unable to find the implementation version of this agent"); } - s_logger.info("Implementation Version is " + _version); + LOGGER.info("Implementation Version is {}", _version); loadProperties(); parseCommand(args); - if (s_logger.isDebugEnabled()) { + if (LOGGER.isDebugEnabled()) { List properties = Collections.list((Enumeration)_properties.propertyNames()); for (String property : properties) { - s_logger.debug("Found property: " + property); + LOGGER.debug("Found property: {}", property); } } - s_logger.info("Defaulting to using properties file for storage"); + LOGGER.info("Defaulting to using properties file for storage"); _storage = new PropertiesStorage(); _storage.configure("Storage", new HashMap()); @@ -403,14 +404,14 @@ public void init(String[] args) throws ConfigurationException { _properties.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } - s_logger.info("Defaulting to the constant time backoff algorithm"); + LOGGER.info("Defaulting to the constant time backoff algorithm"); _backoff = new ConstantTimeBackoff(); _backoff.configure("ConstantTimeBackoff", new HashMap()); } private void launchAgent() throws ConfigurationException { String resourceClassNames = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.RESOURCE); - s_logger.trace("resource=" + resourceClassNames); + LOGGER.trace("resource={}", resourceClassNames); if (resourceClassNames != null) { launchAgentFromClassInfo(resourceClassNames); return; @@ -440,10 +441,10 @@ private void launchAgentFromClassInfo(String resourceClassNames) throws Configur private void launchAgentFromTypeInfo() throws ConfigurationException { String typeInfo = getProperty(null, "type"); if (typeInfo == null) { - s_logger.error("Unable to retrieve the type"); + LOGGER.error("Unable to retrieve the type"); throw new ConfigurationException("Unable to retrieve the type of this agent."); } - s_logger.trace("Launching agent based on type=" + typeInfo); + LOGGER.trace("Launching agent based on type={}", typeInfo); } public void launchNewAgent(ServerResource resource) throws ConfigurationException { @@ -477,17 +478,17 @@ public void start() { } if (ipv6disabled) { - s_logger.info("Preferring IPv4 address family for agent connection"); + LOGGER.info("Preferring IPv4 address family for agent connection"); System.setProperty("java.net.preferIPv4Stack", "true"); if (ipv6prefer) { - s_logger.info("ipv6prefer is set to true, but ipv6disabled is false. Not preferring IPv6 for agent connection"); + LOGGER.info("ipv6prefer is set to true, but ipv6disabled is false. Not preferring IPv6 for agent connection"); } } else { if (ipv6prefer) { - s_logger.info("Preferring IPv6 address family for agent connection"); + LOGGER.info("Preferring IPv6 address family for agent connection"); System.setProperty("java.net.preferIPv6Addresses", "true"); } else { - s_logger.info("Using default Java settings for IPv6 preference for agent connection"); + LOGGER.info("Using default Java settings for IPv6 preference for agent connection"); } } @@ -505,7 +506,7 @@ public void start() { String pidDir = getProperty(null, "piddir"); final String run = "agent." + instance + "pid"; - s_logger.debug("Checking to see if " + run + " exists."); + LOGGER.debug("Checking to see if {} exists.", run); ProcessUtil.pidCheck(pidDir, run); launchAgent(); @@ -514,11 +515,11 @@ public void start() { while (!_exit) Thread.sleep(1000); } catch (InterruptedException e) { - s_logger.debug("[ignored] AgentShell was interrupted."); + LOGGER.debug("[ignored] AgentShell was interrupted."); } } catch (final Exception e) { - s_logger.error("Unable to start agent: ", e); + LOGGER.error("Unable to start agent: ", e); System.exit(ExitStatus.Error.value()); } } @@ -535,7 +536,7 @@ public void destroy() { public static void main(String[] args) { try { - s_logger.debug("Initializing AgentShell from main"); + LOGGER.debug("Initializing AgentShell from main"); AgentShell shell = new AgentShell(); shell.init(args); shell.start(); diff --git a/agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java b/agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java index 87610c29f345..17e0ceeeedea 100644 --- a/agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java +++ b/agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java @@ -24,7 +24,8 @@ import java.util.Properties; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.dao.StorageComponent; import com.cloud.utils.PropertiesUtil; @@ -36,7 +37,7 @@ * path to the properties _file | String | db/db.properties || * } **/ public class PropertiesStorage implements StorageComponent { - private static final Logger s_logger = Logger.getLogger(PropertiesStorage.class); + protected Logger logger = LogManager.getLogger(getClass()); Properties _properties = new Properties(); File _file; String _name; @@ -49,7 +50,7 @@ public synchronized String get(String key) { @Override public synchronized void persist(String key, String value) { if (!loadFromFile(_file)) { - s_logger.error("Failed to load changes and then write to them"); + logger.error("Failed to load changes and then write to them"); } _properties.setProperty(key, value); FileOutputStream output = null; @@ -59,7 +60,7 @@ public synchronized void persist(String key, String value) { output.flush(); output.close(); } catch (IOException e) { - s_logger.error("Uh-oh: ", e); + logger.error("Uh-oh: ", e); } finally { IOUtils.closeQuietly(output); } @@ -70,10 +71,10 @@ private synchronized boolean loadFromFile(final File file) { PropertiesUtil.loadFromFile(_properties, file); _file = file; } catch (FileNotFoundException e) { - s_logger.error("How did we get here? ", e); + logger.error("How did we get here? ", e); return false; } catch (IOException e) { - s_logger.error("IOException: ", e); + logger.error("IOException: ", e); return false; } return true; @@ -92,14 +93,12 @@ public synchronized boolean configure(String name, Map params) { file = new File(path); try { if (!file.createNewFile()) { - s_logger.error(String.format("Unable to create _file: %s", file.getAbsolutePath())); + logger.error("Unable to create _file: {}", file.getAbsolutePath()); return false; } } catch (IOException e) { - s_logger.error(String.format("Unable to create file: %s", file.getAbsolutePath())); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("IOException while trying to create file: %s", file.getAbsolutePath()), e); - } + logger.error("Unable to create file: {}", file.getAbsolutePath()); + logger.debug("IOException while trying to create file: {}", file.getAbsolutePath(), e); return false; } } diff --git a/agent/src/main/java/com/cloud/agent/dhcp/DhcpProtocolParserServer.java b/agent/src/main/java/com/cloud/agent/dhcp/DhcpProtocolParserServer.java index 0ee9fd6860db..00488f94382b 100644 --- a/agent/src/main/java/com/cloud/agent/dhcp/DhcpProtocolParserServer.java +++ b/agent/src/main/java/com/cloud/agent/dhcp/DhcpProtocolParserServer.java @@ -25,12 +25,13 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import org.apache.log4j.Logger; import com.cloud.utils.concurrency.NamedThreadFactory; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class DhcpProtocolParserServer extends Thread { - private static final Logger s_logger = Logger.getLogger(DhcpProtocolParserServer.class);; + protected Logger logger = LogManager.getLogger(DhcpProtocolParserServer.class);; protected ExecutorService _executor; private int dhcpServerPort = 67; private int bufferSize = 300; @@ -54,7 +55,7 @@ public void run() { dhcpSocket.receive(dgp); } } catch (IOException e) { - s_logger.debug(e.getMessage()); + logger.debug(e.getMessage()); } } } diff --git a/agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java b/agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java index b155cb725b13..54fdde3d3d28 100644 --- a/agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java +++ b/agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java @@ -22,14 +22,15 @@ import java.util.Random; import java.util.Set; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine.State; public class MockVmMgr implements VmMgr { - private static final Logger s_logger = Logger.getLogger(MockVmMgr.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int DEFAULT_DOM0_MEM_MB = 128; private static final Random randSeed = new Random(); @@ -56,14 +57,14 @@ public Set getCurrentVMs() { public String startVM(String vmName, String vnetId, String gateway, String dns, String privateIP, String privateMac, String privateMask, String publicIP, String publicMac, String publicMask, int cpuCount, int cpuUtilization, long ramSize, String localPath, String vncPassword) { - if (s_logger.isInfoEnabled()) { + if (logger.isInfoEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("Start VM. name: " + vmName + ", vnet: " + vnetId + ", dns: " + dns); sb.append(", privateIP: " + privateIP + ", privateMac: " + privateMac + ", privateMask: " + privateMask); sb.append(", publicIP: " + publicIP + ", publicMac: " + publicMac + ", publicMask: " + publicMask); sb.append(", cpu count: " + cpuCount + ", cpuUtilization: " + cpuUtilization + ", ram : " + ramSize); sb.append(", localPath: " + localPath); - s_logger.info(sb.toString()); + logger.info(sb.toString()); } synchronized (this) { @@ -86,8 +87,7 @@ public String startVM(String vmName, String vnetId, String gateway, String dns, @Override public String stopVM(String vmName, boolean force) { - if (s_logger.isInfoEnabled()) - s_logger.info("Stop VM. name: " + vmName); + logger.info("Stop VM. name: {}", vmName); synchronized (this) { MockVm vm = vms.get(vmName); @@ -102,8 +102,7 @@ public String stopVM(String vmName, boolean force) { @Override public String rebootVM(String vmName) { - if (s_logger.isInfoEnabled()) - s_logger.info("Reboot VM. name: " + vmName); + logger.info("Reboot VM. name: {}", vmName); synchronized (this) { MockVm vm = vms.get(vmName); @@ -115,8 +114,7 @@ public String rebootVM(String vmName) { @Override public boolean migrate(String vmName, String params) { - if (s_logger.isInfoEnabled()) - s_logger.info("Migrate VM. name: " + vmName); + logger.info("Migrate VM. name: {}", vmName); synchronized (this) { MockVm vm = vms.get(vmName); @@ -258,13 +256,13 @@ public MockVm createVmFromSpec(VirtualMachineTO vmSpec) { vm = vms.get(vmName); if (vm == null) { if (ramSize > getHostFreeMemory()) { - s_logger.debug("host is out of memory"); + logger.debug("host is out of memory"); throw new CloudRuntimeException("Host is out of Memory"); } int vncPort = allocVncPort(); if (vncPort < 0) { - s_logger.debug("Unable to allocate VNC port"); + logger.debug("Unable to allocate VNC port"); throw new CloudRuntimeException("Unable to allocate vnc port"); } diff --git a/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java b/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java index cc0acfd18d35..8f97edc39357 100644 --- a/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java +++ b/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java @@ -803,6 +803,13 @@ public Property getWorkers() { */ public static final Property KEYSTORE_PASSPHRASE = new Property<>(KeyStoreUtils.KS_PASSPHRASE_PROPERTY, null, String.class); + /** + * Implicit host tags + * Data type: String.
+ * Default value: null + */ + public static final Property HOST_TAGS = new Property<>("host.tags", null, String.class); + public static class Property { private String name; private T defaultValue; diff --git a/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java b/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java index 602aa1efcb0d..b28018fcd943 100644 --- a/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java +++ b/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java @@ -22,7 +22,8 @@ import org.apache.commons.beanutils.converters.IntegerConverter; import org.apache.commons.beanutils.converters.LongConverter; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; /** * This class provides a facility to read the agent's properties file and get @@ -31,7 +32,7 @@ */ public class AgentPropertiesFileHandler { - private static final Logger logger = Logger.getLogger(AgentPropertiesFileHandler.class); + protected static Logger LOGGER = LogManager.getLogger(AgentPropertiesFileHandler.class); /** * This method reads the property in the agent.properties file. @@ -47,7 +48,7 @@ public static T getPropertyValue(AgentProperties.Property property) { File agentPropertiesFile = PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE); if (agentPropertiesFile == null) { - logger.debug(String.format("File [%s] was not found, we will use default defined values. Property [%s]: [%s].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue)); + LOGGER.debug("File [{}] was not found, we will use default defined values. Property [{}]: [{}].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue); return defaultValue; } @@ -55,7 +56,7 @@ public static T getPropertyValue(AgentProperties.Property property) { try { String configValue = PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(name); if (StringUtils.isBlank(configValue)) { - logger.debug(String.format("Property [%s] has empty or null value. Using default value [%s].", name, defaultValue)); + LOGGER.debug("Property [{}] has empty or null value. Using default value [{}].", name, defaultValue); return defaultValue; } @@ -67,11 +68,11 @@ public static T getPropertyValue(AgentProperties.Property property) { ConvertUtils.register(new LongConverter(defaultValue), Long.class); } - logger.debug(String.format("Property [%s] was altered. Now using the value [%s].", name, configValue)); + LOGGER.debug("Property [{}] was altered. Now using the value [{}].", name, configValue); return (T)ConvertUtils.convert(configValue, property.getTypeClass()); } catch (IOException ex) { - logger.debug(String.format("Failed to get property [%s]. Using default value [%s].", name, defaultValue), ex); + LOGGER.debug("Failed to get property [{}]. Using default value [{}].", name, defaultValue, ex); } return defaultValue; diff --git a/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java b/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java index 5412c3470127..ccd0d976e583 100644 --- a/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java +++ b/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java @@ -34,7 +34,6 @@ import com.cloud.agent.api.proxy.AllowConsoleAccessCommand; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; import com.cloud.agent.Agent.ExitStatus; import com.cloud.agent.api.AgentControlAnswer; @@ -81,7 +80,6 @@ * */ public class ConsoleProxyResource extends ServerResourceBase implements ServerResource { - static final Logger s_logger = Logger.getLogger(ConsoleProxyResource.class); private final Properties properties = new Properties(); private Thread consoleProxyMain = null; @@ -101,7 +99,7 @@ public Answer executeRequest(final Command cmd) { } else if (cmd instanceof WatchConsoleProxyLoadCommand) { return execute((WatchConsoleProxyLoadCommand)cmd); } else if (cmd instanceof ReadyCommand) { - s_logger.info("Receive ReadyCommand, response with ReadyAnswer"); + logger.info("Receive ReadyCommand, response with ReadyAnswer"); return new ReadyAnswer((ReadyCommand)cmd); } else if (cmd instanceof CheckHealthCommand) { return new CheckHealthAnswer((CheckHealthCommand)cmd, true); @@ -123,13 +121,13 @@ private Answer execute(AllowConsoleAccessCommand cmd) { return new Answer(cmd); } catch (SecurityException | NoSuchMethodException | ClassNotFoundException | InvocationTargetException | IllegalAccessException e) { String errorMsg = "Unable to add allowed session due to: " + e.getMessage(); - s_logger.error(errorMsg, e); + logger.error(errorMsg, e); return new Answer(cmd, false, errorMsg); } } private Answer execute(StartConsoleProxyAgentHttpHandlerCommand cmd) { - s_logger.info("Invoke launchConsoleProxy() in responding to StartConsoleProxyAgentHttpHandlerCommand"); + logger.info("Invoke launchConsoleProxy() in responding to StartConsoleProxyAgentHttpHandlerCommand"); launchConsoleProxy(cmd.getKeystoreBits(), cmd.getKeystorePassword(), cmd.getEncryptorPassword(), cmd.isSourceIpCheckEnabled()); return new Answer(cmd); } @@ -140,7 +138,7 @@ private void disableRpFilter() { { out.write("0"); } catch (IOException e) { - s_logger.warn("Unable to disable rp_filter"); + logger.warn("Unable to disable rp_filter"); } } @@ -177,12 +175,12 @@ private Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, fin try { is.close(); } catch (final IOException e) { - s_logger.warn("Exception when closing , console proxy address : " + proxyManagementIp); + logger.warn("Exception when closing , console proxy address : {}", proxyManagementIp); success = false; } } } catch (final IOException e) { - s_logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp); + logger.warn("Unable to open console proxy command port url, console proxy address : {}", proxyManagementIp); success = false; } @@ -227,14 +225,14 @@ public boolean configure(String name, Map params) throws Configu if (eth1Ip != null) { params.put("private.network.device", "eth1"); } else { - s_logger.info("eth1ip parameter has not been configured, assuming that we are not inside a system vm"); + logger.info("eth1ip parameter has not been configured, assuming that we are not inside a system vm"); } String eth2ip = (String)params.get("eth2ip"); if (eth2ip != null) { params.put("public.network.device", "eth2"); } else { - s_logger.info("eth2ip parameter is not found, assuming that we are not inside a system vm"); + logger.info("eth2ip parameter is not found, assuming that we are not inside a system vm"); } super.configure(name, params); @@ -262,7 +260,7 @@ public boolean configure(String name, Map params) throws Configu } String internalDns1 = (String) params.get("internaldns1"); if (internalDns1 == null) { - s_logger.warn("No DNS entry found during configuration of ConsoleProxy"); + logger.warn("No DNS entry found during configuration of ConsoleProxy"); } else { addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, internalDns1); } @@ -280,20 +278,19 @@ public boolean configure(String name, Map params) throws Configu disableRpFilter(); } - if (s_logger.isInfoEnabled()) - s_logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + proxyVmId); + logger.info("Receive proxyVmId in ConsoleProxyResource configuration as {}", proxyVmId); return true; } private void addRouteToInternalIpOrCidr(String localgw, String eth1ip, String eth1mask, String destIpOrCidr) { - s_logger.debug("addRouteToInternalIp: localgw=" + localgw + ", eth1ip=" + eth1ip + ", eth1mask=" + eth1mask + ",destIp=" + destIpOrCidr); + logger.debug("addRouteToInternalIp: localgw={}, eth1ip={}, eth1mask={}, destIp={}", localgw, eth1ip, eth1mask, destIpOrCidr); if (destIpOrCidr == null) { - s_logger.debug("addRouteToInternalIp: destIp is null"); + logger.debug("addRouteToInternalIp: destIp is null"); return; } if (!NetUtils.isValidIp4(destIpOrCidr) && !NetUtils.isValidIp4Cidr(destIpOrCidr)) { - s_logger.warn(" destIp is not a valid ip address or cidr destIp=" + destIpOrCidr); + logger.warn(" destIp is not a valid ip address or cidr destIp={}", destIpOrCidr); return; } boolean inSameSubnet = false; @@ -301,27 +298,27 @@ private void addRouteToInternalIpOrCidr(String localgw, String eth1ip, String et if (eth1ip != null && eth1mask != null) { inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr, eth1mask); } else { - s_logger.warn("addRouteToInternalIp: unable to determine same subnet: eth1ip=" + eth1ip + ", dest ip=" + destIpOrCidr + ", eth1mask=" + eth1mask); + logger.warn("addRouteToInternalIp: unable to determine same subnet: eth1ip={}, dest ip={}, eth1mask={}", eth1ip, destIpOrCidr, eth1mask); } } else { inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr, NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask)); } if (inSameSubnet) { - s_logger.debug("addRouteToInternalIp: dest ip " + destIpOrCidr + " is in the same subnet as eth1 ip " + eth1ip); + logger.debug("addRouteToInternalIp: dest ip {} is in the same subnet as eth1 ip {}", destIpOrCidr, eth1ip); return; } - Script command = new Script("/bin/bash", s_logger); + Script command = new Script("/bin/bash", logger); command.add("-c"); command.add("ip route delete " + destIpOrCidr); command.execute(); - command = new Script("/bin/bash", s_logger); + command = new Script("/bin/bash", logger); command.add("-c"); command.add("ip route add " + destIpOrCidr + " via " + localgw); String result = command.execute(); if (result != null) { - s_logger.warn("Error in configuring route to internal ip err=" + result); + logger.warn("Error in configuring route to internal ip err={}", result); } else { - s_logger.debug("addRouteToInternalIp: added route to internal ip=" + destIpOrCidr + " via " + localgw); + logger.debug("addRouteToInternalIp: added route to internal ip={} via {}", destIpOrCidr, localgw); } } @@ -332,36 +329,36 @@ public String getName() { private void launchConsoleProxy(final byte[] ksBits, final String ksPassword, final String encryptorPassword, final Boolean isSourceIpCheckEnabled) { final Object resource = this; - s_logger.info("Building class loader for com.cloud.consoleproxy.ConsoleProxy"); + logger.info("Building class loader for com.cloud.consoleproxy.ConsoleProxy"); if (consoleProxyMain == null) { - s_logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password=" + encryptorPassword); + logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password={}", encryptorPassword); consoleProxyMain = new Thread(new ManagedContextRunnable() { @Override protected void runInContext() { try { Class consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy"); try { - s_logger.info("Invoke startWithContext()"); + logger.info("Invoke startWithContext()"); Method method = consoleProxyClazz.getMethod("startWithContext", Properties.class, Object.class, byte[].class, String.class, String.class, Boolean.class); method.invoke(null, properties, resource, ksBits, ksPassword, encryptorPassword, isSourceIpCheckEnabled); } catch (SecurityException e) { - s_logger.error("Unable to launch console proxy due to SecurityException", e); + logger.error("Unable to launch console proxy due to SecurityException", e); System.exit(ExitStatus.Error.value()); } catch (NoSuchMethodException e) { - s_logger.error("Unable to launch console proxy due to NoSuchMethodException", e); + logger.error("Unable to launch console proxy due to NoSuchMethodException", e); System.exit(ExitStatus.Error.value()); } catch (IllegalArgumentException e) { - s_logger.error("Unable to launch console proxy due to IllegalArgumentException", e); + logger.error("Unable to launch console proxy due to IllegalArgumentException", e); System.exit(ExitStatus.Error.value()); } catch (IllegalAccessException e) { - s_logger.error("Unable to launch console proxy due to IllegalAccessException", e); + logger.error("Unable to launch console proxy due to IllegalAccessException", e); System.exit(ExitStatus.Error.value()); } catch (InvocationTargetException e) { - s_logger.error("Unable to launch console proxy due to InvocationTargetException " + e.getTargetException().toString(), e); + logger.error("Unable to launch console proxy due to InvocationTargetException {}", e.getTargetException().toString(), e); System.exit(ExitStatus.Error.value()); } } catch (final ClassNotFoundException e) { - s_logger.error("Unable to launch console proxy due to ClassNotFoundException"); + logger.error("Unable to launch console proxy due to ClassNotFoundException"); System.exit(ExitStatus.Error.value()); } } @@ -369,7 +366,7 @@ protected void runInContext() { consoleProxyMain.setDaemon(true); consoleProxyMain.start(); } else { - s_logger.info("com.cloud.consoleproxy.ConsoleProxy is already running"); + logger.info("com.cloud.consoleproxy.ConsoleProxy is already running"); try { Class consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy"); @@ -378,22 +375,22 @@ protected void runInContext() { methodSetup = consoleProxyClazz.getMethod("setIsSourceIpCheckEnabled", Boolean.class); methodSetup.invoke(null, isSourceIpCheckEnabled); } catch (SecurityException e) { - s_logger.error("Unable to launch console proxy due to SecurityException", e); + logger.error("Unable to launch console proxy due to SecurityException", e); System.exit(ExitStatus.Error.value()); } catch (NoSuchMethodException e) { - s_logger.error("Unable to launch console proxy due to NoSuchMethodException", e); + logger.error("Unable to launch console proxy due to NoSuchMethodException", e); System.exit(ExitStatus.Error.value()); } catch (IllegalArgumentException e) { - s_logger.error("Unable to launch console proxy due to IllegalArgumentException", e); + logger.error("Unable to launch console proxy due to IllegalArgumentException", e); System.exit(ExitStatus.Error.value()); } catch (IllegalAccessException e) { - s_logger.error("Unable to launch console proxy due to IllegalAccessException", e); + logger.error("Unable to launch console proxy due to IllegalAccessException", e); System.exit(ExitStatus.Error.value()); } catch (InvocationTargetException e) { - s_logger.error("Unable to launch console proxy due to InvocationTargetException " + e.getTargetException().toString(), e); + logger.error("Unable to launch console proxy due to InvocationTargetException " + e.getTargetException().toString(), e); System.exit(ExitStatus.Error.value()); } catch (final ClassNotFoundException e) { - s_logger.error("Unable to launch console proxy due to ClassNotFoundException", e); + logger.error("Unable to launch console proxy due to ClassNotFoundException", e); System.exit(ExitStatus.Error.value()); } } @@ -420,10 +417,10 @@ public String authenticateConsoleAccess(String host, String port, String vmId, S result.setTunnelUrl(authAnswer.getTunnelUrl()); result.setTunnelSession(authAnswer.getTunnelSession()); } else { - s_logger.error("Authentication failed for vm: " + vmId + " with sid: " + sid); + logger.error("Authentication failed for vm: {} with sid: {}", vmId, sid); } } catch (AgentControlChannelException e) { - s_logger.error("Unable to send out console access authentication request due to " + e.getMessage(), e); + logger.error("Unable to send out console access authentication request due to {}", e.getMessage(), e); } return new Gson().toJson(result); @@ -433,18 +430,15 @@ public void reportLoadInfo(String gsonLoadInfo) { ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(proxyVmId, gsonLoadInfo); try { getAgentControl().postRequest(cmd); - - if (s_logger.isDebugEnabled()) - s_logger.debug("Report proxy load info, proxy : " + proxyVmId + ", load: " + gsonLoadInfo); + logger.debug("Report proxy load info, proxy : {}, load: {}", proxyVmId, gsonLoadInfo); } catch (AgentControlChannelException e) { - s_logger.error("Unable to send out load info due to " + e.getMessage(), e); + logger.error("Unable to send out load info due to {}", e.getMessage(), e); } } public void ensureRoute(String address) { if (localGateway != null) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Ensure route for " + address + " via " + localGateway); + logger.debug("Ensure route for {} via {}", address, localGateway); // this method won't be called in high frequency, serialize access // to script execution @@ -452,7 +446,7 @@ public void ensureRoute(String address) { try { addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, address); } catch (Throwable e) { - s_logger.warn("Unexpected exception while adding internal route to " + address, e); + logger.warn("Unexpected exception while adding internal route to {}", address, e); } } } diff --git a/agent/src/test/java/com/cloud/agent/AgentShellTest.java b/agent/src/test/java/com/cloud/agent/AgentShellTest.java index f7151779f585..4126692546f2 100644 --- a/agent/src/test/java/com/cloud/agent/AgentShellTest.java +++ b/agent/src/test/java/com/cloud/agent/AgentShellTest.java @@ -350,4 +350,16 @@ public void setHostTestValueIsNullPropertyDoesNotStartAndEndWithAtSignSetHosts() Mockito.verify(agentShellSpy).setHosts(expected); } + + @Test + public void updateAndGetConnectedHost() { + String expected = "test"; + + AgentShell shell = new AgentShell(); + shell.setHosts("test"); + shell.getNextHost(); + shell.updateConnectedHost(); + + Assert.assertEquals(expected, shell.getConnectedHost()); + } } diff --git a/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/api/pom.xml b/api/pom.xml index 749d4b6e9888..32897725e0c1 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT diff --git a/api/src/main/java/com/cloud/agent/api/Command.java b/api/src/main/java/com/cloud/agent/api/Command.java index c873139099cc..eb979c0060b9 100644 --- a/api/src/main/java/com/cloud/agent/api/Command.java +++ b/api/src/main/java/com/cloud/agent/api/Command.java @@ -20,6 +20,8 @@ import java.util.Map; import com.cloud.agent.api.LogLevel.Log4jLevel; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; /** * implemented by classes that extends the Command class. Command specifies @@ -27,6 +29,8 @@ */ public abstract class Command { + protected transient Logger logger = LogManager.getLogger(getClass()); + public static enum OnError { Continue, Stop } diff --git a/api/src/main/java/com/cloud/agent/api/LogLevel.java b/api/src/main/java/com/cloud/agent/api/LogLevel.java index a8da272f39f4..136cb6d7228c 100644 --- a/api/src/main/java/com/cloud/agent/api/LogLevel.java +++ b/api/src/main/java/com/cloud/agent/api/LogLevel.java @@ -23,8 +23,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; /** */ @@ -41,7 +41,7 @@ private Log4jLevel(Level level) { } public boolean enabled(Logger logger) { - return _level != Level.OFF && logger.isEnabledFor(_level); + return _level != Level.OFF && logger.isEnabled(_level); } } diff --git a/api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java b/api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java index d4daf0e4270a..6396e3deb723 100644 --- a/api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java +++ b/api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java @@ -39,7 +39,8 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -63,7 +64,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class OVFHelper { - private static final Logger s_logger = Logger.getLogger(OVFHelper.class); + protected Logger logger = LogManager.getLogger(getClass()); private final OVFParser ovfParser; @@ -118,7 +119,7 @@ protected OVFPropertyTO createOVFPropertyFromNode(Node node, int index, String c boolean password = StringUtils.isNotBlank(passStr) && passStr.equalsIgnoreCase("true"); String label = ovfParser.getChildNodeValue(node, "Label"); String description = ovfParser.getChildNodeValue(node, "Description"); - s_logger.debug("Creating OVF property index " + index + (category == null ? "" : " for category " + category) + logger.debug("Creating OVF property index " + index + (category == null ? "" : " for category " + category) + " with key = " + key); return new OVFPropertyTO(key, type, value, qualifiers, userConfigurable, label, description, password, index, category); @@ -151,7 +152,7 @@ public List getConfigurableOVFPropertiesFromDocument(Document doc if (child.getNodeName().equalsIgnoreCase("Category") || child.getNodeName().endsWith(":Category")) { lastCategoryFound = child.getTextContent(); - s_logger.info("Category found " + lastCategoryFound); + logger.info("Category found " + lastCategoryFound); } else if (child.getNodeName().equalsIgnoreCase("Property") || child.getNodeName().endsWith(":Property")) { OVFPropertyTO prop = createOVFPropertyFromNode(child, propertyIndex, lastCategoryFound); @@ -249,13 +250,13 @@ private List matchHardwareItemsToDiskAndFilesInformation(List extractDisksFromOvfDocumentTree(Document doc) { od._controller = getControllerType(items, od._diskId); vd.add(od); } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("found %d disk definitions",vd.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("found %d disk definitions",vd.size())); } return vd; } @@ -365,8 +366,8 @@ protected List extractFilesFromOvfDocumentTree(File ovfFile, Document d vf.add(of); } } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("found %d file definitions in %s",vf.size(), ovfFile.getPath())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("found %d file definitions in %s",vf.size(), ovfFile.getPath())); } return vf; } @@ -461,7 +462,7 @@ public void rewriteOVFFileForSingleDisk(final String origOvfFilePath, final Stri Element disk = (Element)disks.item(i); String fileRef = ovfParser.getNodeAttribute(disk, "fileRef"); if (keepfile == null) { - s_logger.info("FATAL: OVA format error"); + logger.info("FATAL: OVA format error"); } else if (keepfile.equals(fileRef)) { keepdisk = ovfParser.getNodeAttribute(disk, "diskId"); } else { @@ -505,7 +506,7 @@ private void writeDocumentToFile(String newOvfFilePath, Document doc) { outfile.write(writer.toString()); outfile.close(); } catch (IOException | TransformerException e) { - s_logger.info("Unexpected exception caught while rewriting OVF:" + e.getMessage(), e); + logger.info("Unexpected exception caught while rewriting OVF:" + e.getMessage(), e); throw new CloudRuntimeException(e); } } @@ -521,8 +522,8 @@ OVFFile getFileDefinitionFromDiskDefinition(String fileRef, List files) public List getNetPrerequisitesFromDocument(Document doc) throws InternalErrorException { if (doc == null) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("no document to parse; returning no prerequisite networks"); + if (logger.isTraceEnabled()) { + logger.trace("no document to parse; returning no prerequisite networks"); } return Collections.emptyList(); } @@ -539,8 +540,8 @@ public List getNetPrerequisitesFromDocument(Document doc) throws I private void matchNicsToNets(Map nets, Node systemElement) { final DocumentTraversal traversal = (DocumentTraversal) systemElement; final NodeIterator iterator = traversal.createNodeIterator(systemElement, NodeFilter.SHOW_ELEMENT, null, true); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("starting out with %d network-prerequisites, parsing hardware",nets.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("starting out with %d network-prerequisites, parsing hardware",nets.size())); } int nicCount = 0; for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) { @@ -549,8 +550,8 @@ private void matchNicsToNets(Map nets, Node systemElement) nicCount++; String name = e.getTextContent(); // should be in our nets if(nets.get(name) == null) { - if(s_logger.isInfoEnabled()) { - s_logger.info(String.format("found a nic definition without a network definition byname %s, adding it to the list.", name)); + if(logger.isInfoEnabled()) { + logger.info(String.format("found a nic definition without a network definition byname %s, adding it to the list.", name)); } nets.put(name, new OVFNetworkTO()); } @@ -560,8 +561,8 @@ private void matchNicsToNets(Map nets, Node systemElement) } } } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("ending up with %d network-prerequisites, parsed %d nics", nets.size(), nicCount)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("ending up with %d network-prerequisites, parsed %d nics", nets.size(), nicCount)); } } @@ -584,7 +585,7 @@ private void fillNicPrerequisites(OVFNetworkTO nic, Node parentNode) { int addressOnParent = Integer.parseInt(addressOnParentStr); nic.setAddressOnParent(addressOnParent); } catch (NumberFormatException e) { - s_logger.warn("Encountered element of type \"AddressOnParent\", that could not be parse to an integer number: " + addressOnParentStr); + logger.warn("Encountered element of type \"AddressOnParent\", that could not be parse to an integer number: " + addressOnParentStr); } boolean automaticAllocation = StringUtils.isNotBlank(automaticAllocationStr) && Boolean.parseBoolean(automaticAllocationStr); @@ -596,7 +597,7 @@ private void fillNicPrerequisites(OVFNetworkTO nic, Node parentNode) { int instanceId = Integer.parseInt(instanceIdStr); nic.setInstanceID(instanceId); } catch (NumberFormatException e) { - s_logger.warn("Encountered element of type \"InstanceID\", that could not be parse to an integer number: " + instanceIdStr); + logger.warn("Encountered element of type \"InstanceID\", that could not be parse to an integer number: " + instanceIdStr); } nic.setResourceSubType(resourceSubType); @@ -608,7 +609,7 @@ private void checkForOnlyOneSystemNode(Document doc) throws InternalErrorExcepti NodeList systemElements = ovfParser.getElementsFromOVFDocument(doc, "VirtualSystem"); if (systemElements.getLength() != 1) { String msg = "found " + systemElements.getLength() + " system definitions in OVA, can only handle exactly one."; - s_logger.warn(msg); + logger.warn(msg); throw new InternalErrorException(msg); } } @@ -629,8 +630,8 @@ private Map getNetworksFromDocumentTree(Document doc) { nets.put(networkName,network); } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("found %d networks in template", nets.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("found %d networks in template", nets.size())); } return nets; } @@ -770,7 +771,7 @@ private Long getLongValueFromString(String value) { try { return Long.parseLong(value); } catch (NumberFormatException e) { - s_logger.debug("Could not parse the value: " + value + ", ignoring it"); + logger.debug("Could not parse the value: " + value + ", ignoring it"); } } return null; @@ -781,7 +782,7 @@ private Integer getIntValueFromString(String value) { try { return Integer.parseInt(value); } catch (NumberFormatException e) { - s_logger.debug("Could not parse the value: " + value + ", ignoring it"); + logger.debug("Could not parse the value: " + value + ", ignoring it"); } } return null; @@ -819,7 +820,7 @@ public List getEulaSectionsFromDocument(Document doc) { try { compressedLicense = compressOVFEula(eulaLicense); } catch (IOException e) { - s_logger.error("Could not compress the license for info " + eulaInfo); + logger.error("Could not compress the license for info " + eulaInfo); continue; } OVFEulaSectionTO eula = new OVFEulaSectionTO(eulaInfo, compressedLicense, eulaIndex); diff --git a/api/src/main/java/com/cloud/agent/api/storage/OVFParser.java b/api/src/main/java/com/cloud/agent/api/storage/OVFParser.java index b66fbe418d73..38f478d63cf8 100644 --- a/api/src/main/java/com/cloud/agent/api/storage/OVFParser.java +++ b/api/src/main/java/com/cloud/agent/api/storage/OVFParser.java @@ -27,7 +27,8 @@ import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -36,7 +37,7 @@ import org.xml.sax.SAXException; public class OVFParser { - private static final Logger s_logger = Logger.getLogger(OVFParser.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String DEFAULT_OVF_SCHEMA = "http://schemas.dmtf.org/ovf/envelope/1"; private static final String VMW_SCHEMA = "http://www.vmware.com/schema/ovf"; @@ -53,7 +54,7 @@ public OVFParser() { documentBuilderFactory.setNamespaceAware(true); documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { - s_logger.error("Cannot start the OVF parser: " + e.getMessage(), e); + logger.error("Cannot start the OVF parser: " + e.getMessage(), e); } } @@ -69,7 +70,7 @@ public Document parseOVFFile(String ovfFilePath) { try { return documentBuilder.parse(new File(ovfFilePath)); } catch (SAXException | IOException e) { - s_logger.error("Error parsing " + ovfFilePath + " " + e.getMessage(), e); + logger.error("Error parsing " + ovfFilePath + " " + e.getMessage(), e); return null; } } diff --git a/api/src/main/java/com/cloud/agent/api/to/BucketTO.java b/api/src/main/java/com/cloud/agent/api/to/BucketTO.java new file mode 100644 index 000000000000..f7e4bfea80fb --- /dev/null +++ b/api/src/main/java/com/cloud/agent/api/to/BucketTO.java @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.api.to; + +import org.apache.cloudstack.storage.object.Bucket; + +public final class BucketTO { + + private String name; + + private String accessKey; + + private String secretKey; + + public BucketTO(Bucket bucket) { + this.name = bucket.getName(); + this.accessKey = bucket.getAccessKey(); + this.secretKey = bucket.getSecretKey(); + } + + public BucketTO(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public String getAccessKey() { + return this.accessKey; + } + + public String getSecretKey() { + return this.secretKey; + } +} diff --git a/api/src/main/java/com/cloud/agent/api/to/FirewallRuleTO.java b/api/src/main/java/com/cloud/agent/api/to/FirewallRuleTO.java index d08884d1cbe0..25c75001a3c1 100644 --- a/api/src/main/java/com/cloud/agent/api/to/FirewallRuleTO.java +++ b/api/src/main/java/com/cloud/agent/api/to/FirewallRuleTO.java @@ -155,9 +155,7 @@ public FirewallRuleTO(FirewallRule rule, String srcVlanTag, String srcIp, Firewa rule.getIcmpType(), rule.getIcmpCode()); this.trafficType = trafficType; - if (FirewallRule.Purpose.Ipv6Firewall.equals(purpose)) { - this.destCidrList = rule.getDestinationCidrList(); - } + this.destCidrList = rule.getDestinationCidrList(); } public FirewallRuleTO(FirewallRule rule, String srcVlanTag, String srcIp, FirewallRule.Purpose purpose, FirewallRule.TrafficType trafficType, diff --git a/api/src/main/java/com/cloud/agent/api/to/NicTO.java b/api/src/main/java/com/cloud/agent/api/to/NicTO.java index 3a616170d7e0..573363c04fb1 100644 --- a/api/src/main/java/com/cloud/agent/api/to/NicTO.java +++ b/api/src/main/java/com/cloud/agent/api/to/NicTO.java @@ -32,6 +32,9 @@ public class NicTO extends NetworkTO { Map details; boolean dpdkEnabled; Integer mtu; + Long networkId; + + String networkSegmentName; public NicTO() { super(); @@ -127,4 +130,20 @@ public Integer getMtu() { public void setMtu(Integer mtu) { this.mtu = mtu; } + + public Long getNetworkId() { + return networkId; + } + + public void setNetworkId(Long networkId) { + this.networkId = networkId; + } + + public String getNetworkSegmentName() { + return networkSegmentName; + } + + public void setNetworkSegmentName(String networkSegmentName) { + this.networkSegmentName = networkSegmentName; + } } diff --git a/api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java b/api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java index db6cba775483..6f24b1cd6ca8 100644 --- a/api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java +++ b/api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java @@ -82,7 +82,10 @@ public class VirtualMachineTO { Map guestOsDetails = new HashMap(); Map extraConfig = new HashMap<>(); + Map networkIdToNetworkNameMap = new HashMap<>(); DeployAsIsInfoTO deployAsIsInfo; + String metadataManufacturer; + String metadataProductName; public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os, boolean enableHA, boolean limitCpuUse, String vncPassword) { @@ -392,6 +395,14 @@ public Map getExtraConfig() { return extraConfig; } + public Map getNetworkIdToNetworkNameMap() { + return networkIdToNetworkNameMap; + } + + public void setNetworkIdToNetworkNameMap(Map networkIdToNetworkNameMap) { + this.networkIdToNetworkNameMap = networkIdToNetworkNameMap; + } + public String getBootType() { return bootType; } @@ -420,6 +431,22 @@ public void setDeployAsIsInfo(DeployAsIsInfoTO deployAsIsInfo) { this.deployAsIsInfo = deployAsIsInfo; } + public String getMetadataManufacturer() { + return metadataManufacturer; + } + + public void setMetadataManufacturer(String metadataManufacturer) { + this.metadataManufacturer = metadataManufacturer; + } + + public String getMetadataProductName() { + return metadataProductName; + } + + public void setMetadataProductName(String metadataProductName) { + this.metadataProductName = metadataProductName; + } + @Override public String toString() { return String.format("VM {id: \"%s\", name: \"%s\", uuid: \"%s\", type: \"%s\"}", id, name, uuid, type); diff --git a/api/src/main/java/com/cloud/bgp/ASNumber.java b/api/src/main/java/com/cloud/bgp/ASNumber.java new file mode 100644 index 000000000000..b0e5394df75e --- /dev/null +++ b/api/src/main/java/com/cloud/bgp/ASNumber.java @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.bgp; + +import org.apache.cloudstack.acl.InfrastructureEntity; +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +import java.util.Date; + +public interface ASNumber extends InfrastructureEntity, InternalIdentity, Identity { + + Long getAccountId(); + Long getDomainId(); + long getAsNumber(); + long getAsNumberRangeId(); + long getDataCenterId(); + Date getAllocatedTime(); + boolean isAllocated(); + Long getNetworkId(); + Long getVpcId(); + Date getCreated(); + Date getRemoved(); +} diff --git a/api/src/main/java/com/cloud/bgp/ASNumberRange.java b/api/src/main/java/com/cloud/bgp/ASNumberRange.java new file mode 100644 index 000000000000..ae877ee60db7 --- /dev/null +++ b/api/src/main/java/com/cloud/bgp/ASNumberRange.java @@ -0,0 +1,31 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.bgp; + +import org.apache.cloudstack.acl.InfrastructureEntity; +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +import java.util.Date; + +public interface ASNumberRange extends InfrastructureEntity, InternalIdentity, Identity { + + long getStartASNumber(); + long getEndASNumber(); + long getDataCenterId(); + Date getCreated(); +} diff --git a/api/src/main/java/com/cloud/bgp/BGPService.java b/api/src/main/java/com/cloud/bgp/BGPService.java new file mode 100644 index 000000000000..935237092dd7 --- /dev/null +++ b/api/src/main/java/com/cloud/bgp/BGPService.java @@ -0,0 +1,39 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.bgp; + +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.vpc.Vpc; +import com.cloud.utils.Pair; +import org.apache.cloudstack.api.command.user.bgp.ListASNumbersCmd; + +import java.util.List; + +public interface BGPService { + + ASNumberRange createASNumberRange(long zoneId, long startASNumber, long endASNumber); + List listASNumberRanges(Long zoneId); + Pair, Integer> listASNumbers(ListASNumbersCmd cmd); + boolean allocateASNumber(long zoneId, Long asNumber, Long networkId, Long vpcId); + Pair releaseASNumber(long zoneId, long asNumber, boolean isReleaseNetworkDestroy); + boolean deleteASRange(long id); + + boolean applyBgpPeers(Network network, boolean continueOnError) throws ResourceUnavailableException; + + boolean applyBgpPeers(Vpc vpc, boolean continueOnError) throws ResourceUnavailableException; +} diff --git a/api/src/main/java/com/cloud/capacity/Capacity.java b/api/src/main/java/com/cloud/capacity/Capacity.java index 684490a605c3..a4e2c2a7f05d 100644 --- a/api/src/main/java/com/cloud/capacity/Capacity.java +++ b/api/src/main/java/com/cloud/capacity/Capacity.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.capacity; +import java.util.List; + import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.api.InternalIdentity; @@ -35,6 +37,11 @@ public interface Capacity extends InternalIdentity, Identity { public static final short CAPACITY_TYPE_CPU_CORE = 90; + public static final List STORAGE_CAPACITY_TYPES = List.of(CAPACITY_TYPE_STORAGE, + CAPACITY_TYPE_STORAGE_ALLOCATED, + CAPACITY_TYPE_SECONDARY_STORAGE, + CAPACITY_TYPE_LOCAL_STORAGE); + public Long getHostOrPoolId(); public Long getDataCenterId(); @@ -54,4 +61,6 @@ public interface Capacity extends InternalIdentity, Identity { public Float getUsedPercentage(); public Long getAllocatedCapacity(); + + public String getTag(); } diff --git a/api/src/main/java/com/cloud/configuration/Resource.java b/api/src/main/java/com/cloud/configuration/Resource.java index 32db2fcafeaf..bf8fca9d9051 100644 --- a/api/src/main/java/com/cloud/configuration/Resource.java +++ b/api/src/main/java/com/cloud/configuration/Resource.java @@ -85,5 +85,6 @@ public String getName() { long getOwnerId(); ResourceOwnerType getResourceOwnerType(); + String getTag(); } diff --git a/api/src/main/java/com/cloud/cpu/CPU.java b/api/src/main/java/com/cloud/cpu/CPU.java new file mode 100644 index 000000000000..4e1b9f5a5011 --- /dev/null +++ b/api/src/main/java/com/cloud/cpu/CPU.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.cpu; + +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.commons.lang3.StringUtils; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class CPU { + + public static final String archX86Identifier = "i686"; + public static final String archX86_64Identifier = "x86_64"; + public static final String archARM64Identifier = "aarch64"; + + public static class CPUArch { + private static final Map cpuArchMap = new LinkedHashMap<>(); + + public static final CPUArch archX86 = new CPUArch(archX86Identifier, 32); + public static final CPUArch amd64 = new CPUArch(archX86_64Identifier, 64); + public static final CPUArch arm64 = new CPUArch(archARM64Identifier, 64); + + private String type; + private int bits; + + public CPUArch(String type, int bits) { + this.type = type; + this.bits = bits; + cpuArchMap.put(type, this); + } + + public String getType() { + return this.type; + } + + public int getBits() { + return this.bits; + } + + public static CPUArch fromType(String type) { + if (StringUtils.isBlank(type)) { + return amd64; + } + switch (type) { + case archX86Identifier: return archX86; + case archX86_64Identifier: return amd64; + case archARM64Identifier: return arm64; + default: throw new CloudRuntimeException(String.format("Unsupported arch type: %s", type)); + } + } + } +} diff --git a/api/src/main/java/com/cloud/dc/DedicatedResources.java b/api/src/main/java/com/cloud/dc/DedicatedResources.java index 63188ca0b0e9..23e6cc88a1e0 100644 --- a/api/src/main/java/com/cloud/dc/DedicatedResources.java +++ b/api/src/main/java/com/cloud/dc/DedicatedResources.java @@ -21,6 +21,10 @@ import org.apache.cloudstack.api.InternalIdentity; public interface DedicatedResources extends InfrastructureEntity, InternalIdentity, Identity { + enum Type { + Zone, Pod, Cluster, Host + } + @Override long getId(); diff --git a/api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java b/api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java index a668b79187dc..2697311d2b94 100644 --- a/api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java +++ b/api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java @@ -57,6 +57,17 @@ public interface DeploymentClusterPlanner extends DeploymentPlanner { false, ConfigKey.Scope.Global); + static final ConfigKey VmAllocationAlgorithm = new ConfigKey<>( + String.class, + "vm.allocation.algorithm", + "Advanced", + "random", + "Order in which hosts within a cluster will be considered for VM/volume allocation. The value can be 'random', 'firstfit', 'userdispersing', 'userconcentratedpod_random', 'userconcentratedpod_firstfit', or 'firstfitleastconsumed'.", + true, + ConfigKey.Scope.Global, null, null, null, null, null, + ConfigKey.Kind.Select, + "random,firstfit,userdispersing,userconcentratedpod_random,userconcentratedpod_firstfit,firstfitleastconsumed"); + /** * This is called to determine list of possible clusters where a virtual * machine can be deployed. diff --git a/api/src/main/java/com/cloud/deploy/DeploymentPlanner.java b/api/src/main/java/com/cloud/deploy/DeploymentPlanner.java index e9f706ac1cee..354f9cfaac53 100644 --- a/api/src/main/java/com/cloud/deploy/DeploymentPlanner.java +++ b/api/src/main/java/com/cloud/deploy/DeploymentPlanner.java @@ -21,8 +21,12 @@ import java.util.HashSet; import java.util.Set; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + import com.cloud.dc.DataCenter; import com.cloud.dc.Pod; +import com.cloud.exception.CloudException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.ResourceUnavailableException; @@ -75,7 +79,7 @@ public enum PlannerResourceUsage { public static class ExcludeList implements Serializable { private static final long serialVersionUID = -482175549460148301L; - + protected static Logger LOGGER = LogManager.getLogger(ExcludeList.class); private Set _dcIds; private Set _podIds; private Set _clusterIds; @@ -104,13 +108,26 @@ public ExcludeList(Set dcIds, Set podIds, Set clusterIds, Set< } } + private void logAvoid(Class scope, CloudException e) { + Long id = null; + if (e instanceof InsufficientCapacityException) { + id = ((InsufficientCapacityException) e).getId(); + } else if (e instanceof ResourceUnavailableException) { + id = ((ResourceUnavailableException) e).getResourceId(); + } else { + LOGGER.debug("Failed to log avoided component due to unexpected exception type [{}].", e.getMessage()); + return; + } + LOGGER.debug("Adding {} [{}] to the avoid set due to [{}].", scope.getSimpleName(), id, e.getMessage()); + } + public boolean add(InsufficientCapacityException e) { Class scope = e.getScope(); if (scope == null) { return false; } - + logAvoid(scope, e); if (Host.class.isAssignableFrom(scope)) { addHost(e.getId()); } else if (Pod.class.isAssignableFrom(scope)) { @@ -128,13 +145,14 @@ public boolean add(InsufficientCapacityException e) { return true; } + public boolean add(ResourceUnavailableException e) { Class scope = e.getScope(); if (scope == null) { return false; } - + logAvoid(scope, e); if (Host.class.isAssignableFrom(scope)) { addHost(e.getResourceId()); } else if (Pod.class.isAssignableFrom(scope)) { diff --git a/api/src/main/java/com/cloud/event/EventTypes.java b/api/src/main/java/com/cloud/event/EventTypes.java index 496d9f5b6891..5e5309965c1e 100644 --- a/api/src/main/java/com/cloud/event/EventTypes.java +++ b/api/src/main/java/com/cloud/event/EventTypes.java @@ -28,8 +28,12 @@ import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.config.Configuration; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; import org.apache.cloudstack.ha.HAConfig; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; import org.apache.cloudstack.quota.QuotaTariff; +import org.apache.cloudstack.storage.sharedfs.SharedFS; import org.apache.cloudstack.storage.object.Bucket; import org.apache.cloudstack.storage.object.ObjectStore; import org.apache.cloudstack.usage.Usage; @@ -242,6 +246,8 @@ public class EventTypes { public static final String EVENT_ROLE_UPDATE = "ROLE.UPDATE"; public static final String EVENT_ROLE_DELETE = "ROLE.DELETE"; public static final String EVENT_ROLE_IMPORT = "ROLE.IMPORT"; + public static final String EVENT_ROLE_ENABLE = "ROLE.ENABLE"; + public static final String EVENT_ROLE_DISABLE = "ROLE.DISABLE"; public static final String EVENT_ROLE_PERMISSION_CREATE = "ROLE.PERMISSION.CREATE"; public static final String EVENT_ROLE_PERMISSION_UPDATE = "ROLE.PERMISSION.UPDATE"; public static final String EVENT_ROLE_PERMISSION_DELETE = "ROLE.PERMISSION.DELETE"; @@ -333,6 +339,7 @@ public class EventTypes { public static final String EVENT_SNAPSHOT_OFF_PRIMARY = "SNAPSHOT.OFF_PRIMARY"; public static final String EVENT_SNAPSHOT_DELETE = "SNAPSHOT.DELETE"; public static final String EVENT_SNAPSHOT_REVERT = "SNAPSHOT.REVERT"; + public static final String EVENT_SNAPSHOT_EXTRACT = "SNAPSHOT.EXTRACT"; public static final String EVENT_SNAPSHOT_POLICY_CREATE = "SNAPSHOTPOLICY.CREATE"; public static final String EVENT_SNAPSHOT_POLICY_UPDATE = "SNAPSHOTPOLICY.UPDATE"; public static final String EVENT_SNAPSHOT_POLICY_DELETE = "SNAPSHOTPOLICY.DELETE"; @@ -390,6 +397,11 @@ public class EventTypes { public static final String EVENT_VLAN_IP_RANGE_RELEASE = "VLAN.IP.RANGE.RELEASE"; public static final String EVENT_VLAN_IP_RANGE_UPDATE = "VLAN.IP.RANGE.UPDATE"; + // AS Number + public static final String EVENT_AS_RANGE_CREATE = "AS.RANGE.CREATE"; + public static final String EVENT_AS_RANGE_DELETE = "AS.RANGE.DELETE"; + public static final String EVENT_AS_NUMBER_RELEASE = "AS.NUMBER.RELEASE"; + public static final String EVENT_MANAGEMENT_IP_RANGE_CREATE = "MANAGEMENT.IP.RANGE.CREATE"; public static final String EVENT_MANAGEMENT_IP_RANGE_DELETE = "MANAGEMENT.IP.RANGE.DELETE"; public static final String EVENT_MANAGEMENT_IP_RANGE_UPDATE = "MANAGEMENT.IP.RANGE.UPDATE"; @@ -448,6 +460,7 @@ public class EventTypes { public static final String EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE = "MAINT.PREPARE.PS"; // Primary storage pool + public static final String EVENT_UPDATE_PRIMARY_STORAGE = "UPDATE.PS"; public static final String EVENT_ENABLE_PRIMARY_STORAGE = "ENABLE.PS"; public static final String EVENT_DISABLE_PRIMARY_STORAGE = "DISABLE.PS"; public static final String EVENT_SYNC_STORAGE_POOL = "SYNC.STORAGE.POOL"; @@ -722,6 +735,8 @@ public class EventTypes { // SystemVM public static final String EVENT_LIVE_PATCH_SYSTEMVM = "LIVE.PATCH.SYSTEM.VM"; + //Purge resources + public static final String EVENT_PURGE_EXPUNGED_RESOURCES = "PURGE.EXPUNGED.RESOURCES"; // OBJECT STORE public static final String EVENT_OBJECT_STORE_CREATE = "OBJECT.STORE.CREATE"; @@ -738,6 +753,37 @@ public class EventTypes { public static final String EVENT_QUOTA_TARIFF_DELETE = "QUOTA.TARIFF.DELETE"; public static final String EVENT_QUOTA_TARIFF_UPDATE = "QUOTA.TARIFF.UPDATE"; + // Routing + public static final String EVENT_ZONE_IP4_SUBNET_CREATE = "ZONE.IP4.SUBNET.CREATE"; + public static final String EVENT_ZONE_IP4_SUBNET_UPDATE = "ZONE.IP4.SUBNET.UPDATE"; + public static final String EVENT_ZONE_IP4_SUBNET_DELETE = "ZONE.IP4.SUBNET.DELETE"; + public static final String EVENT_ZONE_IP4_SUBNET_DEDICATE = "ZONE.IP4.SUBNET.DEDICATE"; + public static final String EVENT_ZONE_IP4_SUBNET_RELEASE = "ZONE.IP4.SUBNET.RELEASE"; + public static final String EVENT_IP4_GUEST_SUBNET_CREATE = "IP4.GUEST.SUBNET.CREATE"; + public static final String EVENT_IP4_GUEST_SUBNET_DELETE = "IP4.GUEST.SUBNET.DELETE"; + public static final String EVENT_ROUTING_IPV4_FIREWALL_RULE_CREATE = "ROUTING.IPV4.FIREWALL.RULE.CREATE"; + public static final String EVENT_ROUTING_IPV4_FIREWALL_RULE_UPDATE = "ROUTING.IPV4.FIREWALL.RULE.UPDATE"; + public static final String EVENT_ROUTING_IPV4_FIREWALL_RULE_DELETE = "ROUTING.IPV4.FIREWALL.RULE.DELETE"; + public static final String EVENT_BGP_PEER_CREATE = "BGP.PEER.CREATE"; + public static final String EVENT_BGP_PEER_UPDATE = "BGP.PEER.UPDATE"; + public static final String EVENT_BGP_PEER_DELETE = "BGP.PEER.DELETE"; + public static final String EVENT_BGP_PEER_DEDICATE = "BGP.PEER.DEDICATE"; + public static final String EVENT_BGP_PEER_RELEASE = "BGP.PEER.RELEASE"; + public static final String EVENT_NETWORK_BGP_PEER_UPDATE = "NETWORK.BGP.PEER.UPDATE"; + public static final String EVENT_VPC_BGP_PEER_UPDATE = "VPC.BGP.PEER.UPDATE"; + + // SharedFS + public static final String EVENT_SHAREDFS_CREATE = "SHAREDFS.CREATE"; + public static final String EVENT_SHAREDFS_START = "SHAREDFS.START"; + public static final String EVENT_SHAREDFS_UPDATE = "SHAREDFS.UPDATE"; + public static final String EVENT_SHAREDFS_CHANGE_SERVICE_OFFERING = "SHAREDFS.CHANGE.SERVICE.OFFERING"; + public static final String EVENT_SHAREDFS_CHANGE_DISK_OFFERING = "SHAREDFS.CHANGE.DISK.OFFERING"; + public static final String EVENT_SHAREDFS_STOP = "SHAREDFS.STOP"; + public static final String EVENT_SHAREDFS_RESTART = "SHAREDFS.RESTART"; + public static final String EVENT_SHAREDFS_DESTROY = "SHAREDFS.DESTROY"; + public static final String EVENT_SHAREDFS_EXPUNGE = "SHAREDFS.EXPUNGE"; + public static final String EVENT_SHAREDFS_RECOVER = "SHAREDFS.RECOVER"; + static { // TODO: need a way to force author adding event types to declare the entity details as well, with out braking @@ -839,6 +885,8 @@ public class EventTypes { entityEventDetails.put(EVENT_ROLE_UPDATE, Role.class); entityEventDetails.put(EVENT_ROLE_DELETE, Role.class); entityEventDetails.put(EVENT_ROLE_IMPORT, Role.class); + entityEventDetails.put(EVENT_ROLE_ENABLE, Role.class); + entityEventDetails.put(EVENT_ROLE_DISABLE, Role.class); entityEventDetails.put(EVENT_ROLE_PERMISSION_CREATE, RolePermission.class); entityEventDetails.put(EVENT_ROLE_PERMISSION_UPDATE, RolePermission.class); entityEventDetails.put(EVENT_ROLE_PERMISSION_DELETE, RolePermission.class); @@ -895,6 +943,7 @@ public class EventTypes { // Snapshots entityEventDetails.put(EVENT_SNAPSHOT_CREATE, Snapshot.class); entityEventDetails.put(EVENT_SNAPSHOT_DELETE, Snapshot.class); + entityEventDetails.put(EVENT_SNAPSHOT_EXTRACT, Snapshot.class); entityEventDetails.put(EVENT_SNAPSHOT_ON_PRIMARY, Snapshot.class); entityEventDetails.put(EVENT_SNAPSHOT_OFF_PRIMARY, Snapshot.class); entityEventDetails.put(EVENT_SNAPSHOT_POLICY_CREATE, SnapshotPolicy.class); @@ -999,6 +1048,7 @@ public class EventTypes { entityEventDetails.put(EVENT_MAINTENANCE_PREPARE_PRIMARY_STORAGE, Host.class); // Primary storage pool + entityEventDetails.put(EVENT_UPDATE_PRIMARY_STORAGE, StoragePool.class); entityEventDetails.put(EVENT_ENABLE_PRIMARY_STORAGE, StoragePool.class); entityEventDetails.put(EVENT_DISABLE_PRIMARY_STORAGE, StoragePool.class); entityEventDetails.put(EVENT_CHANGE_STORAGE_POOL_SCOPE, StoragePool.class); @@ -1193,6 +1243,35 @@ public class EventTypes { entityEventDetails.put(EVENT_QUOTA_TARIFF_CREATE, QuotaTariff.class); entityEventDetails.put(EVENT_QUOTA_TARIFF_DELETE, QuotaTariff.class); entityEventDetails.put(EVENT_QUOTA_TARIFF_UPDATE, QuotaTariff.class); + + // Routing + entityEventDetails.put(EVENT_ZONE_IP4_SUBNET_CREATE, DataCenterIpv4GuestSubnet.class); + entityEventDetails.put(EVENT_ZONE_IP4_SUBNET_UPDATE, DataCenterIpv4GuestSubnet.class); + entityEventDetails.put(EVENT_ZONE_IP4_SUBNET_DELETE, DataCenterIpv4GuestSubnet.class); + entityEventDetails.put(EVENT_ZONE_IP4_SUBNET_DEDICATE, DataCenterIpv4GuestSubnet.class); + entityEventDetails.put(EVENT_ZONE_IP4_SUBNET_RELEASE, DataCenterIpv4GuestSubnet.class); + entityEventDetails.put(EVENT_IP4_GUEST_SUBNET_CREATE, Ipv4GuestSubnetNetworkMap.class); + entityEventDetails.put(EVENT_IP4_GUEST_SUBNET_DELETE, Ipv4GuestSubnetNetworkMap.class); + entityEventDetails.put(EVENT_ROUTING_IPV4_FIREWALL_RULE_CREATE, FirewallRule.class); + entityEventDetails.put(EVENT_ROUTING_IPV4_FIREWALL_RULE_UPDATE, FirewallRule.class); + entityEventDetails.put(EVENT_ROUTING_IPV4_FIREWALL_RULE_DELETE, FirewallRule.class); + entityEventDetails.put(EVENT_BGP_PEER_CREATE, BgpPeer.class); + entityEventDetails.put(EVENT_BGP_PEER_UPDATE, BgpPeer.class); + entityEventDetails.put(EVENT_BGP_PEER_DELETE, BgpPeer.class); + entityEventDetails.put(EVENT_BGP_PEER_DEDICATE, BgpPeer.class); + entityEventDetails.put(EVENT_BGP_PEER_RELEASE, BgpPeer.class); + + // SharedFS + entityEventDetails.put(EVENT_SHAREDFS_CREATE, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_START, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_STOP, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_UPDATE, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_CHANGE_SERVICE_OFFERING, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_CHANGE_DISK_OFFERING, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_RESTART, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_DESTROY, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class); + entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class); } public static boolean isNetworkEvent(String eventType) { diff --git a/api/src/main/java/com/cloud/host/Host.java b/api/src/main/java/com/cloud/host/Host.java index 4a3b914364f8..56b4ed75a311 100644 --- a/api/src/main/java/com/cloud/host/Host.java +++ b/api/src/main/java/com/cloud/host/Host.java @@ -16,6 +16,7 @@ // under the License. package com.cloud.host; +import com.cloud.cpu.CPU; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.resource.ResourceState; import com.cloud.utils.fsm.StateObject; @@ -208,4 +209,6 @@ public static String[] toStrings(Host.Type... types) { boolean isDisabled(); ResourceState getResourceState(); + + CPU.CPUArch getArch(); } diff --git a/api/src/main/java/com/cloud/hypervisor/Hypervisor.java b/api/src/main/java/com/cloud/hypervisor/Hypervisor.java index 2f0cc736af3d..e1108b34a837 100644 --- a/api/src/main/java/com/cloud/hypervisor/Hypervisor.java +++ b/api/src/main/java/com/cloud/hypervisor/Hypervisor.java @@ -17,55 +17,45 @@ package com.cloud.hypervisor; import com.cloud.storage.Storage.ImageFormat; +import org.apache.commons.lang3.StringUtils; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; +import java.util.Objects; public class Hypervisor { + public static class HypervisorType { + private static final Map hypervisorTypeMap = new LinkedHashMap<>(); + public static final HypervisorType None = new HypervisorType("None"); //for storage hosts + public static final HypervisorType XenServer = new HypervisorType("XenServer", ImageFormat.VHD); + public static final HypervisorType KVM = new HypervisorType("KVM", ImageFormat.QCOW2); + public static final HypervisorType VMware = new HypervisorType("VMware", ImageFormat.OVA); + public static final HypervisorType Hyperv = new HypervisorType("Hyperv"); + public static final HypervisorType VirtualBox = new HypervisorType("VirtualBox"); + public static final HypervisorType Parralels = new HypervisorType("Parralels"); + public static final HypervisorType BareMetal = new HypervisorType("BareMetal"); + public static final HypervisorType Simulator = new HypervisorType("Simulator"); + public static final HypervisorType Ovm = new HypervisorType("Ovm", ImageFormat.RAW); + public static final HypervisorType Ovm3 = new HypervisorType("Ovm3", ImageFormat.RAW); + public static final HypervisorType LXC = new HypervisorType("LXC"); + public static final HypervisorType Custom = new HypervisorType("Custom"); + public static final HypervisorType Any = new HypervisorType("Any"); /*If you don't care about the hypervisor type*/ + private final String name; + private final ImageFormat imageFormat; - static Map hypervisorTypeMap; - static Map supportedImageFormatMap; - - public enum HypervisorType { - None, //for storage hosts - XenServer, - KVM, - VMware, - Hyperv, - VirtualBox, - Parralels, - BareMetal, - Simulator, - Ovm, - Ovm3, - LXC, - Custom, - - Any; /*If you don't care about the hypervisor type*/ - - static { - hypervisorTypeMap = new HashMap<>(); - hypervisorTypeMap.put("xenserver", HypervisorType.XenServer); - hypervisorTypeMap.put("kvm", HypervisorType.KVM); - hypervisorTypeMap.put("vmware", HypervisorType.VMware); - hypervisorTypeMap.put("hyperv", HypervisorType.Hyperv); - hypervisorTypeMap.put("virtualbox", HypervisorType.VirtualBox); - hypervisorTypeMap.put("parallels", HypervisorType.Parralels); - hypervisorTypeMap.put("baremetal", HypervisorType.BareMetal); - hypervisorTypeMap.put("simulator", HypervisorType.Simulator); - hypervisorTypeMap.put("ovm", HypervisorType.Ovm); - hypervisorTypeMap.put("lxc", HypervisorType.LXC); - hypervisorTypeMap.put("any", HypervisorType.Any); - hypervisorTypeMap.put("ovm3", HypervisorType.Ovm3); - hypervisorTypeMap.put("custom", HypervisorType.Custom); - - supportedImageFormatMap = new HashMap<>(); - supportedImageFormatMap.put(HypervisorType.XenServer, ImageFormat.VHD); - supportedImageFormatMap.put(HypervisorType.KVM, ImageFormat.QCOW2); - supportedImageFormatMap.put(HypervisorType.VMware, ImageFormat.OVA); - supportedImageFormatMap.put(HypervisorType.Ovm, ImageFormat.RAW); - supportedImageFormatMap.put(HypervisorType.Ovm3, ImageFormat.RAW); + public HypervisorType(String name) { + this(name, null); + } + + public HypervisorType(String name, ImageFormat imageFormat) { + this.name = name; + this.imageFormat = imageFormat; + if (name.equals("Parralels")){ // typo in the original code + hypervisorTypeMap.put("parallels", this); + } else { + hypervisorTypeMap.putIfAbsent(name.toLowerCase(Locale.ROOT), this); + } } public static HypervisorType getType(String hypervisor) { @@ -75,24 +65,62 @@ public static HypervisorType getType(String hypervisor) { hypervisorTypeMap.getOrDefault(hypervisor.toLowerCase(Locale.ROOT), HypervisorType.None)); } + public static HypervisorType[] values() { + return hypervisorTypeMap.values().toArray(HypervisorType[]::new).clone(); + } + + public static HypervisorType valueOf(String name) { + if (StringUtils.isBlank(name)) { + return null; + } + + HypervisorType hypervisorType = hypervisorTypeMap.get(name.toLowerCase(Locale.ROOT)); + if (hypervisorType == null) { + throw new IllegalArgumentException("HypervisorType '" + name + "' not found"); + } + return hypervisorType; + } + /** * Returns the display name of a hypervisor type in case the custom hypervisor is used, * using the 'hypervisor.custom.display.name' setting. Otherwise, returns hypervisor name */ public String getHypervisorDisplayName() { - return !Hypervisor.HypervisorType.Custom.equals(this) ? - this.toString() : - HypervisorGuru.HypervisorCustomDisplayName.value(); + return HypervisorType.Custom.equals(this) ? HypervisorGuru.HypervisorCustomDisplayName.value() : name; } /** * This method really needs to be part of the properties of the hypervisor type itself. * - * @param hyperType * @return */ - public static ImageFormat getSupportedImageFormat(HypervisorType hyperType) { - return supportedImageFormatMap.getOrDefault(hyperType, null); + public ImageFormat getSupportedImageFormat() { + return imageFormat; + } + + public String name() { + return name; + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } else if (o == null || getClass() != o.getClass()) { + return false; + } + HypervisorType that = (HypervisorType) o; + return Objects.equals(name, that.name); + } + + @Override + public String toString() { + return name; } } diff --git a/api/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelper.java b/api/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelper.java index a39c26680fdb..a13c1b3a6a89 100644 --- a/api/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelper.java +++ b/api/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelper.java @@ -24,5 +24,6 @@ public interface KubernetesServiceHelper extends Adapter { ControlledEntity findByUuid(String uuid); + ControlledEntity findByVmId(long vmId); void checkVmCanBeDestroyed(UserVm userVm); } diff --git a/api/src/main/java/com/cloud/network/IpAddress.java b/api/src/main/java/com/cloud/network/IpAddress.java index cf2e2f82db9f..ae1af4505773 100644 --- a/api/src/main/java/com/cloud/network/IpAddress.java +++ b/api/src/main/java/com/cloud/network/IpAddress.java @@ -97,4 +97,6 @@ enum Purpose { void setRuleState(State ruleState); + boolean isForSystemVms(); + } diff --git a/api/src/main/java/com/cloud/network/Network.java b/api/src/main/java/com/cloud/network/Network.java index 458169c80aa3..d3bc5005cb7a 100644 --- a/api/src/main/java/com/cloud/network/Network.java +++ b/api/src/main/java/com/cloud/network/Network.java @@ -103,7 +103,7 @@ class Service { public static final Service Vpn = new Service("Vpn", Capability.SupportedVpnProtocols, Capability.VpnTypes); public static final Service Dhcp = new Service("Dhcp", Capability.ExtraDhcpOptions); public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification); - public static final Service Gateway = new Service("Gateway"); + public static final Service Gateway = new Service("Gateway", Capability.RedundantRouter); public static final Service Firewall = new Service("Firewall", Capability.SupportedProtocols, Capability.MultipleIps, Capability.TrafficStatistics, Capability.SupportedTrafficDirection, Capability.SupportedEgressProtocols); public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedLBIsolation, Capability.SupportedProtocols, @@ -205,6 +205,8 @@ public static class Provider { //Add Tungsten Fabric provider public static final Provider Tungsten = new Provider("Tungsten", false); + public static final Provider Nsx = new Provider("Nsx", false); + private final String name; private final boolean isExternal; @@ -410,12 +412,16 @@ public void setIp6Address(String ip6Address) { String getGateway(); + void setGateway(String gateway); + // "cidr" is the Cloudstack managed address space, all CloudStack managed vms get IP address from "cidr", // In general "cidr" also serves as the network CIDR // But in case IP reservation is configured for a Guest network, "networkcidr" is the Effective network CIDR for that network, // "cidr" will still continue to be the effective address space for CloudStack managed vms in that Guest network String getCidr(); + void setCidr(String cidr); + // "networkcidr" is the network CIDR of the guest network which uses IP reservation. // It is the summation of "cidr" and the reservedIPrange(the address space used for non CloudStack purposes). // For networks not configured with IP reservation, "networkcidr" is always null @@ -427,6 +433,8 @@ public void setIp6Address(String ip6Address) { long getDataCenterId(); + long getAccountId(); + long getNetworkOfferingId(); @Override @@ -499,4 +507,6 @@ public void setIp6Address(String ip6Address) { Integer getPublicMtu(); Integer getPrivateMtu(); + + Integer getNetworkCidrSize(); } diff --git a/api/src/main/java/com/cloud/network/NetworkModel.java b/api/src/main/java/com/cloud/network/NetworkModel.java index ed3506c0da16..a4cd87af0080 100644 --- a/api/src/main/java/com/cloud/network/NetworkModel.java +++ b/api/src/main/java/com/cloud/network/NetworkModel.java @@ -173,6 +173,8 @@ public interface NetworkModel { boolean isProviderSupportServiceInNetwork(long networkId, Service service, Provider provider); + boolean isAnyServiceSupportedInNetwork(long networkId, Provider provider, Service... services); + boolean isProviderEnabledInPhysicalNetwork(long physicalNetowrkId, String providerName); String getNetworkTag(HypervisorType hType, Network network); @@ -356,4 +358,8 @@ List generateVmData(String userData, String userDataDetails, String se void verifyIp6DnsPair(final String ip6Dns1, final String ip6Dns2); + boolean isSecurityGroupSupportedForZone(Long zoneId); + + boolean checkSecurityGroupSupportForNetwork(Account account, DataCenter zone, List networkIds, + List securityGroupsIds); } diff --git a/api/src/main/java/com/cloud/network/NetworkProfile.java b/api/src/main/java/com/cloud/network/NetworkProfile.java index 448530695750..83dc247cc9ee 100644 --- a/api/src/main/java/com/cloud/network/NetworkProfile.java +++ b/api/src/main/java/com/cloud/network/NetworkProfile.java @@ -22,10 +22,8 @@ import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; -import org.apache.log4j.Logger; public class NetworkProfile implements Network { - static final Logger s_logger = Logger.getLogger(NetworkProfile.class); private final long id; private final String uuid; private final long dataCenterId; @@ -43,8 +41,8 @@ public class NetworkProfile implements Network { private final Mode mode; private final BroadcastDomainType broadcastDomainType; private TrafficType trafficType; - private final String gateway; - private final String cidr; + private String gateway; + private String cidr; private final String networkCidr; private final String ip6Gateway; private final String ip6Cidr; @@ -64,6 +62,7 @@ public class NetworkProfile implements Network { private final String guruName; private boolean strechedL2Subnet; private String externalId; + private Integer networkCidrSize; public NetworkProfile(Network network) { id = network.getId(); @@ -100,6 +99,7 @@ public NetworkProfile(Network network) { isRedundant = network.isRedundant(); isRollingRestart = network.isRollingRestart(); externalId = network.getExternalId(); + networkCidrSize = network.getNetworkCidrSize(); } @Override @@ -212,11 +212,21 @@ public String getGateway() { return gateway; } + @Override + public void setGateway(String gateway) { + this.gateway = gateway; + } + @Override public String getCidr() { return cidr; } + @Override + public void setCidr(String cidr) { + this.cidr = cidr; + } + @Override public String getNetworkCidr() { return networkCidr; @@ -369,4 +379,9 @@ public Integer getPrivateMtu() { return null; } + @Override + public Integer getNetworkCidrSize() { + return networkCidrSize; + } + } diff --git a/api/src/main/java/com/cloud/network/NetworkService.java b/api/src/main/java/com/cloud/network/NetworkService.java index c562a54a048a..b8dd464b3655 100644 --- a/api/src/main/java/com/cloud/network/NetworkService.java +++ b/api/src/main/java/com/cloud/network/NetworkService.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Map; +import com.cloud.dc.DataCenter; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.api.command.admin.address.ReleasePodIpCmdByAdmin; import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd; @@ -56,6 +57,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.Nic; import com.cloud.vm.NicSecondaryIp; +import org.apache.cloudstack.network.element.InternalLoadBalancerElementService; /** * The NetworkService interface is the "public" api to entities that make requests to the orchestration engine @@ -88,6 +90,8 @@ IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId, Boolean displ IpAddress reserveIpAddress(Account account, Boolean displayIp, Long ipAddressId) throws ResourceAllocationException; + IpAddress reserveIpAddressWithVlanDetail(Account account, DataCenter zone, Boolean displayIp, String vlanDetailKey) throws ResourceAllocationException; + boolean releaseReservedIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; boolean releaseIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; @@ -259,4 +263,9 @@ Network createPrivateNetwork(String networkName, String displayText, long physic PublicIpQuarantine updatePublicIpAddressInQuarantine(UpdateQuarantinedIpCmd cmd); void removePublicIpAddressFromQuarantine(RemoveQuarantinedIpCmd cmd); + + InternalLoadBalancerElementService getInternalLoadBalancerElementByType(VirtualRouterProvider.Type type); + InternalLoadBalancerElementService getInternalLoadBalancerElementByNetworkServiceProviderId(long networkProviderId); + InternalLoadBalancerElementService getInternalLoadBalancerElementById(long providerId); + List getInternalLoadBalancerElements(); } diff --git a/api/src/main/java/com/cloud/network/Networks.java b/api/src/main/java/com/cloud/network/Networks.java index aeed5d4aec6a..dfa0ddb84cae 100644 --- a/api/src/main/java/com/cloud/network/Networks.java +++ b/api/src/main/java/com/cloud/network/Networks.java @@ -128,7 +128,8 @@ public URI toUri(T value) { }, UnDecided(null, null), OpenDaylight("opendaylight", String.class), - TUNGSTEN("tf", String.class); + TUNGSTEN("tf", String.class), + NSX("nsx", String.class); private final String scheme; private final Class type; diff --git a/api/src/main/java/com/cloud/network/VirtualRouterProvider.java b/api/src/main/java/com/cloud/network/VirtualRouterProvider.java index aca526b1832b..98410ca09f88 100644 --- a/api/src/main/java/com/cloud/network/VirtualRouterProvider.java +++ b/api/src/main/java/com/cloud/network/VirtualRouterProvider.java @@ -21,7 +21,7 @@ public interface VirtualRouterProvider extends InternalIdentity, Identity { public enum Type { - VirtualRouter, ElasticLoadBalancerVm, VPCVirtualRouter, InternalLbVm, NetScalerVm + VirtualRouter, ElasticLoadBalancerVm, VPCVirtualRouter, InternalLbVm, NetScalerVm, Nsx } public Type getType(); diff --git a/api/src/main/java/com/cloud/network/element/BgpServiceProvider.java b/api/src/main/java/com/cloud/network/element/BgpServiceProvider.java new file mode 100644 index 000000000000..ee919cb1af7d --- /dev/null +++ b/api/src/main/java/com/cloud/network/element/BgpServiceProvider.java @@ -0,0 +1,31 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.element; + +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.vpc.Vpc; + +import org.apache.cloudstack.network.BgpPeer; + +import java.util.List; + +public interface BgpServiceProvider extends NetworkElement { + + boolean applyBgpPeers(Vpc vpc, Network network, List bgpPeers) throws ResourceUnavailableException; + +} diff --git a/api/src/main/java/com/cloud/network/element/LoadBalancingServiceProvider.java b/api/src/main/java/com/cloud/network/element/LoadBalancingServiceProvider.java index 1bb37be970d3..dc0f60f45196 100644 --- a/api/src/main/java/com/cloud/network/element/LoadBalancingServiceProvider.java +++ b/api/src/main/java/com/cloud/network/element/LoadBalancingServiceProvider.java @@ -48,4 +48,7 @@ public interface LoadBalancingServiceProvider extends NetworkElement, IpDeployin List updateHealthChecks(Network network, List lbrules); boolean handlesOnlyRulesInTransitionState(); + + default void expungeLbVmRefs(List vmIds, Long batchSize) { + } } diff --git a/api/src/main/java/com/cloud/network/element/NetworkACLServiceProvider.java b/api/src/main/java/com/cloud/network/element/NetworkACLServiceProvider.java index 8c3243c99f4b..852a650cfcde 100644 --- a/api/src/main/java/com/cloud/network/element/NetworkACLServiceProvider.java +++ b/api/src/main/java/com/cloud/network/element/NetworkACLServiceProvider.java @@ -21,6 +21,7 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; import com.cloud.network.vpc.NetworkACLItem; +import com.cloud.network.vpc.Vpc; public interface NetworkACLServiceProvider extends NetworkElement { @@ -32,4 +33,6 @@ public interface NetworkACLServiceProvider extends NetworkElement { */ boolean applyNetworkACLs(Network config, List rules) throws ResourceUnavailableException; + boolean reorderAclRules(Vpc vpc, List networks, List networkACLItems); + } diff --git a/api/src/main/java/com/cloud/network/element/VpcProvider.java b/api/src/main/java/com/cloud/network/element/VpcProvider.java index 14e86195a704..6debd1fbc2d8 100644 --- a/api/src/main/java/com/cloud/network/element/VpcProvider.java +++ b/api/src/main/java/com/cloud/network/element/VpcProvider.java @@ -22,6 +22,7 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.IpAddress; import com.cloud.network.vpc.NetworkACLItem; import com.cloud.network.vpc.PrivateGateway; import com.cloud.network.vpc.StaticRouteProfile; @@ -52,4 +53,6 @@ boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context boolean applyStaticRoutes(Vpc vpc, List routes) throws ResourceUnavailableException; boolean applyACLItemsToPrivateGw(PrivateGateway gateway, List rules) throws ResourceUnavailableException; + + boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address); } diff --git a/api/src/main/java/com/cloud/network/guru/NetworkGuru.java b/api/src/main/java/com/cloud/network/guru/NetworkGuru.java index c4f2beba63ee..7b81c75ed845 100644 --- a/api/src/main/java/com/cloud/network/guru/NetworkGuru.java +++ b/api/src/main/java/com/cloud/network/guru/NetworkGuru.java @@ -79,20 +79,24 @@ public interface NetworkGuru extends Adapter { * be used to make determination can be isolation methods, services * provided on the guest network and the service provider that's on the * guest network. - * + *

* If a network is already fully substantiated with the necessary resources * during this design phase, then the state should be set to Setup. If * the resources are not allocated at this point, the state should be set * to Allocated. * - * @param offering network offering that contains the package of services - * the end user intends to use on that network. - * @param plan where is this network being deployed. + * @param offering network offering that contains the package of services + * the end user intends to use on that network. + * @param plan where is this network being deployed. * @param userSpecified user specified parameters for this network. - * @param owner owner of this network. + * @param name + * @param vpcId + * @param owner owner of this network. * @return Network */ - Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner); + Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner); + + void setup(Network network, long networkId); /** * For guest networks that are in Allocated state after the design stage, diff --git a/api/src/main/java/com/cloud/network/nsx/NsxProvider.java b/api/src/main/java/com/cloud/network/nsx/NsxProvider.java new file mode 100644 index 000000000000..19cb3b4b939e --- /dev/null +++ b/api/src/main/java/com/cloud/network/nsx/NsxProvider.java @@ -0,0 +1,34 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.nsx; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +public interface NsxProvider extends InternalIdentity, Identity { + String getHostname(); + + String getPort(); + String getProviderName(); + String getUsername(); + long getZoneId(); + + String getTier0Gateway(); + String getEdgeCluster(); + + String getTransportZone(); +} diff --git a/api/src/main/java/com/cloud/network/nsx/NsxService.java b/api/src/main/java/com/cloud/network/nsx/NsxService.java new file mode 100644 index 000000000000..bc4e6aafbfec --- /dev/null +++ b/api/src/main/java/com/cloud/network/nsx/NsxService.java @@ -0,0 +1,36 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.nsx; + +import com.cloud.network.IpAddress; +import com.cloud.network.vpc.Vpc; +import org.apache.cloudstack.framework.config.ConfigKey; + +public interface NsxService { + + ConfigKey NSX_API_FAILURE_RETRIES = new ConfigKey<>("Advanced", Integer.class, + "nsx.api.failure.retries", "30", + "Number of retries for NSX API operations in case of failures", + true, ConfigKey.Scope.Zone); + ConfigKey NSX_API_FAILURE_INTERVAL = new ConfigKey<>("Advanced", Integer.class, + "nsx.api.failure.interval", "60", + "Waiting time (in seconds) before retrying an NSX API operation in case of failure", + true, ConfigKey.Scope.Zone); + + boolean createVpcNetwork(Long zoneId, long accountId, long domainId, Long vpcId, String vpcName, boolean sourceNatEnabled); + boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address); +} diff --git a/api/src/main/java/com/cloud/network/vpc/VpcOffering.java b/api/src/main/java/com/cloud/network/vpc/VpcOffering.java index b4df8e38dbac..38263f59667c 100644 --- a/api/src/main/java/com/cloud/network/vpc/VpcOffering.java +++ b/api/src/main/java/com/cloud/network/vpc/VpcOffering.java @@ -18,6 +18,7 @@ import java.util.Date; +import com.cloud.offering.NetworkOffering; import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.api.InternalIdentity; @@ -29,6 +30,8 @@ public enum State { public static final String defaultVPCOfferingName = "Default VPC offering"; public static final String defaultVPCNSOfferingName = "Default VPC offering with Netscaler"; public static final String redundantVPCOfferingName = "Redundant VPC offering"; + public static final String DEFAULT_VPC_NAT_NSX_OFFERING_NAME = "VPC offering with NSX - NAT Mode"; + public static final String DEFAULT_VPC_ROUTE_NSX_OFFERING_NAME = "VPC offering with NSX - Route Mode"; /** * @@ -53,6 +56,10 @@ public enum State { */ boolean isDefault(); + boolean isForNsx(); + + NetworkOffering.NetworkMode getNetworkMode(); + /** * @return service offering id used by VPC virtual router */ @@ -73,4 +80,8 @@ public enum State { Date getRemoved(); Date getCreated(); + + NetworkOffering.RoutingMode getRoutingMode(); + + Boolean isSpecifyAsNumber(); } diff --git a/api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java b/api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java index 5cccd6c5a823..10f1ddcc12d6 100644 --- a/api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java +++ b/api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java @@ -24,6 +24,7 @@ import org.apache.cloudstack.api.command.admin.vpc.UpdateVPCOfferingCmd; import org.apache.cloudstack.api.command.user.vpc.ListVPCOfferingsCmd; +import com.cloud.offering.NetworkOffering; import com.cloud.utils.Pair; import com.cloud.utils.net.NetUtils; @@ -36,7 +37,10 @@ public interface VpcProvisioningService { VpcOffering createVpcOffering(String name, String displayText, List supportedServices, Map> serviceProviders, Map serviceCapabilitystList, NetUtils.InternetProtocol internetProtocol, - Long serviceOfferingId, List domainIds, List zoneIds, VpcOffering.State state); + Long serviceOfferingId, Boolean forNsx, NetworkOffering.NetworkMode networkMode, + List domainIds, List zoneIds, VpcOffering.State state, + NetworkOffering.RoutingMode routingMode, boolean specifyAsNumber); + Pair,Integer> listVpcOfferings(ListVPCOfferingsCmd cmd); diff --git a/api/src/main/java/com/cloud/network/vpc/VpcService.java b/api/src/main/java/com/cloud/network/vpc/VpcService.java index 0f0d29f4082c..af2a9847a62d 100644 --- a/api/src/main/java/com/cloud/network/vpc/VpcService.java +++ b/api/src/main/java/com/cloud/network/vpc/VpcService.java @@ -56,7 +56,8 @@ public interface VpcService { * @throws ResourceAllocationException TODO */ Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain, - String ip4Dns1, String ip4Dns2, String ip6Dns1, String ip6Dns2, Boolean displayVpc, Integer publicMtu) + String ip4Dns1, String ip4Dns2, String ip6Dns1, String ip6Dns2, Boolean displayVpc, Integer publicMtu, Integer cidrSize, + Long asNumber, List bgpPeerIds) throws ResourceAllocationException; /** diff --git a/api/src/main/java/com/cloud/offering/NetworkOffering.java b/api/src/main/java/com/cloud/offering/NetworkOffering.java index 207880ea28c0..7011aea679ee 100644 --- a/api/src/main/java/com/cloud/offering/NetworkOffering.java +++ b/api/src/main/java/com/cloud/offering/NetworkOffering.java @@ -43,6 +43,15 @@ public enum Detail { InternalLbProvider, PublicLbProvider, servicepackageuuid, servicepackagedescription, PromiscuousMode, MacAddressChanges, ForgedTransmits, MacLearning, RelatedNetworkOffering, domainid, zoneid, pvlanType, internetProtocol } + public enum NetworkMode { + NATTED, + ROUTED + } + + enum RoutingMode { + Static, Dynamic + } + public final static String SystemPublicNetwork = "System-Public-Network"; public final static String SystemControlNetwork = "System-Control-Network"; public final static String SystemManagementNetwork = "System-Management-Network"; @@ -52,6 +61,11 @@ public enum Detail { public final static String DefaultSharedNetworkOfferingWithSGService = "DefaultSharedNetworkOfferingWithSGService"; public static final String DEFAULT_TUNGSTEN_SHARED_NETWORK_OFFERING_WITH_SGSERVICE = "DefaultTungstenSharedNetworkOfferingWithSGService"; + public static final String DEFAULT_NAT_NSX_OFFERING_FOR_VPC = "DefaultNATNSXNetworkOfferingForVpc"; + public static final String DEFAULT_NAT_NSX_OFFERING_FOR_VPC_WITH_ILB = "DefaultNATNSXNetworkOfferingForVpcWithInternalLB"; + public static final String DEFAULT_ROUTED_NSX_OFFERING_FOR_VPC = "DefaultRoutedNSXNetworkOfferingForVpc"; + public static final String DEFAULT_NAT_NSX_OFFERING = "DefaultNATNSXNetworkOffering"; + public static final String DEFAULT_ROUTED_NSX_OFFERING = "DefaultRoutedNSXNetworkOffering"; public final static String QuickCloudNoServices = "QuickCloudNoServices"; public final static String DefaultIsolatedNetworkOfferingWithSourceNatService = "DefaultIsolatedNetworkOfferingWithSourceNatService"; public final static String OvsIsolatedNetworkOfferingWithSourceNatService = "OvsIsolatedNetworkOfferingWithSourceNatService"; @@ -90,6 +104,10 @@ public enum Detail { boolean isForTungsten(); + boolean isForNsx(); + + NetworkMode getNetworkMode(); + TrafficType getTrafficType(); boolean isSpecifyVlan(); @@ -151,4 +169,8 @@ public enum Detail { String getServicePackage(); Date getCreated(); + + RoutingMode getRoutingMode(); + + Boolean isSpecifyAsNumber(); } diff --git a/api/src/main/java/com/cloud/offering/ServiceOffering.java b/api/src/main/java/com/cloud/offering/ServiceOffering.java index 58c7b0dbaf96..acb7a9f1cf91 100644 --- a/api/src/main/java/com/cloud/offering/ServiceOffering.java +++ b/api/src/main/java/com/cloud/offering/ServiceOffering.java @@ -33,6 +33,9 @@ public interface ServiceOffering extends InfrastructureEntity, InternalIdentity, static final String internalLbVmDefaultOffUniqueName = "Cloud.Com-InternalLBVm"; // leaving cloud.com references as these are identifyers and no real world addresses (check against DB) + + static final String PURGE_DB_ENTITIES_KEY = "purge.db.entities"; + enum State { Inactive, Active, } diff --git a/api/src/main/java/com/cloud/org/Cluster.java b/api/src/main/java/com/cloud/org/Cluster.java index 4079c88dfde3..5124168084c6 100644 --- a/api/src/main/java/com/cloud/org/Cluster.java +++ b/api/src/main/java/com/cloud/org/Cluster.java @@ -16,6 +16,7 @@ // under the License. package com.cloud.org; +import com.cloud.cpu.CPU; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.org.Managed.ManagedState; import org.apache.cloudstack.kernel.Partition; @@ -38,4 +39,6 @@ public static enum ClusterType { AllocationState getAllocationState(); ManagedState getManagedState(); + + CPU.CPUArch getArch(); } diff --git a/api/src/main/java/com/cloud/storage/DataStoreRole.java b/api/src/main/java/com/cloud/storage/DataStoreRole.java index 185e370159ca..d9af495ab00d 100644 --- a/api/src/main/java/com/cloud/storage/DataStoreRole.java +++ b/api/src/main/java/com/cloud/storage/DataStoreRole.java @@ -20,6 +20,7 @@ import com.cloud.utils.exception.CloudRuntimeException; + public enum DataStoreRole { Primary("primary"), Image("image"), ImageCache("imagecache"), Backup("backup"), Object("object"); diff --git a/api/src/main/java/com/cloud/storage/Storage.java b/api/src/main/java/com/cloud/storage/Storage.java index 1163fcc892fa..c997f5e1dbfd 100644 --- a/api/src/main/java/com/cloud/storage/Storage.java +++ b/api/src/main/java/com/cloud/storage/Storage.java @@ -16,10 +16,14 @@ // under the License. package com.cloud.storage; -import org.apache.commons.lang.NotImplementedException; - import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; + +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang3.StringUtils; public class Storage { public static enum ImageFormat { @@ -135,37 +139,72 @@ public static enum TemplateType { ISODISK /* Template corresponding to a iso (non root disk) present in an OVA */ } - public static enum StoragePoolType { - Filesystem(false, true, true), // local directory - NetworkFilesystem(true, true, true), // NFS - IscsiLUN(true, false, false), // shared LUN, with a clusterfs overlay - Iscsi(true, false, false), // for e.g., ZFS Comstar - ISO(false, false, false), // for iso image - LVM(false, false, false), // XenServer local LVM SR - CLVM(true, false, false), - RBD(true, true, false), // http://libvirt.org/storage.html#StorageBackendRBD - SharedMountPoint(true, true, true), - VMFS(true, true, false), // VMware VMFS storage - PreSetup(true, true, false), // for XenServer, Storage Pool is set up by customers. - EXT(false, true, false), // XenServer local EXT SR - OCFS2(true, false, false), - SMB(true, false, false), - Gluster(true, false, false), - PowerFlex(true, true, true), // Dell EMC PowerFlex/ScaleIO (formerly VxFlexOS) - ManagedNFS(true, false, false), - Linstor(true, true, false), - DatastoreCluster(true, true, false), // for VMware, to abstract pool of clusters - StorPool(true, true, true), - FiberChannel(true, true, false); // Fiber Channel Pool for KVM hypervisors is used to find the volume by WWN value (/dev/disk/by-id/wwn-) - + /** + * StoragePoolTypes carry some details about the format and capabilities of a storage pool. While not necessarily a + * 1:1 with PrimaryDataStoreDriver (and for KVM agent, KVMStoragePool and StorageAdaptor) implementations, it is + * often used to decide which storage plugin or storage command to call, so it may be necessary for new storage + * plugins to add a StoragePoolType. This can be done by adding it below, or by creating a new public static final + * instance of StoragePoolType in the plugin itself, which registers it with the map. + * + * Note that if the StoragePoolType is for KVM and defined in plugin code rather than below, care must be taken to + * ensure this is available on the agent side as well. This is best done by defining the StoragePoolType in a common + * package available on both management server and agent plugin jars. + */ + public static class StoragePoolType { + private static final Map map = new LinkedHashMap<>(); + + public static final StoragePoolType Filesystem = new StoragePoolType("Filesystem", false, true, true); + public static final StoragePoolType NetworkFilesystem = new StoragePoolType("NetworkFilesystem", true, true, true); + public static final StoragePoolType IscsiLUN = new StoragePoolType("IscsiLUN", true, false, false); + public static final StoragePoolType Iscsi = new StoragePoolType("Iscsi", true, false, false); + public static final StoragePoolType ISO = new StoragePoolType("ISO", false, false, false); + public static final StoragePoolType LVM = new StoragePoolType("LVM", false, false, false); + public static final StoragePoolType CLVM = new StoragePoolType("CLVM", true, false, false); + public static final StoragePoolType RBD = new StoragePoolType("RBD", true, true, false); + public static final StoragePoolType SharedMountPoint = new StoragePoolType("SharedMountPoint", true, true, true); + public static final StoragePoolType VMFS = new StoragePoolType("VMFS", true, true, false); + public static final StoragePoolType PreSetup = new StoragePoolType("PreSetup", true, true, false); + public static final StoragePoolType EXT = new StoragePoolType("EXT", false, true, false); + public static final StoragePoolType OCFS2 = new StoragePoolType("OCFS2", true, false, false); + public static final StoragePoolType SMB = new StoragePoolType("SMB", true, false, false); + public static final StoragePoolType Gluster = new StoragePoolType("Gluster", true, false, false); + public static final StoragePoolType PowerFlex = new StoragePoolType("PowerFlex", true, true, true); + public static final StoragePoolType ManagedNFS = new StoragePoolType("ManagedNFS", true, false, false); + public static final StoragePoolType Linstor = new StoragePoolType("Linstor", true, true, false); + public static final StoragePoolType DatastoreCluster = new StoragePoolType("DatastoreCluster", true, true, false); + public static final StoragePoolType StorPool = new StoragePoolType("StorPool", true,true,true); + public static final StoragePoolType FiberChannel = new StoragePoolType("FiberChannel", true,true,false); + + + private final String name; private final boolean shared; private final boolean overProvisioning; private final boolean encryption; - StoragePoolType(boolean shared, boolean overProvisioning, boolean encryption) { + /** + * New StoragePoolType, set the name to check with it in Dao (Note: Do not register it into the map of pool types). + * @param name name of the StoragePoolType. + */ + public StoragePoolType(String name) { + this.name = name; + this.shared = false; + this.overProvisioning = false; + this.encryption = false; + } + + /** + * Define a new StoragePoolType, and register it into the map of pool types known to the management server. + * @param name Simple unique name of the StoragePoolType. + * @param shared Storage pool is shared/accessible to multiple hypervisors + * @param overProvisioning Storage pool supports overProvisioning + * @param encryption Storage pool supports encrypted volumes + */ + public StoragePoolType(String name, boolean shared, boolean overProvisioning, boolean encryption) { + this.name = name; this.shared = shared; this.overProvisioning = overProvisioning; this.encryption = encryption; + addStoragePoolType(this); } public boolean isShared() { @@ -179,6 +218,48 @@ public boolean supportsOverProvisioning() { public boolean supportsEncryption() { return encryption; } + + private static void addStoragePoolType(StoragePoolType storagePoolType) { + map.putIfAbsent(storagePoolType.name, storagePoolType); + } + + public static StoragePoolType[] values() { + return map.values().toArray(StoragePoolType[]::new).clone(); + } + + public static StoragePoolType valueOf(String name) { + if (StringUtils.isBlank(name)) { + return null; + } + + StoragePoolType storage = map.get(name); + if (storage == null) { + throw new IllegalArgumentException("StoragePoolType '" + name + "' not found"); + } + return storage; + } + + @Override + public String toString() { + return name; + } + + public String name() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + StoragePoolType that = (StoragePoolType) o; + return Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } } public static List getNonSharedStoragePoolTypes() { diff --git a/api/src/main/java/com/cloud/storage/StorageService.java b/api/src/main/java/com/cloud/storage/StorageService.java index 1ce335b01153..b8df75cd3e4c 100644 --- a/api/src/main/java/com/cloud/storage/StorageService.java +++ b/api/src/main/java/com/cloud/storage/StorageService.java @@ -95,6 +95,10 @@ public interface StorageService { StoragePool updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException; + StoragePool enablePrimaryStoragePool(Long id); + + StoragePool disablePrimaryStoragePool(Long id); + StoragePool getStoragePool(long id); boolean deleteImageStore(DeleteImageStoreCmd cmd); diff --git a/api/src/main/java/com/cloud/storage/Upload.java b/api/src/main/java/com/cloud/storage/Upload.java index 59d203ac73ae..4e696e877cc8 100644 --- a/api/src/main/java/com/cloud/storage/Upload.java +++ b/api/src/main/java/com/cloud/storage/Upload.java @@ -40,7 +40,7 @@ public static enum Status { } public static enum Type { - VOLUME, TEMPLATE, ISO + VOLUME, SNAPSHOT, TEMPLATE, ISO } public static enum Mode { diff --git a/api/src/main/java/com/cloud/storage/Volume.java b/api/src/main/java/com/cloud/storage/Volume.java index 308ed2544ed0..c7fbdb0a5445 100644 --- a/api/src/main/java/com/cloud/storage/Volume.java +++ b/api/src/main/java/com/cloud/storage/Volume.java @@ -30,6 +30,8 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, BasedOn, StateObject, Displayable { + static final long DISK_OFFERING_SUITABILITY_CHECK_VOLUME_ID = -1; + // Managed storage volume parameters (specified in the compute/disk offering for PowerFlex) String BANDWIDTH_LIMIT_IN_MBPS = "bandwidthLimitInMbps"; String IOPS_LIMIT = "iopsLimit"; @@ -269,11 +271,13 @@ enum Event { void setExternalUuid(String externalUuid); - public Long getPassphraseId(); + Long getPassphraseId(); + + void setPassphraseId(Long id); - public void setPassphraseId(Long id); + String getEncryptFormat(); - public String getEncryptFormat(); + void setEncryptFormat(String encryptFormat); - public void setEncryptFormat(String encryptFormat); + boolean isDeleteProtection(); } diff --git a/api/src/main/java/com/cloud/storage/VolumeApiService.java b/api/src/main/java/com/cloud/storage/VolumeApiService.java index 4f09702b7dba..6f4c7aa09e26 100644 --- a/api/src/main/java/com/cloud/storage/VolumeApiService.java +++ b/api/src/main/java/com/cloud/storage/VolumeApiService.java @@ -102,8 +102,12 @@ public interface VolumeApiService { boolean deleteVolume(long volumeId, Account caller); + Volume changeDiskOfferingForVolumeInternal(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean autoMigrateVolume, boolean shrinkOk) throws ResourceAllocationException; + Volume attachVolumeToVM(AttachVolumeCmd command); + Volume attachVolumeToVM(Long vmId, Long volumeId, Long deviceId, Boolean allowAttachForSharedFS); + Volume detachVolumeViaDestroyVM(long vmId, long volumeId); Volume detachVolumeFromVM(DetachVolumeCmd cmd); @@ -113,7 +117,9 @@ Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account acc Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType, List zoneIds) throws ResourceAllocationException; - Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long owner, String chainInfo, String name); + Volume updateVolume(long volumeId, String path, String state, Long storageId, + Boolean displayVolume, Boolean deleteProtection, + String customId, long owner, String chainInfo, String name); /** * Extracts the volume to a particular location. diff --git a/api/src/main/java/com/cloud/storage/snapshot/SnapshotApiService.java b/api/src/main/java/com/cloud/storage/snapshot/SnapshotApiService.java index 0893f337ce2f..67afd6aa4e24 100644 --- a/api/src/main/java/com/cloud/storage/snapshot/SnapshotApiService.java +++ b/api/src/main/java/com/cloud/storage/snapshot/SnapshotApiService.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.api.command.user.snapshot.CopySnapshotCmd; import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotPolicyCmd; import org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotPoliciesCmd; +import org.apache.cloudstack.api.command.user.snapshot.ExtractSnapshotCmd; import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd; import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd; import org.apache.cloudstack.api.command.user.snapshot.UpdateSnapshotPolicyCmd; @@ -106,6 +107,16 @@ Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapsh */ Snapshot createSnapshot(Long volumeId, Long policyId, Long snapshotId, Account snapshotOwner); + /** + * Extracts the snapshot to a particular location. + * + * @param cmd + * the command specifying url (where the snapshot needs to be extracted to), zoneId (zone where the snapshot exists) and + * id (the id of the snapshot) + * + */ + String extractSnapshot(ExtractSnapshotCmd cmd); + /** * Archives a snapshot from primary storage to secondary storage. * @param id Snapshot ID diff --git a/api/src/main/java/com/cloud/template/VirtualMachineTemplate.java b/api/src/main/java/com/cloud/template/VirtualMachineTemplate.java index 1f8cef0365b1..d8872d5fe724 100644 --- a/api/src/main/java/com/cloud/template/VirtualMachineTemplate.java +++ b/api/src/main/java/com/cloud/template/VirtualMachineTemplate.java @@ -19,6 +19,7 @@ import java.util.Date; import java.util.Map; +import com.cloud.cpu.CPU; import com.cloud.user.UserData; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.api.Identity; @@ -148,4 +149,6 @@ public enum TemplateFilter { UserData.UserDataOverridePolicy getUserDataOverridePolicy(); + CPU.CPUArch getArch(); + } diff --git a/api/src/main/java/com/cloud/user/ResourceLimitService.java b/api/src/main/java/com/cloud/user/ResourceLimitService.java index f2d87a4390df..2f4ad1347be5 100644 --- a/api/src/main/java/com/cloud/user/ResourceLimitService.java +++ b/api/src/main/java/com/cloud/user/ResourceLimitService.java @@ -18,13 +18,18 @@ import java.util.List; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.framework.config.ConfigKey; + import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.ResourceCount; import com.cloud.configuration.ResourceLimit; import com.cloud.domain.Domain; import com.cloud.exception.ResourceAllocationException; -import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.cloudstack.user.ResourceReservation; +import com.cloud.offering.DiskOffering; +import com.cloud.offering.ServiceOffering; +import com.cloud.template.VirtualMachineTemplate; public interface ResourceLimitService { @@ -33,7 +38,21 @@ public interface ResourceLimitService { static final ConfigKey MaxProjectSecondaryStorage = new ConfigKey<>("Project Defaults", Long.class, "max.project.secondary.storage", "400", "The default maximum secondary storage space (in GiB) that can be used for a project", false); static final ConfigKey ResourceCountCheckInterval = new ConfigKey<>("Advanced", Long.class, "resourcecount.check.interval", "300", - "Time (in seconds) to wait before running resource recalculation and fixing task. Default is 300 seconds, Setting this to 0 disables execution of the task", false); + "Time (in seconds) to wait before running resource recalculation and fixing tasks like stale resource reservation cleanup" + + ". Default is 300 seconds, Setting this to 0 disables execution of the task", true); + static final ConfigKey ResourceReservationCleanupDelay = new ConfigKey<>("Advanced", Long.class, "resource.reservation.cleanup.delay", "3600", + "Time (in seconds) after which a resource reservation gets deleted. Default is 3600 seconds, Setting this to 0 disables execution of the task", true); + static final ConfigKey ResourceLimitHostTags = new ConfigKey<>("Advanced", String.class, "resource.limit.host.tags", "", + "A comma-separated list of tags for host resource limits", true); + static final ConfigKey ResourceLimitStorageTags = new ConfigKey<>("Advanced", String.class, "resource.limit.storage.tags", "", + "A comma-separated list of tags for storage resource limits", true); + static final ConfigKey DefaultMaxAccountProjects = new ConfigKey<>("Account Defaults",Long.class,"max.account.projects","10", + "The default maximum number of projects that can be created for an account",false); + static final ConfigKey DefaultMaxDomainProjects = new ConfigKey<>("Domain Defaults",Long.class,"max.domain.projects","50", + "The default maximum number of projects that can be created for a domain",false); + + static final List HostTagsSupportingTypes = List.of(ResourceType.user_vm, ResourceType.cpu, ResourceType.memory); + static final List StorageTagsSupportingTypes = List.of(ResourceType.volume, ResourceType.primary_storage); /** * Updates an existing resource limit with the specified details. If a limit doesn't exist, will create one. @@ -46,22 +65,27 @@ public interface ResourceLimitService { * TODO * @param max * TODO + * @param tag + * tag for the resource type * * @return the updated/created resource limit */ - ResourceLimit updateResourceLimit(Long accountId, Long domainId, Integer resourceType, Long max); + ResourceLimit updateResourceLimit(Long accountId, Long domainId, Integer resourceType, Long max, String tag); /** * Updates an existing resource count details for the account/domain * * @param accountId - * TODO + * Id of the account for which resource recalculation to be done * @param domainId - * TODO + * Id of the domain for which resource recalculation to be doneDO * @param typeId - * TODO + * type of the resource for which recalculation to be done + * @param tag + * tag for the resource type for which recalculation to be done * @return the updated/created resource counts */ + List recalculateResourceCount(Long accountId, Long domainId, Integer typeId, String tag); List recalculateResourceCount(Long accountId, Long domainId, Integer typeId); /** @@ -77,7 +101,7 @@ public interface ResourceLimitService { * TODO * @return a list of limits that match the criteria */ - public List searchForLimits(Long id, Long accountId, Long domainId, ResourceType resourceType, Long startIndex, Long pageSizeVal); + public List searchForLimits(Long id, Long accountId, Long domainId, ResourceType resourceType, String tag, Long startIndex, Long pageSizeVal); /** * Finds the resource limit for a specified account and type. If the account has an infinite limit, will check @@ -85,9 +109,10 @@ public interface ResourceLimitService { * * @param account * @param type + * @param tag * @return resource limit */ - public long findCorrectResourceLimitForAccount(Account account, ResourceType type); + public long findCorrectResourceLimitForAccount(Account account, ResourceType type, String tag); /** * This call should be used when we have already queried resource limit for an account. This is to handle @@ -105,9 +130,10 @@ public interface ResourceLimitService { * * @param domain * @param type + * @param tag * @return resource limit */ - public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type); + public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type, String tag); /** * Finds the default resource limit for a specified type. @@ -122,9 +148,10 @@ public interface ResourceLimitService { * * @param domain * @param type + * @param tag * @return resource limit */ - public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type); + public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type, String tag); /** * Increments the resource count @@ -134,6 +161,7 @@ public interface ResourceLimitService { * @param delta */ public void incrementResourceCount(long accountId, ResourceType type, Long... delta); + public void incrementResourceCountWithTag(long accountId, ResourceType type, String tag, Long... delta); /** * Decrements the resource count @@ -143,6 +171,7 @@ public interface ResourceLimitService { * @param delta */ public void decrementResourceCount(long accountId, ResourceType type, Long... delta); + public void decrementResourceCountWithTag(long accountId, ResourceType type, String tag, Long... delta); /** * Checks if a limit has been exceeded for an account @@ -155,15 +184,17 @@ public interface ResourceLimitService { * @throws ResourceAllocationException */ public void checkResourceLimit(Account account, ResourceCount.ResourceType type, long... count) throws ResourceAllocationException; + public void checkResourceLimitWithTag(Account account, ResourceCount.ResourceType type, String tag, long... count) throws ResourceAllocationException; /** * Gets the count of resources for a resource type and account * * @param account * @param type + * @param tag * @return count of resources */ - public long getResourceCount(Account account, ResourceType type); + public long getResourceCount(Account account, ResourceType type, String tag); /** * Checks if a limit has been exceeded for an account if displayResource flag is on @@ -208,15 +239,49 @@ public interface ResourceLimitService { */ void decrementResourceCount(long accountId, ResourceType type, Boolean displayResource, Long... delta); - /** - * Adds a reservation that will be counted in subsequent calls to {count}getResourceCount{code} until {code}this[code} - * is closed. It will create a reservation record that will be counted when resource limits are checked. - * @param account The account for which the reservation is. - * @param displayResource whether this resource is shown to users at all (if not it is not counted to limits) - * @param type resource type - * @param delta amount to reserve (will not be <+ 0) - * @return a {code}AutoClosable{Code} object representing the resource the user needs - */ - ResourceReservation getReservation(Account account, Boolean displayResource, ResourceType type, Long delta) throws ResourceAllocationException; + List getResourceLimitHostTags(); + List getResourceLimitHostTags(ServiceOffering serviceOffering, VirtualMachineTemplate template); + List getResourceLimitStorageTags(); + List getResourceLimitStorageTags(DiskOffering diskOffering); + void updateTaggedResourceLimitsAndCountsForAccounts(List responses, String tag); + void updateTaggedResourceLimitsAndCountsForDomains(List responses, String tag); + void checkVolumeResourceLimit(Account owner, Boolean display, Long size, DiskOffering diskOffering) throws ResourceAllocationException; + + void checkVolumeResourceLimitForDiskOfferingChange(Account owner, Boolean display, Long currentSize, Long newSize, + DiskOffering currentOffering, DiskOffering newOffering) throws ResourceAllocationException; + + void checkPrimaryStorageResourceLimit(Account owner, Boolean display, Long size, DiskOffering diskOffering) throws ResourceAllocationException; + + void incrementVolumeResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering); + void decrementVolumeResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering); + + void updateVmResourceCountForTemplateChange(long accountId, Boolean display, ServiceOffering offering, VirtualMachineTemplate currentTemplate, VirtualMachineTemplate newTemplate); + + void updateVmResourceCountForServiceOfferingChange(long accountId, Boolean display, Long currentCpu, Long newCpu, Long currentMemory, + Long newMemory, + ServiceOffering currentOffering, ServiceOffering newOffering, + VirtualMachineTemplate template); + + void updateVolumeResourceCountForDiskOfferingChange(long accountId, Boolean display, Long currentSize, Long newSize, + DiskOffering currentDiskOffering, DiskOffering newDiskOffering); + + void incrementVolumePrimaryStorageResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering); + void decrementVolumePrimaryStorageResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering); + void checkVmResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template) throws ResourceAllocationException; + void incrementVmResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template); + void decrementVmResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template); + + void checkVmResourceLimitsForServiceOfferingChange(Account owner, Boolean display, Long currentCpu, Long newCpu, + Long currentMemory, Long newMemory, ServiceOffering currentOffering, ServiceOffering newOffering, VirtualMachineTemplate template) throws ResourceAllocationException; + + void checkVmResourceLimitsForTemplateChange(Account owner, Boolean display, ServiceOffering offering, + VirtualMachineTemplate currentTemplate, VirtualMachineTemplate newTemplate) throws ResourceAllocationException; + + void checkVmCpuResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu) throws ResourceAllocationException; + void incrementVmCpuResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu); + void decrementVmCpuResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu); + void checkVmMemoryResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory) throws ResourceAllocationException; + void incrementVmMemoryResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory); + void decrementVmMemoryResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory); } diff --git a/api/src/main/java/com/cloud/vm/UserVmService.java b/api/src/main/java/com/cloud/vm/UserVmService.java index 2fdd25924831..5a9301eef7fa 100644 --- a/api/src/main/java/com/cloud/vm/UserVmService.java +++ b/api/src/main/java/com/cloud/vm/UserVmService.java @@ -68,10 +68,7 @@ public interface UserVmService { /** * Destroys one virtual machine * - * @param userId - * the id of the user performing the action - * @param vmId - * the id of the virtual machine. + * @param cmd the API Command Object containg the parameters to use for this service action * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ @@ -112,14 +109,14 @@ public interface UserVmService { UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException; + UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ResourceAllocationException; + void startVirtualMachine(UserVm vm) throws OperationTimedoutException, ResourceUnavailableException, InsufficientCapacityException; void startVirtualMachineForHA(VirtualMachine vm, Map params, DeploymentPlanner planner) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException; - UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException; - UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException; /** @@ -156,14 +153,6 @@ void startVirtualMachineForHA(VirtualMachine vm, Map volumeToPool); - UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException; + UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ResourceAllocationException; UserVm restoreVirtualMachine(Account caller, long vmId, Long newTemplateId, Long rootDiskOfferingId, boolean expunge, Map details) throws InsufficientCapacityException, ResourceUnavailableException; diff --git a/api/src/main/java/com/cloud/vm/VirtualMachine.java b/api/src/main/java/com/cloud/vm/VirtualMachine.java index e7c5efb773b1..e2ea408e7b8c 100644 --- a/api/src/main/java/com/cloud/vm/VirtualMachine.java +++ b/api/src/main/java/com/cloud/vm/VirtualMachine.java @@ -333,6 +333,8 @@ public boolean isUsedBySystem() { */ Date getCreated(); + Date getRemoved(); + long getServiceOfferingId(); Long getBackupOfferingId(); diff --git a/api/src/main/java/com/cloud/vm/VmDetailConstants.java b/api/src/main/java/com/cloud/vm/VmDetailConstants.java index 9338cc11cd4d..603948d76cfc 100644 --- a/api/src/main/java/com/cloud/vm/VmDetailConstants.java +++ b/api/src/main/java/com/cloud/vm/VmDetailConstants.java @@ -19,6 +19,7 @@ public interface VmDetailConstants { String KEYBOARD = "keyboard"; String CPU_CORE_PER_SOCKET = "cpu.corespersocket"; + String CPU_THREAD_PER_CORE = "cpu.threadspercore"; String ROOT_DISK_SIZE = "rootdisksize"; String BOOT_MODE = "boot.mode"; String NAME_ON_HYPERVISOR= "nameonhypervisor"; diff --git a/api/src/main/java/org/apache/cloudstack/acl/Role.java b/api/src/main/java/org/apache/cloudstack/acl/Role.java index 5e5ffd583d87..ce4166ef4c81 100644 --- a/api/src/main/java/org/apache/cloudstack/acl/Role.java +++ b/api/src/main/java/org/apache/cloudstack/acl/Role.java @@ -21,7 +21,18 @@ import org.apache.cloudstack.api.InternalIdentity; public interface Role extends RoleEntity, InternalIdentity, Identity { + + enum State { + ENABLED, DISABLED; + + @Override + public String toString(){ + return super.toString().toLowerCase(); + } + } + RoleType getRoleType(); boolean isDefault(); boolean isPublicRole(); + State getState(); } diff --git a/api/src/main/java/org/apache/cloudstack/acl/RoleService.java b/api/src/main/java/org/apache/cloudstack/acl/RoleService.java index 07f62a7e7f8f..68204d432534 100644 --- a/api/src/main/java/org/apache/cloudstack/acl/RoleService.java +++ b/api/src/main/java/org/apache/cloudstack/acl/RoleService.java @@ -54,6 +54,10 @@ public interface RoleService { boolean deleteRole(Role role); + boolean enableRole(Role role); + + boolean disableRole(Role role); + RolePermission findRolePermission(Long id); RolePermission findRolePermissionByRoleIdAndRule(Long roleId, String rule); @@ -76,7 +80,7 @@ public interface RoleService { */ List listRoles(); - Pair, Integer> listRoles(Long startIndex, Long limit); + Pair, Integer> listRoles(String state, Long startIndex, Long limit); /** * Find all roles that have the giving {@link String} as part of their name. @@ -84,14 +88,14 @@ public interface RoleService { */ List findRolesByName(String name); - Pair, Integer> findRolesByName(String name, String keyword, Long startIndex, Long limit); + Pair, Integer> findRolesByName(String name, String keyword, String state, Long startIndex, Long limit); /** * Find all roles by {@link RoleType}. If the role type is {@link RoleType#Admin}, the calling account must be a root admin, otherwise we return an empty list. */ List findRolesByType(RoleType roleType); - Pair, Integer> findRolesByType(RoleType roleType, Long startIndex, Long limit); + Pair, Integer> findRolesByType(RoleType roleType, String state, Long startIndex, Long limit); List findAllPermissionsBy(Long roleId); diff --git a/api/src/main/java/org/apache/cloudstack/acl/RoleType.java b/api/src/main/java/org/apache/cloudstack/acl/RoleType.java index ec82cd6605bb..005d47c85bc2 100644 --- a/api/src/main/java/org/apache/cloudstack/acl/RoleType.java +++ b/api/src/main/java/org/apache/cloudstack/acl/RoleType.java @@ -20,7 +20,8 @@ import com.cloud.user.Account; import com.google.common.base.Enums; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.util.HashMap; import java.util.Map; @@ -37,7 +38,7 @@ public enum RoleType { private Account.Type accountType; private int mask; - private static Logger logger = Logger.getLogger(RoleType.class.getName()); + private static Logger LOGGER = LogManager.getLogger(RoleType.class.getName()); private static Map ACCOUNT_TYPE_MAP = new HashMap<>(); static { @@ -104,10 +105,10 @@ public static Long getRoleByAccountType(final Long roleId, final Account.Type ac * */ public static Account.Type getAccountTypeByRole(final Role role, final Account.Type defautAccountType) { if (role != null) { - logger.debug(String.format("Role [%s] is not null; therefore, we use its account type [%s].", role, defautAccountType)); + LOGGER.debug(String.format("Role [%s] is not null; therefore, we use its account type [%s].", role, defautAccountType)); return role.getRoleType().getAccountType(); } - logger.debug(String.format("Role is null; therefore, we use the default account type [%s] value.", defautAccountType)); + LOGGER.debug(String.format("Role is null; therefore, we use the default account type [%s] value.", defautAccountType)); return defautAccountType; } } diff --git a/api/src/main/java/org/apache/cloudstack/affinity/AffinityGroupResponse.java b/api/src/main/java/org/apache/cloudstack/affinity/AffinityGroupResponse.java index 6cda8d07bd86..69f391a5656a 100644 --- a/api/src/main/java/org/apache/cloudstack/affinity/AffinityGroupResponse.java +++ b/api/src/main/java/org/apache/cloudstack/affinity/AffinityGroupResponse.java @@ -25,6 +25,7 @@ import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.EntityReference; import org.apache.cloudstack.api.response.ControlledViewEntityResponse; +import org.apache.cloudstack.dedicated.DedicatedResourceResponse; import com.cloud.serializer.Param; @@ -76,6 +77,10 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledVie @Param(description = "virtual machine IDs associated with this affinity group") private List vmIdList; + @SerializedName("dedicatedresources") + @Param(description = "dedicated resources associated with this affinity group") + private List dedicatedResources; + public AffinityGroupResponse() { } @@ -171,4 +176,12 @@ public void addVMId(String vmId) { this.vmIdList.add(vmId); } + public void addDedicatedResource(DedicatedResourceResponse dedicatedResourceResponse) { + if (this.dedicatedResources == null) { + this.dedicatedResources = new ArrayList<>(); + } + + this.dedicatedResources.add(dedicatedResourceResponse); + } + } diff --git a/api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java b/api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java index ed3381ae97c0..083a1be00f56 100644 --- a/api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java @@ -25,11 +25,9 @@ import org.apache.cloudstack.api.response.GetUploadParamsResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; public abstract class AbstractGetUploadParamsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AbstractGetUploadParamsCmd.class.getName()); @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the volume/template/iso") private String name; diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiArgValidator.java b/api/src/main/java/org/apache/cloudstack/api/ApiArgValidator.java index 3e06fc0e44eb..380472352735 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiArgValidator.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiArgValidator.java @@ -32,4 +32,9 @@ public enum ApiArgValidator { * Validates if the parameter is an UUID with the method {@link UuidUtils#isUuid(String)}. */ UuidString, + + /** + * Validates if the parameter is a valid RFC Compliance domain name. + */ + RFCComplianceDomainName, } diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java b/api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java index 938936765167..f2f52cec9697 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java @@ -85,7 +85,8 @@ public enum ApiCommandResourceType { Bucket(org.apache.cloudstack.storage.object.Bucket.class), QuotaTariff(org.apache.cloudstack.quota.QuotaTariff.class), KubernetesCluster(null), - KubernetesSupportedVersion(null); + KubernetesSupportedVersion(null), + SharedFS(org.apache.cloudstack.storage.sharedfs.SharedFS.class); private final Class clazz; diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java index d6099ac47178..bb16b0ff90de 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java @@ -29,10 +29,18 @@ public class ApiConstants { public static final String ADDRESS = "address"; public static final String ALGORITHM = "algorithm"; public static final String ALIAS = "alias"; + public static final String ALLOCATED_DATE = "allocateddate"; public static final String ALLOCATED_ONLY = "allocatedonly"; + public static final String ALLOCATED_TIME = "allocated"; + public static final String ALLOW_USER_FORCE_STOP_VM = "allowuserforcestopvm"; public static final String ANNOTATION = "annotation"; public static final String API_KEY = "apikey"; public static final String ARCHIVED = "archived"; + public static final String ARCH = "arch"; + public static final String AS_NUMBER = "asnumber"; + public static final String AS_NUMBER_ID = "asnumberid"; + public static final String ASN_RANGE = "asnrange"; + public static final String ASN_RANGE_ID = "asnrangeid"; public static final String ASYNC_BACKUP = "asyncbackup"; public static final String AUTO_SELECT = "autoselect"; public static final String USER_API_KEY = "userapikey"; @@ -46,6 +54,8 @@ public class ApiConstants { public static final String BACKUP_OFFERING_NAME = "backupofferingname"; public static final String BACKUP_OFFERING_ID = "backupofferingid"; public static final String BASE64_IMAGE = "base64image"; + public static final String BGP_PEERS = "bgppeers"; + public static final String BGP_PEER_IDS = "bgppeerids"; public static final String BITS = "bits"; public static final String BOOTABLE = "bootable"; public static final String BIND_DN = "binddn"; @@ -87,6 +97,8 @@ public class ApiConstants { public static final String DNS_SEARCH_ORDER = "dnssearchorder"; public static final String CHAIN_INFO = "chaininfo"; public static final String CIDR = "cidr"; + public static final String CIDR_SIZE = "cidrsize"; + public static final String IP6_CIDR = "ip6cidr"; public static final String CIDR_LIST = "cidrlist"; public static final String DEST_CIDR_LIST = "destcidrlist"; @@ -126,6 +138,7 @@ public class ApiConstants { public static final String DATACENTER_NAME = "datacentername"; public static final String DATADISK_OFFERING_LIST = "datadiskofferinglist"; public static final String DEFAULT_VALUE = "defaultvalue"; + public static final String DELETE_PROTECTION = "deleteprotection"; public static final String DESCRIPTION = "description"; public static final String DESTINATION = "destination"; public static final String DESTINATION_ZONE_ID = "destzoneid"; @@ -170,11 +183,14 @@ public class ApiConstants { public static final String DURATION = "duration"; public static final String ELIGIBLE = "eligible"; public static final String EMAIL = "email"; + public static final String END_ASN = "endasn"; public static final String END_DATE = "enddate"; public static final String END_IP = "endip"; public static final String END_IPV6 = "endipv6"; public static final String END_PORT = "endport"; public static final String ENTRY_TIME = "entrytime"; + public static final String EVENT_ID = "eventid"; + public static final String EVENT_TYPE = "eventtype"; public static final String EXPIRES = "expires"; public static final String EXTRA_CONFIG = "extraconfig"; public static final String EXTRA_DHCP_OPTION = "extradhcpoption"; @@ -185,6 +201,7 @@ public class ApiConstants { public static final String EXTERNAL_UUID = "externaluuid"; public static final String FENCE = "fence"; public static final String FETCH_LATEST = "fetchlatest"; + public static final String FILESYSTEM = "filesystem"; public static final String FIRSTNAME = "firstname"; public static final String FORCED = "forced"; public static final String FORCED_DESTROY_LOCAL_STORAGE = "forcedestroylocalstorage"; @@ -210,6 +227,7 @@ public class ApiConstants { public static final String HA_PROVIDER = "haprovider"; public static final String HA_STATE = "hastate"; public static final String HEALTH = "health"; + public static final String HEADERS = "headers"; public static final String HIDE_IP_ADDRESS_USAGE = "hideipaddressusage"; public static final String HOST_ID = "hostid"; public static final String HOST_IDS = "hostids"; @@ -268,6 +286,7 @@ public class ApiConstants { public static final String IS_ENCRYPTED = "isencrypted"; public static final String IS_EXTRACTABLE = "isextractable"; public static final String IS_FEATURED = "isfeatured"; + public static final String IS_IMPLICIT = "isimplicit"; public static final String IS_PORTABLE = "isportable"; public static final String IS_PUBLIC = "ispublic"; public static final String IS_PERSISTENT = "ispersistent"; @@ -283,6 +302,7 @@ public class ApiConstants { public static final String JOB_STATUS = "jobstatus"; public static final String KEEPALIVE_ENABLED = "keepaliveenabled"; public static final String KERNEL_VERSION = "kernelversion"; + public static final String KEY = "key"; public static final String LABEL = "label"; public static final String LASTNAME = "lastname"; public static final String LAST_BOOT = "lastboottime"; @@ -290,6 +310,7 @@ public class ApiConstants { public static final String LAST_SERVER_STOP = "lastserverstop"; public static final String LEVEL = "level"; public static final String LENGTH = "length"; + public static final String LIMIT = "limit"; public static final String LIMIT_CPU_USE = "limitcpuuse"; public static final String LIST_HOSTS = "listhosts"; public static final String LOCK = "lock"; @@ -307,6 +328,10 @@ public class ApiConstants { public static final String MIGRATIONS = "migrations"; public static final String MEMORY = "memory"; public static final String MODE = "mode"; + public static final String MULTI_ARCH = "ismultiarch"; + public static final String NSX_MODE = "nsxmode"; + public static final String NETWORK_MODE = "networkmode"; + public static final String NSX_ENABLED = "isnsxenabled"; public static final String NAME = "name"; public static final String METHOD_NAME = "methodname"; public static final String NETWORK_DOMAIN = "networkdomain"; @@ -326,6 +351,7 @@ public class ApiConstants { public static final String IS_DEFAULT_USE = "defaultuse"; public static final String OLD_FORMAT = "oldformat"; public static final String OP = "op"; + public static final String OPTION = "option"; public static final String OPTIONS = "options"; public static final String OS_CATEGORY_ID = "oscategoryid"; public static final String OS_CATEGORY_NAME = "oscategoryname"; @@ -345,6 +371,7 @@ public class ApiConstants { public static final String PARENT = "parent"; public static final String PARENT_ID = "parentid"; public static final String PARENT_DOMAIN_ID = "parentdomainid"; + public static final String PARENT_SUBNET = "parentsubnet"; public static final String PARENT_TEMPLATE_ID = "parenttemplateid"; public static final String PASSWORD = "password"; public static final String CURRENT_PASSWORD = "currentpassword"; @@ -353,6 +380,7 @@ public class ApiConstants { public static final String SSHKEY_ENABLED = "sshkeyenabled"; public static final String PATH = "path"; public static final String PAYLOAD = "payload"; + public static final String PAYLOAD_URL = "payloadurl"; public static final String POD_ID = "podid"; public static final String POD_NAME = "podname"; public static final String POD_IDS = "podids"; @@ -380,11 +408,13 @@ public class ApiConstants { public static final String PUBLIC_START_PORT = "publicport"; public static final String PUBLIC_END_PORT = "publicendport"; public static final String PUBLIC_ZONE = "publiczone"; + public static final String PURGE_RESOURCES = "purgeresources"; public static final String RECEIVED_BYTES = "receivedbytes"; public static final String RECONNECT = "reconnect"; public static final String RECOVER = "recover"; public static final String REPAIR = "repair"; public static final String REQUIRES_HVM = "requireshvm"; + public static final String RESOURCE_COUNT = "resourcecount"; public static final String RESOURCE_NAME = "resourcename"; public static final String RESOURCE_TYPE = "resourcetype"; public static final String RESOURCE_TYPE_NAME = "resourcetypename"; @@ -397,11 +427,9 @@ public class ApiConstants { public static final String QUERY_FILTER = "queryfilter"; public static final String SCHEDULE = "schedule"; public static final String SCOPE = "scope"; - public static final String SECRET_KEY = "usersecretkey"; - public static final String SECONDARY_IP = "secondaryip"; - public static final String SINCE = "since"; - public static final String KEY = "key"; public static final String SEARCH_BASE = "searchbase"; + public static final String SECONDARY_IP = "secondaryip"; + public static final String SECRET_KEY = "secretkey"; public static final String SECURITY_GROUP_IDS = "securitygroupids"; public static final String SECURITY_GROUP_NAMES = "securitygroupnames"; public static final String SECURITY_GROUP_NAME = "securitygroupname"; @@ -419,14 +447,17 @@ public class ApiConstants { public static final String SHOW_UNIQUE = "showunique"; public static final String SIGNATURE = "signature"; public static final String SIGNATURE_VERSION = "signatureversion"; + public static final String SINCE = "since"; public static final String SIZE = "size"; + public static final String SIZEGB = "sizegb"; public static final String SNAPSHOT = "snapshot"; public static final String SNAPSHOT_ID = "snapshotid"; public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid"; public static final String SNAPSHOT_TYPE = "snapshottype"; public static final String SNAPSHOT_QUIESCEVM = "quiescevm"; - public static final String SUPPORTS_STORAGE_SNAPSHOT = "supportsstoragesnapshot"; public static final String SOURCE_ZONE_ID = "sourcezoneid"; + public static final String SSL_VERIFICATION = "sslverification"; + public static final String START_ASN = "startasn"; public static final String START_DATE = "startdate"; public static final String START_ID = "startid"; public static final String START_IP = "startip"; @@ -446,6 +477,9 @@ public class ApiConstants { public static final String SYSTEM_VM_TYPE = "systemvmtype"; public static final String TAGS = "tags"; public static final String STORAGE_TAGS = "storagetags"; + public static final String SUCCESS = "success"; + public static final String SUITABLE_FOR_VM = "suitableforvirtualmachine"; + public static final String SUPPORTS_STORAGE_SNAPSHOT = "supportsstoragesnapshot"; public static final String TARGET_IQN = "targetiqn"; public static final String TEMPLATE_FILTER = "templatefilter"; public static final String TEMPLATE_ID = "templateid"; @@ -456,6 +490,7 @@ public class ApiConstants { public static final String TIMEOUT = "timeout"; public static final String TIMEZONE = "timezone"; public static final String TIMEZONEOFFSET = "timezoneoffset"; + public static final String TOTAL = "total"; public static final String TOTAL_SUBNETS = "totalsubnets"; public static final String TYPE = "type"; public static final String TRUST_STORE = "truststore"; @@ -478,6 +513,7 @@ public class ApiConstants { public static final String USERNAME = "username"; public static final String USER_CONFIGURABLE = "userconfigurable"; public static final String USER_SECURITY_GROUP_LIST = "usersecuritygrouplist"; + public static final String USER_SECRET_KEY = "usersecretkey"; public static final String USE_VIRTUAL_NETWORK = "usevirtualnetwork"; public static final String UPDATE_IN_SEQUENCE = "updateinsequence"; public static final String VALUE = "value"; @@ -487,6 +523,7 @@ public class ApiConstants { public static final String VIRTUAL_MACHINE_ID_IP = "vmidipmap"; public static final String VIRTUAL_MACHINE_COUNT = "virtualmachinecount"; public static final String VIRTUAL_MACHINE_TYPE = "virtualmachinetype"; + public static final String VIRTUAL_MACHINE_STATE = "vmstate"; public static final String VIRTUAL_MACHINES = "virtualmachines"; public static final String USAGE_ID = "usageid"; public static final String USAGE_TYPE = "usagetype"; @@ -499,6 +536,7 @@ public class ApiConstants { public static final String ISOLATED_PVLAN = "isolatedpvlan"; public static final String ISOLATED_PVLAN_TYPE = "isolatedpvlantype"; public static final String ISOLATION_URI = "isolationuri"; + public static final String IS_ALLOCATED = "isallocated"; public static final String IS_DEDICATED = "isdedicated"; public static final String TAKEN = "taken"; public static final String VM_AVAILABLE = "vmavailable"; @@ -527,6 +565,7 @@ public class ApiConstants { public static final String NETWORK_ID = "networkid"; public static final String NETWORK_FILTER = "networkfilter"; public static final String NIC_ID = "nicid"; + public static final String SPECIFY_AS_NUMBER = "specifyasnumber"; public static final String SPECIFY_VLAN = "specifyvlan"; public static final String IS_DEFAULT = "isdefault"; public static final String IS_SYSTEM = "issystem"; @@ -557,6 +596,7 @@ public class ApiConstants { public static final String ALLOCATION_STATE = "allocationstate"; public static final String MANAGED_STATE = "managedstate"; public static final String MANAGEMENT_SERVER_ID = "managementserverid"; + public static final String MANAGEMENT_SERVER_NAME = "managementservername"; public static final String STORAGE = "storage"; public static final String STORAGE_ID = "storageid"; public static final String PING_STORAGE_SERVER_IP = "pingstorageserverip"; @@ -667,6 +707,8 @@ public class ApiConstants { public static final String ASSOCIATED_NETWORK = "associatednetwork"; public static final String ASSOCIATED_NETWORK_ID = "associatednetworkid"; public static final String ASSOCIATED_NETWORK_NAME = "associatednetworkname"; + public static final String ASSOCIATED_VPC_ID = "associatedvpcid"; + public static final String ASSOCIATED_VPC_NAME = "associatedvpcname"; public static final String SOURCE_NAT_SUPPORTED = "sourcenatsupported"; public static final String RESOURCE_STATE = "resourcestate"; public static final String PROJECT_INVITE_REQUIRED = "projectinviterequired"; @@ -679,8 +721,11 @@ public class ApiConstants { public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor"; public static final String KEYWORD = "keyword"; public static final String LIST_ALL = "listall"; + public static final String LIST_ONLY_REMOVED = "listonlyremoved"; public static final String LIST_SYSTEM_VMS = "listsystemvms"; public static final String IP_RANGES = "ipranges"; + public static final String IPV4_ROUTING = "ip4routing"; + public static final String IPV4_ROUTES = "ip4routes"; public static final String IPV6_ROUTING = "ip6routing"; public static final String IPV6_ROUTES = "ip6routes"; public static final String SPECIFY_IP_RANGES = "specifyipranges"; @@ -708,6 +753,12 @@ public class ApiConstants { public static final String VSWITCH_TYPE_PUBLIC_TRAFFIC = "publicvswitchtype"; public static final String VSWITCH_NAME_GUEST_TRAFFIC = "guestvswitchname"; public static final String VSWITCH_NAME_PUBLIC_TRAFFIC = "publicvswitchname"; + + // NSX + public static final String EDGE_CLUSTER = "edgecluster"; + public static final String TIER0_GATEWAY = "tier0gateway"; + + public static final String TRANSPORT_ZONE = "transportzone"; // Tungsten-Fabric public static final String TUNGSTEN_VIRTUAL_ROUTER_UUID = "tungstenvirtualrouteruuid"; public static final String TUNGSTEN_PROVIDER_HOSTNAME = "tungstenproviderhostname"; @@ -731,6 +782,7 @@ public class ApiConstants { public static final String POLICY_UUID = "policyuuid"; public static final String RULE_UUID = "ruleuuid"; public static final String DIRECTION = "direction"; + public static final String TAGGED_RESOURCES = "taggedresources"; public static final String TAG_UUID = "taguuid"; public static final String TAG_TYPE = "tagtype"; public static final String TAG_VALUE = "tagvalue"; @@ -828,6 +880,9 @@ public class ApiConstants { public static final String FORCE_ENCAP = "forceencap"; public static final String SPLIT_CONNECTIONS = "splitconnections"; public static final String FOR_VPC = "forvpc"; + public static final String FOR_NSX = "fornsx"; + public static final String NSX_SUPPORT_LB = "nsxsupportlb"; + public static final String NSX_SUPPORTS_INTERNAL_LB = "nsxsupportsinternallb"; public static final String FOR_TUNGSTEN = "fortungsten"; public static final String SHRINK_OK = "shrinkok"; public static final String NICIRA_NVP_DEVICE_ID = "nvpdeviceid"; @@ -837,6 +892,11 @@ public class ApiConstants { public static final String NICIRA_NVP_L2_GATEWAYSERVICE_UUID = "l2gatewayserviceuuid"; public static final String NSX_LOGICAL_SWITCH = "nsxlogicalswitch"; public static final String NSX_LOGICAL_SWITCH_PORT = "nsxlogicalswitchport"; + public static final String NSX_PROVIDER_UUID = "nsxprovideruuid"; + public static final String NSX_PROVIDER_HOSTNAME = "nsxproviderhostname"; + + public static final String NSX_PROVIDER_PORT = "nsxproviderport"; + public static final String NSX_CONTROLLER_ID = "nsxcontrollerid"; public static final String S3_ACCESS_KEY = "accesskey"; public static final String S3_SECRET_KEY = "secretkey"; public static final String S3_END_POINT = "endpoint"; @@ -882,6 +942,7 @@ public class ApiConstants { public static final String AUTOSCALE_VMGROUP_NAME = "autoscalevmgroupname"; public static final String BAREMETAL_DISCOVER_NAME = "baremetaldiscovername"; public static final String BAREMETAL_RCT_URL = "baremetalrcturl"; + public static final String BATCH_SIZE = "batchsize"; public static final String UCS_DN = "ucsdn"; public static final String GSLB_PROVIDER = "gslbprovider"; public static final String EXCLUSIVE_GSLB_PROVIDER = "isexclusivegslbprovider"; @@ -926,6 +987,7 @@ public class ApiConstants { public static final String NUMBER = "number"; public static final String IS_DYNAMICALLY_SCALABLE = "isdynamicallyscalable"; public static final String ROUTING = "isrouting"; + public static final String ROUTING_MODE = "routingmode"; public static final String MAX_CONNECTIONS = "maxconnections"; public static final String SERVICE_STATE = "servicestate"; @@ -961,6 +1023,7 @@ public class ApiConstants { public static final String SUPPORTS_REGION_LEVEL_VPC = "supportsregionLevelvpc"; public static final String SUPPORTS_STRECHED_L2_SUBNET = "supportsstrechedl2subnet"; public static final String SUPPORTS_PUBLIC_ACCESS = "supportspublicaccess"; + public static final String SUPPORTS_INTERNAL_LB = "supportsinternallb"; public static final String SUPPORTS_VM_AUTOSCALING = "supportsvmautoscaling"; public static final String REGION_LEVEL_VPC = "regionlevelvpc"; public static final String STRECHED_L2_SUBNET = "strechedl2subnet"; @@ -1079,14 +1142,13 @@ public class ApiConstants { public static final String SOURCE_NAT_IP = "sourcenatipaddress"; public static final String SOURCE_NAT_IP_ID = "sourcenatipaddressid"; public static final String HAS_RULES = "hasrules"; + public static final String NSX_DETAIL_KEY = "forNsx"; public static final String DISK_PATH = "diskpath"; public static final String IMPORT_SOURCE = "importsource"; public static final String TEMP_PATH = "temppath"; public static final String OBJECT_STORAGE = "objectstore"; - public static final String HEURISTIC_RULE = "heuristicrule"; public static final String HEURISTIC_TYPE_VALID_OPTIONS = "Valid options are: ISO, SNAPSHOT, TEMPLATE and VOLUME."; - public static final String MANAGEMENT = "management"; public static final String IS_VNF = "isvnf"; public static final String VNF_NICS = "vnfnics"; @@ -1103,7 +1165,19 @@ public class ApiConstants { public static final String PARAMETER_DESCRIPTION_IS_TAG_A_RULE = "Whether the informed tag is a JS interpretable rule or not."; + public static final String WEBHOOK_ID = "webhookid"; + public static final String WEBHOOK_NAME = "webhookname"; + public static final String NFS_MOUNT_OPTIONS = "nfsmountopts"; + public static final String MOUNT_OPTIONS = "mountopts"; + + public static final String SHAREDFSVM_MIN_CPU_COUNT = "sharedfsvmmincpucount"; + public static final String SHAREDFSVM_MIN_RAM_SIZE = "sharedfsvmminramsize"; + + public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " + + "a boolean or a numeric value: if it results in a boolean value, the tariff value will be applied according to the result; if it results in a numeric value, the " + + "numeric value will be applied; if the result is neither a boolean nor a numeric value, the tariff will not be applied. If the rule is not informed, the tariff " + + "value will be applied."; /** * This enum specifies IO Drivers, each option controls specific policies on I/O. @@ -1127,6 +1201,14 @@ public String toString() { } } + public static final String PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS = "The recommended format is \"yyyy-MM-dd'T'HH:mm:ssZ\" (e.g.: \"2023-01-01T12:00:00+0100\"); " + + "however, the following formats are also accepted: \"yyyy-MM-dd HH:mm:ss\" (e.g.: \"2023-01-01 12:00:00\") and \"yyyy-MM-dd\" (e.g.: \"2023-01-01\" - if the time is not " + + "added, it will be interpreted as \"00:00:00\"). If the recommended format is not used, the date will be considered in the server timezone."; + + public static final String PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS = "The recommended format is \"yyyy-MM-dd'T'HH:mm:ssZ\" (e.g.: \"2023-01-01T12:00:00+0100\"); " + + "however, the following formats are also accepted: \"yyyy-MM-dd HH:mm:ss\" (e.g.: \"2023-01-01 12:00:00\") and \"yyyy-MM-dd\" (e.g.: \"2023-01-01\" - if the time is not " + + "added, it will be interpreted as \"23:59:59\"). If the recommended format is not used, the date will be considered in the server timezone."; + public enum BootType { UEFI, BIOS; diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiServerService.java b/api/src/main/java/org/apache/cloudstack/api/ApiServerService.java index 54fda7e36b82..cbbcdc3bda42 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiServerService.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiServerService.java @@ -21,7 +21,9 @@ import javax.servlet.http.HttpSession; +import com.cloud.domain.Domain; import com.cloud.exception.CloudAuthenticationException; +import com.cloud.user.UserAccount; public interface ApiServerService { public boolean verifyRequest(Map requestParameters, Long userId, InetAddress remoteAddress) throws ServerApiException; @@ -42,4 +44,8 @@ public ResponseObject loginUser(HttpSession session, String username, String pas public String handleRequest(Map params, String responseType, StringBuilder auditTrailSb) throws ServerApiException; public Class getCmdClass(String cmdName); + + boolean forgotPassword(UserAccount userAccount, Domain domain); + + boolean resetPassword(UserAccount userAccount, String token, String password); } diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java index 865ec7456409..6859b0a7f406 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api; -import org.apache.log4j.Logger; /** * queryAsyncJobResult API command. @@ -30,7 +29,6 @@ public abstract class BaseAsyncCmd extends BaseCmd { public static final String migrationSyncObject = "migration"; public static final String snapshotHostSyncObject = "snapshothost"; public static final String gslbSyncObject = "globalserverloadbalancer"; - private static final Logger s_logger = Logger.getLogger(BaseAsyncCmd.class.getName()); private Object job; diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseCmd.java index f32922819b01..457afdc88478 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseCmd.java @@ -31,6 +31,7 @@ import javax.inject.Inject; +import com.cloud.bgp.BGPService; import org.apache.cloudstack.acl.ProjectRoleService; import org.apache.cloudstack.acl.RoleService; import org.apache.cloudstack.acl.RoleType; @@ -38,7 +39,7 @@ import org.apache.cloudstack.alert.AlertService; import org.apache.cloudstack.annotation.AnnotationService; import org.apache.cloudstack.context.CallContext; -import org.apache.cloudstack.network.element.InternalLoadBalancerElementService; +import org.apache.cloudstack.network.RoutedIpv4Manager; import org.apache.cloudstack.network.lb.ApplicationLoadBalancerService; import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService; import org.apache.cloudstack.query.QueryService; @@ -47,7 +48,8 @@ import org.apache.cloudstack.storage.template.VnfTemplateManager; import org.apache.cloudstack.usage.UsageService; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.configuration.ConfigurationService; import com.cloud.exception.ConcurrentOperationException; @@ -95,7 +97,7 @@ import com.cloud.vm.snapshot.VMSnapshotService; public abstract class BaseCmd { - private static final Logger s_logger = Logger.getLogger(BaseCmd.class.getName()); + protected transient Logger logger = LogManager.getLogger(getClass()); public static final String RESPONSE_SUFFIX = "response"; public static final String RESPONSE_TYPE_XML = HttpUtils.RESPONSE_TYPE_XML; public static final String RESPONSE_TYPE_JSON = HttpUtils.RESPONSE_TYPE_JSON; @@ -200,8 +202,6 @@ public static enum CommandType { @Inject public AffinityGroupService _affinityGroupService; @Inject - public InternalLoadBalancerElementService _internalLbElementSvc; - @Inject public InternalLoadBalancerVMService _internalLbSvc; @Inject public NetworkModel _ntwkModel; @@ -219,7 +219,11 @@ public static enum CommandType { public VnfTemplateManager vnfTemplateManager; @Inject public BucketApiService _bucketService; + @Inject + public BGPService bgpService; + @Inject + public RoutedIpv4Manager routedIpv4Manager; public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException; @@ -374,7 +378,7 @@ public List getParamFields() { if (roleIsAllowed) { validFields.add(field); } else { - s_logger.debug("Ignoring parameter " + parameterAnnotation.name() + " as the caller is not authorized to pass it in"); + logger.debug("Ignoring parameter " + parameterAnnotation.name() + " as the caller is not authorized to pass it in"); } } @@ -419,7 +423,7 @@ public boolean isDisplay(){ if(!isDisplay) break; } catch (Exception e){ - s_logger.trace("Caught exception while checking first class entities for display property, continuing on", e); + logger.trace("Caught exception while checking first class entities for display property, continuing on", e); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java index 052d7d1e8b72..be95547a8a73 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ResponseObject.ResponseView; import org.apache.cloudstack.api.command.ResponseViewProvider; @@ -28,7 +27,6 @@ import com.cloud.user.Account; public abstract class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd implements ResponseViewProvider { - public Logger logger = getLogger(); protected static final String s_name = "listtemplatepermissionsresponse"; ///////////////////////////////////////////////////// @@ -59,9 +57,6 @@ public long getEntityOwnerId() { return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked } - protected Logger getLogger() { - return Logger.getLogger(BaseListTemplateOrIsoPermissionsCmd.class); - } @Override public String getCommandName() { diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java index 08f390f19724..9a8282df1121 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java @@ -16,15 +16,15 @@ // under the License. package org.apache.cloudstack.api; -import org.apache.log4j.Logger; +import com.cloud.cpu.CPU; import org.apache.cloudstack.api.response.GuestOSResponse; import org.apache.cloudstack.api.response.TemplateResponse; +import org.apache.commons.lang3.StringUtils; import java.util.Collection; import java.util.Map; public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(BaseUpdateTemplateOrIsoCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -79,6 +79,11 @@ public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { description = "optional boolean field, which indicates if details should be cleaned up or not (if set to true, details removed for this resource, details field ignored; if false or not set, no action)") private Boolean cleanupDetails; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the template/ISO. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -143,4 +148,11 @@ public Map getDetails() { public boolean isCleanupDetails(){ return cleanupDetails == null ? false : cleanupDetails.booleanValue(); } + + public CPU.CPUArch getCPUArch() { + if (StringUtils.isBlank(arch)) { + return null; + } + return CPU.CPUArch.fromType(arch); + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java index 410ffefb00dd..e6ee0897db02 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; @@ -27,16 +26,12 @@ import com.cloud.exception.InvalidParameterValueException; public abstract class BaseUpdateTemplateOrIsoPermissionsCmd extends BaseCmd { - public Logger _logger = getLogger(); protected String _name = getResponseName(); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// - protected Logger getLogger() { - return Logger.getLogger(BaseUpdateTemplateOrIsoPermissionsCmd.class); - } protected String getResponseName() { return "updatetemplateorisopermissionsresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java index ef759aaf9c3e..ea0d946ee417 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java +++ b/api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java @@ -22,6 +22,9 @@ import java.util.Map; import java.util.Set; +import com.cloud.bgp.ASNumber; +import com.cloud.bgp.ASNumberRange; + import org.apache.cloudstack.storage.object.Bucket; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupResponse; @@ -31,11 +34,14 @@ import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse; +import org.apache.cloudstack.api.response.ASNRangeResponse; +import org.apache.cloudstack.api.response.ASNumberResponse; import org.apache.cloudstack.api.response.AsyncJobResponse; import org.apache.cloudstack.api.response.AutoScalePolicyResponse; import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse; import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse; import org.apache.cloudstack.api.response.BackupOfferingResponse; +import org.apache.cloudstack.api.response.BackupRepositoryResponse; import org.apache.cloudstack.api.response.BackupResponse; import org.apache.cloudstack.api.response.BackupScheduleResponse; import org.apache.cloudstack.api.response.BucketResponse; @@ -54,6 +60,7 @@ import org.apache.cloudstack.api.response.DomainRouterResponse; import org.apache.cloudstack.api.response.EventResponse; import org.apache.cloudstack.api.response.ExtractResponse; +import org.apache.cloudstack.api.response.SharedFSResponse; import org.apache.cloudstack.api.response.FirewallResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse; @@ -139,6 +146,7 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.backup.Backup; import org.apache.cloudstack.backup.BackupOffering; +import org.apache.cloudstack.backup.BackupRepository; import org.apache.cloudstack.backup.BackupSchedule; import org.apache.cloudstack.config.Configuration; import org.apache.cloudstack.config.ConfigurationGroup; @@ -151,6 +159,7 @@ import org.apache.cloudstack.region.PortableIpRange; import org.apache.cloudstack.region.Region; import org.apache.cloudstack.secstorage.heuristics.Heuristic; +import org.apache.cloudstack.storage.sharedfs.SharedFS; import org.apache.cloudstack.storage.object.ObjectStore; import org.apache.cloudstack.usage.Usage; @@ -345,9 +354,11 @@ public interface ResponseGenerator { SecurityGroupResponse createSecurityGroupResponse(SecurityGroup group); - ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode, String url); + ExtractResponse createImageExtractResponse(Long id, Long zoneId, Long accountId, String mode, String url); + + ExtractResponse createVolumeExtractResponse(Long id, Long zoneId, Long accountId, String mode, String url); - ExtractResponse createExtractResponse(Long id, Long zoneId, Long accountId, String mode, String url); + ExtractResponse createSnapshotExtractResponse(Long id, Long zoneId, Long accountId, String url); String toSerializedString(CreateCmdResponse response, String responseType); @@ -549,4 +560,12 @@ List createTemplateResponses(ResponseView view, VirtualMachine ObjectStoreResponse createObjectStoreResponse(ObjectStore os); BucketResponse createBucketResponse(Bucket bucket); + + ASNRangeResponse createASNumberRangeResponse(ASNumberRange asnRange); + + ASNumberResponse createASNumberResponse(ASNumber asn); + + BackupRepositoryResponse createBackupRepositoryResponse(BackupRepository repository); + + SharedFSResponse createSharedFSResponse(ResponseView view, SharedFS sharedFS); } diff --git a/api/src/main/java/org/apache/cloudstack/api/auth/APIAuthenticationType.java b/api/src/main/java/org/apache/cloudstack/api/auth/APIAuthenticationType.java index 5ba9d182daa0..1f78708f7e58 100644 --- a/api/src/main/java/org/apache/cloudstack/api/auth/APIAuthenticationType.java +++ b/api/src/main/java/org/apache/cloudstack/api/auth/APIAuthenticationType.java @@ -17,5 +17,5 @@ package org.apache.cloudstack.api.auth; public enum APIAuthenticationType { - LOGIN_API, LOGOUT_API, READONLY_API, LOGIN_2FA_API + LOGIN_API, LOGOUT_API, READONLY_API, LOGIN_2FA_API, PASSWORD_RESET } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java index 945bb956c3eb..6dbc6acc59a9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java @@ -21,7 +21,6 @@ import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ @APICommand(name = "createAccount", description = "Creates an account", responseObject = AccountResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = true, responseHasSensitiveInfo = true) public class CreateAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateAccountCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java index 9a0ea4e9ec0e..a90fc4aebe9c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.region.RegionService; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.user.Account; @@ -39,7 +38,6 @@ @APICommand(name = "deleteAccount", description = "Deletes a account, and all users associated with this account", responseObject = SuccessResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAccountCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAccountCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -91,12 +89,11 @@ public void execute() { CallContext.current().setEventDetails("Account ID: " + (account != null ? account.getUuid() : getId())); // Account not found is already handled by service boolean result = _regionService.deleteUserAccount(this); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - setResponseObject(response); - } else { + if (!result) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete user account and all corresponding users"); } + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); } @Override diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java index 91b0673e186e..55293eca619e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -43,7 +42,6 @@ @APICommand(name = "disableAccount", description = "Disables an account", responseObject = AccountResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DisableAccountCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableAccountCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java index cc37dc237134..da96383f1345 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ @APICommand(name = "enableAccount", description = "Enables an account", responseObject = AccountResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class EnableAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(EnableAccountCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java index a430914a25a1..d7847373e927 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.account; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class LockAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LockAccountCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java index 36d299bcfc85..91cbb90e4da4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.response.RoleResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -43,7 +42,6 @@ @APICommand(name = "updateAccount", description = "Updates account information for the authenticated user", responseObject = AccountResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateAccountCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/DisableRoleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/DisableRoleCmd.java new file mode 100644 index 000000000000..80cb92c8362f --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/DisableRoleCmd.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.acl; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import org.apache.cloudstack.acl.Role; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.RoleResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; + +@APICommand(name = "disableRole", description = "Disables a role", responseObject = SuccessResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin}) +public class DisableRoleCmd extends BaseCmd { + + @Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, required = true, entityType = RoleResponse.class, + description = "ID of the role", validations = {ApiArgValidator.PositiveNumber}) + private Long roleId; + + public Long getRoleId() { + return roleId; + } + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + Role role = roleService.findRole(getRoleId()); + if (role == null) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot find the role with provided id"); + } + CallContext.current().setEventDetails("Role id: " + role.getId()); + boolean result = roleService.disableRole(role); + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setSuccess(result); + setResponseObject(response); + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/EnableRoleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/EnableRoleCmd.java new file mode 100644 index 000000000000..c4a6505d52f6 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/EnableRoleCmd.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.acl; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import org.apache.cloudstack.acl.Role; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.RoleResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; + +@APICommand(name = "enableRole", description = "Enables a role", responseObject = SuccessResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin}) +public class EnableRoleCmd extends BaseCmd { + + @Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, required = true, entityType = RoleResponse.class, + description = "ID of the role", validations = {ApiArgValidator.PositiveNumber}) + private Long roleId; + + public Long getRoleId() { + return roleId; + } + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + Role role = roleService.findRole(getRoleId()); + if (role == null) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Cannot find the role with provided id"); + } + CallContext.current().setEventDetails("Role id: " + role.getId()); + boolean result = roleService.enableRole(role); + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setSuccess(result); + setResponseObject(response); + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ListRolesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ListRolesCmd.java index fef2b27eaa5a..d82cc852e4ff 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ListRolesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/ListRolesCmd.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; +import com.cloud.exception.InvalidParameterValueException; import org.apache.cloudstack.acl.Role; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -51,6 +52,9 @@ public class ListRolesCmd extends BaseListCmd { @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "List role by role type, valid options are: Admin, ResourceAdmin, DomainAdmin, User.") private String roleType; + @Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "List role by role type status, valid options are: enabled, disabled") + private String roleState; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -70,6 +74,17 @@ public RoleType getRoleType() { return null; } + public Role.State getRoleState() { + if (roleState == null) { + return null; + } + try { + return Role.State.valueOf(roleState.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new InvalidParameterValueException("Unrecognized role state value"); + } + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -93,6 +108,7 @@ private void setupResponse(final Pair, Integer> roles) { roleResponse.setDescription(role.getDescription()); roleResponse.setIsDefault(role.isDefault()); roleResponse.setPublicRole(role.isPublicRole()); + roleResponse.setState(role.getState().toString()); roleResponse.setObjectName("role"); roleResponses.add(roleResponse); } @@ -104,14 +120,16 @@ private void setupResponse(final Pair, Integer> roles) { @Override public void execute() { Pair, Integer> roles; + Role.State state = getRoleState(); + String roleStateStr = state != null ? state.toString() : null; if (getId() != null && getId() > 0L) { roles = new Pair<>(Collections.singletonList(roleService.findRole(getId(), true)), 1); } else if (StringUtils.isNotBlank(getName()) || StringUtils.isNotBlank(getKeyword())) { - roles = roleService.findRolesByName(getName(), getKeyword(), getStartIndex(), getPageSizeVal()); + roles = roleService.findRolesByName(getName(), getKeyword(), roleStateStr, getStartIndex(), getPageSizeVal()); } else if (getRoleType() != null) { - roles = roleService.findRolesByType(getRoleType(), getStartIndex(), getPageSizeVal()); + roles = roleService.findRolesByType(getRoleType(), roleStateStr, getStartIndex(), getPageSizeVal()); } else { - roles = roleService.listRoles(getStartIndex(), getPageSizeVal()); + roles = roleService.listRoles(roleStateStr, getStartIndex(), getPageSizeVal()); } setupResponse(roles); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/RoleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/RoleCmd.java index 4c317d06b136..b3d816adc3fb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/RoleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/RoleCmd.java @@ -59,6 +59,7 @@ protected void setupResponse(final Role role) { response.setRoleType(role.getRoleType()); response.setDescription(role.getDescription()); response.setPublicRole(role.isPublicRole()); + response.setState(role.getState().toString()); response.setResponseName(getCommandName()); response.setObjectName("role"); setResponseObject(response); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java index a965624a2a94..7397697bd2cc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "acquirePodIpAddress", description = "Allocates IP addresses in respective Pod of a Zone", responseObject = AcquirePodIpCmdResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AcquirePodIpCmdByAdmin extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AcquirePodIpCmdByAdmin.class.getName()); private static final String s_name = "acquirepodipaddress"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java index 56f41b5f58ed..672691ffbd8f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject.ResponseView; @@ -27,5 +26,4 @@ @APICommand(name = "associateIpAddress", description = "Acquires and associates a public IP to an account.", responseObject = IPAddressResponse.class, responseView = ResponseView.Full, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AssociateIPAddrCmdByAdmin extends AssociateIPAddrCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmdByAdmin.class.getName()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java index b6bfbcaa1e22..7d4cab6a0ac4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java @@ -16,7 +16,6 @@ //under the License. package org.apache.cloudstack.api.command.admin.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -31,7 +30,6 @@ @APICommand(name = "releasePodIpAddress", description = "Releases a Pod IP back to the Pod", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleasePodIpCmdByAdmin extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ReleasePodIpCmdByAdmin.class.getName()); private static final String s_name = "releasepodipresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java index 7bf9b64481b3..43e70838e18f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.affinitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject.ResponseView; @@ -33,5 +32,4 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateVMAffinityGroupCmdByAdmin extends UpdateVMAffinityGroupCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVMAffinityGroupCmdByAdmin.class.getName()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/alert/GenerateAlertCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/alert/GenerateAlertCmd.java index 9446272df6e6..30f3bbbec1b2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/alert/GenerateAlertCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/alert/GenerateAlertCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; @@ -35,7 +34,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GenerateAlertCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(GenerateAlertCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java index 617d1104eda5..7fa66ffff1f4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ @APICommand(name = "createCounter", description = "Adds metric counter for VM auto scaling", responseObject = CounterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateCounterCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateCounterCmd.class.getName()); private static final String s_name = "counterresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java index e1f7859a56b5..b7b2ce5cb70d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ @APICommand(name = "deleteCounter", description = "Deletes a counter for VM auto scaling", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteCounterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteCounterCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -55,7 +53,7 @@ public void execute() { try { result = _autoScaleService.deleteCounter(getId()); } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } @@ -63,7 +61,7 @@ public void execute() { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - s_logger.warn("Failed to delete counter with Id: " + getId()); + logger.warn("Failed to delete counter with Id: " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete counter."); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java index 1cd6f4a83280..9de06715ee74 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.backup.BackupOffering; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.user.Account; @@ -39,7 +38,6 @@ @APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0") public class UpdateBackupOfferingCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(UpdateBackupOfferingCmd.class.getName()); @Inject private BackupManager backupManager; @@ -100,7 +98,7 @@ public void execute() { this.setResponseObject(response); } catch (CloudRuntimeException e) { ApiErrorCode paramError = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR; - LOGGER.error(String.format("Failed to update Backup Offering [id: %s] due to: [%s].", id, e.getMessage()), e); + logger.error(String.format("Failed to update Backup Offering [id: %s] due to: [%s].", id, e.getMessage()), e); throw new ServerApiException(paramError, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/CreateASNRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/CreateASNRangeCmd.java new file mode 100644 index 000000000000..beacba850c3f --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/CreateASNRangeCmd.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.bgp; + +import com.cloud.bgp.ASNumberRange; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ASNRangeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; + +@APICommand(name = "createASNRange", + description = "Creates a range of Autonomous Systems for BGP Dynamic Routing", + responseObject = ASNRangeResponse.class, + entityType = {ASNumberRange.class}, + since = "4.20.0", + authorized = {RoleType.Admin}) +public class CreateASNRangeCmd extends BaseCmd { + + @Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class, + description = "the zone ID", required = true) + private Long zoneId; + + @Parameter(name = ApiConstants.START_ASN, type = CommandType.LONG, required=true, description = "the start AS Number") + private Long startASNumber; + + @Parameter(name = ApiConstants.END_ASN, type = CommandType.LONG, required=true, description = "the end AS Number") + private Long endASNumber; + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + ASNumberRange asnRange = bgpService.createASNumberRange(zoneId, startASNumber, endASNumber); + ASNRangeResponse response = _responseGenerator.createASNumberRangeResponse(asnRange); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (Exception e) { + String msg = String.format("Cannot create AS Number Range %s-%s for zone %s: %s", startASNumber, endASNumber, zoneId, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, msg); + } + } + + public Long getZoneId() { + return zoneId; + } + + public Long getStartASNumber() { + return startASNumber; + } + + public Long getEndASNumber() { + return endASNumber; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/DeleteASNRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/DeleteASNRangeCmd.java new file mode 100644 index 000000000000..33e139315bf6 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/DeleteASNRangeCmd.java @@ -0,0 +1,79 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.bgp; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ASNRangeResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; + +@APICommand(name = "deleteASNRange", + description = "deletes a range of Autonomous Systems for BGP Dynamic Routing", + responseObject = SuccessResponse.class, + since = "4.20.0", + authorized = {RoleType.Admin}) +public class DeleteASNRangeCmd extends BaseCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + //////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + entityType = ASNRangeResponse.class, + required = true, + description = "ID of the AS range") + private Long id; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + if (bgpService.deleteASRange(getId())) { + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove AS range: " + getId()); + } + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/ListASNRangesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/ListASNRangesCmd.java new file mode 100644 index 000000000000..82e545811029 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/ListASNRangesCmd.java @@ -0,0 +1,79 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.bgp; + +import com.cloud.bgp.ASNumberRange; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ASNRangeResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ZoneResponse; + +import java.util.ArrayList; +import java.util.List; + +@APICommand(name = "listASNRanges", + description = "List Autonomous Systems Number Ranges", + responseObject = ASNRangeResponse.class, + entityType = {ASNumberRange.class}, + since = "4.20.0", + authorized = {RoleType.Admin}) +public class ListASNRangesCmd extends BaseListCmd { + + @Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class, + description = "the zone ID") + private Long zoneId; + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + List ranges = bgpService.listASNumberRanges(zoneId); + ListResponse response = new ListResponse<>(); + List responses = new ArrayList<>(); + for (ASNumberRange asnRange : ranges) { + responses.add(_responseGenerator.createASNumberRangeResponse(asnRange)); + } + response.setResponses(responses); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (Exception e) { + String msg = String.format("Error listing AS Number Ranges: %s", e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, msg); + } + } + + public Long getZoneId() { + return zoneId; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/ReleaseASNumberCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/ReleaseASNumberCmd.java new file mode 100644 index 000000000000..687f60dc6da8 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/bgp/ReleaseASNumberCmd.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.bgp; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import com.cloud.utils.Pair; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.api.response.ZoneResponse; + +@APICommand(name = "releaseASNumber", + description = "Releases an AS Number back to the pool", + since = "4.20.0", + authorized = {RoleType.Admin}, + responseObject = SuccessResponse.class, + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false) +public class ReleaseASNumberCmd extends BaseCmd { + + @Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class, + description = "the zone ID", required = true) + private Long zoneId; + + @Parameter(name= ApiConstants.AS_NUMBER, type=CommandType.LONG, description="the AS Number to be released", + required = true) + private Long asNumber; + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + Pair resultPair = bgpService.releaseASNumber(zoneId, asNumber, false); + Boolean result = resultPair.first(); + if (!result) { + String details = resultPair.second(); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Cannot release AS Number %s: %s", asNumber, details)); + } + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setDisplayText(String.format("AS Number %s is released successfully", asNumber)); + setResponseObject(response); + } catch (Exception e) { + String msg = String.format("Error releasing AS Number %s: %s", asNumber, e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, msg); + } + } + + public Long getZoneId() { + return zoneId; + } + + public Long getAsNumber() { + return asNumber; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/ca/IssueCertificateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/ca/IssueCertificateCmd.java index 4c543fdb6a89..463af000f58b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/ca/IssueCertificateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/ca/IssueCertificateCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.framework.ca.Certificate; import org.apache.cloudstack.utils.security.CertUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; @@ -49,7 +48,6 @@ since = "4.11.0", authorized = {RoleType.Admin}) public class IssueCertificateCmd extends BaseAsyncCmd { - private static final Logger LOG = Logger.getLogger(IssueCertificateCmd.class); @Inject @@ -132,7 +130,7 @@ public void execute() { certificateResponse.setCaCertificate(CertUtils.x509CertificatesToPem(certificate.getCaCertificates())); } } catch (final IOException e) { - LOG.error("Failed to generate and convert client certificate(s) to PEM due to error: ", e); + logger.error("Failed to generate and convert client certificate(s) to PEM due to error: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to process and return client certificate"); } certificateResponse.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java index df48b2511b60..69cb43ce40ec 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java @@ -20,8 +20,8 @@ import java.util.ArrayList; import java.util.List; +import com.cloud.cpu.CPU; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +42,6 @@ @APICommand(name = "addCluster", description = "Adds a new cluster", responseObject = ClusterResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class AddClusterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName()); @Parameter(name = ApiConstants.CLUSTER_NAME, type = CommandType.STRING, required = true, description = "the cluster name") @@ -69,6 +68,11 @@ public class AddClusterCmd extends BaseCmd { description = "hypervisor type of the cluster: XenServer,KVM,VMware,Hyperv,BareMetal,Simulator,Ovm3") private String hypervisor; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the cluster. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + @Parameter(name = ApiConstants.CLUSTER_TYPE, type = CommandType.STRING, required = true, description = "type of the cluster: CloudManaged, ExternalManaged") private String clusterType; @@ -206,6 +210,10 @@ public ApiCommandResourceType getApiResourceType() { return ApiCommandResourceType.Cluster; } + public CPU.CPUArch getArch() { + return CPU.CPUArch.fromType(arch); + } + @Override public void execute() { try { @@ -226,10 +234,10 @@ public void execute() { this.setResponseObject(response); } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); for (String proxyObj : ex.getIdProxyList()) { e.addProxyObject(proxyObj); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java index 497cef4c3eca..2b1cfe8bcb58 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.cluster; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ @APICommand(name = "deleteCluster", description = "Deletes a cluster.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteClusterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteClusterCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java index d83330c664a9..67d0678410cf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "listClusters", description = "Lists clusters.", responseObject = ClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListClustersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListClustersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java index dd527fb409af..c4ee87380ed9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java @@ -16,8 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.admin.cluster; +import com.cloud.cpu.CPU; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -30,11 +30,11 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.org.Cluster; import com.cloud.user.Account; +import org.apache.commons.lang3.StringUtils; @APICommand(name = "updateCluster", description = "Updates an existing cluster", responseObject = ClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateClusterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName()); @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ClusterResponse.class, required = true, description = "the ID of the Cluster") @@ -55,6 +55,11 @@ public class UpdateClusterCmd extends BaseCmd { @Parameter(name = ApiConstants.MANAGED_STATE, type = CommandType.STRING, description = "whether this cluster is managed by cloudstack") private String managedState; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the cluster. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + public String getClusterName() { return clusterName; } @@ -110,6 +115,13 @@ public ApiCommandResourceType getApiResourceType() { return ApiCommandResourceType.Cluster; } + public CPU.CPUArch getArch() { + if (StringUtils.isBlank(arch)) { + return null; + } + return CPU.CPUArch.fromType(arch); + } + @Override public void execute() { Cluster cluster = _resourceService.getCluster(getId()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgGroupsByCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgGroupsByCmd.java index 46ab10cb2bcd..d735218169d6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgGroupsByCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgGroupsByCmd.java @@ -27,14 +27,12 @@ import org.apache.cloudstack.api.response.ConfigurationGroupResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.config.ConfigurationGroup; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; @APICommand(name = ListCfgGroupsByCmd.APINAME, description = "Lists all configuration groups (primarily used for UI).", responseObject = ConfigurationGroupResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0") public class ListCfgGroupsByCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListCfgGroupsByCmd.class.getName()); public static final String APINAME = "listConfigurationGroups"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java index 80abe5d3e8ff..e365d8bc2dc7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -47,7 +46,6 @@ public class ListCfgsByCmd extends BaseListCmd { public static final String APINAME = "listConfigurations"; - public static final Logger s_logger = Logger.getLogger(ListCfgsByCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java index 4f5186a6df69..78fa31beeb48 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListCmd; @@ -29,7 +28,6 @@ @APICommand(name = "listDeploymentPlanners", description = "Lists all DeploymentPlanners available.", responseObject = DeploymentPlannersResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDeploymentPlannersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDeploymentPlannersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListHypervisorCapabilitiesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListHypervisorCapabilitiesCmd.java index 64f1c19b70cd..e7cc9e0234e2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListHypervisorCapabilitiesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListHypervisorCapabilitiesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListHypervisorCapabilitiesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListHypervisorCapabilitiesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java index ada389e00930..f114b263b634 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.ClusterResponse; @@ -41,7 +40,6 @@ @APICommand(name = "resetConfiguration", description = "Resets a configuration. The configuration will be set to default value for global setting, and removed from account_details or domain_details for Account/Domain settings", responseObject = ConfigurationResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0") public class ResetCfgCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ResetCfgCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java index 63dc51452f0f..dbf478df7012 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java @@ -19,7 +19,6 @@ import com.cloud.utils.crypt.DBEncryptionUtil; import org.apache.cloudstack.acl.RoleService; import org.apache.cloudstack.api.response.DomainResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ @APICommand(name = "updateConfiguration", description = "Updates a configuration.", responseObject = ConfigurationResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateCfgCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateCfgCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java index 6c70b24653d8..01f7af108416 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.config; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateHypervisorCapabilitiesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateHypervisorCapabilitiesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/diagnostics/RunDiagnosticsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/diagnostics/RunDiagnosticsCmd.java index 3d3c7410dc58..4537eb6f215c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/diagnostics/RunDiagnosticsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/diagnostics/RunDiagnosticsCmd.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.diagnostics.DiagnosticsService; import org.apache.cloudstack.diagnostics.DiagnosticsType; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InsufficientCapacityException; @@ -53,7 +52,6 @@ authorized = {RoleType.Admin}, since = "4.12.0.0") public class RunDiagnosticsCmd extends BaseAsyncCmd { - private static final Logger LOGGER = Logger.getLogger(RunDiagnosticsCmd.class); @Inject private DiagnosticsService diagnosticsService; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java index 53b29a37f8f1..145ff6ba7823 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.direct.download.DirectDownloadCertificate; import org.apache.cloudstack.direct.download.DirectDownloadCertificateHostMap; import org.apache.cloudstack.direct.download.DirectDownloadManager; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -63,7 +62,6 @@ public class ListTemplateDirectDownloadCertificatesCmd extends BaseListCmd { description = "if set to true: include the hosts where the certificate is uploaded to") private Boolean listHosts; - private static final Logger LOG = Logger.getLogger(ListTemplateDirectDownloadCertificatesCmd.class); public boolean isListHosts() { return listHosts != null && listHosts; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/RevokeTemplateDirectDownloadCertificateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/RevokeTemplateDirectDownloadCertificateCmd.java index e44ebd312742..eb9031cbc587 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/RevokeTemplateDirectDownloadCertificateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/RevokeTemplateDirectDownloadCertificateCmd.java @@ -41,7 +41,6 @@ import org.apache.cloudstack.direct.download.DirectDownloadManager.HostCertificateStatus; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -57,7 +56,6 @@ public class RevokeTemplateDirectDownloadCertificateCmd extends BaseCmd { @Inject DirectDownloadManager directDownloadManager; - private static final Logger LOG = Logger.getLogger(RevokeTemplateDirectDownloadCertificateCmd.class); @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DirectDownloadCertificateResponse.class, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java index 0fa1797c7fe8..c5c102be56d6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.direct.download.DirectDownloadCertificate; import org.apache.cloudstack.direct.download.DirectDownloadManager; import org.apache.cloudstack.direct.download.DirectDownloadManager.HostCertificateStatus; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -49,7 +48,6 @@ public class UploadTemplateDirectDownloadCertificateCmd extends BaseCmd { @Inject DirectDownloadManager directDownloadManager; - private static final Logger LOG = Logger.getLogger(UploadTemplateDirectDownloadCertificateCmd.class); @Parameter(name = ApiConstants.CERTIFICATE, type = BaseCmd.CommandType.STRING, required = true, length = 65535, description = "SSL certificate") @@ -97,7 +95,7 @@ public void execute() { } try { - LOG.debug("Uploading certificate " + name + " to agents for Direct Download"); + logger.debug("Uploading certificate " + name + " to agents for Direct Download"); Pair> uploadStatus = directDownloadManager.uploadCertificateToHosts(certificate, name, hypervisor, zoneId, hostId); DirectDownloadCertificate certificate = uploadStatus.first(); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java index f6e09695f88b..c7f06920bb8d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.domain; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = { RoleType.Admin, RoleType.DomainAdmin }) public class CreateDomainCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateDomainCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java index e0783b63098f..db3bae25e399 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.region.RegionService; -import org.apache.log4j.Logger; import com.cloud.domain.Domain; import com.cloud.event.EventTypes; @@ -40,7 +39,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = { RoleType.Admin, RoleType.DomainAdmin }) public class DeleteDomainCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteDomainCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java index 72614627f31f..8514bb6dda56 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java @@ -22,7 +22,6 @@ import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "listDomainChildren", description = "Lists all children domains belonging to a specified domain", responseObject = DomainResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDomainChildrenCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDomainChildrenCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java index 8b6661f27ff2..b91e56dcaef0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java @@ -20,11 +20,6 @@ import java.util.EnumSet; import java.util.List; -import com.cloud.server.ResourceIcon; -import com.cloud.server.ResourceTag; -import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants.DomainDetails; @@ -34,14 +29,17 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ResourceIconResponse; +import org.apache.commons.collections.CollectionUtils; import com.cloud.domain.Domain; import com.cloud.exception.InvalidParameterValueException; +import com.cloud.server.ResourceIcon; +import com.cloud.server.ResourceTag; @APICommand(name = "listDomains", description = "Lists domains and provides detailed information for listed domains", responseObject = DomainResponse.class, responseView = ResponseView.Restricted, entityType = {Domain.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDomainsCmd extends BaseListCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListDomainsCmd.class.getName()); private static final String s_name = "listdomainsresponse"; @@ -73,6 +71,9 @@ public class ListDomainsCmd extends BaseListCmd implements UserCmd { description = "flag to display the resource icon for domains") private Boolean showIcon; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for resource type to return usage", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -112,10 +113,14 @@ public EnumSet getDetails() throws InvalidParameterValueException return dv; } - public Boolean getShowIcon() { + public boolean getShowIcon() { return showIcon != null ? showIcon : false; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -130,12 +135,17 @@ public void execute() { ListResponse response = _queryService.searchForDomains(this); response.setResponseName(getCommandName()); this.setResponseObject(response); - if (response != null && response.getCount() > 0 && getShowIcon()) { - updateDomainResponse(response.getResponses()); - } + updateDomainResponse(response.getResponses()); } - private void updateDomainResponse(List response) { + protected void updateDomainResponse(List response) { + if (CollectionUtils.isEmpty(response)) { + return; + } + _resourceLimitService.updateTaggedResourceLimitsAndCountsForDomains(response, getTag()); + if (!getShowIcon()) { + return; + } for (DomainResponse domainResponse : response) { ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Domain, domainResponse.getId()); if (resourceIcon == null) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java index db4030da7726..353cb852bfdf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "updateDomain", description = "Updates a domain with a new name", responseObject = DomainResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateDomainCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateDomainCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java index 0ad500712878..b854e8389c4f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.guest; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ @APICommand(name = "addGuestOs", description = "Add a new guest OS type", responseObject = GuestOSResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddGuestOsCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddGuestOsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java index 0ddd21994e3e..3fdfebb54bf5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.guest; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ @APICommand(name = "addGuestOsMapping", description = "Adds a guest OS name to hypervisor OS name mapping", responseObject = GuestOsMappingResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddGuestOsMappingCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddGuestOsMappingCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/GetHypervisorGuestOsNamesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/GetHypervisorGuestOsNamesCmd.java index 795177082900..da920a2ec2d0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/GetHypervisorGuestOsNamesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/GetHypervisorGuestOsNamesCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.HypervisorGuestOsNamesResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.user.Account; @@ -35,8 +34,6 @@ @APICommand(name = GetHypervisorGuestOsNamesCmd.APINAME, description = "Gets the guest OS names in the hypervisor", responseObject = HypervisorGuestOsNamesResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin}) public class GetHypervisorGuestOsNamesCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(GetHypervisorGuestOsNamesCmd.class.getName()); - public static final String APINAME = "getHypervisorGuestOsNames"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java index 29ae0b4f1884..23e62cdc7810 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "listGuestOsMapping", description = "Lists all available OS mappings for given hypervisor", responseObject = GuestOsMappingResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListGuestOsMappingCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListGuestOsMappingCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java index 14beb83e073f..d38682ce5bb4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.guest; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveGuestOsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveGuestOsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java index 0a72b7e04515..a472ab672c55 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.guest; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveGuestOsMappingCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveGuestOsMappingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java index 25f022b3b515..c98cd149ef30 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.guest; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -42,7 +41,6 @@ since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateGuestOsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateGuestOsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java index c83be131b4fd..fc67ef0a7e76 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.guest; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ @APICommand(name = "updateGuestOsMapping", description = "Updates the information about Guest OS to Hypervisor specific name mapping", responseObject = GuestOsMappingResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateGuestOsMappingCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateGuestOsMappingCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java index 15955b9f0a85..ca27837aa881 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ @APICommand(name = "addHost", description = "Adds a new host.", responseObject = HostResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class AddHostCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddHostCmd.class.getName()); ///////////////////////////////////////////////////// @@ -150,7 +148,7 @@ public void execute() { this.setResponseObject(response); } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java index 225eb1dfecdc..c965a39450bd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "addSecondaryStorage", description = "Adds secondary storage.", responseObject = ImageStoreResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddSecondaryStorageCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddSecondaryStorageCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -81,7 +79,7 @@ public void execute(){ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java index cca449f570b2..a514a61b8a41 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ @APICommand(name = "cancelHostMaintenance", description = "Cancels host maintenance.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CancelMaintenanceCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CancelMaintenanceCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java index 934965cd24cc..38325c2f072d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "deleteHost", description = "Deletes a host.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteHostCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteHostCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java index 2b6ccb68eea7..db30e4f4c02f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "findHostsForMigration", description = "Find hosts suitable for migrating a virtual machine.", responseObject = HostForMigrationResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class FindHostsForMigrationCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(FindHostsForMigrationCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostTagsCmd.java index ed4f9a09bc5f..9ea2b2a7fbb5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostTagsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostTagsCmd.java @@ -18,7 +18,6 @@ */ package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.BaseListCmd; @@ -27,7 +26,6 @@ @APICommand(name = "listHostTags", description = "Lists host tags", responseObject = HostTagResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListHostTagsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListHostTagsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java index b8668f61ca46..af87bbf33bb0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -45,7 +44,6 @@ @APICommand(name = "listHosts", description = "Lists hosts.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListHostsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListHostsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java index a89965e822ee..2641c54364ee 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.host.Host; @@ -35,7 +34,6 @@ @APICommand(name = "prepareHostForMaintenance", description = "Prepares a host for maintenance.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class PrepareForMaintenanceCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(PrepareForMaintenanceCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java index 7439d9da514b..3550d61fdb97 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.AgentUnavailableException; @@ -36,7 +35,6 @@ @APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReconnectHostCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReconnectHostCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java index 90c388bc7dc7..7fee0684c781 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ @APICommand(name = "releaseHostReservation", description = "Releases host reservation.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseHostReservationCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseHostReservationCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java index 9cf47a9c4b96..88eeadb9b139 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java @@ -27,14 +27,12 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.GuestOSCategoryResponse; import org.apache.cloudstack.api.response.HostResponse; -import org.apache.log4j.Logger; import java.util.List; @APICommand(name = "updateHost", description = "Updates a host.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateHostCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateHostCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -127,7 +125,7 @@ public void execute() { hostResponse.setResponseName(getCommandName()); this.setResponseObject(hostResponse); } catch (Exception e) { - s_logger.debug("Failed to update host:" + getId(), e); + logger.debug("Failed to update host:" + getId(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update host:" + getId() + "," + e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java index 2e05ad144756..c94fe2c58656 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java @@ -24,14 +24,12 @@ import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = "updateHostPassword", description = "Update password of a host/pool on management server.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class UpdateHostPasswordCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateHostPasswordCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java index 1c7e4a0ce214..c94d326ee622 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java @@ -17,12 +17,6 @@ package org.apache.cloudstack.api.command.admin.internallb; -import java.util.List; - -import javax.inject.Inject; - -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -47,10 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ConfigureInternalLoadBalancerElementCmd.class.getName()); - - @Inject - private List _service; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -100,7 +90,8 @@ public String getEventDescription() { @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { CallContext.current().setEventDetails("Internal load balancer element: " + id); - VirtualRouterProvider result = _service.get(0).configureInternalLoadBalancerElement(getId(), getEnabled()); + InternalLoadBalancerElementService service = _networkService.getInternalLoadBalancerElementById(id); + VirtualRouterProvider result = service.configureInternalLoadBalancerElement(getId(), getEnabled()); if (result != null) { InternalLoadBalancerElementResponse routerResponse = _responseGenerator.createInternalLbElementResponse(result); routerResponse.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java index f11f081031a0..924287b673ba 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java @@ -16,12 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.internallb; -import java.util.List; - -import javax.inject.Inject; - -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -45,10 +39,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateInternalLoadBalancerElementCmd.class.getName()); - - @Inject - private List _service; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -85,7 +75,8 @@ public long getEntityOwnerId() { @Override public void execute() { CallContext.current().setEventDetails("Virtual router element Id: " + getEntityId()); - VirtualRouterProvider result = _service.get(0).getInternalLoadBalancerElement(getEntityId()); + InternalLoadBalancerElementService service = _networkService.getInternalLoadBalancerElementByNetworkServiceProviderId(getNspId()); + VirtualRouterProvider result = service.getInternalLoadBalancerElement(getEntityId()); if (result != null) { InternalLoadBalancerElementResponse response = _responseGenerator.createInternalLbElementResponse(result); response.setResponseName(getCommandName()); @@ -97,7 +88,8 @@ public void execute() { @Override public void create() throws ResourceAllocationException { - VirtualRouterProvider result = _service.get(0).addInternalLoadBalancerElement(getNspId()); + InternalLoadBalancerElementService service = _networkService.getInternalLoadBalancerElementByNetworkServiceProviderId(getNspId()); + VirtualRouterProvider result = service.addInternalLoadBalancerElement(getNspId()); if (result != null) { setEntityId(result.getId()); setEntityUuid(result.getUuid()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java index f57569097062..0eb00234382d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.internallb; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ @APICommand(name = "listInternalLoadBalancerVMs", description = "List internal LB VMs.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListInternalLBVMsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListInternalLBVMsCmd.class.getName()); private static final String s_name = "listinternallbvmsresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java index 82d373e31192..b17cc22e7466 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java @@ -17,12 +17,9 @@ package org.apache.cloudstack.api.command.admin.internallb; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import javax.inject.Inject; - -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListCmd; @@ -46,10 +43,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListInternalLoadBalancerElementsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListInternalLoadBalancerElementsCmd.class.getName()); - - @Inject - private InternalLoadBalancerElementService _service; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -88,12 +81,21 @@ public Boolean getEnabled() { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - List providers = _service.searchForInternalLoadBalancerElements(getId(), getNspId(), getEnabled()); + List services; + if (id == null && nspId == null) { + services = _networkService.getInternalLoadBalancerElements(); + } else { + InternalLoadBalancerElementService elementService = id != null ? _networkService.getInternalLoadBalancerElementById(id) : _networkService.getInternalLoadBalancerElementByNetworkServiceProviderId(nspId); + services = Collections.singletonList(elementService); + } ListResponse response = new ListResponse(); List providerResponses = new ArrayList(); - for (VirtualRouterProvider provider : providers) { - InternalLoadBalancerElementResponse providerResponse = _responseGenerator.createInternalLbElementResponse(provider); - providerResponses.add(providerResponse); + for (InternalLoadBalancerElementService service : services) { + List providers = service.searchForInternalLoadBalancerElements(getId(), getNspId(), getEnabled()); + for (VirtualRouterProvider provider : providers) { + InternalLoadBalancerElementResponse providerResponse = _responseGenerator.createInternalLbElementResponse(provider); + providerResponses.add(providerResponse); + } } response.setResponses(providerResponses); response.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java index fdec79478538..3dd7d2adf378 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.internallb; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -42,7 +41,6 @@ @APICommand(name = "startInternalLoadBalancerVM", responseObject = DomainRouterResponse.class, description = "Starts an existing internal lb vm.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StartInternalLBVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StartInternalLBVMCmd.class.getName()); private static final String s_name = "startinternallbvmresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java index 76ad4d438d28..a746e5d906d6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.internallb; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ @APICommand(name = "stopInternalLoadBalancerVM", description = "Stops an Internal LB vm.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StopInternalLBVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StopInternalLBVMCmd.class.getName()); private static final String s_name = "stopinternallbvmresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java index 3af772d332f1..a68ed62857ac 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java @@ -23,12 +23,10 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ManagementServerResponse; -import org.apache.log4j.Logger; @APICommand(name = "listManagementServers", description = "Lists management servers.", responseObject = ManagementServerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListMgmtsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListMgmtsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java index be0cd9f2fa74..334772970431 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -44,7 +43,6 @@ responseObject = NetworkDeviceResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddNetworkDeviceCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddNetworkDeviceCmd.class); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java index 176375ce1812..40a822393452 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddNetworkServiceProviderCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddNetworkServiceProviderCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateGuestNetworkIpv6PrefixCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateGuestNetworkIpv6PrefixCmd.java index d7c7bec99f9e..f6b035c57837 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateGuestNetworkIpv6PrefixCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateGuestNetworkIpv6PrefixCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.DataCenterGuestIpv6PrefixResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenterGuestIpv6Prefix; import com.cloud.event.EventTypes; @@ -45,7 +44,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class CreateGuestNetworkIpv6PrefixCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateGuestNetworkIpv6PrefixCmd.class); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForGuestNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForGuestNetworkCmd.java new file mode 100644 index 000000000000..a482cb1d4f27 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForGuestNetworkCmd.java @@ -0,0 +1,108 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.api.response.Ipv4SubnetForGuestNetworkResponse; + +import com.cloud.event.EventTypes; +import com.cloud.user.Account; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; + +@APICommand(name = "createIpv4SubnetForGuestNetwork", + description = "Creates a IPv4 subnet for guest networks.", + responseObject = Ipv4SubnetForGuestNetworkResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class CreateIpv4SubnetForGuestNetworkCmd extends BaseAsyncCmd { + + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.PARENT_ID, + type = CommandType.UUID, + entityType = DataCenterIpv4SubnetResponse.class, + required = true, + description = "The zone Ipv4 subnet which the IPv4 subnet belongs to.") + private Long parentId; + + @Parameter(name = ApiConstants.SUBNET, + type = CommandType.STRING, + description = "The CIDR of this Ipv4 subnet.") + private String subnet; + + @Parameter(name = ApiConstants.CIDR_SIZE, + type = CommandType.INTEGER, + description = "the CIDR size of IPv4 network. This is mutually exclusive with subnet.") + private Integer cidrSize; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public Long getParentId() { + return parentId; + } + + public String getSubnet() { + return subnet; + } + + public Integer getCidrSize() { + return cidrSize; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_IP4_GUEST_SUBNET_CREATE; + } + + @Override + public String getEventDescription() { + return "Creating guest IPv4 subnet " + getSubnet() + " in zone subnet=" + getParentId(); + } + + @Override + public void execute() { + Ipv4GuestSubnetNetworkMap result = routedIpv4Manager.createIpv4SubnetForGuestNetwork(this); + if (result != null) { + Ipv4SubnetForGuestNetworkResponse response = routedIpv4Manager.createIpv4SubnetForGuestNetworkResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create zone guest IPv4 subnet."); + } + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForZoneCmd.java new file mode 100644 index 000000000000..5f48cf9c6327 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForZoneCmd.java @@ -0,0 +1,125 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; + +import com.cloud.event.EventTypes; +import com.cloud.user.Account; + +@APICommand(name = "createIpv4SubnetForZone", + description = "Creates a IPv4 subnet for a zone.", + responseObject = DataCenterIpv4SubnetResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class CreateIpv4SubnetForZoneCmd extends BaseAsyncCmd { + + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + required = true, + description = "UUID of the zone which the IPv4 subnet belongs to.", + validations = {ApiArgValidator.PositiveNumber}) + private Long zoneId; + + @Parameter(name = ApiConstants.SUBNET, + type = CommandType.STRING, + required = true, + description = "The CIDR of the IPv4 subnet.") + private String subnet; + + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account who will own the IPv4 subnet") + private String accountName; + + @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "project who will own the IPv4 subnet") + private Long projectId; + + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "domain ID of the account owning the IPv4 subnet") + private Long domainId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public Long getZoneId() { + return zoneId; + } + + public String getSubnet() { + return subnet; + } + + public String getAccountName() { + return accountName; + } + + public Long getProjectId() { + return projectId; + } + + public Long getDomainId() { + return domainId; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_ZONE_IP4_SUBNET_CREATE; + } + + @Override + public String getEventDescription() { + return "Creating guest IPv4 subnet " + getSubnet() + " for zone=" + getZoneId(); + } + + @Override + public void execute() { + DataCenterIpv4GuestSubnet result = routedIpv4Manager.createDataCenterIpv4GuestSubnet(this); + if (result != null) { + DataCenterIpv4SubnetResponse response = routedIpv4Manager.createDataCenterIpv4SubnetResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create zone guest IPv4 subnet."); + } + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateManagementNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateManagementNetworkIpRangeCmd.java index 2bab4f053523..85cfddfb714f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateManagementNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateManagementNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.ApiArgValidator; @@ -44,7 +43,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class CreateManagementNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateManagementNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java index 53b02718ea35..d8b57f79528c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.network; import org.apache.cloudstack.api.ApiArgValidator; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -25,14 +24,16 @@ import org.apache.cloudstack.api.ResponseObject.ResponseView; import org.apache.cloudstack.api.command.admin.AdminCmd; import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; +import org.apache.cloudstack.api.response.BgpPeerResponse; import org.apache.cloudstack.api.response.NetworkResponse; import com.cloud.network.Network; +import java.util.List; + @APICommand(name = "createNetwork", description = "Creates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Full, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkCmdByAdmin extends CreateNetworkCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkCmdByAdmin.class.getName()); @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network") private String vlan; @@ -51,6 +52,14 @@ public class CreateNetworkCmdByAdmin extends CreateNetworkCmd implements AdminCm validations = {ApiArgValidator.NotNullOrEmpty}) private String routerIpv6; + @Parameter(name = ApiConstants.BGP_PEER_IDS, + type = CommandType.LIST, + collectionType = CommandType.UUID, + entityType = BgpPeerResponse.class, + description = "Ids of the Bgp Peer for the network", + since = "4.20.0") + private List bgpPeerIds; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -80,4 +89,8 @@ public String getRouterIp() { public String getRouterIpv6() { return routerIpv6; } + + public List getBgpPeerIds() { + return bgpPeerIds; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java index 2112be34543e..af3db374a7c9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java @@ -24,12 +24,15 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import com.cloud.network.Network; +import com.cloud.network.VirtualRouterProvider; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -47,10 +50,19 @@ import com.cloud.offering.NetworkOffering.Availability; import com.cloud.user.Account; +import static com.cloud.network.Network.Service.Dhcp; +import static com.cloud.network.Network.Service.Dns; +import static com.cloud.network.Network.Service.Lb; +import static com.cloud.network.Network.Service.StaticNat; +import static com.cloud.network.Network.Service.SourceNat; +import static com.cloud.network.Network.Service.PortForwarding; +import static com.cloud.network.Network.Service.NetworkACL; +import static com.cloud.network.Network.Service.UserData; +import static com.cloud.network.Network.Service.Firewall; + @APICommand(name = "createNetworkOffering", description = "Creates a network offering.", responseObject = NetworkOfferingResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -128,6 +140,30 @@ public class CreateNetworkOfferingCmd extends BaseCmd { description = "true if network offering is meant to be used for VPC, false otherwise.") private Boolean forVpc; + @Parameter(name = ApiConstants.FOR_NSX, + type = CommandType.BOOLEAN, + description = "true if network offering is meant to be used for NSX, false otherwise.", + since = "4.20.0") + private Boolean forNsx; + + @Parameter(name = ApiConstants.NSX_SUPPORT_LB, + type = CommandType.BOOLEAN, + description = "true if network offering for NSX network offering supports Load balancer service.", + since = "4.20.0") + private Boolean nsxSupportsLbService; + + @Parameter(name = ApiConstants.NSX_SUPPORTS_INTERNAL_LB, + type = CommandType.BOOLEAN, + description = "true if network offering for NSX network offering supports Internal Load balancer service.", + since = "4.20.0") + private Boolean nsxSupportsInternalLbService; + + @Parameter(name = ApiConstants.NETWORK_MODE, + type = CommandType.STRING, + description = "Indicates the mode with which the network will operate. Valid option: NATTED or ROUTED", + since = "4.20.0") + private String networkMode; + @Parameter(name = ApiConstants.FOR_TUNGSTEN, type = CommandType.BOOLEAN, description = "true if network offering is meant to be used for Tungsten-Fabric, false otherwise.") @@ -175,6 +211,16 @@ public class CreateNetworkOfferingCmd extends BaseCmd { since = "4.16") private Boolean enable; + @Parameter(name = ApiConstants.SPECIFY_AS_NUMBER, type = CommandType.BOOLEAN, since = "4.20.0", + description = "true if network offering supports choosing AS number") + private Boolean specifyAsNumber; + + @Parameter(name = ApiConstants.ROUTING_MODE, + type = CommandType.STRING, + since = "4.20.0", + description = "the routing mode for the network offering. Supported types are: Static or Dynamic.") + private String routingMode; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -212,7 +258,27 @@ public Long getServiceOfferingId() { } public List getSupportedServices() { - return supportedServices == null ? new ArrayList() : supportedServices; + if (!isForNsx()) { + return supportedServices == null ? new ArrayList() : supportedServices; + } else { + List services = new ArrayList<>(List.of( + Dhcp.getName(), + Dns.getName(), + StaticNat.getName(), + SourceNat.getName(), + PortForwarding.getName(), + UserData.getName() + )); + if (getNsxSupportsLbService()) { + services.add(Lb.getName()); + } + if (Boolean.TRUE.equals(forVpc)) { + services.add(NetworkACL.getName()); + } else { + services.add(Firewall.getName()); + } + return services; + } } public String getGuestIpType() { @@ -242,6 +308,22 @@ public Boolean getForVpc() { return forVpc; } + public boolean isForNsx() { + return BooleanUtils.isTrue(forNsx); + } + + public String getNetworkMode() { + return networkMode; + } + + public boolean getNsxSupportsLbService() { + return BooleanUtils.isTrue(nsxSupportsLbService); + } + + public boolean getNsxSupportsInternalLbService() { + return BooleanUtils.isTrue(nsxSupportsInternalLbService); + } + public Boolean getForTungsten() { return forTungsten; } @@ -262,9 +344,8 @@ public Integer getMaxconnections() { } public Map> getServiceProviders() { - Map> serviceProviderMap = null; - if (serviceProviderList != null && !serviceProviderList.isEmpty()) { - serviceProviderMap = new HashMap>(); + Map> serviceProviderMap = new HashMap<>(); + if (serviceProviderList != null && !serviceProviderList.isEmpty() && !isForNsx()) { Collection servicesCollection = serviceProviderList.values(); Iterator iter = servicesCollection.iterator(); while (iter.hasNext()) { @@ -280,11 +361,37 @@ public Map> getServiceProviders() { providerList.add(provider); serviceProviderMap.put(service, providerList); } + } else if (Boolean.TRUE.equals(forNsx)) { + getServiceProviderMapForNsx(serviceProviderMap); } - return serviceProviderMap; } + private void getServiceProviderMapForNsx(Map> serviceProviderMap) { + String routerProvider = Boolean.TRUE.equals(getForVpc()) ? VirtualRouterProvider.Type.VPCVirtualRouter.name() : + VirtualRouterProvider.Type.VirtualRouter.name(); + List unsupportedServices = new ArrayList<>(List.of("Vpn", "SecurityGroup", "Connectivity", + "Gateway", "BaremetalPxeService")); + List routerSupported = List.of("Dhcp", "Dns", "UserData"); + List allServices = Service.listAllServices().stream().map(Service::getName).collect(Collectors.toList()); + if (routerProvider.equals(VirtualRouterProvider.Type.VPCVirtualRouter.name())) { + unsupportedServices.add("Firewall"); + } else { + unsupportedServices.add("NetworkACL"); + } + for (String service : allServices) { + if (unsupportedServices.contains(service)) + continue; + if (routerSupported.contains(service)) + serviceProviderMap.put(service, List.of(routerProvider)); + else + serviceProviderMap.put(service, List.of(Network.Provider.Nsx.getName())); + if (!getNsxSupportsLbService()) { + serviceProviderMap.remove(Lb.getName()); + } + } + } + public Map getServiceCapabilities(Service service) { Map capabilityMap = null; @@ -365,6 +472,14 @@ public Boolean getEnable() { return false; } + public boolean getSpecifyAsNumber() { + return BooleanUtils.toBoolean(specifyAsNumber); + } + + public String getRoutingMode() { + return routingMode; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java index 294ee047fe68..7eb52b92456c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ @APICommand(name = "createPhysicalNetwork", description = "Creates a physical network", responseObject = PhysicalNetworkResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreatePhysicalNetworkCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java index d2dc3d8688fa..42262cc2bf15 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateStorageNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateStorageNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// @@ -119,7 +117,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Create storage network IP range failed", e); + logger.warn("Create storage network IP range failed", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java index e6a289d096b7..355f738679e0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java @@ -18,7 +18,6 @@ */ package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ @APICommand(name = "dedicateGuestVlanRange", description = "Dedicates a guest vlan range to an account", responseObject = GuestVlanRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicateGuestVlanRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DedicateGuestVlanRangeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateIpv4SubnetForZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateIpv4SubnetForZoneCmd.java new file mode 100644 index 000000000000..2df032c559c5 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateIpv4SubnetForZoneCmd.java @@ -0,0 +1,111 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "dedicateIpv4SubnetForZone", + description = "Dedicates an existing IPv4 subnet for a zone to an account or a domain.", + responseObject = DataCenterIpv4SubnetResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class DedicateIpv4SubnetForZoneCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DataCenterIpv4SubnetResponse.class, required = true, description = "Id of the guest network IPv4 subnet") + private Long id; + + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account who will own the IPv4 subnet") + private String accountName; + + @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "project who will own the IPv4 subnet") + private Long projectId; + + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "domain ID of the account owning the IPv4 subnet") + private Long domainId; + + public Long getId() { + return id; + } + + public String getAccountName() { + return accountName; + } + + public Long getProjectId() { + return projectId; + } + + public Long getDomainId() { + return domainId; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_ZONE_IP4_SUBNET_DEDICATE; + } + + @Override + public String getEventDescription() { + return "Dedicating zone IPv4 subnet " + getId(); + } + + @Override + public void execute() { + try { + DataCenterIpv4GuestSubnet result = routedIpv4Manager.dedicateDataCenterIpv4GuestSubnet(this); + if (result != null) { + DataCenterIpv4SubnetResponse response = routedIpv4Manager.createDataCenterIpv4SubnetResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate guest network IPv4 subnet:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteGuestNetworkIpv6PrefixCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteGuestNetworkIpv6PrefixCmd.java index 67d309456d6a..e2ada4191a82 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteGuestNetworkIpv6PrefixCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteGuestNetworkIpv6PrefixCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.DataCenterGuestIpv6PrefixResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -45,7 +44,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class DeleteGuestNetworkIpv6PrefixCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteGuestNetworkIpv6PrefixCmd.class); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForGuestNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForGuestNetworkCmd.java new file mode 100644 index 000000000000..28a646f9d036 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForGuestNetworkCmd.java @@ -0,0 +1,88 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.Ipv4SubnetForGuestNetworkResponse; +import org.apache.cloudstack.api.response.SuccessResponse; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "deleteIpv4SubnetForGuestNetwork", + description = "Deletes an existing IPv4 subnet for guest network.", + responseObject = SuccessResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class DeleteIpv4SubnetForGuestNetworkCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = Ipv4SubnetForGuestNetworkResponse.class, required = true, description = "Id of the guest network IPv4 subnet") + private Long id; + + public Long getId() { + return id; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_IP4_GUEST_SUBNET_DELETE; + } + + @Override + public String getEventDescription() { + return "Deleting guest IPv4 subnet " + getId(); + } + + @Override + public void execute() { + try { + boolean result = routedIpv4Manager.deleteIpv4SubnetForGuestNetwork(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete guest network IPv4 subnet:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForZoneCmd.java new file mode 100644 index 000000000000..222bc1bad98d --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForZoneCmd.java @@ -0,0 +1,88 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.api.response.SuccessResponse; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "deleteIpv4SubnetForZone", + description = "Deletes an existing IPv4 subnet for a zone.", + responseObject = SuccessResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class DeleteIpv4SubnetForZoneCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DataCenterIpv4SubnetResponse.class, required = true, description = "Id of the guest network IPv4 subnet") + private Long id; + + public Long getId() { + return id; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_ZONE_IP4_SUBNET_DELETE; + } + + @Override + public String getEventDescription() { + return "Deleting zone IPv4 subnet " + getId(); + } + + @Override + public void execute() { + try { + boolean result = routedIpv4Manager.deleteDataCenterIpv4GuestSubnet(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete guest network IPv4 subnet:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java index abb72eb27244..41cf5e518b34 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.ApiArgValidator; @@ -42,7 +41,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class DeleteManagementNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteManagementNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// @@ -112,13 +110,13 @@ public void execute() { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (Exception e) { - s_logger.warn("Failed to delete management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId(), e); + logger.warn("Failed to delete management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java index d7e8744d6b72..89a36d0b94f5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ @APICommand(name = "deleteNetworkDevice", description = "Deletes network device.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkDeviceCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkDeviceCmd.class); @Inject ExternalNetworkDeviceManager nwDeviceMgr; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java index 80ce48cc7d98..e0598b71ea17 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "deleteNetworkOffering", description = "Deletes a network offering.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java index 1ccfff5d7ba2..4b56612fddaa 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ @APICommand(name = "deleteNetworkServiceProvider", description = "Deletes a Network Service Provider.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkServiceProviderCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkServiceProviderCmd.class.getName()); ///////////////////////////////////////////////////// @@ -78,10 +76,10 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete network service provider"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java index 79f0685c6c65..3233130211c4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ @APICommand(name = "deletePhysicalNetwork", description = "Deletes a Physical Network.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePhysicalNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePhysicalNetworkCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java index b5de43dc5e24..454dfba92f20 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "deleteStorageNetworkIpRange", description = "Deletes a storage network IP Range.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteStorageNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteStorageNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// @@ -77,7 +75,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Failed to delete storage network ip range " + getId(), e); + logger.warn("Failed to delete storage network ip range " + getId(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListDedicatedGuestVlanRangesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListDedicatedGuestVlanRangesCmd.java index 67324d819272..0247a3069212 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListDedicatedGuestVlanRangesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListDedicatedGuestVlanRangesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ @APICommand(name = "listDedicatedGuestVlanRanges", description = "Lists dedicated guest vlan ranges", responseObject = GuestVlanRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedGuestVlanRangesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedGuestVlanRangesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListGuestVlansCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListGuestVlansCmd.java index 1daeac9c53d0..4b368f5e0341 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListGuestVlansCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListGuestVlansCmd.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ since = "4.17.0", authorized = {RoleType.Admin}) public class ListGuestVlansCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListGuestVlansCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForGuestNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForGuestNetworkCmd.java new file mode 100644 index 000000000000..9761f6e89ebc --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForGuestNetworkCmd.java @@ -0,0 +1,123 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.network; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.api.response.Ipv4SubnetForGuestNetworkResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NetworkResponse; +import org.apache.cloudstack.api.response.VpcResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; + +@APICommand(name = "listIpv4SubnetsForGuestNetwork", + description = "Lists IPv4 subnets for guest networks.", + responseObject = Ipv4SubnetForGuestNetworkResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class ListIpv4SubnetsForGuestNetworkCmd extends BaseListCmd { + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + entityType = Ipv4SubnetForGuestNetworkResponse.class, + description = "UUID of the IPv4 subnet for guest network.") + private Long id; + + @Parameter(name = ApiConstants.PARENT_ID, + type = CommandType.UUID, + entityType = DataCenterIpv4SubnetResponse.class, + description = "UUID of zone Ipv4 subnet which the IPv4 subnet belongs to.") + private Long parentId; + + @Parameter(name = ApiConstants.SUBNET, + type = CommandType.STRING, + description = "The CIDR of the Ipv4 subnet.") + private String subnet; + + @Parameter(name = ApiConstants.ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + description = "UUID of zone to which the IPv4 subnet belongs to.") + private Long zoneId; + + @Parameter(name = ApiConstants.NETWORK_ID, + type = CommandType.UUID, + entityType = NetworkResponse.class, + description = "UUID of network to which the IPv4 subnet is associated to.") + private Long networkId; + + @Parameter(name = ApiConstants.VPC_ID, + type = CommandType.UUID, + entityType = VpcResponse.class, + description = "UUID of VPC to which the IPv4 subnet is associated to.") + private Long vpcId; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public Long getParentId() { + return parentId; + } + + public Long getZoneId() { + return zoneId; + } + + public String getSubnet() { + return subnet; + } + + public Long getNetworkId() { + return networkId; + } + + public Long getVpcId() { + return vpcId; + } + + @Override + public void execute() { + List subnets = routedIpv4Manager.listIpv4GuestSubnetsForGuestNetwork(this); + ListResponse response = new ListResponse<>(); + List subnetResponses = new ArrayList<>(); + for (Ipv4GuestSubnetNetworkMap subnet : subnets) { + Ipv4SubnetForGuestNetworkResponse subnetResponse = routedIpv4Manager.createIpv4SubnetForGuestNetworkResponse(subnet); + subnetResponses.add(subnetResponse); + } + + response.setResponses(subnetResponses, subnets.size()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } + +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForZoneCmd.java new file mode 100644 index 000000000000..2c2182250edb --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForZoneCmd.java @@ -0,0 +1,120 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.network; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; + +@APICommand(name = "listIpv4SubnetsForZone", + description = "Lists IPv4 subnets for zone.", + responseObject = DataCenterIpv4SubnetResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class ListIpv4SubnetsForZoneCmd extends BaseListCmd { + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + entityType = DataCenterIpv4SubnetResponse.class, + description = "UUID of the IPv4 subnet.") + private Long id; + + @Parameter(name = ApiConstants.ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + description = "UUID of zone to which the IPv4 subnet belongs to.") + private Long zoneId; + + @Parameter(name = ApiConstants.SUBNET, + type = CommandType.STRING, + description = "CIDR of the IPv4 subnet.") + private String subnet; + + @Parameter(name = ApiConstants.ACCOUNT, + type = CommandType.STRING, + description = "the account which the IPv4 subnet is dedicated to. Must be used with the domainId parameter.") + private String accountName; + + @Parameter(name = ApiConstants.PROJECT_ID, + type = CommandType.UUID, + entityType = ProjectResponse.class, + description = "project who which the IPv4 subnet is dedicated to") + private Long projectId; + + @Parameter(name = ApiConstants.DOMAIN_ID, + type = CommandType.UUID, + entityType = DomainResponse.class, + description = "the domain ID which the IPv4 subnet is dedicated to.") + private Long domainId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public Long getZoneId() { + return zoneId; + } + + public String getSubnet() { + return subnet; + } + + public String getAccountName() { + return accountName; + } + + public Long getProjectId() { + return projectId; + } + + public Long getDomainId() { + return domainId; + } + + @Override + public void execute() { + List subnets = routedIpv4Manager.listDataCenterIpv4GuestSubnets(this); + ListResponse response = new ListResponse<>(); + List subnetResponses = new ArrayList<>(); + for (DataCenterIpv4GuestSubnet subnet : subnets) { + DataCenterIpv4SubnetResponse subnetResponse = routedIpv4Manager.createDataCenterIpv4SubnetResponse(subnet); + subnetResponses.add(subnetResponse); + } + + response.setResponses(subnetResponses, subnets.size()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } + +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java index 405c2654bdf1..768bab641087 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java @@ -22,7 +22,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -45,7 +44,6 @@ @APICommand(name = "listNetworkDevice", description = "List network devices", responseObject = NetworkDeviceResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkDeviceCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkDeviceCmd.class); private static final String s_name = "listnetworkdevice"; @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkServiceProvidersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkServiceProvidersCmd.java index 67fc8292a938..68495a62215f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkServiceProvidersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkServiceProvidersCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkServiceProvidersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkServiceProvidersCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java index b8f30d3f7a11..51a6ddabd9f1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "listPhysicalNetworks", description = "Lists physical networks", responseObject = PhysicalNetworkResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPhysicalNetworksCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListPhysicalNetworksCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java index c22ec8ee19b8..556162ca360d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ @APICommand(name = "listStorageNetworkIpRange", description = "List a storage network IP range.", responseObject = StorageNetworkIpRangeResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListStorageNetworkIpRangeCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListStorageNetworkIpRangeCmd.class); String _name = "liststoragenetworkiprangeresponse"; @@ -99,7 +97,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId()); + logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListSupportedNetworkServicesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListSupportedNetworkServicesCmd.java index 361da2d0db44..120c6af41ad6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListSupportedNetworkServicesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListSupportedNetworkServicesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSupportedNetworkServicesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSupportedNetworkServicesCmd.class.getName()); @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "network service provider name") private String providerName; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateNetworkCmd.java index b38e8f453b0e..8ef853b99da8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateNetworkCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -48,7 +47,6 @@ since = "4.11.0", authorized = {RoleType.Admin}) public class MigrateNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateNetworkCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateVPCCmd.java index cca367ce7506..3e0801be40b1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateVPCCmd.java @@ -19,7 +19,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker; @@ -50,7 +49,6 @@ since = "4.11.0", authorized = {RoleType.Admin}) public class MigrateVPCCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateVPCCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java index 916357920a16..b3125ec36680 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ @APICommand(name = "releaseDedicatedGuestVlanRange", description = "Releases a dedicated guest vlan range to the system", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedGuestVlanRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedGuestVlanRangeCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedIpv4SubnetForZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedIpv4SubnetForZoneCmd.java new file mode 100644 index 000000000000..3e151b9b58f4 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedIpv4SubnetForZoneCmd.java @@ -0,0 +1,88 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "releaseIpv4SubnetForZone", + description = "Releases an existing dedicated IPv4 subnet for a zone.", + responseObject = DataCenterIpv4SubnetResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class ReleaseDedicatedIpv4SubnetForZoneCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DataCenterIpv4SubnetResponse.class, required = true, description = "Id of the guest network IPv4 subnet") + private Long id; + + public Long getId() { + return id; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_ZONE_IP4_SUBNET_RELEASE; + } + + @Override + public String getEventDescription() { + return "Releasing a dedicated zone IPv4 subnet " + getId(); + } + + @Override + public void execute() { + try { + DataCenterIpv4GuestSubnet result = routedIpv4Manager.releaseDedicatedDataCenterIpv4GuestSubnet(this); + if (result != null) { + DataCenterIpv4SubnetResponse response = routedIpv4Manager.createDataCenterIpv4SubnetResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to release guest network IPv4 subnet:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateIpv4SubnetForZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateIpv4SubnetForZoneCmd.java new file mode 100644 index 000000000000..da7a23f50d9c --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateIpv4SubnetForZoneCmd.java @@ -0,0 +1,98 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "updateIpv4SubnetForZone", + description = "Updates an existing IPv4 subnet for a zone.", + responseObject = DataCenterIpv4SubnetResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class UpdateIpv4SubnetForZoneCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DataCenterIpv4SubnetResponse.class, required = true, description = "Id of the guest network IPv4 subnet") + private Long id; + + @Parameter(name = ApiConstants.SUBNET, + type = CommandType.STRING, + required = true, + description = "The new CIDR of the IPv4 subnet.") + private String subnet; + + public Long getId() { + return id; + } + + public String getSubnet() { + return subnet; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_ZONE_IP4_SUBNET_UPDATE; + } + + @Override + public String getEventDescription() { + return "Updating zone IPv4 subnet " + getId(); + } + + @Override + public void execute() { + try { + DataCenterIpv4GuestSubnet result = routedIpv4Manager.updateDataCenterIpv4GuestSubnet(this); + if (result != null) { + DataCenterIpv4SubnetResponse response = routedIpv4Manager.createDataCenterIpv4SubnetResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update guest network IPv4 subnet:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java index e8f9e5f8cfe7..75fb45e1f115 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkOfferingResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; @@ -39,7 +38,6 @@ @APICommand(name = "updateNetworkOffering", description = "Updates a network offering.", responseObject = NetworkOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java index 1bbf21b85ed4..b4801d9368eb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkServiceProviderCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkServiceProviderCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java index 24fd93f49d1e..162116470bd5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -34,7 +33,6 @@ @APICommand(name = "updatePhysicalNetwork", description = "Updates a physical network", responseObject = PhysicalNetworkResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdatePhysicalNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdatePhysicalNetworkCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java index 4e880f122d85..6f90a070f0d1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -42,7 +41,6 @@ authorized = {RoleType.Admin}) public class UpdatePodManagementNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdatePodManagementNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// @@ -138,10 +136,10 @@ public void execute() { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (Exception e) { - s_logger.warn("Failed to update pod management IP range " + getNewStartIP() + "-" + getNewEndIP() + " of Pod: " + getPodId(), e); + logger.warn("Failed to update pod management IP range " + getNewStartIP() + "-" + getNewEndIP() + " of Pod: " + getPodId(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java index 459c89debc9a..65e2437417de 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateStorageNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateStorageNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -107,7 +105,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Update storage network IP range failed", e); + logger.warn("Update storage network IP range failed", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForNetworkCmd.java new file mode 100644 index 000000000000..1d6bffca342e --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForNetworkCmd.java @@ -0,0 +1,109 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.admin.AdminCmd; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.api.response.NetworkResponse; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.Network; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +import java.util.List; + +@APICommand(name = "changeBgpPeersForNetwork", + description = "Change the BGP peers for a network.", + responseObject = BgpPeerResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class ChangeBgpPeersForNetworkCmd extends BaseAsyncCmd implements AdminCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.NETWORK_ID, + type = CommandType.UUID, + entityType = NetworkResponse.class, + required = true, + description = "UUID of the network which the Bgp Peers are associated to.", + validations = {ApiArgValidator.PositiveNumber}) + private Long networkId; + + @Parameter(name = ApiConstants.BGP_PEER_IDS, + type = CommandType.LIST, + collectionType = CommandType.UUID, + entityType = BgpPeerResponse.class, + description = "Ids of the Bgp Peer. If it is empty, all BGP peers will be unlinked.") + private List bgpPeerIds; + + public Long getNetworkId() { + return networkId; + } + + public List getBgpPeerIds() { + return bgpPeerIds; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_NETWORK_BGP_PEER_UPDATE; + } + + @Override + public String getEventDescription() { + return "Changing Bgp Peers for network " + getNetworkId(); + } + + @Override + public void execute() { + try { + Network result = routedIpv4Manager.changeBgpPeersForNetwork(this); + if (result != null) { + NetworkResponse response = _responseGenerator.createNetworkResponse(getResponseView(), result); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to change BGP Peers for network"); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForVpcCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForVpcCmd.java new file mode 100644 index 000000000000..0c89f3f1d43c --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForVpcCmd.java @@ -0,0 +1,109 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.admin.AdminCmd; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.api.response.VpcResponse; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.vpc.Vpc; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +import java.util.List; + +@APICommand(name = "changeBgpPeersForVpc", + description = "Change the BGP peers for a VPC.", + responseObject = BgpPeerResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class ChangeBgpPeersForVpcCmd extends BaseAsyncCmd implements AdminCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.VPC_ID, + type = CommandType.UUID, + entityType = VpcResponse.class, + required = true, + description = "UUID of the VPC which the Bgp Peers are associated to.", + validations = {ApiArgValidator.PositiveNumber}) + private Long vpcId; + + @Parameter(name = ApiConstants.BGP_PEER_IDS, + type = CommandType.LIST, + collectionType = CommandType.UUID, + entityType = BgpPeerResponse.class, + description = "Ids of the Bgp Peer. If it is empty, all BGP peers will be unlinked.") + private List bgpPeerIds; + + public Long getVpcId() { + return vpcId; + } + + public List getBgpPeerIds() { + return bgpPeerIds; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VPC_BGP_PEER_UPDATE; + } + + @Override + public String getEventDescription() { + return "Changing Bgp Peers for VPC " + getVpcId(); + } + + @Override + public void execute() { + try { + Vpc result = routedIpv4Manager.changeBgpPeersForVpc(this); + if (result != null) { + VpcResponse response = _responseGenerator.createVpcResponse(getResponseView(), result); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to change BGP Peers for vpc"); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/CreateBgpPeerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/CreateBgpPeerCmd.java new file mode 100644 index 000000000000..80642124938a --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/CreateBgpPeerCmd.java @@ -0,0 +1,168 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.commons.collections.MapUtils; + +import com.cloud.event.EventTypes; +import com.cloud.user.Account; + +import java.util.Collection; +import java.util.Map; + +@APICommand(name = "createBgpPeer", + description = "Creates a Bgp Peer for a zone.", + responseObject = BgpPeerResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = true, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class CreateBgpPeerCmd extends BaseAsyncCmd { + + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + required = true, + description = "UUID of the zone which the Bgp Peer belongs to.", + validations = {ApiArgValidator.PositiveNumber}) + private Long zoneId; + + @Parameter(name = ApiConstants.IP_ADDRESS, + type = CommandType.STRING, + description = "The IPv4 address of the Bgp Peer.") + private String ip4Address; + + @Parameter(name = ApiConstants.IP6_ADDRESS, + type = CommandType.STRING, + description = "The IPv6 address of the Bgp Peer.") + private String ip6Address; + + @Parameter(name = ApiConstants.AS_NUMBER, + type = CommandType.LONG, + required = true, + description = "The AS number of the Bgp Peer.") + private Long asNumber; + + @Parameter(name = ApiConstants.PASSWORD, + type = CommandType.STRING, + description = "The password of the Bgp Peer.") + private String password; + + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account who will own the Bgp Peer") + private String accountName; + + @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "project who will own the Bgp Peer") + private Long projectId; + + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "domain ID of the account owning the Bgp Peer") + private Long domainId; + + @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, + description = "BGP peer details in key/value pairs.") + protected Map details; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public Long getZoneId() { + return zoneId; + } + + public String getIp4Address() { + return ip4Address; + } + + public String getIp6Address() { + return ip6Address; + } + + public String getPassword() { + return password; + } + + public Long getAsNumber() { + return asNumber; + } + + public String getAccountName() { + return accountName; + } + + public Long getProjectId() { + return projectId; + } + + public Long getDomainId() { + return domainId; + } + + public Map getDetails() { + if (MapUtils.isEmpty(details)) { + return null; + } + Collection paramsCollection = this.details.values(); + return (Map) (paramsCollection.toArray())[0]; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_BGP_PEER_CREATE; + } + + @Override + public String getEventDescription() { + return "Creating Bgp Peer " + getAsNumber() + " for zone=" + getZoneId(); + } + + @Override + public void execute() { + BgpPeer result = routedIpv4Manager.createBgpPeer(this); + if (result != null) { + BgpPeerResponse response = routedIpv4Manager.createBgpPeerResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Bgp Peer."); + } + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/DedicateBgpPeerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/DedicateBgpPeerCmd.java new file mode 100644 index 000000000000..ec3d0ea11629 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/DedicateBgpPeerCmd.java @@ -0,0 +1,111 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.network.BgpPeer; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "dedicateBgpPeer", + description = "Dedicates an existing Bgp Peer to an account or a domain.", + responseObject = BgpPeerResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class DedicateBgpPeerCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BgpPeerResponse.class, required = true, description = "Id of the Bgp Peer") + private Long id; + + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account who will own the Bgp Peer") + private String accountName; + + @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "project who will own the Bgp Peer") + private Long projectId; + + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "domain ID of the account owning the Bgp Peer") + private Long domainId; + + public Long getId() { + return id; + } + + public String getAccountName() { + return accountName; + } + + public Long getProjectId() { + return projectId; + } + + public Long getDomainId() { + return domainId; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_BGP_PEER_DEDICATE; + } + + @Override + public String getEventDescription() { + return "Dedicating Bgp Peer " + getId(); + } + + @Override + public void execute() { + try { + BgpPeer result = routedIpv4Manager.dedicateBgpPeer(this); + if (result != null) { + BgpPeerResponse response = routedIpv4Manager.createBgpPeerResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate Bgp Peer:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/DeleteBgpPeerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/DeleteBgpPeerCmd.java new file mode 100644 index 000000000000..a01711efa44f --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/DeleteBgpPeerCmd.java @@ -0,0 +1,88 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.api.response.SuccessResponse; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "deleteBgpPeer", + description = "Deletes an existing Bgp Peer.", + responseObject = SuccessResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class DeleteBgpPeerCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BgpPeerResponse.class, required = true, description = "Id of the Bgp Peer") + private Long id; + + public Long getId() { + return id; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_BGP_PEER_DELETE; + } + + @Override + public String getEventDescription() { + return "Deleting Bgp Peer " + getId(); + } + + @Override + public void execute() { + try { + boolean result = routedIpv4Manager.deleteBgpPeer(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Bgp Peer:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ListBgpPeersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ListBgpPeersCmd.java new file mode 100644 index 000000000000..ea15f0970e87 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ListBgpPeersCmd.java @@ -0,0 +1,130 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.network.bgp; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.network.BgpPeer; + +@APICommand(name = "listBgpPeers", + description = "Lists Bgp Peers.", + responseObject = BgpPeerResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class ListBgpPeersCmd extends BaseListCmd { + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + entityType = BgpPeerResponse.class, + description = "UUID of the Bgp Peer.") + private Long id; + + @Parameter(name = ApiConstants.ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + description = "UUID of zone to which the Bgp Peer belongs to.") + private Long zoneId; + + @Parameter(name = ApiConstants.AS_NUMBER, + type = CommandType.LONG, + description = "AS number of the Bgp Peer.") + private Long asNumber; + + @Parameter(name = ApiConstants.ACCOUNT, + type = CommandType.STRING, + description = "the account which the Bgp Peer is dedicated to. Must be used with the domainId parameter.") + private String accountName; + + @Parameter(name = ApiConstants.PROJECT_ID, + type = CommandType.UUID, + entityType = ProjectResponse.class, + description = "project who which the Bgp Peer is dedicated to") + private Long projectId; + + @Parameter(name = ApiConstants.DOMAIN_ID, + type = CommandType.UUID, + entityType = DomainResponse.class, + description = "the domain ID which the Bgp Peer is dedicated to.") + private Long domainId; + + @Parameter(name = ApiConstants.IS_DEDICATED, + type = CommandType.BOOLEAN, + description = "Lists only dedicated or non-dedicated Bgp Peers. If not set, lists all dedicated and non-dedicated BGP peers the domain/account can access.") + private Boolean isDedicated; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public Long getZoneId() { + return zoneId; + } + + public Long getAsNumber() { + return asNumber; + } + + public String getAccountName() { + return accountName; + } + + public Long getProjectId() { + return projectId; + } + + public Long getDomainId() { + return domainId; + } + + public Boolean getDedicated() { + return isDedicated; + } + + @Override + public void execute() { + List subnets = routedIpv4Manager.listBgpPeers(this); + ListResponse response = new ListResponse<>(); + List subnetResponses = new ArrayList<>(); + for (BgpPeer subnet : subnets) { + BgpPeerResponse subnetResponse = routedIpv4Manager.createBgpPeerResponse(subnet); + subnetResponse.setObjectName("bgppeer"); + subnetResponses.add(subnetResponse); + } + + response.setResponses(subnetResponses, subnets.size()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } + +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ReleaseDedicatedBgpPeerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ReleaseDedicatedBgpPeerCmd.java new file mode 100644 index 000000000000..92610c233ef0 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/ReleaseDedicatedBgpPeerCmd.java @@ -0,0 +1,88 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.network.BgpPeer; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "releaseBgpPeer", + description = "Releases an existing dedicated Bgp Peer.", + responseObject = BgpPeerResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class ReleaseDedicatedBgpPeerCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BgpPeerResponse.class, required = true, description = "Id of the Bgp Peer") + private Long id; + + public Long getId() { + return id; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_BGP_PEER_RELEASE; + } + + @Override + public String getEventDescription() { + return "Releasing a dedicated Bgp Peer " + getId(); + } + + @Override + public void execute() { + try { + BgpPeer result = routedIpv4Manager.releaseDedicatedBgpPeer(this); + if (result != null) { + BgpPeerResponse response = routedIpv4Manager.createBgpPeerResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to release Bgp Peer:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/UpdateBgpPeerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/UpdateBgpPeerCmd.java new file mode 100644 index 000000000000..ae44330ea033 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/bgp/UpdateBgpPeerCmd.java @@ -0,0 +1,149 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.network.BgpPeer; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.commons.collections.MapUtils; + +import java.util.Collection; +import java.util.Map; + +@APICommand(name = "updateBgpPeer", + description = "Updates an existing Bgp Peer.", + responseObject = BgpPeerResponse.class, + since = "4.20.0", + requestHasSensitiveInfo = true, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}) +public class UpdateBgpPeerCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BgpPeerResponse.class, required = true, description = "Id of the Bgp Peer") + private Long id; + + @Parameter(name = ApiConstants.IP_ADDRESS, + type = CommandType.STRING, + description = "The IPv4 address of the Bgp Peer.") + private String ip4Address; + + @Parameter(name = ApiConstants.IP6_ADDRESS, + type = CommandType.STRING, + description = "The IPv6 address of the Bgp Peer.") + private String ip6Address; + + @Parameter(name = ApiConstants.AS_NUMBER, + type = CommandType.LONG, + description = "The AS number of the Bgp Peer.") + private Long asNumber; + + @Parameter(name = ApiConstants.PASSWORD, + type = CommandType.STRING, + description = "The password of the Bgp Peer.") + private String password; + + @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, + description = "BGP peer details in key/value pairs.") + protected Map details; + + @Parameter(name = ApiConstants.CLEAN_UP_DETAILS, + type = CommandType.BOOLEAN, + description = "optional boolean field, which indicates if details should be cleaned up or not (if set to true, details are removed for this resource; if false or not set, no action)") + private Boolean cleanupDetails; + + public Long getId() { + return id; + } + + public String getIp4Address() { + return ip4Address; + } + + public String getIp6Address() { + return ip6Address; + } + + public Long getAsNumber() { + return asNumber; + } + + public String getPassword() { + return password; + } + + public Map getDetails() { + if (MapUtils.isEmpty(details)) { + return null; + } + Collection paramsCollection = this.details.values(); + return (Map) (paramsCollection.toArray())[0]; + } + + public boolean isCleanupDetails(){ + return cleanupDetails == null ? false : cleanupDetails.booleanValue(); + } + + @Override + public String getEventType() { + return EventTypes.EVENT_BGP_PEER_UPDATE; + } + + @Override + public String getEventDescription() { + return "Updating Bgp Peer " + getId(); + } + + @Override + public void execute() { + try { + BgpPeer result = routedIpv4Manager.updateBgpPeer(this); + if (result != null) { + BgpPeerResponse response = routedIpv4Manager.createBgpPeerResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update Bgp Peer:" + getId()); + } + } catch (InvalidParameterValueException ex) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java index c2d8b3b6839f..c46e4cd6b445 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java @@ -37,7 +37,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.offering.DiskOffering; import com.cloud.offering.ServiceOffering; @@ -47,7 +46,6 @@ @APICommand(name = "createDiskOffering", description = "Creates a disk offering.", responseObject = DiskOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateDiskOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateDiskOfferingCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java index e3b2887ad338..8f6d5413d72d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java @@ -37,7 +37,6 @@ import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.offering.ServiceOffering; @@ -47,7 +46,6 @@ @APICommand(name = "createServiceOffering", description = "Creates a service offering.", responseObject = ServiceOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateServiceOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateServiceOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -248,6 +246,12 @@ public class CreateServiceOfferingCmd extends BaseCmd { @Parameter(name = ApiConstants.ENCRYPT_ROOT, type = CommandType.BOOLEAN, description = "VMs using this offering require root volume encryption", since="4.18") private Boolean encryptRoot; + @Parameter(name = ApiConstants.PURGE_RESOURCES, type = CommandType.BOOLEAN, + description = "Whether to cleanup instance and its associated resource from database upon expunge of the instance", + since="4.20") + private Boolean purgeResources; + + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -275,7 +279,7 @@ public Integer getMemory() { public String getServiceOfferingName() { if (StringUtils.isEmpty(serviceOfferingName)) { - throw new InvalidParameterValueException("Failed to create service offering because offering name has not been spified."); + throw new InvalidParameterValueException("Failed to create service offering because offering name has not been specified."); } return serviceOfferingName; } @@ -483,6 +487,10 @@ public boolean getEncryptRoot() { return false; } + public boolean isPurgeResources() { + return Boolean.TRUE.equals(purgeResources); + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java index 0159cd297f9c..591b09c60a5d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.offering; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "deleteDiskOffering", description = "Updates a disk offering.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteDiskOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteDiskOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java index 9b7f9d48e30a..19203289d104 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.offering; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "deleteServiceOffering", description = "Deletes a service offering.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteServiceOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteServiceOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java index 424ee1609ad8..370453804cfc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; @@ -41,7 +40,6 @@ @APICommand(name = "updateDiskOffering", description = "Updates a disk offering.", responseObject = DiskOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateDiskOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateDiskOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java index 2f3dba4d9c52..e580f0d9f41a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; @@ -41,7 +40,6 @@ @APICommand(name = "updateServiceOffering", description = "Updates a service offering.", responseObject = ServiceOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateServiceOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateServiceOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -91,6 +89,11 @@ public class UpdateServiceOfferingCmd extends BaseCmd { description = "state of the service offering") private String serviceOfferingState; + @Parameter(name = ApiConstants.PURGE_RESOURCES, type = CommandType.BOOLEAN, + description = "Whether to cleanup VM and its associated resource upon expunge", + since="4.20") + private Boolean purgeResources; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -187,6 +190,10 @@ public State getState() { return state; } + public boolean isPurgeResources() { + return Boolean.TRUE.equals(purgeResources); + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java index b15854ca875f..c1d9a6db4296 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.pod; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "createPod", description = "Creates a new Pod.", responseObject = PodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreatePodCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreatePodCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java index bdb9ef266944..c1de800d745b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.pod; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ @APICommand(name = "deletePod", description = "Deletes a Pod.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePodCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeletePodCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java index c0e26a32eee9..5ad0b457ced7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "listPods", description = "Lists all Pods.", responseObject = PodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPodsByCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListPodsByCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java index 99ab5e1cee4a..7dae6f4c7cf0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.pod; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ @APICommand(name = "updatePod", description = "Updates a Pod.", responseObject = PodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdatePodCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdatePodCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/AddRegionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/AddRegionCmd.java index 61bf32ab822c..3a93a2750429 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/AddRegionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/AddRegionCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "addRegion", description = "Adds a Region", responseObject = RegionResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddRegionCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddRegionCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/CreatePortableIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/CreatePortableIpRangeCmd.java index 61deceb06913..fd103c838309 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/CreatePortableIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/CreatePortableIpRangeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.region; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ responseHasSensitiveInfo = false) public class CreatePortableIpRangeCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreatePortableIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// @@ -126,7 +124,7 @@ public void create() throws ResourceAllocationException { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create portable public IP range"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/DeletePortableIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/DeletePortableIpRangeCmd.java index 6cc884645e9c..3ff46fcc94d5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/DeletePortableIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/DeletePortableIpRangeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.region; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ @APICommand(name = "deletePortableIpRange", description = "deletes a range of portable public IP's associated with a region", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePortableIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePortableIpRangeCmd.class.getName()); private static final String s_name = "deleteportablepublicipresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java index ed0ddd68aca2..e654da6df449 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPortableIpRangesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListPortableIpRangesCmd.class.getName()); private static final String s_name = "listportableipresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/RemoveRegionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/RemoveRegionCmd.java index 180e34c7a8f0..3ea323eebfba 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/RemoveRegionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/RemoveRegionCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "removeRegion", description = "Removes specified region", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveRegionCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RemoveRegionCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/UpdateRegionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/UpdateRegionCmd.java index c772efd5e1fe..4267f6a2c286 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/UpdateRegionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/UpdateRegionCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "updateRegion", description = "Updates a region", responseObject = RegionResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateRegionCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateRegionCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ArchiveAlertsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ArchiveAlertsCmd.java index 003b823e106e..dc8c15cf09df 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ArchiveAlertsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ArchiveAlertsCmd.java @@ -19,7 +19,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ArchiveAlertsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ArchiveAlertsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/CleanVMReservationsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/CleanVMReservationsCmd.java index 9acc71ce6930..1ae8c9441233 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/CleanVMReservationsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/CleanVMReservationsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.resource; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -31,7 +30,6 @@ @APICommand(name = "cleanVMReservations", description = "Cleanups VM reservations in the database.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CleanVMReservationsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CleanVMReservationsCmd.class.getName()); private static final String s_name = "cleanvmreservationresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/DeleteAlertsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/DeleteAlertsCmd.java index eb3848927583..9262a120f72c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/DeleteAlertsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/DeleteAlertsCmd.java @@ -19,7 +19,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAlertsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAlertsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertsCmd.java index 3471ab60837a..64cf691e6a73 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertsCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.AlertResponse; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import com.cloud.alert.Alert; import com.cloud.utils.Pair; @@ -34,7 +33,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAlertsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListAlertsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java index 253677616f03..6b31c4cc43cd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java @@ -21,7 +21,6 @@ import java.util.Comparator; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListCapacityCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListCapacityCmd.class.getName()); private static final DecimalFormat s_percentFormat = new DecimalFormat("##.##"); @@ -73,6 +71,9 @@ public class ListCapacityCmd extends BaseListCmd { @Parameter(name = ApiConstants.SORT_BY, type = CommandType.STRING, since = "3.0.0", description = "Sort the results. Available values: Usage") private String sortBy; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -109,6 +110,10 @@ public String getSortBy() { return null; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/PurgeExpungedResourcesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/PurgeExpungedResourcesCmd.java new file mode 100644 index 000000000000..b6833f097336 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/PurgeExpungedResourcesCmd.java @@ -0,0 +1,131 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.resource; + + +import java.util.Date; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.PurgeExpungedResourcesResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.resource.ResourceCleanupService; + +import com.cloud.event.EventTypes; + +@APICommand(name = "purgeExpungedResources", + description = "Purge expunged resources", + responseObject = SuccessResponse.class, + responseView = ResponseObject.ResponseView.Full, + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin}, + since = "4.20") +public class PurgeExpungedResourcesCmd extends BaseAsyncCmd { + + @Inject + ResourceCleanupService resourceCleanupService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.RESOURCE_TYPE, type = BaseCmd.CommandType.STRING, + description = "The type of the resource which need to be purged. Supported types: " + + "VirtualMachine") + private String resourceType; + + @Parameter(name = ApiConstants.BATCH_SIZE, type = CommandType.LONG, + description = "The size of batch used during purging") + private Long batchSize; + + @Parameter(name = ApiConstants.START_DATE, + type = CommandType.DATE, + description = "The start date range of the expunged resources used for purging " + + "(use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\")") + private Date startDate; + + @Parameter(name = ApiConstants.END_DATE, + type = CommandType.DATE, + description = "The end date range of the expunged resources used for purging " + + "(use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\")") + private Date endDate; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public String getResourceType() { + return resourceType; + } + + public Long getBatchSize() { + return batchSize; + } + + public Date getStartDate() { + return startDate; + } + + public Date getEndDate() { + return endDate; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + @Override + public String getEventType() { + return EventTypes.EVENT_PURGE_EXPUNGED_RESOURCES; + } + + @Override + public String getEventDescription() { + return "Purging expunged resources"; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() { + try { + long result = resourceCleanupService.purgeExpungedResources(this); + PurgeExpungedResourcesResponse response = new PurgeExpungedResourcesResponse(); + response.setResourceCount(result); + response.setObjectName(getCommandName().toLowerCase()); + setResponseObject(response); + } catch (Exception e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getLocalizedMessage()); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/StartRollingMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/StartRollingMaintenanceCmd.java index 7ee3e50e0cd9..04fa1002611c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/StartRollingMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/StartRollingMaintenanceCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.RollingMaintenanceResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -55,7 +54,6 @@ public class StartRollingMaintenanceCmd extends BaseAsyncCmd { @Inject RollingMaintenanceManager manager; - public static final Logger s_logger = Logger.getLogger(StartRollingMaintenanceCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java index 5dfada572162..c5ae6890c3e5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.resource; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ description = "Uploads a custom certificate for the console proxy VMs to use for SSL. Can be used to upload a single certificate signed by a known CA. Can also be used, through multiple calls, to upload a chain of certificates from CA to the custom certificate itself.", requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class UploadCustomCertificateCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UploadCustomCertificateCmd.class.getName()); @Parameter(name = ApiConstants.CERTIFICATE, type = CommandType.STRING, required = true, description = "The certificate to be uploaded.", length = 65535) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/DeleteResourceIconCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/DeleteResourceIconCmd.java index 8fb02ea70542..e97a68bddcb6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/DeleteResourceIconCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/DeleteResourceIconCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import java.util.List; @@ -37,7 +36,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}) public class DeleteResourceIconCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteResourceIconCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/ListResourceIconCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/ListResourceIconCmd.java index 0af11ceec220..6cc3173cf155 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/ListResourceIconCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/ListResourceIconCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import java.util.List; @@ -35,7 +34,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}) public class ListResourceIconCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListResourceIconCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/UploadResourceIconCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/UploadResourceIconCmd.java index ea5d8995a2af..5a6acd961bf5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/UploadResourceIconCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/UploadResourceIconCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.awt.image.BufferedImage; @@ -46,7 +45,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}) public class UploadResourceIconCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(UploadResourceIconCmd.class.getName()); ///////////////////////////////////////////////////// @@ -120,7 +118,7 @@ private boolean imageValidator (String base64Image) { return false; } } catch (Exception e) { - LOGGER.warn("Data uploaded not a valid image"); + logger.warn("Data uploaded not a valid image"); return false; } return true; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureOvsElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureOvsElementCmd.java index a1b01a1c04fb..4a8c0bc3a3b9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureOvsElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureOvsElementCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.OvsProviderResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -42,8 +41,6 @@ @APICommand(name = "configureOvsElement", responseObject = OvsProviderResponse.class, description = "Configures an ovs element.", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigureOvsElementCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger - .getLogger(ConfigureOvsElementCmd.class.getName()); @Inject private List _service; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java index b7f7a050d07d..aa119f3aca75 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ @APICommand(name = "configureVirtualRouterElement", responseObject = VirtualRouterProviderResponse.class, description = "Configures a virtual router element.", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ConfigureVirtualRouterElementCmd.class.getName()); @Inject private List _service; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java index f93ca35a06a7..e85531c83c4d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -43,7 +42,6 @@ @APICommand(name = "createVirtualRouterElement", responseObject = VirtualRouterProviderResponse.class, description = "Create a virtual router element.", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVirtualRouterElementCmd.class.getName()); @Inject private List _service; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java index d2dce6b9ff34..39ccee47fbeb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -38,7 +37,6 @@ @APICommand(name = "destroyRouter", description = "Destroys a router.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DestroyRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DestroyRouterCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/GetRouterHealthCheckResultsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/GetRouterHealthCheckResultsCmd.java index 93a48eba49cc..4bef26e05550 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/GetRouterHealthCheckResultsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/GetRouterHealthCheckResultsCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.RouterHealthCheckResultsListResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceUnavailableException; @@ -47,7 +46,6 @@ responseHasSensitiveInfo = false, since = "4.14.0") public class GetRouterHealthCheckResultsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetRouterHealthCheckResultsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListOvsElementsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListOvsElementsCmd.java index 89b39f87e446..a267aa526691 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListOvsElementsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListOvsElementsCmd.java @@ -26,11 +26,9 @@ import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.OvsProviderResponse; import org.apache.cloudstack.api.response.ProviderResponse; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -42,8 +40,7 @@ @APICommand(name = "listOvsElements", description = "Lists all available ovs elements.", responseObject = OvsProviderResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListOvsElementsCmd extends BaseListCmd { - public static final Logger s_logger = Logger - .getLogger(ListNetworkOfferingsCmd.class.getName()); + @Inject private List _service; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java index 6e955e462121..e0cdc0dcf807 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.router; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ @APICommand(name = "listRouters", description = "List routers.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListRoutersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListVirtualRouterElementsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListVirtualRouterElementsCmd.java index 6eb24dce0747..424b8c29d041 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListVirtualRouterElementsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListVirtualRouterElementsCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ @APICommand(name = "listVirtualRouterElements", description = "Lists all available virtual router elements.", responseObject = VirtualRouterProviderResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVirtualRouterElementsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListVirtualRouterElementsCmd.class.getName()); // TODO, VirtualRouterElementServer is not singleton in system! @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java index 6e334d7e4422..1d97dd803098 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ @APICommand(name = "rebootRouter", description = "Starts a router.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RebootRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RebootRouterCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java index 121b2a1bd11f..24ab78810374 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -41,7 +40,6 @@ @APICommand(name = "startRouter", responseObject = DomainRouterResponse.class, description = "Starts a router.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StartRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StartRouterCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java index 2da38d904264..971086a57cff 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ @APICommand(name = "stopRouter", description = "Stops a router.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StopRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StopRouterCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java index 2d5255614c6e..3265a089d672 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "changeServiceForRouter", description = "Upgrades domain router to a new service offering", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpgradeRouterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpgradeRouterCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterTemplateCmd.java index fa0fe5800eeb..74464cab3150 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterTemplateCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.router; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ @APICommand(name = "upgradeRouterTemplate", description = "Upgrades router to use newer template", responseObject = BaseResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpgradeRouterTemplateCmd extends org.apache.cloudstack.api.BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpgradeRouterTemplateCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java index b8ab1461a2ba..7c8f0e21afbb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java @@ -21,7 +21,6 @@ import java.util.Iterator; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ @APICommand(name = "addImageStore", description = "Adds backup image store.", responseObject = ImageStoreResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddImageStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddImageStoreCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -137,7 +135,7 @@ public void execute(){ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java index 34ff171b91fa..2fe3c7cd106a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java @@ -38,7 +38,6 @@ import java.util.Map; import com.cloud.utils.storage.S3.ClientOptions; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -59,7 +58,6 @@ @APICommand(name = "addImageStoreS3", description = "Adds S3 Image Store", responseObject = ImageStoreResponse.class, since = "4.7.0", requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public final class AddImageStoreS3CMD extends BaseCmd implements ClientOptions { - public static final Logger s_logger = Logger.getLogger(AddImageStoreS3CMD.class.getName()); private static final String s_name = "addImageStoreS3Response"; @@ -141,7 +139,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3 Image Store."); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmd.java index a538962e076b..b779ba2a2b47 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ObjectStoreResponse; -import org.apache.log4j.Logger; import java.util.Collection; import java.util.HashMap; @@ -35,7 +34,6 @@ @APICommand(name = "addObjectStoragePool", description = "Adds a object storage pool", responseObject = ObjectStoreResponse.class, since = "4.19.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddObjectStoragePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddObjectStoragePoolCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -125,7 +123,7 @@ public void execute(){ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add object storage"); } } catch (Exception ex) { - s_logger.error("Exception: ", ex); + logger.error("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java index a694aba30fbe..7e925f286d09 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ @APICommand(name = "cancelStorageMaintenance", description = "Cancels maintenance for primary storage", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CancelPrimaryStorageMaintenanceCmd.class.getName()); private static final String s_name = "cancelprimarystoragemaintenanceresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmd.java index 08069446893b..5776eb6464cf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmd.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "createSecondaryStagingStore", description = "create secondary staging store.", responseObject = ImageStoreResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSecondaryStagingStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateSecondaryStagingStoreCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -113,7 +111,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (Exception ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java index 477d7570dfad..75813a7aabf5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java @@ -19,7 +19,6 @@ import java.net.UnknownHostException; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ @APICommand(name = "createStoragePool", description = "Creates a storage pool.", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateStoragePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateStoragePoolCmd.class.getName()); ///////////////////////////////////////////////////// @@ -170,13 +168,13 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add storage pool"); } } catch (ResourceUnavailableException ex1) { - s_logger.warn("Exception: ", ex1); + logger.warn("Exception: ", ex1); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex1.getMessage()); } catch (ResourceInUseException ex2) { - s_logger.warn("Exception: ", ex2); + logger.warn("Exception: ", ex2); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex2.getMessage()); } catch (UnknownHostException ex3) { - s_logger.warn("Exception: ", ex3); + logger.warn("Exception: ", ex3); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex3.getMessage()); } catch (Exception ex4) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex4.getMessage()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteImageStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteImageStoreCmd.java index 194f0baf603e..50a9d9a6f397 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteImageStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteImageStoreCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "deleteImageStore", description = "Deletes an image store or Secondary Storage.", responseObject = SuccessResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteImageStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteImageStoreCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmd.java index ed305d9689d5..6cb38d4c862c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmd.java @@ -25,12 +25,10 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ObjectStoreResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; @APICommand(name = "deleteObjectStoragePool", description = "Deletes an Object Storage Pool", responseObject = SuccessResponse.class, since = "4.19.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteObjectStoragePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteObjectStoragePoolCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java index d87768e7f393..28f71e0740f7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "deleteStoragePool", description = "Deletes a storage pool.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeletePoolCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteSecondaryStagingStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteSecondaryStagingStoreCmd.java index 34a26461fa82..a0c2731ccdaf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteSecondaryStagingStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteSecondaryStagingStoreCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "deleteSecondaryStagingStore", description = "Deletes a secondary staging store .", responseObject = SuccessResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSecondaryStagingStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSecondaryStagingStoreCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java index b19fa78bdd48..a45f72766dc6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.storage.StoragePool; import com.cloud.utils.Pair; @@ -38,7 +37,6 @@ @APICommand(name = "findStoragePoolsForMigration", description = "Lists storage pools available for migration of a volume.", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class FindStoragePoolsForMigrationCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(FindStoragePoolsForMigrationCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java index a9eac3ed76d0..5270569de44e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java @@ -23,12 +23,10 @@ import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; @APICommand(name = "listImageStores", description = "Lists image stores.", responseObject = ImageStoreResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListImageStoresCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListImageStoresCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListObjectStoragePoolsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListObjectStoragePoolsCmd.java index 9d8d8eccc3ce..005a1a54444d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListObjectStoragePoolsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListObjectStoragePoolsCmd.java @@ -23,13 +23,11 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ObjectStoreResponse; -import org.apache.log4j.Logger; @APICommand(name = "listObjectStoragePools", description = "Lists object storage pools.", responseObject = ObjectStoreResponse.class, since = "4.19.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListObjectStoragePoolsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListObjectStoragePoolsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListSecondaryStagingStoresCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListSecondaryStagingStoresCmd.java index e315c8a6d47d..0cad16a247fd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListSecondaryStagingStoresCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListSecondaryStagingStoresCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -29,7 +28,6 @@ @APICommand(name = "listSecondaryStagingStores", description = "Lists secondary staging stores.", responseObject = ImageStoreResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSecondaryStagingStoresCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSecondaryStagingStoresCmd.class.getName()); private static final String s_name = "listsecondarystagingstoreresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java index 3da99de050b1..57a87939b6bd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -33,7 +32,6 @@ @APICommand(name = "listStoragePools", description = "Lists storage pools.", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListStoragePoolsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListStoragePoolsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageProvidersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageProvidersCmd.java index 347b66061f6e..efe7a23b5cb4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageProvidersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageProvidersCmd.java @@ -20,7 +20,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ @APICommand(name = "listStorageProviders", description = "Lists storage providers.", responseObject = StorageProviderResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListStorageProvidersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListStorageProvidersCmd.class.getName()); @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "the type of storage provider: either primary or image", required = true) private String type; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageTagsCmd.java index 43981ee1a3dc..d9bb5d4cd930 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageTagsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageTagsCmd.java @@ -18,7 +18,6 @@ */ package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.BaseListCmd; @@ -27,7 +26,6 @@ @APICommand(name = "listStorageTags", description = "Lists storage tags", responseObject = StorageTagResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListStorageTagsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListStorageTagsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/MigrateSecondaryStorageDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/MigrateSecondaryStorageDataCmd.java index de9b55a9ff12..8f5a7aced3fe 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/MigrateSecondaryStorageDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/MigrateSecondaryStorageDataCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.api.response.MigrationResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; @@ -41,7 +40,6 @@ authorized = {RoleType.Admin}) public class MigrateSecondaryStorageDataCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(MigrateSecondaryStorageDataCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java index ddabefb14c86..818b3a5bbeab 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ @APICommand(name = "enableStorageMaintenance", description = "Puts storage pool into maintenance state", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(PreparePrimaryStorageForMaintenanceCmd.class.getName()); private static final String s_name = "prepareprimarystorageformaintenanceresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/SyncStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/SyncStoragePoolCmd.java index d7a783a4ff43..9f81f2f6c86c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/SyncStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/SyncStoragePoolCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.context.CallContext; -import java.util.logging.Logger; @APICommand(name = "syncStoragePool", description = "Sync storage pool with management server (currently supported for Datastore Cluster in VMware and syncs the datastores in it)", @@ -45,7 +44,6 @@ ) public class SyncStoragePoolCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(SyncStoragePoolCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java index 3351d389c6f6..5ac34f27bada 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java @@ -21,7 +21,6 @@ import java.util.Iterator; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "updateCloudToUseObjectStore", description = "Migrate current NFS secondary storages to use object store.", responseObject = ImageStoreResponse.class, since = "4.3.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateCloudToUseObjectStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateCloudToUseObjectStoreCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -130,7 +128,7 @@ public void execute(){ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java index 87d056cabf7b..0e1631a46ba2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java @@ -25,14 +25,12 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.storage.ImageStore; @APICommand(name = UpdateImageStoreCmd.APINAME, description = "Updates image store read-only status", responseObject = ImageStoreResponse.class, entityType = {ImageStore.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.15.0") public class UpdateImageStoreCmd extends BaseCmd { - private static final Logger LOG = Logger.getLogger(UpdateImageStoreCmd.class.getName()); public static final String APINAME = "updateImageStore"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStorageCapabilitiesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStorageCapabilitiesCmd.java index 8403d3c62418..716c95b45c3e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStorageCapabilitiesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStorageCapabilitiesCmd.java @@ -29,14 +29,12 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "updateStorageCapabilities", description = "Syncs capabilities of storage pools", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0") public class UpdateStorageCapabilitiesCmd extends BaseCmd { - private static final Logger LOG = Logger.getLogger(UpdateStorageCapabilitiesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java index 7a907e0f76a7..f2d7bbeb189e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java @@ -20,7 +20,6 @@ import java.util.Map; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,12 +31,13 @@ import com.cloud.storage.StoragePool; import com.cloud.user.Account; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.ObjectUtils; @SuppressWarnings("rawtypes") @APICommand(name = "updateStoragePool", description = "Updates a storage pool.", responseObject = StoragePoolResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateStoragePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateStoragePoolCmd.class.getName()); ///////////////////////////////////////////////////// @@ -149,7 +149,17 @@ public void setUrl(String url) { @Override public void execute() { - StoragePool result = _storageService.updateStoragePool(this); + StoragePool result = null; + if (ObjectUtils.anyNotNull(name, capacityIops, capacityBytes, url, isTagARule, tags) || + MapUtils.isNotEmpty(details)) { + result = _storageService.updateStoragePool(this); + } + + if (enabled != null) { + result = enabled ? _storageService.enablePrimaryStoragePool(id) + : _storageService.disablePrimaryStoragePool(id); + } + if (result != null) { StoragePoolResponse response = _responseGenerator.createStoragePoolResponse(result); response.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/heuristics/RemoveSecondaryStorageSelectorCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/heuristics/RemoveSecondaryStorageSelectorCmd.java index 79554f44782a..468c87d4d995 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/heuristics/RemoveSecondaryStorageSelectorCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/heuristics/RemoveSecondaryStorageSelectorCmd.java @@ -27,7 +27,7 @@ import org.apache.cloudstack.secstorage.heuristics.Heuristic; @APICommand(name = "removeSecondaryStorageSelector", description = "Removes an existing secondary storage selector.", since = "4.19.0", responseObject = - SecondaryStorageHeuristicsResponse.class, requestHasSensitiveInfo = false, entityType = {Heuristic.class}, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) + SuccessResponse.class, requestHasSensitiveInfo = false, entityType = {Heuristic.class}, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class RemoveSecondaryStorageSelectorCmd extends BaseCmd { @Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, entityType = SecondaryStorageHeuristicsResponse.class, required = true, description = "The unique identifier of the secondary storage selector to be removed.") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java index 7eb87006d0d6..bd72f3213de1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java @@ -19,7 +19,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "addSwift", description = "Adds Swift.", responseObject = ImageStoreResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddSwiftCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddSwiftCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -102,7 +100,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Swift secondary storage"); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java index 6d7bfbaf1b10..e21a23349bb5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.swift; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -31,7 +30,6 @@ @APICommand(name = "listSwifts", description = "List Swift.", responseObject = ImageStoreResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSwiftsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSwiftsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java index 7ed536f6d4cb..7e0faab2fb50 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.systemvm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ @APICommand(name = "destroySystemVm", responseObject = SystemVmResponse.class, description = "Destroys a system virtual machine.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DestroySystemVmCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DestroySystemVmCmd.class.getName()); @ACL(accessType = AccessType.OperateEntry) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java index b6f8c92fa178..e8e5ee0ebad6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ @APICommand(name = "listSystemVms", description = "List system virtual machines.", responseObject = SystemVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSystemVMsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSystemVMsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java index f0f7aca16c8d..ccc6093aa834 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.SystemVmResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -47,7 +46,6 @@ @APICommand(name = "migrateSystemVm", description = "Attempts Migration of a system virtual machine to the host specified.", responseObject = SystemVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class MigrateSystemVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateSystemVMCmd.class.getName()); ///////////////////////////////////////////////////// @@ -171,16 +169,16 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate the system vm"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (ManagementServerException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (VirtualMachineMigrationException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/PatchSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/PatchSystemVMCmd.java index ae3c36b4948e..4f4b26316673 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/PatchSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/PatchSystemVMCmd.java @@ -30,13 +30,11 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.SystemVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "patchSystemVm", description = "Attempts to live patch systemVMs - CPVM, SSVM ", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = { RoleType.Admin }, since = "4.17.0") public class PatchSystemVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(PatchSystemVMCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java index 0ba7e0c2edf5..30bd51184ac3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.systemvm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ @APICommand(name = "rebootSystemVm", description = "Reboots a system VM.", responseObject = SystemVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RebootSystemVmCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RebootSystemVmCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java index f694988efa05..06e57674c537 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java @@ -18,7 +18,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -46,7 +45,6 @@ + "The system vm must be in a \"Stopped\" state for " + "this command to take effect.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ScaleSystemVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ScaleSystemVMCmd.class.getName()); private static final String s_name = "changeserviceforsystemvmresponse"; ///////////////////////////////////////////////////// @@ -111,16 +109,16 @@ public void execute() { try { result = _mgr.upgradeSystemVM(this); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ManagementServerException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (VirtualMachineMigrationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } if (result != null) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java index 0cb517f40585..eac3d64ab59e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.systemvm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ @APICommand(name = "startSystemVm", responseObject = SystemVmResponse.class, description = "Starts a system virtual machine.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StartSystemVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StartSystemVMCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java index 4bb533ce5b6a..1d84382f5d22 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.systemvm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ @APICommand(name = "stopSystemVm", description = "Stops a system VM.", responseObject = SystemVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StopSystemVmCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StopSystemVmCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java index 12f80f32b069..5abe90e3f589 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java @@ -18,7 +18,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ + "The system vm must be in a \"Stopped\" state for " + "this command to take effect.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpgradeSystemVMCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpgradeSystemVMCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java index 9b8d402864a8..9a59efb19f2a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ @APICommand(name = "prepareTemplate", responseObject = TemplateResponse.class, description = "load template into primary storage", entityType = {VirtualMachineTemplate.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class PrepareTemplateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(PrepareTemplateCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java index 95593714feb0..5c0f1fc1cd21 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "addTrafficMonitor", description = "Adds Traffic Monitor Host for Direct Network Usage", responseObject = TrafficMonitorResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddTrafficMonitorCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddTrafficMonitorCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java index 809129402a87..b1810676b744 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ @APICommand(name = "addTrafficType", description = "Adds traffic type to a physical network", responseObject = TrafficTypeResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddTrafficTypeCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddTrafficTypeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java index ff371d6e83d9..8fdb3af399c1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ @APICommand(name = "deleteTrafficMonitor", description = "Deletes an traffic monitor host.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTrafficMonitorCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTrafficMonitorCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java index a728690a09d6..a1e4ebda09a3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -34,7 +33,6 @@ @APICommand(name = "deleteTrafficType", description = "Deletes traffic type of a physical network", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTrafficTypeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTrafficTypeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java index 65b864f2ab6e..a0314586d92d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java @@ -18,7 +18,6 @@ import java.util.Date; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GenerateUsageRecordsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GenerateUsageRecordsCmd.class.getName()); ///////////////////////////////////////////////////// @@ -49,13 +47,13 @@ public class GenerateUsageRecordsCmd extends BaseCmd { @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, - required = true, + required = false, description = "End date range for usage record query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.") private Date endDate; @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, - required = true, + required = false, description = "Start date range for usage record query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.") private Date startDate; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java index f3a65bbfffd8..ed42bc42dbd1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "listTrafficMonitors", description = "List traffic monitor Hosts.", responseObject = TrafficMonitorResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTrafficMonitorsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTrafficMonitorsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypeImplementorsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypeImplementorsCmd.java index 97f43155be67..1ad8872db962 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypeImplementorsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypeImplementorsCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -44,7 +43,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTrafficTypeImplementorsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTrafficTypeImplementorsCmd.class); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypesCmd.java index 6e36ca3bd8d1..d106a736fcab 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "listTrafficTypes", description = "Lists traffic types of a given physical network.", responseObject = ProviderResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTrafficTypesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTrafficTypesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageRecordsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageRecordsCmd.java index 3cb148c2af03..9ce1fcb2bc99 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageRecordsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageRecordsCmd.java @@ -53,16 +53,12 @@ public class ListUsageRecordsCmd extends BaseListCmd { @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "List usage records for the specified domain.") private Long domainId; - @Parameter(name = ApiConstants.END_DATE, - type = CommandType.DATE, - required = true, - description = "End date range for usage record query (use format \"yyyy-MM-dd\" or the new format \"yyyy-MM-dd HH:mm:ss\", e.g. startDate=2015-01-01 or startdate=2015-01-01 10:30:00).") + @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = true, description = "End date range for usage record query. " + + ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS) private Date endDate; - @Parameter(name = ApiConstants.START_DATE, - type = CommandType.DATE, - required = true, - description = "Start date range for usage record query (use format \"yyyy-MM-dd\" or the new format \"yyyy-MM-dd HH:mm:ss\", e.g. startDate=2015-01-01 or startdate=2015-01-01 11:00:00).") + @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "Start date range for usage record query. " + + ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS) private Date startDate; @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account") @@ -137,11 +133,11 @@ public void setDomainId(Long domainId) { } public void setEndDate(Date endDate) { - this.endDate = endDate == null ? null : new Date(endDate.getTime()); + this.endDate = endDate; } public void setStartDate(Date startDate) { - this.startDate = startDate == null ? null : new Date(startDate.getTime()); + this.startDate = startDate; } public void setAccountId(Long accountId) { @@ -167,8 +163,8 @@ public Boolean isRecursive() { @Override public void execute() { Pair, Integer> usageRecords = _usageService.getUsageRecords(this); - ListResponse response = new ListResponse(); - List usageResponses = new ArrayList(); + ListResponse response = new ListResponse<>(); + List usageResponses = new ArrayList<>(); Map> resourceTagResponseMap = null; if (usageRecords != null) { //read the resource tags details for all the resources in usage data and store in Map diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java index 15f9dd20e29f..b993735dba76 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java @@ -18,19 +18,18 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.UsageTypeResponse; +import org.apache.cloudstack.usage.UsageTypes; import com.cloud.user.Account; @APICommand(name = "listUsageTypes", description = "List Usage Types", responseObject = UsageTypeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListUsageTypesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListUsageTypesCmd.class.getName()); @Override public long getEntityOwnerId() { @@ -39,8 +38,8 @@ public long getEntityOwnerId() { @Override public void execute() { - List result = _usageService.listUsageTypes(); - ListResponse response = new ListResponse(); + List result = UsageTypes.listUsageTypes(); + ListResponse response = new ListResponse<>(); response.setResponses(result); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/RemoveRawUsageRecordsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/RemoveRawUsageRecordsCmd.java index 710a11c0d7f2..3e698e614423 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/RemoveRawUsageRecordsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/RemoveRawUsageRecordsCmd.java @@ -29,11 +29,9 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; @APICommand(name = "removeRawUsageRecords", description = "Safely removes raw records from cloud_usage table", responseObject = SuccessResponse.class, since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveRawUsageRecordsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RemoveRawUsageRecordsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java index 103e58c4e038..c7b3c2b433b4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -34,7 +33,6 @@ @APICommand(name = "updateTrafficType", description = "Updates traffic type of a physical network", responseObject = TrafficTypeResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateTrafficTypeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateTrafficTypeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java index e8f5944e4079..e2a2baecc866 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.User; @@ -35,7 +34,6 @@ @APICommand(name = "createUser", description = "Creates a user for an account that already exists", responseObject = UserResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = true) public class CreateUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java index a4f13d5e9c7e..ddf21affb535 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "deleteUser", description = "Deletes a user for an account", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteUserCmd.class.getName()); ///////////////////////////////////////////////////// @@ -86,11 +84,10 @@ public ApiCommandResourceType getApiResourceType() { public void execute() { CallContext.current().setEventDetails("UserId: " + getId()); boolean result = _regionService.deleteUser(this); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - } else { + if (!result) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete user"); } + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java index f7a51d0b1d3b..974c1c7bebed 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ @APICommand(name = "disableUser", description = "Disables a user account", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DisableUserCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableUserCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java index f13eac8f2a90..77d8d530daf2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "enableUser", description = "Enables a user account", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class EnableUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(EnableUserCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java index 5fcad8068b12..3427cef33661 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.user; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -30,7 +29,6 @@ @APICommand(name = "getUser", description = "Find user account by API key", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class GetUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserKeysCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserKeysCmd.java index 253a55652ead..3a3414d95d8a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserKeysCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserKeysCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.UserResponse; import java.util.Map; -import org.apache.log4j.Logger; @APICommand(name = "getUserKeys", description = "This command allows the user to query the seceret and API keys for the account", @@ -44,7 +43,6 @@ public class GetUserKeysCmd extends BaseCmd{ @Parameter(name= ApiConstants.ID, type = CommandType.UUID, entityType = UserResponse.class, required = true, description = "ID of the user whose keys are required") private Long id; - public static final Logger s_logger = Logger.getLogger(GetUserKeysCmd.class.getName()); public Long getID(){ return id; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java index a516a30e769b..ef9e3fa22405 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java @@ -20,7 +20,6 @@ import com.cloud.server.ResourceTag; import com.cloud.user.Account; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "listUsers", description = "Lists user accounts", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListUsersCmd extends BaseListAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListUsersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java index df6ef4f7b0b0..5c8bff0732ad 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.user; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ @APICommand(name = "lockUser", description = "Locks a user account", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class LockUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LockUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/MoveUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/MoveUserCmd.java index b7090977d96f..e57258a45711 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/MoveUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/MoveUserCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.region.RegionService; import org.apache.commons.lang3.ObjectUtils; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.User; @@ -46,7 +45,6 @@ since = "4.11", authorized = {RoleType.Admin}) public class MoveUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(MoveUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterCmd.java index 4199015b9ca4..b3e7d2bec821 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.user; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ description = "This command allows a user to register for the developer API, returning a secret key and an API key. This request is made through the integration API port, so it is a privileged command and must be made on behalf of a user. It is up to the implementer just how the username and password are entered, and then how that translates to an integration API request. Both secret key and API key should be returned to the user", requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RegisterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RegisterCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java index cb9f6e189f03..c9e1e934152d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.region.RegionService; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.User; @@ -37,7 +36,6 @@ @APICommand(name = "updateUser", description = "Updates a user account", responseObject = UserResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = true) public class UpdateUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateUserCmd.class.getName()); ///////////////////////////////////////////////////// @@ -68,7 +66,7 @@ public class UpdateUserCmd extends BaseCmd { @Parameter(name = ApiConstants.CURRENT_PASSWORD, type = CommandType.STRING, description = "Current password that was being used by the user. You must inform the current password when updating the password.", acceptedOnAdminPort = false) private String currentPassword; - @Parameter(name = ApiConstants.SECRET_KEY, type = CommandType.STRING, description = "The secret key for the user. Must be specified with userApiKey") + @Parameter(name = ApiConstants.USER_SECRET_KEY, type = CommandType.STRING, description = "The secret key for the user. Must be specified with userApiKey") private String secretKey; @Parameter(name = ApiConstants.TIMEZONE, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java index 66aefd46966b..c0ba99a82333 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vlan; import com.cloud.utils.net.NetUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,10 +39,11 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.user.Account; +import java.util.Objects; + @APICommand(name = "createVlanIpRange", description = "Creates a VLAN IP range.", responseObject = VlanIpRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVlanIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateVlanIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// @@ -114,6 +114,9 @@ public class CreateVlanIpRangeCmd extends BaseCmd { @Parameter(name = ApiConstants.FOR_SYSTEM_VMS, type = CommandType.BOOLEAN, description = "true if IP range is set to system vms, false if not") private Boolean forSystemVms; + @Parameter(name = ApiConstants.FOR_NSX, type = CommandType.BOOLEAN, description = "true if the IP range is used for NSX resource", since = "4.20.0") + private boolean forNsx; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -154,8 +157,12 @@ public String getStartIp() { return startIp; } + public boolean isForNsx() { + return !Objects.isNull(forNsx) && forNsx; + } + public String getVlan() { - if (vlan == null || vlan.isEmpty()) { + if ((vlan == null || vlan.isEmpty()) && !isForNsx()) { vlan = "untagged"; } return vlan; @@ -226,10 +233,10 @@ public void execute() throws ResourceUnavailableException, ResourceAllocationExc throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vlan ip range"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { - s_logger.info(ex); + logger.info(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java index 7c122dfc22e6..cac029f3aa12 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vlan; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "dedicatePublicIpRange", description = "Dedicates a Public IP range to an account", responseObject = VlanIpRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicatePublicIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DedicatePublicIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java index 390759c2c066..7ab0b053004c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vlan; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "deleteVlanIpRange", description = "Deletes a VLAN IP range.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVlanIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVlanIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ListVlanIpRangesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ListVlanIpRangesCmd.java index 3b5370e3f15d..c11b505c684d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ListVlanIpRangesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ListVlanIpRangesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ @APICommand(name = "listVlanIpRanges", description = "Lists all VLAN IP ranges.", responseObject = VlanIpRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVlanIpRangesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListVlanIpRangesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ReleasePublicIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ReleasePublicIpRangeCmd.java index 846433a60fc9..be4cea41cd89 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ReleasePublicIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ReleasePublicIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vlan; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "releasePublicIpRange", description = "Releases a Public IP range back to the system pool", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleasePublicIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ReleasePublicIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/UpdateVlanIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/UpdateVlanIpRangeCmd.java index caaf4c5ae016..df6d99f8e2af 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/UpdateVlanIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/UpdateVlanIpRangeCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.VlanIpRangeResponse; -import org.apache.log4j.Logger; import com.cloud.dc.Vlan; import com.cloud.exception.ConcurrentOperationException; @@ -39,7 +38,6 @@ authorized = {RoleType.Admin}) public class UpdateVlanIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVlanIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -149,7 +147,7 @@ public void execute() throws ResourceUnavailableException, ResourceAllocationExc throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to Update vlan ip range"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java index 1d53bbb39ad7..ac63a5efac37 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java @@ -19,7 +19,6 @@ import java.util.List; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -46,7 +45,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class AssignVMCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AssignVMCmd.class.getName()); ///////////////////////////////////////////////////// @@ -133,7 +131,7 @@ public void execute() { e.printStackTrace(); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (Exception e) { - s_logger.error("Failed to move vm due to: " + e.getStackTrace()); + logger.error("Failed to move vm due to: " + e.getStackTrace()); if (e.getMessage() != null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage()); } else if (e.getCause() != null) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java index acdc0e074278..6bb7657b86ba 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java @@ -20,7 +20,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ClusterResponse; import org.apache.cloudstack.api.response.PodResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject.ResponseView; @@ -34,7 +33,6 @@ @APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DeployVMCmdByAdmin extends DeployVMCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(DeployVMCmdByAdmin.class.getName()); @Parameter(name = ApiConstants.POD_ID, type = CommandType.UUID, entityType = PodResponse.class, description = "destination Pod ID to deploy the VM to - parameter available for root admin only", since = "4.13") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ExpungeVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ExpungeVMCmd.java index 4cd7f541c4ef..a964e873bad1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ExpungeVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ExpungeVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -43,7 +42,6 @@ @APICommand(name = "expungeVirtualMachine", description = "Expunge a virtual machine. Once expunged, it cannot be recoverd.", responseObject = SuccessResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ExpungeVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ExpungeVMCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java index 98af820201c3..8745ef12ce44 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VMUserDataResponse; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.uservm.UserVm; @@ -32,7 +31,6 @@ @APICommand(name = "getVirtualMachineUserData", description = "Returns user data associated with the VM", responseObject = VMUserDataResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetVMUserDataCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetVMUserDataCmd.class); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java index 3d8b23318ddd..ae6ceff26c7d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java @@ -41,7 +41,6 @@ import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -65,7 +64,6 @@ authorized = {RoleType.Admin}, since = "4.14.0") public class ImportUnmanagedInstanceCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(ImportUnmanagedInstanceCmd.class); @Inject public VmImportService vmImportService; @@ -203,8 +201,8 @@ public Map getNicNetworkList() { for (Map entry : (Collection>)nicNetworkList.values()) { String nic = entry.get(VmDetailConstants.NIC); String networkUuid = entry.get(VmDetailConstants.NETWORK); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); } if (StringUtils.isAnyEmpty(nic, networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) { throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic)); @@ -221,8 +219,8 @@ public Map getNicIpAddressList() { for (Map entry : (Collection>)nicIpAddressList.values()) { String nic = entry.get(VmDetailConstants.NIC); String ipAddress = StringUtils.defaultIfEmpty(entry.get(VmDetailConstants.IP4_ADDRESS), null); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("nic, '%s', gets ip, '%s'", nic, ipAddress)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("nic, '%s', gets ip, '%s'", nic, ipAddress)); } if (StringUtils.isEmpty(nic)) { throw new InvalidParameterValueException(String.format("NIC ID: '%s' is invalid for IP address mapping", nic)); @@ -246,8 +244,8 @@ public Map getDataDiskToDiskOfferingList() { for (Map entry : (Collection>)dataDiskToDiskOfferingList.values()) { String disk = entry.get(VmDetailConstants.DISK); String offeringUuid = entry.get(VmDetailConstants.DISK_OFFERING); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("disk, '%s', gets offering, '%s'", disk, offeringUuid)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("disk, '%s', gets offering, '%s'", disk, offeringUuid)); } if (StringUtils.isAnyEmpty(disk, offeringUuid) || _entityMgr.findByUuid(DiskOffering.class, offeringUuid) == null) { throw new InvalidParameterValueException(String.format("Disk offering ID: %s for disk ID: %s is invalid", offeringUuid, disk)); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java index 945f861cd3e2..6f148ff0ee41 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java @@ -40,7 +40,6 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -53,7 +52,6 @@ authorized = {RoleType.Admin}, since = "4.19.0") public class ImportVmCmd extends ImportUnmanagedInstanceCmd { - public static final Logger LOGGER = Logger.getLogger(ImportVmCmd.class); @Inject public VmImportService vmImportService; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListUnmanagedInstancesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListUnmanagedInstancesCmd.java index 13b6748c74de..6932aa383fa2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListUnmanagedInstancesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListUnmanagedInstancesCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.vm.UnmanagedInstanceTO; import org.apache.cloudstack.vm.VmImportService; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -51,7 +50,6 @@ authorized = {RoleType.Admin}, since = "4.14.0") public class ListUnmanagedInstancesCmd extends BaseListCmd { - public static final Logger LOGGER = Logger.getLogger(ListUnmanagedInstancesCmd.class.getName()); @Inject public VmImportService vmImportService; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java index 5b3e607416be..b48941e7d17a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java @@ -27,14 +27,12 @@ import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.log4j.Logger; import com.cloud.vm.VirtualMachine; @APICommand(name = "listVirtualMachines", description = "List the virtual machines owned by the account.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListVMsCmdByAdmin extends ListVMsCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(ListVMsCmdByAdmin.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVmsForImportCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVmsForImportCmd.java index 88df04d9ef56..f40f1c0cb4a9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVmsForImportCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVmsForImportCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.vm.UnmanagedInstanceTO; import org.apache.cloudstack.vm.VmImportService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -50,7 +49,6 @@ authorized = {RoleType.Admin}, since = "4.19.0") public class ListVmsForImportCmd extends BaseListCmd { - public static final Logger LOGGER = Logger.getLogger(ListVmsForImportCmd.class.getName()); @Inject public VmImportService vmImportService; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java index b685b366cd11..8881a2bc354e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vm; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -50,7 +49,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class MigrateVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateVMCmd.class.getName()); ///////////////////////////////////////////////////// @@ -184,10 +182,10 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate vm"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (VirtualMachineMigrationException | ConcurrentOperationException | ManagementServerException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java index 549d02b45791..b736e8606364 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.SystemVmResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -52,7 +51,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class MigrateVirtualMachineWithVolumeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateVirtualMachineWithVolumeCmd.class.getName()); ///////////////////////////////////////////////////// @@ -157,7 +155,7 @@ private Host getDestinationHost() { Host destinationHost = _resourceService.getHost(getHostId()); // OfflineVmwareMigration: destination host would have to not be a required parameter for stopped VMs if (destinationHost == null) { - s_logger.error(String.format("Unable to find the host with ID [%s].", getHostId())); + logger.error(String.format("Unable to find the host with ID [%s].", getHostId())); throw new InvalidParameterValueException("Unable to find the specified host to migrate the VM."); } return destinationHost; @@ -193,10 +191,10 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate vm"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException | ManagementServerException | VirtualMachineMigrationException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java index b0698ed1e7a2..f34d555dc707 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vm; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ @APICommand(name = "recoverVirtualMachine", description = "Recovers a virtual machine.", responseObject = UserVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RecoverVMCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RecoverVMCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java index 20c7c536c45e..bbcb8840f666 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java @@ -40,7 +40,6 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.vm.UnmanagedVMsManager; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -53,7 +52,6 @@ since = "4.15.0") public class UnmanageVMInstanceCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(UnmanageVMInstanceCmd.class); @Inject private UnmanagedVMsManager unmanagedVMsManager; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java index 44ce32f90c2f..0840b4ce6f99 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ responseHasSensitiveInfo = true) public class DestroyVolumeCmdByAdmin extends DestroyVolumeCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(DestroyVolumeCmdByAdmin.class.getName()); @Override public void execute() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java index f51aeec97197..e276c8a00b65 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -36,7 +35,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RecoverVolumeCmdByAdmin extends RecoverVolumeCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(RecoverVolumeCmdByAdmin.class.getName()); @Override public void execute() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayByAdminCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayByAdminCmd.java index b5ba70cf5e27..1b2163853ec3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayByAdminCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayByAdminCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vpc; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ since = "4.17.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreatePrivateGatewayByAdminCmd extends CreatePrivateGatewayCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(CreatePrivateGatewayByAdminCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java index bd00876ed36c..9dc31f8cefec 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdmin.java @@ -17,13 +17,31 @@ package org.apache.cloudstack.api.command.admin.vpc; import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ResponseObject.ResponseView; import org.apache.cloudstack.api.command.admin.AdminCmd; import org.apache.cloudstack.api.command.user.vpc.CreateVPCCmd; +import org.apache.cloudstack.api.response.BgpPeerResponse; import org.apache.cloudstack.api.response.VpcResponse; import com.cloud.network.vpc.Vpc; +import java.util.List; + @APICommand(name = "createVPC", description = "Creates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Full, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) -public class CreateVPCCmdByAdmin extends CreateVPCCmd implements AdminCmd {} +public class CreateVPCCmdByAdmin extends CreateVPCCmd implements AdminCmd { + @Parameter(name = ApiConstants.BGP_PEER_IDS, + type = CommandType.LIST, + collectionType = CommandType.UUID, + entityType = BgpPeerResponse.class, + description = "Ids of the Bgp Peer for the VPC", + since = "4.20.0") + private List bgpPeerIds; + + + public List getBgpPeerIds() { + return bgpPeerIds; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java index b69e7f4a828e..73b4f5df196b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java @@ -24,12 +24,16 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.Network; +import com.cloud.network.VirtualRouterProvider; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -45,10 +49,18 @@ import com.cloud.network.vpc.VpcOffering; import com.cloud.user.Account; +import static com.cloud.network.Network.Service.Dhcp; +import static com.cloud.network.Network.Service.Dns; +import static com.cloud.network.Network.Service.Lb; +import static com.cloud.network.Network.Service.StaticNat; +import static com.cloud.network.Network.Service.SourceNat; +import static com.cloud.network.Network.Service.PortForwarding; +import static com.cloud.network.Network.Service.NetworkACL; +import static com.cloud.network.Network.Service.UserData; + @APICommand(name = "createVPCOffering", description = "Creates VPC offering", responseObject = VpcOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVPCOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -62,7 +74,6 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.SUPPORTED_SERVICES, type = CommandType.LIST, - required = true, collectionType = CommandType.STRING, description = "services supported by the vpc offering") private List supportedServices; @@ -101,12 +112,40 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { since = "4.13") private List zoneIds; + @Parameter(name = ApiConstants.FOR_NSX, + type = CommandType.BOOLEAN, + description = "true if network offering is meant to be used for NSX, false otherwise.", + since = "4.20.0") + private Boolean forNsx; + + @Parameter(name = ApiConstants.NSX_SUPPORT_LB, + type = CommandType.BOOLEAN, + description = "true if network offering for NSX VPC offering supports Load balancer service.", + since = "4.20.0") + private Boolean nsxSupportsLbService; + @Parameter(name = ApiConstants.ENABLE, type = CommandType.BOOLEAN, description = "set to true if the offering is to be enabled during creation. Default is false", since = "4.16") private Boolean enable; + @Parameter(name = ApiConstants.NETWORK_MODE, + type = CommandType.STRING, + description = "Indicates the mode with which the network will operate. Valid option: NATTED or ROUTED", + since = "4.20.0") + private String networkMode; + + @Parameter(name = ApiConstants.SPECIFY_AS_NUMBER, type = CommandType.BOOLEAN, since = "4.20.0", + description = "true if the VPC offering supports choosing AS number") + private Boolean specifyAsNumber; + + @Parameter(name = ApiConstants.ROUTING_MODE, + type = CommandType.STRING, + since = "4.20.0", + description = "the routing mode for the VPC offering. Supported types are: Static or Dynamic.") + private String routingMode; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -120,21 +159,49 @@ public String getDisplayText() { } public List getSupportedServices() { + if (!isForNsx() && CollectionUtils.isEmpty(supportedServices)) { + throw new InvalidParameterValueException("Supported services needs to be provided"); + } + if (isForNsx()) { + supportedServices = new ArrayList<>(List.of( + Dhcp.getName(), + Dns.getName(), + StaticNat.getName(), + SourceNat.getName(), + NetworkACL.getName(), + PortForwarding.getName(), + UserData.getName() + )); + if (getNsxSupportsLbService()) { + supportedServices.add(Lb.getName()); + } + } return supportedServices; } + public boolean isForNsx() { + return BooleanUtils.isTrue(forNsx); + } + + public String getNetworkMode() { + return networkMode; + } + + public boolean getNsxSupportsLbService() { + return org.apache.commons.lang3.BooleanUtils.isTrue(nsxSupportsLbService); + } + public Map> getServiceProviders() { - Map> serviceProviderMap = null; - if (serviceProviderList != null && !serviceProviderList.isEmpty()) { - serviceProviderMap = new HashMap>(); + Map> serviceProviderMap = new HashMap<>(); + if (serviceProviderList != null && !serviceProviderList.isEmpty() && !isForNsx()) { Collection> servicesCollection = serviceProviderList.values(); Iterator> iter = servicesCollection.iterator(); while (iter.hasNext()) { Map obj = iter.next(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("service provider entry specified: " + obj); + if (logger.isTraceEnabled()) { + logger.trace("service provider entry specified: " + obj); } - HashMap services = (HashMap)obj; + HashMap services = (HashMap) obj; String service = services.get("service"); String provider = services.get("provider"); List providerList = null; @@ -146,11 +213,31 @@ public Map> getServiceProviders() { providerList.add(provider); serviceProviderMap.put(service, providerList); } + } else if (Boolean.TRUE.equals(forNsx)) { + getServiceProviderMapForNsx(serviceProviderMap); } return serviceProviderMap; } + private void getServiceProviderMapForNsx(Map> serviceProviderMap) { + List unsupportedServices = List.of("Vpn", "BaremetalPxeService", "SecurityGroup", "Connectivity", + "Gateway", "Firewall"); + List routerSupported = List.of("Dhcp", "Dns", "UserData"); + List allServices = Network.Service.listAllServices().stream().map(Network.Service::getName).collect(Collectors.toList()); + for (String service : allServices) { + if (unsupportedServices.contains(service)) + continue; + if (routerSupported.contains(service)) + serviceProviderMap.put(service, List.of(VirtualRouterProvider.Type.VPCVirtualRouter.name())); + else + serviceProviderMap.put(service, List.of(Network.Provider.Nsx.getName())); + } + if (!getNsxSupportsLbService()) { + serviceProviderMap.remove(Lb.getName()); + } + } + public Map> getServiceCapabilityList() { return serviceCapabilityList; } @@ -188,6 +275,14 @@ public Boolean getEnable() { return false; } + public Boolean getSpecifyAsNumber() { + return BooleanUtils.toBoolean(specifyAsNumber); + } + + public String getRoutingMode() { + return routingMode; + } + @Override public void create() throws ResourceAllocationException { VpcOffering vpcOff = _vpcProvSvc.createVpcOffering(this); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java index d6c3cac68c72..d104edc381bc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -41,7 +40,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeletePrivateGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePrivateGatewayCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java index aba4c857b0b9..6aa0c3f3afce 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vpc; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "deleteVPCOffering", description = "Deletes VPC offering", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVPCOfferingCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVPCOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListPrivateGatewaysCmdByAdminCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListPrivateGatewaysCmdByAdminCmd.java index 13a63e9cdd83..1211bd3311c5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListPrivateGatewaysCmdByAdminCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListPrivateGatewaysCmdByAdminCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject; @@ -30,6 +29,5 @@ responseView = ResponseObject.ResponseView.Full, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPrivateGatewaysCmdByAdminCmd extends ListPrivateGatewaysCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(ListPrivateGatewaysCmdByAdminCmd.class.getName()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java index 12babad504e0..b59837281ef3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; @@ -40,7 +39,6 @@ @APICommand(name = "updateVPCOffering", description = "Updates VPC offering", responseObject = VpcOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVPCOfferingCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVPCOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java index aca3e00d0957..24660e41ed9b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.zone; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "createZone", description = "Creates a Zone.", responseObject = ZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateZoneCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateZoneCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java index c530e999bf8d..b89636c6fe52 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.zone; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ @APICommand(name = "deleteZone", description = "Deletes a Zone.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteZoneCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteZoneCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java index 264aea3f449c..5d3f5dcd47fa 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.zone; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ @APICommand(name = "markDefaultZoneForAccount", description = "Marks a default zone for this account", responseObject = AccountResponse.class, since = "4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class MarkDefaultZoneForAccountCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MarkDefaultZoneForAccountCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java index 1379050cbf79..1b2793d3e158 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "updateZone", description = "Updates a Zone.", responseObject = ZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateZoneCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateZoneCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java index 57c0e4848434..2fbcb6df1ccb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.response.ProjectRoleResponse; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -44,7 +43,6 @@ @APICommand(name = "addAccountToProject", description = "Adds account to a project", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddAccountToProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddAccountToProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java index 34935f506ec9..5e0977938a30 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java @@ -19,7 +19,6 @@ import java.util.List; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "deleteAccountFromProject", description = "Deletes account from the project", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAccountFromProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAccountFromProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteUserFromProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteUserFromProjectCmd.java index fbcffb7332c2..0731d8378047 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteUserFromProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteUserFromProjectCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -41,7 +40,6 @@ @APICommand(name = "deleteUserFromProject", description = "Deletes user from the project", responseObject = SuccessResponse.class, since = "4.15.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}) public class DeleteUserFromProjectCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(DeleteUserFromProjectCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java index 66a4d91172af..0a962b19e4f3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java @@ -31,7 +31,7 @@ import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; +import org.apache.commons.collections.CollectionUtils; import com.cloud.exception.InvalidParameterValueException; import com.cloud.server.ResourceIcon; @@ -41,7 +41,6 @@ @APICommand(name = "listAccounts", description = "Lists accounts and provides detailed account information for listed accounts", responseObject = AccountResponse.class, responseView = ResponseView.Restricted, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName()); private static final String s_name = "listaccountsresponse"; ///////////////////////////////////////////////////// @@ -75,6 +74,9 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserC description = "flag to display the resource icon for accounts") private Boolean showIcon; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for resource type to return usage", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -118,10 +120,14 @@ public EnumSet getDetails() throws InvalidParameterValueException return dv; } - public Boolean getShowIcon() { + public boolean getShowIcon() { return showIcon != null ? showIcon : false; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -136,12 +142,17 @@ public void execute() { ListResponse response = _queryService.searchForAccounts(this); response.setResponseName(getCommandName()); setResponseObject(response); - if (response != null && response.getCount() > 0 && getShowIcon()) { - updateAccountResponse(response.getResponses()); - } + updateAccountResponse(response.getResponses()); } - private void updateAccountResponse(List response) { + protected void updateAccountResponse(List response) { + if (CollectionUtils.isEmpty(response)) { + return; + } + _resourceLimitService.updateTaggedResourceLimitsAndCountsForAccounts(response, getTag()); + if (!getShowIcon()) { + return; + } for (AccountResponse accountResponse : response) { ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Account, accountResponse.getObjectId()); if (resourceIcon == null) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java index 3d50fc553b80..21aedc7d7725 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java @@ -26,14 +26,12 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ProjectRoleResponse; import org.apache.cloudstack.api.response.UserResponse; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = "listProjectAccounts", description = "Lists project's accounts", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListProjectAccountsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListProjectAccountsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java index 75b83b40f3eb..5ea144785167 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -65,7 +64,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AssociateIPAddrCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmd.class.getName()); private static final String s_name = "associateipaddressresponse"; ///////////////////////////////////////////////////// @@ -325,11 +323,11 @@ public void create() throws ResourceAllocationException { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to allocate IP address"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientAddressCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java index f9bfcb253b4d..f4c06e512f07 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ @APICommand(name = "disassociateIpAddress", description = "Disassociates an IP address from the account.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, entityType = { IpAddress.class }) public class DisassociateIPAddrCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisassociateIPAddrCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java index 22eb70cc0c21..5760ca3ba1c3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; +import org.apache.commons.lang.BooleanUtils; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -43,7 +43,6 @@ @APICommand(name = "listPublicIpAddresses", description = "Lists all public IP addresses", responseObject = IPAddressResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, entityType = { IpAddress.class }) public class ListPublicIpAddressesCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName()); private static final String s_name = "listpublicipaddressesresponse"; @@ -106,6 +105,9 @@ public class ListPublicIpAddressesCmd extends BaseListRetrieveOnlyResourceCountC @Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin}) private Boolean display; + @Parameter(name = ApiConstants.FOR_SYSTEM_VMS, type = CommandType.BOOLEAN, description = "true if range is dedicated for system VMs", since = "4.20.0") + private Boolean forSystemVMs; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -177,6 +179,10 @@ public String getState() { return state; } + public boolean getForSystemVMs() { + return BooleanUtils.isTrue(forSystemVMs); + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReleaseIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReleaseIPAddrCmd.java index eb908300283b..effe45c51ed0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReleaseIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReleaseIPAddrCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -41,7 +40,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ReleaseIPAddrCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseIPAddrCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReserveIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReserveIPAddrCmd.java index 5e72986fb582..e323d413b9ac 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReserveIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReserveIPAddrCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.address; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -51,7 +50,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ReserveIPAddrCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ReserveIPAddrCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java index 7055e1d5cb2e..194967e2e4a4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.address; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -42,7 +41,6 @@ @APICommand(name = "updateIpAddress", description = "Updates an IP address", responseObject = IPAddressResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, entityType = { IpAddress.class }) public class UpdateIPAddrCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateIPAddrCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java index 60dbc2a6e9a0..ee0a38ef35dc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.affinitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ @APICommand(name = "createAffinityGroup", responseObject = AffinityGroupResponse.class, description = "Creates an affinity/anti-affinity group", entityType = {AffinityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateAffinityGroupCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateAffinityGroupCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java index c8967b080204..2f24158cadbb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java @@ -18,7 +18,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupResponse; @@ -40,7 +39,6 @@ @APICommand(name = "deleteAffinityGroup", description = "Deletes affinity group", responseObject = SuccessResponse.class, entityType = {AffinityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAffinityGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAffinityGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java index 2d6f45cc06e5..c90294171b31 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupTypeResponse; import org.apache.cloudstack.api.APICommand; @@ -31,7 +30,6 @@ @APICommand(name = "listAffinityGroupTypes", description = "Lists affinity group types available", responseObject = AffinityGroupTypeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAffinityGroupTypesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListAffinityGroupTypesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java index ed6c31451982..ee23e3794ce1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.affinitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupResponse; @@ -31,7 +30,6 @@ @APICommand(name = "listAffinityGroups", description = "Lists affinity groups", responseObject = AffinityGroupResponse.class, entityType = {AffinityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAffinityGroupsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListAffinityGroupsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java index c70e4fbda669..6cd9bce62595 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java @@ -20,7 +20,6 @@ import java.util.EnumSet; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.affinity.AffinityGroupResponse; @@ -55,7 +54,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateVMAffinityGroupCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVMAffinityGroupCmd.class.getName()); private static final String s_name = "updatevirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java index eff93522b626..a000e265f93b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateAutoScalePolicyCmd.class.getName()); private static final String s_name = "autoscalepolicyresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java index cdbe153f0179..7c9362d4b691 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -45,7 +44,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateAutoScaleVmGroupCmd.class.getName()); private static final String s_name = "autoscalevmgroupresponse"; @@ -233,7 +231,7 @@ public void execute() { } } catch (Exception ex) { // TODO what will happen if Resource Layer fails in a step in between - s_logger.warn("Failed to create autoscale vm group", ex); + logger.warn("Failed to create autoscale vm group", ex); } finally { if (!success || vmGroup == null) { _autoScaleService.deleteAutoScaleVmGroup(getEntityId(), true); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java index 8c1d38c1375e..2d84b20c5828 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java @@ -20,7 +20,6 @@ import java.util.Map; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -51,7 +50,6 @@ responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateAutoScaleVmProfileCmd.class.getName()); private static final String s_name = "autoscalevmprofileresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java index 77bc15b1e0f1..0ffb9afdac4d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ @APICommand(name = "createCondition", description = "Creates a condition for VM auto scaling", responseObject = ConditionResponse.class, entityType = {Condition.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateConditionCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateConditionCmd.class.getName()); private static final String s_name = "conditionresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java index cf5ff3660968..cee9460dbe60 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ @APICommand(name = "deleteAutoScalePolicy", description = "Deletes a autoscale policy.", responseObject = SuccessResponse.class, entityType = {AutoScalePolicy.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAutoScalePolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAutoScalePolicyCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// @@ -93,7 +91,7 @@ public void execute() { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { - s_logger.warn("Failed to delete autoscale policy " + getId()); + logger.warn("Failed to delete autoscale policy " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete AutoScale Policy"); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java index badfcc0957e8..6bf2157533e1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ @APICommand(name = "deleteAutoScaleVmGroup", description = "Deletes a autoscale vm group.", responseObject = SuccessResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAutoScaleVmGroupCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// @@ -103,7 +101,7 @@ public void execute() { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { - s_logger.warn("Failed to delete autoscale vm group " + getId()); + logger.warn("Failed to delete autoscale vm group " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete autoscale vm group"); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java index 06bf7a9d378f..b90f6aa8ffa5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ @APICommand(name = "deleteAutoScaleVmProfile", description = "Deletes a autoscale vm profile.", responseObject = SuccessResponse.class, entityType = {AutoScaleVmProfile.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAutoScaleVmProfileCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAutoScaleVmProfileCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// @@ -92,7 +90,7 @@ public void execute() { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { - s_logger.warn("Failed to delete autoscale vm profile " + getId()); + logger.warn("Failed to delete autoscale vm profile " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete autoscale vm profile"); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java index 840484e45adc..9590012e0375 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ @APICommand(name = "deleteCondition", description = "Removes a condition for VM auto scaling", responseObject = SuccessResponse.class, entityType = {Condition.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteConditionCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteConditionCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -59,14 +57,14 @@ public void execute() { try { result = _autoScaleService.deleteCondition(getId()); } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { - s_logger.warn("Failed to delete condition " + getId()); + logger.warn("Failed to delete condition " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete condition."); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java index b0daf2ec6648..2414c0d82b62 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ @APICommand(name = "disableAutoScaleVmGroup", description = "Disables an AutoScale Vm Group", responseObject = AutoScaleVmGroupResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DisableAutoScaleVmGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableAutoScaleVmGroupCmd.class.getName()); private static final String s_name = "disableautoscalevmGroupresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java index b6f2a82ac49f..96d329d3e0c8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ @APICommand(name = "enableAutoScaleVmGroup", description = "Enables an AutoScale Vm Group", responseObject = AutoScaleVmGroupResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class EnableAutoScaleVmGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(EnableAutoScaleVmGroupCmd.class.getName()); private static final String s_name = "enableautoscalevmGroupresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScalePoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScalePoliciesCmd.java index dc0baf4c7866..4935889c5255 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScalePoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScalePoliciesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "listAutoScalePolicies", description = "Lists autoscale policies.", responseObject = AutoScalePolicyResponse.class, entityType = {AutoScalePolicy.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAutoScalePoliciesCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListAutoScalePoliciesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmGroupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmGroupsCmd.java index 8404fbbb49f4..6aa4abcccd8c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmGroupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmGroupsCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -39,7 +38,6 @@ @APICommand(name = "listAutoScaleVmGroups", description = "Lists autoscale vm groups.", responseObject = AutoScaleVmGroupResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAutoScaleVmGroupsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListAutoScaleVmGroupsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmProfilesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmProfilesCmd.java index 435471faf135..bcaea273ce84 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmProfilesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmProfilesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ @APICommand(name = "listAutoScaleVmProfiles", description = "Lists autoscale vm profiles.", responseObject = AutoScaleVmProfileResponse.class, entityType = {AutoScaleVmProfile.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAutoScaleVmProfilesCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListAutoScaleVmProfilesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListConditionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListConditionsCmd.java index fc1ca7097c8e..febf937d75f6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListConditionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListConditionsCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "listConditions", description = "List Conditions for VM auto scaling", responseObject = ConditionResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListConditionsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListConditionsCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListCountersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListCountersCmd.java index 7da8bd40b61a..d03584fd63d5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListCountersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListCountersCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "listCounters", description = "List the counters for VM auto scaling", responseObject = CounterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListCountersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListCountersCmd.class.getName()); private static final String s_name = "counterresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java index a64b5cb16801..927a9191fcc2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ @APICommand(name = "updateAutoScalePolicy", description = "Updates an existing autoscale policy.", responseObject = AutoScalePolicyResponse.class, entityType = {AutoScalePolicy.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateAutoScalePolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateAutoScalePolicyCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java index 87cd1fd3f4ed..69ae8aa36aa1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -42,7 +41,6 @@ @APICommand(name = "updateAutoScaleVmGroup", description = "Updates an existing autoscale vm group.", responseObject = AutoScaleVmGroupResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateAutoScaleVmGroupCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java index 34c81bfc4839..0b73fd91b525 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -46,7 +45,6 @@ @APICommand(name = "updateAutoScaleVmProfile", description = "Updates an existing autoscale vm profile.", responseObject = AutoScaleVmProfileResponse.class, entityType = {AutoScaleVmProfile.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateAutoScaleVmProfileCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java index e946dd370c13..4ed8244ff0c9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -41,7 +40,6 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0") public class UpdateConditionCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(UpdateConditionCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -69,7 +67,7 @@ public void execute() { response.setResponseName(getCommandName()); setResponseObject(response); } catch (ResourceInUseException ex) { - LOGGER.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupScheduleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupScheduleCmd.java index 6cc765328f61..a76107174358 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupScheduleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupScheduleCmd.java @@ -19,6 +19,7 @@ import javax.inject.Inject; +import com.amazonaws.util.CollectionUtils; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -27,6 +28,7 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.BackupScheduleResponse; +import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.backup.BackupManager; import org.apache.cloudstack.backup.BackupSchedule; @@ -39,6 +41,9 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.utils.exception.CloudRuntimeException; +import java.util.ArrayList; +import java.util.List; + @APICommand(name = "listBackupSchedule", description = "List backup schedule of a VM", responseObject = BackupScheduleResponse.class, since = "4.14.0", @@ -74,9 +79,14 @@ public Long getVmId() { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { try{ - BackupSchedule schedule = backupManager.listBackupSchedule(getVmId()); - if (schedule != null) { - BackupScheduleResponse response = _responseGenerator.createBackupScheduleResponse(schedule); + List schedules = backupManager.listBackupSchedule(getVmId()); + ListResponse response = new ListResponse<>(); + List scheduleResponses = new ArrayList<>(); + if (CollectionUtils.isNullOrEmpty(schedules)) { + for (BackupSchedule schedule : schedules) { + scheduleResponses.add(_responseGenerator.createBackupScheduleResponse(schedule)); + } + response.setResponses(scheduleResponses, schedules.size()); response.setResponseName(getCommandName()); setResponseObject(response); } else { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java index 57a1de2f105c..7d87cc37e6cd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/ListBackupsCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.backup.Backup; import org.apache.cloudstack.backup.BackupManager; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -50,7 +49,6 @@ responseObject = BackupResponse.class, since = "4.14.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListBackupsCmd extends BaseListProjectAndAccountResourcesCmd { - private static final Logger s_logger = Logger.getLogger(ListBackupsCmd.class); @Inject private BackupManager backupManager; @@ -118,7 +116,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE Pair, Integer> result = backupManager.listBackups(this); setupResponseBackupList(result.first(), result.second()); } catch (Exception e) { - s_logger.debug("Exception while listing backups", e); + logger.debug("Exception while listing backups", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/AddBackupRepositoryCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/AddBackupRepositoryCmd.java new file mode 100644 index 000000000000..5d0c838bc377 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/AddBackupRepositoryCmd.java @@ -0,0 +1,137 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.backup.repository; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BackupRepositoryResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.backup.BackupRepository; +import org.apache.cloudstack.backup.BackupRepositoryService; +import org.apache.cloudstack.context.CallContext; + +import javax.inject.Inject; + +@APICommand(name = "addBackupRepository", + description = "Adds a backup repository to store NAS backups", + responseObject = BackupRepositoryResponse.class, since = "4.20.0", + authorized = {RoleType.Admin}) +public class AddBackupRepositoryCmd extends BaseCmd { + + @Inject + private BackupRepositoryService backupRepositoryService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the backup repository") + private String name; + + @Parameter(name = ApiConstants.ADDRESS, type = CommandType.STRING, required = true, description = "address of the backup repository") + private String address; + + @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, required = true, description = "type of the backup repository storage. Supported values: nfs, cephfs, cifs") + private String type; + + @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "backup repository provider") + private String provider; + + @Parameter(name = ApiConstants.MOUNT_OPTIONS, type = CommandType.STRING, description = "shared storage mount options") + private String mountOptions; + + @Parameter(name = ApiConstants.ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + required = true, + description = "ID of the zone where the backup repository is to be added") + private Long zoneId; + + @Parameter(name = ApiConstants.CAPACITY_BYTES, type = CommandType.LONG, description = "capacity of this backup repository") + private Long capacityBytes; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public BackupRepositoryService getBackupRepositoryService() { + return backupRepositoryService; + } + + public String getName() { + return name; + } + + public String getType() { + if ("cephfs".equalsIgnoreCase(type)) { + return "ceph"; + } + return type.toLowerCase(); + } + + public String getAddress() { + return address; + } + + public String getProvider() { + return provider; + } + + public String getMountOptions() { + return mountOptions == null ? "" : mountOptions; + } + + public Long getZoneId() { + return zoneId; + } + + public Long getCapacityBytes() { + return capacityBytes; + } + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() { + try { + BackupRepository result = backupRepositoryService.addBackupRepository(this); + if (result != null) { + BackupRepositoryResponse response = _responseGenerator.createBackupRepositoryResponse(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add backup repository"); + } + } catch (Exception ex4) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex4.getMessage()); + } + + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/DeleteBackupRepositoryCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/DeleteBackupRepositoryCmd.java new file mode 100644 index 000000000000..912170eb4ca2 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/DeleteBackupRepositoryCmd.java @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.backup.repository; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BackupRepositoryResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.backup.BackupRepositoryService; + +import javax.inject.Inject; + +@APICommand(name = "deleteBackupRepository", + description = "delete a backup repository", + responseObject = SuccessResponse.class, since = "4.20.0", + authorized = {RoleType.Admin}) +public class DeleteBackupRepositoryCmd extends BaseCmd { + + @Inject + BackupRepositoryService backupRepositoryService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + entityType = BackupRepositoryResponse.class, + required = true, + description = "ID of the backup repository to be deleted") + private Long id; + + + ///////////////////////////////////////////////////// + //////////////// Accessors ////////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + @Override + public void execute() { + boolean result = backupRepositoryService.deleteBackupRepository(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete backup repository"); + } + } + + @Override + public long getEntityOwnerId() { + return 0; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/ListBackupRepositoriesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/ListBackupRepositoriesCmd.java new file mode 100644 index 000000000000..8293afb657d5 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/backup/repository/ListBackupRepositoriesCmd.java @@ -0,0 +1,110 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.backup.repository; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.utils.Pair; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.BackupRepositoryResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.backup.BackupRepository; +import org.apache.cloudstack.backup.BackupRepositoryService; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +@APICommand(name = "listBackupRepositories", + description = "Lists all backup repositories", + responseObject = BackupRepositoryResponse.class, since = "4.20.0", + authorized = {RoleType.Admin}) +public class ListBackupRepositoriesCmd extends BaseListCmd { + + @Inject + BackupRepositoryService backupRepositoryService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "name of the backup repository") + private String name; + + @Parameter(name = ApiConstants.ZONE_ID, + type = CommandType.UUID, + entityType = ZoneResponse.class, + description = "ID of the zone where the backup repository is to be added") + private Long zoneId; + + @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "the backup repository provider") + private String provider; + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BackupRepositoryResponse.class, description = "ID of the backup repository") + private Long id; + + ///////////////////////////////////////////////////// + //////////////// Accessors ////////////////////////// + ///////////////////////////////////////////////////// + + + public String getName() { + return name; + } + + public Long getZoneId() { + return zoneId; + } + + public String getProvider() { + return provider; + } + + public Long getId() { + return id; + } + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + Pair, Integer> repositoriesPair = backupRepositoryService.listBackupRepositories(this); + List backupRepositories = repositoriesPair.first(); + ListResponse response = new ListResponse<>(); + List responses = new ArrayList<>(); + for (BackupRepository repository : backupRepositories) { + responses.add(_responseGenerator.createBackupRepositoryResponse(repository)); + } + response.setResponses(responses, repositoriesPair.second()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (Exception e) { + String msg = String.format("Error listing backup repositories, due to: %s", e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, msg); + } + + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bgp/ListASNumbersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bgp/ListASNumbersCmd.java new file mode 100644 index 000000000000..b835f7225df3 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bgp/ListASNumbersCmd.java @@ -0,0 +1,134 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.bgp; + +import com.cloud.bgp.ASNumber; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.utils.Pair; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ASNRangeResponse; +import org.apache.cloudstack.api.response.ASNumberResponse; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NetworkResponse; +import org.apache.cloudstack.api.response.VpcResponse; +import org.apache.cloudstack.api.response.ZoneResponse; + +import java.util.ArrayList; +import java.util.List; + +@APICommand(name = "listASNumbers", + description = "List Autonomous Systems Numbers", + responseObject = ASNumberResponse.class, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, + since = "4.20.0") +public class ListASNumbersCmd extends BaseListCmd { + + @Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class, + description = "the zone ID") + private Long zoneId; + + @Parameter(name = ApiConstants.ASN_RANGE_ID, type = BaseCmd.CommandType.UUID, entityType = ASNRangeResponse.class, + description = "the AS Number range ID") + private Long asNumberRangeId; + + @Parameter(name = ApiConstants.AS_NUMBER, type = CommandType.INTEGER, entityType = ASNumberResponse.class, + description = "AS number") + private Integer asNumber; + + @Parameter(name = ApiConstants.IS_ALLOCATED, type = CommandType.BOOLEAN, + description = "to indicate if the AS number is allocated to any network") + private Boolean allocated; + + @Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class, + description = "the network id") + private Long networkId; + + @Parameter(name = ApiConstants.VPC_ID, type = CommandType.UUID, entityType = VpcResponse.class, + description = "the vpc id") + private Long vpcId; + + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, entityType = AccountResponse.class, + description = "account name") + private String account; + + @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, + description = "domain id") + private Long domainId; + + public Long getZoneId() { + return zoneId; + } + + public Long getAsNumberRangeId() { + return asNumberRangeId; + } + + public Boolean getAllocated() { + return allocated; + } + + public Integer getAsNumber() { return asNumber; } + + public Long getNetworkId() { + return networkId; + } + + public String getAccount() { + return account; + } + + public Long getDomainId() { + return domainId; + } + + public Long getVpcId() { + return vpcId; + } + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + try { + Pair, Integer> pair = bgpService.listASNumbers(this); + List asNumbers = pair.first(); + ListResponse response = new ListResponse<>(); + List responses = new ArrayList<>(); + for (ASNumber asn : asNumbers) { + responses.add(_responseGenerator.createASNumberResponse(asn)); + } + response.setResponses(responses, pair.second()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (Exception e) { + String msg = String.format("Error listing AS Numbers, due to: %s", e.getMessage()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, msg); + } + + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/CreateBucketCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/CreateBucketCmd.java index e9a140cf46eb..d2c91e578713 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/CreateBucketCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/CreateBucketCmd.java @@ -34,14 +34,12 @@ import org.apache.cloudstack.api.response.ObjectStoreResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "createBucket", responseObject = BucketResponse.class, description = "Creates a bucket in the specified object storage pool. ", responseView = ResponseView.Restricted, entityType = {Bucket.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateBucketCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateBucketCmd.class.getName()); private static final String s_name = "createbucketresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/DeleteBucketCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/DeleteBucketCmd.java index bf9552b779e6..8cd2790e4ae2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/DeleteBucketCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/DeleteBucketCmd.java @@ -30,13 +30,11 @@ import org.apache.cloudstack.api.response.BucketResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "deleteBucket", description = "Deletes an empty Bucket.", responseObject = SuccessResponse.class, entityType = {Bucket.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeleteBucketCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteBucketCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/ListBucketsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/ListBucketsCmd.java index 897b9fc66960..bda0c7ed381e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/ListBucketsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/ListBucketsCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.BucketResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; -import org.apache.log4j.Logger; import java.util.List; @@ -36,7 +35,6 @@ Bucket.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListBucketsCmd extends BaseListTaggedResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListBucketsCmd.class.getName()); private static final String s_name = "listbucketsresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/UpdateBucketCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/UpdateBucketCmd.java index b3b7e00770d9..8e281b20e915 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/UpdateBucketCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/UpdateBucketCmd.java @@ -32,13 +32,11 @@ import org.apache.cloudstack.api.response.BucketResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "updateBucket", description = "Updates Bucket properties", responseObject = SuccessResponse.class, entityType = {Bucket.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class UpdateBucketCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateBucketCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java index 65920a97c98a..0cecbb370202 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java @@ -23,14 +23,12 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.response.CapabilitiesResponse; import org.apache.cloudstack.config.ApiServiceConfiguration; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = "listCapabilities", description = "Lists capabilities", responseObject = CapabilitiesResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListCapabilitiesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListCapabilitiesCmd.class.getName()); @Override @@ -57,6 +55,7 @@ public void execute() { response.setAllowUserExpungeRecoverVM((Boolean)capabilities.get("allowUserExpungeRecoverVM")); response.setAllowUserExpungeRecoverVolume((Boolean)capabilities.get("allowUserExpungeRecoverVolume")); response.setAllowUserViewAllDomainAccounts((Boolean)capabilities.get("allowUserViewAllDomainAccounts")); + response.setAllowUserForceStopVM((Boolean)capabilities.get(ApiConstants.ALLOW_USER_FORCE_STOP_VM)); response.setKubernetesServiceEnabled((Boolean)capabilities.get("kubernetesServiceEnabled")); response.setKubernetesClusterExperimentalFeaturesEnabled((Boolean)capabilities.get("kubernetesClusterExperimentalFeaturesEnabled")); response.setCustomHypervisorDisplayName((String) capabilities.get("customHypervisorDisplayName")); @@ -71,6 +70,8 @@ public void execute() { response.setInstancesStatsUserOnly((Boolean) capabilities.get(ApiConstants.INSTANCES_STATS_USER_ONLY)); response.setInstancesDisksStatsRetentionEnabled((Boolean) capabilities.get(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_ENABLED)); response.setInstancesDisksStatsRetentionTime((Integer) capabilities.get(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_TIME)); + response.setSharedFsVmMinCpuCount((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_CPU_COUNT)); + response.setSharedFsVmMinRamSize((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_RAM_SIZE)); response.setObjectName("capability"); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java index 11e84f1bef9c..63b47e163b6b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.utils.consoleproxy.ConsoleAccessUtils; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.Map; @@ -46,7 +45,6 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateConsoleEndpointCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateConsoleEndpointCmd.class.getName()); @Inject private ConsoleAccessManager consoleManager; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java index cdff7882e656..669b1782e9e4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java @@ -19,7 +19,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ArchiveEventsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ArchiveEventsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java index 9d049ac5f063..c9c3f1d69554 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java @@ -19,7 +19,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteEventsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteEventsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventTypesCmd.java index dd0f51792781..e3f14f711ce7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventTypesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventTypesCmd.java @@ -18,7 +18,6 @@ import java.util.ArrayList; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -30,7 +29,6 @@ @APICommand(name = "listEventTypes", description = "List Event Types", responseObject = EventTypeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListEventTypesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListEventTypesCmd.class.getName()); @Override public long getEntityOwnerId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java index 89f1c7090e0a..b5273c649222 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java @@ -24,14 +24,12 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.EventResponse; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import com.cloud.event.Event; @APICommand(name = "listEvents", description = "A command to list events.", responseObject = EventResponse.class, entityType = {Event.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListEventsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java index bedb073b8806..8cbbcea6a59f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java @@ -21,7 +21,6 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -48,7 +47,6 @@ @APICommand(name = "createEgressFirewallRule", description = "Creates a egress firewall rule for a given network ", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements FirewallRule { - public static final Logger s_logger = Logger.getLogger(CreateEgressFirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// @@ -257,10 +255,10 @@ public void create() { } } catch (NetworkRuleConflictException ex) { String message = "Network rule conflict: "; - if (!s_logger.isTraceEnabled()) { - s_logger.info(message + ex.getMessage()); + if (!logger.isTraceEnabled()) { + logger.info(message + ex.getMessage()); } else { - s_logger.trace(message, ex); + logger.trace(message, ex); } throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java index b77041ee1748..56c818f832b0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -46,7 +45,6 @@ @APICommand(name = "createFirewallRule", description = "Creates a firewall rule for a given IP address", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements FirewallRule { - public static final Logger s_logger = Logger.getLogger(CreateFirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// @@ -96,11 +94,35 @@ public Long getIpAddressId() { return ipAddressId; } + public void setIpAddressId(Long ipAddressId) { + this.ipAddressId = ipAddressId; + } + @Override public String getProtocol() { return protocol.trim(); } + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public Integer getPublicStartPort() { + return publicStartPort; + } + + public void setPublicStartPort(Integer publicStartPort) { + this.publicStartPort = publicStartPort; + } + + public Integer getPublicEndPort() { + return publicEndPort; + } + + public void setPublicEndPort(Integer publicEndPort) { + this.publicEndPort = publicEndPort; + } + @Override public List getSourceCidrList() { if (cidrlist != null) { @@ -248,7 +270,7 @@ public void create() { setEntityUuid(result.getUuid()); } } catch (NetworkRuleConflictException ex) { - s_logger.trace("Network Rule Conflict: ", ex); + logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage(), ex); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java index 5e1362101502..3545b3d21fb9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -54,7 +53,6 @@ VirtualMachine.class, IpAddress.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule { - public static final Logger s_logger = Logger.getLogger(CreatePortForwardingRuleCmd.class.getName()); // /////////////////////////////////////////////////// @@ -352,7 +350,7 @@ public void create() { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException ex) { - s_logger.trace("Network Rule Conflict: ", ex); + logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage(), ex); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java index f0ba8a92d01c..b93d943eab9f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.firewall; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ @APICommand(name = "deleteEgressFirewallRule", description = "Deletes an egress firewall rule", responseObject = SuccessResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteEgressFirewallRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteEgressFirewallRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java index da1f6b62eca4..c4a4dfd75cb1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.firewall; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -40,7 +39,6 @@ @APICommand(name = "deleteFirewallRule", description = "Deletes a firewall rule", responseObject = SuccessResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteFirewallRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteFirewallRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java index aebf8da159b9..267d18d8a8a7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.firewall; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ @APICommand(name = "deletePortForwardingRule", description = "Deletes a port forwarding rule", responseObject = SuccessResponse.class, entityType = {PortForwardingRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePortForwardingRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePortForwardingRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java index c8c0e85252bb..aa0fd28fdec8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -39,7 +38,6 @@ @APICommand(name = "listEgressFirewallRules", description = "Lists all egress firewall rules for network ID.", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListEgressFirewallRulesCmd extends BaseListTaggedResourcesCmd implements IListFirewallRulesCmd { - public static final Logger s_logger = Logger.getLogger(ListEgressFirewallRulesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java index f79b77893d2a..19a05b158908 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -38,7 +37,6 @@ @APICommand(name = "listFirewallRules", description = "Lists all firewall rules for an IP address.", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListFirewallRulesCmd extends BaseListTaggedResourcesCmd implements IListFirewallRulesCmd { - public static final Logger s_logger = Logger.getLogger(ListFirewallRulesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListPortForwardingRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListPortForwardingRulesCmd.java index 3a942c485fcd..a2e9152a9e47 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListPortForwardingRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListPortForwardingRulesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ @APICommand(name = "listPortForwardingRules", description = "Lists all port forwarding rules for an IP address.", responseObject = FirewallRuleResponse.class, entityType = {PortForwardingRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPortForwardingRulesCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListPortForwardingRulesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java index 1aa060743676..a8db4ec2b29e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.response.FirewallResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -37,7 +36,6 @@ @APICommand(name = "updateEgressFirewallRule", description = "Updates egress firewall rule ", responseObject = FirewallResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateEgressFirewallRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateEgressFirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java index b39efa01350d..89c9bc891eb0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.response.FirewallResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -37,7 +36,6 @@ @APICommand(name = "updateFirewallRule", description = "Updates firewall rule ", responseObject = FirewallResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateFirewallRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateFirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java index 2afc0bb66adf..3fb66bd861fc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -38,7 +37,6 @@ description = "Updates a port forwarding rule. Only the private port and the virtual machine can be updated.", entityType = {PortForwardingRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdatePortForwardingRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdatePortForwardingRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCategoriesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCategoriesCmd.java index 18a209011c1a..c74514d662ca 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCategoriesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCategoriesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "listOsCategories", description = "Lists all supported OS categories for this cloud.", responseObject = GuestOSCategoryResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListGuestOsCategoriesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListGuestOsCategoriesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCmd.java index 9d6cd4385610..b31a46692201 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCmd.java @@ -20,7 +20,6 @@ import java.util.List; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ @APICommand(name = "listOsTypes", description = "Lists all supported OS types for this cloud.", responseObject = GuestOSResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListGuestOsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListGuestOsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java index d4c59cd8d475..18af5b2973ee 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -44,13 +43,12 @@ import com.cloud.utils.net.NetUtils; @APICommand(name = "createIpv6FirewallRule", - description = "Creates an Ipv6 firewall rule in the given network (the network has to belong to VPC)", + description = "Creates an Ipv6 firewall rule in the given network (the network must not belong to VPC)", responseObject = FirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateIpv6FirewallRuleCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateIpv6FirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// @@ -224,7 +222,7 @@ public void create() { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.trace("Network Rule Conflict: ", e); + logger.trace("Network Rule Conflict: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage(), e); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/DeleteIpv6FirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/DeleteIpv6FirewallRuleCmd.java index 5e176a3fabf1..aaee19b59489 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/DeleteIpv6FirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/DeleteIpv6FirewallRuleCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceUnavailableException; @@ -41,7 +40,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeleteIpv6FirewallRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteIpv6FirewallRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/ListIpv6FirewallRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/ListIpv6FirewallRulesCmd.java index 239413162751..7ade2e3ed040 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/ListIpv6FirewallRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/ListIpv6FirewallRulesCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.NetworkResponse; -import org.apache.log4j.Logger; import com.cloud.network.rules.FirewallRule; import com.cloud.utils.Pair; @@ -41,7 +40,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListIpv6FirewallRulesCmd extends BaseListTaggedResourcesCmd implements IListFirewallRulesCmd { - public static final Logger s_logger = Logger.getLogger(ListIpv6FirewallRulesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/UpdateIpv6FirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/UpdateIpv6FirewallRuleCmd.java index 49765c58dafa..2d63d703dc5e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/UpdateIpv6FirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/UpdateIpv6FirewallRuleCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.FirewallResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceUnavailableException; @@ -41,7 +40,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class UpdateIpv6FirewallRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateIpv6FirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java index cdc72de4a107..d795fbabb528 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.iso; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ @APICommand(name = "attachIso", description = "Attaches an ISO to a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class AttachIsoCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(AttachIsoCmd.class.getName()); private static final String s_name = "attachisoresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/CopyIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/CopyIsoCmd.java index b7c13ce4adb2..2db7b7e1eb95 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/CopyIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/CopyIsoCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject.ResponseView; @@ -26,6 +25,5 @@ @APICommand(name = "copyIso", description = "Copies an ISO from one zone to another.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CopyIsoCmd extends CopyTemplateCmd { - public static final Logger s_logger = Logger.getLogger(CopyIsoCmd.class.getName()); private static final String s_name = "copyisoresponse"; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java index 504e7c1b5cf7..feae31026b9f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ @APICommand(name = "deleteIso", description = "Deletes an ISO file.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteIsoCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteIsoCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java index e3b22c4a49f7..292e1c6f099b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.iso; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "detachIso", description = "Detaches any ISO file (if any) currently attached to a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DetachIsoCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(DetachIsoCmd.class.getName()); private static final String s_name = "detachisoresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java index 03ba2fab7225..7861c1e5d412 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -38,7 +37,6 @@ @APICommand(name = "extractIso", description = "Extracts an ISO", responseObject = ExtractResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ExtractIsoCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ExtractIsoCmd.class.getName()); ///////////////////////////////////////////////////// @@ -122,7 +120,7 @@ public void execute() { CallContext.current().setEventDetails(getEventDescription()); String uploadUrl = _templateService.extract(this); if (uploadUrl != null) { - ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl); + ExtractResponse response = _responseGenerator.createImageExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl); response.setResponseName(getCommandName()); response.setObjectName("iso"); this.setResponseObject(response); @@ -130,7 +128,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract ISO"); } } catch (InternalErrorException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java index e17595662994..01a47f22b726 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java @@ -117,7 +117,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE response.setResponseName(getCommandName()); setResponseObject(response); } catch (ResourceAllocationException | MalformedURLException e) { - s_logger.error("Exception while registering ISO", e); + logger.error("Exception while registering ISO", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Exception while registering ISO: " + e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java index fbbe0880aef9..6f220c774b84 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd; @@ -40,10 +39,6 @@ public String getMediaType() { return "iso"; } - @Override - protected Logger getLogger() { - return Logger.getLogger(ListIsoPermissionsCmd.class.getName()); - } @Override protected boolean templateIsCorrectType(VirtualMachineTemplate template) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java index f723cb93ae90..5c4d606a93cd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java @@ -16,10 +16,10 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; +import com.cloud.cpu.CPU; import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,13 +35,13 @@ import com.cloud.template.VirtualMachineTemplate.TemplateFilter; import com.cloud.user.Account; +import org.apache.commons.lang3.StringUtils; import java.util.List; @APICommand(name = "listIsos", description = "Lists all available ISO files.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListIsosCmd extends BaseListTaggedResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListIsosCmd.class.getName()); private static final String s_name = "listisosresponse"; @@ -90,6 +90,11 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd implements UserCmd { @Parameter(name = ApiConstants.SHOW_RESOURCE_ICON, type = CommandType.BOOLEAN, description = "flag to display the resource image for the isos") private Boolean showIcon; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the ISO. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -161,6 +166,13 @@ public boolean listInReadyState() { return onlyReady; } + public CPU.CPUArch getArch() { + if (StringUtils.isBlank(arch)) { + return null; + } + return CPU.CPUArch.fromType(arch); + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java index 1d750038042b..81f525522895 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java @@ -18,6 +18,7 @@ import java.util.List; +import com.cloud.cpu.CPU; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ResourceAllocationException; import com.cloud.template.VirtualMachineTemplate; @@ -43,7 +43,6 @@ @APICommand(name = "registerIso", responseObject = TemplateResponse.class, description = "Registers an existing ISO into the CloudStack Cloud.", responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RegisterIsoCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RegisterIsoCmd.class.getName()); private static final String s_name = "registerisoresponse"; @@ -120,6 +119,11 @@ public class RegisterIsoCmd extends BaseCmd implements UserCmd { description = "true if password reset feature is supported; default is false") private Boolean passwordEnabled; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the ISO. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -231,6 +235,14 @@ public boolean isPasswordEnabled() { return passwordEnabled == null ? false : passwordEnabled; } + public void setArch(String arch) { + this.arch = arch; + } + + public CPU.CPUArch getArch() { + return CPU.CPUArch.fromType(arch); + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java index 58c475c661e3..95d9feed7e33 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.iso; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -33,7 +32,6 @@ @APICommand(name = "updateIso", description = "Updates an ISO file.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName()); private static final String s_name = "updateisoresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoPermissionsCmd.java index dd07faf9a873..02ada253fd25 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoPermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd; @@ -33,10 +32,6 @@ protected String getResponseName() { return "updateisopermissionsresponse"; } - @Override - protected Logger getLogger() { - return Logger.getLogger(UpdateIsoPermissionsCmd.class.getName()); - } @Override public long getEntityOwnerId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/job/QueryAsyncJobResultCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/job/QueryAsyncJobResultCmd.java index f578078e3a18..3d328543dc29 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/job/QueryAsyncJobResultCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/job/QueryAsyncJobResultCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.job; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -29,7 +28,6 @@ @APICommand(name = "queryAsyncJobResult", description = "Retrieves the current status of asynchronous job.", responseObject = AsyncJobResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QueryAsyncJobResultCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QueryAsyncJobResultCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java index 50d69c8d3aea..4f9d2f37d13f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java @@ -17,7 +17,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AssignCertToLoadBalancerCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AssignCertToLoadBalancerCmd.class.getName()); @Parameter(name = ApiConstants.LBID, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java index dc27587b917e..c4424b1d9374 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java @@ -24,7 +24,6 @@ import java.util.Map; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -51,7 +50,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AssignToLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateApplicationLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateApplicationLoadBalancerCmd.java index 8c63c8f7951c..2199dfb4e8b4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateApplicationLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateApplicationLoadBalancerCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InsufficientAddressCapacityException; @@ -44,7 +43,6 @@ @APICommand(name = "createLoadBalancer", description = "Creates an internal load balancer", responseObject = ApplicationLoadBalancerResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateApplicationLoadBalancerCmd.class.getName()); ///////////////////////////////////////////////////// @@ -202,7 +200,7 @@ public void execute() throws ResourceAllocationException, ResourceUnavailableExc setResponseObject(lbResponse); lbResponse.setResponseName(getCommandName()); } catch (Exception ex) { - s_logger.warn("Failed to create load balancer due to exception ", ex); + logger.warn("Failed to create load balancer due to exception ", ex); } finally { if (rule == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create load balancer"); @@ -220,13 +218,13 @@ public void create() { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } catch (InsufficientAddressCapacityException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } catch (InsufficientVirtualNetworkCapacityException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java index 57cb80787385..c24a5f19f077 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LBHealthCheckResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -44,7 +43,6 @@ responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class CreateLBHealthCheckPolicyCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateLBHealthCheckPolicyCmd.class.getName()); // /////////////////////////////////////////////////// @@ -181,7 +179,7 @@ public void create() { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (InvalidParameterValueException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java index 66a15984ae42..c6b5036bc955 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LBStickinessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -44,7 +43,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateLBStickinessPolicyCmd.class.getName()); private static final String s_name = "createLBStickinessPolicy"; @@ -164,7 +162,7 @@ public void create() { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java index ef9e46f3a76f..f86d1ae85dab 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; @@ -52,7 +51,6 @@ @APICommand(name = "createLoadBalancerRule", description = "Creates a load balancer rule", responseObject = LoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements LoadBalancer */{ - public static final Logger s_logger = Logger.getLogger(CreateLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// @@ -284,7 +282,7 @@ public void execute() throws ResourceAllocationException, ResourceUnavailableExc } lbResponse.setResponseName(getCommandName()); } catch (Exception ex) { - s_logger.warn("Failed to create LB rule due to exception ", ex); + logger.warn("Failed to create LB rule due to exception ", ex); } finally { if (!success || rule == null) { @@ -309,10 +307,10 @@ public void create() { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } catch (InsufficientAddressCapacityException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } catch (InvalidParameterValueException e) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteApplicationLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteApplicationLoadBalancerCmd.java index 912c760168b7..410df086393c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteApplicationLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteApplicationLoadBalancerCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ @APICommand(name = "deleteLoadBalancer", description = "Deletes an internal load balancer", responseObject = SuccessResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteApplicationLoadBalancerCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteApplicationLoadBalancerCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java index 159d6b21cbc6..3cf1f345037a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "deleteLBHealthCheckPolicy", description = "Deletes a load balancer health check policy.", responseObject = SuccessResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteLBHealthCheckPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteLBHealthCheckPolicyCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java index 10c342911b44..5d04de3cae58 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "deleteLBStickinessPolicy", description = "Deletes a load balancer stickiness policy.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteLBStickinessPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteLBStickinessPolicyCmd.class.getName()); private static final String s_name = "deleteLBstickinessrruleresponse"; // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java index f05d4cd2be38..b4079430ee32 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ @APICommand(name = "deleteLoadBalancerRule", description = "Deletes a load balancer rule.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteSslCertCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteSslCertCmd.java index 3db733182a1f..887007e537e8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteSslCertCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteSslCertCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ @APICommand(name = "deleteSslCert", description = "Delete a certificate to CloudStack", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSslCertCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSslCertCmd.class.getName()); @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListApplicationLoadBalancersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListApplicationLoadBalancersCmd.java index ad68b301844d..d54f3e1155ec 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListApplicationLoadBalancersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListApplicationLoadBalancersCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.rules.LoadBalancerContainer.Scheme; @@ -38,7 +37,6 @@ @APICommand(name = "listLoadBalancers", description = "Lists internal load balancers", responseObject = ApplicationLoadBalancerResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListApplicationLoadBalancersCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListApplicationLoadBalancersCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java index 1c1f5d1f9afe..cb2cdb446d1c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LBHealthCheckResponse; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; @@ -37,7 +36,6 @@ @APICommand(name = "listLBHealthCheckPolicies", description = "Lists load balancer health check policies.", responseObject = LBHealthCheckResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListLBHealthCheckPoliciesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListLBHealthCheckPoliciesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java index 3d08d9257978..a48e2ea37b71 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.LBStickinessResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.network.rules.LoadBalancer; import com.cloud.network.rules.StickinessPolicy; @@ -38,7 +37,6 @@ @APICommand(name = "listLBStickinessPolicies", description = "Lists load balancer stickiness policies.", responseObject = LBStickinessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListLBStickinessPoliciesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListLBStickinessPoliciesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java index 723e0efec122..3bfc68a95bad 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListLoadBalancerRuleInstancesCmd.class.getName()); private static final String s_name = "listloadbalancerruleinstancesresponse"; @@ -97,10 +95,10 @@ public String getCommandName() { public void execute() { Pair, List> vmServiceMap = _lbService.listLoadBalancerInstances(this); List result = vmServiceMap.first(); - s_logger.debug(String.format("A total of [%s] user VMs were obtained when listing the load balancer instances: [%s].", result.size(), result)); + logger.debug(String.format("A total of [%s] user VMs were obtained when listing the load balancer instances: [%s].", result.size(), result)); List serviceStates = vmServiceMap.second(); - s_logger.debug(String.format("A total of [%s] service states were obtained when listing the load balancer instances: [%s].", serviceStates.size(), serviceStates)); + logger.debug(String.format("A total of [%s] service states were obtained when listing the load balancer instances: [%s].", serviceStates.size(), serviceStates)); if (!isListLbVmip()) { ListResponse response = new ListResponse<>(); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRulesCmd.java index 51a8fa4bfc8c..b8b82f0c4a89 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRulesCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.network.rules.LoadBalancer; import com.cloud.utils.Pair; @@ -39,7 +38,6 @@ @APICommand(name = "listLoadBalancerRules", description = "Lists load balancer rules.", responseObject = LoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListLoadBalancerRulesCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListLoadBalancerRulesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java index 3f422801780b..1bc300fdc69f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ @APICommand(name = "listSslCerts", description = "Lists SSL certificates", responseObject = SslCertResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSslCertsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListSslCertsCmd.class.getName()); @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java index 38593629f787..dfaafe89923b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveCertFromLoadBalancerCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveCertFromLoadBalancerCmd.class.getName()); @Parameter(name = ApiConstants.LBID, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java index 01c30c4b3c73..d29f2676ed55 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java @@ -24,7 +24,6 @@ import java.util.ArrayList; import com.cloud.vm.VirtualMachine; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -49,7 +48,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveFromLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java index 27d49096ed69..d129cd8988f8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -34,7 +33,6 @@ @APICommand(name = "updateLoadBalancer", description = "Updates an internal load balancer", responseObject = ApplicationLoadBalancerResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateApplicationLoadBalancerCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateApplicationLoadBalancerCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBHealthCheckPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBHealthCheckPolicyCmd.java index b6bb59e60dc9..fdd98fc3a0a4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBHealthCheckPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBHealthCheckPolicyCmd.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.LBHealthCheckResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.rules.HealthCheckPolicy; @@ -30,7 +29,6 @@ @APICommand(name = "updateLBHealthCheckPolicy", description = "Updates load balancer health check policy", responseObject = LBHealthCheckResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateLBHealthCheckPolicyCmd extends BaseAsyncCustomIdCmd{ - public static final Logger s_logger = Logger.getLogger(UpdateLBHealthCheckPolicyCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBStickinessPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBStickinessPolicyCmd.java index 2b1f1cc38f60..b2137cf262d8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBStickinessPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBStickinessPolicyCmd.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.LBStickinessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.rules.LoadBalancer; @@ -29,7 +28,6 @@ @APICommand(name = "updateLBStickinessPolicy", description = "Updates load balancer stickiness policy", responseObject = LBStickinessResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateLBStickinessPolicyCmd extends BaseAsyncCustomIdCmd{ - public static final Logger s_logger = Logger.getLogger(UpdateLBStickinessPolicyCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java index b09c01adee63..25254ba9eb75 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LoadBalancerResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -38,7 +37,6 @@ @APICommand(name = "updateLoadBalancerRule", description = "Updates load balancer", responseObject = LoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateLoadBalancerRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UploadSslCertCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UploadSslCertCmd.java index abafde856158..e51b4dee9db6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UploadSslCertCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UploadSslCertCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ @APICommand(name = "uploadSslCert", description = "Upload a certificate to CloudStack", responseObject = SslCertResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UploadSslCertCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UploadSslCertCmd.class.getName()); @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java index 62c4906b1b78..e883a7a0e4dd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -45,7 +44,6 @@ @APICommand(name = "createIpForwardingRule", description = "Creates an IP forwarding rule", responseObject = FirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements StaticNatRule { - public static final Logger s_logger = Logger.getLogger(CreateIpForwardingRuleCmd.class.getName()); ///////////////////////////////////////////////////// @@ -150,7 +148,7 @@ public void create() { setEntityId(rule.getId()); setEntityUuid(rule.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.info("Unable to create static NAT rule due to ", e); + logger.info("Unable to create static NAT rule due to ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java index 5b1335ccf22d..e4c16a317518 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.nat; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ @APICommand(name = "deleteIpForwardingRule", description = "Deletes an IP forwarding rule", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteIpForwardingRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java index 9afdfa3642ee..2bee7dfcc895 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.nat; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "disableStaticNat", description = "Disables static rule for given IP address", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DisableStaticNatCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableStaticNatCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java index ba97356582a3..48c6cc20bf1c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.nat; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ @APICommand(name = "enableStaticNat", description = "Enables static NAT for given IP address", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class EnableStaticNatCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(EnableStaticNatCmd.class.getName()); ///////////////////////////////////////////////////// @@ -133,8 +131,8 @@ public void execute() throws ResourceUnavailableException { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable static NAT"); } } catch (NetworkRuleConflictException ex) { - s_logger.info("Network rule conflict: " + ex.getMessage()); - s_logger.trace("Network Rule Conflict: ", ex); + logger.info("Network rule conflict: " + ex.getMessage()); + logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/ListIpForwardingRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/ListIpForwardingRulesCmd.java index 5e9da328bc84..89981a6453b5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/ListIpForwardingRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/ListIpForwardingRulesCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "listIpForwardingRules", description = "List the IP forwarding rules", responseObject = FirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListIpForwardingRulesCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListIpForwardingRulesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java index 70e67151c1df..8d8e598bcab8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -43,7 +42,6 @@ @APICommand(name = "createNetworkACL", description = "Creates a ACL rule in the given network (the network has to belong to VPC)", responseObject = NetworkACLItemResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkACLCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkACLCmd.class.getName()); // /////////////////////////////////////////////////// @@ -115,6 +113,10 @@ public String getProtocol() { return p; } + public void setProtocol(String protocol) { + this.protocol = protocol; + } + public List getSourceCidrList() { if (cidrlist != null) { return cidrlist; @@ -138,6 +140,9 @@ public NetworkACLItem.TrafficType getTrafficType() { throw new InvalidParameterValueException("Invalid traffic type " + trafficType); } + public void setTrafficType(String trafficType) { + this.trafficType = trafficType; + } // /////////////////////////////////////////////////// // ///////////// API Implementation/////////////////// // /////////////////////////////////////////////////// @@ -146,15 +151,23 @@ public String getAction() { return action; } + public void setAction(String action) { + this.action = action; + } + public Integer getNumber() { return number; } - public Integer getSourcePortStart() { + public Integer getPublicStartPort() { return publicStartPort; } - public Integer getSourcePortEnd() { + public void setPublicStartPort(Integer publicStartPort) { + this.publicStartPort = publicStartPort; + } + + public Integer getPublicEndPort() { if (publicEndPort == null) { if (publicStartPort != null) { return publicStartPort; @@ -166,10 +179,18 @@ public Integer getSourcePortEnd() { return null; } + public void setPublicEndPort(Integer publicEndPort) { + this.publicEndPort = publicEndPort; + } + public Long getNetworkId() { return networkId; } + public void setNetworkId(Long networkId) { + this.networkId = networkId; + } + @Override public long getEntityOwnerId() { Account caller = CallContext.current().getCallingAccount(); @@ -209,6 +230,10 @@ public Long getACLId() { return aclId; } + public void setAclId(Long aclId) { + this.aclId = aclId; + } + public String getReason() { return reason; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java index e5dbcc7b6d1b..cd25a604e776 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -41,7 +40,6 @@ responseObject = NetworkACLResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkACLListCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkACLListCmd.class.getName()); // /////////////////////////////////////////////////// @@ -130,7 +128,7 @@ public long getEntityOwnerId() { } else { account = CallContext.current().getCallingAccount(); if (!Account.Type.ADMIN.equals(account.getType())) { - s_logger.warn(String.format("Only Root Admin can create global ACLs. Account [%s] cannot create any global ACL.", account)); + logger.warn(String.format("Only Root Admin can create global ACLs. Account [%s] cannot create any global ACL.", account)); throw new PermissionDeniedException("Only Root Admin can create global ACLs."); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java index ca379fb1596f..aca3d3ca1b45 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -51,7 +50,6 @@ @APICommand(name = "createNetwork", description = "Creates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkCmd.class.getName()); private static final String s_name = "createnetworkresponse"; @@ -193,6 +191,14 @@ public class CreateNetworkCmd extends BaseCmd implements UserCmd { since = "4.19") private String sourceNatIP; + @Parameter(name = ApiConstants.CIDR_SIZE, type = CommandType.INTEGER, + description = "the CIDR size of IPv4 network. For regular users, this is required for isolated networks with ROUTED mode.", + since = "4.20.0") + private Integer cidrSize; + + @Parameter(name=ApiConstants.AS_NUMBER, type=CommandType.LONG, since = "4.20.0", description="the AS Number of the network") + private Long asNumber; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -366,6 +372,10 @@ public String getIp6Cidr() { return NetUtils.standardizeIp6Cidr(ip6Cidr); } + public Integer getCidrSize() { + return cidrSize; + } + public Long getAclId() { return aclId; } @@ -393,6 +403,10 @@ public String getIp6Dns2() { return ip6Dns2; } + public Long getAsNumber() { + return asNumber; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkPermissionsCmd.java index 4a1f65ba7a23..1df472cbb228 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkPermissionsCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; @@ -43,7 +42,6 @@ since = "4.17.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateNetworkPermissionsCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(CreateNetworkPermissionsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java index f171492b2f6f..ca42626eacb5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "deleteNetworkACL", description = "Deletes a network ACL", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkACLCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkACLCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java index 5c24efae6eb7..45bc86e8c91d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "deleteNetworkACLList", description = "Deletes a network ACL", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkACLListCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkACLListCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java index 5f15c23e23f1..8e8e18c67024 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -37,7 +36,6 @@ @APICommand(name = "deleteNetwork", description = "Deletes a network", responseObject = SuccessResponse.class, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLListsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLListsCmd.java index f3a06142d788..c88f956943b4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLListsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLListsCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.VpcResponse; -import org.apache.log4j.Logger; import com.cloud.network.vpc.NetworkACL; import com.cloud.utils.Pair; @@ -36,7 +35,6 @@ @APICommand(name = "listNetworkACLLists", description = "Lists all network ACLs", responseObject = NetworkACLResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkACLListsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkACLListsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLsCmd.java index 945142f4df00..1ef2b9b7bfbf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLsCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.NetworkACLItemResponse; import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.NetworkResponse; -import org.apache.log4j.Logger; import com.cloud.network.vpc.NetworkACLItem; import com.cloud.utils.Pair; @@ -36,7 +35,6 @@ @APICommand(name = "listNetworkACLs", description = "Lists all network ACL items", responseObject = NetworkACLItemResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkACLsCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkACLsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java index 70c01fd1d889..bdc89d804cdf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.NetworkOfferingResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.offering.NetworkOffering; import com.cloud.utils.Pair; @@ -36,7 +35,6 @@ @APICommand(name = "listNetworkOfferings", description = "Lists all available network offerings.", responseObject = NetworkOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkOfferingsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkOfferingsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -112,6 +110,12 @@ public class ListNetworkOfferingsCmd extends BaseListCmd { @Parameter(name = ApiConstants.FOR_VPC, type = CommandType.BOOLEAN, description = "the network offering can be used" + " only for network creation inside the VPC") private Boolean forVpc; + @Parameter(name = ApiConstants.ROUTING_MODE, + type = CommandType.STRING, + description = "the routing mode for the network offering. Supported types are: Static or Dynamic.", + since = "4.20.0") + private String routingMode; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -188,6 +192,8 @@ public Boolean getForVpc() { return forVpc; } + public String getRoutingMode() { return routingMode; } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkPermissionsCmd.java index 9e6b01d36763..6ea4937e1153 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkPermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -42,7 +41,6 @@ since = "4.17.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListNetworkPermissionsCmd extends BaseCmd implements UserCmd { - public static final Logger LOGGER = Logger.getLogger(ListNetworkPermissionsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmd.java new file mode 100644 index 000000000000..a7c359d66c2d --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmd.java @@ -0,0 +1,107 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.network; + +import com.cloud.utils.net.NetworkProtocols; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NetworkProtocolResponse; +import org.apache.cloudstack.context.CallContext; + +import java.util.ArrayList; +import java.util.List; + +@APICommand(name = "listNetworkProtocols", description = "Lists details of network protocols", responseObject = NetworkProtocolResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + authorized = { RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}, since = "4.19.0") +public class ListNetworkProtocolsCmd extends BaseCmd { + + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.OPTION, type = CommandType.STRING, required = true, + description = "The option of network protocols. Supported values are: protocolnumber, icmptype.") + private String option; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public String getOption() { + return option; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() { + ListResponse response = new ListResponse<>(); + List networkProtocolResponses = new ArrayList<>(); + + NetworkProtocols.Option option = NetworkProtocols.Option.getOption(getOption()); + switch (option) { + case ProtocolNumber: + updateResponseWithProtocolNumbers(networkProtocolResponses); + break; + case IcmpType: + updateResponseWithIcmpTypes(networkProtocolResponses); + break; + default: + break; + } + + response.setResponses(networkProtocolResponses); + response.setResponseName(getCommandName()); + setResponseObject(response); + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + private void updateResponseWithProtocolNumbers(List responses) { + for (NetworkProtocols.ProtocolNumber protocolNumber : NetworkProtocols.ProtocolNumbers) { + NetworkProtocolResponse networkProtocolResponse = new NetworkProtocolResponse(protocolNumber.getNumber(), + protocolNumber.getKeyword(), protocolNumber.getProtocol()); + networkProtocolResponse.setObjectName("networkprotocol"); + responses.add(networkProtocolResponse); + } + } + + private void updateResponseWithIcmpTypes(List responses) { + for (NetworkProtocols.IcmpType icmpType : NetworkProtocols.IcmpTypes) { + NetworkProtocolResponse networkProtocolResponse = new NetworkProtocolResponse(icmpType.getType(), + null, icmpType.getDescription()); + for (NetworkProtocols.IcmpCode code : icmpType.getIcmpCodes()) { + networkProtocolResponse.addDetail(String.valueOf(code.getCode()), code.getDescription()); + } + networkProtocolResponse.setObjectName("networkprotocol"); + responses.add(networkProtocolResponse); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java index c1e85a9b4c30..0e8425b14b4b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.response.NetworkOfferingResponse; import org.apache.cloudstack.api.response.ResourceIconResponse; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -46,7 +45,6 @@ @APICommand(name = "listNetworks", description = "Lists all available networks.", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworksCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworksCmd.class.getName()); private static final String s_name = "listnetworksresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/MoveNetworkAclItemCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/MoveNetworkAclItemCmd.java index da6ac437aa0e..5d36dcfd8e93 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/MoveNetworkAclItemCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/MoveNetworkAclItemCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.NetworkACLItemResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.vpc.NetworkACLItem; @@ -32,7 +31,6 @@ @APICommand(name = "moveNetworkAclItem", description = "Move an ACL rule to a position bettwen two other ACL rules of the same ACL network list", responseObject = NetworkACLItemResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class MoveNetworkAclItemCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(MoveNetworkAclItemCmd.class.getName()); private static final String s_name = "moveNetworkAclItemResponse"; @Parameter(name = ApiConstants.ID, type = CommandType.STRING, required = true, description = "The ID of the network ACL rule that is being moved to a new position.") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/RemoveNetworkPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/RemoveNetworkPermissionsCmd.java index 05785c815886..c199d872e0c0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/RemoveNetworkPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/RemoveNetworkPermissionsCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; @@ -43,7 +42,6 @@ since = "4.17.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class RemoveNetworkPermissionsCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(RemoveNetworkPermissionsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java index ea4e74149f4d..f6e9557aadb3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "replaceNetworkACLList", description = "Replaces ACL associated with a network or private gateway", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReplaceNetworkACLListCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReplaceNetworkACLListCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ResetNetworkPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ResetNetworkPermissionsCmd.java index f9817f9be5f9..a23b98c84a88 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ResetNetworkPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ResetNetworkPermissionsCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.network.Network; import com.cloud.user.Account; @@ -38,7 +37,6 @@ since = "4.17.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ResetNetworkPermissionsCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(ResetNetworkPermissionsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java index 141dee3c9a04..ffc2e36dee53 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -43,7 +42,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RestartNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RestartNetworkCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java index f675fa23e343..42cb0697edb4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.NetworkACLItemResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceUnavailableException; @@ -35,7 +34,6 @@ @APICommand(name = "updateNetworkACLItem", description = "Updates ACL item with specified ID", responseObject = NetworkACLItemResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkACLItemCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLItemCmd.class.getName()); private static final String s_name = "createnetworkaclresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java index ddcb202aa8da..adab885542d1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceUnavailableException; @@ -34,7 +33,6 @@ @APICommand(name = "updateNetworkACLList", description = "Updates network ACL list", responseObject = SuccessResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLListCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java index d3cc169b7da4..0d92a635e7f9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.NetworkOfferingResponse; import org.apache.cloudstack.api.response.NetworkResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -43,7 +42,6 @@ @APICommand(name = "updateNetwork", description = "Updates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkCmd extends BaseAsyncCustomIdCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmd.class.getName()); private static final String s_name = "updatenetworkresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmd.java new file mode 100644 index 000000000000..7146d1ae1d19 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmd.java @@ -0,0 +1,271 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.network.routing; + +import java.util.ArrayList; +import java.util.List; + +import com.cloud.exception.NetworkRuleConflictException; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCreateCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.FirewallResponse; +import org.apache.cloudstack.api.response.FirewallRuleResponse; +import org.apache.cloudstack.api.response.NetworkResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.commons.lang3.StringUtils; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.rules.FirewallRule; +import com.cloud.user.Account; +import com.cloud.utils.net.NetUtils; + +@APICommand(name = "createRoutingFirewallRule", + description = "Creates a routing firewall rule in the given network in ROUTED mode", + since = "4.20.0", + responseObject = FirewallRuleResponse.class, + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class CreateRoutingFirewallRuleCmd extends BaseAsyncCreateCmd { + + + // /////////////////////////////////////////////////// + // ////////////// API parameters ///////////////////// + // /////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, description = "the protocol for the firewall rule. Valid values are TCP/UDP/ICMP/ALL or valid protocol number") + private String protocol; + + @Parameter(name = ApiConstants.START_PORT, type = CommandType.INTEGER, description = "the starting port of firewall rule") + private Integer publicStartPort; + + @Parameter(name = ApiConstants.END_PORT, type = CommandType.INTEGER, description = "the ending port of firewall rule") + private Integer publicEndPort; + + @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, + description = "the source CIDR list to allow traffic from. Multiple entries must be separated by a single comma character (,).") + protected List sourceCidrList; + + @Parameter(name = ApiConstants.DEST_CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, + description = "the destination CIDR list to allow traffic to. Multiple entries must be separated by a single comma character (,).") + protected List destinationCidrlist; + + @Parameter(name = ApiConstants.ICMP_TYPE, type = CommandType.INTEGER, description = "type of the ICMP message being sent") + private Integer icmpType; + + @Parameter(name = ApiConstants.ICMP_CODE, type = CommandType.INTEGER, description = "error code for this ICMP message") + private Integer icmpCode; + + @Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class, + description = "The network of the VM the firewall rule will be created for", required = true) + private Long networkId; + + @Parameter(name = ApiConstants.TRAFFIC_TYPE, type = CommandType.STRING, + description = "the traffic type for the Routing firewall rule, can be ingress or egress, defaulted to ingress if not specified") + private String trafficType; + + @Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, + description = "an optional field, whether to the display the rule to the end user or not", authorized = {RoleType.Admin}) + private Boolean display; + + // /////////////////////////////////////////////////// + // ///////////////// Accessors /////////////////////// + // /////////////////////////////////////////////////// + + @Override + public boolean isDisplay() { + if (display != null) { + return display; + } else { + return true; + } + } + + public String getProtocol() { + String p = protocol == null ? "" : protocol.trim(); + if (StringUtils.isNumeric(p)) { + int protoNumber = Integer.parseInt(p); + switch (protoNumber) { + case 1: + p = NetUtils.ICMP_PROTO; + break; + case 6: + p = NetUtils.TCP_PROTO; + break; + case 17: + p = NetUtils.UDP_PROTO; + break; + default: + throw new InvalidParameterValueException(String.format("Protocol %d not supported", protoNumber)); + + } + } + return p; + } + + public List getSourceCidrList() { + if (sourceCidrList != null) { + return sourceCidrList; + } else { + List oneCidrList = new ArrayList(); + oneCidrList.add(NetUtils.ALL_IP4_CIDRS); + return oneCidrList; + } + } + + public List getDestinationCidrList() { + if (destinationCidrlist != null) { + return destinationCidrlist; + } else { + List oneCidrList = new ArrayList(); + oneCidrList.add(NetUtils.ALL_IP4_CIDRS); + return oneCidrList; + } + } + + public FirewallRule.TrafficType getTrafficType() { + if (trafficType == null) { + return FirewallRule.TrafficType.Ingress; + } + for (FirewallRule.TrafficType type : FirewallRule.TrafficType.values()) { + if (type.toString().equalsIgnoreCase(trafficType)) { + return type; + } + } + throw new InvalidParameterValueException("Invalid traffic type " + trafficType); + } + + // /////////////////////////////////////////////////// + // ///////////// API Implementation/////////////////// + // /////////////////////////////////////////////////// + + public Integer getSourcePortStart() { + return publicStartPort; + } + + public Integer getSourcePortEnd() { + if (publicEndPort == null) { + if (publicStartPort != null) { + return publicStartPort; + } + } else { + return publicEndPort; + } + + return null; + } + + public Long getNetworkId() { + return networkId; + } + + @Override + public long getEntityOwnerId() { + Network network = _networkService.getNetwork(networkId); + if (network != null) { + return network.getAccountId(); + } + Account owner = CallContext.current().getCallingAccount(); + return owner.getAccountId(); + } + + @Override + public String getEventType() { + return EventTypes.EVENT_ROUTING_IPV4_FIREWALL_RULE_CREATE; + } + + @Override + public String getEventDescription() { + return "Creating ipv4 firewall rule for routed network"; + } + + public Integer getIcmpCode() { + if (icmpCode != null) { + return icmpCode; + } else if (getProtocol().equalsIgnoreCase(NetUtils.ICMP_PROTO)) { + return -1; + } + return null; + } + + public Integer getIcmpType() { + if (icmpType != null) { + return icmpType; + } else if (getProtocol().equalsIgnoreCase(NetUtils.ICMP_PROTO)) { + return -1; + + } + return null; + } + + @Override + public void create() { + try { + FirewallRule result = routedIpv4Manager.createRoutingFirewallRule(this); + setEntityId(result.getId()); + setEntityUuid(result.getUuid()); + } catch (NetworkRuleConflictException e) { + logger.trace("Network Rule Conflict: ", e); + throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage(), e); + } + } + + @Override + public void execute() throws ResourceUnavailableException { + boolean success = false; + FirewallRule rule = _firewallService.getFirewallRule(getEntityId()); + try { + CallContext.current().setEventDetails("Rule ID: " + getEntityId()); + success = routedIpv4Manager.applyRoutingFirewallRule(rule.getId()); + + // State is different after the rule is applied, so get new object here + rule = _firewallService.getFirewallRule(getEntityId()); + FirewallResponse ruleResponse = new FirewallResponse(); + if (rule != null) { + ruleResponse = _responseGenerator.createFirewallResponse(rule); + setResponseObject(ruleResponse); + } + ruleResponse.setResponseName(getCommandName()); + } catch (Exception ex) { + logger.error("Got exception when create Routing firewall rules: " + ex); + } finally { + if (!success || rule == null) { + routedIpv4Manager.revokeRoutingFirewallRule(getEntityId()); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Routing firewall rule"); + } + } + } + + @Override + public Long getApiResourceId() { + return getNetworkId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Network; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmd.java new file mode 100644 index 000000000000..16696f5f71b7 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmd.java @@ -0,0 +1,109 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.network.routing; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.FirewallRuleResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; + +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.rules.FirewallRule; +import com.cloud.user.Account; + +@APICommand(name = "deleteRoutingFirewallRule", + description = "Deletes a routing firewall rule", + since = "4.20.0", + responseObject = SuccessResponse.class, + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class DeleteRoutingFirewallRuleCmd extends BaseAsyncCmd { + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the Routing firewall rule") + private Long id; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getEventType() { + return EventTypes.EVENT_ROUTING_IPV4_FIREWALL_RULE_DELETE; + } + + @Override + public String getEventDescription() { + return String.format("Deleting ipv4 routing firewall rule ID=%s", id); + } + + @Override + public long getEntityOwnerId() { + FirewallRule rule = _firewallService.getFirewallRule(id); + if (rule != null) { + return rule.getAccountId(); + } + Account caller = CallContext.current().getCallingAccount(); + return caller.getAccountId(); + } + + @Override + public void execute() throws ResourceUnavailableException { + CallContext.current().setEventDetails("Routing firewall rule ID: " + id); + boolean result = routedIpv4Manager.revokeRoutingFirewallRule(id); + + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Routing firewall rule"); + } + } + + @Override + public Long getApiResourceId() { + FirewallRule rule = _firewallService.getFirewallRule(id); + if (rule != null) { + return rule.getNetworkId(); + } + return null; + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Network; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmd.java new file mode 100644 index 000000000000..3fdf3b0f5b46 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmd.java @@ -0,0 +1,115 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.network.routing; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListTaggedResourcesCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.command.user.firewall.IListFirewallRulesCmd; +import org.apache.cloudstack.api.response.FirewallResponse; +import org.apache.cloudstack.api.response.FirewallRuleResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NetworkResponse; + +import com.cloud.network.rules.FirewallRule; +import com.cloud.utils.Pair; + +@APICommand(name = "listRoutingFirewallRules", + description = "Lists all Routing firewall rules", + since = "4.20.0", + responseObject = FirewallRuleResponse.class, + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class ListRoutingFirewallRulesCmd extends BaseListTaggedResourcesCmd implements IListFirewallRulesCmd { + + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, + description = "Lists Routing firewall rule with the specified ID") + private Long id; + + @Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class, description = "list Routing firewall rules by network ID") + private Long networkId; + + @Parameter(name = ApiConstants.TRAFFIC_TYPE, type = CommandType.STRING, description = "list Routing firewall rules by traffic type - ingress or egress") + private String trafficType; + + @Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", authorized = {RoleType.Admin}) + private Boolean display; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + @Override + public Long getNetworkId() { + return networkId; + } + + @Override + public Long getId() { + return id; + } + + @Override + public FirewallRule.TrafficType getTrafficType() { + if (trafficType != null) { + return FirewallRule.TrafficType.valueOf(trafficType); + } + return null; + } + + @Override + public Long getIpAddressId() { + return null; + } + + @Override + public Boolean getDisplay() { + if (display != null) { + return display; + } + return super.getDisplay(); + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() { + Pair, Integer> result = routedIpv4Manager.listRoutingFirewallRules(this); + ListResponse response = new ListResponse<>(); + List ruleResponses = new ArrayList<>(); + + for (FirewallRule rule : result.first()) { + FirewallResponse ruleData = _responseGenerator.createFirewallResponse(rule); + ruleResponses.add(ruleData); + } + response.setResponses(ruleResponses, result.second()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmd.java new file mode 100644 index 000000000000..c6f6034b1ba1 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmd.java @@ -0,0 +1,125 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.network.routing; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.FirewallResponse; +import org.apache.cloudstack.api.response.FirewallRuleResponse; +import org.apache.cloudstack.context.CallContext; + +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.rules.FirewallRule; +import com.cloud.user.Account; + +@APICommand(name = "updateRoutingFirewallRule", + description = "Updates Routing firewall rule with specified ID", + since = "4.20.0", + responseObject = FirewallRuleResponse.class, + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class UpdateRoutingFirewallRuleCmd extends BaseAsyncCustomIdCmd { + + + // /////////////////////////////////////////////////// + // ////////////// API parameters ///////////////////// + // /////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the Routing firewall rule") + private Long id; + + @Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "an optional field, whether to the display the Routing firewall rule to the end user or not", + authorized = {RoleType.Admin}) + private Boolean display; + + // /////////////////////////////////////////////////// + // ///////////////// Accessors /////////////////////// + // /////////////////////////////////////////////////// + + @Override + public boolean isDisplay() { + if (display != null) { + return display; + } else { + return true; + } + } + + public Long getId() { + return id; + } + + // /////////////////////////////////////////////////// + // ///////////// API Implementation/////////////////// + // /////////////////////////////////////////////////// + + @Override + public long getEntityOwnerId() { + FirewallRule rule = _firewallService.getFirewallRule(id); + if (rule != null) { + return rule.getAccountId(); + } + Account caller = CallContext.current().getCallingAccount(); + return caller.getAccountId(); + } + + @Override + public String getEventType() { + return EventTypes.EVENT_ROUTING_IPV4_FIREWALL_RULE_UPDATE; + } + + @Override + public String getEventDescription() { + return "Updating ipv4 routing firewall rule"; + } + + @Override + public void execute() throws ResourceUnavailableException { + CallContext.current().setEventDetails("Rule Id: " + getId()); + FirewallRule rule = routedIpv4Manager.updateRoutingFirewallRule(this); + FirewallResponse ruleResponse = _responseGenerator.createFirewallResponse(rule); + setResponseObject(ruleResponse); + ruleResponse.setResponseName(getCommandName()); + } + + @Override + public void checkUuid() { + if (this.getCustomId() != null) { + _uuidMgr.checkUuid(this.getCustomId(), FirewallRule.class); + } + } + + @Override + public Long getApiResourceId() { + FirewallRule rule = _firewallService.getFirewallRule(id); + if (rule != null) { + return rule.getNetworkId(); + } + return null; + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Network; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java index 6f32b58b733b..f9b9ec59a400 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java @@ -16,28 +16,26 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; -import com.cloud.offering.DiskOffering.State; -import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; -import org.apache.cloudstack.api.response.StoragePoolResponse; -import org.apache.cloudstack.api.response.VolumeResponse; -import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.commons.lang3.EnumUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import static com.cloud.offering.DiskOffering.State.Active; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.StoragePoolResponse; +import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.commons.lang3.EnumUtils; +import org.apache.commons.lang3.StringUtils; -import static com.cloud.offering.DiskOffering.State.Active; +import com.cloud.offering.DiskOffering.State; @APICommand(name = "listDiskOfferings", description = "Lists all available disk offerings.", responseObject = DiskOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListDiskOfferingsCmd.class.getName()); ///////////////////////////////////////////////////// @@ -77,6 +75,13 @@ public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd since = "4.19") private String diskOfferingState; + @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, + type = CommandType.UUID, + entityType = UserVmResponse.class, + description = "The ID of a virtual machine. Pass this in if you want to see the suitable disk offering that can be used to create and add a disk to the virtual machine. Suitability is returned with suitableforvirtualmachine flag in the response", + since = "4.20.0") + private Long virtualMachineId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -116,13 +121,16 @@ public State getState() { return state; } + public Long getVirtualMachineId() { + return virtualMachineId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @Override public void execute() { - ListResponse response = _queryService.searchForDiskOfferings(this); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java index 246984aaadab..1b3f531e370d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java @@ -16,26 +16,25 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; -import com.cloud.offering.ServiceOffering.State; -import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; -import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.commons.lang3.EnumUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import static com.cloud.offering.ServiceOffering.State.Active; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ServiceOfferingResponse; +import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.commons.lang3.EnumUtils; +import org.apache.commons.lang3.StringUtils; -import static com.cloud.offering.ServiceOffering.State.Active; +import com.cloud.offering.ServiceOffering.State; @APICommand(name = "listServiceOfferings", description = "Lists all available service offerings.", responseObject = ServiceOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName()); ///////////////////////////////////////////////////// @@ -104,6 +103,13 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC since = "4.19") private String serviceOfferingState; + @Parameter(name = ApiConstants.TEMPLATE_ID, + type = CommandType.UUID, + entityType = TemplateResponse.class, + description = "The ID of the template that listed offerings must support", + since = "4.20.0") + private Long templateId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -161,6 +167,10 @@ public State getState() { return state; } + public Long getTemplateId() { + return templateId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java index 58cc93ff95d3..42e045d4389f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "activateProject", description = "Activates a project", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ActivateProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ActivateProjectCmd.class.getName()); private static final String s_name = "activaterojectresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java index a5742e8d0dea..cb93729381a4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -39,7 +38,6 @@ @APICommand(name = "createProject", description = "Creates a project", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateProjectCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java index 85b411b075d3..1fd205fdae41 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "deleteProject", description = "Deletes a project", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java index 600fac350dec..d1b17eda76b1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.project; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "deleteProjectInvitation", description = "Deletes project invitation", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteProjectInvitationCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java index b8d2f9b5f1ac..210394ec2ddf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.project; import org.apache.cloudstack.api.response.UserResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListProjectInvitationsCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java index 39d1c0dfedaa..d4679dbe0578 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java @@ -24,7 +24,6 @@ import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -44,7 +43,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListProjectsCmd extends BaseListAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListProjectsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java index 4937b164aab7..a3eee8c80bb7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "suspendProject", description = "Suspends a project", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class SuspendProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(SuspendProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java index 6520aa63a64b..4fabf7da788c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -40,7 +39,6 @@ @APICommand(name = "updateProject", description = "Updates a project", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java index e783aa644677..0cbd9f702c27 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.user.Account; @@ -35,7 +34,6 @@ @APICommand(name = "updateProjectInvitation", description = "Accepts or declines project invitation", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateProjectInvitationCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ListRegionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ListRegionsCmd.java index d3eb8bf8b0f9..777f437851ca 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ListRegionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ListRegionsCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "listRegions", description = "Lists Regions", responseObject = RegionResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListRegionsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListRegionsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java index aedc363e5ccb..649b2a7bd9bc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java @@ -25,7 +25,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -53,7 +52,6 @@ responseHasSensitiveInfo = false) public class AssignToGlobalLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AssignToGlobalLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java index 3aaf06073924..ddaadde78524 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse; import org.apache.cloudstack.api.response.RegionResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; @@ -42,7 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateGlobalLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// @@ -157,7 +155,7 @@ public void create() { this.setEntityUuid(gslbRule.getUuid()); CallContext.current().setEventDetails("Rule Id: " + getEntityId()); } catch (Exception ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); } finally { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java index 87c4e60a90b8..7f3308614ccf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -41,7 +40,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteGlobalLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteGlobalLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java index 7a1bcfc37a72..bf0cf22a2ecb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java @@ -22,7 +22,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "listGlobalLoadBalancerRules", description = "Lists load balancer rules.", responseObject = GlobalLoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListGlobalLoadBalancerRuleCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListGlobalLoadBalancerRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java index b9bbfec847fe..d4b02139892c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -47,7 +46,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveFromGlobalLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveFromGlobalLoadBalancerRuleCmd.class.getName()); private static final String s_name = "removefromloadbalancerruleresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java index c8d307e4084c..7996998e5d92 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "updateGlobalLoadBalancerRule", description = "update global load balancer rules.", responseObject = GlobalLoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateGlobalLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateGlobalLoadBalancerRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java index b513b811e467..b9e43336217d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java @@ -18,7 +18,6 @@ import java.util.ArrayList; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "getCloudIdentifier", description = "Retrieves a cloud identifier.", responseObject = CloudIdentifierResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetCloudIdentifierCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetCloudIdentifierCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListHypervisorsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListHypervisorsCmd.java index a0e750eb19f6..556f3b081f02 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListHypervisorsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListHypervisorsCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "listHypervisors", description = "List hypervisors", responseObject = HypervisorResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListHypervisorsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListHypervisorsCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java index adf1c93e4d03..71b886ed12b6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java @@ -19,22 +19,20 @@ import java.util.ArrayList; import java.util.List; -import com.cloud.configuration.Resource; -import com.cloud.exception.InvalidParameterValueException; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ResourceLimitResponse; -import org.apache.log4j.Logger; +import com.cloud.configuration.Resource; import com.cloud.configuration.ResourceLimit; +import com.cloud.exception.InvalidParameterValueException; @APICommand(name = "listResourceLimits", description = "Lists resource limits.", responseObject = ResourceLimitResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListResourceLimitsCmd.class.getName()); ///////////////////////////////////////////////////// @@ -74,6 +72,10 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd + "secondary_storage - SecondaryStorage. Total secondary storage space (in GiB) a user can use. ") private String resourceTypeName; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0") + private String tag; + + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -90,6 +92,10 @@ public String getResourceTypeName() { return resourceTypeName; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -98,7 +104,7 @@ public String getResourceTypeName() { public void execute() { List result = _resourceLimitService.searchForLimits(id, _accountService.finalyzeAccountId(this.getAccountName(), this.getDomainId(), this.getProjectId(), false), this.getDomainId(), - getResourceTypeEnum(), this.getStartIndex(), this.getPageSizeVal()); + getResourceTypeEnum(), getTag(), this.getStartIndex(), this.getPageSizeVal()); ListResponse response = new ListResponse(); List limitResponses = new ArrayList(); for (ResourceLimit limit : result) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java index 424087bc71ee..49c6ee605c8c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java @@ -30,15 +30,16 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceCountResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.configuration.ResourceCount; import com.cloud.user.Account; -@APICommand(name = "updateResourceCount", description = "Recalculate and update resource count for an account or domain.", responseObject = ResourceCountResponse.class, - requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +@APICommand(name = "updateResourceCount", + description = "Recalculate and update resource count for an account or domain. " + + "This also executes some cleanup tasks before calculating resource counts.", + responseObject = ResourceCountResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateResourceCountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateResourceCountCmd.class.getName()); ///////////////////////////////////////////////////// @@ -77,6 +78,9 @@ public class UpdateResourceCountCmd extends BaseCmd { @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "Update resource limits for project") private Long projectId; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -93,6 +97,10 @@ public Integer getResourceType() { return resourceType; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -119,7 +127,7 @@ public long getEntityOwnerId() { @Override public void execute() { List result = - _resourceLimitService.recalculateResourceCount(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType()); + _resourceLimitService.recalculateResourceCount(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType(), getTag()); if ((result != null) && (result.size() > 0)) { ListResponse response = new ListResponse(); @@ -127,7 +135,6 @@ public void execute() { for (ResourceCount count : result) { ResourceCountResponse resourceCountResponse = _responseGenerator.createResourceCountResponse(count); - resourceCountResponse.setObjectName("resourcecount"); countResponses.add(resourceCountResponse); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java index 41676ed23ca2..3538a389a6e9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java @@ -26,14 +26,12 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceLimitResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.configuration.ResourceLimit; @APICommand(name = "updateResourceLimit", description = "Updates resource limits for an account or domain.", responseObject = ResourceLimitResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateResourceLimitCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateResourceLimitCmd.class.getName()); ///////////////////////////////////////////////////// @@ -64,6 +62,7 @@ public class UpdateResourceLimitCmd extends BaseCmd { + "2 - Volume. Number of disk volumes a user can create. " + "3 - Snapshot. Number of snapshots a user can create. " + "4 - Template. Number of templates that a user can register/create. " + + "5 - Project. Number of projects a user can create. " + "6 - Network. Number of guest network a user can create. " + "7 - VPC. Number of VPC a user can create. " + "8 - CPU. Total number of CPU cores a user can use. " @@ -72,6 +71,9 @@ public class UpdateResourceLimitCmd extends BaseCmd { + "11 - SecondaryStorage. Total secondary storage space (in GiB) a user can use. ") private Integer resourceType; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -84,6 +86,10 @@ public Long getDomainId() { return domainId; } + public String getTag() { + return tag; + } + public Integer getResourceType() { return resourceType; } @@ -104,7 +110,7 @@ public long getEntityOwnerId() { @Override public void execute() { - ResourceLimit result = _resourceLimitService.updateResourceLimit(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max); + ResourceLimit result = _resourceLimitService.updateResourceLimit(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max, getTag()); if (result != null || (result == null && max != null && max.longValue() == -1L)) { ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result); response.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java index 737bdc8773b3..13faafe348c0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -50,7 +49,6 @@ responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class AuthorizeSecurityGroupEgressCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AuthorizeSecurityGroupEgressCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java index b6918905f292..640870fc3de3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -50,7 +49,6 @@ responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AuthorizeSecurityGroupIngressCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java index 4978aa174fc5..673eaaef33da 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "createSecurityGroup", responseObject = SecurityGroupResponse.class, description = "Creates a security group", entityType = {SecurityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSecurityGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateSecurityGroupCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java index 57d365d5ce12..b2ea90792b8e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ @APICommand(name = "deleteSecurityGroup", description = "Deletes security group", responseObject = SuccessResponse.class, entityType = {SecurityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSecurityGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSecurityGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -124,7 +122,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete security group"); } } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/ListSecurityGroupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/ListSecurityGroupsCmd.java index c4c103cf98e9..f93e7b39586b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/ListSecurityGroupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/ListSecurityGroupsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -32,7 +31,6 @@ @APICommand(name = "listSecurityGroups", description = "Lists security groups", responseObject = SecurityGroupResponse.class, entityType = {SecurityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSecurityGroupsCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListSecurityGroupsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java index f4a0362fce96..bf435406174c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -38,7 +37,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RevokeSecurityGroupEgressCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RevokeSecurityGroupEgressCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java index c5f88c9673f0..c426647fe36c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ @APICommand(name = "revokeSecurityGroupIngress", responseObject = SuccessResponse.class, description = "Deletes a particular ingress rule from this security group", entityType = {SecurityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RevokeSecurityGroupIngressCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RevokeSecurityGroupIngressCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/UpdateSecurityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/UpdateSecurityGroupCmd.java index 9b3000b1bf71..801fb6ac5e51 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/UpdateSecurityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/UpdateSecurityGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -37,7 +36,6 @@ since = "4.14.0.0", authorized = {RoleType.Admin}) public class UpdateSecurityGroupCmd extends BaseCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateSecurityGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ArchiveSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ArchiveSnapshotCmd.java index 78aa208ac1f1..f72de2278cc7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ArchiveSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ArchiveSnapshotCmd.java @@ -35,13 +35,11 @@ import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "archiveSnapshot", description = "Archives (moves) a snapshot on primary storage to secondary storage", responseObject = SnapshotResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ArchiveSnapshotCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ArchiveSnapshotCmd.class.getName()); private static final String s_name = "createsnapshotresponse"; @ACL(accessType = SecurityChecker.AccessType.OperateEntry) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java index f6d16c3eb493..07973fcbfca5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -43,13 +42,15 @@ import com.cloud.exception.StorageUnavailableException; import com.cloud.storage.Snapshot; import com.cloud.user.Account; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; @APICommand(name = "copySnapshot", description = "Copies a snapshot from one zone to another.", responseObject = SnapshotResponse.class, responseView = ResponseObject.ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CopySnapshotCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CopySnapshotCmd.class.getName()); + public static final Logger logger = LogManager.getLogger(CopySnapshotCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -170,10 +171,10 @@ public void execute() throws ResourceUnavailableException { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy snapshot"); } } catch (StorageUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java index eed3aa49fa59..3289ac2fe106 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -50,7 +49,6 @@ @APICommand(name = "createSnapshot", description = "Creates an instant snapshot of a volume.", responseObject = SnapshotResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSnapshotCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateSnapshotCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -240,7 +238,7 @@ public void execute() { } String errorMessage = "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeUuid(); - s_logger.error(errorMessage, e); + logger.error(errorMessage, e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage); } } @@ -257,7 +255,7 @@ private Snapshot.LocationType getLocationType() { } catch (IllegalArgumentException e) { String errMesg = "Invalid locationType " + locationType + "Specified for volume " + getVolumeId() + " Valid values are: primary,secondary "; - s_logger.warn(errMesg); + logger.warn(errMesg); throw new CloudRuntimeException(errMesg); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java index 7b89e87202d9..6bebdc09f59b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.VMSnapshotResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -43,7 +42,6 @@ @APICommand(name = "createSnapshotFromVMSnapshot", description = "Creates an instant snapshot of a volume from existing vm snapshot.", responseObject = SnapshotResponse.class, entityType = {Snapshot.class}, since = "4.10.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSnapshotFromVMSnapshotCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateSnapshotFromVMSnapshotCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -166,7 +164,7 @@ public void create() throws ResourceAllocationException { @Override public void execute() { - s_logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot id:" + getVMSnapshotId() + " and snapshot id:" + getEntityId() + " starts:" + System.currentTimeMillis()); + logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot id:" + getVMSnapshotId() + " and snapshot id:" + getEntityId() + " starts:" + System.currentTimeMillis()); CallContext.current().setEventDetails("Vm Snapshot Id: "+ this._uuidMgr.getUuid(VMSnapshot.class, getVMSnapshotId())); Snapshot snapshot = null; try { @@ -181,14 +179,14 @@ public void execute() { } catch (InvalidParameterValueException ex) { throw ex; } catch (Exception e) { - s_logger.debug("Failed to create snapshot", e); + logger.debug("Failed to create snapshot", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId()); } finally { if (snapshot == null) { try { _snapshotService.deleteSnapshot(getEntityId(), null); } catch (Exception e) { - s_logger.debug("Failed to clean failed snapshot" + getEntityId()); + logger.debug("Failed to clean failed snapshot" + getEntityId()); } } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java index 00bfb9e7e2c9..e30b897db2ea 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; @@ -45,7 +44,6 @@ @APICommand(name = "createSnapshotPolicy", description = "Creates a snapshot policy for the account.", responseObject = SnapshotPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSnapshotPolicyCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateSnapshotPolicyCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java index 6d71b1363b42..a0a8cfac9bd2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.snapshot; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ @APICommand(name = "deleteSnapshot", description = "Deletes a snapshot of a disk volume.", responseObject = SuccessResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSnapshotCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSnapshotCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java index 1a72b22f06c5..6f4b60dc8b21 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "deleteSnapshotPolicies", description = "Deletes snapshot policies for the account.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSnapshotPoliciesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSnapshotPoliciesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ExtractSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ExtractSnapshotCmd.java new file mode 100644 index 000000000000..3f0f82ea4e3b --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ExtractSnapshotCmd.java @@ -0,0 +1,115 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.snapshot; + +import com.cloud.event.EventTypes; +import com.cloud.storage.Snapshot; +import com.cloud.user.Account; +import org.apache.cloudstack.acl.SecurityChecker.AccessType; +import org.apache.cloudstack.api.ACL; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ExtractResponse; +import org.apache.cloudstack.api.response.SnapshotResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.context.CallContext; + +@APICommand(name = "extractSnapshot", description = "Returns a download URL for extracting a snapshot. It must be in the Backed Up state.", since = "4.20.0", + responseObject = ExtractResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class ExtractSnapshotCmd extends BaseAsyncCmd { + + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @ACL(accessType = AccessType.OperateEntry) + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=SnapshotResponse.class, required=true, since="4.20.0", description="the ID of the snapshot") + private Long id; + + @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, since="4.20.0", + description = "the ID of the zone where the snapshot is located") + private Long zoneId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public Long getZoneId() { + return zoneId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Snapshot; + } + + @Override + public Long getApiResourceId() { + return getId(); + } + + /** + * @return ID of the snapshot to extract, if any. Otherwise returns the ACCOUNT_ID_SYSTEM, so ERROR events will be traceable. + */ + @Override + public long getEntityOwnerId() { + Snapshot snapshot = _entityMgr.findById(Snapshot.class, getId()); + if (snapshot != null) { + return snapshot.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_SNAPSHOT_EXTRACT; + } + + @Override + public String getEventDescription() { + return "Snapshot extraction job"; + } + + @Override + public void execute() { + CallContext.current().setEventDetails("Snapshot ID: " + this._uuidMgr.getUuid(Snapshot.class, getId())); + String uploadUrl = _snapshotService.extractSnapshot(this); + logger.info("Extract URL [{}] of snapshot [{}].", uploadUrl, id); + if (uploadUrl != null) { + ExtractResponse response = _responseGenerator.createSnapshotExtractResponse(id, zoneId, getEntityOwnerId(), uploadUrl); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract snapshot"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java index e30ee75dee76..126a4080e6d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java @@ -20,7 +20,6 @@ import java.util.List; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "listSnapshotPolicies", description = "Lists snapshot policies.", responseObject = SnapshotPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSnapshotPoliciesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSnapshotPoliciesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java index cf665127a171..826c54c2e052 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java @@ -28,14 +28,12 @@ import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.storage.Snapshot; @APICommand(name = "listSnapshots", description = "Lists all available snapshots for the account.", responseObject = SnapshotResponse.class, entityType = { Snapshot.class }, responseView = ResponseObject.ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListSnapshotsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java index e65a03812d6f..fe3b4da0160e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.storage.Snapshot; @@ -39,7 +38,6 @@ @APICommand(name = "revertSnapshot", description = "This is supposed to revert a volume snapshot. This command is only supported with KVM so far", responseObject = SnapshotResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RevertSnapshotCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RevertSnapshotCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/UpdateSnapshotPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/UpdateSnapshotPolicyCmd.java index 0bedbe66199b..e7feb11f4afd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/UpdateSnapshotPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/UpdateSnapshotPolicyCmd.java @@ -33,13 +33,11 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SnapshotPolicyResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "updateSnapshotPolicy", description = "Updates the snapshot policy.", responseObject = SnapshotPolicyResponse.class, responseView = ResponseObject.ResponseView.Restricted, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateSnapshotPolicyCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateSnapshotPolicyCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java index 521148b596d9..5212779e9654 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.ssh; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "createSSHKeyPair", description = "Create a new keypair and returns the private key", responseObject = CreateSSHKeyPairResponse.class, entityType = {SSHKeyPair.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class CreateSSHKeyPairCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateSSHKeyPairCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java index 39c65c181c50..364ca77ae1fc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.ssh; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "deleteSSHKeyPair", description = "Deletes a keypair by name", responseObject = SuccessResponse.class, entityType = {SSHKeyPair.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSSHKeyPairCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSSHKeyPairCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/ListSSHKeyPairsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/ListSSHKeyPairsCmd.java index 71fbb66a337b..6bf8dca864b0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/ListSSHKeyPairsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/ListSSHKeyPairsCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "listSSHKeyPairs", description = "List registered keypairs", responseObject = SSHKeyPairResponse.class, entityType = {SSHKeyPair.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSSHKeyPairsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListSSHKeyPairsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java index 8bacfde7f737..6a0c0541bb4f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.ssh; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ @APICommand(name = "registerSSHKeyPair", description = "Register a public key in a keypair under a certain name", responseObject = SSHKeyPairResponse.class, entityType = {SSHKeyPair.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RegisterSSHKeyPairCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RegisterSSHKeyPairCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ChangeSharedFSDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ChangeSharedFSDiskOfferingCmd.java new file mode 100644 index 000000000000..b078ce4aae95 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ChangeSharedFSDiskOfferingCmd.java @@ -0,0 +1,145 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.DiskOfferingResponse; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import com.cloud.event.EventTypes; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.user.Account; + +@APICommand(name = "changeSharedFileSystemDiskOffering", + responseObject= SharedFSResponse.class, + description = "Change Disk offering of a Shared FileSystem", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class ChangeSharedFSDiskOfferingCmd extends BaseAsyncCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + required = true, + entityType = SharedFSResponse.class, + description = "the ID of the shared filesystem") + private Long id; + + @Parameter(name = ApiConstants.DISK_OFFERING_ID, + type = CommandType.UUID, + entityType = DiskOfferingResponse.class, + description = "the disk offering to use for the underlying storage") + private Long diskOfferingId; + + @Parameter(name = ApiConstants.SIZE, + type = CommandType.LONG, + description = "the size of the shared filesystem in GiB") + private Long size; + + @Parameter(name = ApiConstants.MIN_IOPS, + type = CommandType.LONG, + description = "min iops") + private Long minIops; + + @Parameter(name = ApiConstants.MAX_IOPS, + type = CommandType.LONG, + description = "max iops") + private Long maxIops; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public Long getSize() { + return size; + } + + public Long getDiskOfferingId() { + return diskOfferingId; + } + + public Long getMinIops() { + return minIops; + } + + public Long getMaxIops() { + return maxIops; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getEventType() { + return EventTypes.EVENT_SHAREDFS_CHANGE_DISK_OFFERING; + } + + @Override + public String getEventDescription() { + return "Changing disk offering for the Shared FileSystem " + id; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + @Override + public void execute() throws ResourceAllocationException { + SharedFS sharedFS = sharedFSService.changeSharedFSDiskOffering(this); + if (sharedFS != null) { + ResponseObject.ResponseView respView = getResponseView(); + Account caller = CallContext.current().getCallingAccount(); + if (_accountService.isRootAdmin(caller.getId())) { + respView = ResponseObject.ResponseView.Full; + } + SharedFSResponse response = _responseGenerator.createSharedFSResponse(respView, sharedFS); + response.setObjectName(SharedFS.class.getSimpleName().toLowerCase()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to change disk offering for the Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ChangeSharedFSServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ChangeSharedFSServiceOfferingCmd.java new file mode 100644 index 000000000000..70fb543d64c3 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ChangeSharedFSServiceOfferingCmd.java @@ -0,0 +1,147 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ManagementServerException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "changeSharedFileSystemServiceOffering", + responseObject= SharedFSResponse.class, + description = "Change Service offering of a Shared FileSystem", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class ChangeSharedFSServiceOfferingCmd extends BaseAsyncCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + required = true, + entityType = SharedFSResponse.class, + description = "the ID of the shared filesystem") + private Long id; + + @Parameter(name = ApiConstants.SERVICE_OFFERING_ID, + type = CommandType.UUID, + entityType = ServiceOfferingResponse.class, + required = true, + description = "the offering to use for the shared filesystem instance") + private Long serviceOfferingId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public Long getServiceOfferingId() { + return serviceOfferingId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getEventType() { + return EventTypes.EVENT_SHAREDFS_CHANGE_SERVICE_OFFERING; + } + + @Override + public String getEventDescription() { + return "Changing service offering for the Shared FileSystem " + id; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + private String getExceptionMsg(Exception ex) { + return "Shared FileSystem restart failed with exception" + ex.getMessage(); + } + + @Override + public void execute() { + SharedFS sharedFS; + try { + sharedFS = sharedFSService.changeSharedFSServiceOffering(this); + } catch (ResourceUnavailableException ex) { + logger.warn("Shared FileSystem change service offering exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, getExceptionMsg(ex)); + } catch (InsufficientCapacityException ex) { + logger.warn("Shared FileSystem change service offering exception: ", ex); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, getExceptionMsg(ex)); + } catch (OperationTimedoutException ex) { + logger.warn("Shared FileSystem change service offering exception: ", ex); + throw new CloudRuntimeException("Shared FileSystem change service offering timed out due to " + ex.getMessage()); + } catch (ManagementServerException ex) { + logger.warn("Shared FileSystem change service offering exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } catch (VirtualMachineMigrationException ex) { + logger.warn("Shared FileSystem change service offering exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + if (sharedFS != null) { + ResponseObject.ResponseView respView = getResponseView(); + Account caller = CallContext.current().getCallingAccount(); + if (_accountService.isRootAdmin(caller.getId())) { + respView = ResponseObject.ResponseView.Full; + } + SharedFSResponse response = _responseGenerator.createSharedFSResponse(respView, sharedFS); + response.setObjectName(SharedFS.class.getSimpleName().toLowerCase()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to change the service offering for the Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/CreateSharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/CreateSharedFSCmd.java new file mode 100644 index 000000000000..ddaa31612a89 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/CreateSharedFSCmd.java @@ -0,0 +1,304 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import javax.inject.Inject; + +import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCreateCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.DiskOfferingResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.api.response.NetworkResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSProvider; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +@APICommand(name = "createSharedFileSystem", + responseObject= SharedFSResponse.class, + description = "Create a new Shared File System of specified size and disk offering, attached to the given network", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class CreateSharedFSCmd extends BaseAsyncCreateCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.NAME, + type = CommandType.STRING, + required = true, + description = "the name of the shared filesystem.") + private String name; + + @Parameter(name = ApiConstants.ACCOUNT, + type = BaseCmd.CommandType.STRING, + description = "the account associated with the shared filesystem. Must be used with the domainId parameter.") + private String accountName; + + @Parameter(name = ApiConstants.DOMAIN_ID, + type = CommandType.UUID, + entityType = DomainResponse.class, + description = "the domain ID associated with the shared filesystem. If used with the account parameter" + + " returns the shared filesystem associated with the account for the specified domain." + + "If account is NOT provided then the shared filesystem will be assigned to the caller account and domain.") + private Long domainId; + + @Parameter(name = ApiConstants.PROJECT_ID, + type = CommandType.UUID, + entityType = ProjectResponse.class, + description = "the project associated with the shared filesystem. Mutually exclusive with account parameter") + private Long projectId; + + @Parameter(name = ApiConstants.DESCRIPTION, + type = CommandType.STRING, + description = "the description for the shared filesystem.") + private String description; + + @Parameter(name = ApiConstants.SIZE, + type = CommandType.LONG, + description = "the size of the shared filesystem in GiB") + private Long size; + + @Parameter(name = ApiConstants.ZONE_ID, + type = CommandType.UUID, + required = true, + entityType = ZoneResponse.class, + description = "the zone id.") + private Long zoneId; + + @Parameter(name = ApiConstants.DISK_OFFERING_ID, + type = CommandType.UUID, + required = true, + entityType = DiskOfferingResponse.class, + description = "the disk offering to use for the underlying storage. This will define the size and other specifications like encryption and qos for the shared filesystem.") + private Long diskOfferingId; + + @Parameter(name = ApiConstants.MIN_IOPS, + type = CommandType.LONG, + description = "min iops") + private Long minIops; + + @Parameter(name = ApiConstants.MAX_IOPS, + type = CommandType.LONG, + description = "max iops") + private Long maxIops; + + @Parameter(name = ApiConstants.SERVICE_OFFERING_ID, + type = CommandType.UUID, + required = true, + entityType = ServiceOfferingResponse.class, + description = "the service offering to use for the shared filesystem instance hosting the data. The offering should be HA enabled and the cpu count and memory size should be greater than equal to sharedfsvm.min.cpu.count and sharedfsvm.min.ram.size respectively") + private Long serviceOfferingId; + + @Parameter(name = ApiConstants.FILESYSTEM, + type = CommandType.STRING, + required = true, + description = "the filesystem format (XFS / EXT4) which will be installed on the shared filesystem.") + private String fsFormat; + + @Parameter(name = ApiConstants.PROVIDER, + type = CommandType.STRING, + description = "the provider to be used for the shared filesystem. The list of providers can be fetched by using the listSharedFileSystemProviders API.") + private String sharedFSProviderName; + + @Parameter(name = ApiConstants.NETWORK_ID, + type = CommandType.UUID, + required = true, + entityType = NetworkResponse.class, + description = "network to attach the shared filesystem to") + private Long networkId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getName() { + return name; + } + + + public Long getProjectId() { + return projectId; + } + + public Long getDomainId() { + return domainId; + } + + public String getAccountName() { + return accountName; + } + public String getDescription() { + return description; + } + + public Long getSize() { + return size; + } + + public Long getZoneId() { + return zoneId; + } + + public Long getDiskOfferingId() { + return diskOfferingId; + } + + public Long getServiceOfferingId() { + return serviceOfferingId; + } + + public Long getMaxIops() { + return maxIops; + } + + public Long getMinIops() { + return minIops; + } + + public String getFsFormat() { + return fsFormat; + } + + public Long getNetworkId() { + return networkId; + } + + public String getSharedFSProviderName() { + if (sharedFSProviderName != null) { + return sharedFSProviderName; + } else { + return SharedFSProvider.SharedFSProviderType.SHAREDFSVM.toString(); + } + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.SharedFS; + } + + @Override + public Long getApiResourceId() { + return this.getEntityId(); + } + @Override + public long getEntityOwnerId() { + Long accountId = _accountService.finalyzeAccountId(accountName, domainId, projectId, true); + if (accountId == null) { + return CallContext.current().getCallingAccount().getId(); + } + return accountId; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_SHAREDFS_CREATE; + } + + @Override + public String getEventDescription() { + return "Creating shared filesystem " + name; + } + + private String getCreateExceptionMsg(Exception ex) { + return "Shared FileSystem create failed with exception" + ex.getMessage(); + } + + private String getStartExceptionMsg(Exception ex) { + return "Shared FileSystem start failed with exception: " + ex.getMessage(); + } + + public void create() { + SharedFS sharedFS; + sharedFS = sharedFSService.allocSharedFS(this); + if (sharedFS != null) { + setEntityId(sharedFS.getId()); + setEntityUuid(sharedFS.getUuid()); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Shared FileSystem"); + } + } + + @Override + public void execute() { + SharedFS sharedFS; + try { + sharedFS = sharedFSService.deploySharedFS(this); + } catch (ResourceUnavailableException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, getStartExceptionMsg(ex)); + } catch (ConcurrentOperationException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, getStartExceptionMsg(ex)); + } catch (InsufficientCapacityException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, getStartExceptionMsg(ex)); + } catch (ResourceAllocationException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (OperationTimedoutException ex) { + throw new CloudRuntimeException("Shared FileSystem start timed out due to " + ex.getMessage()); + } + + if (sharedFS != null) { + ResponseObject.ResponseView respView = getResponseView(); + Account caller = CallContext.current().getCallingAccount(); + if (_accountService.isRootAdmin(caller.getId())) { + respView = ResponseObject.ResponseView.Full; + } + SharedFSResponse response = _responseGenerator.createSharedFSResponse(respView, sharedFS); + response.setObjectName(SharedFS.class.getSimpleName().toLowerCase()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/DestroySharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/DestroySharedFSCmd.java new file mode 100644 index 000000000000..09fae53f1284 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/DestroySharedFSCmd.java @@ -0,0 +1,116 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import javax.inject.Inject; + +import com.cloud.event.EventTypes; + +@APICommand(name = "destroySharedFileSystem", + responseObject= SuccessResponse.class, + description = "Destroy a Shared FileSystem by id", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class DestroySharedFSCmd extends BaseAsyncCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + entityType = SharedFSResponse.class, + description = "the ID of the shared filesystem to delete") + private Long id; + + @Parameter(name = ApiConstants.EXPUNGE, + type = CommandType.BOOLEAN, + description = "If true is passed, the shared filesystem is expunged immediately. False by default.") + private Boolean expunge; + + @Parameter(name = ApiConstants.FORCED, + type = CommandType.BOOLEAN, + description = "If true is passed, the shared filesystem can be destroyed without stopping it first.") + private Boolean forced; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public boolean isExpunge() { + return (expunge != null) ? expunge : false; + } + + public boolean isForced() { + return (forced != null) ? forced : false; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getEventType() { + return EventTypes.EVENT_SHAREDFS_DESTROY; + } + + @Override + public String getEventDescription() { + return "Destroying Shared FileSystem " + id; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + @Override + public void execute() { + Boolean result = sharedFSService.destroySharedFS(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ExpungeSharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ExpungeSharedFSCmd.java new file mode 100644 index 000000000000..39b99218b667 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ExpungeSharedFSCmd.java @@ -0,0 +1,96 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import com.cloud.event.EventTypes; + +@APICommand(name = "expungeSharedFileSystem", + responseObject= SuccessResponse.class, + description = "Expunge a Shared FileSystem by id", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class ExpungeSharedFSCmd extends BaseAsyncCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = SharedFSResponse.class, description = "the ID of the shared filesystem to expunge") + private Long id; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getEventType() { + return EventTypes.EVENT_SHAREDFS_EXPUNGE; + } + + @Override + public String getEventDescription() { + return "Expunging Shared FileSystem " + id; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + @Override + public void execute() { + try { + sharedFSService.deleteSharedFS(id); + } catch (Exception ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to expunge Shared FileSystem"); + } finally { + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ListSharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ListSharedFSCmd.java new file mode 100644 index 000000000000..c52c691ac0b9 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ListSharedFSCmd.java @@ -0,0 +1,114 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListRetrieveOnlyResourceCountCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.DiskOfferingResponse; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NetworkResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import javax.inject.Inject; + +@APICommand(name = "listSharedFileSystems", + responseObject= SharedFSResponse.class, + description = "List Shared FileSystems", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class ListSharedFSCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = SharedFSResponse.class, description = "the ID of the shared filesystem") + private Long id; + + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the shared filesystem") + private String name; + + @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "the ID of the availability zone") + private Long zoneId; + + @Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class, description = "the ID of the network") + private Long networkId; + + @Parameter(name = ApiConstants.DISK_OFFERING_ID, type = CommandType.UUID, entityType = DiskOfferingResponse.class, description = "the disk offering of the shared filesystem") + private Long diskOfferingId; + + @Parameter(name = ApiConstants.SERVICE_OFFERING_ID, type = CommandType.UUID, entityType = ServiceOfferingResponse.class, description = "the service offering of the shared filesystem") + private Long serviceOfferingId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public Long getZoneId() { + return zoneId; + } + + public Long getNetworkId() { + return networkId; + } + + public Long getDiskOfferingId() { + return diskOfferingId; + } + + public Long getServiceOfferingId() { + return serviceOfferingId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + public long getEntityOwnerId() { + return 0; + } + + @Override + public void execute() { + ListResponse response = sharedFSService.searchForSharedFS(getResponseView(), this); + response.setResponseName(getCommandName()); + setResponseObject(response); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ListSharedFSProvidersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ListSharedFSProvidersCmd.java new file mode 100644 index 000000000000..940e07225cf9 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/ListSharedFSProvidersCmd.java @@ -0,0 +1,60 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.response.SharedFSProviderResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.storage.sharedfs.SharedFSProvider; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +@APICommand(name = "listSharedFileSystemProviders", + responseObject = SharedFSProviderResponse.class, + description = "Lists all available shared filesystem providers.", + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class ListSharedFSProvidersCmd extends BaseListCmd { + + @Inject + public SharedFSService sharedFSService; + + @Override + public void execute() { + List sharedFSProviders = sharedFSService.getSharedFSProviders(); + final ListResponse response = new ListResponse<>(); + final List responses = new ArrayList<>(); + + for (SharedFSProvider sharedFSProvider : sharedFSProviders) { + SharedFSProviderResponse sharedFSProviderResponse = new SharedFSProviderResponse(); + sharedFSProviderResponse.setName(sharedFSProvider.getName()); + sharedFSProviderResponse.setObjectName("sharedfilesystemprovider"); + responses.add(sharedFSProviderResponse); + } + response.setResponses(responses, responses.size()); + response.setResponseName(this.getCommandName()); + setResponseObject(response); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/RecoverSharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/RecoverSharedFSCmd.java new file mode 100644 index 000000000000..6e5bbaa4d8a8 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/RecoverSharedFSCmd.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +@APICommand(name = "recoverSharedFileSystem", + responseObject= SuccessResponse.class, + description = "Recover a Shared FileSystem by id", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class RecoverSharedFSCmd extends BaseCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = SharedFSResponse.class, description = "the ID of the shared filesystem to recover") + private Long id; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + @Override + public void execute() { + SharedFS sharedFS = sharedFSService.recoverSharedFS(id); + if (sharedFS != null) { + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to recover Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/RestartSharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/RestartSharedFSCmd.java new file mode 100644 index 000000000000..576c472b6eb2 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/RestartSharedFSCmd.java @@ -0,0 +1,145 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "restartSharedFileSystem", + responseObject= SuccessResponse.class, + description = "Restart a Shared FileSystem", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class RestartSharedFSCmd extends BaseAsyncCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + required = true, + entityType = SharedFSResponse.class, + description = "the ID of the shared filesystem") + private Long id; + + @Parameter(name = ApiConstants.CLEANUP, + type = CommandType.BOOLEAN, + description = "is cleanup required") + private boolean cleanup; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public Boolean getCleanup() { + return cleanup; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getEventType() { + return EventTypes.EVENT_SHAREDFS_RESTART; + } + + @Override + public String getEventDescription() { + return "Restarting Shared FileSystem " + id; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + private String getRestartExceptionMsg(Exception ex) { + return "Shared FileSystem restart failed with exception" + ex.getMessage(); + } + + @Override + public void execute() { + SharedFS sharedFS; + try { + sharedFS = sharedFSService.restartSharedFS(this.getId(), this.getCleanup()); + } catch (ResourceUnavailableException ex) { + logger.warn("Shared FileSystem restart exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, getRestartExceptionMsg(ex)); + } catch (ConcurrentOperationException ex) { + logger.warn("Shared FileSystem restart exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, getRestartExceptionMsg(ex)); + } catch (InsufficientCapacityException ex) { + logger.warn("Shared FileSystem restart exception: ", ex); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, getRestartExceptionMsg(ex)); + } catch (ResourceAllocationException ex) { + logger.warn("Shared FileSystem restart exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (OperationTimedoutException ex) { + logger.warn("Shared FileSystem restart exception: ", ex); + throw new CloudRuntimeException("Shared FileSystem start timed out due to " + ex.getMessage()); + } + + if (sharedFS != null) { + ResponseObject.ResponseView respView = getResponseView(); + Account caller = CallContext.current().getCallingAccount(); + if (_accountService.isRootAdmin(caller.getId())) { + respView = ResponseObject.ResponseView.Full; + } + SharedFSResponse response = _responseGenerator.createSharedFSResponse(respView, sharedFS); + response.setObjectName(SharedFS.class.getSimpleName().toLowerCase()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restart Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/StartSharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/StartSharedFSCmd.java new file mode 100644 index 000000000000..bd384aceef73 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/StartSharedFSCmd.java @@ -0,0 +1,135 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "startSharedFileSystem", + responseObject= SharedFSResponse.class, + description = "Start a Shared FileSystem", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class StartSharedFSCmd extends BaseAsyncCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + required = true, + entityType = SharedFSResponse.class, + description = "the ID of the shared filesystem") + private Long id; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + @Override + public String getEventDescription() { + return "Starting Shared FileSystem " + id; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_SHAREDFS_START; + } + + private String getStartExceptionMsg(Exception ex) { + return "Shared FileSystem start failed with exception: " + ex.getMessage(); + } + + @Override + public void execute() { + SharedFS sharedFS; + try { + sharedFS = sharedFSService.startSharedFS(this.getId()); + } catch (ResourceUnavailableException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, getStartExceptionMsg(ex)); + } catch (ConcurrentOperationException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, getStartExceptionMsg(ex)); + } catch (InsufficientCapacityException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, getStartExceptionMsg(ex)); + } catch (ResourceAllocationException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); + } catch (OperationTimedoutException ex) { + logger.warn("Shared FileSystem start exception: ", ex); + throw new CloudRuntimeException("Shared FileSystem start timed out due to " + ex.getMessage()); + } + + if (sharedFS != null) { + ResponseObject.ResponseView respView = getResponseView(); + Account caller = CallContext.current().getCallingAccount(); + if (_accountService.isRootAdmin(caller.getId())) { + respView = ResponseObject.ResponseView.Full; + } + SharedFSResponse response = _responseGenerator.createSharedFSResponse(respView, sharedFS); + response.setObjectName(SharedFS.class.getSimpleName().toLowerCase()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/StopSharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/StopSharedFSCmd.java new file mode 100644 index 000000000000..d6e0737144a5 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/StopSharedFSCmd.java @@ -0,0 +1,115 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import com.cloud.event.EventTypes; +import com.cloud.user.Account; + +@APICommand(name = "stopSharedFileSystem", + responseObject= SharedFSResponse.class, + description = "Stop a Shared FileSystem", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class StopSharedFSCmd extends BaseAsyncCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + required = true, + entityType = SharedFSResponse.class, + description = "the ID of the shared filesystem") + private Long id; + + @Parameter(name = ApiConstants.FORCED, + type = CommandType.BOOLEAN, + description = "Force stop the shared filesystem.") + private Boolean forced; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public boolean isForced() { + return (forced != null) ? forced : false; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + @Override + public String getEventType() { + return EventTypes.EVENT_SHAREDFS_STOP; + } + + @Override + public String getEventDescription() { + return "Stopping Shared FileSystem " + id; + } + + @Override + public void execute() { + SharedFS sharedFS = sharedFSService.stopSharedFS(this.getId(), this.isForced()); + if (sharedFS != null) { + ResponseObject.ResponseView respView = getResponseView(); + Account caller = CallContext.current().getCallingAccount(); + if (_accountService.isRootAdmin(caller.getId())) { + respView = ResponseObject.ResponseView.Full; + } + SharedFSResponse response = _responseGenerator.createSharedFSResponse(respView, sharedFS); + response.setObjectName(SharedFS.class.getSimpleName().toLowerCase()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/UpdateSharedFSCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/UpdateSharedFSCmd.java new file mode 100644 index 000000000000..daad6cc78c56 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/storage/sharedfs/UpdateSharedFSCmd.java @@ -0,0 +1,113 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.storage.sharedfs; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSService; + +import javax.inject.Inject; + +import com.cloud.user.Account; + +@APICommand(name = "updateSharedFileSystem", + responseObject= SharedFSResponse.class, + description = "Update a Shared FileSystem", + responseView = ResponseObject.ResponseView.Restricted, + entityType = SharedFS.class, + requestHasSensitiveInfo = false, + since = "4.20.0", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class UpdateSharedFSCmd extends BaseCmd implements UserCmd { + + @Inject + SharedFSService sharedFSService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, + type = CommandType.UUID, + required = true, + entityType = SharedFSResponse.class, + description = "the ID of the shared filesystem") + private Long id; + + @Parameter(name = ApiConstants.NAME, + type = CommandType.STRING, + description = "the name of the shared filesystem.") + private String name; + + @Parameter(name = ApiConstants.DESCRIPTION, + type = CommandType.STRING, + description = "the description for the shared filesystem.") + private String description; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + @Override + public void execute() { + SharedFS sharedFS = sharedFSService.updateSharedFS(this); + if (sharedFS != null) { + ResponseObject.ResponseView respView = getResponseView(); + Account caller = CallContext.current().getCallingAccount(); + if (_accountService.isRootAdmin(caller.getId())) { + respView = ResponseObject.ResponseView.Full; + } + SharedFSResponse response = _responseGenerator.createSharedFSResponse(respView, sharedFS); + response.setObjectName(SharedFS.class.getSimpleName().toLowerCase()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update Shared FileSystem"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java index 67705859419b..30904db46c44 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "createTags", description = "Creates resource tag(s)", responseObject = SuccessResponse.class, since = "4.0.0", entityType = {ResourceTag.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTagsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTagsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java index 55dec6e9645a..f8f319eba23d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ @APICommand(name = "deleteTags", description = "Deleting resource tag(s)", responseObject = SuccessResponse.class, since = "4.0.0", entityType = {ResourceTag.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTagsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTagsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java index f672d4c8890e..f094bc435070 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -43,7 +42,6 @@ @APICommand(name = "copyTemplate", description = "Copies a template from one zone to another.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CopyTemplateCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CopyTemplateCmd.class.getName()); private static final String s_name = "copytemplateresponse"; ///////////////////////////////////////////////////// @@ -191,7 +189,7 @@ public void execute() throws ResourceAllocationException { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template"); } } catch (StorageUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java index 6c39ab6d3c7e..0a7bf2918435 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java @@ -40,7 +40,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -55,7 +54,6 @@ + "A template created from this command is automatically designated as a private template visible to the account that created it.", responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTemplateCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateTemplateCmd.class.getName()); private static final String s_name = "createtemplateresponse"; // /////////////////////////////////////////////////// @@ -348,11 +346,11 @@ private Long findAccountIdToUse(Account callingAccount) { try { accountIdToUse = _accountService.finalyzeAccountId(accountName, domainId, projectId, true); } catch (InvalidParameterValueException | PermissionDeniedException ex) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("An exception occurred while finalizing account id with accountName, domainId and projectId" + + if (logger.isDebugEnabled()) { + logger.debug(String.format("An exception occurred while finalizing account id with accountName, domainId and projectId" + "using callingAccountId=%s", callingAccount.getUuid()), ex); } - s_logger.warn("Unable to find accountId associated with accountName=" + accountName + " and domainId=" + logger.warn("Unable to find accountId associated with accountName=" + accountName + " and domainId=" + domainId + " or projectId=" + projectId + ", using callingAccountId=" + callingAccount.getUuid()); } return accountIdToUse != null ? accountIdToUse : callingAccount.getAccountId(); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java index 3d7aaaec31c1..5e9bf317fe1d 100755 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java @@ -17,8 +17,8 @@ package org.apache.cloudstack.api.command.user.template; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; +import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +40,6 @@ description = "Deletes a template from the system. All virtual machines using the deleted template will not be affected.", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTemplateCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTemplateCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -55,6 +54,9 @@ public class DeleteTemplateCmd extends BaseAsyncCmd { @Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force delete a template.", since = "4.9+") private Boolean forced; + @Parameter(name = ApiConstants.IS_SYSTEM, type = CommandType.BOOLEAN, required = false, description = "Necessary if the template's type is system.", since = "4.20.0", authorized = {RoleType.Admin}) + private Boolean isSystem; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -71,6 +73,10 @@ public boolean isForced() { return BooleanUtils.toBooleanDefaultIfNull(forced, false); } + public boolean getIsSystem() { + return BooleanUtils.toBooleanDefaultIfNull(isSystem, false); + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java index 91e8d168ecb5..0fa0679bfd9e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -38,7 +37,6 @@ @APICommand(name = "extractTemplate", description = "Extracts a template", responseObject = ExtractResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ExtractTemplateCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ExtractTemplateCmd.class.getName()); ///////////////////////////////////////////////////// @@ -122,14 +120,15 @@ public void execute() { CallContext.current().setEventDetails(getEventDescription()); String uploadUrl = _templateService.extract(this); if (uploadUrl != null) { - ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl); + ExtractResponse response = _responseGenerator.createImageExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl); response.setResponseName(getCommandName()); + response.setObjectName("template"); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract template"); } } catch (InternalErrorException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java index ab872b84edbc..8fa1a5d53eb7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Map; +import com.cloud.cpu.CPU; import com.cloud.hypervisor.Hypervisor; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -34,7 +35,6 @@ import org.apache.cloudstack.api.response.GuestOSResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ResourceAllocationException; @@ -43,7 +43,6 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetUploadParamsForTemplateCmd extends AbstractGetUploadParamsCmd { - public static final Logger s_logger = Logger.getLogger(GetUploadParamsForTemplateCmd.class.getName()); private static final String s_name = "postuploadtemplateresponse"; @@ -57,6 +56,11 @@ public class GetUploadParamsForTemplateCmd extends AbstractGetUploadParamsCmd { description = "the ID of the OS Type that best represents the OS of this template. Not required for VMware as the guest OS is obtained from the OVF file.") private Long osTypeId; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the template. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + @Parameter(name = ApiConstants.BITS, type = CommandType.INTEGER, description = "32 or 64 bits support. 64 by default") private Integer bits; @@ -164,6 +168,10 @@ public boolean isDeployAsIs() { Boolean.TRUE.equals(deployAsIs); } + public CPU.CPUArch getArch() { + return CPU.CPUArch.fromType(arch); + } + @Override public void execute() throws ServerApiException { validateRequest(); @@ -172,7 +180,7 @@ public void execute() throws ServerApiException { response.setResponseName(getCommandName()); setResponseObject(response); } catch (ResourceAllocationException | MalformedURLException e) { - s_logger.error("exception while registering template", e); + logger.error("exception while registering template", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "exception while registering template: " + e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java index 970c6b347430..6d544df41871 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.template; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd; @@ -40,11 +39,6 @@ public String getMediaType() { return "template"; } - @Override - protected Logger getLogger() { - return Logger.getLogger(ListTemplatePermissionsCmd.class.getName()); - } - @Override protected boolean templateIsCorrectType(VirtualMachineTemplate template) { return !template.getFormat().equals(ImageFormat.ISO); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java index dae7cc97a4c9..bff65ef70a92 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java @@ -16,12 +16,12 @@ // under the License. package org.apache.cloudstack.api.command.user.template; +import com.cloud.cpu.CPU; import com.cloud.exception.InvalidParameterValueException; import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.ResourceIconResponse; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.Collections; @@ -42,11 +42,11 @@ import com.cloud.template.VirtualMachineTemplate; import com.cloud.template.VirtualMachineTemplate.TemplateFilter; import com.cloud.user.Account; +import org.apache.commons.lang3.StringUtils; @APICommand(name = "listTemplates", description = "List all public, private, and privileged templates.", responseObject = TemplateResponse.class, entityType = {VirtualMachineTemplate.class}, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTemplatesCmd extends BaseListTaggedResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListTemplatesCmd.class.getName()); private static final String s_name = "listtemplatesresponse"; @@ -106,6 +106,11 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd implements User since = "4.19.0") private Boolean isVnf; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the template. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -193,6 +198,13 @@ public Boolean getVnf() { return isVnf; } + public CPU.CPUArch getArch() { + if (StringUtils.isBlank(arch)) { + return null; + } + return CPU.CPUArch.fromType(arch); + } + @Override public String getCommandName() { return s_name; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java index 0a087888d521..a7826dedcd04 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java @@ -16,6 +16,7 @@ // under the License. package org.apache.cloudstack.api.command.user.template; +import com.cloud.cpu.CPU; import com.cloud.hypervisor.Hypervisor; import java.net.URISyntaxException; import java.util.ArrayList; @@ -41,7 +42,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ResourceAllocationException; import com.cloud.template.VirtualMachineTemplate; @@ -49,7 +49,6 @@ @APICommand(name = "registerTemplate", description = "Registers an existing template into the CloudStack cloud. ", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RegisterTemplateCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RegisterTemplateCmd.class.getName()); private static final String s_name = "registertemplateresponse"; @@ -174,6 +173,11 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd { since = "4.19.0") private String templateType; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the template. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -295,6 +299,10 @@ public String getTemplateType() { return templateType; } + public CPU.CPUArch getArch() { + return CPU.CPUArch.fromType(arch); + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -335,7 +343,7 @@ public void execute() throws ResourceAllocationException { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template"); } } catch (URISyntaxException ex1) { - s_logger.info(ex1); + logger.info(ex1); throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java index 2afa6a98b13d..dbbd771293a4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java @@ -16,8 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.template; -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +33,6 @@ @APICommand(name = "updateTemplate", description = "Updates attributes of a template.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName()); private static final String s_name = "updatetemplateresponse"; ///////////////////////////////////////////////////// @@ -46,6 +43,9 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements Use description = "the type of the template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).") private String templateType; + @Parameter(name = ApiConstants.TEMPLATE_TAG, type = CommandType.STRING, description = "the tag for this template.", since = "4.20.0") + private String templateTag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -59,6 +59,10 @@ public String getTemplateType() { return templateType; } + public String getTemplateTag() { + return templateTag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java index 7cf5e0bc3f5b..de8f09a64005 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.template; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd; @@ -35,10 +34,6 @@ protected String getResponseName() { return "updatetemplatepermissionsresponse"; } - @Override - protected Logger getLogger() { - return Logger.getLogger(UpdateTemplatePermissionsCmd.class.getName()); - } @Override public long getEntityOwnerId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/DeleteUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/DeleteUserDataCmd.java index d27b90f07a1c..a1d1afc7b057 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/DeleteUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/DeleteUserDataCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserDataResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.UserData; @@ -39,7 +38,6 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeleteUserDataCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteUserDataCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/LinkUserDataToTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/LinkUserDataToTemplateCmd.java index be1a95c36941..e322de00bb1b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/LinkUserDataToTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/LinkUserDataToTemplateCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.command.admin.AdminCmd; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.UserDataResponse; -import org.apache.log4j.Logger; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; @@ -39,7 +38,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class LinkUserDataToTemplateCmd extends BaseCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(LinkUserDataToTemplateCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java index 87d8883e2e30..64ab3ec3d70e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.UserDataResponse; -import org.apache.log4j.Logger; import com.cloud.user.UserData; import com.cloud.utils.Pair; @@ -35,7 +34,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListUserDataCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListUserDataCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java index 3d44230cac12..41d865d678c8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.UserDataResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -52,7 +51,6 @@ authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class RegisterUserDataCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RegisterUserDataCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java index fc009c7e5db1..e76a75ae398a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.response.NicResponse; import org.apache.cloudstack.api.response.NicSecondaryIpResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -46,7 +45,6 @@ @APICommand(name = "addIpToNic", description = "Assigns secondary IP to NIC", responseObject = NicSecondaryIpResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddIpToVmNicCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddIpToVmNicCmd.class.getName()); private static final String s_name = "addiptovmnicresponse"; ///////////////////////////////////////////////////// @@ -81,7 +79,7 @@ public long getNicId() { private boolean isZoneSGEnabled() { Network ntwk = _entityMgr.findById(Network.class, getNetworkId()); DataCenter dc = _entityMgr.findById(DataCenter.class, ntwk.getDataCenterId()); - return dc.isSecurityGroupEnabled(); + return dc.isSecurityGroupEnabled() || _ntwkModel.isSecurityGroupSupportedForZone(dc.getId()); } @Override diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java index 1e395831a6ff..ecd066d98cd5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -51,7 +50,6 @@ @APICommand(name = "addNicToVirtualMachine", description = "Adds VM to specified network by creating a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class AddNicToVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(AddNicToVMCmd.class); private static final String s_name = "addnictovirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmd.java index 935f39bf4ddb..5811eb1abfc5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmd.java @@ -68,7 +68,7 @@ public class CreateVMScheduleCmd extends BaseCmd { @Parameter(name = ApiConstants.ACTION, type = CommandType.STRING, required = true, - description = "Action to take on the VM (start/stop/restart/force_stop/force_reboot).") + description = "Action to take on the VM (start/stop/reboot/force_stop/force_reboot).") private String action; @Parameter(name = ApiConstants.START_DATE, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index e02111af59f7..52d42a95d981 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -31,6 +31,7 @@ import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.ACL; import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiArgValidator; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants.IoDriverPolicy; @@ -56,7 +57,6 @@ import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.LogLevel; import com.cloud.event.EventTypes; @@ -80,7 +80,6 @@ @APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd { - public static final Logger s_logger = Logger.getLogger(DeployVMCmd.class.getName()); private static final String s_name = "deployvirtualmachineresponse"; @@ -99,7 +98,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG @Parameter(name = ApiConstants.TEMPLATE_ID, type = CommandType.UUID, entityType = TemplateResponse.class, required = true, description = "the ID of the template for the virtual machine") private Long templateId; - @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "host name for the virtual machine") + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "host name for the virtual machine", validations = {ApiArgValidator.RFCComplianceDomainName}) private String name; @Parameter(name = ApiConstants.DISPLAY_NAME, type = CommandType.STRING, description = "an optional user generated name for the virtual machine") @@ -317,7 +316,7 @@ public ApiConstants.BootType getBootType() { } catch (IllegalArgumentException e) { String errMesg = "Invalid bootType " + bootType + "Specified for vm " + getName() + " Valid values are: " + Arrays.toString(ApiConstants.BootType.values()); - s_logger.warn(errMesg); + logger.warn(errMesg); throw new InvalidParameterValueException(errMesg); } } @@ -364,14 +363,14 @@ public ApiConstants.BootMode getBootMode() { } catch (IllegalArgumentException e) { String msg = String.format("Invalid %s: %s specified for VM: %s. Valid values are: %s", ApiConstants.BOOT_MODE, bootMode, getName(), Arrays.toString(ApiConstants.BootMode.values())); - s_logger.error(msg); + logger.error(msg); throw new InvalidParameterValueException(msg); } } if (ApiConstants.BootType.UEFI.equals(getBootType())) { String msg = String.format("%s must be specified for the VM with boot type: %s. Valid values are: %s", ApiConstants.BOOT_MODE, getBootType(), Arrays.toString(ApiConstants.BootMode.values())); - s_logger.error(msg); + logger.error(msg); throw new InvalidParameterValueException(msg); } return null; @@ -404,8 +403,8 @@ public Map getVmNetworkMap() { nic = null; } String networkUuid = entry.get(VmDetailConstants.NETWORK); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); } if (nic == null || StringUtils.isEmpty(networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) { throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic)); @@ -715,7 +714,7 @@ public ApiConstants.IoDriverPolicy getIoDriverPolicy() { return ApiConstants.IoDriverPolicy.valueOf(policyType); } catch (IllegalArgumentException e) { String errMesg = String.format("Invalid io policy %s specified for vm %s. Valid values are: %s", ioDriverPolicy, getName(), Arrays.toString(ApiConstants.IoDriverPolicy.values())); - s_logger.warn(errMesg); + logger.warn(errMesg); throw new InvalidParameterValueException(errMesg); } } @@ -781,13 +780,13 @@ public void execute() { try { result = _userVmService.startVirtualMachine(this); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { StringBuilder message = new StringBuilder(ex.getMessage()); @@ -796,12 +795,12 @@ public void execute() { message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them"); } } - s_logger.info(String.format("%s: %s", message.toString(), ex.getLocalizedMessage())); - s_logger.debug(message.toString(), ex); + logger.info(String.format("%s: %s", message.toString(), ex.getLocalizedMessage())); + logger.debug(message.toString(), ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); } } else { - s_logger.info("VM " + getEntityUuid() + " already created, load UserVm from DB"); + logger.info("VM " + getEntityUuid() + " already created, load UserVm from DB"); result = _userVmService.finalizeCreateVirtualMachine(getEntityId()); } @@ -827,17 +826,17 @@ public void create() throws ResourceAllocationException { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm"); } } catch (InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex.getMessage(), ex); + logger.info(ex); + logger.trace(ex.getMessage(), ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java index 07fd55276f84..aa121162cb4e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -46,7 +45,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DestroyVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(DestroyVMCmd.class.getName()); private static final String s_name = "destroyvirtualmachineresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java index d3cbf82f7557..11534fd43759 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java @@ -16,10 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; -import java.security.InvalidParameterException; - -import org.apache.log4j.Logger; - import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; import org.apache.cloudstack.api.APICommand; @@ -29,6 +25,7 @@ import org.apache.cloudstack.api.response.GetVMPasswordResponse; import org.apache.cloudstack.api.response.UserVmResponse; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.user.Account; import com.cloud.uservm.UserVm; import com.cloud.vm.VirtualMachine; @@ -36,7 +33,6 @@ @APICommand(name = "getVMPassword", responseObject = GetVMPasswordResponse.class, description = "Returns an encrypted password for the VM", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetVMPasswordCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetVMPasswordCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -63,7 +59,7 @@ public Long getId() { public void execute() { String passwd = _mgr.getVMPassword(this); if (passwd == null || passwd.equals("")) - throw new InvalidParameterException("No password for VM with id '" + getId() + "' found."); + throw new InvalidParameterValueException("No password for VM with id '" + getId() + "' found."); setResponseObject(new GetVMPasswordResponse(getCommandName(), passwd)); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java index 44710d018d3b..0e659fc02a1a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.NicResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -45,7 +44,6 @@ @APICommand(name = "listNics", description = "list the vm nics IP to NIC", responseObject = NicResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNicsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNicsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -157,7 +155,7 @@ public void execute() throws ResourceUnavailableException, ResourceAllocationExc this.setResponseObject(response); } } catch (Exception e) { - s_logger.warn("Failed to list secondary ip address per nic "); + logger.warn("Failed to list secondary ip address per nic "); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java index 37b702e166af..50e1798112d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java @@ -47,7 +47,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.server.ResourceIcon; @@ -58,7 +57,6 @@ @APICommand(name = "listVirtualMachines", description = "List the virtual machines owned by the account.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListVMsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java index 9bdcc1aed56c..153f5ea65636 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java @@ -16,8 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; -import org.apache.log4j.Logger; +import com.cloud.exception.ResourceAllocationException; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; import org.apache.cloudstack.api.APICommand; @@ -42,7 +42,6 @@ @APICommand(name = "rebootVirtualMachine", description = "Reboots a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RebootVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RebootVMCmd.class.getName()); private static final String s_name = "rebootvirtualmachineresponse"; ///////////////////////////////////////////////////// @@ -115,7 +114,7 @@ public Long getApiResourceId() { } @Override - public void execute() throws ResourceUnavailableException, InsufficientCapacityException { + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException { CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId())); UserVm result; result = _userVmService.rebootVirtualMachine(this); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java index e964cc69231b..2f53c3d4e4cd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -41,7 +40,6 @@ @APICommand(name = "removeIpFromNic", description = "Removes secondary IP from the NIC.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveIpFromVmNicCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveIpFromVmNicCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -129,7 +127,7 @@ public NetworkType getNetworkType() { private boolean isZoneSGEnabled() { Network ntwk = _entityMgr.findById(Network.class, getNetworkId()); DataCenter dc = _entityMgr.findById(DataCenter.class, ntwk.getDataCenterId()); - return dc.isSecurityGroupEnabled(); + return dc.isSecurityGroupEnabled() || _ntwkModel.isSecurityGroupSupportedForZone(dc.getId()); } @Override diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java index 5fd016c38edc..d9024f340228 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java @@ -20,7 +20,6 @@ import java.util.EnumSet; import com.cloud.vm.Nic; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -45,7 +44,6 @@ @APICommand(name = "removeNicFromVirtualMachine", description = "Removes VM from specified network by deleting a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RemoveNicFromVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RemoveNicFromVMCmd.class); private static final String s_name = "removenicfromvirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java index 1cf4c929b32d..7270004aeed8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -45,7 +44,6 @@ "support this feature for this command to take effect. [async]", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ResetVMPasswordCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ResetVMPasswordCmd.class.getName()); private static final String s_name = "resetpasswordforvirtualmachineresponse"; @@ -122,9 +120,9 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE UserVm vm = _responseGenerator.findUserVmById(getId()); if (StringUtils.isBlank(password)) { password = _mgr.generateRandomPassword(); - s_logger.debug(String.format("Resetting VM [%s] password to a randomly generated password.", vm.getUuid())); + logger.debug(String.format("Resetting VM [%s] password to a randomly generated password.", vm.getUuid())); } else { - s_logger.debug(String.format("Resetting VM [%s] password to password defined by user.", vm.getUuid())); + logger.debug(String.format("Resetting VM [%s] password to password defined by user.", vm.getUuid())); } CallContext.current().setEventDetails("Vm Id: " + getId()); UserVm result = _userVmService.resetVMPassword(this, password); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java index 259cfebbad56..a4019411e1d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -50,7 +49,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ResetVMSSHKeyCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ResetVMSSHKeyCmd.class.getName()); private static final String s_name = "resetSSHKeyforvirtualmachineresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java index 7e0aab98760f..0ecf4ff13845 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.api.response.UserDataResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import java.util.Map; @@ -46,7 +45,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true, since = "4.18.0") public class ResetVMUserDataCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ResetVMUserDataCmd.class.getName()); private static final String s_name = "resetuserdataforvirtualmachineresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java index 17c4e97eb3b7..3839049eee5e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java @@ -17,11 +17,8 @@ package org.apache.cloudstack.api.command.user.vm; import com.cloud.vm.VmDetailConstants; -import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.cloudstack.api.response.DiskOfferingResponse; -import org.apache.log4j.Logger; - import org.apache.cloudstack.acl.SecurityChecker.AccessType; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ACL; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -31,6 +28,7 @@ import org.apache.cloudstack.api.ResponseObject.ResponseView; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; @@ -50,7 +48,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RestoreVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RestoreVMCmd.class); private static final String s_name = "restorevmresponse"; @ACL(accessType = AccessType.OperateEntry) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java index 5af45762ece6..3af6d5245f00 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -49,7 +48,6 @@ @APICommand(name = "scaleVirtualMachine", description = "Scales the virtual machine to a new service offering. This command also considers the volume size in the service offering or disk offering linked to the new service offering and apply all characteristics to the root volume.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ScaleVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ScaleVMCmd.class.getName()); private static final String s_name = "scalevirtualmachineresponse"; ///////////////////////////////////////////////////// @@ -169,16 +167,16 @@ public void execute() { try { result = _userVmService.upgradeVirtualMachine(this); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ManagementServerException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (VirtualMachineMigrationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } if (result != null){ diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java index 10c50dc380b4..c0311d599974 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java @@ -18,7 +18,6 @@ import org.apache.cloudstack.api.response.ClusterResponse; import org.apache.cloudstack.api.response.PodResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -51,7 +50,6 @@ @APICommand(name = "startVirtualMachine", responseObject = UserVmResponse.class, description = "Starts a virtual machine.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class StartVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName()); private static final String s_name = "startvirtualmachineresponse"; @@ -104,6 +102,10 @@ public Long getId() { return id; } + public void setId(Long id) { + this.id = id; + } + public Long getHostId() { return hostId; } @@ -188,19 +190,19 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (StorageUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ExecutionException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { StringBuilder message = new StringBuilder(ex.getMessage()); @@ -209,8 +211,8 @@ public void execute() { message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them"); } } - s_logger.info(ex); - s_logger.info(message.toString(), ex); + logger.info(ex); + logger.info(message.toString(), ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java index 113ba9ed25db..bfd5d8d07f61 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ @APICommand(name = "stopVirtualMachine", responseObject = UserVmResponse.class, description = "Stops a virtual machine.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class StopVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(StopVMCmd.class.getName()); private static final String s_name = "stopvirtualmachineresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java index ff533f82095e..837bde06a6ca 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java @@ -20,7 +20,6 @@ import java.util.EnumSet; import com.cloud.vm.Nic; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -45,7 +44,6 @@ @APICommand(name = "updateDefaultNicForVirtualMachine", description = "Changes the default NIC on a VM", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateDefaultNicForVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateDefaultNicForVMCmd.class); private static final String s_name = "updatedefaultnicforvirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java index 1660255979a6..0f5dade96d25 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java @@ -22,8 +22,9 @@ import java.util.Map; import com.cloud.utils.exception.CloudRuntimeException; + +import org.apache.cloudstack.api.ApiArgValidator; import org.apache.cloudstack.api.response.UserDataResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -54,7 +55,6 @@ "Therefore, stop the VM manually before issuing this call.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction, UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVMCmd.class.getName()); private static final String s_name = "updatevirtualmachineresponse"; ///////////////////////////////////////////////////// @@ -106,7 +106,7 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction, description = "true if VM contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory. This can be updated only when dynamic scaling is enabled on template, service offering and the corresponding global setting") protected Boolean isDynamicallyScalable; - @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "new host name of the vm. The VM has to be stopped/started for this update to take affect", since = "4.4") + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "new host name of the vm. The VM has to be stopped/started for this update to take affect", validations = {ApiArgValidator.RFCComplianceDomainName}, since = "4.4") private String name; @Parameter(name = ApiConstants.INSTANCE_NAME, type = CommandType.STRING, description = "instance name of the user vm", since = "4.4", authorized = {RoleType.Admin}) @@ -146,6 +146,14 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction, @Parameter(name = ApiConstants.EXTRA_CONFIG, type = CommandType.STRING, since = "4.12", description = "an optional URL encoded string that can be passed to the virtual machine upon successful deployment", length = 5120) private String extraConfig; + @Parameter(name = ApiConstants.DELETE_PROTECTION, + type = CommandType.BOOLEAN, since = "4.20.0", + description = "Set delete protection for the virtual machine. If " + + "true, the instance will be protected from deletion. " + + "Note: If the instance is managed by another service like" + + " autoscaling groups or CKS, delete protection will be ignored.") + private Boolean deleteProtection; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -215,6 +223,10 @@ public boolean isCleanupDetails(){ return cleanupDetails == null ? false : cleanupDetails.booleanValue(); } + public Boolean getDeleteProtection() { + return deleteProtection; + } + public Map> getDhcpOptionsMap() { Map> dhcpOptionsMap = new HashMap<>(); if (dhcpOptionsNetworkList != null && !dhcpOptionsNetworkList.isEmpty()) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVmNicIpCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVmNicIpCmd.java index 40658f9b58db..5c654701de91 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVmNicIpCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVmNicIpCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.EnumSet; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -49,7 +48,6 @@ @APICommand(name = "updateVmNicIp", description = "Update the default Ip of a VM Nic", responseObject = UserVmResponse.class) public class UpdateVmNicIpCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVmNicIpCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java index 4b31c12ec0a3..6a7422e70bbb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java @@ -18,7 +18,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -47,7 +46,6 @@ "this command to take effect.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpgradeVMCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpgradeVMCmd.class.getName()); private static final String s_name = "changeserviceforvirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java index 154ec45873ad..e2952b5bd818 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vmgroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "createInstanceGroup", description = "Creates a vm group", responseObject = InstanceGroupResponse.class, entityType = {InstanceGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVMGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateVMGroupCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java index 0bdda0bb9e77..b74bc43eeb7a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vmgroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -35,7 +34,6 @@ @APICommand(name = "deleteInstanceGroup", description = "Deletes a vm group", responseObject = SuccessResponse.class, entityType = {InstanceGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVMGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVMGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/ListVMGroupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/ListVMGroupsCmd.java index 2e61c898ae05..31845a956e92 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/ListVMGroupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/ListVMGroupsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vmgroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -30,7 +29,6 @@ @APICommand(name = "listInstanceGroups", description = "Lists vm groups", responseObject = InstanceGroupResponse.class, entityType = {InstanceGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVMGroupsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVMGroupsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java index 8873c852460a..5c553f064042 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vmgroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -35,7 +34,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVMGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVMGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/CreateVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/CreateVMSnapshotCmd.java index e83c6b4009d3..18a478e9daec 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/CreateVMSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/CreateVMSnapshotCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VMSnapshotResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; @@ -42,7 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVMSnapshotCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVMSnapshotCmd.class.getName()); @ACL(accessType = AccessType.OperateEntry) @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, required = true, entityType = UserVmResponse.class, description = "The ID of the vm") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/DeleteVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/DeleteVMSnapshotCmd.java index bcddc75a8e77..94b8824f8685 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/DeleteVMSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/DeleteVMSnapshotCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.vmsnapshot; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ @APICommand(name = "deleteVMSnapshot", description = "Deletes a vmsnapshot.", responseObject = SuccessResponse.class, since = "4.2.0", entityType = {VMSnapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVMSnapshotCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVMSnapshotCmd.class.getName()); @ACL(accessType = AccessType.OperateEntry) @Parameter(name = ApiConstants.VM_SNAPSHOT_ID, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java index 42cd18bfa2fc..310b45687d49 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vmsnapshot; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -45,7 +44,6 @@ @APICommand(name = "revertToVMSnapshot", description = "Revert VM from a vmsnapshot.", responseObject = UserVmResponse.class, since = "4.2.0", responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RevertToVMSnapshotCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RevertToVMSnapshotCmd.class.getName()); private static final String s_name = "reverttovmsnapshotresponse"; @ACL(accessType = AccessType.OperateEntry, pointerToEntity = "getVmId()") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java index 8d472d96eef5..287991fa9846 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java @@ -18,7 +18,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ @APICommand(name = "addResourceDetail", description = "Adds detail for the Resource.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddResourceDetailCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddResourceDetailCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AssignVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AssignVolumeCmd.java index 03413682c4f7..1a51aa03c226 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AssignVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AssignVolumeCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.VolumeResponse; -import org.apache.log4j.Logger; import com.cloud.storage.Volume; @@ -38,7 +37,6 @@ @APICommand(name = AssignVolumeCmd.CMD_NAME, responseObject = VolumeResponse.class, description = "Changes ownership of a Volume from one account to another.", entityType = { Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0.0") public class AssignVolumeCmd extends BaseCmd implements UserCmd { - public static final Logger LOGGER = Logger.getLogger(AssignVolumeCmd.class.getName()); public static final String CMD_NAME = "assignVolume"; ///////////////////////////////////////////////////// @@ -96,7 +94,7 @@ public void execute() { } catch (CloudRuntimeException | ResourceAllocationException e) { String msg = String.format("Assign volume command for volume [%s] failed due to [%s].", getFullUrlParams().get("volumeid"), e.getMessage()); - LOGGER.error(msg, e); + logger.error(msg, e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, msg); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java index 687d683309c6..1a3b9220877f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ @APICommand(name = "attachVolume", description = "Attaches a disk volume to a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AttachVolumeCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(AttachVolumeCmd.class.getName()); private static final String s_name = "attachvolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java index e28efd108524..56fdf6bc126c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java @@ -16,8 +16,8 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import com.cloud.event.EventTypes; -import com.cloud.exception.InvalidParameterValueException; +import java.util.Arrays; + import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -30,21 +30,19 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.EnumUtils; -import org.apache.log4j.Logger; +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceAllocationException; import com.cloud.storage.Volume; import com.cloud.user.Account; import com.cloud.utils.Pair; import com.cloud.utils.StringUtils; -import java.util.Arrays; - @APICommand(name = "checkVolume", description = "Check the volume for any errors or leaks and also repairs when repair parameter is passed, this is currently supported for KVM only", responseObject = VolumeResponse.class, entityType = {Volume.class}, since = "4.19.1", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CheckAndRepairVolumeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CheckAndRepairVolumeCmd.class.getName()); private static final String s_name = "checkandrepairvolumeresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java index 566e8a46bd94..7ffcea50b219 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -48,7 +47,6 @@ Volume.class, VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateVolumeCmd.class.getName()); private static final String s_name = "createvolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java index 4bcc8a88545f..6111488a8021 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ @APICommand(name = "deleteVolume", description = "Deletes a detached disk volume.", responseObject = SuccessResponse.class, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVolumeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVolumeCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DestroyVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DestroyVolumeCmd.java index f4007ce9f40b..2eafb76e5915 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DestroyVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DestroyVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -42,7 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DestroyVolumeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DestroyVolumeCmd.class.getName()); private static final String s_name = "destroyvolumeresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java index e92f6a3cb0d8..2fddcace84dd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -42,7 +41,6 @@ @APICommand(name = "detachVolume", description = "Detaches a disk volume from a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DetachVolumeCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(DetachVolumeCmd.class.getName()); private static final String s_name = "detachvolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java index 8f6e3a6c1204..9445aba23c06 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -32,16 +31,13 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; -import com.cloud.storage.Upload; import com.cloud.storage.Volume; import com.cloud.user.Account; @APICommand(name = "extractVolume", description = "Extracts volume", responseObject = ExtractResponse.class, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ExtractVolumeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ExtractVolumeCmd.class.getName()); ///////////////////////////////////////////////////// @@ -126,20 +122,8 @@ public void execute() { CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId())); String uploadUrl = _volumeService.extractVolume(this); if (uploadUrl != null) { - ExtractResponse response = new ExtractResponse(); + ExtractResponse response = _responseGenerator.createVolumeExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl); response.setResponseName(getCommandName()); - response.setObjectName("volume"); - Volume vol = _entityMgr.findById(Volume.class, id); - response.setId(vol.getUuid()); - response.setName(vol.getName()); - DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId); - response.setZoneId(zone.getUuid()); - response.setZoneName(zone.getName()); - response.setMode(mode); - response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString()); - Account account = _entityMgr.findById(Account.class, getEntityOwnerId()); - response.setAccountId(account.getUuid()); - response.setUrl(uploadUrl); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract volume"); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/GetUploadParamsForVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/GetUploadParamsForVolumeCmd.java index 1342ffc4748c..4ccd5f97993a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/GetUploadParamsForVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/GetUploadParamsForVolumeCmd.java @@ -30,12 +30,10 @@ import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.GetUploadParamsResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "getUploadParamsForVolume", description = "Upload a data disk to the cloudstack cloud.", responseObject = GetUploadParamsResponse.class, since = "4.6.0", requestHasSensitiveInfo= false, responseHasSensitiveInfo = false) public class GetUploadParamsForVolumeCmd extends AbstractGetUploadParamsCmd { - public static final Logger s_logger = Logger.getLogger(GetUploadParamsForVolumeCmd.class.getName()); private static final String s_name = "postuploadvolumeresponse"; @@ -62,7 +60,7 @@ public void execute() throws ServerApiException { response.setResponseName(getCommandName()); setResponseObject(response); } catch (MalformedURLException | ResourceAllocationException e) { - s_logger.error("exception while uploading volume", e); + logger.error("exception while uploading volume", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "exception while uploading a volume: " + e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java index 6510106557b4..a1024a988981 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java @@ -37,14 +37,12 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.storage.Volume; @APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = { Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVolumesCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListVolumesCmd.class.getName()); private static final String s_name = "listvolumesresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RecoverVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RecoverVolumeCmd.java index 2589f816bc63..cd5a7735e382 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RecoverVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RecoverVolumeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -39,7 +38,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RecoverVolumeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RecoverVolumeCmd.class.getName()); private static final String s_name = "recovervolumeresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RemoveResourceDetailCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RemoveResourceDetailCmd.java index 98fe6a7e821f..bad839f8ac7e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RemoveResourceDetailCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RemoveResourceDetailCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -31,7 +30,6 @@ @APICommand(name = "removeResourceDetail", description = "Removes detail for the Resource.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveResourceDetailCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveResourceDetailCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java index 0daf141ba4a6..65a3d6a7063a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -44,7 +43,6 @@ @APICommand(name = "resizeVolume", description = "Resizes a volume", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ResizeVolumeCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ResizeVolumeCmd.class.getName()); private static final String s_name = "resizevolumeresponse"; @@ -103,6 +101,10 @@ public Long getId() { return getEntityId(); } + public void setId(Long id) { + this.id = id; + } + public Long getMinIops() { return minIops; } @@ -115,6 +117,10 @@ public Long getSize() { return size; } + public void setSize(Long size) { + this.size = size; + } + public boolean isShrinkOk() { return shrinkOk; } @@ -195,10 +201,10 @@ public void execute() { volume = _volumeService.resizeVolume(this); } catch (ResourceAllocationException ex) { - s_logger.error(ex.getMessage()); + logger.error(ex.getMessage()); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } catch (InvalidParameterValueException ex) { - s_logger.info(ex.getMessage()); + logger.info(ex.getMessage()); throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java index e7782674828f..22b819c8cba2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -41,7 +40,6 @@ @APICommand(name = "updateVolume", description = "Updates the volume.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVolumeCmd.class.getName()); private static final String s_name = "updatevolumeresponse"; ///////////////////////////////////////////////////// @@ -79,6 +77,14 @@ public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd { @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "new name of the volume", since = "4.16") private String name; + @Parameter(name = ApiConstants.DELETE_PROTECTION, + type = CommandType.BOOLEAN, since = "4.20.0", + description = "Set delete protection for the volume. If true, The volume " + + "will be protected from deletion. Note: If the volume is managed by " + + "another service like autoscaling groups or CKS, delete protection will be " + + "ignored.") + private Boolean deleteProtection; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -111,6 +117,10 @@ public String getName() { return name; } + public Boolean getDeleteProtection() { + return deleteProtection; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -170,7 +180,7 @@ public String getEventDescription() { public void execute() { CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId())); Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(), - getCustomId(), getEntityOwnerId(), getChainInfo(), getName()); + getDeleteProtection(), getCustomId(), getEntityOwnerId(), getChainInfo(), getName()); if (result != null) { VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), result); response.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java index c622081079d8..339c276d59ea 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -45,7 +44,6 @@ @APICommand(name = "uploadVolume", description = "Uploads a data disk.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UploadVolumeCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UploadVolumeCmd.class.getName()); private static final String s_name = "uploadvolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreatePrivateGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreatePrivateGatewayCmd.java index cf1315c9d55f..dceaabf648de 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreatePrivateGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreatePrivateGatewayCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -52,7 +51,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreatePrivateGatewayCmd.class.getName()); private static final String s_name = "createprivategatewayresponse"; @@ -149,11 +147,11 @@ public void create() throws ResourceAllocationException { try { result = _vpcService.createVpcPrivateGateway(this); } catch (InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java index 68d7a77d946b..b28c02cb8004 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -42,7 +41,6 @@ @APICommand(name = "createStaticRoute", description = "Creates a static route", responseObject = StaticRouteResponse.class, entityType = {StaticRoute.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateStaticRouteCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateStaticRouteCmd.class.getName()); @Parameter(name = ApiConstants.GATEWAY_ID, type = CommandType.UUID, @@ -75,8 +73,8 @@ public void create() throws ResourceAllocationException { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException ex) { - s_logger.info("Network rule conflict: " + ex.getMessage()); - s_logger.trace("Network rule conflict: ", ex); + logger.info("Network rule conflict: " + ex.getMessage()); + logger.trace("Network rule conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java index 39f2b32751de..2f62d0d7210d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpc; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -46,7 +45,6 @@ @APICommand(name = "createVPC", description = "Creates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateVPCCmd.class.getName()); private static final String s_name = "createvpcresponse"; // /////////////////////////////////////////////////// @@ -77,10 +75,15 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { private String displayText; - @Parameter(name = ApiConstants.CIDR, type = CommandType.STRING, required = true, description = "the cidr of the VPC. All VPC " + - "guest networks' cidrs should be within this CIDR") + @Parameter(name = ApiConstants.CIDR, type = CommandType.STRING, + description = "the cidr of the VPC. All VPC guest networks' cidrs should be within this CIDR") private String cidr; + @Parameter(name = ApiConstants.CIDR_SIZE, type = CommandType.INTEGER, + description = "the CIDR size of VPC. For regular users, this is required for VPC with ROUTED mode.", + since = "4.20.0") + private Integer cidrSize; + @Parameter(name = ApiConstants.VPC_OFF_ID, type = CommandType.UUID, entityType = VpcOfferingResponse.class, required = true, description = "the ID of the VPC offering") private Long vpcOffering; @@ -119,6 +122,9 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { since = "4.19") private String sourceNatIP; + @Parameter(name=ApiConstants.AS_NUMBER, type=CommandType.LONG, since = "4.20.0", description="the AS Number of the VPC tiers") + private Long asNumber; + // /////////////////////////////////////////////////// // ///////////////// Accessors /////////////////////// // /////////////////////////////////////////////////// @@ -143,6 +149,10 @@ public String getCidr() { return cidr; } + public Integer getCidrSize() { + return cidrSize; + } + public String getDisplayText() { return StringUtils.isEmpty(displayText) ? vpcName : displayText; } @@ -191,6 +201,10 @@ public String getSourceNatIP() { return sourceNatIP; } + public Long getAsNumber() { + return asNumber; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -213,14 +227,14 @@ public void execute() { _vpcService.startVpc(this); vpc = _entityMgr.findById(Vpc.class, getEntityId()); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java index 6210d80586f5..01b6aae425b3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -40,7 +39,6 @@ @APICommand(name = "deleteStaticRoute", description = "Deletes a static route", responseObject = SuccessResponse.class, entityType = {StaticRoute.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteStaticRouteCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteStaticRouteCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java index f408e32f62de..c35d9084bcc5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpc; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ @APICommand(name = "deleteVPC", description = "Deletes a VPC", responseObject = SuccessResponse.class, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVPCCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVPCCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -81,10 +79,10 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete VPC"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java index 8813cccc7791..2304cef3c6d1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ responseView = ResponseObject.ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPrivateGatewaysCmd extends BaseListProjectAndAccountResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListPrivateGatewaysCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java index c0f95fcd3616..f48e113286a9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.network.vpc.VpcOffering; import com.cloud.utils.Pair; @@ -35,7 +34,6 @@ @APICommand(name = "listVPCOfferings", description = "Lists VPC offerings", responseObject = VpcOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVPCOfferingsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListVPCOfferingsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java index 76cbcca61bb3..d128be1414d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.network.vpc.Vpc; import com.cloud.utils.Pair; @@ -42,7 +41,6 @@ @APICommand(name = "listVPCs", description = "Lists VPCs", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVPCsCmd extends BaseListTaggedResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListVPCsCmd.class.getName()); private static final String s_name = "listvpcsresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java index 04946619c0ad..5ccd496eeb4c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.VpcResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -39,7 +38,6 @@ @APICommand(name = "restartVPC", description = "Restarts a VPC", responseObject = SuccessResponse.class, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RestartVPCCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RestartVPCCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -101,14 +99,14 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restart VPC"); } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (final ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (final InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java index d4c7d0d5c599..6fcfb5311f62 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpc; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -42,7 +41,6 @@ @APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVPCCmd extends BaseAsyncCustomIdCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName()); private static final String s_name = "updatevpcresponse"; ///////////////////////////////////////////////////// @@ -129,11 +127,11 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC"); } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (final InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java index 8f0fb7bc0960..59ba7e94b04d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "addVpnUser", description = "Adds vpn users", responseObject = VpnUsersResponse.class, entityType = {VpnUser.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddVpnUserCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddVpnUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java index 8ecf4b051ced..417ba2773c41 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -41,7 +40,6 @@ @APICommand(name = "createRemoteAccessVpn", description = "Creates a l2tp/ipsec remote access vpn", responseObject = RemoteAccessVpnResponse.class, entityType = {RemoteAccessVpn.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateRemoteAccessVpnCmd.class.getName()); ///////////////////////////////////////////////////// @@ -148,8 +146,8 @@ public void create() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create remote access vpn"); } } catch (NetworkRuleConflictException e) { - s_logger.info("Network rule conflict: " + e.getMessage()); - s_logger.trace("Network Rule Conflict: ", e); + logger.info("Network rule conflict: " + e.getMessage()); + logger.trace("Network Rule Conflict: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } @@ -166,7 +164,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create remote access vpn"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java index 84aaafc60ed6..0b5c46d36eb9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -41,7 +40,6 @@ @APICommand(name = "createVpnConnection", description = "Create site to site vpn connection", responseObject = Site2SiteVpnConnectionResponse.class, entityType = {Site2SiteVpnConnection.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVpnConnectionCmd.class.getName()); ///////////////////////////////////////////////////// @@ -135,8 +133,8 @@ public void create() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create site to site vpn connection"); } } catch (NetworkRuleConflictException e) { - s_logger.info("Network rule conflict: " + e.getMessage()); - s_logger.trace("Network Rule Conflict: ", e); + logger.info("Network rule conflict: " + e.getMessage()); + logger.trace("Network Rule Conflict: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } @@ -153,7 +151,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create site to site vpn connection"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java index 88c6c12fac72..a2fa0d9829c8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; @@ -37,7 +36,6 @@ @APICommand(name = "createVpnCustomerGateway", description = "Creates site to site vpn customer gateway", responseObject = Site2SiteCustomerGatewayResponse.class, entityType = {Site2SiteCustomerGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVpnCustomerGatewayCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVpnCustomerGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java index c354e9727373..6f31176c4ff6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java @@ -31,12 +31,10 @@ import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse; import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "createVpnGateway", description = "Creates site to site vpn local gateway", responseObject = Site2SiteVpnGatewayResponse.class, entityType = {Site2SiteVpnGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVpnGatewayCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVpnGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java index dfc80b2fabcd..bf8d01579238 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "deleteRemoteAccessVpn", description = "Destroys a l2tp/ipsec remote access vpn", responseObject = SuccessResponse.class, entityType = {RemoteAccessVpn.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteRemoteAccessVpnCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java index 8a57dfc8edda..2528d93a0422 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "deleteVpnConnection", description = "Delete site to site vpn connection", responseObject = SuccessResponse.class, entityType = {Site2SiteVpnConnection.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVpnConnectionCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVpnConnectionCmd.class.getName()); ///////////////////////////////////////////////////// @@ -86,7 +84,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete site to site VPN connection"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java index e2f0aee90ec8..2b657fd3c088 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ @APICommand(name = "deleteVpnCustomerGateway", description = "Delete site to site vpn customer gateway", responseObject = SuccessResponse.class, entityType = {Site2SiteCustomerGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVpnCustomerGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVpnCustomerGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java index b7acc5c45069..27ded12dc58d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "deleteVpnGateway", description = "Delete site to site vpn gateway", responseObject = SuccessResponse.class, entityType = {Site2SiteVpnGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVpnGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVpnGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java index 1f2f95188e7e..4efc70c84199 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ @APICommand(name = "listRemoteAccessVpns", description = "Lists remote access vpns", responseObject = RemoteAccessVpnResponse.class, entityType = {RemoteAccessVpn.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListRemoteAccessVpnsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListRemoteAccessVpnsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java index 763a374645b9..aeeae44d0046 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -36,7 +35,6 @@ @APICommand(name = "listVpnConnections", description = "Lists site to site vpn connection gateways", responseObject = Site2SiteVpnConnectionResponse.class, entityType = {Site2SiteVpnConnection.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVpnConnectionsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVpnConnectionsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java index b66c47899f7f..258a8a753ebe 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "listVpnCustomerGateways", description = "Lists site to site vpn customer gateways", responseObject = Site2SiteCustomerGatewayResponse.class, entityType = {Site2SiteCustomerGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVpnCustomerGatewaysCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVpnCustomerGatewaysCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java index fb9c82620039..d30fbf8d32bb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -36,7 +35,6 @@ @APICommand(name = "listVpnGateways", description = "Lists site 2 site vpn gateways", responseObject = Site2SiteVpnGatewayResponse.class, entityType = {Site2SiteVpnGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVpnGatewaysCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVpnGatewaysCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnUsersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnUsersCmd.java index 9f8581eb0140..48591765ec34 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnUsersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnUsersCmd.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ @APICommand(name = "listVpnUsers", description = "Lists vpn users", responseObject = VpnUsersResponse.class, entityType = {VpnUser.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVpnUsersCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVpnUsersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java index 4adf385b127a..48e7a9ee5193 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ @APICommand(name = "removeVpnUser", description = "Removes vpn user", responseObject = SuccessResponse.class, entityType = {VpnUser.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveVpnUserCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveVpnUserCmd.class.getName()); ///////////////////////////////////////////////////// @@ -109,7 +107,7 @@ public void execute() { boolean result = _ravService.removeVpnUser(ownerId, userName, CallContext.current().getCallingAccount()); if (!result) { String errorMessage = String.format("Failed to remove VPN user=[%s]. VPN owner id=[%s].", userName, ownerId); - s_logger.error(errorMessage); + logger.error(errorMessage); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage); } @@ -118,13 +116,13 @@ public void execute() { appliedVpnUsers = _ravService.applyVpnUsers(ownerId, userName, true); } catch (ResourceUnavailableException ex) { String errorMessage = String.format("Failed to refresh VPN user=[%s] due to resource unavailable. VPN owner id=[%s].", userName, ownerId); - s_logger.error(errorMessage, ex); + logger.error(errorMessage, ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage, ex); } if (!appliedVpnUsers) { String errorMessage = String.format("Failed to refresh VPN user=[%s]. VPN owner id=[%s].", userName, ownerId); - s_logger.debug(errorMessage); + logger.debug(errorMessage); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java index c63126578f2e..736295b4119c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "resetVpnConnection", description = "Reset site to site vpn connection", responseObject = Site2SiteVpnConnectionResponse.class, entityType = {Site2SiteVpnConnection.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ResetVpnConnectionCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ResetVpnConnectionCmd.class.getName()); ///////////////////////////////////////////////////// @@ -105,7 +103,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset site to site VPN connection"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java index d5b36f662f9e..defde70b63ac 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.RemoteAccessVpnResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -32,7 +31,6 @@ @APICommand(name = "updateRemoteAccessVpn", description = "Updates remote access vpn", responseObject = RemoteAccessVpnResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateRemoteAccessVpnCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateRemoteAccessVpnCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java index 67cb65bdb93f..62dd6167b753 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.Site2SiteVpnConnection; @@ -31,7 +30,6 @@ @APICommand(name = "updateVpnConnection", description = "Updates site to site vpn connection", responseObject = Site2SiteVpnConnectionResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVpnConnectionCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVpnConnectionCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java index 179bc0407b46..9f3ac2ec4367 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java @@ -18,7 +18,6 @@ import org.apache.cloudstack.api.ApiArgValidator; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "updateVpnCustomerGateway", description = "Update site to site vpn customer gateway", responseObject = Site2SiteCustomerGatewayResponse.class, entityType = {Site2SiteCustomerGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVpnCustomerGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVpnCustomerGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java index c69bbb5689f2..9fe5ae0480f7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.Site2SiteVpnGateway; @@ -31,7 +30,6 @@ @APICommand(name = "updateVpnGateway", description = "Updates site to site vpn local gateway", responseObject = Site2SiteVpnGatewayResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVpnGatewayCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVpnGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java index c29f3a851061..d926257437e6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java @@ -29,12 +29,10 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; @APICommand(name = "listZones", description = "Lists zones", responseObject = ZoneResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListZonesCmd extends BaseListCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListZonesCmd.class.getName()); private static final String s_name = "listzonesresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ASNRangeResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ASNRangeResponse.java new file mode 100644 index 000000000000..86dab54ca6b8 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/ASNRangeResponse.java @@ -0,0 +1,93 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import com.cloud.bgp.ASNumberRange; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; + +import java.util.Date; + +@EntityReference(value = ASNumberRange.class) +public class ASNRangeResponse extends BaseResponse { + + @SerializedName(ApiConstants.ID) + @Param(description = "ID of the AS Number Range") + private String id; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "Zone ID") + private String zoneId; + + @SerializedName(ApiConstants.START_ASN) + @Param(description = "Start AS Number") + private Long startASNumber; + + @SerializedName(ApiConstants.END_ASN) + @Param(description = "End AS Number") + private Long endASNumber; + + @SerializedName(ApiConstants.CREATED) + @Param(description = "Created date") + private Date created; + + public ASNRangeResponse() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getZoneId() { + return zoneId; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public Long getStartASNumber() { + return startASNumber; + } + + public void setStartASNumber(Long startASNumber) { + this.startASNumber = startASNumber; + } + + public Long getEndASNumber() { + return endASNumber; + } + + public void setEndASNumber(Long endASNumber) { + this.endASNumber = endASNumber; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ASNumberResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ASNumberResponse.java new file mode 100644 index 000000000000..45884250984e --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/ASNumberResponse.java @@ -0,0 +1,237 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import com.cloud.bgp.ASNumber; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; + +import java.util.Date; + +@EntityReference(value = ASNumber.class) +public class ASNumberResponse extends BaseResponse { + + @SerializedName(ApiConstants.ID) + @Param(description = "ID of the AS Number") + private String id; + + @SerializedName(ApiConstants.ACCOUNT_ID) + @Param(description = "Account ID") + private String accountId; + + @SerializedName(ApiConstants.ACCOUNT) + @Param(description = "the account name") + private String accountName; + + @SerializedName(ApiConstants.DOMAIN_ID) + @Param(description = "Domain ID") + private String domainId; + + @SerializedName(ApiConstants.DOMAIN) + @Param(description = "the domain name") + private String domainName; + + @SerializedName(ApiConstants.AS_NUMBER) + @Param(description = "AS Number") + private Long asNumber; + + @SerializedName(ApiConstants.ASN_RANGE_ID) + @Param(description = "AS Number ID") + private String asNumberRangeId; + + @SerializedName(ApiConstants.ASN_RANGE) + @Param(description = "AS Number Range") + private String asNumberRange; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "Zone ID") + private String zoneId; + + @SerializedName(ApiConstants.ZONE_NAME) + @Param(description = "the zone name of the AS Number range") + private String zoneName; + + @SerializedName("allocated") + @Param(description = "Allocated Date") + private Date allocated; + + @SerializedName(ApiConstants.ALLOCATION_STATE) + @Param(description = "Allocation state") + private String allocationState; + + @SerializedName(ApiConstants.ASSOCIATED_NETWORK_ID) + @Param(description = "Network ID") + private String associatedNetworkId; + + @SerializedName(ApiConstants.ASSOCIATED_NETWORK_NAME) + @Param(description = "Network Name") + private String associatedNetworkName; + + @SerializedName((ApiConstants.VPC_ID)) + @Param(description = "VPC ID") + private String vpcId; + + @SerializedName(ApiConstants.VPC_NAME) + @Param(description = "VPC Name") + private String vpcName; + + @SerializedName(ApiConstants.CREATED) + @Param(description = "Created Date") + private Date created; + + public ASNumberResponse() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getAccountId() { + return accountId; + } + + public void setAccountId(String accountId) { + this.accountId = accountId; + } + + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public String getDomainId() { + return domainId; + } + + public void setDomainId(String domainId) { + this.domainId = domainId; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public Long getAsNumber() { + return asNumber; + } + + public void setAsNumber(Long asNumber) { + this.asNumber = asNumber; + } + + public String getAsNumberRangeId() { + return asNumberRangeId; + } + + public void setAsNumberRangeId(String asNumberRangeId) { + this.asNumberRangeId = asNumberRangeId; + } + + public String getAsNumberRange() { + return asNumberRange; + } + + public void setAsNumberRange(String asNumberRange) { + this.asNumberRange = asNumberRange; + } + + public String getZoneId() { + return zoneId; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public String getZoneName() { + return zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public Date getAllocated() { + return allocated; + } + + public void setAllocated(Date allocatedDate) { + this.allocated = allocatedDate; + } + + public String getAllocationState() { + return allocationState; + } + + public void setAllocationState(String allocated) { + allocationState = allocated; + } + + public String getAssociatedNetworkId() { + return associatedNetworkId; + } + + public void setAssociatedNetworkId(String associatedNetworkId) { + this.associatedNetworkId = associatedNetworkId; + } + + public String getAssociatedNetworkName() { + return associatedNetworkName; + } + + public void setAssociatedNetworkName(String associatedNetworkName) { + this.associatedNetworkName = associatedNetworkName; + } + + public String getVpcId() { + return vpcId; + } + + public void setVpcId(String vpcId) { + this.vpcId = vpcId; + } + + public String getVpcName() { + return vpcName; + } + + public void setVpcName(String vpcName) { + this.vpcName = vpcName; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java index 7ffe7d095e44..7a84e85a4a6f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java @@ -267,6 +267,10 @@ public class AccountResponse extends BaseResponse implements ResourceLimitAndCou @Param(description = "Base64 string representation of the resource icon", since = "4.16.0.0") ResourceIconResponse icon; + @SerializedName(ApiConstants.TAGGED_RESOURCES) + @Param(description = "The tagged resource limit and count for the account", since = "4.20.0") + List taggedResources; + @Override public String getObjectId() { return id; @@ -545,4 +549,9 @@ public void setGroups(List groups) { public void setResourceIconResponse(ResourceIconResponse icon) { this.icon = icon; } + + @Override + public void setTaggedResourceLimitsAndCounts(List taggedResourceLimitsAndCounts) { + this.taggedResources = taggedResourceLimitsAndCounts; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/AcquirePodIpCmdResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/AcquirePodIpCmdResponse.java index 77c4d0d3ffcc..2226efd063d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/AcquirePodIpCmdResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/AcquirePodIpCmdResponse.java @@ -44,7 +44,7 @@ public class AcquirePodIpCmdResponse extends BaseResponse { @SerializedName(ApiConstants.NIC_ID) @Param(description = "the ID of the nic") - private Long instanceId; + private Long nicId; @SerializedName(ApiConstants.HOST_MAC) @Param(description = "MAC address of the pod the IP") @@ -58,8 +58,8 @@ public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; } - public void setInstanceId(Long instanceId) { - this.instanceId = instanceId; + public void setNicId(Long nicId) { + this.nicId = nicId; } public void setPodId(long podId) { @@ -82,8 +82,8 @@ public long getId() { return id; } - public Long getInstanceId() { - return instanceId; + public Long getNicId() { + return nicId; } public long getPodId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/response/BackupRepositoryResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/BackupRepositoryResponse.java new file mode 100644 index 000000000000..3847176608c0 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/BackupRepositoryResponse.java @@ -0,0 +1,154 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.backup.BackupRepository; + +import java.util.Date; + +@EntityReference(value = BackupRepository.class) +public class BackupRepositoryResponse extends BaseResponse { + + @SerializedName(ApiConstants.ID) + @Param(description = "the ID of the backup repository") + private String id; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "the Zone ID of the backup repository") + private String zoneId; + + @SerializedName(ApiConstants.ZONE_NAME) + @Param(description = "the Zone name of the backup repository") + private String zoneName; + + @SerializedName(ApiConstants.NAME) + @Param(description = "the name of the backup repository") + private String name; + + @SerializedName(ApiConstants.ADDRESS) + @Param(description = "the address / url of the backup repository") + private String address; + + @SerializedName(ApiConstants.PROVIDER) + @Param(description = "name of the provider") + private String providerName; + + @SerializedName(ApiConstants.TYPE) + @Param(description = "backup type") + private String type; + + @SerializedName(ApiConstants.MOUNT_OPTIONS) + @Param(description = "mount options for the backup repository") + private String mountOptions; + + @SerializedName(ApiConstants.CAPACITY_BYTES) + @Param(description = "capacity of the backup repository") + private Long capacityBytes; + + @SerializedName("created") + @Param(description = "the date and time the backup repository was added") + private Date created; + + public BackupRepositoryResponse() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getZoneId() { + return zoneId; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public String getZoneName() { + return zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getMountOptions() { + return mountOptions; + } + + public void setMountOptions(String mountOptions) { + this.mountOptions = mountOptions; + } + + public String getProviderName() { + return providerName; + } + + public void setProviderName(String providerName) { + this.providerName = providerName; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Long getCapacityBytes() { + return capacityBytes; + } + + public void setCapacityBytes(Long capacityBytes) { + this.capacityBytes = capacityBytes; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/BgpPeerResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/BgpPeerResponse.java new file mode 100644 index 000000000000..344e65c6badc --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/BgpPeerResponse.java @@ -0,0 +1,200 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.response; + +import java.util.Date; +import java.util.Map; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.network.BgpPeer; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +@EntityReference(value = BgpPeer.class) +public class BgpPeerResponse extends BaseResponse { + @SerializedName(ApiConstants.ID) + @Param(description = "id of the bgp peer") + private String id; + + @SerializedName(ApiConstants.IP_ADDRESS) + @Param(description = "IPv4 address of bgp peer") + private String ip4Address; + + @SerializedName(ApiConstants.IP6_ADDRESS) + @Param(description = "IPv6 address of bgp peer") + private String ip6Address; + + @SerializedName(ApiConstants.AS_NUMBER) + @Param(description = "AS number of bgp peer") + private Long asNumber; + + @SerializedName(ApiConstants.PASSWORD) + @Param(description = "password of bgp peer") + private String password; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "id of zone to which the bgp peer belongs to." ) + private String zoneId; + + @SerializedName(ApiConstants.ZONE_NAME) + @Param(description = "name of zone to which the bgp peer belongs to." ) + private String zoneName; + + @SerializedName(ApiConstants.CREATED) + @Param(description = "date when this bgp peer was created." ) + private Date created; + + @SerializedName(ApiConstants.ACCOUNT) + @Param(description = "the account of the bgp peer") + private String accountName; + + @SerializedName(ApiConstants.DOMAIN_ID) + @Param(description = "the domain ID of the bgp peer") + private String domainId; + + @SerializedName(ApiConstants.DOMAIN) + @Param(description = "the domain name of the bgp peer") + private String domainName; + + @SerializedName(ApiConstants.PROJECT_ID) + @Param(description = "the project id of the bgp peer") + private String projectId; + + @SerializedName(ApiConstants.PROJECT) + @Param(description = "the project name of the bgp peer") + private String projectName; + + @SerializedName(ApiConstants.DETAILS) + @Param(description = "additional key/value details of the bgp peer") + private Map details; + + public void setId(String id) { + this.id = id; + } + + public void setIp4Address(String ip4Address) { + this.ip4Address = ip4Address; + } + + public void setIp6Address(String ip6Address) { + this.ip6Address = ip6Address; + } + + public void setAsNumber(Long asNumber) { + this.asNumber = asNumber; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public void setDomainId(String domainId) { + this.domainId = domainId; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public void setDetails(Map details) { + this.details = details; + } + + public String getId() { + return id; + } + + public String getIp4Address() { + return ip4Address; + } + + public String getIp6Address() { + return ip6Address; + } + + public Long getAsNumber() { + return asNumber; + } + + public String getPassword() { + return password; + } + + public String getZoneId() { + return zoneId; + } + + public String getZoneName() { + return zoneName; + } + + public Date getCreated() { + return created; + } + + public String getAccountName() { + return accountName; + } + + public String getDomainId() { + return domainId; + } + + public String getDomainName() { + return domainName; + } + + public String getProjectId() { + return projectId; + } + + public String getProjectName() { + return projectName; + } + + public Map getDetails() { + return details; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/BucketResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/BucketResponse.java index c66629c8e133..f2dd365452cd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/BucketResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/BucketResponse.java @@ -102,7 +102,7 @@ public class BucketResponse extends BaseResponseWithTagInformation implements Co @Param(description = "Bucket Access Key") private String accessKey; - @SerializedName(ApiConstants.SECRET_KEY) + @SerializedName(ApiConstants.USER_SECRET_KEY) @Param(description = "Bucket Secret Key") private String secretKey; diff --git a/api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java index e4224c85e970..3861ac455ed5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java @@ -92,6 +92,10 @@ public class CapabilitiesResponse extends BaseResponse { @Param(description = "true if users can see all accounts within the same domain, false otherwise") private boolean allowUserViewAllDomainAccounts; + @SerializedName(ApiConstants.ALLOW_USER_FORCE_STOP_VM) + @Param(description = "true if users are allowed to force stop a vm, false otherwise", since = "4.20.0") + private boolean allowUserForceStopVM; + @SerializedName("kubernetesserviceenabled") @Param(description = "true if Kubernetes Service plugin is enabled, false otherwise") private boolean kubernetesServiceEnabled; @@ -124,6 +128,14 @@ public class CapabilitiesResponse extends BaseResponse { @Param(description = "the retention time for Instances disks stats", since = "4.18.0") private Integer instancesDisksStatsRetentionTime; + @SerializedName(ApiConstants.SHAREDFSVM_MIN_CPU_COUNT) + @Param(description = "the min CPU count for the service offering used by the shared filesystem instance", since = "4.20.0") + private Integer sharedFsVmMinCpuCount; + + @SerializedName(ApiConstants.SHAREDFSVM_MIN_RAM_SIZE) + @Param(description = "the min Ram size for the service offering used by the shared filesystem instance", since = "4.20.0") + private Integer sharedFsVmMinRamSize; + public void setSecurityGroupsEnabled(boolean securityGroupsEnabled) { this.securityGroupsEnabled = securityGroupsEnabled; } @@ -192,6 +204,10 @@ public void setAllowUserViewAllDomainAccounts(boolean allowUserViewAllDomainAcco this.allowUserViewAllDomainAccounts = allowUserViewAllDomainAccounts; } + public void setAllowUserForceStopVM(boolean allowUserForceStopVM) { + this.allowUserForceStopVM = allowUserForceStopVM; + } + public void setKubernetesServiceEnabled(boolean kubernetesServiceEnabled) { this.kubernetesServiceEnabled = kubernetesServiceEnabled; } @@ -223,4 +239,12 @@ public void setInstancesDisksStatsRetentionTime(Integer instancesDisksStatsReten public void setCustomHypervisorDisplayName(String customHypervisorDisplayName) { this.customHypervisorDisplayName = customHypervisorDisplayName; } + + public void setSharedFsVmMinCpuCount(Integer sharedFsVmMinCpuCount) { + this.sharedFsVmMinCpuCount = sharedFsVmMinCpuCount; + } + + public void setSharedFsVmMinRamSize(Integer sharedFsVmMinRamSize) { + this.sharedFsVmMinRamSize = sharedFsVmMinRamSize; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java index e9724497c38b..2d0e21586515 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java @@ -16,12 +16,11 @@ // under the License. package org.apache.cloudstack.api.response; -import com.google.gson.annotations.SerializedName; - import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; public class CapacityResponse extends BaseResponse { @SerializedName(ApiConstants.TYPE) @@ -72,6 +71,10 @@ public class CapacityResponse extends BaseResponse { @Param(description = "the percentage of capacity currently in use") private String percentUsed; + @SerializedName(ApiConstants.TAG) + @Param(description = "The tag for the capacity type", since = "4.20.0") + private String tag; + public Short getCapacityType() { return capacityType; } @@ -167,4 +170,8 @@ public String getPercentUsed() { public void setPercentUsed(String percentUsed) { this.percentUsed = percentUsed; } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ClusterResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ClusterResponse.java index ca01a2012f6a..1c69849239f9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ClusterResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ClusterResponse.java @@ -91,6 +91,10 @@ public class ClusterResponse extends BaseResponseWithAnnotations { @Param(description = "Meta data associated with the zone (key/value pairs)") private Map resourceDetails; + @SerializedName(ApiConstants.ARCH) + @Param(description = "CPU Arch of the hosts in the cluster", since = "4.20") + private String arch; + public String getId() { return id; } @@ -247,4 +251,12 @@ public void setOvm3vip(String ovm3vip) { public void setCapacities(List capacities) { this.capacities = capacities; } + + public void setArch(String arch) { + this.arch = arch; + } + + public String getArch() { + return arch; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/DataCenterIpv4SubnetResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/DataCenterIpv4SubnetResponse.java new file mode 100644 index 000000000000..a1a87794a888 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/DataCenterIpv4SubnetResponse.java @@ -0,0 +1,151 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.response; + +import java.util.Date; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +@EntityReference(value = DataCenterIpv4GuestSubnet.class) +public class DataCenterIpv4SubnetResponse extends BaseResponse { + @SerializedName(ApiConstants.ID) + @Param(description = "id of the guest IPv4 subnet") + private String id; + + @SerializedName(ApiConstants.SUBNET) + @Param(description = "guest IPv4 subnet") + private String subnet; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "id of zone to which the IPv4 subnet belongs to." ) + private String zoneId; + + @SerializedName(ApiConstants.ZONE_NAME) + @Param(description = "name of zone to which the IPv4 subnet belongs to." ) + private String zoneName; + + @SerializedName(ApiConstants.CREATED) + @Param(description = "date when this IPv4 subnet was created." ) + private Date created; + + @SerializedName(ApiConstants.ACCOUNT) + @Param(description = "the account of the IPv4 subnet") + private String accountName; + + @SerializedName(ApiConstants.DOMAIN_ID) + @Param(description = "the domain ID of the IPv4 subnet") + private String domainId; + + @SerializedName(ApiConstants.DOMAIN) + @Param(description = "the domain name of the IPv4 subnet") + private String domainName; + + @SerializedName(ApiConstants.PROJECT_ID) + @Param(description = "the project id of the IPv4 subnet") + private String projectId; + + @SerializedName(ApiConstants.PROJECT) + @Param(description = "the project name of the IPv4 subnet") + private String projectName; + + public void setId(String id) { + this.id = id; + } + + public void setSubnet(String subnet) { + this.subnet = subnet; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public void setDomainId(String domainId) { + this.domainId = domainId; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public String getId() { + return id; + } + + public String getSubnet() { + return subnet; + } + + public String getZoneId() { + return zoneId; + } + + public String getZoneName() { + return zoneName; + } + + public Date getCreated() { + return created; + } + + public String getAccountName() { + return accountName; + } + + public String getDomainId() { + return domainId; + } + + public String getDomainName() { + return domainName; + } + + public String getProjectId() { + return projectId; + } + + public String getProjectName() { + return projectName; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java index 5b4434fbd8d0..0fed9827ef13 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java @@ -173,6 +173,10 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "additional key/value details tied with this disk offering", since = "4.17") private Map details; + @SerializedName(ApiConstants.SUITABLE_FOR_VM) + @Param(description = "Returns true if the disk offering is suitable for the given virtual machine for disk creation otherwise false", since = "4.20.0") + private Boolean suitableForVm; + public Boolean getDisplayOffering() { return displayOffering; } @@ -403,4 +407,8 @@ public void setDiskSizeStrictness(Boolean diskSizeStrictness) { public void setDetails(Map details) { this.details = details; } + + public void setSuitableForVm(Boolean suitableForVm) { + this.suitableForVm = suitableForVm; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java index e4e409a40ee1..7c6ad3a91c38 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java @@ -26,6 +26,7 @@ import com.cloud.serializer.Param; import java.util.Date; +import java.util.List; import java.util.Map; @EntityReference(value = Domain.class) @@ -184,6 +185,10 @@ public class DomainResponse extends BaseResponseWithAnnotations implements Resou @Param(description = "details for the domain") private Map details; + @SerializedName(ApiConstants.TAGGED_RESOURCES) + @Param(description = "The tagged resource limit and count for the domain", since = "4.20.0") + List taggedResources; + public String getId() { return this.id; } @@ -447,4 +452,9 @@ public void setResourceIconResponse(ResourceIconResponse icon) { public void setDetails(Map details) { this.details = details; } + + @Override + public void setTaggedResourceLimitsAndCounts(List taggedResourceLimitsAndCounts) { + this.taggedResources = taggedResourceLimitsAndCounts; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java index 41a0fdc4567e..24015e0b4597 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java @@ -208,6 +208,14 @@ public class HostForMigrationResponse extends BaseResponse { @Param(description = "comma-separated list of tags for the host") private String hostTags; + @SerializedName("explicithosttags") + @Param(description = "comma-separated list of explicit host tags for the host", since = "4.20.0") + private String explicitHostTags; + + @SerializedName("implicithosttags") + @Param(description = "comma-separated list of implicit host tags for the host", since = "4.20.0") + private String implicitHostTags; + @SerializedName("hasenoughcapacity") @Param(description = "true if this host has enough CPU and RAM capacity to migrate a VM to it, false otherwise") private Boolean hasEnoughCapacity; @@ -414,6 +422,14 @@ public void setHostTags(String hostTags) { this.hostTags = hostTags; } + public void setExplicitHostTags(String explicitHostTags) { + this.explicitHostTags = explicitHostTags; + } + + public void setImplicitHostTags(String implicitHostTags) { + this.implicitHostTags = implicitHostTags; + } + public void setHasEnoughCapacity(Boolean hasEnoughCapacity) { this.hasEnoughCapacity = hasEnoughCapacity; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java index 99aabd889134..62bcc07b16d9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java @@ -222,6 +222,14 @@ public class HostResponse extends BaseResponseWithAnnotations { @Param(description = "comma-separated list of tags for the host") private String hostTags; + @SerializedName("explicithosttags") + @Param(description = "comma-separated list of explicit host tags for the host", since = "4.20.0") + private String explicitHostTags; + + @SerializedName("implicithosttags") + @Param(description = "comma-separated list of implicit host tags for the host", since = "4.20.0") + private String implicitHostTags; + @SerializedName(ApiConstants.IS_TAG_A_RULE) @Param(description = ApiConstants.PARAMETER_DESCRIPTION_IS_TAG_A_RULE) private Boolean isTagARule; @@ -282,6 +290,10 @@ public class HostResponse extends BaseResponseWithAnnotations { @Param(description = "true if the host supports instance conversion (using virt-v2v)", since = "4.19.1") private Boolean instanceConversionSupported; + @SerializedName(ApiConstants.ARCH) + @Param(description = "CPU Arch of the host", since = "4.20") + private String arch; + @Override public String getObjectId() { return this.getId(); @@ -463,6 +475,22 @@ public void setHostTags(String hostTags) { this.hostTags = hostTags; } + public String getExplicitHostTags() { + return explicitHostTags; + } + + public void setExplicitHostTags(String explicitHostTags) { + this.explicitHostTags = explicitHostTags; + } + + public String getImplicitHostTags() { + return implicitHostTags; + } + + public void setImplicitHostTags(String implicitHostTags) { + this.implicitHostTags = implicitHostTags; + } + public void setHasEnoughCapacity(Boolean hasEnoughCapacity) { this.hasEnoughCapacity = hasEnoughCapacity; } @@ -763,6 +791,14 @@ public void setIsTagARule(Boolean tagARule) { isTagARule = tagARule; } + public void setArch(String arch) { + this.arch = arch; + } + + public String getArch() { + return arch; + } + public Long getCpuAllocatedValue() { return cpuAllocatedValue; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/HostTagResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/HostTagResponse.java index 4a924ea78a08..f772da6dcb66 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/HostTagResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/HostTagResponse.java @@ -19,6 +19,7 @@ import com.google.gson.annotations.SerializedName; import com.cloud.serializer.Param; +import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; public class HostTagResponse extends BaseResponse { @@ -34,6 +35,10 @@ public class HostTagResponse extends BaseResponse { @Param(description = "the name of the host tag") private String name; + @SerializedName(ApiConstants.IS_IMPLICIT) + @Param(description = "true if the host tag is implicit", since = "4.20.0") + private boolean isImplicit; + public String getId() { return id; } @@ -57,4 +62,12 @@ public String getName() { public void setName(String name) { this.name = name; } + + public boolean isImplicit() { + return isImplicit; + } + + public void setImplicit(boolean implicit) { + isImplicit = implicit; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java index fe7a6c14d738..0018edc86388 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java @@ -171,6 +171,10 @@ public class IPAddressResponse extends BaseResponseWithAnnotations implements Co @Param(description="whether the ip address has Firewall/PortForwarding/LoadBalancing rules defined") private boolean hasRules; + @SerializedName(ApiConstants.FOR_SYSTEM_VMS) + @Param(description="true if range is dedicated for System VMs") + private boolean forSystemVms; + public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; } @@ -324,4 +328,8 @@ public void setNetworkName(String networkName) { public void setHasRules(final boolean hasRules) { this.hasRules = hasRules; } + + public void setForSystemVms(boolean forSystemVms) { + this.forSystemVms = forSystemVms; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/Ipv4RouteResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/Ipv4RouteResponse.java new file mode 100644 index 000000000000..136c87971b79 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/Ipv4RouteResponse.java @@ -0,0 +1,59 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.response; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class Ipv4RouteResponse extends BaseResponse { + + @SerializedName(ApiConstants.SUBNET) + @Param(description = "the guest Ipv4 cidr for route") + private String subnet; + + @SerializedName(ApiConstants.GATEWAY) + @Param(description = "the outbound Ipv4 gateway") + private String gateway; + + public Ipv4RouteResponse() { + } + + public Ipv4RouteResponse(String subnet, String gateway) { + this.subnet = subnet; + this.gateway = gateway; + } + + public String getSubnet() { + return subnet; + } + + public void setSubnet(String subnet) { + this.subnet = subnet; + } + + public String getGateway() { + return gateway; + } + + public void setGateway(String gateway) { + this.gateway = gateway; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/Ipv4SubnetForGuestNetworkResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/Ipv4SubnetForGuestNetworkResponse.java new file mode 100644 index 000000000000..1430bcd059c1 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/Ipv4SubnetForGuestNetworkResponse.java @@ -0,0 +1,199 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.response; + +import java.util.Date; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +@EntityReference(value = Ipv4GuestSubnetNetworkMap.class) +public class Ipv4SubnetForGuestNetworkResponse extends BaseResponse { + @SerializedName(ApiConstants.ID) + @Param(description = "id of the IPv4 subnet for guest network") + private String id; + + @SerializedName(ApiConstants.PARENT_ID) + @Param(description = "id of the data center IPv4 subnet") + private String parentId; + + @SerializedName(ApiConstants.PARENT_SUBNET) + @Param(description = "subnet of the data center IPv4 subnet") + private String parentSubnet; + + @SerializedName(ApiConstants.SUBNET) + @Param(description = "subnet of the IPv4 network") + private String subnet; + + @SerializedName(ApiConstants.STATE) + @Param(description = "state of subnet of the IPv4 network") + private String state; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "id of zone to which the IPv4 subnet belongs to." ) + private String zoneId; + + @SerializedName(ApiConstants.ZONE_NAME) + @Param(description = "id of zone to which the IPv4 subnet belongs to." ) + private String zoneName; + + @SerializedName(ApiConstants.NETWORK_ID) + @Param(description = "id of network which the IPv4 subnet is associated with." ) + private String networkId; + + @SerializedName(ApiConstants.NETWORK_NAME) + @Param(description = "name of network which the IPv4 subnet is associated with." ) + private String networkName; + + @SerializedName(ApiConstants.VPC_ID) + @Param(description = "Id of the VPC which the IPv4 subnet is associated with.") + private String vpcId; + + @SerializedName(ApiConstants.VPC_NAME) + @Param(description = "Name of the VPC which the IPv4 subnet is associated with.") + private String vpcName; + + @SerializedName(ApiConstants.CREATED) + @Param(description = "date when this IPv4 subnet was created." ) + private Date created; + + @SerializedName(ApiConstants.REMOVED) + @Param(description = "date when this IPv4 subnet was removed." ) + private Date removed; + + @SerializedName(ApiConstants.ALLOCATED_TIME) + @Param(description = "date when this IPv4 subnet was allocated." ) + private Date allocatedTime; + + public void setId(String id) { + this.id = id; + } + + public void setParentId(String parentId) { + this.parentId = parentId; + } + + public void setParentSubnet(String parentSubnet) { + this.parentSubnet = parentSubnet; + } + + public void setSubnet(String subnet) { + this.subnet = subnet; + } + + public void setState(String state) { + this.state = state; + } + + public void setNetworkId(String networkId) { + this.networkId = networkId; + } + + public void setNetworkName(String networkName) { + this.networkName = networkName; + } + + public void setVpcId(String vpcId) { + this.vpcId = vpcId; + } + + public void setVpcName(String vpcName) { + this.vpcName = vpcName; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public void setCreated(Date created) { + this.created = created; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public void setAllocatedTime(Date allocatedTime) { + this.allocatedTime = allocatedTime; + } + + public String getId() { + return id; + } + + public String getParentId() { + return parentId; + } + + public String getParentSubnet() { + return parentSubnet; + } + + public String getSubnet() { + return subnet; + } + + public String getState() { + return state; + } + + public String getZoneId() { + return zoneId; + } + + public String getZoneName() { + return zoneName; + } + + public String getNetworkId() { + return networkId; + } + + public String getNetworkName() { + return networkName; + } + + public String getVpcId() { + return vpcId; + } + + public String getVpcName() { + return vpcName; + } + + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } + + public Date getAllocatedTime() { + return allocatedTime; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java index b92725d883e4..81a8129ecb76 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java @@ -99,10 +99,18 @@ public class NetworkOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "true if network offering can be used by VPC networks only") private Boolean forVpc; + @SerializedName(ApiConstants.FOR_NSX) + @Param(description = "true if network offering can be used by NSX networks only") + private Boolean forNsx; + @SerializedName(ApiConstants.FOR_TUNGSTEN) @Param(description = "true if network offering can be used by Tungsten-Fabric networks only") private Boolean forTungsten; + @SerializedName(ApiConstants.NETWORK_MODE) + @Param(description = "Mode in which the network will operate. The valid values are NATTED and ROUTED") + private String networkMode; + @SerializedName(ApiConstants.IS_PERSISTENT) @Param(description = "true if network offering supports persistent networks, false otherwise") private Boolean isPersistent; @@ -127,6 +135,10 @@ public class NetworkOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "true if network offering supports public access for guest networks", since = "4.10.0") private Boolean supportsPublicAccess; + @SerializedName(ApiConstants.SUPPORTS_INTERNAL_LB) + @Param(description = "true if network offering supports public access for guest networks", since = "4.20.0") + private Boolean supportsInternalLb; + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description = "the domain ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.") private String domainId; @@ -147,6 +159,14 @@ public class NetworkOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "the internet protocol of the network offering") private String internetProtocol; + @SerializedName(ApiConstants.SPECIFY_AS_NUMBER) + @Param(description = "true if network offering supports choosing AS numbers") + private Boolean specifyAsNumber; + + @SerializedName(ApiConstants.ROUTING_MODE) + @Param(description = "the routing mode for the network offering, supported types are Static or Dynamic.") + private String routingMode; + public void setId(String id) { this.id = id; } @@ -215,10 +235,18 @@ public void setForVpc(Boolean forVpc) { this.forVpc = forVpc; } + public void setForNsx(Boolean forNsx) { + this.forNsx = forNsx; + } + public void setForTungsten(Boolean forTungsten) { this.forTungsten = forTungsten; } + public void setNetworkMode(String networkMode) { + this.networkMode = networkMode; + } + public void setIsPersistent(Boolean isPersistent) { this.isPersistent = isPersistent; } @@ -243,6 +271,10 @@ public void setSupportsPublicAccess(Boolean supportsPublicAccess) { this.supportsPublicAccess = supportsPublicAccess; } + public void setSupportsInternalLb(Boolean supportsInternalLb) { + this.supportsInternalLb = supportsInternalLb; + } + public String getDomainId() { return domainId; } @@ -282,4 +314,20 @@ public String getInternetProtocol() { public void setInternetProtocol(String internetProtocol) { this.internetProtocol = internetProtocol; } + + public Boolean getSpecifyAsNumber() { + return specifyAsNumber; + } + + public void setSpecifyAsNumber(Boolean specifyAsNumber) { + this.specifyAsNumber = specifyAsNumber; + } + + public String getRoutingMode() { + return routingMode; + } + + public void setRoutingMode(String routingMode) { + this.routingMode = routingMode; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/NetworkProtocolResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/NetworkProtocolResponse.java new file mode 100644 index 000000000000..775333f7192d --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/NetworkProtocolResponse.java @@ -0,0 +1,89 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class NetworkProtocolResponse extends BaseResponse { + @SerializedName(ApiConstants.INDEX) + @Param(description = "the index (ID, Value, Code, Type, Option, etc) of the protocol parameter") + private Integer index; + + @SerializedName(ApiConstants.NAME) + @Param(description = "the name of the protocol parameter") + private String name; + + @SerializedName(ApiConstants.DESCRIPTION) + @Param(description = "the description of the protocol parameter") + private String description; + + @SerializedName(ApiConstants.DETAILS) + @Param(description = "the details of the protocol parameter") + private Map details; + + public NetworkProtocolResponse(Integer index, String name, String description) { + this.index = index; + this.name = name; + this.description = description; + } + + public Integer getIndex() { + return index; + } + + public void setIndex(Integer index) { + this.index = index; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map getDetails() { + return details; + } + + public void setDetails(Map details) { + this.details = details; + } + + public void addDetail(String key, String value) { + if (this.details == null) { + this.details = new LinkedHashMap(); + } + this.details.put(key, value); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java index 1049740bf55a..a80317c83cd8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.api.response; import java.util.Date; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -135,6 +136,14 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement @Param(description = "The vlan of the network. This parameter is visible to ROOT admins only") private String vlan; + @SerializedName(ApiConstants.AS_NUMBER_ID) + @Param(description = "UUID of AS NUMBER", since = "4.20.0") + private String asNumberId; + + @SerializedName(ApiConstants.AS_NUMBER) + @Param(description = "AS NUMBER", since = "4.20.0") + private Long asNumber; + @SerializedName(ApiConstants.ACL_TYPE) @Param(description = "acl type - access type to the network") private String aclType; @@ -292,7 +301,7 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement private String internetProtocol; @SerializedName(ApiConstants.IPV6_ROUTING) - @Param(description = "The routing mode of network offering", since = "4.17.0") + @Param(description = "The Ipv6 routing type of network offering", since = "4.17.0") private String ipv6Routing; @SerializedName(ApiConstants.IPV6_ROUTES) @@ -315,6 +324,18 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement @Param(description = "the second IPv6 DNS for the network", since = "4.18.0") private String ipv6Dns2; + @SerializedName(ApiConstants.IPV4_ROUTING) + @Param(description = "The IPv4 routing type of network", since = "4.20.0") + private String ipv4Routing; + + @SerializedName(ApiConstants.IPV4_ROUTES) + @Param(description = "The routes for the network to ease adding route in upstream router", since = "4.20.0") + private Set ipv4Routes; + + @SerializedName(ApiConstants.BGP_PEERS) + @Param(description = "The BGP peers for the network", since = "4.20.0") + private Set bgpPeers; + public NetworkResponse() {} public Boolean getDisplayNetwork() { @@ -415,6 +436,14 @@ public void setVlan(String vlan) { this.vlan = vlan; } + public void setAsNumber(long asNumber) { + this.asNumber = asNumber; + } + + public void setAsNumberId(String asNumberId) { + this.asNumberId = asNumberId; + } + public void setIsSystem(Boolean isSystem) { this.isSystem = isSystem; } @@ -624,6 +653,18 @@ public void setInternetProtocol(String internetProtocol) { this.internetProtocol = internetProtocol; } + public void setIpv4Routing(String ipv4Routing) { + this.ipv4Routing = ipv4Routing; + } + + public void setIpv4Routes(Set ipv4Routes) { + this.ipv4Routes = ipv4Routes; + } + + public void addIpv4Route(Ipv4RouteResponse ipv4Route) { + this.ipv4Routes.add(ipv4Route); + } + public void setIpv6Routing(String ipv6Routing) { this.ipv6Routing = ipv6Routing; } @@ -636,6 +677,17 @@ public void addIpv6Route(Ipv6RouteResponse ipv6Route) { this.ipv6Routes.add(ipv6Route); } + public void setBgpPeers(Set bgpPeers) { + this.bgpPeers = bgpPeers; + } + + public void addBgpPeer(BgpPeerResponse bgpPeer) { + if (this.bgpPeers == null) { + this.setBgpPeers(new LinkedHashSet<>()); + } + this.bgpPeers.add(bgpPeer); + } + public Integer getPublicMtu() { return publicMtu; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java index c43dd09b127a..1c63697559b5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java @@ -216,6 +216,10 @@ public class ProjectResponse extends BaseResponse implements ResourceLimitAndCou @Param(description = "the date this project was created", since = "4.16.0") private Date created; + @SerializedName(ApiConstants.TAGGED_RESOURCES) + @Param(description = "The tagged resource limit and count for the project", since = "4.20.0") + List taggedResources; + public void setId(String id) { this.id = id; } @@ -447,4 +451,9 @@ public Date getCreated() { public void setCreated(Date created) { this.created = created; } + + @Override + public void setTaggedResourceLimitsAndCounts(List taggedResourceLimitsAndCounts) { + this.taggedResources = taggedResourceLimitsAndCounts; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/PurgeExpungedResourcesResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/PurgeExpungedResourcesResponse.java new file mode 100644 index 000000000000..3807d0d5b168 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/PurgeExpungedResourcesResponse.java @@ -0,0 +1,39 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.response; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class PurgeExpungedResourcesResponse extends BaseResponse { + + @SerializedName(ApiConstants.RESOURCE_COUNT) + @Param(description = "The count of the purged expunged resources") + private Long resourceCount; + + public Long getResourceCount() { + return resourceCount; + } + + public void setResourceCount(Long resourceCount) { + this.resourceCount = resourceCount; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java index d7081884daf6..74511a0f7430 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java @@ -16,13 +16,12 @@ // under the License. package org.apache.cloudstack.api.response; -import com.cloud.configuration.Resource; -import com.google.gson.annotations.SerializedName; - import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; +import com.cloud.configuration.Resource; import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") public class ResourceCountResponse extends BaseResponse implements ControlledEntityResponse { @@ -58,10 +57,14 @@ public class ResourceCountResponse extends BaseResponse implements ControlledEnt @Param(description = "resource type name. Values include user_vm, public_ip, volume, snapshot, template, project, network, vpc, cpu, memory, primary_storage, secondary_storage.") private String resourceTypeName; - @SerializedName("resourcecount") - @Param(description = "resource count") + @SerializedName(ApiConstants.RESOURCE_COUNT) + @Param(description = "The resource count") private long resourceCount; + @SerializedName(ApiConstants.TAG) + @Param(description = "Tag for the resource", since = "4.20.0") + private String tag; + @Override public void setAccountName(String accountName) { this.accountName = accountName; @@ -101,4 +104,7 @@ public void setProjectName(String projectName) { this.projectName = projectName; } + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java index f247be834cb1..f9e6df3a0386 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java @@ -20,6 +20,8 @@ package org.apache.cloudstack.api.response; +import java.util.List; + public interface ResourceLimitAndCountResponse { public void setNetworkLimit(String networkLimit); @@ -92,4 +94,6 @@ public interface ResourceLimitAndCountResponse { public void setVmRunning(Integer vmRunning); + public void setTaggedResourceLimitsAndCounts(List taggedResourceLimitsAndCounts); + } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java index 7780d46f7f6c..b5b03873f3f1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java @@ -16,15 +16,14 @@ // under the License. package org.apache.cloudstack.api.response; -import com.cloud.configuration.Resource; -import com.google.gson.annotations.SerializedName; - import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.EntityReference; +import com.cloud.configuration.Resource; import com.cloud.configuration.ResourceLimit; import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; @EntityReference(value = ResourceLimit.class) @SuppressWarnings("unused") @@ -65,6 +64,10 @@ public class ResourceLimitResponse extends BaseResponse implements ControlledEnt @Param(description = "the project name of the resource limit") private String projectName; + @SerializedName(ApiConstants.TAG) + @Param(description = "The tag for the resource limit", since = "4.20.0") + private String tag; + @Override public void setAccountName(String accountName) { this.accountName = accountName; @@ -102,4 +105,8 @@ public void setMax(Long max) { public void setProjectId(String projectId) { this.projectId = projectId; } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/RoleResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/RoleResponse.java index 1861028f0ed5..92e3b46139f3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/RoleResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/RoleResponse.java @@ -36,6 +36,10 @@ public class RoleResponse extends BaseRoleResponse { @Param(description = "true if role is default, false otherwise") private Boolean isDefault; + @SerializedName(ApiConstants.STATE) + @Param(description = "the state of the role") + private String state; + public void setRoleType(RoleType roleType) { if (roleType != null) { this.roleType = roleType.name(); @@ -45,4 +49,8 @@ public void setRoleType(RoleType roleType) { public void setIsDefault(Boolean isDefault) { this.isDefault = isDefault; } + + public void setState(String state) { + this.state = state; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java index c7740c19214b..0622b936f6e0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java @@ -234,6 +234,10 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "true if virtual machine root disk will be encrypted on storage", since = "4.18") private Boolean encryptRoot; + @SerializedName(ApiConstants.PURGE_RESOURCES) + @Param(description = "Whether to cleanup VM and its associated resource upon expunge", since = "4.20") + private Boolean purgeResources; + public ServiceOfferingResponse() { } @@ -555,4 +559,8 @@ public String getDiskOfferingDisplayText() { } public void setEncryptRoot(Boolean encrypt) { this.encryptRoot = encrypt; } + + public void setPurgeResources(Boolean purgeResources) { + this.purgeResources = purgeResources; + } } diff --git a/server/src/main/java/com/cloud/api/query/vo/HostTagVO.java b/api/src/main/java/org/apache/cloudstack/api/response/SharedFSProviderResponse.java similarity index 55% rename from server/src/main/java/com/cloud/api/query/vo/HostTagVO.java rename to api/src/main/java/org/apache/cloudstack/api/response/SharedFSProviderResponse.java index 0a279e5c4903..4d92945646f6 100644 --- a/server/src/main/java/com/cloud/api/query/vo/HostTagVO.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/SharedFSProviderResponse.java @@ -14,48 +14,25 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package com.cloud.api.query.vo; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +package org.apache.cloudstack.api.response; -import org.apache.cloudstack.api.InternalIdentity; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; -/** - * Storage Tags DB view. - * - */ -@Entity -@Table(name = "host_tags") -public class HostTagVO extends BaseViewVO implements InternalIdentity { - private static final long serialVersionUID = 1L; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; - @Id - @Column(name = "id") - private long id; - - @Column(name = "tag") +public class SharedFSProviderResponse extends BaseResponse { + @SerializedName(ApiConstants.NAME) + @Param(description = "the name of the shared filesystem provider") private String name; - @Column(name = "host_id") - long hostId; - - @Override - public long getId() { - return id; - } - public String getName() { return name; } - public long getHostId() { - return hostId; - } - - public void setHostId(long hostId) { - this.hostId = hostId; + public void setName(String name) { + this.name = name; } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/SharedFSResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/SharedFSResponse.java new file mode 100644 index 000000000000..bac348fe36e4 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/SharedFSResponse.java @@ -0,0 +1,369 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.response; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponseWithTagInformation; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.storage.sharedfs.SharedFS; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.List; + + +@EntityReference(value = SharedFS.class) +public class SharedFSResponse extends BaseResponseWithTagInformation implements ControlledViewEntityResponse { + + @SerializedName(ApiConstants.ID) + @Param(description = "ID of the shared filesystem") + private String id; + + @SerializedName(ApiConstants.NAME) + @Param(description = "name of the shared filesystem") + private String name; + + @SerializedName(ApiConstants.DESCRIPTION) + @Param(description = "description of the shared filesystem") + private String description; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "ID of the availability zone") + private String zoneId; + + @SerializedName(ApiConstants.ZONE_NAME) + @Param(description = "Name of the availability zone") + private String zoneName; + + @SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) + @Param(description = "ID of the storage fs vm") + private String virtualMachineId; + + @SerializedName(ApiConstants.VIRTUAL_MACHINE_STATE) + @Param(description = "ID of the storage fs vm") + private String virtualMachineState; + + @SerializedName(ApiConstants.VOLUME_NAME) + @Param(description = "name of the storage fs data volume") + private String volumeName; + + @SerializedName(ApiConstants.VOLUME_ID) + @Param(description = "ID of the storage fs data volume") + private String volumeId; + + @SerializedName(ApiConstants.STORAGE) + @Param(description = "name of the storage pool hosting the data volume") + private String storagePoolName; + + @SerializedName(ApiConstants.STORAGE_ID) + @Param(description = "ID of the storage pool hosting the data volume") + private String storagePoolId; + + @SerializedName(ApiConstants.SIZE) + @Param(description = "size of the shared filesystem") + private Long size; + + @SerializedName(ApiConstants.SIZEGB) + @Param(description = "size of the shared filesystem in GiB") + private String sizeGB; + + @SerializedName(ApiConstants.DISK_OFFERING_ID) + @Param(description = "disk offering ID for the shared filesystem") + private String diskOfferingId; + + @SerializedName("diskofferingname") + @Param(description = "disk offering for the shared filesystem") + private String diskOfferingName; + + @SerializedName("iscustomdiskoffering") + @Param(description = "disk offering for the shared filesystem has custom size") + private Boolean isCustomDiskOffering; + + @SerializedName("diskofferingdisplaytext") + @Param(description = "disk offering display text for the shared filesystem") + private String diskOfferingDisplayText; + + @SerializedName(ApiConstants.SERVICE_OFFERING_ID) + @Param(description = "service offering ID for the shared filesystem") + private String serviceOfferingId; + + @SerializedName("serviceofferingname") + @Param(description = "service offering for the shared filesystem") + private String serviceOfferingName; + + @SerializedName(ApiConstants.NETWORK_ID) + @Param(description = "Network ID of the shared filesystem") + private String networkId; + + @SerializedName(ApiConstants.NETWORK_NAME) + @Param(description = "Network name of the shared filesystem") + private String networkName; + + @SerializedName(ApiConstants.NIC) + @Param(description = "the list of nics associated with the shared filesystem", responseObject = NicResponse.class) + private List nics; + + @SerializedName(ApiConstants.PATH) + @Param(description = "path to mount the shared filesystem") + private String path; + + @SerializedName(ApiConstants.STATE) + @Param(description = "the state of the shared filesystem") + private String state; + + @SerializedName(ApiConstants.PROVIDER) + @Param(description = "the shared filesystem provider") + private String provider; + + @SerializedName(ApiConstants.FILESYSTEM) + @Param(description = "the filesystem format") + private String filesystem; + + @SerializedName(ApiConstants.ACCOUNT) + @Param(description = "the account associated with the shared filesystem") + private String accountName; + + @SerializedName(ApiConstants.PROJECT_ID) + @Param(description = "the project ID of the shared filesystem") + private String projectId; + + @SerializedName(ApiConstants.PROJECT) + @Param(description = "the project name of the shared filesystem") + private String projectName; + + @SerializedName(ApiConstants.DOMAIN_ID) + @Param(description = "the ID of the domain associated with the shared filesystem") + private String domainId; + + @SerializedName(ApiConstants.DOMAIN) + @Param(description = "the domain associated with the shared filesystem") + private String domainName; + + @SerializedName(ApiConstants.DOMAIN_PATH) + @Param(description = "path of the domain to which the shared filesystem") + private String domainPath; + + @SerializedName(ApiConstants.PROVISIONINGTYPE) + @Param(description = "provisioning type used in the shared filesystem") + private String provisioningType; + + @SerializedName(ApiConstants.DISK_IO_READ) + @Param(description = "the read (IO) of disk on the shared filesystem") + private Long diskIORead; + + @SerializedName(ApiConstants.DISK_IO_WRITE) + @Param(description = "the write (IO) of disk on the shared filesystem") + private Long diskIOWrite; + + @SerializedName(ApiConstants.DISK_KBS_READ) + @Param(description = "the shared filesystem's disk read in KiB") + private Long diskKbsRead; + + @SerializedName(ApiConstants.DISK_KBS_WRITE) + @Param(description = "the shared filesystem's disk write in KiB") + private Long diskKbsWrite; + + @SerializedName(ApiConstants.VIRTUAL_SIZE) + @Param(description = "the bytes allocated") + private Long virtualSize; + + @SerializedName(ApiConstants.PHYSICAL_SIZE) + @Param(description = "the bytes actually consumed on disk") + private Long physicalSize; + + @SerializedName(ApiConstants.UTILIZATION) + @Param(description = "the disk utilization") + private String utilization; + + @Override + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + @Override + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + @Override + public void setDomainId(String domainId) { + this.domainId = domainId; + } + + @Override + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + @Override + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + public void setId(String id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public void setVirtualMachineId(String virtualMachineId) { + this.virtualMachineId = virtualMachineId; + } + + public void setState(String state) { + this.state = state; + } + + public void setVolumeId(String volumeId) { + this.volumeId = volumeId; + } + + public void setNetworkId(String networkId) { + this.networkId = networkId; + } + + public void setNetworkName(String networkName) { + this.networkName = networkName; + } + + public List getNics() { + return nics; + } + + public void addNic(NicResponse nic) { + if (this.nics == null) { + this.nics = new ArrayList<>(); + } + this.nics.add(nic); + } + + public void setSize(Long size) { + this.size = size; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setPath(String path) { + this.path = path; + } + + public void setVolumeName(String volumeName) { + this.volumeName = volumeName; + } + + public void setStoragePoolName(String storagePoolName) { + this.storagePoolName = storagePoolName; + } + + public void setStoragePoolId(String storagePoolId) { + this.storagePoolId = storagePoolId; + } + + public void setProvider(String provider) { + this.provider = provider; + } + + public void setFilesystem(String filesystem) { + this.filesystem = filesystem; + } + + public void setSizeGB(Long size) { + if (size != null) { + this.sizeGB = String.format("%.2f GiB", size / (1024.0 * 1024.0 * 1024.0)); + } + } + + public void setDiskOfferingId(String diskOfferingId) { + this.diskOfferingId = diskOfferingId; + } + + public void setDiskOfferingName(String diskOfferingName) { + this.diskOfferingName = diskOfferingName; + } + + public void setDiskOfferingDisplayText(String diskOfferingDisplayText) { + this.diskOfferingDisplayText = diskOfferingDisplayText; + } + + public void setServiceOfferingId(String serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; + } + + public void setServiceOfferingName(String serviceOfferingName) { + this.serviceOfferingName = serviceOfferingName; + } + + public void setProvisioningType(String provisioningType) { + this.provisioningType = provisioningType; + } + + public void setDiskIORead(Long diskIORead) { + this.diskIORead = diskIORead; + } + + public void setDiskIOWrite(Long diskIOWrite) { + this.diskIOWrite = diskIOWrite; + } + + public void setDiskKbsRead(Long diskKbsRead) { + this.diskKbsRead = diskKbsRead; + } + + public void setDiskKbsWrite(Long diskKbsWrite) { + this.diskKbsWrite = diskKbsWrite; + } + + public void setVirtualSize(Long virtualSize) { + this.virtualSize = virtualSize; + } + + public void setPhysicalSize(Long physicalSize) { + this.physicalSize = physicalSize; + } + + public void setUtilization(String utilization) { + this.utilization = utilization; + } + + public void setIsCustomDiskOffering(Boolean isCustomDiskOffering) { + this.isCustomDiskOffering = isCustomDiskOffering; + } + + public void setVirtualMachineState(String virtualMachineState) { + this.virtualMachineState = virtualMachineState; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java new file mode 100644 index 000000000000..bfb03b7667c2 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java @@ -0,0 +1,86 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.response; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +import com.cloud.configuration.Resource; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class TaggedResourceLimitAndCountResponse extends BaseResponse { + + @SerializedName(ApiConstants.RESOURCE_TYPE) + @Param(description = "Numerical value for the type of the resource. See the ResourceType for more information on these values.") + private Integer resourceType; + + @SerializedName(ApiConstants.RESOURCE_TYPE_NAME) + @Param(description = "Name for the type of the resource") + private String resourceTypeName; + + @SerializedName(ApiConstants.TAG) + @Param(description = "The tag for the resource type") + private String tag; + + @SerializedName(ApiConstants.LIMIT) + @Param(description = "The limit for the resource count for the type and tag for the owner") + private Long limit; + + @SerializedName(ApiConstants.TOTAL) + @Param(description = "The total amount of the resource for the type and tag that is used by the owner") + private Long total; + + @SerializedName(ApiConstants.AVAILABLE) + @Param(description = "The available amount of the resource for the type and tag that is available for the owner") + private Long available; + + + public void setResourceType(Resource.ResourceType resourceType) { + this.resourceType = resourceType.getOrdinal(); + this.resourceTypeName = resourceType.getName(); + } + + public void setTag(String tag) { + this.tag = tag; + } + + public void setLimit(Long limit) { + this.limit = limit; + } + + public void setTotal(Long total) { + this.total = total; + } + + public void setAvailable(Long available) { + this.available = available; + } + + public Long getLimit() { + return limit; + } + + public Long getTotal() { + return total; + } + + public Long getAvailable() { + return available; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/TemplateResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/TemplateResponse.java index 604c9f0955f2..98e96091d8c7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/TemplateResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/TemplateResponse.java @@ -183,6 +183,10 @@ public class TemplateResponse extends BaseResponseWithTagInformation implements @Param(description = "Lists the download progress of a template across all secondary storages") private List> downloadDetails; + @SerializedName(ApiConstants.ARCH) + @Param(description = "CPU Arch of the template", since = "4.20") + private String arch; + @SerializedName(ApiConstants.BITS) @Param(description = "the processor bit size", since = "4.10") private int bits; @@ -520,4 +524,8 @@ public String getUserDataParams() { public void setUserDataParams(String userDataParams) { this.userDataParams = userDataParams; } + + public void setArch(String arch) { + this.arch = arch; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/UsageRecordResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/UsageRecordResponse.java index 25382f3aaf9f..4aeded642871 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/UsageRecordResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/UsageRecordResponse.java @@ -16,6 +16,7 @@ // under the License. package org.apache.cloudstack.api.response; +import java.util.Date; import java.util.LinkedHashSet; import java.util.Set; @@ -137,11 +138,11 @@ public class UsageRecordResponse extends BaseResponseWithTagInformation implemen @SerializedName(ApiConstants.START_DATE) @Param(description = "start date of the usage record") - private String startDate; + private Date startDate; @SerializedName(ApiConstants.END_DATE) @Param(description = "end date of the usage record") - private String endDate; + private Date endDate; @SerializedName("issourcenat") @Param(description = "True if the IPAddress is source NAT") @@ -164,7 +165,7 @@ public class UsageRecordResponse extends BaseResponseWithTagInformation implemen private String vpcId; public UsageRecordResponse() { - tags = new LinkedHashSet(); + tags = new LinkedHashSet<>(); } public void setTags(Set tags) { @@ -249,11 +250,11 @@ public void setSize(Long size) { this.size = size; } - public void setStartDate(String startDate) { + public void setStartDate(Date startDate) { this.startDate = startDate; } - public void setEndDate(String endDate) { + public void setEndDate(Date endDate) { this.endDate = endDate; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/UsageTypeResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/UsageTypeResponse.java index 83b97f00c151..5beef5ac5562 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/UsageTypeResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/UsageTypeResponse.java @@ -25,12 +25,16 @@ public class UsageTypeResponse extends BaseResponse { - @SerializedName("usagetypeid") - @Param(description = "usage type") + @SerializedName("id") + @Param(description = "Usage type ID") private Integer usageType; + @SerializedName(ApiConstants.NAME) + @Param(description = "Usage type name") + private String name; + @SerializedName(ApiConstants.DESCRIPTION) - @Param(description = "description of usage type") + @Param(description = "Usage type description") private String description; public String getDescription() { @@ -49,10 +53,10 @@ public void setUsageType(Integer usageType) { this.usageType = usageType; } - public UsageTypeResponse(Integer usageType, String description) { + public UsageTypeResponse(Integer usageType, String name, String description) { this.usageType = usageType; + this.name = name; this.description = description; setObjectName("usagetype"); } - } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java index a9e4587169ce..1f4b493fba2f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java @@ -320,6 +320,10 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co @Param(description = "true if vm contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory.") private Boolean isDynamicallyScalable; + @SerializedName(ApiConstants.DELETE_PROTECTION) + @Param(description = "true if vm has delete protection.", since = "4.20.0") + private boolean deleteProtection; + @SerializedName(ApiConstants.SERVICE_STATE) @Param(description = "State of the Service from LB rule") private String serviceState; @@ -388,6 +392,10 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co @Param(description = "VNF details", since = "4.19.0") private Map vnfDetails; + @SerializedName((ApiConstants.VM_TYPE)) + @Param(description = "User VM type", since = "4.20.0") + private String vmType; + public UserVmResponse() { securityGroupList = new LinkedHashSet<>(); nics = new TreeSet<>(Comparator.comparingInt(x -> Integer.parseInt(x.getDeviceId()))); @@ -991,6 +999,14 @@ public void setDynamicallyScalable(Boolean dynamicallyScalable) { isDynamicallyScalable = dynamicallyScalable; } + public boolean isDeleteProtection() { + return deleteProtection; + } + + public void setDeleteProtection(boolean deleteProtection) { + this.deleteProtection = deleteProtection; + } + public String getOsTypeId() { return osTypeId; } @@ -1142,6 +1158,14 @@ public void addVnfDetail(String key, String value) { this.vnfDetails.put(key,value); } + public void setVmType(String vmType) { + this.vmType = vmType; + } + + public String getVmType() { + return vmType; + } + public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VlanIpRangeResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VlanIpRangeResponse.java index 5f5af69f6a96..1492c23e882a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VlanIpRangeResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VlanIpRangeResponse.java @@ -127,6 +127,10 @@ public class VlanIpRangeResponse extends BaseResponse implements ControlledEntit @Param(description = "indicates whether VLAN IP range is dedicated to system vms or not") private Boolean forSystemVms; + @SerializedName(ApiConstants.FOR_NSX) + @Param(description = "indicates whether IP range is dedicated to NSX resources or not") + private Boolean forNsx; + public void setId(String id) { this.id = id; } @@ -244,4 +248,8 @@ public void setIp6Gateway(String ip6Gateway) { public void setIp6Cidr(String ip6Cidr) { this.ip6Cidr = ip6Cidr; } + + public void setForNsx(Boolean forNsx) { + this.forNsx = forNsx; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java index 623499822cba..209ca57c50d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java @@ -93,7 +93,7 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co @Param(description = "display name of the virtual machine") private String virtualMachineDisplayName; - @SerializedName("vmstate") + @SerializedName(ApiConstants.VIRTUAL_MACHINE_STATE) @Param(description = "state of the virtual machine") private String virtualMachineState; @@ -261,12 +261,16 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co @Param(description = "true if storage snapshot is supported for the volume, false otherwise", since = "4.16") private boolean supportsStorageSnapshot; + @SerializedName(ApiConstants.DELETE_PROTECTION) + @Param(description = "true if volume has delete protection.", since = "4.20.0") + private boolean deleteProtection; + @SerializedName(ApiConstants.PHYSICAL_SIZE) - @Param(description = "the bytes allocated") + @Param(description = "the bytes actually consumed on disk") private Long physicalsize; @SerializedName(ApiConstants.VIRTUAL_SIZE) - @Param(description = "the bytes actually consumed on disk") + @Param(description = "the bytes allocated") private Long virtualsize; @SerializedName(ApiConstants.UTILIZATION) @@ -584,6 +588,14 @@ public boolean getSupportsStorageSnapshot() { return this.supportsStorageSnapshot; } + public boolean isDeleteProtection() { + return deleteProtection; + } + + public void setDeleteProtection(boolean deleteProtection) { + this.deleteProtection = deleteProtection; + } + public String getIsoId() { return isoId; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java index 6881969646b2..b11764da7d98 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java @@ -63,9 +63,17 @@ public class VpcOfferingResponse extends BaseResponse { private Boolean supportsDistributedRouter; @SerializedName((ApiConstants.SUPPORTS_REGION_LEVEL_VPC)) - @Param(description = " indicated if the offering can support region level vpc", since = "4.4") + @Param(description = "indicated if the offering can support region level vpc", since = "4.4") private Boolean supportsRegionLevelVpc; + @SerializedName(ApiConstants.FOR_NSX) + @Param(description = "true if vpc offering can be used by NSX networks only") + private Boolean forNsx; + + @SerializedName(ApiConstants.NETWORK_MODE) + @Param(description = "Mode in which the network will operate. The valid values are NATTED and ROUTED") + private String networkMode; + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description = "the domain ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.") private String domainId; @@ -86,6 +94,14 @@ public class VpcOfferingResponse extends BaseResponse { @Param(description = "the internet protocol of the vpc offering") private String internetProtocol; + @SerializedName(ApiConstants.SPECIFY_AS_NUMBER) + @Param(description = "true if network offering supports choosing AS numbers") + private Boolean specifyAsNumber; + + @SerializedName(ApiConstants.ROUTING_MODE) + @Param(description = "the routing mode for the network offering, supported types are Static or Dynamic.") + private String routingMode; + public void setId(String id) { this.id = id; } @@ -138,6 +154,14 @@ public void setDomain(String domain) { this.domain = domain; } + public void setForNsx(Boolean forNsx) { + this.forNsx = forNsx; + } + + public void setNetworkMode(String networkMode) { + this.networkMode = networkMode; + } + public String getZoneId() { return zoneId; } @@ -161,4 +185,20 @@ public String getInternetProtocol() { public void setInternetProtocol(String internetProtocol) { this.internetProtocol = internetProtocol; } + + public Boolean getSpecifyAsNumber() { + return specifyAsNumber; + } + + public void setSpecifyAsNumber(Boolean specifyAsNumber) { + this.specifyAsNumber = specifyAsNumber; + } + + public String getRoutingMode() { + return routingMode; + } + + public void setRoutingMode(String routingMode) { + this.routingMode = routingMode; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java index 6f91da7d2d73..56479506686a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VpcResponse.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.api.response; import java.util.Date; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -160,6 +161,26 @@ public class VpcResponse extends BaseResponseWithAnnotations implements Controll @Param(description = "the second IPv6 DNS for the VPC", since = "4.18.0") private String ipv6Dns2; + @SerializedName(ApiConstants.IPV4_ROUTING) + @Param(description = "The IPv4 routing mode of VPC", since = "4.20.0") + private String ipv4Routing; + + @SerializedName(ApiConstants.IPV4_ROUTES) + @Param(description = "The routes for the VPC to ease adding route in upstream router", since = "4.20.0") + private Set ipv4Routes; + + @SerializedName(ApiConstants.AS_NUMBER_ID) + @Param(description = "UUID of AS NUMBER", since = "4.20.0") + private String asNumberId; + + @SerializedName(ApiConstants.AS_NUMBER) + @Param(description = "AS NUMBER", since = "4.20.0") + private Long asNumber; + + @SerializedName(ApiConstants.BGP_PEERS) + @Param(description = "The BGP peers for the VPC", since = "4.20.0") + private Set bgpPeers; + public void setId(final String id) { this.id = id; } @@ -279,6 +300,18 @@ public void setResourceIconResponse(ResourceIconResponse icon) { this.icon = icon; } + public void setIpv4Routing(String ipv4Routing) { + this.ipv4Routing = ipv4Routing; + } + + public void setIpv4Routes(Set ipv4Routes) { + this.ipv4Routes = ipv4Routes; + } + + public void addIpv4Route(Ipv4RouteResponse ipv4Route) { + this.ipv4Routes.add(ipv4Route); + } + public void setIpv6Routes(Set ipv6Routes) { this.ipv6Routes = ipv6Routes; } @@ -306,4 +339,23 @@ public void setIpv6Dns1(String ipv6Dns1) { public void setIpv6Dns2(String ipv6Dns2) { this.ipv6Dns2 = ipv6Dns2; } + + public void setAsNumber(long asNumber) { + this.asNumber = asNumber; + } + + public void setAsNumberId(String asNumberId) { + this.asNumberId = asNumberId; + } + + public void setBgpPeers(Set bgpPeers) { + this.bgpPeers = bgpPeers; + } + + public void addBgpPeer(BgpPeerResponse bgpPeer) { + if (this.bgpPeers == null) { + this.setBgpPeers(new LinkedHashSet<>()); + } + this.bgpPeers.add(bgpPeer); + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ZoneResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ZoneResponse.java index efcd461cb2db..143dfad0eafd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ZoneResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ZoneResponse.java @@ -145,6 +145,18 @@ public class ZoneResponse extends BaseResponseWithAnnotations implements SetReso @Param(description = "the type of the zone - core or edge", since = "4.18.0") String type; + @SerializedName(ApiConstants.NSX_ENABLED) + @Param(description = "true, if zone is NSX enabled", since = "4.20.0") + private boolean nsxEnabled = false; + + @SerializedName(ApiConstants.MULTI_ARCH) + @Param(description = "true, if zone contains clusters and hosts from different CPU architectures", since = "4.20") + private boolean multiArch; + + @SerializedName(ApiConstants.ASN_RANGE) + @Param(description = "AS Number Range") + private String asnRange; + public ZoneResponse() { tags = new LinkedHashSet(); } @@ -308,10 +320,6 @@ public String getNetworkType() { return networkType; } - public boolean isSecurityGroupsEnabled() { - return securityGroupsEnabled; - } - public String getAllocationState() { return allocationState; } @@ -328,10 +336,6 @@ public List getCapacities() { return capacities; } - public boolean isLocalStorageEnabled() { - return localStorageEnabled; - } - public Set getTags() { return tags; } @@ -340,6 +344,14 @@ public Map getResourceDetails() { return resourceDetails; } + public boolean isSecurityGroupsEnabled() { + return securityGroupsEnabled; + } + + public boolean isLocalStorageEnabled() { + return localStorageEnabled; + } + public Boolean getAllowUserSpecifyVRMtu() { return allowUserSpecifyVRMtu; } @@ -352,6 +364,10 @@ public Integer getRouterPublicInterfaceMaxMtu() { return routerPublicInterfaceMaxMtu; } + public boolean isNsxEnabled() { + return nsxEnabled; + } + @Override public void setResourceIconResponse(ResourceIconResponse resourceIconResponse) { this.resourceIconResponse = resourceIconResponse; @@ -380,4 +396,20 @@ public void setType(String type) { public String getType() { return type; } + + public void setNsxEnabled(boolean nsxEnabled) { + this.nsxEnabled = nsxEnabled; + } + + public void setMultiArch(boolean multiArch) { + this.multiArch = multiArch; + } + + public void setAsnRange(String asnRange) { + this.asnRange = asnRange; + } + + public String getAsnRange() { + return asnRange; + } } diff --git a/api/src/main/java/org/apache/cloudstack/backup/Backup.java b/api/src/main/java/org/apache/cloudstack/backup/Backup.java index df1b243dbabb..f21f20adb33e 100644 --- a/api/src/main/java/org/apache/cloudstack/backup/Backup.java +++ b/api/src/main/java/org/apache/cloudstack/backup/Backup.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.backup; import java.util.Date; +import java.util.List; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.api.Identity; @@ -141,5 +142,6 @@ public String toString() { Backup.Status getStatus(); Long getSize(); Long getProtectedSize(); + List getBackedUpVolumes(); long getZoneId(); } diff --git a/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java b/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java index 7b39804c738e..8b45bb4ee5ef 100644 --- a/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java +++ b/api/src/main/java/org/apache/cloudstack/backup/BackupManager.java @@ -107,7 +107,7 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer * @param vmId * @return */ - BackupSchedule listBackupSchedule(Long vmId); + List listBackupSchedule(Long vmId); /** * Deletes VM backup schedule for a VM diff --git a/api/src/main/java/org/apache/cloudstack/backup/BackupProvider.java b/api/src/main/java/org/apache/cloudstack/backup/BackupProvider.java index 9c1b14ae60f2..d36dfb7360f6 100644 --- a/api/src/main/java/org/apache/cloudstack/backup/BackupProvider.java +++ b/api/src/main/java/org/apache/cloudstack/backup/BackupProvider.java @@ -93,7 +93,7 @@ public interface BackupProvider { /** * Restore a volume from a backup */ - Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid); + Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid, Pair vmNameAndState); /** * Returns backup metrics for a list of VMs in a zone diff --git a/api/src/main/java/org/apache/cloudstack/backup/BackupRepository.java b/api/src/main/java/org/apache/cloudstack/backup/BackupRepository.java new file mode 100644 index 000000000000..8e5c9740e690 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/backup/BackupRepository.java @@ -0,0 +1,34 @@ +//Licensed to the Apache Software Foundation (ASF) under one +//or more contributor license agreements. See the NOTICE file +//distributed with this work for additional information +//regarding copyright ownership. The ASF licenses this file +//to you under the Apache License, Version 2.0 (the +//"License"); you may not use this file except in compliance +//the License. You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, +//software distributed under the License is distributed on an +//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +//KIND, either express or implied. See the License for the +//specific language governing permissions and limitations +//under the License. +package org.apache.cloudstack.backup; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +import java.util.Date; + +public interface BackupRepository extends InternalIdentity, Identity { + String getProvider(); + long getZoneId(); + String getName(); + String getType(); + String getAddress(); + String getMountOptions(); + Long getCapacityBytes(); + Long getUsedBytes(); + Date getCreated(); +} diff --git a/api/src/main/java/org/apache/cloudstack/backup/BackupRepositoryService.java b/api/src/main/java/org/apache/cloudstack/backup/BackupRepositoryService.java new file mode 100644 index 000000000000..ae71053e400d --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/backup/BackupRepositoryService.java @@ -0,0 +1,34 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package org.apache.cloudstack.backup; + +import com.cloud.utils.Pair; +import org.apache.cloudstack.api.command.user.backup.repository.AddBackupRepositoryCmd; +import org.apache.cloudstack.api.command.user.backup.repository.DeleteBackupRepositoryCmd; +import org.apache.cloudstack.api.command.user.backup.repository.ListBackupRepositoriesCmd; + +import java.util.List; + +public interface BackupRepositoryService { + BackupRepository addBackupRepository(AddBackupRepositoryCmd cmd); + boolean deleteBackupRepository(DeleteBackupRepositoryCmd cmd); + Pair, Integer> listBackupRepositories(ListBackupRepositoriesCmd cmd); + +} diff --git a/api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java b/api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java index f19b5398dd9e..5bd9699b2019 100644 --- a/api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java +++ b/api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.api.command.user.consoleproxy.ConsoleEndpoint; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; +import java.util.Date; public interface ConsoleAccessManager extends Manager, Configurable { @@ -44,4 +45,7 @@ public interface ConsoleAccessManager extends Manager, Configurable { void removeSessions(String[] sessionUuids); void acquireSession(String sessionUuid); + + String genAccessTicket(String host, String port, String sid, String tag, String sessionUuid); + String genAccessTicket(String host, String port, String sid, String tag, Date normalizedHashTime, String sessionUuid); } diff --git a/api/src/main/java/org/apache/cloudstack/context/CallContext.java b/api/src/main/java/org/apache/cloudstack/context/CallContext.java index ecc109977eb6..69376e4f6d7d 100644 --- a/api/src/main/java/org/apache/cloudstack/context/CallContext.java +++ b/api/src/main/java/org/apache/cloudstack/context/CallContext.java @@ -23,8 +23,8 @@ import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal; -import org.apache.log4j.Logger; -import org.apache.log4j.NDC; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.exception.CloudAuthenticationException; import com.cloud.projects.Project; @@ -33,6 +33,7 @@ import com.cloud.utils.UuidUtils; import com.cloud.utils.db.EntityManager; import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.logging.log4j.ThreadContext; /** * CallContext records information about the environment the call is made. This @@ -40,7 +41,7 @@ * entry point must set the context and remove it when the thread finishes. */ public class CallContext { - private static final Logger s_logger = Logger.getLogger(CallContext.class); + protected static Logger LOGGER = LogManager.getLogger(CallContext.class); private static ManagedThreadLocal s_currentContext = new ManagedThreadLocal(); private static ManagedThreadLocal> s_currentContextStack = new ManagedThreadLocal>() { @Override @@ -178,9 +179,9 @@ protected static CallContext register(User callingUser, Account callingAccount, callingContext = new CallContext(userId, accountId, contextId); } s_currentContext.set(callingContext); - NDC.push("ctx-" + UuidUtils.first(contextId)); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Registered: " + callingContext); + ThreadContext.push("ctx-" + UuidUtils.first(contextId)); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Registered: " + callingContext); } s_currentContextStack.get().push(callingContext); @@ -209,7 +210,7 @@ public static CallContext registerSystemCallContextOnceOnly() { assert context.getCallingUserId() == User.UID_SYSTEM : "You are calling a very specific method that registers a one time system context. This method is meant for background threads that does processing."; return context; } catch (Exception e) { - s_logger.error("Failed to register the system call context.", e); + LOGGER.error("Failed to register the system call context.", e); throw new CloudRuntimeException("Failed to register system call context", e); } } @@ -278,18 +279,18 @@ public static CallContext unregister() { return null; } s_currentContext.remove(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Unregistered: " + context); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Unregistered: " + context); } String contextId = context.getContextId(); String sessionIdOnStack = null; String sessionIdPushedToNDC = "ctx-" + UuidUtils.first(contextId); - while ((sessionIdOnStack = NDC.pop()) != null) { + while ((sessionIdOnStack = ThreadContext.pop()) != null) { if (sessionIdOnStack.isEmpty() || sessionIdPushedToNDC.equals(sessionIdOnStack)) { break; } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Popping from NDC: " + contextId); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Popping from NDC: " + contextId); } } diff --git a/api/src/main/java/org/apache/cloudstack/context/LogContext.java b/api/src/main/java/org/apache/cloudstack/context/LogContext.java index c81d0f499cb8..c367975aba3b 100644 --- a/api/src/main/java/org/apache/cloudstack/context/LogContext.java +++ b/api/src/main/java/org/apache/cloudstack/context/LogContext.java @@ -20,8 +20,8 @@ import java.util.Map; import java.util.UUID; -import org.apache.log4j.Logger; -import org.apache.log4j.MDC; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal; @@ -31,13 +31,14 @@ import com.cloud.utils.UuidUtils; import com.cloud.utils.db.EntityManager; import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.logging.log4j.ThreadContext; /** * LogContext records information about the environment the API call is made. This * class must be always be available in all CloudStack code. */ public class LogContext { - private static final Logger s_logger = Logger.getLogger(LogContext.class); + protected static Logger LOGGER = LogManager.getLogger(LogContext.class); private static ManagedThreadLocal s_currentContext = new ManagedThreadLocal(); private String logContextId; @@ -134,9 +135,9 @@ protected static LogContext register(User callingUser, Account callingAccount, L callingContext = new LogContext(userId, accountId, contextId); } s_currentContext.set(callingContext); - MDC.put("logcontextid", UuidUtils.first(contextId)); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Registered for log: " + callingContext); + ThreadContext.put("logcontextid", UuidUtils.first(contextId)); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Registered for log: " + callingContext); } return callingContext; } @@ -160,7 +161,7 @@ public static LogContext registerSystemLogContextOnceOnly() { assert context.getCallingUserId() == User.UID_SYSTEM : "You are calling a very specific method that registers a one time system context. This method is meant for background threads that does processing."; return context; } catch (Exception e) { - s_logger.error("Failed to register the system log context.", e); + LOGGER.error("Failed to register the system log context.", e); throw new CloudRuntimeException("Failed to register system log context", e); } } @@ -206,11 +207,11 @@ public static void unregister() { LogContext context = s_currentContext.get(); if (context != null) { s_currentContext.remove(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Unregistered: " + context); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Unregistered: " + context); } } - MDC.clear(); + ThreadContext.clearMap(); } public void setStartEventId(long startEventId) { diff --git a/api/src/main/java/org/apache/cloudstack/datacenter/DataCenterIpv4GuestSubnet.java b/api/src/main/java/org/apache/cloudstack/datacenter/DataCenterIpv4GuestSubnet.java new file mode 100644 index 000000000000..90d55cc57513 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/datacenter/DataCenterIpv4GuestSubnet.java @@ -0,0 +1,36 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.datacenter; + +import java.util.Date; + +import org.apache.cloudstack.acl.InfrastructureEntity; +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +public interface DataCenterIpv4GuestSubnet extends InfrastructureEntity, InternalIdentity, Identity { + Long getDataCenterId(); + + String getSubnet(); + + Long getDomainId(); + + Long getAccountId(); + + Date getCreated(); +} diff --git a/api/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceResponse.java b/api/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceResponse.java new file mode 100644 index 000000000000..fc116cbb91e3 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceResponse.java @@ -0,0 +1,44 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.dedicated; + +import com.cloud.dc.DedicatedResources; +import com.cloud.serializer.Param; + +import com.google.gson.annotations.SerializedName; + +import org.apache.cloudstack.api.BaseResponse; + +public class DedicatedResourceResponse extends BaseResponse { + @SerializedName("resourceid") + @Param(description = "the ID of the resource") + private String resourceId; + + @SerializedName("resourcename") + @Param(description = "the name of the resource") + private String resourceName; + + @SerializedName("resourcetype") + @Param(description = "the type of the resource") + private DedicatedResources.Type resourceType; + + public DedicatedResourceResponse(String resourceId, String resourceName, DedicatedResources.Type resourceType) { + this.resourceId = resourceId; + this.resourceName = resourceName; + this.resourceType = resourceType; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/network/BgpPeer.java b/api/src/main/java/org/apache/cloudstack/network/BgpPeer.java new file mode 100644 index 000000000000..e1d7eca0a03e --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/network/BgpPeer.java @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.network; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +import java.util.Date; + +public interface BgpPeer extends Identity, InternalIdentity { + + Long getDomainId(); + + Long getAccountId(); + + enum State { + Active, Add, Revoke + } + + enum Detail { + EBGP_MultiHop + } + + long getDataCenterId(); + + String getIp4Address(); + + String getIp6Address(); + + Long getAsNumber(); + + String getPassword(); + + Date getCreated(); +} diff --git a/api/src/main/java/org/apache/cloudstack/network/BgpPeerTO.java b/api/src/main/java/org/apache/cloudstack/network/BgpPeerTO.java new file mode 100644 index 000000000000..b05033146169 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/network/BgpPeerTO.java @@ -0,0 +1,91 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network; + +import java.util.Map; + +public class BgpPeerTO { + Long peerId; + Long peerAsNumber; + String ip4Address; + String ip6Address; + String peerPassword; + Long networkId; + Long networkAsNumber; + String guestIp4Cidr; + String guestIp6Cidr; + + Map details; + + public BgpPeerTO(Long peerId, String ip4Address, String ip6Address, Long peerAsNumber, String peerPassword, + Long networkId, Long networkAsNumber, String guestIp4Cidr, String guestIp6Cidr, Map details) { + this.peerId = peerId; + this.ip4Address = ip4Address; + this.ip6Address = ip6Address; + this.peerAsNumber = peerAsNumber; + this.peerPassword = peerPassword; + this.networkId = networkId; + this.networkAsNumber = networkAsNumber; + this.guestIp4Cidr = guestIp4Cidr; + this.guestIp6Cidr = guestIp6Cidr; + this.details = details; + } + + public BgpPeerTO(Long networkId) { + this.networkId = networkId; + } + + public Long getPeerId() { + return peerId; + } + + public String getIp4Address() { + return ip4Address; + } + + public String getIp6Address() { + return ip6Address; + } + + public Long getPeerAsNumber() { + return peerAsNumber; + } + + public String getPeerPassword() { + return peerPassword; + } + + public Long getNetworkId() { + return networkId; + } + + public Long getNetworkAsNumber() { + return networkAsNumber; + } + + public String getGuestIp4Cidr() { + return guestIp4Cidr; + } + + public String getGuestIp6Cidr() { + return guestIp6Cidr; + } + + public Map getDetails() { + return details; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/network/Ipv4GuestSubnetNetworkMap.java b/api/src/main/java/org/apache/cloudstack/network/Ipv4GuestSubnetNetworkMap.java new file mode 100644 index 000000000000..569ed22c1640 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/network/Ipv4GuestSubnetNetworkMap.java @@ -0,0 +1,47 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.network; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +import java.util.Date; + +public interface Ipv4GuestSubnetNetworkMap extends Identity, InternalIdentity { + Date getAllocated(); + + Date getCreated(); + + enum State { + Allocating, // The subnet will be assigned to a network + Allocated, // The subnet is in use. + Releasing, // The subnet is being released. + Free // The subnet is ready to be allocated. + } + + Long getParentId(); + + String getSubnet(); + + Long getVpcId(); + + Long getNetworkId(); + + State getState(); + +} diff --git a/api/src/main/java/org/apache/cloudstack/network/RoutedIpv4Manager.java b/api/src/main/java/org/apache/cloudstack/network/RoutedIpv4Manager.java new file mode 100644 index 000000000000..2f704e9f47de --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/network/RoutedIpv4Manager.java @@ -0,0 +1,199 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network; + +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.network.Network; +import com.cloud.network.rules.FirewallRule; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcOffering; +import com.cloud.offering.NetworkOffering; +import com.cloud.user.Account; +import com.cloud.utils.Pair; +import com.cloud.utils.component.PluggableService; + +import org.apache.cloudstack.api.command.admin.network.CreateIpv4SubnetForZoneCmd; +import org.apache.cloudstack.api.command.admin.network.CreateIpv4SubnetForGuestNetworkCmd; +import org.apache.cloudstack.api.command.admin.network.DedicateIpv4SubnetForZoneCmd; +import org.apache.cloudstack.api.command.admin.network.DeleteIpv4SubnetForZoneCmd; +import org.apache.cloudstack.api.command.admin.network.DeleteIpv4SubnetForGuestNetworkCmd; +import org.apache.cloudstack.api.command.admin.network.ListIpv4SubnetsForZoneCmd; +import org.apache.cloudstack.api.command.admin.network.ListIpv4SubnetsForGuestNetworkCmd; +import org.apache.cloudstack.api.command.admin.network.ReleaseDedicatedIpv4SubnetForZoneCmd; +import org.apache.cloudstack.api.command.admin.network.UpdateIpv4SubnetForZoneCmd; +import org.apache.cloudstack.api.command.admin.network.bgp.ChangeBgpPeersForNetworkCmd; +import org.apache.cloudstack.api.command.admin.network.bgp.ChangeBgpPeersForVpcCmd; +import org.apache.cloudstack.api.command.admin.network.bgp.CreateBgpPeerCmd; +import org.apache.cloudstack.api.command.admin.network.bgp.DedicateBgpPeerCmd; +import org.apache.cloudstack.api.command.admin.network.bgp.DeleteBgpPeerCmd; +import org.apache.cloudstack.api.command.admin.network.bgp.ListBgpPeersCmd; +import org.apache.cloudstack.api.command.admin.network.bgp.ReleaseDedicatedBgpPeerCmd; +import org.apache.cloudstack.api.command.admin.network.bgp.UpdateBgpPeerCmd; +import org.apache.cloudstack.api.command.user.network.routing.CreateRoutingFirewallRuleCmd; +import org.apache.cloudstack.api.command.user.network.routing.ListRoutingFirewallRulesCmd; +import org.apache.cloudstack.api.command.user.network.routing.UpdateRoutingFirewallRuleCmd; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.api.response.Ipv4SubnetForGuestNetworkResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; + +import java.util.List; + +public interface RoutedIpv4Manager extends PluggableService, Configurable { + + ConfigKey RoutedNetworkIPv4MaxCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class, + "routed.network.ipv4.max.cidr.size", "30", "The maximum value of the cidr size for isolated networks in ROUTED mode", + true, ConfigKey.Scope.Account); + + ConfigKey RoutedNetworkIPv4MinCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class, + "routed.network.ipv4.min.cidr.size", "24", "The minimum value of the cidr size for isolated networks in ROUTED mode", + true, ConfigKey.Scope.Account); + + ConfigKey RoutedVpcIPv4MaxCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class, + "routed.ipv4.vpc.max.cidr.size", "28", "The maximum value of the cidr size for VPC in ROUTED mode", + true, ConfigKey.Scope.Account); + + ConfigKey RoutedVpcIPv4MinCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class, + "routed.ipv4.vpc.min.cidr.size", "22", "The minimum value of the cidr size for VPC in ROUTED mode", + true, ConfigKey.Scope.Account); + + ConfigKey RoutedIPv4NetworkCidrAutoAllocationEnabled = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Boolean.class, + "routed.ipv4.network.cidr.auto.allocation.enabled", + "true", + "Indicates whether the auto-allocation of network CIDR for routed network is enabled or not.", + true, + ConfigKey.Scope.Account); + + ConfigKey UseSystemBgpPeers = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Boolean.class, + "use.system.bgp.peers", + "true", + "If true, when account has dedicated bgp peers(s), the guest networks with dynamic routing will use both system and dedicated bgp peers. If false, only dedicated bgp peers will be used.", + true, + ConfigKey.Scope.Account); + + // Methods for DataCenterIpv4GuestSubnet APIs + DataCenterIpv4GuestSubnet createDataCenterIpv4GuestSubnet(CreateIpv4SubnetForZoneCmd createIpv4SubnetForZoneCmd); + + DataCenterIpv4SubnetResponse createDataCenterIpv4SubnetResponse(DataCenterIpv4GuestSubnet result); + + boolean deleteDataCenterIpv4GuestSubnet(DeleteIpv4SubnetForZoneCmd deleteIpv4SubnetForZoneCmd); + + DataCenterIpv4GuestSubnet updateDataCenterIpv4GuestSubnet(UpdateIpv4SubnetForZoneCmd updateIpv4SubnetForZoneCmd); + + List listDataCenterIpv4GuestSubnets(ListIpv4SubnetsForZoneCmd listIpv4SubnetsForZoneCmd); + + DataCenterIpv4GuestSubnet dedicateDataCenterIpv4GuestSubnet(DedicateIpv4SubnetForZoneCmd dedicateIpv4SubnetForZoneCmd); + + DataCenterIpv4GuestSubnet releaseDedicatedDataCenterIpv4GuestSubnet(ReleaseDedicatedIpv4SubnetForZoneCmd releaseDedicatedIpv4SubnetForZoneCmd); + + // Methods for Ipv4SubnetForGuestNetwork APIs + Ipv4GuestSubnetNetworkMap createIpv4SubnetForGuestNetwork(CreateIpv4SubnetForGuestNetworkCmd createIpv4SubnetForGuestNetworkCmd); + + boolean deleteIpv4SubnetForGuestNetwork(DeleteIpv4SubnetForGuestNetworkCmd deleteIpv4SubnetForGuestNetworkCmd); + + void releaseIpv4SubnetForGuestNetwork(long networkId); + + void releaseIpv4SubnetForVpc(long vpcId); + + List listIpv4GuestSubnetsForGuestNetwork(ListIpv4SubnetsForGuestNetworkCmd listIpv4SubnetsForGuestNetworkCmd); + + Ipv4SubnetForGuestNetworkResponse createIpv4SubnetForGuestNetworkResponse(Ipv4GuestSubnetNetworkMap subnet); + + // Methods for internal calls + void getOrCreateIpv4SubnetForGuestNetwork(Network network, String networkCidr); + + Ipv4GuestSubnetNetworkMap getOrCreateIpv4SubnetForGuestNetwork(Long domainId, Long accountId, Long zoneId, Integer networkCidrSize); + + void getOrCreateIpv4SubnetForVpc(Vpc vpc, String networkCidr); + + Ipv4GuestSubnetNetworkMap getOrCreateIpv4SubnetForVpc(Vpc vpc, Integer vpcCidrSize); + + void assignIpv4SubnetToNetwork(Network network); + + void assignIpv4SubnetToVpc(Vpc vpc); + + // Methods for Routing firewall rules + FirewallRule createRoutingFirewallRule(CreateRoutingFirewallRuleCmd createRoutingFirewallRuleCmd) throws NetworkRuleConflictException; + + Pair, Integer> listRoutingFirewallRules(ListRoutingFirewallRulesCmd listRoutingFirewallRulesCmd); + + FirewallRule updateRoutingFirewallRule(UpdateRoutingFirewallRuleCmd updateRoutingFirewallRuleCmd); + + boolean revokeRoutingFirewallRule(Long id); + + boolean applyRoutingFirewallRule(long id); + + boolean isVirtualRouterGateway(Network network); + + boolean isVirtualRouterGateway(NetworkOffering networkOffering); + + boolean isRoutedNetwork(Network network); + + boolean isDynamicRoutedNetwork(Network network); + + boolean isDynamicRoutedNetwork(NetworkOffering networkOffering); + + boolean isRoutedVpc(Vpc vpc); + + boolean isVpcVirtualRouterGateway(VpcOffering vpcOffering); + + BgpPeer createBgpPeer(CreateBgpPeerCmd createBgpPeerCmd); + + BgpPeerResponse createBgpPeerResponse(BgpPeer result); + + boolean deleteBgpPeer(DeleteBgpPeerCmd deleteBgpPeerCmd); + + BgpPeer updateBgpPeer(UpdateBgpPeerCmd updateBgpPeerCmd); + + BgpPeer dedicateBgpPeer(DedicateBgpPeerCmd dedicateBgpPeerCmd); + + BgpPeer releaseDedicatedBgpPeer(ReleaseDedicatedBgpPeerCmd releaseDedicatedBgpPeerCmd); + + List listBgpPeers(ListBgpPeersCmd listBgpPeersCmd); + + Network changeBgpPeersForNetwork(ChangeBgpPeersForNetworkCmd changeBgpPeersForNetworkCmd); + + Network removeBgpPeersFromNetwork(Network network); + + void validateBgpPeers(Account owner, Long zoneId, List bgpPeerIds); + + void persistBgpPeersForGuestNetwork(long networkId, List bgpPeerIds); + + void releaseBgpPeersForGuestNetwork(long networkId); + + boolean isDynamicRoutedVpc(Vpc vpc); + + boolean isDynamicRoutedVpc(VpcOffering vpcOff); + + void persistBgpPeersForVpc(long vpcId, List bgpPeerIds); + + void releaseBgpPeersForVpc(long vpcId); + + Vpc changeBgpPeersForVpc(ChangeBgpPeersForVpcCmd changeBgpPeersForVpcCmd); + + List getBgpPeerIdsForAccount(Account owner, long zoneIdd); + + void removeIpv4SubnetsForZoneByAccountId(long accountId); + + void removeIpv4SubnetsForZoneByDomainId(long domainId); + + void removeBgpPeersByAccountId(long accountId); + + void removeBgpPeersByDomainId(long domainId); +} diff --git a/api/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java b/api/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java index 76706a4cfc9e..1fff54f5f8ff 100644 --- a/api/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java +++ b/api/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java @@ -52,4 +52,6 @@ public interface InternalLoadBalancerElementService extends PluggableService { * @return */ List searchForInternalLoadBalancerElements(Long id, Long ntwkSvsProviderId, Boolean enabled); + + VirtualRouterProvider.Type getProviderType(); } diff --git a/api/src/main/java/org/apache/cloudstack/resource/ResourceCleanupService.java b/api/src/main/java/org/apache/cloudstack/resource/ResourceCleanupService.java new file mode 100644 index 000000000000..0d72edb07489 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/resource/ResourceCleanupService.java @@ -0,0 +1,74 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.resource; + +import org.apache.cloudstack.api.command.admin.resource.PurgeExpungedResourcesCmd; +import org.apache.cloudstack.framework.config.ConfigKey; + +import com.cloud.vm.VirtualMachine; + +public interface ResourceCleanupService { + int MINIMUM_EXPUNGED_RESOURCE_PURGE_JOB_DELAY_IN_SECONDS = 3 * 60; + ConfigKey ExpungedResourcePurgeEnabled = new ConfigKey<>("Advanced", Boolean.class, + "expunged.resources.purge.enabled", "false", + "Whether to run a background task to purge the DB records of the expunged resources", + false, ConfigKey.Scope.Global); + ConfigKey ExpungedResourcePurgeResources = new ConfigKey<>("Advanced", String.class, + "expunged.resources.purge.resources", "", + "A comma-separated list of resource types that will be considered by the background task " + + "to purge the DB records of the expunged resources. Currently only VirtualMachine is supported. " + + "An empty value will result in considering all resource types for purging", + false, ConfigKey.Scope.Global); + ConfigKey ExpungedResourcesPurgeInterval = new ConfigKey<>("Advanced", Integer.class, + "expunged.resources.purge.interval", "86400", + "Interval (in seconds) for the background task to purge the DB records of the expunged resources", + false); + ConfigKey ExpungedResourcesPurgeDelay = new ConfigKey<>("Advanced", Integer.class, + "expunged.resources.purge.delay", "300", + "Initial delay (in seconds) to start the background task to purge the DB records of the " + + "expunged resources task", false); + ConfigKey ExpungedResourcesPurgeBatchSize = new ConfigKey<>("Advanced", Integer.class, + "expunged.resources.purge.batch.size", "50", + "Batch size to be used during purging of the DB records of the expunged resources", + true); + ConfigKey ExpungedResourcesPurgeStartTime = new ConfigKey<>("Advanced", String.class, + "expunged.resources.purge.start.time", "", + "Start time to be used by the background task to purge the DB records of the expunged " + + "resources. Use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\"", true); + ConfigKey ExpungedResourcesPurgeKeepPastDays = new ConfigKey<>("Advanced", Integer.class, + "expunged.resources.purge.keep.past.days", "30", + "The number of days in the past from the execution time of the background task to purge " + + "the DB records of the expunged resources for which the expunged resources must not be purged. " + + "To enable purging DB records of the expunged resource till the execution of the background " + + "task, set the value to zero.", true); + ConfigKey ExpungedResourcePurgeJobDelay = new ConfigKey<>("Advanced", Integer.class, + "expunged.resource.purge.job.delay", + String.valueOf(MINIMUM_EXPUNGED_RESOURCE_PURGE_JOB_DELAY_IN_SECONDS), + String.format("Delay (in seconds) to execute the purging of the DB records of an expunged resource " + + "initiated by the configuration in the offering. Minimum value should be %d seconds " + + "and if a lower value is set then the minimum value will be used", + MINIMUM_EXPUNGED_RESOURCE_PURGE_JOB_DELAY_IN_SECONDS), + true); + + enum ResourceType { + VirtualMachine + } + + long purgeExpungedResources(PurgeExpungedResourcesCmd cmd); + void purgeExpungedVmResourcesLaterIfNeeded(VirtualMachine vm); +} diff --git a/api/src/main/java/org/apache/cloudstack/storage/browser/DataStoreObjectResponse.java b/api/src/main/java/org/apache/cloudstack/storage/browser/DataStoreObjectResponse.java index cac5cc91b03e..c281fa115fdd 100644 --- a/api/src/main/java/org/apache/cloudstack/storage/browser/DataStoreObjectResponse.java +++ b/api/src/main/java/org/apache/cloudstack/storage/browser/DataStoreObjectResponse.java @@ -41,6 +41,10 @@ public class DataStoreObjectResponse extends BaseResponse { @Param(description = "Template ID associated with the data store object.") private String templateId; + @SerializedName(ApiConstants.TEMPLATE_NAME) + @Param(description = "Template Name associated with the data store object.") + private String templateName; + @SerializedName(ApiConstants.FORMAT) @Param(description = "Format of template associated with the data store object.") private String format; @@ -49,10 +53,18 @@ public class DataStoreObjectResponse extends BaseResponse { @Param(description = "Snapshot ID associated with the data store object.") private String snapshotId; + @SerializedName("snapshotname") + @Param(description = "Snapshot Name associated with the data store object.") + private String snapshotName; + @SerializedName(ApiConstants.VOLUME_ID) @Param(description = "Volume ID associated with the data store object.") private String volumeId; + @SerializedName(ApiConstants.VOLUME_NAME) + @Param(description = "Volume Name associated with the data store object.") + private String volumeName; + @SerializedName(ApiConstants.LAST_UPDATED) @Param(description = "Last modified date of the file/directory.") private Date lastUpdated; @@ -86,6 +98,18 @@ public void setVolumeId(String volumeId) { this.volumeId = volumeId; } + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public void setSnapshotName(String snapshotName) { + this.snapshotName = snapshotName; + } + + public void setVolumeName(String volumeName) { + this.volumeName = volumeName; + } + public String getName() { return name; } @@ -117,4 +141,16 @@ public String getVolumeId() { public Date getLastUpdated() { return lastUpdated; } + + public String getTemplateName() { + return templateName; + } + + public String getSnapshotName() { + return snapshotName; + } + + public String getVolumeName() { + return volumeName; + } } diff --git a/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFS.java b/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFS.java new file mode 100644 index 000000000000..bcba425abbff --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFS.java @@ -0,0 +1,189 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.sharedfs; + +import com.cloud.utils.fsm.StateMachine2; +import com.cloud.utils.fsm.StateObject; + +import org.apache.cloudstack.acl.ControlledEntity; +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; +import org.apache.cloudstack.framework.config.ConfigKey; + +import java.util.Date; + +public interface SharedFS extends ControlledEntity, Identity, InternalIdentity, StateObject { + + static final ConfigKey SharedFSFeatureEnabled = new ConfigKey("Advanced", Boolean.class, + "sharedfs.feature.enabled", + "true", + " Indicates whether the Shared FileSystem feature is enabled or not. Management server restart needed on change", + false); + + ConfigKey SharedFSCleanupInterval = new ConfigKey<>(Integer.class, + "sharedfs.cleanup.interval", + "Advanced", + "14400", + "The interval (in seconds) to wait before running the shared filesystem cleanup thread.", + false, + ConfigKey.Scope.Global, + null, + SharedFSFeatureEnabled.key()); + + ConfigKey SharedFSCleanupDelay = new ConfigKey<>(Integer.class, + "sharedfs.cleanup.delay", + "Advanced", + "86400", + "Determines how long (in seconds) to wait before actually expunging destroyed shared filesystem.", + false, + ConfigKey.Scope.Global, + null, + SharedFSFeatureEnabled.key()); + + ConfigKey SharedFSExpungeWorkers = new ConfigKey<>(Integer.class, + "sharedfs.expunge.workers", + "Advanced", + "2", + "Determines how many threads are created to do the work of expunging destroyed shared filesystem.", + false, + ConfigKey.Scope.Global, + null, + SharedFSFeatureEnabled.key()); + + String SharedFSVmNamePrefix = "sharedfs"; + String SharedFSPath = "/export"; + + enum FileSystemType { + EXT4, XFS + } + + enum Protocol { + NFS + } + + enum State { + Allocated(false, "The shared filesystem is allocated in db but hasn't been created or started yet."), + Ready(false, "The shared filesystem is ready to use."), + Stopping(true, "The shared filesystem is being stopped"), + Stopped(false, "The shared filesystem is in stopped state. It can not be used but the data is still there."), + Starting(true, "The shared filesystem is being started."), + Destroyed(false, "The shared filesystem is destroyed."), + Expunging(true, "The shared filesystem is being expunged."), + Expunged(false, "The shared filesystem has been expunged."), + Error(false, "The shared filesystem is in error state."); + + boolean _transitional; + String _description; + + /** + * SharedFS State + * + * @param transitional true for transition/non-final state, otherwise false + * @param description description of the state + */ + State(boolean transitional, String description) { + _transitional = transitional; + _description = description; + } + + public boolean isTransitional() { + return _transitional; + } + + public String getDescription() { + return _description; + } + + private final static StateMachine2 s_fsm = new StateMachine2(); + + public static StateMachine2 getStateMachine() { + return s_fsm; + } + + static { + s_fsm.addTransition(new StateMachine2.Transition(Allocated, Event.OperationFailed, Error, null)); + s_fsm.addTransition(new StateMachine2.Transition(Allocated, Event.OperationSucceeded, Ready, null)); + s_fsm.addTransition(new StateMachine2.Transition(Error, Event.DestroyRequested, Destroyed, null)); + s_fsm.addTransition(new StateMachine2.Transition(Stopped, Event.StartRequested, Starting, null)); + s_fsm.addTransition(new StateMachine2.Transition(Starting, Event.OperationSucceeded, Ready, null)); + s_fsm.addTransition(new StateMachine2.Transition(Starting, Event.OperationFailed, Stopped, null)); + s_fsm.addTransition(new StateMachine2.Transition(Ready, Event.StopRequested, Stopping, null)); + s_fsm.addTransition(new StateMachine2.Transition(Stopping, Event.OperationSucceeded, Stopped, null)); + s_fsm.addTransition(new StateMachine2.Transition(Stopping, Event.OperationFailed, Ready, null)); + s_fsm.addTransition(new StateMachine2.Transition(Stopped, Event.DestroyRequested, Destroyed, null)); + s_fsm.addTransition(new StateMachine2.Transition(Destroyed, Event.RecoveryRequested, Stopped, null)); + s_fsm.addTransition(new StateMachine2.Transition(Destroyed, Event.ExpungeOperation, Expunging, null)); + s_fsm.addTransition(new StateMachine2.Transition(Error, Event.ExpungeOperation, Expunging, null)); + s_fsm.addTransition(new StateMachine2.Transition(Expunging, Event.ExpungeOperation, Expunging, null)); + s_fsm.addTransition(new StateMachine2.Transition(Expunging, Event.OperationSucceeded, Expunged, null)); + } + } + + enum Event { + StopRequested, + StartRequested, + DestroyRequested, + OperationSucceeded, + OperationFailed, + ExpungeOperation, + RecoveryRequested, + } + + static String getSharedFSPath() { + return SharedFSPath; + } + + long getId(); + + String getName(); + + void setName(String name); + + String getUuid(); + + String getDescription(); + + void setDescription(String description); + + Long getDataCenterId(); + + State getState(); + + String getFsProviderName(); + + Protocol getProtocol(); + + Long getVolumeId(); + + void setVolumeId(Long volumeId); + + Long getVmId(); + + void setVmId(Long vmId); + + FileSystemType getFsType(); + + Long getServiceOfferingId(); + + void setServiceOfferingId(Long serviceOfferingId); + + Date getUpdated(); + + public long getUpdatedCount(); + + public void incrUpdatedCount(); +} diff --git a/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSLifeCycle.java b/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSLifeCycle.java new file mode 100644 index 000000000000..552dcf79f78b --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSLifeCycle.java @@ -0,0 +1,43 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.storage.sharedfs; + +import com.cloud.dc.DataCenter; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ManagementServerException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; +import com.cloud.utils.Pair; + +public interface SharedFSLifeCycle { + void checkPrerequisites(DataCenter zone, Long serviceOfferingId); + + Pair deploySharedFS(SharedFS sharedFS, Long networkId, Long diskOfferingId, Long size, Long minIops, Long maxIops) throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, OperationTimedoutException; + + void startSharedFS(SharedFS sharedFS) throws OperationTimedoutException, ResourceUnavailableException, InsufficientCapacityException; + + boolean stopSharedFS(SharedFS sharedFS, Boolean forced); + + boolean deleteSharedFS(SharedFS sharedFS); + + boolean reDeploySharedFS(SharedFS sharedFS) throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, OperationTimedoutException; + + boolean changeSharedFSServiceOffering(SharedFS sharedFS, Long serviceOfferingId) throws ManagementServerException, ResourceUnavailableException, VirtualMachineMigrationException; +} diff --git a/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSProvider.java b/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSProvider.java new file mode 100644 index 000000000000..3966970f1887 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSProvider.java @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.sharedfs; + +import com.cloud.utils.component.Adapter; + +public interface SharedFSProvider extends Adapter { + + enum SharedFSProviderType { + SHAREDFSVM + } + + void configure(); + + SharedFSLifeCycle getSharedFSLifeCycle(); +} diff --git a/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSService.java b/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSService.java new file mode 100644 index 000000000000..21184de27a26 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSService.java @@ -0,0 +1,72 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.sharedfs; + +import java.util.List; + +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.command.user.storage.sharedfs.ChangeSharedFSDiskOfferingCmd; +import org.apache.cloudstack.api.command.user.storage.sharedfs.ChangeSharedFSServiceOfferingCmd; +import org.apache.cloudstack.api.command.user.storage.sharedfs.CreateSharedFSCmd; +import org.apache.cloudstack.api.command.user.storage.sharedfs.DestroySharedFSCmd; + +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ManagementServerException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; + +import org.apache.cloudstack.api.command.user.storage.sharedfs.ListSharedFSCmd; +import org.apache.cloudstack.api.command.user.storage.sharedfs.UpdateSharedFSCmd; +import org.apache.cloudstack.api.response.SharedFSResponse; +import org.apache.cloudstack.api.response.ListResponse; + +public interface SharedFSService { + + List getSharedFSProviders(); + + boolean stateTransitTo(SharedFS sharedFS, SharedFS.Event event); + + void setSharedFSProviders(List sharedFSProviders); + + SharedFSProvider getSharedFSProvider(String sharedFSProviderName); + + SharedFS allocSharedFS(CreateSharedFSCmd cmd); + + SharedFS deploySharedFS(CreateSharedFSCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, OperationTimedoutException; + + SharedFS startSharedFS(Long sharedFSId) throws OperationTimedoutException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException; + + SharedFS stopSharedFS(Long sharedFSId, Boolean forced); + + SharedFS restartSharedFS(Long sharedFSId, boolean cleanup) throws OperationTimedoutException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException; + + ListResponse searchForSharedFS(ResponseObject.ResponseView respView, ListSharedFSCmd cmd); + + SharedFS updateSharedFS(UpdateSharedFSCmd cmd); + + SharedFS changeSharedFSDiskOffering(ChangeSharedFSDiskOfferingCmd cmd) throws ResourceAllocationException; + + SharedFS changeSharedFSServiceOffering(ChangeSharedFSServiceOfferingCmd cmd) throws OperationTimedoutException, ResourceUnavailableException, InsufficientCapacityException, ManagementServerException, VirtualMachineMigrationException; + + Boolean destroySharedFS(DestroySharedFSCmd cmd); + + SharedFS recoverSharedFS(Long sharedFSId); + + void deleteSharedFS(Long sharedFSId); +} diff --git a/api/src/main/java/org/apache/cloudstack/usage/UsageService.java b/api/src/main/java/org/apache/cloudstack/usage/UsageService.java index 73962ba58752..00e8b431f8fe 100644 --- a/api/src/main/java/org/apache/cloudstack/usage/UsageService.java +++ b/api/src/main/java/org/apache/cloudstack/usage/UsageService.java @@ -20,7 +20,6 @@ import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd; import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd; import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd; -import org.apache.cloudstack.api.response.UsageTypeResponse; import java.util.List; import java.util.TimeZone; @@ -62,6 +61,4 @@ public interface UsageService { TimeZone getUsageTimezone(); boolean removeRawUsageRecords(RemoveRawUsageRecordsCmd cmd); - - List listUsageTypes(); } diff --git a/api/src/main/java/org/apache/cloudstack/usage/UsageTypes.java b/api/src/main/java/org/apache/cloudstack/usage/UsageTypes.java index 32ae34056ec6..5ad360a80262 100644 --- a/api/src/main/java/org/apache/cloudstack/usage/UsageTypes.java +++ b/api/src/main/java/org/apache/cloudstack/usage/UsageTypes.java @@ -51,31 +51,31 @@ public class UsageTypes { public static List listUsageTypes() { List responseList = new ArrayList(); - responseList.add(new UsageTypeResponse(RUNNING_VM, "Running Vm Usage")); - responseList.add(new UsageTypeResponse(ALLOCATED_VM, "Allocated Vm Usage")); - responseList.add(new UsageTypeResponse(IP_ADDRESS, "IP Address Usage")); - responseList.add(new UsageTypeResponse(NETWORK_BYTES_SENT, "Network Usage (Bytes Sent)")); - responseList.add(new UsageTypeResponse(NETWORK_BYTES_RECEIVED, "Network Usage (Bytes Received)")); - responseList.add(new UsageTypeResponse(VOLUME, "Volume Usage")); - responseList.add(new UsageTypeResponse(TEMPLATE, "Template Usage")); - responseList.add(new UsageTypeResponse(ISO, "ISO Usage")); - responseList.add(new UsageTypeResponse(SNAPSHOT, "Snapshot Usage")); - responseList.add(new UsageTypeResponse(SECURITY_GROUP, "Security Group Usage")); - responseList.add(new UsageTypeResponse(LOAD_BALANCER_POLICY, "Load Balancer Usage")); - responseList.add(new UsageTypeResponse(PORT_FORWARDING_RULE, "Port Forwarding Usage")); - responseList.add(new UsageTypeResponse(NETWORK_OFFERING, "Network Offering Usage")); - responseList.add(new UsageTypeResponse(VPN_USERS, "VPN users usage")); - responseList.add(new UsageTypeResponse(VM_DISK_IO_READ, "VM Disk usage(I/O Read)")); - responseList.add(new UsageTypeResponse(VM_DISK_IO_WRITE, "VM Disk usage(I/O Write)")); - responseList.add(new UsageTypeResponse(VM_DISK_BYTES_READ, "VM Disk usage(Bytes Read)")); - responseList.add(new UsageTypeResponse(VM_DISK_BYTES_WRITE, "VM Disk usage(Bytes Write)")); - responseList.add(new UsageTypeResponse(VM_SNAPSHOT, "VM Snapshot storage usage")); - responseList.add(new UsageTypeResponse(VOLUME_SECONDARY, "Volume on secondary storage usage")); - responseList.add(new UsageTypeResponse(VM_SNAPSHOT_ON_PRIMARY, "VM Snapshot on primary storage usage")); - responseList.add(new UsageTypeResponse(BACKUP, "Backup storage usage")); - responseList.add(new UsageTypeResponse(BUCKET, "Bucket storage usage")); - responseList.add(new UsageTypeResponse(NETWORK, "Network usage")); - responseList.add(new UsageTypeResponse(VPC, "VPC usage")); + responseList.add(new UsageTypeResponse(RUNNING_VM, "RUNNING_VM", "Running Vm Usage")); + responseList.add(new UsageTypeResponse(ALLOCATED_VM, "ALLOCATED_VM", "Allocated Vm Usage")); + responseList.add(new UsageTypeResponse(IP_ADDRESS, "IP_ADDRESS", "IP Address Usage")); + responseList.add(new UsageTypeResponse(NETWORK_BYTES_SENT, "NETWORK_BYTES_SENT", "Network Usage (Bytes Sent)")); + responseList.add(new UsageTypeResponse(NETWORK_BYTES_RECEIVED, "NETWORK_BYTES_RECEIVED", "Network Usage (Bytes Received)")); + responseList.add(new UsageTypeResponse(VOLUME, "VOLUME", "Volume Usage")); + responseList.add(new UsageTypeResponse(TEMPLATE, "TEMPLATE", "Template Usage")); + responseList.add(new UsageTypeResponse(ISO, "ISO", "ISO Usage")); + responseList.add(new UsageTypeResponse(SNAPSHOT, "SNAPSHOT", "Snapshot Usage")); + responseList.add(new UsageTypeResponse(SECURITY_GROUP, "SECURITY_GROUP", "Security Group Usage")); + responseList.add(new UsageTypeResponse(LOAD_BALANCER_POLICY, "LOAD_BALANCER_POLICY", "Load Balancer Usage")); + responseList.add(new UsageTypeResponse(PORT_FORWARDING_RULE, "PORT_FORWARDING_RULE", "Port Forwarding Usage")); + responseList.add(new UsageTypeResponse(NETWORK_OFFERING, "NETWORK_OFFERING", "Network Offering Usage")); + responseList.add(new UsageTypeResponse(VPN_USERS, "VPN_USERS", "VPN users usage")); + responseList.add(new UsageTypeResponse(VM_DISK_IO_READ, "VM_DISK_IO_READ", "VM Disk usage(I/O Read)")); + responseList.add(new UsageTypeResponse(VM_DISK_IO_WRITE, "VM_DISK_IO_WRITE", "VM Disk usage(I/O Write)")); + responseList.add(new UsageTypeResponse(VM_DISK_BYTES_READ, "VM_DISK_BYTES_READ", "VM Disk usage(Bytes Read)")); + responseList.add(new UsageTypeResponse(VM_DISK_BYTES_WRITE, "VM_DISK_BYTES_WRITE", "VM Disk usage(Bytes Write)")); + responseList.add(new UsageTypeResponse(VM_SNAPSHOT, "VM_SNAPSHOT", "VM Snapshot storage usage")); + responseList.add(new UsageTypeResponse(VOLUME_SECONDARY, "VOLUME_SECONDARY", "Volume on secondary storage usage")); + responseList.add(new UsageTypeResponse(VM_SNAPSHOT_ON_PRIMARY, "VM_SNAPSHOT_ON_PRIMARY", "VM Snapshot on primary storage usage")); + responseList.add(new UsageTypeResponse(BACKUP, "BACKUP", "Backup storage usage")); + responseList.add(new UsageTypeResponse(BUCKET, "BUCKET", "Bucket storage usage")); + responseList.add(new UsageTypeResponse(NETWORK, "NETWORK", "Network usage")); + responseList.add(new UsageTypeResponse(VPC, "VPC", "VPC usage")); return responseList; } } diff --git a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java b/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java index 170193570cf1..d49120d44919 100644 --- a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java +++ b/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java @@ -18,9 +18,12 @@ // package org.apache.cloudstack.user; -import com.cloud.configuration.Resource; import org.apache.cloudstack.api.InternalIdentity; +import com.cloud.configuration.Resource; + +import java.util.Date; + /** * an interface defining an {code}AutoClosable{code} reservation object */ @@ -33,5 +36,11 @@ Resource.ResourceType getResourceType(); + Long getResourceId(); + + String getTag(); + Long getReservedAmount(); + + Date getCreated(); } diff --git a/api/src/main/resources/META-INF/cloudstack/api-config/spring-api-config-context.xml b/api/src/main/resources/META-INF/cloudstack/api-config/spring-api-config-context.xml index 5ea32464ee9b..12d3c2361acd 100644 --- a/api/src/main/resources/META-INF/cloudstack/api-config/spring-api-config-context.xml +++ b/api/src/main/resources/META-INF/cloudstack/api-config/spring-api-config-context.xml @@ -28,5 +28,5 @@ > - + diff --git a/api/src/main/resources/META-INF/cloudstack/api-planner/spring-api-planner-context.xml b/api/src/main/resources/META-INF/cloudstack/api-planner/spring-api-planner-context.xml index 8523daf1d216..b614e362950b 100644 --- a/api/src/main/resources/META-INF/cloudstack/api-planner/spring-api-planner-context.xml +++ b/api/src/main/resources/META-INF/cloudstack/api-planner/spring-api-planner-context.xml @@ -30,5 +30,5 @@ - + diff --git a/api/src/test/java/com/cloud/storage/StorageTest.java b/api/src/test/java/com/cloud/storage/StorageTest.java index 76fd5c5d3a4c..2bcc28e2b4b6 100644 --- a/api/src/test/java/com/cloud/storage/StorageTest.java +++ b/api/src/test/java/com/cloud/storage/StorageTest.java @@ -74,4 +74,13 @@ public void supportsOverProvisioningTestAllStoragePoolTypes() { Assert.assertTrue(StoragePoolType.DatastoreCluster.supportsOverProvisioning()); Assert.assertTrue(StoragePoolType.Linstor.supportsOverProvisioning()); } + + @Test + public void equalityTest() { + StoragePoolType t1 = StoragePoolType.NetworkFilesystem; + StoragePoolType t2 = StoragePoolType.NetworkFilesystem; + Assert.assertTrue(t1 == StoragePoolType.NetworkFilesystem); + Assert.assertTrue(t1.equals(StoragePoolType.NetworkFilesystem)); + Assert.assertFalse(t1.equals(StoragePoolType.EXT)); + } } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmdTest.java index d26065da21c3..365646de7a33 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmdTest.java @@ -22,7 +22,8 @@ import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -38,7 +39,7 @@ import com.cloud.user.User; public class CreateAccountCmdTest { - public static final Logger s_logger = Logger.getLogger(CreateAccountCmdTest.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); @Mock private AccountService accountService; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/CreateASNRangeCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/CreateASNRangeCmdTest.java new file mode 100644 index 000000000000..603cda2040d0 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/CreateASNRangeCmdTest.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.bgp; + +import com.cloud.bgp.ASNumberRange; +import com.cloud.bgp.BGPService; + +import org.apache.cloudstack.api.ResponseGenerator; +import org.apache.cloudstack.api.response.ASNRangeResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class CreateASNRangeCmdTest { + + BGPService bgpService = Mockito.spy(BGPService.class); + ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); + + @Test + public void testCreateASNRangeCmd() { + Long zoneId = 1L; + Long startASNumber = 110000L; + Long endASNumber = 120000L; + + CreateASNRangeCmd cmd = new CreateASNRangeCmd(); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd, "startASNumber", startASNumber); + ReflectionTestUtils.setField(cmd, "endASNumber", endASNumber); + ReflectionTestUtils.setField(cmd,"bgpService", bgpService); + ReflectionTestUtils.setField(cmd,"_responseGenerator", _responseGenerator); + + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(startASNumber, cmd.getStartASNumber()); + Assert.assertEquals(endASNumber, cmd.getEndASNumber()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + + ASNumberRange asnRange = Mockito.mock(ASNumberRange.class); + Mockito.when(bgpService.createASNumberRange(zoneId, startASNumber, endASNumber)).thenReturn(asnRange); + + ASNRangeResponse response = Mockito.mock(ASNRangeResponse.class); + Mockito.when(_responseGenerator.createASNumberRangeResponse(asnRange)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/DeleteASNRangeCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/DeleteASNRangeCmdTest.java new file mode 100644 index 000000000000..2abcf736c5b5 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/DeleteASNRangeCmdTest.java @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.bgp; + +import com.cloud.bgp.BGPService; + +import org.apache.cloudstack.api.response.SuccessResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class DeleteASNRangeCmdTest { + + BGPService bgpService = Mockito.spy(BGPService.class); + + @Test + public void testDeleteASNRangeCmd() { + Long id = 200L; + + DeleteASNRangeCmd cmd = new DeleteASNRangeCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd,"bgpService", bgpService); + + Assert.assertEquals(id, cmd.getId()); + + Mockito.when(bgpService.deleteASRange(id)).thenReturn(true); + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Object response = cmd.getResponseObject(); + Assert.assertTrue(response instanceof SuccessResponse); + + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/ListASNRangesCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/ListASNRangesCmdTest.java new file mode 100644 index 000000000000..7f49c61a6936 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/ListASNRangesCmdTest.java @@ -0,0 +1,75 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.bgp; + +import com.cloud.bgp.ASNumberRange; +import com.cloud.bgp.BGPService; + +import org.apache.cloudstack.api.ResponseGenerator; +import org.apache.cloudstack.api.response.ASNRangeResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class ListASNRangesCmdTest { + + BGPService bgpService = Mockito.spy(BGPService.class); + ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); + + @Test + public void testListASNRangesCmdTest() { + Long zoneId = 1L; + + ListASNRangesCmd cmd = new ListASNRangesCmd(); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd,"bgpService", bgpService); + ReflectionTestUtils.setField(cmd,"_responseGenerator", _responseGenerator); + + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + + List ranges = new ArrayList<>(); + ASNumberRange asnRange = Mockito.mock(ASNumberRange.class); + ranges.add(asnRange); + + ASNRangeResponse asnRangeResponse = Mockito.mock(ASNRangeResponse.class); + Mockito.when(_responseGenerator.createASNumberRangeResponse(asnRange)).thenReturn(asnRangeResponse); + + Mockito.when(bgpService.listASNumberRanges(zoneId)).thenReturn(ranges); + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Object response = cmd.getResponseObject(); + Assert.assertTrue(response instanceof ListResponse); + ListResponse listResponse = (ListResponse) response; + Assert.assertEquals(1L, (long) listResponse.getCount()); + Assert.assertTrue(listResponse.getResponses().get(0) instanceof ASNRangeResponse); + ASNRangeResponse firstResponse = (ASNRangeResponse) listResponse.getResponses().get(0); + Assert.assertEquals(asnRangeResponse, firstResponse); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/ReleaseASNumberCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/ReleaseASNumberCmdTest.java new file mode 100644 index 000000000000..1b80e5bff7f0 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/bgp/ReleaseASNumberCmdTest.java @@ -0,0 +1,61 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.bgp; + +import com.cloud.bgp.BGPService; +import com.cloud.utils.Pair; + +import org.apache.cloudstack.api.response.SuccessResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ReleaseASNumberCmdTest { + + BGPService bgpService = Mockito.spy(BGPService.class); + + @Test + public void testReleaseASNumberCmd() { + Long zoneId = 1L; + Long asNumber = 10000L; + + ReleaseASNumberCmd cmd = new ReleaseASNumberCmd(); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd, "asNumber", asNumber); + ReflectionTestUtils.setField(cmd,"bgpService", bgpService); + + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(asNumber, cmd.getAsNumber()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + + Pair resultPair = Mockito.mock(Pair.class); + Mockito.when(resultPair.first()).thenReturn(true); + Mockito.when(bgpService.releaseASNumber(zoneId, asNumber, false)).thenReturn(resultPair); + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Object response = cmd.getResponseObject(); + Assert.assertTrue(response instanceof SuccessResponse); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java new file mode 100644 index 000000000000..3c9d4cb67ae1 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java @@ -0,0 +1,77 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.domain; + +import java.util.List; + +import org.apache.cloudstack.api.response.DomainResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.ResourceLimitService; + +@RunWith(MockitoJUnitRunner.class) +public class ListDomainsCmdTest { + + @Mock + ResourceLimitService resourceLimitService; + + + @Test + public void testGetShowIcon() { + ListDomainsCmd cmd = new ListDomainsCmd(); + ReflectionTestUtils.setField(cmd, "showIcon", null); + Assert.assertFalse(cmd.getShowIcon()); + ReflectionTestUtils.setField(cmd, "showIcon", false); + Assert.assertFalse(cmd.getShowIcon()); + ReflectionTestUtils.setField(cmd, "showIcon", true); + Assert.assertTrue(cmd.getShowIcon()); + } + + @Test + public void testGetTag() { + ListDomainsCmd cmd = new ListDomainsCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } + + @Test + public void testUpdateDomainResponseNoDomains() { + ListDomainsCmd cmd = new ListDomainsCmd(); + cmd._resourceLimitService = resourceLimitService; + cmd.updateDomainResponse(null); + Mockito.verify(resourceLimitService, Mockito.never()).updateTaggedResourceLimitsAndCountsForDomains(Mockito.anyList(), Mockito.anyString()); + } + + @Test + public void testUpdateDomainResponseWithDomains() { + ListDomainsCmd cmd = new ListDomainsCmd(); + cmd._resourceLimitService = resourceLimitService; + ReflectionTestUtils.setField(cmd, "tag", "abc"); + cmd.updateDomainResponse(List.of(Mockito.mock(DomainResponse.class))); + Mockito.verify(resourceLimitService, Mockito.times(1)).updateTaggedResourceLimitsAndCountsForDomains(Mockito.any(), Mockito.any()); + } + +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForGuestNetworkCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForGuestNetworkCmdTest.java new file mode 100644 index 000000000000..e1393e316993 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForGuestNetworkCmdTest.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import com.cloud.event.EventTypes; + +import org.apache.cloudstack.api.response.Ipv4SubnetForGuestNetworkResponse; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class CreateIpv4SubnetForGuestNetworkCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testCreateIpv4SubnetForGuestNetworkCmd() { + Long parentId = 1L; + String subnet = "192.168.1.0/24"; + Integer cidrSize = 26; + + CreateIpv4SubnetForGuestNetworkCmd cmd = new CreateIpv4SubnetForGuestNetworkCmd(); + ReflectionTestUtils.setField(cmd, "parentId", parentId); + ReflectionTestUtils.setField(cmd, "subnet", subnet); + ReflectionTestUtils.setField(cmd, "cidrSize", cidrSize); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(parentId, cmd.getParentId()); + Assert.assertEquals(subnet, cmd.getSubnet()); + Assert.assertEquals(cidrSize, cmd.getCidrSize()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_IP4_GUEST_SUBNET_CREATE, cmd.getEventType()); + Assert.assertEquals(String.format("Creating guest IPv4 subnet %s in zone subnet=%s", subnet, parentId), cmd.getEventDescription()); + + Ipv4GuestSubnetNetworkMap ipv4GuestSubnetNetworkMap = Mockito.mock(Ipv4GuestSubnetNetworkMap.class); + Mockito.when(routedIpv4Manager.createIpv4SubnetForGuestNetwork(cmd)).thenReturn(ipv4GuestSubnetNetworkMap); + + Ipv4SubnetForGuestNetworkResponse response = Mockito.mock(Ipv4SubnetForGuestNetworkResponse.class); + Mockito.when(routedIpv4Manager.createIpv4SubnetForGuestNetworkResponse(ipv4GuestSubnetNetworkMap)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForZoneCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForZoneCmdTest.java new file mode 100644 index 000000000000..51c1eb986c47 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForZoneCmdTest.java @@ -0,0 +1,75 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import com.cloud.event.EventTypes; + +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class CreateIpv4SubnetForZoneCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testCreateIpv4SubnetForZoneCmd() { + Long zoneId = 1L; + String subnet = "192.168.1.0/24"; + String accountName = "user"; + Long projectId = 10L; + Long domainId = 11L; + + CreateIpv4SubnetForZoneCmd cmd = new CreateIpv4SubnetForZoneCmd(); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd, "subnet", subnet); + ReflectionTestUtils.setField(cmd, "accountName", accountName); + ReflectionTestUtils.setField(cmd,"projectId", projectId); + ReflectionTestUtils.setField(cmd,"domainId", domainId); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(subnet, cmd.getSubnet()); + Assert.assertEquals(accountName, cmd.getAccountName()); + Assert.assertEquals(projectId, cmd.getProjectId()); + Assert.assertEquals(domainId, cmd.getDomainId()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_ZONE_IP4_SUBNET_CREATE, cmd.getEventType()); + Assert.assertEquals(String.format("Creating guest IPv4 subnet %s for zone=%s", subnet, zoneId), cmd.getEventDescription()); + + DataCenterIpv4GuestSubnet zoneSubnet = Mockito.mock(DataCenterIpv4GuestSubnet.class); + Mockito.when(routedIpv4Manager.createDataCenterIpv4GuestSubnet(cmd)).thenReturn(zoneSubnet); + + DataCenterIpv4SubnetResponse response = Mockito.mock(DataCenterIpv4SubnetResponse.class); + Mockito.when(routedIpv4Manager.createDataCenterIpv4SubnetResponse(zoneSubnet)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DedicateIpv4SubnetForZoneCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DedicateIpv4SubnetForZoneCmdTest.java new file mode 100644 index 000000000000..7db77098b233 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DedicateIpv4SubnetForZoneCmdTest.java @@ -0,0 +1,72 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import com.cloud.event.EventTypes; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class DedicateIpv4SubnetForZoneCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testDedicateIpv4SubnetForZoneCmd() { + Long id = 1L; + String accountName = "user"; + Long projectId = 10L; + Long domainId = 11L; + + DedicateIpv4SubnetForZoneCmd cmd = new DedicateIpv4SubnetForZoneCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd, "accountName", accountName); + ReflectionTestUtils.setField(cmd,"projectId", projectId); + ReflectionTestUtils.setField(cmd,"domainId", domainId); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(accountName, cmd.getAccountName()); + Assert.assertEquals(projectId, cmd.getProjectId()); + Assert.assertEquals(domainId, cmd.getDomainId()); + + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_ZONE_IP4_SUBNET_DEDICATE, cmd.getEventType()); + Assert.assertEquals(String.format("Dedicating zone IPv4 subnet %s", id), cmd.getEventDescription()); + + DataCenterIpv4GuestSubnet zoneSubnet = Mockito.mock(DataCenterIpv4GuestSubnet.class); + Mockito.when(routedIpv4Manager.dedicateDataCenterIpv4GuestSubnet(cmd)).thenReturn(zoneSubnet); + + DataCenterIpv4SubnetResponse response = Mockito.mock(DataCenterIpv4SubnetResponse.class); + Mockito.when(routedIpv4Manager.createDataCenterIpv4SubnetResponse(zoneSubnet)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForGuestNetworkCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForGuestNetworkCmdTest.java new file mode 100644 index 000000000000..a4af5ddf748f --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForGuestNetworkCmdTest.java @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import com.cloud.event.EventTypes; + +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class DeleteIpv4SubnetForGuestNetworkCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testDeleteIpv4SubnetForGuestNetworkCmd() { + Long id = 1L; + + DeleteIpv4SubnetForGuestNetworkCmd cmd = new DeleteIpv4SubnetForGuestNetworkCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_IP4_GUEST_SUBNET_DELETE, cmd.getEventType()); + Assert.assertEquals(String.format("Deleting guest IPv4 subnet %s", id), cmd.getEventDescription()); + + Mockito.when(routedIpv4Manager.deleteIpv4SubnetForGuestNetwork(cmd)).thenReturn(true); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertTrue(cmd.getResponseObject() instanceof SuccessResponse); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForZoneCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForZoneCmdTest.java new file mode 100644 index 000000000000..7af173f09d96 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForZoneCmdTest.java @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import com.cloud.event.EventTypes; + +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class DeleteIpv4SubnetForZoneCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testDeleteIpv4SubnetForZoneCmd() { + Long id = 1L; + + DeleteIpv4SubnetForZoneCmd cmd = new DeleteIpv4SubnetForZoneCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_ZONE_IP4_SUBNET_DELETE, cmd.getEventType()); + Assert.assertEquals(String.format("Deleting zone IPv4 subnet %s", id), cmd.getEventDescription()); + + Mockito.when(routedIpv4Manager.deleteDataCenterIpv4GuestSubnet(cmd)).thenReturn(true); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertTrue(cmd.getResponseObject() instanceof SuccessResponse); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForGuestNetworkCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForGuestNetworkCmdTest.java new file mode 100644 index 000000000000..cbfe34f774ac --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForGuestNetworkCmdTest.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.api.response.Ipv4SubnetForGuestNetworkResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Arrays; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class ListIpv4SubnetsForGuestNetworkCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testListIpv4SubnetsForGuestNetworkCmd() { + Long id = 1L; + Long zoneId = 2L; + Long parentId = 2L; + String subnet = "192.168.1.0/24"; + Long networkId = 10L; + Long vpcId = 11L; + + ListIpv4SubnetsForGuestNetworkCmd cmd = new ListIpv4SubnetsForGuestNetworkCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd, "subnet", subnet); + ReflectionTestUtils.setField(cmd, "parentId", parentId); + ReflectionTestUtils.setField(cmd,"networkId", networkId); + ReflectionTestUtils.setField(cmd,"vpcId", vpcId); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(subnet, cmd.getSubnet()); + Assert.assertEquals(networkId, cmd.getNetworkId()); + Assert.assertEquals(vpcId, cmd.getVpcId()); + Assert.assertEquals(parentId, cmd.getParentId()); + + Assert.assertEquals(0L, cmd.getEntityOwnerId()); + + Ipv4GuestSubnetNetworkMap ipv4GuestSubnetNetworkMap = Mockito.mock(Ipv4GuestSubnetNetworkMap.class); + List ipv4GuestSubnetNetworkMaps = Arrays.asList(ipv4GuestSubnetNetworkMap); + Mockito.when(routedIpv4Manager.listIpv4GuestSubnetsForGuestNetwork(cmd)).thenReturn(ipv4GuestSubnetNetworkMaps); + + Ipv4SubnetForGuestNetworkResponse response = Mockito.mock(Ipv4SubnetForGuestNetworkResponse.class); + Mockito.when(routedIpv4Manager.createIpv4SubnetForGuestNetworkResponse(ipv4GuestSubnetNetworkMap)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertTrue(cmd.getResponseObject() instanceof ListResponse); + ListResponse listResponse = (ListResponse) cmd.getResponseObject(); + Assert.assertEquals(1, (int) listResponse.getCount()); + Assert.assertEquals(response, listResponse.getResponses().get(0)); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForZoneCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForZoneCmdTest.java new file mode 100644 index 000000000000..2c7a246f70f8 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForZoneCmdTest.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Arrays; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class ListIpv4SubnetsForZoneCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testListIpv4SubnetsForZoneCmd() { + Long id = 1L; + Long zoneId = 2L; + String subnet = "192.168.1.0/24"; + String accountName = "user"; + Long projectId = 10L; + Long domainId = 11L; + + ListIpv4SubnetsForZoneCmd cmd = new ListIpv4SubnetsForZoneCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd, "subnet", subnet); + ReflectionTestUtils.setField(cmd, "accountName", accountName); + ReflectionTestUtils.setField(cmd,"projectId", projectId); + ReflectionTestUtils.setField(cmd,"domainId", domainId); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(subnet, cmd.getSubnet()); + Assert.assertEquals(accountName, cmd.getAccountName()); + Assert.assertEquals(projectId, cmd.getProjectId()); + Assert.assertEquals(domainId, cmd.getDomainId()); + + Assert.assertEquals(0L, cmd.getEntityOwnerId()); + + DataCenterIpv4GuestSubnet zoneSubnet = Mockito.mock(DataCenterIpv4GuestSubnet.class); + List zoneSubnets = Arrays.asList(zoneSubnet); + Mockito.when(routedIpv4Manager.listDataCenterIpv4GuestSubnets(cmd)).thenReturn(zoneSubnets); + + DataCenterIpv4SubnetResponse response = Mockito.mock(DataCenterIpv4SubnetResponse.class); + Mockito.when(routedIpv4Manager.createDataCenterIpv4SubnetResponse(zoneSubnet)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertTrue(cmd.getResponseObject() instanceof ListResponse); + ListResponse listResponse = (ListResponse) cmd.getResponseObject(); + Assert.assertEquals(1, (int) listResponse.getCount()); + Assert.assertEquals(response, listResponse.getResponses().get(0)); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedIpv4SubnetForZoneCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedIpv4SubnetForZoneCmdTest.java new file mode 100644 index 000000000000..9ce9a4f9464f --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedIpv4SubnetForZoneCmdTest.java @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import com.cloud.event.EventTypes; +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ReleaseDedicatedIpv4SubnetForZoneCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testReleaseDedicatedIpv4SubnetForZoneCmd() { + Long id = 1L; + + ReleaseDedicatedIpv4SubnetForZoneCmd cmd = new ReleaseDedicatedIpv4SubnetForZoneCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_ZONE_IP4_SUBNET_RELEASE, cmd.getEventType()); + Assert.assertEquals(String.format("Releasing a dedicated zone IPv4 subnet %s", id), cmd.getEventDescription()); + + DataCenterIpv4GuestSubnet zoneSubnet = Mockito.mock(DataCenterIpv4GuestSubnet.class); + Mockito.when(routedIpv4Manager.releaseDedicatedDataCenterIpv4GuestSubnet(cmd)).thenReturn(zoneSubnet); + + DataCenterIpv4SubnetResponse response = Mockito.mock(DataCenterIpv4SubnetResponse.class); + Mockito.when(routedIpv4Manager.createDataCenterIpv4SubnetResponse(zoneSubnet)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/UpdateIpv4SubnetForZoneCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/UpdateIpv4SubnetForZoneCmdTest.java new file mode 100644 index 000000000000..cdb9cce22d83 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/UpdateIpv4SubnetForZoneCmdTest.java @@ -0,0 +1,66 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network; + +import com.cloud.event.EventTypes; + +import org.apache.cloudstack.api.response.DataCenterIpv4SubnetResponse; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateIpv4SubnetForZoneCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testUpdateIpv4SubnetForZoneCmd() { + Long id = 1L; + String subnet = "192.168.1.0/24"; + + UpdateIpv4SubnetForZoneCmd cmd = new UpdateIpv4SubnetForZoneCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd, "subnet", subnet); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(subnet, cmd.getSubnet()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_ZONE_IP4_SUBNET_UPDATE, cmd.getEventType()); + Assert.assertEquals(String.format("Updating zone IPv4 subnet %s", id), cmd.getEventDescription()); + + DataCenterIpv4GuestSubnet zoneSubnet = Mockito.mock(DataCenterIpv4GuestSubnet.class); + Mockito.when(routedIpv4Manager.updateDataCenterIpv4GuestSubnet(cmd)).thenReturn(zoneSubnet); + + DataCenterIpv4SubnetResponse response = Mockito.mock(DataCenterIpv4SubnetResponse.class); + Mockito.when(routedIpv4Manager.createDataCenterIpv4SubnetResponse(zoneSubnet)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForNetworkCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForNetworkCmdTest.java new file mode 100644 index 000000000000..28ddad17afe5 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForNetworkCmdTest.java @@ -0,0 +1,74 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import com.cloud.event.EventTypes; + +import com.cloud.network.Network; +import org.apache.cloudstack.api.ResponseGenerator; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.response.NetworkResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Arrays; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class ChangeBgpPeersForNetworkCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); + + @Test + public void testChangeBgpPeersForNetworkCmd() { + Long networkId = 10L; + List bgpPeerIds = Arrays.asList(20L, 21L); + + ChangeBgpPeersForNetworkCmd cmd = new ChangeBgpPeersForNetworkCmd(); + ReflectionTestUtils.setField(cmd, "networkId", networkId); + ReflectionTestUtils.setField(cmd, "bgpPeerIds", bgpPeerIds); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + ReflectionTestUtils.setField(cmd,"_responseGenerator", _responseGenerator); + + Assert.assertEquals(networkId, cmd.getNetworkId()); + Assert.assertEquals(bgpPeerIds, cmd.getBgpPeerIds()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_NETWORK_BGP_PEER_UPDATE, cmd.getEventType()); + Assert.assertEquals(String.format("Changing Bgp Peers for network %s", networkId), cmd.getEventDescription()); + + Network network = Mockito.mock(Network.class); + Mockito.when(routedIpv4Manager.changeBgpPeersForNetwork(cmd)).thenReturn(network); + + NetworkResponse response = Mockito.mock(NetworkResponse.class); + Mockito.when(_responseGenerator.createNetworkResponse(ResponseObject.ResponseView.Full, network)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForVpcCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForVpcCmdTest.java new file mode 100644 index 000000000000..96eb1f020de2 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForVpcCmdTest.java @@ -0,0 +1,74 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import com.cloud.event.EventTypes; + +import com.cloud.network.vpc.Vpc; +import org.apache.cloudstack.api.ResponseGenerator; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.response.VpcResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Arrays; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class ChangeBgpPeersForVpcCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); + + @Test + public void testChangeBgpPeersForVpcCmd() { + Long VpcId = 10L; + List bgpPeerIds = Arrays.asList(20L, 21L); + + ChangeBgpPeersForVpcCmd cmd = new ChangeBgpPeersForVpcCmd(); + ReflectionTestUtils.setField(cmd, "vpcId", VpcId); + ReflectionTestUtils.setField(cmd, "bgpPeerIds", bgpPeerIds); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + ReflectionTestUtils.setField(cmd,"_responseGenerator", _responseGenerator); + + Assert.assertEquals(VpcId, cmd.getVpcId()); + Assert.assertEquals(bgpPeerIds, cmd.getBgpPeerIds()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_VPC_BGP_PEER_UPDATE, cmd.getEventType()); + Assert.assertEquals(String.format("Changing Bgp Peers for VPC %s", VpcId), cmd.getEventDescription()); + + Vpc Vpc = Mockito.mock(Vpc.class); + Mockito.when(routedIpv4Manager.changeBgpPeersForVpc(cmd)).thenReturn(Vpc); + + VpcResponse response = Mockito.mock(VpcResponse.class); + Mockito.when(_responseGenerator.createVpcResponse(ResponseObject.ResponseView.Full, Vpc)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/CreateBgpPeerCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/CreateBgpPeerCmdTest.java new file mode 100644 index 000000000000..0d802bf36199 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/CreateBgpPeerCmdTest.java @@ -0,0 +1,85 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import com.cloud.event.EventTypes; + +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class CreateBgpPeerCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testCreateBgpPeerCmd() { + Long zoneId = 1L; + String accountName = "user"; + Long projectId = 10L; + Long domainId = 11L; + String ip4Address = "ip4-address"; + String ip6Address = "ip6-address"; + Long peerAsNumber = 15000L; + String peerPassword = "peer-password"; + + CreateBgpPeerCmd cmd = new CreateBgpPeerCmd(); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd, "ip4Address", ip4Address); + ReflectionTestUtils.setField(cmd, "ip6Address", ip6Address); + ReflectionTestUtils.setField(cmd, "asNumber", peerAsNumber); + ReflectionTestUtils.setField(cmd, "password", peerPassword); + ReflectionTestUtils.setField(cmd, "accountName", accountName); + ReflectionTestUtils.setField(cmd,"projectId", projectId); + ReflectionTestUtils.setField(cmd,"domainId", domainId); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(ip4Address, cmd.getIp4Address()); + Assert.assertEquals(ip6Address, cmd.getIp6Address()); + Assert.assertEquals(peerAsNumber, cmd.getAsNumber()); + Assert.assertEquals(peerPassword, cmd.getPassword()); + Assert.assertEquals(accountName, cmd.getAccountName()); + Assert.assertEquals(projectId, cmd.getProjectId()); + Assert.assertEquals(domainId, cmd.getDomainId()); + + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_BGP_PEER_CREATE, cmd.getEventType()); + Assert.assertEquals(String.format("Creating Bgp Peer %s for zone=%s", peerAsNumber, zoneId), cmd.getEventDescription()); + + BgpPeer bgpPeer = Mockito.mock(BgpPeer.class); + Mockito.when(routedIpv4Manager.createBgpPeer(cmd)).thenReturn(bgpPeer); + + BgpPeerResponse response = Mockito.mock(BgpPeerResponse.class); + Mockito.when(routedIpv4Manager.createBgpPeerResponse(bgpPeer)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/DedicateBgpPeerCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/DedicateBgpPeerCmdTest.java new file mode 100644 index 000000000000..f3ae007da285 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/DedicateBgpPeerCmdTest.java @@ -0,0 +1,72 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import com.cloud.event.EventTypes; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class DedicateBgpPeerCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testDedicateBgpPeerCmd() { + Long id = 1L; + String accountName = "user"; + Long projectId = 10L; + Long domainId = 11L; + + DedicateBgpPeerCmd cmd = new DedicateBgpPeerCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd, "accountName", accountName); + ReflectionTestUtils.setField(cmd,"projectId", projectId); + ReflectionTestUtils.setField(cmd,"domainId", domainId); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(accountName, cmd.getAccountName()); + Assert.assertEquals(projectId, cmd.getProjectId()); + Assert.assertEquals(domainId, cmd.getDomainId()); + + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_BGP_PEER_DEDICATE, cmd.getEventType()); + Assert.assertEquals(String.format("Dedicating Bgp Peer %s", id), cmd.getEventDescription()); + + BgpPeer bgpPeer = Mockito.mock(BgpPeer.class); + Mockito.when(routedIpv4Manager.dedicateBgpPeer(cmd)).thenReturn(bgpPeer); + + BgpPeerResponse response = Mockito.mock(BgpPeerResponse.class); + Mockito.when(routedIpv4Manager.createBgpPeerResponse(bgpPeer)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/DeleteBgpPeerCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/DeleteBgpPeerCmdTest.java new file mode 100644 index 000000000000..5e747188fda3 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/DeleteBgpPeerCmdTest.java @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import com.cloud.event.EventTypes; + +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class DeleteBgpPeerCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testDeleteBgpPeerCmd() { + Long id = 1L; + + DeleteBgpPeerCmd cmd = new DeleteBgpPeerCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_BGP_PEER_DELETE, cmd.getEventType()); + Assert.assertEquals(String.format("Deleting Bgp Peer %s", id), cmd.getEventDescription()); + + Mockito.when(routedIpv4Manager.deleteBgpPeer(cmd)).thenReturn(true); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertTrue(cmd.getResponseObject() instanceof SuccessResponse); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ListBgpPeersCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ListBgpPeersCmdTest.java new file mode 100644 index 000000000000..cb2027951adc --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ListBgpPeersCmdTest.java @@ -0,0 +1,96 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Arrays; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class ListBgpPeersCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testIsDedicated() { + ListBgpPeersCmd cmd = new ListBgpPeersCmd(); + + Assert.assertNull(cmd.getDedicated()); + + ReflectionTestUtils.setField(cmd, "isDedicated", Boolean.TRUE); + Assert.assertTrue(cmd.getDedicated()); + + ReflectionTestUtils.setField(cmd, "isDedicated", Boolean.FALSE); + Assert.assertFalse(cmd.getDedicated()); + } + + @Test + public void testListBgpPeersCmd() { + Long id = 1L; + Long zoneId = 2L; + Long peerAsNumber = 15000L; + String accountName = "user"; + Long projectId = 10L; + Long domainId = 11L; + + ListBgpPeersCmd cmd = new ListBgpPeersCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd, "asNumber", peerAsNumber); + ReflectionTestUtils.setField(cmd, "accountName", accountName); + ReflectionTestUtils.setField(cmd,"projectId", projectId); + ReflectionTestUtils.setField(cmd,"domainId", domainId); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(peerAsNumber, cmd.getAsNumber()); + Assert.assertEquals(accountName, cmd.getAccountName()); + Assert.assertEquals(projectId, cmd.getProjectId()); + Assert.assertEquals(domainId, cmd.getDomainId()); + + Assert.assertEquals(0L, cmd.getEntityOwnerId()); + + BgpPeer bgpPeer = Mockito.mock(BgpPeer.class); + List bgpPeers = Arrays.asList(bgpPeer); + Mockito.when(routedIpv4Manager.listBgpPeers(cmd)).thenReturn(bgpPeers); + + BgpPeerResponse response = Mockito.mock(BgpPeerResponse.class); + Mockito.when(routedIpv4Manager.createBgpPeerResponse(bgpPeer)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertTrue(cmd.getResponseObject() instanceof ListResponse); + ListResponse listResponse = (ListResponse) cmd.getResponseObject(); + Assert.assertEquals(1, (int) listResponse.getCount()); + Assert.assertEquals(response, listResponse.getResponses().get(0)); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ReleaseDedicatedBgpPeerCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ReleaseDedicatedBgpPeerCmdTest.java new file mode 100644 index 000000000000..8c55c4a73479 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/ReleaseDedicatedBgpPeerCmdTest.java @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import com.cloud.event.EventTypes; +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ReleaseDedicatedBgpPeerCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testReleaseDedicatedBgpPeerCmd() { + Long id = 1L; + + ReleaseDedicatedBgpPeerCmd cmd = new ReleaseDedicatedBgpPeerCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_BGP_PEER_RELEASE, cmd.getEventType()); + Assert.assertEquals(String.format("Releasing a dedicated Bgp Peer %s", id), cmd.getEventDescription()); + + BgpPeer bgpPeer = Mockito.mock(BgpPeer.class); + Mockito.when(routedIpv4Manager.releaseDedicatedBgpPeer(cmd)).thenReturn(bgpPeer); + + BgpPeerResponse response = Mockito.mock(BgpPeerResponse.class); + Mockito.when(routedIpv4Manager.createBgpPeerResponse(bgpPeer)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/UpdateBgpPeerCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/UpdateBgpPeerCmdTest.java new file mode 100644 index 000000000000..003944c61474 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/network/bgp/UpdateBgpPeerCmdTest.java @@ -0,0 +1,87 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.network.bgp; + +import com.cloud.event.EventTypes; + +import org.apache.cloudstack.api.response.BgpPeerResponse; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateBgpPeerCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + @Test + public void testUpdateBgpPeerCmd() { + Long id = 1L; + String ip4Address = "ip4-address"; + String ip6Address = "ip6-address"; + Long peerAsNumber = 15000L; + String peerPassword = "peer-password"; + + UpdateBgpPeerCmd cmd = new UpdateBgpPeerCmd(); + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd, "ip4Address", ip4Address); + ReflectionTestUtils.setField(cmd, "ip6Address", ip6Address); + ReflectionTestUtils.setField(cmd, "asNumber", peerAsNumber); + ReflectionTestUtils.setField(cmd, "password", peerPassword); + ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); + + Assert.assertEquals(id, cmd.getId()); + Assert.assertEquals(ip4Address, cmd.getIp4Address()); + Assert.assertEquals(ip6Address, cmd.getIp6Address()); + Assert.assertEquals(peerAsNumber, cmd.getAsNumber()); + Assert.assertEquals(peerPassword, cmd.getPassword()); + Assert.assertEquals(1L, cmd.getEntityOwnerId()); + Assert.assertEquals(EventTypes.EVENT_BGP_PEER_UPDATE, cmd.getEventType()); + Assert.assertEquals(String.format("Updating Bgp Peer %s", id), cmd.getEventDescription()); + + BgpPeer bgpPeer = Mockito.mock(BgpPeer.class); + Mockito.when(routedIpv4Manager.updateBgpPeer(cmd)).thenReturn(bgpPeer); + + BgpPeerResponse response = Mockito.mock(BgpPeerResponse.class); + Mockito.when(routedIpv4Manager.createBgpPeerResponse(bgpPeer)).thenReturn(response); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(response, cmd.getResponseObject()); + } + + @Test + public void testUpdateBgpPeerCleanupDetails() { + UpdateBgpPeerCmd cmd = new UpdateBgpPeerCmd(); + Assert.assertFalse(cmd.isCleanupDetails()); + + ReflectionTestUtils.setField(cmd, "cleanupDetails", Boolean.TRUE); + Assert.assertTrue(cmd.isCleanupDetails()); + + ReflectionTestUtils.setField(cmd, "cleanupDetails", Boolean.FALSE); + Assert.assertFalse(cmd.isCleanupDetails()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java index 8b95456a84c2..ef10ebff4678 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java @@ -23,14 +23,16 @@ import org.mockito.InjectMocks; import org.springframework.test.util.ReflectionTestUtils; + public class CreateNetworkOfferingCmdTest { @InjectMocks private CreateNetworkOfferingCmd createNetworkOfferingCmd = new CreateNetworkOfferingCmd(); + String netName = "network"; + @Test public void createVpcNtwkOffWithEmptyDisplayText() { - String netName = "network"; ReflectionTestUtils.setField(createNetworkOfferingCmd, "networkOfferingName", netName); Assert.assertEquals(createNetworkOfferingCmd.getDisplayText(), netName); } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java index 717b5c3262d8..6daa5de07cbf 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) @@ -37,4 +37,22 @@ public void testGetDisplayTextWhenEmpty() { Assert.assertEquals(createServiceOfferingCmd.getDisplayText(), netName); } + @Test + public void testIsPurgeResourcesNoOrNullValue() { + Assert.assertFalse(createServiceOfferingCmd.isPurgeResources()); + ReflectionTestUtils.setField(createServiceOfferingCmd, "purgeResources", false); + Assert.assertFalse(createServiceOfferingCmd.isPurgeResources()); + } + + @Test + public void testIsPurgeResourcesFalse() { + ReflectionTestUtils.setField(createServiceOfferingCmd, "purgeResources", false); + Assert.assertFalse(createServiceOfferingCmd.isPurgeResources()); + } + + @Test + public void testIsPurgeResourcesTrue() { + ReflectionTestUtils.setField(createServiceOfferingCmd, "purgeResources", true); + Assert.assertTrue(createServiceOfferingCmd.isPurgeResources()); + } } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmdTest.java new file mode 100644 index 000000000000..1bb2be041e18 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmdTest.java @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.offering; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateServiceOfferingCmdTest { + + @InjectMocks + private UpdateServiceOfferingCmd updateServiceOfferingCmd; + + @Test + public void testIsPurgeResourcesNoOrNullValue() { + Assert.assertFalse(updateServiceOfferingCmd.isPurgeResources()); + ReflectionTestUtils.setField(updateServiceOfferingCmd, "purgeResources", false); + Assert.assertFalse(updateServiceOfferingCmd.isPurgeResources()); + } + + @Test + public void testIsPurgeResourcesFalse() { + ReflectionTestUtils.setField(updateServiceOfferingCmd, "purgeResources", false); + Assert.assertFalse(updateServiceOfferingCmd.isPurgeResources()); + } + + @Test + public void testIsPurgeResourcesTrue() { + ReflectionTestUtils.setField(updateServiceOfferingCmd, "purgeResources", true); + Assert.assertTrue(updateServiceOfferingCmd.isPurgeResources()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java new file mode 100644 index 000000000000..fc0e6face529 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java @@ -0,0 +1,34 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.admin.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.test.util.ReflectionTestUtils; + +public class ListCapacityCmdTest { + + @Test + public void testGetTag() { + ListCapacityCmd cmd = new ListCapacityCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/PurgeExpungedResourcesCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/PurgeExpungedResourcesCmdTest.java new file mode 100644 index 000000000000..a628f13275c5 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/PurgeExpungedResourcesCmdTest.java @@ -0,0 +1,104 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.resource; + +import static org.junit.Assert.assertNull; + +import java.util.Date; + +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.PurgeExpungedResourcesResponse; +import org.apache.cloudstack.resource.ResourceCleanupService; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.utils.exception.CloudRuntimeException; + +@RunWith(MockitoJUnitRunner.class) +public class PurgeExpungedResourcesCmdTest { + @Mock + ResourceCleanupService resourceCleanupService; + + @Spy + @InjectMocks + PurgeExpungedResourcesCmd spyCmd = Mockito.spy(new PurgeExpungedResourcesCmd()); + + @Test + public void testGetResourceType() { + PurgeExpungedResourcesCmd cmd = new PurgeExpungedResourcesCmd(); + assertNull(cmd.getResourceType()); + ReflectionTestUtils.setField(cmd, "resourceType", ResourceCleanupService.ResourceType.VirtualMachine.toString()); + Assert.assertEquals(ResourceCleanupService.ResourceType.VirtualMachine.toString(), cmd.getResourceType()); + } + + @Test + public void testGetBatchSize() { + PurgeExpungedResourcesCmd cmd = new PurgeExpungedResourcesCmd(); + assertNull(cmd.getBatchSize()); + Long batchSize = 100L; + ReflectionTestUtils.setField(cmd, "batchSize", batchSize); + Assert.assertEquals(batchSize, cmd.getBatchSize()); + } + + @Test + public void testGetStartDate() { + PurgeExpungedResourcesCmd cmd = new PurgeExpungedResourcesCmd(); + assertNull(cmd.getStartDate()); + Date date = new Date(); + ReflectionTestUtils.setField(cmd, "startDate", date); + Assert.assertEquals(date, cmd.getStartDate()); + } + + @Test + public void testGetEndDate() { + PurgeExpungedResourcesCmd cmd = new PurgeExpungedResourcesCmd(); + assertNull(cmd.getEndDate()); + Date date = new Date(); + ReflectionTestUtils.setField(cmd, "endDate", date); + Assert.assertEquals(date, cmd.getEndDate()); + } + + @Test + public void testExecute() { + final PurgeExpungedResourcesResponse[] executeResponse = new PurgeExpungedResourcesResponse[1]; + Long result = 100L; + Mockito.when(resourceCleanupService.purgeExpungedResources(Mockito.any())).thenReturn(result); + Mockito.doAnswer((Answer) invocation -> { + executeResponse[0] = (PurgeExpungedResourcesResponse)invocation.getArguments()[0]; + return null; + }).when(spyCmd).setResponseObject(Mockito.any()); + spyCmd.execute(); + PurgeExpungedResourcesResponse response = executeResponse[0]; + Assert.assertNotNull(response); + Assert.assertEquals(result, response.getResourceCount()); + } + + @Test(expected = ServerApiException.class) + public void testExecuteException() { + Mockito.doThrow(CloudRuntimeException.class).when(resourceCleanupService).purgeExpungedResources(Mockito.any()); + spyCmd.execute(); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java index f64df167e258..a69a7a858ce0 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.response.ObjectStoreResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.storage.object.ObjectStore; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -39,11 +38,10 @@ import java.util.HashMap; import java.util.Map; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; @RunWith(MockitoJUnitRunner.class) public class AddObjectStoragePoolCmdTest { - public static final Logger s_logger = Logger.getLogger(AddObjectStoragePoolCmdTest.class.getName()); @Mock StorageService storageService; @@ -65,9 +63,11 @@ public class AddObjectStoragePoolCmdTest { Map details; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); details = new HashMap<>(); addObjectStoragePoolCmdSpy = Mockito.spy(new AddObjectStoragePoolCmd()); ReflectionTestUtils.setField(addObjectStoragePoolCmdSpy, "name", name); @@ -81,14 +81,15 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test public void testAddObjectStore() throws DiscoveryException { Mockito.doReturn(objectStore).when(storageService).discoverObjectStore(Mockito.anyString(), - Mockito.anyString(), Mockito.anyString(), anyObject()); + Mockito.anyString(), Mockito.anyString(), any()); ObjectStoreResponse objectStoreResponse = new ObjectStoreResponse(); - Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(anyObject()); + Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(any()); addObjectStoragePoolCmdSpy.execute(); Mockito.verify(storageService, Mockito.times(1)) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java index 35be56d0c758..dc5b9f5fa325 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java @@ -20,7 +20,6 @@ import com.cloud.storage.StorageService; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -30,16 +29,17 @@ import org.mockito.Spy; public class DeleteObjectStoragePoolCmdTest { - public static final Logger s_logger = Logger.getLogger(DeleteObjectStoragePoolCmdTest.class.getName()); @Mock private StorageService storageService; @Spy DeleteObjectStoragePoolCmd deleteObjectStoragePoolCmd; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); deleteObjectStoragePoolCmd = Mockito.spy(new DeleteObjectStoragePoolCmd()); deleteObjectStoragePoolCmd._storageService = storageService; } @@ -47,6 +47,7 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java index 5244ff1ef9a3..fbf4d2c495d2 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class FindStoragePoolsForMigrationCmdTest { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java index ef66c2a1a64d..307d80aa3f83 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.response.ObjectStoreResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.storage.object.ObjectStore; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -33,10 +32,9 @@ import org.mockito.Spy; import org.springframework.test.util.ReflectionTestUtils; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; public class UpdateObjectStoragePoolCmdTest { - public static final Logger s_logger = Logger.getLogger(UpdateObjectStoragePoolCmdTest.class.getName()); @Mock private StorageService storageService; @@ -56,9 +54,11 @@ public class UpdateObjectStoragePoolCmdTest { private String provider = "Simulator"; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); updateObjectStoragePoolCmd = Mockito.spy(new UpdateObjectStoragePoolCmd()); updateObjectStoragePoolCmd._storageService = storageService; updateObjectStoragePoolCmd._responseGenerator = responseGenerator; @@ -70,13 +70,14 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test public void testUpdateObjectStore() { Mockito.doReturn(objectStore).when(storageService).updateObjectStore(1L, updateObjectStoragePoolCmd); ObjectStoreResponse objectStoreResponse = new ObjectStoreResponse(); - Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(anyObject()); + Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(any()); updateObjectStoragePoolCmd.execute(); Mockito.verify(storageService, Mockito.times(1)) .updateObjectStore(1L, updateObjectStoragePoolCmd); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmdTest.java index bc1e1854aa77..8a57ac3eb22c 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmdTest.java @@ -22,7 +22,8 @@ import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -38,7 +39,7 @@ import com.cloud.user.User; public class CreateUserCmdTest { - public static final Logger s_logger = Logger.getLogger(CreateUserCmdTest.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); @Mock private AccountService accountService; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdminTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdminTest.java new file mode 100644 index 000000000000..c4e21bb948b2 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCCmdByAdminTest.java @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.admin.vpc; + +import com.cloud.network.vpc.VpcService; +import com.cloud.user.AccountService; +import com.cloud.utils.db.EntityManager; +import junit.framework.TestCase; +import org.apache.cloudstack.api.ResponseGenerator; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class CreateVPCCmdByAdminTest extends TestCase { + + @Mock + public VpcService _vpcService; + @Mock + public EntityManager _entityMgr; + @Mock + public AccountService _accountService; + private ResponseGenerator responseGenerator; + @InjectMocks + CreateVPCCmdByAdmin cmd = new CreateVPCCmdByAdmin(); + + @Test + public void testBgpPeerIds() { + List bgpPeerIds = Mockito.mock(List.class); + ReflectionTestUtils.setField(cmd, "bgpPeerIds", bgpPeerIds); + Assert.assertEquals(bgpPeerIds, cmd.getBgpPeerIds()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java index 16b716d7d638..290a2850c9a6 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java @@ -52,15 +52,15 @@ public void testServiceProvidersEmpty() throws IllegalArgumentException, IllegalAccessException { CreateVPCOfferingCmd cmd = new CreateVPCOfferingCmd(); ApiCmdTestUtil.set(cmd, ApiConstants.SERVICE_PROVIDER_LIST, new HashMap>()); - Assert.assertNull(cmd.getServiceProviders()); + Assert.assertTrue(cmd.getServiceProviders().isEmpty()); } @Test - public void getDetailsNull() throws IllegalArgumentException, + public void getDetailsEmpty() throws IllegalArgumentException, IllegalAccessException { CreateVPCOfferingCmd cmd = new CreateVPCOfferingCmd(); ApiCmdTestUtil.set(cmd, ApiConstants.SERVICE_PROVIDER_LIST, null); - Assert.assertNull(cmd.getServiceProviders()); + Assert.assertTrue(cmd.getServiceProviders().isEmpty()); } @Test diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java index 1e4bb326f7e6..2c43278a582f 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.command.user.project.ActivateProjectCmd; @@ -57,7 +57,7 @@ public Long getId() { @Test public void testGetEntityOwnerIdForNullProject() { ProjectService projectService = Mockito.mock(ProjectService.class); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(null); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(null); activateProjectCmd._projectService = projectService; try { @@ -74,9 +74,9 @@ public void testGetEntityOwnerIdForProject() { ProjectService projectService = Mockito.mock(ProjectService.class); Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(2L); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(project); - Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account); + Mockito.when(projectService.getProjectOwner(ArgumentMatchers.anyLong())).thenReturn(account); activateProjectCmd._projectService = projectService; Assert.assertEquals(2L, activateProjectCmd.getEntityOwnerId()); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java index 199ee00551d7..f100822b8c77 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.command.user.account.AddAccountToProjectCmd; @@ -101,9 +101,9 @@ public void testGetEntityOwnerIdForProject() { Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(2L); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(project); - Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account); + Mockito.when(projectService.getProjectOwner(ArgumentMatchers.anyLong())).thenReturn(account); addAccountToProjectCmd._projectService = projectService; Assert.assertEquals(2L, addAccountToProjectCmd.getEntityOwnerId()); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java index d0cc8be716a3..9ea3a6446e8e 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java @@ -21,7 +21,7 @@ import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.ResponseGenerator; import org.apache.cloudstack.api.command.user.vm.AddIpToVmNicCmd; @@ -59,7 +59,7 @@ public void testCreateSuccess() throws ResourceAllocationException, ResourceUnav NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class); Mockito.when( - networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.any())) + networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any())) .thenReturn(secIp); ipTonicCmd._networkService = networkService; @@ -79,7 +79,7 @@ public void testCreateFailure() throws ResourceAllocationException, ResourceUnav AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class); Mockito.when( - networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.any())) + networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any())) .thenReturn(null); ipTonicCmd._networkService = networkService; @@ -98,7 +98,7 @@ public void testRemoveIpFromVmNicSuccess() throws ResourceAllocationException, R NetworkService networkService = Mockito.mock(NetworkService.class); RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); - Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(true); + Mockito.when(networkService.releaseSecondaryIpFromNic(ArgumentMatchers.anyInt())).thenReturn(true); removeIpFromNic._networkService = networkService; removeIpFromNic.execute(); @@ -109,7 +109,7 @@ public void testRemoveIpFromVmNicFailure() throws InsufficientAddressCapacityExc NetworkService networkService = Mockito.mock(NetworkService.class); RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); - Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(false); + Mockito.when(networkService.releaseSecondaryIpFromNic(ArgumentMatchers.anyInt())).thenReturn(false); removeIpFromNic._networkService = networkService; successResponseGenerator = Mockito.mock(SuccessResponse.class); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java index 8760fc87556f..a62c29e487ab 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java @@ -26,7 +26,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.ServerApiException; @@ -86,7 +86,7 @@ public void testCreateProviderToPhysicalNetworkSuccess() { addNetworkServiceProviderCmd._networkService = networkService; PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito.mock(PhysicalNetworkServiceProvider.class); - Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn( + Mockito.when(networkService.addProviderToPhysicalNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyList())).thenReturn( physicalNetworkServiceProvider); try { @@ -103,7 +103,7 @@ public void testCreateProviderToPhysicalNetworkFailure() throws ResourceAllocati NetworkService networkService = Mockito.mock(NetworkService.class); addNetworkServiceProviderCmd._networkService = networkService; - Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn(null); + Mockito.when(networkService.addProviderToPhysicalNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyList())).thenReturn(null); try { addNetworkServiceProviderCmd.create(); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java index 46fd69056834..86a53787e08f 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java @@ -18,7 +18,7 @@ import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.isNull; @@ -86,7 +86,7 @@ public void testExecuteForNullResult() throws Exception { StorageService resourceService = Mockito.mock(StorageService.class); addImageStoreCmd._storageService = resourceService; - Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)anyObject())) + Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)any())) .thenReturn(null); try { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/CreateRoleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/CreateRoleCmdTest.java index 4b9d4fd8974f..72ce95933647 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/CreateRoleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/CreateRoleCmdTest.java @@ -54,6 +54,7 @@ public void testCreateRoleWithRoleType() { when(role.getDescription()).thenReturn("User test"); when(role.getName()).thenReturn("testuser"); when(role.getRoleType()).thenReturn(RoleType.User); + when(role.getState()).thenReturn(Role.State.ENABLED); when(roleService.createRole(createRoleCmd.getRoleName(), createRoleCmd.getRoleType(), createRoleCmd.getRoleDescription(), true)).thenReturn(role); createRoleCmd.execute(); RoleResponse response = (RoleResponse) createRoleCmd.getResponseObject(); @@ -71,6 +72,7 @@ public void testCreateRoleWithExistingRole() { when(newRole.getDescription()).thenReturn("User test"); when(newRole.getName()).thenReturn("testuser"); when(newRole.getRoleType()).thenReturn(RoleType.User); + when(newRole.getState()).thenReturn(Role.State.ENABLED); when(roleService.createRole(createRoleCmd.getRoleName(), role, createRoleCmd.getRoleDescription(), true)).thenReturn(newRole); createRoleCmd.execute(); RoleResponse response = (RoleResponse) createRoleCmd.getResponseObject(); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java index c5288067e943..34baebe52574 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java @@ -17,10 +17,10 @@ package org.apache.cloudstack.api.command.test; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; import java.util.HashMap; import java.util.List; @@ -126,7 +126,7 @@ public void testCreateFailure() { try { Mockito.when(volumeApiService.takeSnapshot(nullable(Long.class), nullable(Long.class), nullable(Long.class), - nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), anyObject(), Mockito.anyList())).thenReturn(null); + nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), any(), Mockito.anyList())).thenReturn(null); } catch (Exception e) { Assert.fail("Received exception when success expected " + e.getMessage()); } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/ImportRoleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/ImportRoleCmdTest.java index 6299c1ed8e2c..d2597e5162fd 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/ImportRoleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/ImportRoleCmdTest.java @@ -32,19 +32,13 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyCollection; -import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.cloud.exception.InvalidParameterValueException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.regex.Matcher; public class ImportRoleCmdTest { private ImportRoleCmd importRoleCmd; @@ -93,6 +87,7 @@ public void testImportRoleSuccess() { when(role.getDescription()).thenReturn("test user imported"); when(role.getName()).thenReturn("Test User"); when(role.getRoleType()).thenReturn(RoleType.User); + when(role.getState()).thenReturn(Role.State.ENABLED); when(roleService.importRole(anyString(), any(), anyString(), any(), anyBoolean(), anyBoolean())).thenReturn(role); importRoleCmd.execute(); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateRoleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateRoleCmdTest.java index 84b91525742a..9a1dae9a480a 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateRoleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/UpdateRoleCmdTest.java @@ -62,6 +62,7 @@ public void testUpdateSuccess() { when(role.getId()).thenReturn(1L); when(role.getDescription()).thenReturn("Description Initial"); when(role.getName()).thenReturn("User"); + when(role.getState()).thenReturn(Role.State.ENABLED); updateRoleCmd.execute(); RoleResponse response = (RoleResponse) updateRoleCmd.getResponseObject(); assertEquals((String)ReflectionTestUtils.getField(response, "roleName"),role.getName()); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java new file mode 100644 index 000000000000..896a7a6c826b --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.account; + +import java.util.List; + +import org.apache.cloudstack.api.response.AccountResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.ResourceLimitService; + +@RunWith(MockitoJUnitRunner.class) +public class ListAccountsCmdTest { + + @Mock + ResourceLimitService resourceLimitService; + + + @Test + public void testGetShowIcon() { + ListAccountsCmd cmd = new ListAccountsCmd(); + ReflectionTestUtils.setField(cmd, "showIcon", null); + Assert.assertFalse(cmd.getShowIcon()); + ReflectionTestUtils.setField(cmd, "showIcon", false); + Assert.assertFalse(cmd.getShowIcon()); + ReflectionTestUtils.setField(cmd, "showIcon", true); + Assert.assertTrue(cmd.getShowIcon()); + } + + @Test + public void testGetTag() { + ListAccountsCmd cmd = new ListAccountsCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } + + @Test + public void testUpdateDomainResponseNoDomains() { + ListAccountsCmd cmd = new ListAccountsCmd(); + cmd._resourceLimitService = resourceLimitService; + cmd.updateAccountResponse(null); + Mockito.verify(resourceLimitService, Mockito.never()).updateTaggedResourceLimitsAndCountsForAccounts(Mockito.anyList(), Mockito.anyString()); + } + + @Test + public void testUpdateDomainResponseWithDomains() { + ListAccountsCmd cmd = new ListAccountsCmd(); + cmd._resourceLimitService = resourceLimitService; + ReflectionTestUtils.setField(cmd, "tag", "abc"); + cmd.updateAccountResponse(List.of(Mockito.mock(AccountResponse.class))); + Mockito.verify(resourceLimitService, Mockito.times(1)).updateTaggedResourceLimitsAndCountsForAccounts(Mockito.any(), Mockito.any()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/bgp/ListASNumbersCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/bgp/ListASNumbersCmdTest.java new file mode 100644 index 000000000000..9d7f4ef7cf13 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/bgp/ListASNumbersCmdTest.java @@ -0,0 +1,97 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.bgp; + +import com.cloud.bgp.ASNumber; +import com.cloud.bgp.BGPService; + +import com.cloud.utils.Pair; +import org.apache.cloudstack.api.ResponseGenerator; +import org.apache.cloudstack.api.response.ASNumberResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class ListASNumbersCmdTest { + + BGPService bgpService = Mockito.spy(BGPService.class); + ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); + + @Test + public void testListASNumbersCmdTest() { + Long zoneId = 1L; + Long asNumberRangeId = 2L; + Integer asNumber = 10; + Long networkId = 11L; + Long vpcId = 12L; + String account = "account"; + Long domainId = 13L; + + ListASNumbersCmd cmd = new ListASNumbersCmd(); + ReflectionTestUtils.setField(cmd, "zoneId", zoneId); + ReflectionTestUtils.setField(cmd, "asNumberRangeId", asNumberRangeId); + ReflectionTestUtils.setField(cmd, "asNumber", asNumber); + ReflectionTestUtils.setField(cmd, "networkId", networkId); + ReflectionTestUtils.setField(cmd, "vpcId", vpcId); + ReflectionTestUtils.setField(cmd, "account", account); + ReflectionTestUtils.setField(cmd, "domainId", domainId); + ReflectionTestUtils.setField(cmd, "allocated", Boolean.TRUE); + + ReflectionTestUtils.setField(cmd,"bgpService", bgpService); + ReflectionTestUtils.setField(cmd,"_responseGenerator", _responseGenerator); + + Assert.assertEquals(zoneId, cmd.getZoneId()); + Assert.assertEquals(asNumberRangeId, cmd.getAsNumberRangeId()); + Assert.assertEquals(asNumber, cmd.getAsNumber()); + Assert.assertEquals(networkId, cmd.getNetworkId()); + Assert.assertEquals(vpcId, cmd.getVpcId()); + Assert.assertEquals(account, cmd.getAccount()); + Assert.assertEquals(domainId, cmd.getDomainId()); + Assert.assertTrue(cmd.getAllocated()); + + List asNumbers = new ArrayList<>(); + ASNumber asn = Mockito.mock(ASNumber.class); + asNumbers.add(asn); + Pair, Integer> pair = new Pair<>(asNumbers, 1); + + ASNumberResponse asNumberResponse = Mockito.mock(ASNumberResponse.class); + Mockito.when(_responseGenerator.createASNumberResponse(asn)).thenReturn(asNumberResponse); + + Mockito.when(bgpService.listASNumbers(cmd)).thenReturn(pair); + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Object response = cmd.getResponseObject(); + Assert.assertTrue(response instanceof ListResponse); + ListResponse listResponse = (ListResponse) response; + Assert.assertEquals(1L, (long) listResponse.getCount()); + Assert.assertTrue(listResponse.getResponses().get(0) instanceof ASNumberResponse); + ASNumberResponse firstResponse = (ASNumberResponse) listResponse.getResponses().get(0); + Assert.assertEquals(asNumberResponse, firstResponse); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java index 55a41c61ce6a..76836caef28c 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmdTest.java new file mode 100644 index 000000000000..7c29de69aded --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmdTest.java @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.network; + +import com.cloud.utils.net.NetworkProtocols; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NetworkProtocolResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ListNetworkProtocolsCmdTest { + + @Test + public void testListNetworkProtocolNumbers() { + ListNetworkProtocolsCmd cmd = new ListNetworkProtocolsCmd(); + String option = NetworkProtocols.Option.ProtocolNumber.toString(); + ReflectionTestUtils.setField(cmd, "option", option); + Assert.assertEquals(cmd.getOption(), option); + + try { + cmd.execute(); + } catch (Exception e) { + e.printStackTrace(); + } + Object response = cmd.getResponseObject(); + Assert.assertTrue(response instanceof ListResponse); + ListResponse listResponse = (ListResponse) response; + Assert.assertEquals(BaseCmd.getResponseNameByClass(cmd.getClass()), listResponse.getResponseName()); + Assert.assertNotNull(listResponse.getResponses()); + Assert.assertNotEquals(0, listResponse.getResponses().size()); + Object firstResponse = listResponse.getResponses().get(0); + Assert.assertTrue(firstResponse instanceof NetworkProtocolResponse); + Assert.assertEquals("networkprotocol", ((NetworkProtocolResponse) firstResponse).getObjectName()); + Assert.assertEquals(Integer.valueOf(0), ((NetworkProtocolResponse) firstResponse).getIndex()); + Assert.assertEquals("HOPOPT", ((NetworkProtocolResponse) firstResponse).getName()); + } + + @Test + public void testListIcmpTypes() { + ListNetworkProtocolsCmd cmd = new ListNetworkProtocolsCmd(); + String option = NetworkProtocols.Option.IcmpType.toString(); + ReflectionTestUtils.setField(cmd, "option", option); + Assert.assertEquals(cmd.getOption(), option); + + try { + cmd.execute(); + } catch (Exception e) { + e.printStackTrace(); + } + Object response = cmd.getResponseObject(); + Assert.assertTrue(response instanceof ListResponse); + ListResponse listResponse = (ListResponse) response; + Assert.assertEquals(BaseCmd.getResponseNameByClass(cmd.getClass()), listResponse.getResponseName()); + Assert.assertNotNull(listResponse.getResponses()); + Assert.assertNotEquals(0, listResponse.getResponses().size()); + Object firstResponse = listResponse.getResponses().get(0); + Assert.assertTrue(firstResponse instanceof NetworkProtocolResponse); + Assert.assertEquals("networkprotocol", ((NetworkProtocolResponse) firstResponse).getObjectName()); + Assert.assertEquals(Integer.valueOf(0), ((NetworkProtocolResponse) firstResponse).getIndex()); + Assert.assertNotNull(((NetworkProtocolResponse) firstResponse).getDetails()); + System.out.println(((NetworkProtocolResponse) firstResponse).getDetails()); + Assert.assertEquals("Echo reply", ((NetworkProtocolResponse) firstResponse).getDetails().get("0")); + } + + @Test(expected = IllegalArgumentException.class) + public void testListInvalidOption() { + ListNetworkProtocolsCmd cmd = new ListNetworkProtocolsCmd(); + String option = "invalid-option"; + ReflectionTestUtils.setField(cmd, "option", option); + Assert.assertEquals(cmd.getOption(), option); + + cmd.execute(); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmdTest.java new file mode 100644 index 000000000000..11c41f4c92d2 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/CreateRoutingFirewallRuleCmdTest.java @@ -0,0 +1,251 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.network.routing; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.firewall.FirewallService; +import com.cloud.network.rules.FirewallRule; +import com.cloud.utils.net.NetUtils; + +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ResponseGenerator; +import org.apache.cloudstack.api.response.FirewallResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(MockitoJUnitRunner.class) +public class CreateRoutingFirewallRuleCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + FirewallService _firewallService = Mockito.spy(FirewallService.class); + + ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); + + @Test + public void testIsDisplay() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + assertTrue(cmd.isDisplay()); + + ReflectionTestUtils.setField(cmd, "display", Boolean.TRUE); + assertTrue(cmd.isDisplay()); + + ReflectionTestUtils.setField(cmd, "display", Boolean.FALSE); + assertFalse(cmd.isDisplay()); + } + + @Test + public void testGetProtocolValid() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + assertEquals("", cmd.getProtocol()); + + ReflectionTestUtils.setField(cmd, "protocol", "1"); + assertEquals(NetUtils.ICMP_PROTO, cmd.getProtocol()); + + ReflectionTestUtils.setField(cmd, "protocol", "icmp"); + assertEquals(NetUtils.ICMP_PROTO, cmd.getProtocol()); + + ReflectionTestUtils.setField(cmd, "protocol", "6"); + assertEquals(NetUtils.TCP_PROTO, cmd.getProtocol()); + + ReflectionTestUtils.setField(cmd, "protocol", "tcp"); + assertEquals(NetUtils.TCP_PROTO, cmd.getProtocol()); + + ReflectionTestUtils.setField(cmd, "protocol", "17"); + assertEquals(NetUtils.UDP_PROTO, cmd.getProtocol()); + + ReflectionTestUtils.setField(cmd, "protocol", "udp"); + assertEquals(NetUtils.UDP_PROTO, cmd.getProtocol()); + } + + @Test(expected = InvalidParameterValueException.class) + public void testGetProtocolInValid() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + + ReflectionTestUtils.setField(cmd, "protocol", "100"); + cmd.getProtocol(); + } + + @Test + public void testGetSourceCidrListNull() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + + List result = cmd.getSourceCidrList(); + assertNotNull(result); + assertEquals(1, result.size()); + assertEquals(NetUtils.ALL_IP4_CIDRS, result.get(0)); + } + + @Test + public void testGetSourceCidrList() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + + List cidrList = Arrays.asList("192.168.0.0/24", "10.0.0.0/8"); + cmd.sourceCidrList = cidrList; + List result = cmd.getSourceCidrList(); + assertNotNull(result); + assertEquals(cidrList, result); + } + + @Test + public void testGetDestinationCidrListNull() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + + List result = cmd.getDestinationCidrList(); + assertNotNull(result); + assertEquals(1, result.size()); + assertEquals(NetUtils.ALL_IP4_CIDRS, result.get(0)); + } + + @Test + public void testGetDestinationCidrList() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + + List cidrList = Arrays.asList("192.168.0.0/24", "10.0.0.0/8"); + cmd.destinationCidrlist = cidrList; + List result = cmd.getDestinationCidrList(); + assertNotNull(result); + assertEquals(cidrList, result); + } + + @Test + public void testGetTrafficTypeValid() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + assertEquals(FirewallRule.TrafficType.Ingress, cmd.getTrafficType()); + + ReflectionTestUtils.setField(cmd, "trafficType", "ingress"); + assertEquals(FirewallRule.TrafficType.Ingress, cmd.getTrafficType()); + + ReflectionTestUtils.setField(cmd, "trafficType", "egress"); + assertEquals(FirewallRule.TrafficType.Egress, cmd.getTrafficType()); + } + + @Test(expected = InvalidParameterValueException.class) + public void testGetTrafficTypeInValid() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + + ReflectionTestUtils.setField(cmd, "trafficType", "invalid"); + cmd.getTrafficType(); + } + + @Test + public void testSourcePortStartEnd() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + assertNull(cmd.getSourcePortStart()); + assertNull(cmd.getSourcePortEnd()); + + ReflectionTestUtils.setField(cmd, "publicStartPort", 1111); + assertEquals(1111, (int) cmd.getSourcePortStart()); + assertEquals(1111, (int) cmd.getSourcePortEnd()); + + ReflectionTestUtils.setField(cmd, "publicEndPort", 2222); + assertEquals(1111, (int) cmd.getSourcePortStart()); + assertEquals(2222, (int) cmd.getSourcePortEnd()); + } + + @Test + public void testNetworkId() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + + ReflectionTestUtils.setField(cmd, "networkId", 1111L); + assertEquals(1111L, (long) cmd.getNetworkId()); + + assertEquals(1111L, (long) cmd.getApiResourceId()); + assertEquals(ApiCommandResourceType.Network, cmd.getApiResourceType()); + assertEquals(EventTypes.EVENT_ROUTING_IPV4_FIREWALL_RULE_CREATE, cmd.getEventType()); + assertEquals("Creating ipv4 firewall rule for routed network", cmd.getEventDescription()); + } + + @Test + public void testIcmpCodeAndType() { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + ReflectionTestUtils.setField(cmd, "protocol", "tcp"); + assertNull(cmd.getIcmpType()); + assertNull(cmd.getIcmpCode()); + + ReflectionTestUtils.setField(cmd, "protocol", "icmp"); + assertEquals(-1, (int) cmd.getIcmpType()); + assertEquals(-1, (int) cmd.getIcmpCode()); + + ReflectionTestUtils.setField(cmd, "icmpType", 1111); + ReflectionTestUtils.setField(cmd, "icmpCode", 2222); + assertEquals(1111, (int) cmd.getIcmpType()); + assertEquals(2222, (int) cmd.getIcmpCode()); + } + + @Test + public void testCreate() throws Exception { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + ReflectionTestUtils.setField(cmd, "routedIpv4Manager", routedIpv4Manager); + + Long id = 1L; + String uuid = "uuid"; + FirewallRule firewallRule = Mockito.spy(FirewallRule.class); + Mockito.when(firewallRule.getId()).thenReturn(id); + Mockito.when(firewallRule.getUuid()).thenReturn(uuid); + Mockito.when(routedIpv4Manager.createRoutingFirewallRule(cmd)).thenReturn(firewallRule); + + try { + cmd.create(); + } catch (Exception ignored) { + } + + assertEquals(id, cmd.getEntityId()); + assertEquals(uuid, cmd.getEntityUuid()); + } + + @Test + public void testExecute() throws Exception { + CreateRoutingFirewallRuleCmd cmd = new CreateRoutingFirewallRuleCmd(); + ReflectionTestUtils.setField(cmd, "routedIpv4Manager", routedIpv4Manager); + ReflectionTestUtils.setField(cmd, "_firewallService", _firewallService); + ReflectionTestUtils.setField(cmd, "_responseGenerator", _responseGenerator); + + Long id = 1L; + FirewallRule firewallRule = Mockito.spy(FirewallRule.class); + Mockito.when(firewallRule.getId()).thenReturn(id); + Mockito.when(_firewallService.getFirewallRule(id)).thenReturn(firewallRule); + Mockito.when(routedIpv4Manager.applyRoutingFirewallRule(id)).thenReturn(true); + + FirewallResponse ruleResponse = Mockito.mock(FirewallResponse.class); + Mockito.when(_responseGenerator.createFirewallResponse(firewallRule)).thenReturn(ruleResponse); + + try { + ReflectionTestUtils.setField(cmd, "id", id); + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(ruleResponse, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmdTest.java new file mode 100644 index 000000000000..2b55d4c6a58d --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/DeleteRoutingFirewallRuleCmdTest.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.network.routing; + +import com.cloud.event.EventTypes; +import com.cloud.network.firewall.FirewallService; +import com.cloud.network.rules.FirewallRule; + +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import static org.junit.Assert.assertEquals; + +@RunWith(MockitoJUnitRunner.class) +public class DeleteRoutingFirewallRuleCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + FirewallService _firewallService = Mockito.spy(FirewallService.class); + + @Test + public void testProperties() { + DeleteRoutingFirewallRuleCmd cmd = new DeleteRoutingFirewallRuleCmd(); + ReflectionTestUtils.setField(cmd, "_firewallService", _firewallService); + + long id = 1L; + long accountId = 2L; + long networkId = 3L; + + FirewallRule firewallRule = Mockito.spy(FirewallRule.class); + Mockito.when(firewallRule.getAccountId()).thenReturn(accountId); + Mockito.when(firewallRule.getNetworkId()).thenReturn(networkId); + Mockito.when(_firewallService.getFirewallRule(id)).thenReturn(firewallRule); + + ReflectionTestUtils.setField(cmd, "id", id); + assertEquals(id, (long) cmd.getId()); + assertEquals(accountId, cmd.getEntityOwnerId()); + assertEquals(networkId, (long) cmd.getApiResourceId()); + assertEquals(ApiCommandResourceType.Network, cmd.getApiResourceType()); + assertEquals(EventTypes.EVENT_ROUTING_IPV4_FIREWALL_RULE_DELETE, cmd.getEventType()); + assertEquals(String.format("Deleting ipv4 routing firewall rule ID=%s", id), cmd.getEventDescription()); + } + + + @Test + public void testExecute() throws Exception { + DeleteRoutingFirewallRuleCmd cmd = new DeleteRoutingFirewallRuleCmd(); + ReflectionTestUtils.setField(cmd, "routedIpv4Manager", routedIpv4Manager); + + Long id = 1L; + Mockito.when(routedIpv4Manager.revokeRoutingFirewallRule(id)).thenReturn(true); + + try { + ReflectionTestUtils.setField(cmd, "id", id); + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertTrue(cmd.getResponseObject() instanceof SuccessResponse); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmdTest.java new file mode 100644 index 000000000000..53ac45917cb8 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/ListRoutingFirewallRulesCmdTest.java @@ -0,0 +1,115 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.network.routing; + +import com.cloud.network.rules.FirewallRule; +import com.cloud.utils.Pair; + +import org.apache.cloudstack.api.ResponseGenerator; +import org.apache.cloudstack.api.response.FirewallResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(MockitoJUnitRunner.class) +public class ListRoutingFirewallRulesCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); + + @Test + public void testIsDisplay() { + ListRoutingFirewallRulesCmd cmd = new ListRoutingFirewallRulesCmd(); + assertTrue(cmd.getDisplay()); + + ReflectionTestUtils.setField(cmd, "display", Boolean.TRUE); + assertTrue(cmd.getDisplay()); + + ReflectionTestUtils.setField(cmd, "display", Boolean.FALSE); + assertFalse(cmd.getDisplay()); + } + + @Test + public void testTrafficType() { + ListRoutingFirewallRulesCmd cmd = new ListRoutingFirewallRulesCmd(); + assertNull(cmd.getTrafficType()); + + ReflectionTestUtils.setField(cmd, "trafficType", "Ingress"); + assertEquals(FirewallRule.TrafficType.Ingress, cmd.getTrafficType()); + + ReflectionTestUtils.setField(cmd, "trafficType", "Egress"); + assertEquals(FirewallRule.TrafficType.Egress, cmd.getTrafficType()); + } + + @Test + public void testOtherProperties() { + ListRoutingFirewallRulesCmd cmd = new ListRoutingFirewallRulesCmd(); + + long id = 1L; + long networkId = 3L; + + ReflectionTestUtils.setField(cmd, "id", id); + ReflectionTestUtils.setField(cmd, "networkId", networkId); + + assertEquals(id, (long) cmd.getId()); + assertEquals(networkId, (long) cmd.getNetworkId()); + assertNull(cmd.getIpAddressId()); + } + + + @Test + public void testExecute() throws Exception { + ListRoutingFirewallRulesCmd cmd = new ListRoutingFirewallRulesCmd(); + ReflectionTestUtils.setField(cmd, "routedIpv4Manager", routedIpv4Manager); + ReflectionTestUtils.setField(cmd, "_responseGenerator", _responseGenerator); + + Long id = 1L; + FirewallRule firewallRule = Mockito.spy(FirewallRule.class); + List firewallRules = Arrays.asList(firewallRule); + Pair, Integer> result = new Pair<>(firewallRules, 1); + + Mockito.when(routedIpv4Manager.listRoutingFirewallRules(cmd)).thenReturn(result); + + FirewallResponse ruleResponse = Mockito.mock(FirewallResponse.class); + Mockito.when(_responseGenerator.createFirewallResponse(firewallRule)).thenReturn(ruleResponse); + + try { + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertTrue(cmd.getResponseObject() instanceof ListResponse); + ListResponse listResponse = (ListResponse) cmd.getResponseObject(); + Assert.assertEquals(1, (int) listResponse.getCount()); + Assert.assertEquals(ruleResponse, listResponse.getResponses().get(0)); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmdTest.java new file mode 100644 index 000000000000..dd0319df6960 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/network/routing/UpdateRoutingFirewallRuleCmdTest.java @@ -0,0 +1,106 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.api.command.user.network.routing; + +import com.cloud.event.EventTypes; +import com.cloud.network.firewall.FirewallService; +import com.cloud.network.rules.FirewallRule; + +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ResponseGenerator; +import org.apache.cloudstack.api.response.FirewallResponse; +import org.apache.cloudstack.network.RoutedIpv4Manager; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateRoutingFirewallRuleCmdTest { + + RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); + + FirewallService _firewallService = Mockito.spy(FirewallService.class); + + ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); + + @Test + public void testIsDisplay() { + UpdateRoutingFirewallRuleCmd cmd = new UpdateRoutingFirewallRuleCmd(); + assertTrue(cmd.isDisplay()); + + ReflectionTestUtils.setField(cmd, "display", Boolean.TRUE); + assertTrue(cmd.isDisplay()); + + ReflectionTestUtils.setField(cmd, "display", Boolean.FALSE); + assertFalse(cmd.isDisplay()); + } + + @Test + public void testOtherProperties() { + UpdateRoutingFirewallRuleCmd cmd = new UpdateRoutingFirewallRuleCmd(); + ReflectionTestUtils.setField(cmd, "_firewallService", _firewallService); + + long id = 1L; + long accountId = 2L; + long networkId = 3L; + + FirewallRule firewallRule = Mockito.spy(FirewallRule.class); + Mockito.when(firewallRule.getAccountId()).thenReturn(accountId); + Mockito.when(firewallRule.getNetworkId()).thenReturn(networkId); + Mockito.when(_firewallService.getFirewallRule(id)).thenReturn(firewallRule); + + ReflectionTestUtils.setField(cmd, "id", id); + assertEquals(id, (long) cmd.getId()); + assertEquals(accountId, cmd.getEntityOwnerId()); + assertEquals(networkId, (long) cmd.getApiResourceId()); + assertEquals(ApiCommandResourceType.Network, cmd.getApiResourceType()); + assertEquals(EventTypes.EVENT_ROUTING_IPV4_FIREWALL_RULE_UPDATE, cmd.getEventType()); + assertEquals("Updating ipv4 routing firewall rule", cmd.getEventDescription()); + } + + + @Test + public void testExecute() throws Exception { + UpdateRoutingFirewallRuleCmd cmd = new UpdateRoutingFirewallRuleCmd(); + ReflectionTestUtils.setField(cmd, "routedIpv4Manager", routedIpv4Manager); + ReflectionTestUtils.setField(cmd, "_firewallService", _firewallService); + ReflectionTestUtils.setField(cmd, "_responseGenerator", _responseGenerator); + + Long id = 1L; + FirewallRule firewallRule = Mockito.spy(FirewallRule.class); + Mockito.when(routedIpv4Manager.updateRoutingFirewallRule(cmd)).thenReturn(firewallRule); + + FirewallResponse ruleResponse = Mockito.mock(FirewallResponse.class); + Mockito.when(_responseGenerator.createFirewallResponse(firewallRule)).thenReturn(ruleResponse); + + try { + ReflectionTestUtils.setField(cmd, "id", id); + cmd.execute(); + } catch (Exception ignored) { + } + + Assert.assertEquals(ruleResponse, cmd.getResponseObject()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java new file mode 100644 index 000000000000..598fdd8ac4f6 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java @@ -0,0 +1,37 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.offering; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ListDiskOfferingsCmdTest { + + @Test + public void testGetVirtualMachineId() { + ListDiskOfferingsCmd cmd = new ListDiskOfferingsCmd(); + ReflectionTestUtils.setField(cmd, "virtualMachineId", null); + Assert.assertNull(cmd.getVirtualMachineId()); + Long id = 100L; + ReflectionTestUtils.setField(cmd, "virtualMachineId", id); + Assert.assertEquals(id, cmd.getVirtualMachineId()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java new file mode 100644 index 000000000000..f408132e5fce --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.offering; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + + +@RunWith(MockitoJUnitRunner.class) +public class ListServiceOfferingsCmdTest { + + @Test + public void testGetTemplateId() { + ListServiceOfferingsCmd cmd = new ListServiceOfferingsCmd(); + ReflectionTestUtils.setField(cmd, "templateId", null); + Assert.assertNull(cmd.getTemplateId()); + Long id = 100L; + ReflectionTestUtils.setField(cmd, "templateId", id); + Assert.assertEquals(id, cmd.getTemplateId()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java index ee3193123e0f..dc1f2ca51895 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java new file mode 100644 index 000000000000..3e999be2cfd7 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java @@ -0,0 +1,37 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ListResourceLimitsCmdTest { + + @Test + public void testGetTag() { + ListResourceLimitsCmd cmd = new ListResourceLimitsCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java new file mode 100644 index 000000000000..ab7d3253ab52 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java @@ -0,0 +1,37 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateResourceCountCmdTest { + + @Test + public void testGetTag() { + UpdateResourceCountCmd cmd = new UpdateResourceCountCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java new file mode 100644 index 000000000000..dff27a200446 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java @@ -0,0 +1,37 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateResourceLimitCmdTest { + + @Test + public void testGetTag() { + UpdateResourceLimitCmd cmd = new UpdateResourceLimitCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java index 8639e135599e..29b6144fd073 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java index 269a7b8a9e61..fb55e86dc0cc 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java @@ -26,7 +26,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java index 1ba7963b2b90..1dc05888608e 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java @@ -29,7 +29,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java index 0c31e501519d..a063f6c2d6ba 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java @@ -29,7 +29,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java new file mode 100644 index 000000000000..03e558b58a8e --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java @@ -0,0 +1,49 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.template; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.storage.Storage; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateTemplateCmdTest { + + @Test + public void testGetTemplateType() { + UpdateTemplateCmd cmd = new UpdateTemplateCmd(); + ReflectionTestUtils.setField(cmd, "templateType", null); + Assert.assertNull(cmd.getTemplateType()); + String type = Storage.TemplateType.ROUTING.toString(); + ReflectionTestUtils.setField(cmd, "templateTag", type); + Assert.assertEquals(type, cmd.getTemplateTag()); + } + + @Test + public void testGetTemplateTag() { + UpdateTemplateCmd cmd = new UpdateTemplateCmd(); + ReflectionTestUtils.setField(cmd, "templateTag", null); + Assert.assertNull(cmd.getTemplateTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "templateTag", tag); + Assert.assertEquals(tag, cmd.getTemplateTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java index 2fdef2acaa91..99bc9d2b3fb7 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java @@ -23,6 +23,7 @@ import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -31,8 +32,6 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import java.security.InvalidParameterException; - public class CreateVMScheduleCmdTest { @Mock public VMScheduleManager vmScheduleManager; @@ -41,9 +40,16 @@ public class CreateVMScheduleCmdTest { @InjectMocks private CreateVMScheduleCmd createVMScheduleCmd = new CreateVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** @@ -62,11 +68,11 @@ public void testSuccessfulExecution() { /** * given: "We have a VMScheduleManager and CreateVMScheduleCmd" * when: "CreateVMScheduleCmd is executed with an invalid parameter" - * then: "an InvalidParameterException is thrown" + * then: "an InvalidParameterValueException is thrown" */ - @Test(expected = InvalidParameterException.class) - public void testInvalidParameterException() { - Mockito.when(vmScheduleManager.createSchedule(createVMScheduleCmd)).thenThrow(InvalidParameterException.class); + @Test(expected = InvalidParameterValueException.class) + public void testInvalidParameterValueException() { + Mockito.when(vmScheduleManager.createSchedule(createVMScheduleCmd)).thenThrow(InvalidParameterValueException.class); createVMScheduleCmd.execute(); } @@ -86,7 +92,7 @@ public void testSuccessfulGetEntityOwnerId() { /** * given: "We have an EntityManager and CreateVMScheduleCmd" * when: "CreateVMScheduleCmd.getEntityOwnerId is executed for a VM which doesn't exist" - * then: "an InvalidParameterException is thrown" + * then: "an InvalidParameterValueException is thrown" */ @Test(expected = InvalidParameterValueException.class) public void testFailureGetEntityOwnerId() { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java index 6adfc2b905cb..1f764a84365f 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java @@ -25,6 +25,7 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.vm.schedule.VMSchedule; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -33,8 +34,6 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import java.security.InvalidParameterException; - public class DeleteVMScheduleCmdTest { @Mock public VMScheduleManager vmScheduleManager; @@ -44,9 +43,16 @@ public class DeleteVMScheduleCmdTest { @InjectMocks private DeleteVMScheduleCmd deleteVMScheduleCmd = new DeleteVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** @@ -81,11 +87,11 @@ public void testServerApiException() { /** * given: "We have a VMScheduleManager and DeleteVMScheduleCmd" * when: "DeleteVMScheduleCmd is executed with an invalid parameter" - * then: "an InvalidParameterException is thrown" + * then: "an InvalidParameterValueException is thrown" */ - @Test(expected = InvalidParameterException.class) - public void testInvalidParameterException() { - Mockito.when(vmScheduleManager.removeSchedule(deleteVMScheduleCmd)).thenThrow(InvalidParameterException.class); + @Test(expected = InvalidParameterValueException.class) + public void testInvalidParameterValueException() { + Mockito.when(vmScheduleManager.removeSchedule(deleteVMScheduleCmd)).thenThrow(InvalidParameterValueException.class); deleteVMScheduleCmd.execute(); } @@ -105,7 +111,7 @@ public void testSuccessfulGetEntityOwnerId() { /** * given: "We have an EntityManager and DeleteVMScheduleCmd" * when: "DeleteVMScheduleCmd.getEntityOwnerId is executed for a VM which doesn't exist" - * then: "an InvalidParameterException is thrown" + * then: "an InvalidParameterValueException is thrown" */ @Test(expected = InvalidParameterValueException.class) public void testFailureGetEntityOwnerId() { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java index 18657b4c397c..f5434de3581c 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java @@ -18,9 +18,11 @@ */ package org.apache.cloudstack.api.command.user.vm; +import com.cloud.exception.InvalidParameterValueException; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -29,7 +31,6 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.Collections; @@ -38,10 +39,16 @@ public class ListVMScheduleCmdTest { public VMScheduleManager vmScheduleManager; @InjectMocks private ListVMScheduleCmd listVMScheduleCmd = new ListVMScheduleCmd(); + private AutoCloseable closeable; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** @@ -81,11 +88,11 @@ public void testNonEmptyResponse() { /** * given: "We have a VMScheduleManager and ListVMScheduleCmd" * when: "ListVMScheduleCmd is executed with an invalid parameter" - * then: "an InvalidParameterException is thrown" + * then: "an InvalidParameterValueException is thrown" */ - @Test(expected = InvalidParameterException.class) - public void testInvalidParameterException() { - Mockito.when(vmScheduleManager.listSchedule(listVMScheduleCmd)).thenThrow(InvalidParameterException.class); + @Test(expected = InvalidParameterValueException.class) + public void testInvalidParameterValueException() { + Mockito.when(vmScheduleManager.listSchedule(listVMScheduleCmd)).thenThrow(InvalidParameterValueException.class); listVMScheduleCmd.execute(); ListResponse actualResponseObject = (ListResponse) listVMScheduleCmd.getResponseObject(); } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java index 044685b579cb..2c6c485f25bf 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java @@ -24,6 +24,7 @@ import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMSchedule; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -32,8 +33,6 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import java.security.InvalidParameterException; - public class UpdateVMScheduleCmdTest { @Mock public VMScheduleManager vmScheduleManager; @@ -42,9 +41,16 @@ public class UpdateVMScheduleCmdTest { @InjectMocks private UpdateVMScheduleCmd updateVMScheduleCmd = new UpdateVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** @@ -63,11 +69,11 @@ public void testSuccessfulExecution() { /** * given: "We have a VMScheduleManager and UpdateVMScheduleCmd" * when: "UpdateVMScheduleCmd is executed with an invalid parameter" - * then: "an InvalidParameterException is thrown" + * then: "an InvalidParameterValueException is thrown" */ - @Test(expected = InvalidParameterException.class) - public void testInvalidParameterException() { - Mockito.when(vmScheduleManager.updateSchedule(updateVMScheduleCmd)).thenThrow(InvalidParameterException.class); + @Test(expected = InvalidParameterValueException.class) + public void testInvalidParameterValueException() { + Mockito.when(vmScheduleManager.updateSchedule(updateVMScheduleCmd)).thenThrow(InvalidParameterValueException.class); updateVMScheduleCmd.execute(); } @@ -91,7 +97,7 @@ public void testSuccessfulGetEntityOwnerId() { /** * given: "We have an EntityManager and UpdateVMScheduleCmd" * when: "UpdateVMScheduleCmd.getEntityOwnerId is executed for a VM Schedule which doesn't exist" - * then: "an InvalidParameterException is thrown" + * then: "an InvalidParameterValueException is thrown" */ @Test(expected = InvalidParameterValueException.class) public void testFailureGetEntityOwnerId() { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java index a28e9e9fd04f..2505c67e87db 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java @@ -86,6 +86,20 @@ public void testGetCidr() { Assert.assertEquals(cmd.getCidr(), cidr); } + @Test + public void testGetCidrSize() { + int cidrSize = 24; + ReflectionTestUtils.setField(cmd, "cidrSize", cidrSize); + Assert.assertEquals(cidrSize, (int) cmd.getCidrSize()); + } + + @Test + public void testAsNumber() { + long asNumber = 10000; + ReflectionTestUtils.setField(cmd, "asNumber", asNumber); + Assert.assertEquals(asNumber, (long) cmd.getAsNumber()); + } + @Test public void testGetDisplayText() { String displayText = "VPC Network"; diff --git a/api/src/test/java/org/apache/cloudstack/api/response/ASNRangeResponseTest.java b/api/src/test/java/org/apache/cloudstack/api/response/ASNRangeResponseTest.java new file mode 100644 index 000000000000..50248383b4f1 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/response/ASNRangeResponseTest.java @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Date; + +@RunWith(MockitoJUnitRunner.class) +public final class ASNRangeResponseTest { + + private static String uuid = "uuid"; + private static String zoneId = "zoneid"; + private static long startASNumber = 10; + private static long endASNumber = 20; + private static Date created = new Date(); + + @Test + public void testASNRangeResponse() { + final ASNRangeResponse response = new ASNRangeResponse(); + + response.setId(uuid); + response.setZoneId(zoneId); + response.setStartASNumber(startASNumber); + response.setEndASNumber(endASNumber); + response.setCreated(created); + + Assert.assertEquals(uuid, response.getId()); + Assert.assertEquals(zoneId, response.getZoneId()); + Assert.assertEquals(startASNumber, (long) response.getStartASNumber()); + Assert.assertEquals(endASNumber, (long) response.getEndASNumber()); + Assert.assertEquals(created, response.getCreated()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/response/ASNumberResponseTest.java b/api/src/test/java/org/apache/cloudstack/api/response/ASNumberResponseTest.java new file mode 100644 index 000000000000..9515984134eb --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/response/ASNumberResponseTest.java @@ -0,0 +1,92 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Date; + +@RunWith(MockitoJUnitRunner.class) +public final class ASNumberResponseTest { + + private static String uuid = "uuid"; + private static String accountId = "account-id"; + private static String accountName = "account-name"; + private static String domainId = "domain-uuid"; + private static String domainName = "domain-name"; + private static Long asNumber = 15000L; + private static String asNumberRangeId = "as-number-range-uuid"; + private static String asNumberRange = "10000-20000"; + private static String zoneId = "zone-id"; + private static String zoneName = "zone-name"; + private static Date allocated = new Date(); + private static String allocationState = "allocated"; + + private static String associatedNetworkId = "network-id"; + + private static String associatedNetworkName = "network-name"; + + private static String vpcId = "vpc-uuid"; + private static String vpcName = "vpc-name"; + private static Date created = new Date(); + + + + @Test + public void testASNumberResponse() { + final ASNumberResponse response = new ASNumberResponse(); + + response.setId(uuid); + response.setAccountId(accountId); + response.setAccountName(accountName); + response.setDomainId(domainId); + response.setDomainName(domainName); + response.setAsNumber(asNumber); + response.setAsNumberRangeId(asNumberRangeId); + response.setAsNumberRange(asNumberRange); + response.setZoneId(zoneId); + response.setZoneName(zoneName); + response.setAllocated(allocated); + response.setAllocationState(allocationState); + response.setAssociatedNetworkId(associatedNetworkId); + response.setAssociatedNetworkName(associatedNetworkName); + response.setVpcId(vpcId); + response.setVpcName(vpcName); + response.setCreated(created); + + Assert.assertEquals(uuid, response.getId()); + Assert.assertEquals(accountId, response.getAccountId()); + Assert.assertEquals(accountName, response.getAccountName()); + Assert.assertEquals(domainId, response.getDomainId()); + Assert.assertEquals(domainName, response.getDomainName()); + Assert.assertEquals(asNumber, response.getAsNumber()); + Assert.assertEquals(asNumberRangeId, response.getAsNumberRangeId()); + Assert.assertEquals(asNumberRange, response.getAsNumberRange()); + Assert.assertEquals(zoneId, response.getZoneId()); + Assert.assertEquals(zoneName, response.getZoneName()); + Assert.assertEquals(allocated, response.getAllocated()); + Assert.assertEquals(allocationState, response.getAllocationState()); + Assert.assertEquals(associatedNetworkId, response.getAssociatedNetworkId()); + Assert.assertEquals(associatedNetworkName, response.getAssociatedNetworkName()); + Assert.assertEquals(vpcId, response.getVpcId()); + Assert.assertEquals(vpcName, response.getVpcName()); + Assert.assertEquals(created, response.getCreated()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/response/BgpPeerResponseTest.java b/api/src/test/java/org/apache/cloudstack/api/response/BgpPeerResponseTest.java new file mode 100644 index 000000000000..7c82eb843685 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/response/BgpPeerResponseTest.java @@ -0,0 +1,81 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@RunWith(MockitoJUnitRunner.class) +public final class BgpPeerResponseTest { + + private static String uuid = "uuid"; + private static String ip4Address = "ip4-address"; + private static String ip6Address = "ip6-address"; + private static Long asNumber = 15000L; + private static String password = "password"; + private static String accountName = "account-name"; + private static String domainId = "domain-uuid"; + private static String domainName = "domain-name"; + private static String projectId = "project-uuid"; + private static String projectName = "project-name"; + private static String zoneId = "zone-id"; + private static String zoneName = "zone-name"; + private static Date created = new Date(); + + @Test + public void testBgpPeerResponse() { + final BgpPeerResponse response = new BgpPeerResponse(); + + response.setId(uuid); + response.setIp4Address(ip4Address); + response.setIp6Address(ip6Address); + response.setAsNumber(asNumber); + response.setPassword(password); + response.setAccountName(accountName); + response.setDomainId(domainId); + response.setDomainName(domainName); + response.setProjectId(projectId); + response.setProjectName(projectName); + response.setZoneId(zoneId); + response.setZoneName(zoneName); + response.setCreated(created); + Map details = new HashMap<>(); + details.put("key", "value"); + response.setDetails(details); + + Assert.assertEquals(uuid, response.getId()); + Assert.assertEquals(ip4Address, response.getIp4Address()); + Assert.assertEquals(ip6Address, response.getIp6Address()); + Assert.assertEquals(asNumber, response.getAsNumber()); + Assert.assertEquals(password, response.getPassword()); + Assert.assertEquals(accountName, response.getAccountName()); + Assert.assertEquals(domainId, response.getDomainId()); + Assert.assertEquals(domainName, response.getDomainName()); + Assert.assertEquals(projectId, response.getProjectId()); + Assert.assertEquals(projectName, response.getProjectName()); + Assert.assertEquals(zoneId, response.getZoneId()); + Assert.assertEquals(zoneName, response.getZoneName()); + Assert.assertEquals(created, response.getCreated()); + Assert.assertEquals(details, response.getDetails()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/response/DataCenterIpv4SubnetResponseTest.java b/api/src/test/java/org/apache/cloudstack/api/response/DataCenterIpv4SubnetResponseTest.java new file mode 100644 index 000000000000..add9544de7d3 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/response/DataCenterIpv4SubnetResponseTest.java @@ -0,0 +1,66 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Date; + +@RunWith(MockitoJUnitRunner.class) +public final class DataCenterIpv4SubnetResponseTest { + + private static String uuid = "uuid"; + private static String subnet = "10.10.10.0/26"; + private static String accountName = "account-name"; + private static String domainId = "domain-uuid"; + private static String domainName = "domain-name"; + private static String projectId = "project-uuid"; + private static String projectName = "project-name"; + private static String zoneId = "zone-id"; + private static String zoneName = "zone-name"; + private static Date created = new Date(); + + @Test + public void testDataCenterIpv4SubnetResponse() { + final DataCenterIpv4SubnetResponse response = new DataCenterIpv4SubnetResponse(); + + response.setId(uuid); + response.setSubnet(subnet); + response.setAccountName(accountName); + response.setDomainId(domainId); + response.setDomainName(domainName); + response.setProjectId(projectId); + response.setProjectName(projectName); + response.setZoneId(zoneId); + response.setZoneName(zoneName); + response.setCreated(created); + + Assert.assertEquals(uuid, response.getId()); + Assert.assertEquals(subnet, response.getSubnet()); + Assert.assertEquals(accountName, response.getAccountName()); + Assert.assertEquals(domainId, response.getDomainId()); + Assert.assertEquals(domainName, response.getDomainName()); + Assert.assertEquals(projectId, response.getProjectId()); + Assert.assertEquals(projectName, response.getProjectName()); + Assert.assertEquals(zoneId, response.getZoneId()); + Assert.assertEquals(zoneName, response.getZoneName()); + Assert.assertEquals(created, response.getCreated()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/response/Ipv4RouteResponseTest.java b/api/src/test/java/org/apache/cloudstack/api/response/Ipv4RouteResponseTest.java new file mode 100644 index 000000000000..717668d054e6 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/response/Ipv4RouteResponseTest.java @@ -0,0 +1,48 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public final class Ipv4RouteResponseTest { + + private static String subnet = "10.10.10.0/24"; + private static String gateway = "10.10.10.1"; + + @Test + public void testIpv4RouteResponse() { + final Ipv4RouteResponse response = new Ipv4RouteResponse(subnet, gateway); + + Assert.assertEquals(subnet, response.getSubnet()); + Assert.assertEquals(gateway, response.getGateway()); + } + + @Test + public void testIpv4RouteResponse2() { + final Ipv4RouteResponse response = new Ipv4RouteResponse(); + + response.setSubnet(subnet); + response.setGateway(gateway); + + Assert.assertEquals(subnet, response.getSubnet()); + Assert.assertEquals(gateway, response.getGateway()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/response/Ipv4SubnetForGuestNetworkResponseTest.java b/api/src/test/java/org/apache/cloudstack/api/response/Ipv4SubnetForGuestNetworkResponseTest.java new file mode 100644 index 000000000000..6fb5141e7a98 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/response/Ipv4SubnetForGuestNetworkResponseTest.java @@ -0,0 +1,81 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Date; + +@RunWith(MockitoJUnitRunner.class) +public final class Ipv4SubnetForGuestNetworkResponseTest { + + private static String uuid = "uuid"; + private static String parentId = "parent-id"; + private static String parentSubnet = "10.10.0.0/20"; + private static String subnet = "10.10.0.0/24"; + private static String state = "Allocating"; + + private static String zoneId = "zone-id"; + private static String zoneName = "zone-name"; + private static Date allocated = new Date(); + private static String networkId = "network-id"; + private static String networkName = "network-name"; + private static String vpcId = "vpc-uuid"; + private static String vpcName = "vpc-name"; + private static Date created = new Date(); + private static Date removed = new Date(); + + + + @Test + public void testIpv4SubnetForGuestNetworkResponse() { + final Ipv4SubnetForGuestNetworkResponse response = new Ipv4SubnetForGuestNetworkResponse(); + + response.setId(uuid); + response.setSubnet(subnet); + response.setParentId(parentId); + response.setParentSubnet(parentSubnet); + response.setState(state); + response.setZoneId(zoneId); + response.setZoneName(zoneName); + response.setAllocatedTime(allocated); + response.setNetworkId(networkId); + response.setNetworkName(networkName); + response.setVpcId(vpcId); + response.setVpcName(vpcName); + response.setCreated(created); + response.setRemoved(removed); + + Assert.assertEquals(uuid, response.getId()); + Assert.assertEquals(subnet, response.getSubnet()); + Assert.assertEquals(parentId, response.getParentId()); + Assert.assertEquals(parentSubnet, response.getParentSubnet()); + Assert.assertEquals(state, response.getState()); + Assert.assertEquals(zoneId, response.getZoneId()); + Assert.assertEquals(zoneName, response.getZoneName()); + Assert.assertEquals(allocated, response.getAllocatedTime()); + Assert.assertEquals(networkId, response.getNetworkId()); + Assert.assertEquals(networkName, response.getNetworkName()); + Assert.assertEquals(vpcId, response.getVpcId()); + Assert.assertEquals(vpcName, response.getVpcName()); + Assert.assertEquals(created, response.getCreated()); + Assert.assertEquals(removed, response.getRemoved()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java b/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java index eb1336f90e97..d3537d6f8317 100644 --- a/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java +++ b/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.Account; import com.cloud.user.User; diff --git a/api/src/test/java/org/apache/cloudstack/network/BgpPeerTOTest.java b/api/src/test/java/org/apache/cloudstack/network/BgpPeerTOTest.java new file mode 100644 index 000000000000..2d1f8868ffc4 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/network/BgpPeerTOTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class BgpPeerTOTest { + + private static Long peerId = 100L; + private static String ip4Address = "ip4-address"; + private static String ip6Address = "ip6-address"; + private static Long peerAsNumber = 15000L; + private static String peerPassword = "peer-password"; + private static Long networkId = 200L; + private static Long networkAsNumber = 20000L; + private static String guestIp4Cidr = "10.10.10.0/24"; + private static String guestIp6Cidr = "fd00:1111:2222:3333::1/64"; + + @Test + public void testBgpPeerTO1() { + BgpPeerTO bgpPeerTO = new BgpPeerTO(networkId); + + Assert.assertEquals(networkId, bgpPeerTO.getNetworkId()); + } + + @Test + public void testBgpPeerTO2() { + Map details = new HashMap<>(); + details.put(BgpPeer.Detail.EBGP_MultiHop, "100"); + + BgpPeerTO bgpPeerTO = new BgpPeerTO(peerId, ip4Address, ip6Address, peerAsNumber, peerPassword, + networkId, networkAsNumber, guestIp4Cidr, guestIp6Cidr, details); + + Assert.assertEquals(peerId, bgpPeerTO.getPeerId()); + Assert.assertEquals(peerAsNumber, bgpPeerTO.getPeerAsNumber()); + Assert.assertEquals(ip4Address, bgpPeerTO.getIp4Address()); + Assert.assertEquals(ip6Address, bgpPeerTO.getIp6Address()); + Assert.assertEquals(peerPassword, bgpPeerTO.getPeerPassword()); + Assert.assertEquals(networkId, bgpPeerTO.getNetworkId()); + Assert.assertEquals(networkAsNumber, bgpPeerTO.getNetworkAsNumber()); + Assert.assertEquals(guestIp4Cidr, bgpPeerTO.getGuestIp4Cidr()); + Assert.assertEquals(guestIp6Cidr, bgpPeerTO.getGuestIp6Cidr()); + + Assert.assertNotNull(bgpPeerTO.getDetails()); + details = bgpPeerTO.getDetails(); + Assert.assertEquals(1, details.size()); + Assert.assertEquals("100", details.get(BgpPeer.Detail.EBGP_MultiHop)); + } +} diff --git a/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/build/replace.properties b/build/replace.properties index 3d9a45970600..ce38727b80a7 100644 --- a/build/replace.properties +++ b/build/replace.properties @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/client/bindir/cloud-update-xenserver-licenses.in b/client/bindir/cloud-update-xenserver-licenses.in index 9ce1898dc817..2be3a083f973 100755 --- a/client/bindir/cloud-update-xenserver-licenses.in +++ b/client/bindir/cloud-update-xenserver-licenses.in @@ -7,9 +7,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -46,7 +46,7 @@ cfg = "@MSCONF@/db.properties" #---------------------- option parsing and command line checks ------------------------ -usage = """%prog <-a | host names / IP addresses...> +usage = """%prog <-a | host names / IP addresses...> This command deploys the license file specified in the command line into a specific XenServer host or all XenServer hosts known to the management server.""" @@ -88,7 +88,7 @@ def parseuserpwfromhosts(hosts): return creds class XenServerConfigurator(Thread): - + def __init__(self,host,user,password,keyfiledata): Thread.__init__(self) self.host = host @@ -99,7 +99,7 @@ class XenServerConfigurator(Thread): self.stdout = "" self.stderr = "" self.state = 'initialized' - + def run(self): try: self.state = 'running' @@ -120,18 +120,18 @@ class XenServerConfigurator(Thread): c.close() if self.retval != 0: self.state = 'failed' else: self.state = 'finished' - + except Exception as e: self.state = 'failed' self.retval = e #raise - + def __str__(self): if self.state == 'failed': return "<%s XenServerConfigurator on %s@%s: %s>"%(self.state,self.user,self.host,str(self.retval)) else: return "<%s XenServerConfigurator on %s@%s>"%(self.state,self.user,self.host) - + #------------- actual code -------------------- (options, args) = parser.parse_args() @@ -162,7 +162,7 @@ for host,(user,password) in list(creds.items()): for c in configurators: c.start() - + for c in configurators: print(c.host + "...", end=' ') c.join() diff --git a/client/conf/db.properties.in b/client/conf/db.properties.in index 8f31aff17e63..0f7d2706a427 100644 --- a/client/conf/db.properties.in +++ b/client/conf/db.properties.in @@ -34,10 +34,14 @@ db.cloud.uri= # CloudStack database tuning parameters +db.cloud.connectionPoolLib=hikaricp db.cloud.maxActive=250 db.cloud.maxIdle=30 -db.cloud.maxWait=10000 -db.cloud.validationQuery=SELECT 1 +db.cloud.maxWait=600000 +db.cloud.minIdleConnections=5 +db.cloud.connectionTimeout=30000 +db.cloud.keepAliveTime=600000 +db.cloud.validationQuery=/* ping */ SELECT 1 db.cloud.testOnBorrow=true db.cloud.testWhileIdle=true db.cloud.timeBetweenEvictionRunsMillis=40000 @@ -70,9 +74,13 @@ db.usage.uri= # usage database tuning parameters +db.usage.connectionPoolLib=hikaricp db.usage.maxActive=100 db.usage.maxIdle=30 -db.usage.maxWait=10000 +db.usage.maxWait=600000 +db.usage.minIdleConnections=5 +db.usage.connectionTimeout=30000 +db.usage.keepAliveTime=600000 db.usage.url.params=serverTimezone=UTC # Simulator database settings @@ -82,9 +90,13 @@ db.simulator.host=@DBHOST@ db.simulator.driver=@DBDRIVER@ db.simulator.port=3306 db.simulator.name=simulator +db.simulator.connectionPoolLib=hikaricp db.simulator.maxActive=250 db.simulator.maxIdle=30 -db.simulator.maxWait=10000 +db.simulator.maxWait=600000 +db.simulator.minIdleConnections=5 +db.simulator.connectionTimeout=30000 +db.simulator.keepAliveTime=600000 db.simulator.autoReconnect=true # Connection URI to the database "simulator". When this property is set, only the following properties will be used along with it: db.simulator.host, db.simulator.port, db.simulator.name, db.simulator.autoReconnect. Other properties will be ignored. diff --git a/client/conf/log4j-cloud.xml.in b/client/conf/log4j-cloud.xml.in index 223692881dea..26da171269de 100755 --- a/client/conf/log4j-cloud.xml.in +++ b/client/conf/log4j-cloud.xml.in @@ -17,183 +17,118 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + net.sf.cglib.proxy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/pom.xml b/client/pom.xml index 53baebbc2b4d..d89dbbbbe9d6 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT @@ -422,6 +422,11 @@ cloud-mom-kafka ${project.version} + + org.apache.cloudstack + cloud-mom-webhook + ${project.version} + org.apache.cloudstack cloud-framework-agent-lb @@ -607,6 +612,11 @@ cloud-plugin-backup-networker ${project.version} + + org.apache.cloudstack + cloud-plugin-backup-nas + ${project.version} + org.apache.cloudstack cloud-plugin-integrations-kubernetes-service @@ -627,11 +637,21 @@ cloud-plugin-storage-object-minio ${project.version} + + org.apache.cloudstack + cloud-plugin-storage-object-ceph + ${project.version} + org.apache.cloudstack cloud-plugin-storage-object-simulator ${project.version} + + org.apache.cloudstack + cloud-plugin-sharedfs-provider-storagevm + ${project.version} + org.apache.cloudstack cloud-usage @@ -727,7 +747,7 @@ - log4j.configuration + log4j2.configurationFile log4j-cloud.xml @@ -1072,6 +1092,11 @@ cloud-plugin-network-cisco-vnmc ${project.version} + + org.apache.cloudstack + cloud-plugin-network-nsx + ${project.version} + org.apache.cloudstack cloud-plugin-network-tungsten diff --git a/client/src/main/java/org/apache/cloudstack/ServerDaemon.java b/client/src/main/java/org/apache/cloudstack/ServerDaemon.java index fb84e1297e6d..d2e4483835ec 100644 --- a/client/src/main/java/org/apache/cloudstack/ServerDaemon.java +++ b/client/src/main/java/org/apache/cloudstack/ServerDaemon.java @@ -29,7 +29,6 @@ import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.DaemonContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.eclipse.jetty.jmx.MBeanContainer; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -50,6 +49,8 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.webapp.WebAppContext; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.Pair; import com.cloud.utils.PropertiesUtil; @@ -61,7 +62,7 @@ * Configuration parameters are read from server.properties file available on the classpath. */ public class ServerDaemon implements Daemon { - private static final Logger LOG = Logger.getLogger(ServerDaemon.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String WEB_XML = "META-INF/webapp/WEB-INF/web.xml"; ///////////////////////////////////////////////////// @@ -115,12 +116,12 @@ public static void main(final String... anArgs) throws Exception { public void init(final DaemonContext context) { final File confFile = PropertiesUtil.findConfigFile("server.properties"); if (confFile == null) { - LOG.warn(String.format("Server configuration file not found. Initializing server daemon on %s, with http.enable=%s, http.port=%s, https.enable=%s, https.port=%s, context.path=%s", + logger.warn(String.format("Server configuration file not found. Initializing server daemon on %s, with http.enable=%s, http.port=%s, https.enable=%s, https.port=%s, context.path=%s", bindInterface, httpEnable, httpPort, httpsEnable, httpsPort, contextPath)); return; } - LOG.info("Server configuration file found: " + confFile.getAbsolutePath()); + logger.info("Server configuration file found: " + confFile.getAbsolutePath()); try { InputStream is = new FileInputStream(confFile); @@ -141,15 +142,15 @@ public void init(final DaemonContext context) { setSessionTimeout(Integer.valueOf(properties.getProperty(SESSION_TIMEOUT, "30"))); setMaxFormContentSize(Integer.valueOf(properties.getProperty(REQUEST_CONTENT_SIZE_KEY, String.valueOf(DEFAULT_REQUEST_CONTENT_SIZE)))); } catch (final IOException e) { - LOG.warn("Failed to read configuration from server.properties file", e); + logger.warn("Failed to read configuration from server.properties file", e); } finally { // make sure that at least HTTP is enabled if both of them are set to false (misconfiguration) if (!httpEnable && !httpsEnable) { setHttpEnable(true); - LOG.warn("Server configuration malformed, neither http nor https is enabled, http will be enabled."); + logger.warn("Server configuration malformed, neither http nor https is enabled, http will be enabled."); } } - LOG.info(String.format("Initializing server daemon on %s, with http.enable=%s, http.port=%s, https.enable=%s, https.port=%s, context.path=%s", + logger.info(String.format("Initializing server daemon on %s, with http.enable=%s, http.port=%s, https.enable=%s, https.port=%s, context.path=%s", bindInterface, httpEnable, httpPort, httpsEnable, httpsPort, contextPath)); } @@ -253,7 +254,7 @@ private void createHttpsConnector(final HttpConfiguration httpConfig) { KeyStoreScanner scanner = new KeyStoreScanner(sslContextFactory); server.addBean(scanner); } catch (Exception ex) { - LOG.error("failed to set up keystore scanner, manual refresh of certificates will be required", ex); + logger.error("failed to set up keystore scanner, manual refresh of certificates will be required", ex); } } } diff --git a/client/src/main/resources/META-INF/cloudstack/webApplicationContext.xml b/client/src/main/resources/META-INF/cloudstack/webApplicationContext.xml index 3b3c6dbe35c2..e1c462686189 100644 --- a/client/src/main/resources/META-INF/cloudstack/webApplicationContext.xml +++ b/client/src/main/resources/META-INF/cloudstack/webApplicationContext.xml @@ -25,7 +25,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" - > + > diff --git a/client/src/main/webapp/WEB-INF/web.xml b/client/src/main/webapp/WEB-INF/web.xml index 9a3d8bc5b29a..43bee7e59d88 100644 --- a/client/src/main/webapp/WEB-INF/web.xml +++ b/client/src/main/webapp/WEB-INF/web.xml @@ -21,7 +21,7 @@ version="2.5"> - log4jConfigLocation + log4jConfiguration classpath:log4j-cloud.xml diff --git a/core/pom.xml b/core/pom.xml index cef37268b38a..83cdee8cf4f1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT diff --git a/core/src/main/java/com/cloud/agent/api/ReadyCommand.java b/core/src/main/java/com/cloud/agent/api/ReadyCommand.java index 637e4f54da06..42f1d264a50d 100644 --- a/core/src/main/java/com/cloud/agent/api/ReadyCommand.java +++ b/core/src/main/java/com/cloud/agent/api/ReadyCommand.java @@ -34,6 +34,7 @@ public ReadyCommand() { private String lbAlgorithm; private Long lbCheckInterval; private Boolean enableHumanReadableSizes; + private String arch; public ReadyCommand(Long dcId) { super(); @@ -94,4 +95,12 @@ public void setLbCheckInterval(Long lbCheckInterval) { public Boolean getEnableHumanReadableSizes() { return enableHumanReadableSizes; } + + public String getArch() { + return arch; + } + + public void setArch(String arch) { + this.arch = arch; + } } diff --git a/core/src/main/java/com/cloud/agent/api/SecurityGroupRulesCmd.java b/core/src/main/java/com/cloud/agent/api/SecurityGroupRulesCmd.java index ea4ab96c5a7c..5d202172c35a 100644 --- a/core/src/main/java/com/cloud/agent/api/SecurityGroupRulesCmd.java +++ b/core/src/main/java/com/cloud/agent/api/SecurityGroupRulesCmd.java @@ -27,7 +27,6 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.digest.DigestUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.LogLevel.Log4jLevel; import com.cloud.agent.api.to.VirtualMachineTO; @@ -39,7 +38,6 @@ public class SecurityGroupRulesCmd extends Command { public static final char RULE_COMMAND_SEPARATOR = ';'; protected static final String EGRESS_RULE = "E:"; protected static final String INGRESS_RULE = "I:"; - private static final Logger LOGGER = Logger.getLogger(SecurityGroupRulesCmd.class); private final String guestIp; private final String guestIp6; @@ -233,7 +231,7 @@ public String compressStringifiedRules() { dzip.close(); encodedResult = Base64.encodeBase64String(out.toByteArray()); } catch (final IOException e) { - LOGGER.warn("Exception while compressing security group rules"); + logger.warn("Exception while compressing security group rules"); } return encodedResult; } diff --git a/core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java b/core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java index e9781993239b..06583f2d0d3d 100644 --- a/core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java +++ b/core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java @@ -35,6 +35,7 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand { String routerIpv6 = null; String routerIpv6Gateway = null; String routerIpv6Cidr = null; + boolean isVrGuestGateway = false; public NicTO getNic() { return nic; @@ -114,4 +115,12 @@ public void setDefaultIp6Dns1(String defaultIp6Dns1) { public void setDefaultIp6Dns2(String defaultIp6Dns2) { this.defaultIp6Dns2 = defaultIp6Dns2; } + + public boolean isVrGuestGateway() { + return isVrGuestGateway; + } + + public void setVrGuestGateway(boolean vrGuestGateway) { + isVrGuestGateway = vrGuestGateway; + } } diff --git a/core/src/main/java/com/cloud/agent/api/StartupCommand.java b/core/src/main/java/com/cloud/agent/api/StartupCommand.java index 5f2c00d0be63..cca5e16b5854 100644 --- a/core/src/main/java/com/cloud/agent/api/StartupCommand.java +++ b/core/src/main/java/com/cloud/agent/api/StartupCommand.java @@ -47,6 +47,7 @@ public class StartupCommand extends Command { String resourceName; String gatewayIpAddress; String msHostList; + String arch; public StartupCommand(Host.Type type) { this.type = type; @@ -290,6 +291,14 @@ public void setMSHostList(String msHostList) { this.msHostList = msHostList; } + public String getArch() { + return arch; + } + + public void setArch(String arch) { + this.arch = arch; + } + @Override public boolean executeInSequence() { return false; diff --git a/core/src/main/java/com/cloud/agent/api/StartupRoutingCommand.java b/core/src/main/java/com/cloud/agent/api/StartupRoutingCommand.java index b4f9d20df5ed..286fced0c58a 100644 --- a/core/src/main/java/com/cloud/agent/api/StartupRoutingCommand.java +++ b/core/src/main/java/com/cloud/agent/api/StartupRoutingCommand.java @@ -32,6 +32,7 @@ public class StartupRoutingCommand extends StartupCommand { Integer cpuSockets; int cpus; long speed; + String cpuArch; long memory; long dom0MinMemory; boolean poolSync; @@ -174,6 +175,10 @@ public void setHostTags(String hostTag) { this.hostTags.add(hostTag); } + public void setHostTags(List hostTags) { + this.hostTags = hostTags; + } + public HashMap> getGpuGroupDetails() { return groupDetails; } @@ -197,4 +202,12 @@ public Boolean getHostHealthCheckResult() { public void setHostHealthCheckResult(Boolean hostHealthCheckResult) { this.hostHealthCheckResult = hostHealthCheckResult; } + + public String getCpuArch() { + return cpuArch; + } + + public void setCpuArch(String cpuArch) { + this.cpuArch = cpuArch; + } } diff --git a/core/src/main/java/com/cloud/agent/api/routing/SetBgpPeersAnswer.java b/core/src/main/java/com/cloud/agent/api/routing/SetBgpPeersAnswer.java new file mode 100644 index 000000000000..9645b300db59 --- /dev/null +++ b/core/src/main/java/com/cloud/agent/api/routing/SetBgpPeersAnswer.java @@ -0,0 +1,46 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.agent.api.routing; + +import java.util.Arrays; + +import com.cloud.agent.api.Answer; + +public class SetBgpPeersAnswer extends Answer { + String[] results; + + protected SetBgpPeersAnswer() { + } + + public SetBgpPeersAnswer(SetBgpPeersCommand cmd, boolean success, String[] results) { + super(cmd, success, null); + if (results != null) { + assert (cmd.getBpgPeers().length == results.length) : "BGP peers and their results should be the same length"; + this.results = Arrays.copyOf(results, results.length); + } + } + + public String[] getResults() { + if (results != null) { + return Arrays.copyOf(results, results.length); + } + return null; + } +} diff --git a/core/src/main/java/com/cloud/agent/api/routing/SetBgpPeersCommand.java b/core/src/main/java/com/cloud/agent/api/routing/SetBgpPeersCommand.java new file mode 100644 index 000000000000..36371a196c81 --- /dev/null +++ b/core/src/main/java/com/cloud/agent/api/routing/SetBgpPeersCommand.java @@ -0,0 +1,39 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.agent.api.routing; + +import java.util.List; + +import org.apache.cloudstack.network.BgpPeerTO; + +public class SetBgpPeersCommand extends NetworkElementCommand { + BgpPeerTO[] bpgPeers; + + protected SetBgpPeersCommand() { + } + + public SetBgpPeersCommand(List bpgPeers) { + this.bpgPeers = bpgPeers.toArray(new BgpPeerTO[bpgPeers.size()]); + } + + public BgpPeerTO[] getBpgPeers() { + return bpgPeers; + } +} diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VRScripts.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VRScripts.java index e435c838b7de..f9ea3e05e97f 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VRScripts.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VRScripts.java @@ -41,6 +41,7 @@ public class VRScripts { public static final String DHCP_CONFIG = "dhcp.json"; public static final String IP_ALIAS_CONFIG = "ip_aliases.json"; public static final String LOAD_BALANCER_CONFIG = "load_balancer.json"; + public static final String BGP_PEERS_CONFIG = "bgp_peers.json"; public static final String SYSTEM_VM_PATCHED = "patched.sh"; public final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/"; diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index 3e085fb0971b..4afac9b43cb3 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -52,7 +52,8 @@ import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.net.util.SubnetUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.joda.time.Duration; import com.cloud.agent.api.Answer; @@ -86,7 +87,7 @@ **/ public class VirtualRoutingResource { - private static final Logger s_logger = Logger.getLogger(VirtualRoutingResource.class); + protected Logger logger = LogManager.getLogger(getClass()); private VirtualRouterDeployer _vrDeployer; private Map> _vrAggregateCommandsSet; protected Map _vrLockMap = new HashMap(); @@ -118,7 +119,7 @@ public Answer executeRequest(final NetworkElementCommand cmd) { try { ExecutionResult rc = _vrDeployer.prepareCommand(cmd); if (!rc.isSuccess()) { - s_logger.error("Failed to prepare VR command due to " + rc.getDetails()); + logger.error("Failed to prepare VR command due to " + rc.getDetails()); return new Answer(cmd, false, rc.getDetails()); } @@ -169,7 +170,7 @@ public Answer executeRequest(final NetworkElementCommand cmd) { if (!aggregated) { ExecutionResult rc = _vrDeployer.cleanupCommand(cmd); if (!rc.isSuccess()) { - s_logger.error("Failed to cleanup VR command due to " + rc.getDetails()); + logger.error("Failed to cleanup VR command due to " + rc.getDetails()); } } } @@ -225,15 +226,15 @@ private Answer executeQueryCommand(NetworkElementCommand cmd) { } else if (cmd instanceof GetRouterMonitorResultsCommand) { return execute((GetRouterMonitorResultsCommand)cmd); } else { - s_logger.error("Unknown query command in VirtualRoutingResource!"); + logger.error("Unknown query command in VirtualRoutingResource!"); return Answer.createUnsupportedCommandAnswer(cmd); } } - private static String getRouterSshControlIp(NetworkElementCommand cmd) { + private String getRouterSshControlIp(NetworkElementCommand cmd) { String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); - if (s_logger.isDebugEnabled()) - s_logger.debug("Use router's private IP for SSH control. IP : " + routerIp); + if (logger.isDebugEnabled()) + logger.debug("Use router's private IP for SSH control. IP : " + routerIp); return routerIp; } @@ -248,24 +249,24 @@ private Answer execute(UpdateNetworkCommand cmd) { String subnet = address.split("/")[1]; ExecutionResult result = _vrDeployer.executeInVR(routerIp, VRScripts.VR_UPDATE_INTERFACE_CONFIG, ipAddressTO.getPublicIp() + " " + subnet + " " + ipAddressTO.getMtu() + " " + 15); - if (s_logger.isDebugEnabled()) - s_logger.debug("result: " + result.isSuccess() + ", output: " + result.getDetails()); + if (logger.isDebugEnabled()) + logger.debug("result: " + result.isSuccess() + ", output: " + result.getDetails()); if (!Boolean.TRUE.equals(result.isSuccess())) { if (result.getDetails().contains(String.format("Interface with IP %s not found", ipAddressTO.getPublicIp()))) { - s_logger.warn(String.format("Skipping IP: %s as it isn't configured on router interface", ipAddressTO.getPublicIp())); + logger.warn(String.format("Skipping IP: %s as it isn't configured on router interface", ipAddressTO.getPublicIp())); } else if (ipAddressTO.getDetails().get(ApiConstants.REDUNDANT_STATE).equals(VirtualRouter.RedundantState.PRIMARY.name())) { - s_logger.warn(String.format("Failed to update interface mtu to %s on interface with ip: %s", + logger.warn(String.format("Failed to update interface mtu to %s on interface with ip: %s", ipAddressTO.getMtu(), ipAddressTO.getPublicIp())); finalResult = false; } continue; } - s_logger.info(String.format("Successfully updated mtu to %s on interface with ip: %s", + logger.info(String.format("Successfully updated mtu to %s on interface with ip: %s", ipAddressTO.getMtu(), ipAddressTO.getPublicIp())); finalResult &= true; } catch (Exception e) { String msg = "Prepare UpdateNetwork failed due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, e); } } @@ -315,9 +316,9 @@ private Answer applyConfig(NetworkElementCommand cmd, List cfg) { for (ConfigItem configItem : cfg) { long startTimestamp = System.currentTimeMillis(); ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), configItem, VRScripts.VR_SCRIPT_EXEC_TIMEOUT); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { long elapsed = System.currentTimeMillis() - startTimestamp; - s_logger.debug("Processing " + configItem + " took " + elapsed + "ms"); + logger.debug("Processing " + configItem + " took " + elapsed + "ms"); } if (result == null) { result = new ExecutionResult(false, "null execution result"); @@ -329,7 +330,7 @@ private Answer applyConfig(NetworkElementCommand cmd, List cfg) { // Not sure why this matters, but log it anyway if (cmd.getAnswersCount() != results.size()) { - s_logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size()); + logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size()); } if (results.size() == 1) { @@ -378,7 +379,7 @@ private GetRouterMonitorResultsAnswer parseLinesForHealthChecks(GetRouterMonitor } else if (!readingFailedChecks && readingMonitorResults) { // Reading monitor checks result monitorResults.append(line); } else { - s_logger.error("Unexpected lines reached while parsing health check response. Skipping line:- " + line); + logger.error("Unexpected lines reached while parsing health check response. Skipping line:- " + line); } } @@ -398,16 +399,16 @@ private GetRouterMonitorResultsAnswer execute(GetRouterMonitorResultsCommand cmd } String args = cmd.shouldPerformFreshChecks() ? "true" : "false"; - s_logger.info("Fetching health check result for " + routerIp + " and executing fresh checks: " + args); + logger.info("Fetching health check result for " + routerIp + " and executing fresh checks: " + args); ExecutionResult result = _vrDeployer.executeInVR(routerIp, VRScripts.ROUTER_MONITOR_RESULTS, args); if (!result.isSuccess()) { - s_logger.warn("Result of " + cmd + " failed with details: " + result.getDetails()); + logger.warn("Result of " + cmd + " failed with details: " + result.getDetails()); return new GetRouterMonitorResultsAnswer(cmd, false, null, result.getDetails()); } if (result.getDetails().isEmpty()) { - s_logger.warn("Result of " + cmd + " received no details."); + logger.warn("Result of " + cmd + " received no details."); return new GetRouterMonitorResultsAnswer(cmd, false, null, "No results available."); } @@ -417,12 +418,12 @@ private GetRouterMonitorResultsAnswer execute(GetRouterMonitorResultsCommand cmd private Pair checkRouterFileSystem(String routerIp) { ExecutionResult fileSystemWritableTestResult = _vrDeployer.executeInVR(routerIp, VRScripts.ROUTER_FILESYSTEM_WRITABLE_CHECK, null); if (fileSystemWritableTestResult.isSuccess()) { - s_logger.debug("Router connectivity and file system writable check passed"); + logger.debug("Router connectivity and file system writable check passed"); return new Pair(true, "success"); } String resultDetails = fileSystemWritableTestResult.getDetails(); - s_logger.warn("File system writable check failed with details: " + resultDetails); + logger.warn("File system writable check failed with details: " + resultDetails); if (StringUtils.isNotBlank(resultDetails)) { final String readOnlyFileSystemError = "Read-only file system"; if (resultDetails.contains(readOnlyFileSystemError)) { @@ -507,8 +508,8 @@ public boolean configureHostParams(final Map params) { if (params.get("router.aggregation.command.each.timeout") != null) { String value = (String)params.get("router.aggregation.command.each.timeout"); _eachTimeout = Duration.standardSeconds(NumbersUtil.parseLong(value, 600)); - if (s_logger.isDebugEnabled()){ - s_logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); + if (logger.isDebugEnabled()){ + logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); } } @@ -529,8 +530,8 @@ public boolean configure(final String name, final Map params) th value = (String)params.get("router.aggregation.command.each.timeout"); _eachTimeout = Duration.standardSeconds(NumbersUtil.parseInt(value, (int)VRScripts.VR_SCRIPT_EXEC_TIMEOUT.getStandardSeconds())); - if (s_logger.isDebugEnabled()){ - s_logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); + if (logger.isDebugEnabled()){ + logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); } if (_vrDeployer == null) { @@ -553,8 +554,8 @@ public boolean connect(final String ipAddress, int retry, int sleep) { for (int i = 0; i <= retry; i++) { SocketChannel sch = null; try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Trying to connect to " + ipAddress); + if (logger.isDebugEnabled()) { + logger.debug("Trying to connect to " + ipAddress); } sch = SocketChannel.open(); sch.configureBlocking(true); @@ -563,8 +564,8 @@ public boolean connect(final String ipAddress, int retry, int sleep) { sch.connect(addr); return true; } catch (final IOException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Could not connect to " + ipAddress); + if (logger.isDebugEnabled()) { + logger.debug("Could not connect to " + ipAddress); } } finally { if (sch != null) { @@ -580,7 +581,7 @@ public boolean connect(final String ipAddress, int retry, int sleep) { } } - s_logger.debug("Unable to logon to " + ipAddress); + logger.debug("Unable to logon to " + ipAddress); return false; } @@ -590,7 +591,7 @@ private List generateCommandCfg(NetworkElementCommand cmd) { * [TODO] Still have to migrate LoadBalancerConfigCommand and BumpUpPriorityCommand * [FIXME] Have a look at SetSourceNatConfigItem */ - s_logger.debug("Transforming " + cmd.getClass().getCanonicalName() + " to ConfigItems"); + logger.debug("Transforming " + cmd.getClass().getCanonicalName() + " to ConfigItems"); final AbstractConfigItemFacade configItemFacade = AbstractConfigItemFacade.getInstance(cmd.getClass()); @@ -620,7 +621,7 @@ private Answer execute(AggregationControlCommand cmd) { answerCounts += command.getAnswersCount(); List cfg = generateCommandCfg(command); if (cfg == null) { - s_logger.warn("Unknown commands for VirtualRoutingResource, but continue: " + cmd.toString()); + logger.warn("Unknown commands for VirtualRoutingResource, but continue: " + cmd.toString()); continue; } @@ -635,8 +636,8 @@ private Answer execute(AggregationControlCommand cmd) { ScriptConfigItem scriptConfigItem = new ScriptConfigItem(VRScripts.VR_CFG, "-c " + VRScripts.CONFIG_CACHE_LOCATION + cfgFileName); // 120s is the minimal timeout Duration timeout = _eachTimeout.withDurationAdded(_eachTimeout.getStandardSeconds(), answerCounts); - if (s_logger.isDebugEnabled()){ - s_logger.debug("Aggregate action timeout in seconds is " + timeout.getStandardSeconds()); + if (logger.isDebugEnabled()){ + logger.debug("Aggregate action timeout in seconds is " + timeout.getStandardSeconds()); } ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), fileConfigItem, timeout); diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java index bed472b68808..83dfa2a62caa 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.agent.api.BumpUpPriorityCommand; import com.cloud.agent.api.SetupGuestNetworkCommand; @@ -38,6 +37,7 @@ import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand; import com.cloud.agent.api.routing.SavePasswordCommand; +import com.cloud.agent.api.routing.SetBgpPeersCommand; import com.cloud.agent.api.routing.SetFirewallRulesCommand; import com.cloud.agent.api.routing.SetIpv6FirewallRulesCommand; import com.cloud.agent.api.routing.SetMonitorServiceCommand; @@ -59,10 +59,12 @@ import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public abstract class AbstractConfigItemFacade { - private static final Logger s_logger = Logger.getLogger(AbstractConfigItemFacade.class); + protected Logger logger = LogManager.getLogger(getClass()); private final static Gson gson; @@ -97,6 +99,7 @@ public abstract class AbstractConfigItemFacade { flyweight.put(SetSourceNatCommand.class, new SetSourceNatConfigItem()); flyweight.put(IpAssocCommand.class, new IpAssociationConfigItem()); flyweight.put(IpAssocVpcCommand.class, new IpAssociationConfigItem()); + flyweight.put(SetBgpPeersCommand.class, new SetBgpPeersConfigItem()); } protected String destinationFile; @@ -123,8 +126,8 @@ protected List generateConfigItems(final ConfigBase configuration) { final List cfg = new LinkedList<>(); final String remoteFilename = appendUuidToJsonFiles(destinationFile); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Transformed filename: " + destinationFile + " to: " + remoteFilename); + if (logger.isDebugEnabled()) { + logger.debug("Transformed filename: " + destinationFile + " to: " + remoteFilename); } final ConfigItem configFile = new FileConfigItem(VRScripts.CONFIG_PERSIST_LOCATION, remoteFilename, gson.toJson(configuration)); diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetBgpPeersConfigItem.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetBgpPeersConfigItem.java new file mode 100644 index 000000000000..68f4275bb6be --- /dev/null +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetBgpPeersConfigItem.java @@ -0,0 +1,46 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.agent.resource.virtualnetwork.facade; + +import java.util.Arrays; +import java.util.List; + +import com.cloud.agent.api.routing.NetworkElementCommand; +import com.cloud.agent.api.routing.SetBgpPeersCommand; +import com.cloud.agent.resource.virtualnetwork.ConfigItem; +import com.cloud.agent.resource.virtualnetwork.VRScripts; +import com.cloud.agent.resource.virtualnetwork.model.BgpPeers; +import com.cloud.agent.resource.virtualnetwork.model.ConfigBase; + +public class SetBgpPeersConfigItem extends AbstractConfigItemFacade { + + @Override + public List generateConfig(final NetworkElementCommand cmd) { + final SetBgpPeersCommand command = (SetBgpPeersCommand) cmd; + return generateConfigItems(new BgpPeers(Arrays.asList(command.getBpgPeers()))); + } + + @Override + protected List generateConfigItems(final ConfigBase configuration) { + destinationFile = VRScripts.BGP_PEERS_CONFIG; + + return super.generateConfigItems(configuration); + } +} diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetGuestNetworkConfigItem.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetGuestNetworkConfigItem.java index aee1e7795712..1a6824ceb7fc 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetGuestNetworkConfigItem.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetGuestNetworkConfigItem.java @@ -75,6 +75,7 @@ public List generateConfig(final NetworkElementCommand cmd) { guestNetwork.setRouterIp6(command.getRouterIpv6()); guestNetwork.setRouterIp6Gateway(command.getRouterIpv6Gateway()); guestNetwork.setRouterIp6Cidr(command.getRouterIpv6Cidr()); + guestNetwork.setVrGuestGateway(command.isVrGuestGateway()); return generateConfigItems(guestNetwork); } diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java index 52d8442b5ac6..227675ebf4ed 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java @@ -21,7 +21,6 @@ import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.routing.SetMonitorServiceCommand; @@ -32,7 +31,6 @@ import com.cloud.agent.resource.virtualnetwork.model.MonitorService; public class SetMonitorServiceConfigItem extends AbstractConfigItemFacade { - private static final Logger s_logger = Logger.getLogger(SetMonitorServiceConfigItem.class); @Override public List generateConfig(final NetworkElementCommand cmd) { @@ -58,14 +56,14 @@ private void setupHealthChecksRelatedInfo(MonitorService monitorService, SetMoni try { monitorService.setHealthChecksBasicRunInterval(Integer.parseInt(command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_BASIC_INTERVAL))); } catch (NumberFormatException exception) { - s_logger.error("Unexpected health check basic interval set" + command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_BASIC_INTERVAL) + + logger.error("Unexpected health check basic interval set" + command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_BASIC_INTERVAL) + ". Exception: " + exception + "Will use default value"); } try { monitorService.setHealthChecksAdvancedRunInterval(Integer.parseInt(command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_ADVANCED_INTERVAL))); } catch (NumberFormatException exception) { - s_logger.error("Unexpected health check advanced interval set" + command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_ADVANCED_INTERVAL) + + logger.error("Unexpected health check advanced interval set" + command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_ADVANCED_INTERVAL) + ". Exception: " + exception + "Will use default value"); } diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java index a64328d516af..f4c3275aa2b3 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.routing.SetNetworkACLCommand; @@ -41,7 +40,6 @@ public class SetNetworkAclConfigItem extends AbstractConfigItemFacade { - public static final Logger s_logger = Logger.getLogger(SetNetworkAclConfigItem.class.getName()); @Override public List generateConfig(final NetworkElementCommand cmd) { @@ -81,7 +79,7 @@ public List generateConfig(final NetworkElementCommand cmd) { try { aclRule = new ProtocolAclRule(ruleParts[4], "ACCEPT".equals(ruleParts[5]), Integer.parseInt(ruleParts[1])); } catch (final Exception e) { - s_logger.warn("Problem occurred when reading the entries in the ruleParts array. Actual array size is '" + ruleParts.length + "', but trying to read from index 5."); + logger.warn("Problem occurred when reading the entries in the ruleParts array. Actual array size is '" + ruleParts.length + "', but trying to read from index 5."); continue; } } diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/BgpPeers.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/BgpPeers.java new file mode 100644 index 000000000000..54a1ab2e0915 --- /dev/null +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/BgpPeers.java @@ -0,0 +1,45 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.agent.resource.virtualnetwork.model; + +import org.apache.cloudstack.network.BgpPeerTO; + +import java.util.List; + +public class BgpPeers extends ConfigBase { + private List peers; + + public BgpPeers() { + super(ConfigBase.BGP_PEERS); + } + + public BgpPeers(List bgpPeers) { + super(ConfigBase.BGP_PEERS); + this.peers = bgpPeers; + } + + public List getPeers() { + return peers; + } + + public void setPeers(List bgpPeers) { + this.peers = bgpPeers; + } +} diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java index ade80d71384f..e370b764f226 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/ConfigBase.java @@ -39,6 +39,7 @@ public abstract class ConfigBase { public static final String MONITORSERVICE = "monitorservice"; public static final String DHCP_CONFIG = "dhcpconfig"; public static final String LOAD_BALANCER = "loadbalancer"; + public final static String BGP_PEERS = "bgppeers"; private String type = UNKNOWN; diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java index bb5e443c2e8c..a416b4bc5e41 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java @@ -37,6 +37,7 @@ public class GuestNetwork extends ConfigBase { private String routerIp6; private String routerIp6Gateway; private String routerIp6Cidr; + private boolean isVrGuestGateway; private Integer mtu; @@ -202,4 +203,12 @@ public void setMtu(Integer mtu) { public Integer getMtu() { return mtu; } + + public boolean isVrGuestGateway() { + return isVrGuestGateway; + } + + public void setVrGuestGateway(boolean vrGuestGateway) { + isVrGuestGateway = vrGuestGateway; + } } diff --git a/core/src/main/java/com/cloud/agent/transport/LoggingExclusionStrategy.java b/core/src/main/java/com/cloud/agent/transport/LoggingExclusionStrategy.java index 90e964e71391..2301c1fc205b 100644 --- a/core/src/main/java/com/cloud/agent/transport/LoggingExclusionStrategy.java +++ b/core/src/main/java/com/cloud/agent/transport/LoggingExclusionStrategy.java @@ -19,7 +19,8 @@ package com.cloud.agent.transport; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; @@ -29,7 +30,9 @@ import com.cloud.agent.api.LogLevel.Log4jLevel; public class LoggingExclusionStrategy implements ExclusionStrategy { - Logger _logger = null; + protected Logger exclusionLogger = null; + + protected Logger logger = LogManager.getLogger(getClass()); @Override public boolean shouldSkipClass(Class clazz) { @@ -40,20 +43,24 @@ public boolean shouldSkipClass(Class clazz) { LogLevel level = clazz.getAnnotation(LogLevel.class); if (level == null) { log4jLevel = LogLevel.Log4jLevel.Debug; + logger.trace("Class {} does not have any log level annotation, considering level as debug.", clazz); } else { log4jLevel = level.value(); } - return !log4jLevel.enabled(_logger); + return !log4jLevel.enabled(exclusionLogger); } @Override public boolean shouldSkipField(FieldAttributes field) { LogLevel level = field.getAnnotation(LogLevel.class); - return level != null && !level.value().enabled(_logger); + return level != null && !level.value().enabled(exclusionLogger); } public LoggingExclusionStrategy(Logger logger) { - _logger = logger; + exclusionLogger = logger; + } + + public LoggingExclusionStrategy() { } } diff --git a/core/src/main/java/com/cloud/agent/transport/Request.java b/core/src/main/java/com/cloud/agent/transport/Request.java index 241ccd4bbd8b..3769dbbd612c 100644 --- a/core/src/main/java/com/cloud/agent/transport/Request.java +++ b/core/src/main/java/com/cloud/agent/transport/Request.java @@ -33,8 +33,9 @@ import java.util.zip.GZIPOutputStream; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.BadCommand; @@ -75,7 +76,7 @@ * */ public class Request { - private static final Logger s_logger = Logger.getLogger(Request.class); + protected static Logger LOGGER = LogManager.getLogger(Request.class); protected static final Gson s_gson = GsonHelper.getGson(); protected static final Gson s_gogger = GsonHelper.getGsonLogger(); @@ -251,10 +252,10 @@ public Command[] getCommands() { jsonReader.setLenient(true); _cmds = s_gson.fromJson(jsonReader, (Type)Command[].class); } catch (JsonParseException e) { - s_logger.error("Caught problem while parsing JSON command " + _content, e); + LOGGER.error("Caught problem while parsing JSON command " + _content, e); _cmds = new Command[] { new BadCommand() }; } catch (RuntimeException e) { - s_logger.error("Caught problem with " + _content, e); + LOGGER.error("Caught problem with " + _content, e); throw e; } } @@ -300,7 +301,7 @@ public static ByteBuffer doDecompress(ByteBuffer buffer, int length) { } in.close(); } catch (IOException e) { - s_logger.error("Fail to decompress the request!", e); + LOGGER.error("Fail to decompress the request!", e); } retBuff.flip(); return retBuff; @@ -321,7 +322,7 @@ public static ByteBuffer doCompress(ByteBuffer buffer, int length) { out.finish(); out.close(); } catch (IOException e) { - s_logger.error("Fail to compress the request!", e); + LOGGER.error("Fail to compress the request!", e); } return ByteBuffer.wrap(byteOut.toByteArray()); } @@ -369,24 +370,24 @@ public void logD(String msg) { } public void logD(String msg, boolean logContent) { - if (s_logger.isDebugEnabled()) { + if (LOGGER.isDebugEnabled()) { String log = log(msg, logContent, Level.DEBUG); if (log != null) { - s_logger.debug(log); + LOGGER.debug(log); } } } public void logT(String msg, boolean logD) { - if (s_logger.isTraceEnabled()) { + if (LOGGER.isTraceEnabled()) { String log = log(msg, true, Level.TRACE); if (log != null) { - s_logger.trace(log); + LOGGER.trace(log); } - } else if (logD && s_logger.isDebugEnabled()) { + } else if (logD && LOGGER.isDebugEnabled()) { String log = log(msg, false, Level.DEBUG); if (log != null) { - s_logger.debug(log); + LOGGER.debug(log); } } } @@ -403,7 +404,7 @@ protected String log(String msg, boolean logContent, Level level) { try { _cmds = s_gson.fromJson(_content, this instanceof Response ? Answer[].class : Command[].class); } catch (RuntimeException e) { - s_logger.error("Unable to deserialize from json: " + _content); + LOGGER.error("Unable to deserialize from json: " + _content); throw e; } } @@ -414,7 +415,7 @@ protected String log(String msg, boolean logContent, Level level) { for (Command cmd : _cmds) { buff.append(cmd.getClass().getSimpleName()).append("/"); } - s_logger.error("Gson serialization error " + buff.toString(), e); + LOGGER.error("Gson serialization error " + buff.toString(), e); assert false : "More gson errors on " + buff.toString(); return ""; } diff --git a/core/src/main/java/com/cloud/agent/transport/StoragePoolTypeAdaptor.java b/core/src/main/java/com/cloud/agent/transport/StoragePoolTypeAdaptor.java new file mode 100644 index 000000000000..635f6d06cf57 --- /dev/null +++ b/core/src/main/java/com/cloud/agent/transport/StoragePoolTypeAdaptor.java @@ -0,0 +1,53 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.transport; + +import com.cloud.storage.Storage.StoragePoolType; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +/** + * {@link StoragePoolType} acts as extendable set of singleton objects and should return same result when used "==" + * or {@link Object#equals(Object)}. + * To support that, need to return existing object for a given name instead of creating new. + */ +public class StoragePoolTypeAdaptor implements JsonDeserializer, JsonSerializer { + @Override + public StoragePoolType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if (json instanceof JsonPrimitive && ((JsonPrimitive) json).isString()) { + return StoragePoolType.valueOf(json.getAsString()); + } + return null; + } + + @Override + public JsonElement serialize(StoragePoolType src, Type typeOfSrc, JsonSerializationContext context) { + String name = src.name(); + if (name == null) { + return new JsonNull(); + } + return new JsonPrimitive(name); + } +} diff --git a/core/src/main/java/com/cloud/network/HAProxyConfigurator.java b/core/src/main/java/com/cloud/network/HAProxyConfigurator.java index 9d8301f291f0..e4b0a7ffff4c 100644 --- a/core/src/main/java/com/cloud/network/HAProxyConfigurator.java +++ b/core/src/main/java/com/cloud/network/HAProxyConfigurator.java @@ -28,7 +28,8 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.to.LoadBalancerTO; @@ -41,7 +42,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { - private static final Logger s_logger = Logger.getLogger(HAProxyConfigurator.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String blankLine = "\t "; private static String[] globalSection = {"global", "\tlog 127.0.0.1:3914 local0 warning", "\tmaxconn 4096", "\tmaxpipes 1024", "\tchroot /var/lib/haproxy", "\tuser haproxy", "\tgroup haproxy", "\tstats socket /run/haproxy/admin.sock", "\tdaemon"}; @@ -458,7 +459,7 @@ private String getLbSubRuleForStickiness(final LoadBalancerTO lbTO) { * Not supposed to reach here, validation of methods are * done at the higher layer */ - s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause:invalid method "); + logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause:invalid method "); return null; } } @@ -541,7 +542,7 @@ private List getRulesForPool(final LoadBalancerTO lbTO, final boolean ke result.addAll(dstSubRule); } if (stickinessSubRule != null && !destsAvailable) { - s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause: backends are unavailable"); + logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause: backends are unavailable"); } if (publicPort == NetUtils.HTTP_PORT && !keepAliveEnabled || httpbasedStickiness) { sb = new StringBuilder(); @@ -566,7 +567,7 @@ private String generateStatsRule(final LoadBalancerConfigCommand lbCmd, final St final StringBuilder rule = new StringBuilder("\nlisten ").append(ruleName).append("\n\tbind ").append(statsIp).append(":").append(lbCmd.lbStatsPort); // TODO DH: write test for this in both cases if (!lbCmd.keepAliveEnabled) { - s_logger.info("Haproxy mode http enabled"); + logger.info("Haproxy mode http enabled"); rule.append("\n\tmode http\n\toption httpclose"); } rule.append("\n\tstats enable\n\tstats uri ") @@ -575,8 +576,8 @@ private String generateStatsRule(final LoadBalancerConfigCommand lbCmd, final St .append(lbCmd.lbStatsAuth); rule.append("\n"); final String result = rule.toString(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Haproxystats rule: " + result); + if (logger.isDebugEnabled()) { + logger.debug("Haproxystats rule: " + result); } return result; } @@ -590,9 +591,9 @@ public String[] generateConfiguration(final LoadBalancerConfigCommand lbCmd) { // TODO DH: write test for this function final String pipesLine = "\tmaxpipes " + Long.toString(Long.parseLong(lbCmd.maxconn) / 4); gSection.set(3, pipesLine); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { for (final String s : gSection) { - s_logger.debug("global section: " + s); + logger.debug("global section: " + s); } } result.addAll(gSection); @@ -606,9 +607,9 @@ public String[] generateConfiguration(final LoadBalancerConfigCommand lbCmd) { dSection.set(7, "\tno option httpclose"); } - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { for (final String s : dSection) { - s_logger.debug("default section: " + s); + logger.debug("default section: " + s); } } result.addAll(dSection); diff --git a/core/src/main/java/com/cloud/network/resource/TrafficSentinelResource.java b/core/src/main/java/com/cloud/network/resource/TrafficSentinelResource.java index c6596b3c630f..43fb459978a8 100644 --- a/core/src/main/java/com/cloud/network/resource/TrafficSentinelResource.java +++ b/core/src/main/java/com/cloud/network/resource/TrafficSentinelResource.java @@ -35,7 +35,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -66,7 +67,7 @@ public class TrafficSentinelResource implements ServerResource { private String _inclZones; private String _exclZones; - private static final Logger s_logger = Logger.getLogger(TrafficSentinelResource.class); + protected Logger logger = LogManager.getLogger(getClass()); @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -242,10 +243,10 @@ private DirectNetworkUsageAnswer getPublicIpBytesSentAndReceived(DirectNetworkUs } } } catch (MalformedURLException e1) { - s_logger.info("Invalid Traffic Sentinel URL", e1); + logger.info("Invalid Traffic Sentinel URL", e1); throw new ExecutionException(e1.getMessage()); } catch (IOException e) { - s_logger.debug("Error in direct network usage accounting", e); + logger.debug("Error in direct network usage accounting", e); throw new ExecutionException(e.getMessage()); } finally { if (os != null) { @@ -256,7 +257,7 @@ private DirectNetworkUsageAnswer getPublicIpBytesSentAndReceived(DirectNetworkUs } } } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new ExecutionException(e.getMessage()); } return answer; diff --git a/core/src/main/java/com/cloud/resource/CommandWrapper.java b/core/src/main/java/com/cloud/resource/CommandWrapper.java index ee6aa161e33e..72d1348dfe70 100644 --- a/core/src/main/java/com/cloud/resource/CommandWrapper.java +++ b/core/src/main/java/com/cloud/resource/CommandWrapper.java @@ -19,7 +19,8 @@ package com.cloud.resource; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -27,7 +28,7 @@ import com.cloud.utils.script.Script; public abstract class CommandWrapper { - protected Logger logger = Logger.getLogger(getClass()); + protected Logger logger = LogManager.getLogger(getClass()); /** * @param T is the command to be used. diff --git a/core/src/main/java/com/cloud/resource/RequestWrapper.java b/core/src/main/java/com/cloud/resource/RequestWrapper.java index e43cf02e13c1..54d8b289c8d6 100644 --- a/core/src/main/java/com/cloud/resource/RequestWrapper.java +++ b/core/src/main/java/com/cloud/resource/RequestWrapper.java @@ -23,7 +23,8 @@ import java.util.Hashtable; import java.util.Set; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -39,7 +40,7 @@ public CommandNotSupported(String msg, Throwable cause) { } } - private static final Logger s_logger = Logger.getLogger(RequestWrapper.class); + protected Logger logger = LogManager.getLogger(RequestWrapper.class); @SuppressWarnings("rawtypes") protected Hashtable, Hashtable, CommandWrapper>> resources = new Hashtable, Hashtable, CommandWrapper>>(); @@ -141,9 +142,9 @@ protected Hashtable, CommandWrapper> processAnnotations try { commands.put(annotation.handles(), wrapper.newInstance()); } catch (final InstantiationException e) { - s_logger.warn(MessageFormat.format(errorMessage, e.getLocalizedMessage(), wrapper.toString())); + logger.warn(MessageFormat.format(errorMessage, e.getLocalizedMessage(), wrapper.toString())); } catch (final IllegalAccessException e) { - s_logger.warn(MessageFormat.format(errorMessage, e.getLocalizedMessage(), wrapper.toString())); + logger.warn(MessageFormat.format(errorMessage, e.getLocalizedMessage(), wrapper.toString())); } } diff --git a/core/src/main/java/com/cloud/resource/ServerResourceBase.java b/core/src/main/java/com/cloud/resource/ServerResourceBase.java index 18121e21e512..bb44b307047e 100644 --- a/core/src/main/java/com/cloud/resource/ServerResourceBase.java +++ b/core/src/main/java/com/cloud/resource/ServerResourceBase.java @@ -37,7 +37,8 @@ import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsAnswer; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -47,7 +48,7 @@ import com.cloud.utils.script.Script; public abstract class ServerResourceBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(ServerResourceBase.class); + protected Logger logger = LogManager.getLogger(getClass()); protected String name; private ArrayList warnings = new ArrayList(); private ArrayList errors = new ArrayList(); @@ -80,7 +81,7 @@ public boolean configure(final String name, Map params) throws C String infos[] = NetUtils.getNetworkParams(privateNic); if (infos == null) { - s_logger.warn("Incorrect details for private Nic during initialization of ServerResourceBase"); + logger.warn("Incorrect details for private Nic during initialization of ServerResourceBase"); return false; } params.put("host.ip", infos[0]); @@ -106,7 +107,7 @@ protected void defineResourceNetworkInterfaces(Map params) { } protected void tryToAutoDiscoverResourcePrivateNetworkInterface() throws ConfigurationException { - s_logger.info("Trying to autodiscover this resource's private network interface."); + logger.info("Trying to autodiscover this resource's private network interface."); List nics; try { @@ -118,11 +119,11 @@ protected void tryToAutoDiscoverResourcePrivateNetworkInterface() throws Configu throw new ConfigurationException(String.format("Could not retrieve the environment NICs due to [%s].", e.getMessage())); } - s_logger.debug(String.format("Searching the private NIC along the environment NICs [%s].", Arrays.toString(nics.toArray()))); + logger.debug(String.format("Searching the private NIC along the environment NICs [%s].", Arrays.toString(nics.toArray()))); for (NetworkInterface nic : nics) { if (isValidNicToUseAsPrivateNic(nic)) { - s_logger.info(String.format("Using NIC [%s] as private NIC.", nic)); + logger.info(String.format("Using NIC [%s] as private NIC.", nic)); privateNic = nic; return; } @@ -134,18 +135,18 @@ protected void tryToAutoDiscoverResourcePrivateNetworkInterface() throws Configu protected boolean isValidNicToUseAsPrivateNic(NetworkInterface nic) { String nicName = nic.getName(); - s_logger.debug(String.format("Verifying if NIC [%s] can be used as private NIC.", nic)); + logger.debug(String.format("Verifying if NIC [%s] can be used as private NIC.", nic)); String[] nicNameStartsToAvoid = {"vnif", "vnbr", "peth", "vif", "virbr"}; if (nic.isVirtual() || StringUtils.startsWithAny(nicName, nicNameStartsToAvoid) || nicName.contains(":")) { - s_logger.debug(String.format("Not using NIC [%s] because it is either virtual, starts with %s, or contains \":\"" + + logger.debug(String.format("Not using NIC [%s] because it is either virtual, starts with %s, or contains \":\"" + " in its name.", Arrays.toString(nicNameStartsToAvoid), nic)); return false; } String[] info = NetUtils.getNicParams(nicName); if (info == null || info[0] == null) { - s_logger.debug(String.format("Not using NIC [%s] because it does not have a valid IP to use as the private IP.", nic)); + logger.debug(String.format("Not using NIC [%s] because it does not have a valid IP to use as the private IP.", nic)); return false; } @@ -190,8 +191,8 @@ protected void fillNetworkInformation(final StartupCommand cmd) { if (privateNic != null) { info = NetUtils.getNetworkParams(privateNic); if (info != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Parameters for private nic: " + info[0] + " - " + info[1] + "-" + info[2]); + if (logger.isDebugEnabled()) { + logger.debug("Parameters for private nic: " + info[0] + " - " + info[1] + "-" + info[2]); } cmd.setPrivateIpAddress(info[0]); cmd.setPrivateMacAddress(info[1]); @@ -200,16 +201,16 @@ protected void fillNetworkInformation(final StartupCommand cmd) { } if (storageNic != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Storage has its now nic: " + storageNic.getName()); + if (logger.isDebugEnabled()) { + logger.debug("Storage has its now nic: " + storageNic.getName()); } info = NetUtils.getNetworkParams(storageNic); } // NOTE: In case you're wondering, this is not here by mistake. if (info != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Parameters for storage nic: " + info[0] + " - " + info[1] + "-" + info[2]); + if (logger.isDebugEnabled()) { + logger.debug("Parameters for storage nic: " + info[0] + " - " + info[1] + "-" + info[2]); } cmd.setStorageIpAddress(info[0]); cmd.setStorageMacAddress(info[1]); @@ -219,8 +220,8 @@ protected void fillNetworkInformation(final StartupCommand cmd) { if (publicNic != null) { info = NetUtils.getNetworkParams(publicNic); if (info != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Parameters for public nic: " + info[0] + " - " + info[1] + "-" + info[2]); + if (logger.isDebugEnabled()) { + logger.debug("Parameters for public nic: " + info[0] + " - " + info[1] + "-" + info[2]); } cmd.setPublicIpAddress(info[0]); cmd.setPublicMacAddress(info[1]); @@ -231,8 +232,8 @@ protected void fillNetworkInformation(final StartupCommand cmd) { if (storageNic2 != null) { info = NetUtils.getNetworkParams(storageNic2); if (info != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Parameters for storage nic 2: " + info[0] + " - " + info[1] + "-" + info[2]); + if (logger.isDebugEnabled()) { + logger.debug("Parameters for storage nic 2: " + info[0] + " - " + info[1] + "-" + info[2]); } cmd.setStorageIpAddressDeux(info[0]); cmd.setStorageMacAddressDeux(info[1]); diff --git a/core/src/main/java/com/cloud/serializer/GsonHelper.java b/core/src/main/java/com/cloud/serializer/GsonHelper.java index 7c33ef0e5d52..2d2cecf26185 100644 --- a/core/src/main/java/com/cloud/serializer/GsonHelper.java +++ b/core/src/main/java/com/cloud/serializer/GsonHelper.java @@ -21,7 +21,10 @@ import java.util.List; -import org.apache.log4j.Logger; +import com.cloud.hypervisor.Hypervisor; +import org.apache.cloudstack.transport.HypervisorTypeAdaptor; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -37,10 +40,12 @@ import com.cloud.agent.transport.LoggingExclusionStrategy; import com.cloud.agent.transport.Request.NwGroupsCommandTypeAdaptor; import com.cloud.agent.transport.Request.PortConfigListTypeAdaptor; +import com.cloud.agent.transport.StoragePoolTypeAdaptor; +import com.cloud.storage.Storage; import com.cloud.utils.Pair; public class GsonHelper { - private static final Logger s_logger = Logger.getLogger(GsonHelper.class); + protected static Logger LOGGER = LogManager.getLogger(GsonHelper.class); protected static final Gson s_gson; protected static final Gson s_gogger; @@ -48,13 +53,13 @@ public class GsonHelper { static { GsonBuilder gsonBuilder = new GsonBuilder(); s_gson = setDefaultGsonConfig(gsonBuilder); - GsonBuilder loggerBuilder = new GsonBuilder(); - loggerBuilder.disableHtmlEscaping(); - loggerBuilder.setExclusionStrategies(new LoggingExclusionStrategy(s_logger)); - loggerBuilder.serializeSpecialFloatingPointValues(); - // maybe add loggerBuilder.serializeNulls(); as well? - s_gogger = setDefaultGsonConfig(loggerBuilder); - s_logger.info("Default Builder inited."); + GsonBuilder LOGGERBuilder = new GsonBuilder(); + LOGGERBuilder.disableHtmlEscaping(); + LOGGERBuilder.setExclusionStrategies(new LoggingExclusionStrategy(LOGGER)); + LOGGERBuilder.serializeSpecialFloatingPointValues(); + // maybe add LOGGERBuilder.serializeNulls(); as well? + s_gogger = setDefaultGsonConfig(LOGGERBuilder); + LOGGER.info("Default Builder inited."); } static Gson setDefaultGsonConfig(GsonBuilder builder) { @@ -71,6 +76,8 @@ static Gson setDefaultGsonConfig(GsonBuilder builder) { }.getType(), new PortConfigListTypeAdaptor()); builder.registerTypeAdapter(new TypeToken>() { }.getType(), new NwGroupsCommandTypeAdaptor()); + builder.registerTypeAdapter(Storage.StoragePoolType.class, new StoragePoolTypeAdaptor()); + builder.registerTypeAdapter(Hypervisor.HypervisorType.class, new HypervisorTypeAdaptor()); Gson gson = builder.create(); dsAdaptor.initGson(gson); dtAdaptor.initGson(gson); @@ -88,6 +95,6 @@ public final static Gson getGsonLogger() { } public final static Logger getLogger() { - return s_logger; + return LOGGER; } } diff --git a/core/src/main/java/com/cloud/storage/JavaStorageLayer.java b/core/src/main/java/com/cloud/storage/JavaStorageLayer.java index d4c2639d4786..0e51ef7eb205 100644 --- a/core/src/main/java/com/cloud/storage/JavaStorageLayer.java +++ b/core/src/main/java/com/cloud/storage/JavaStorageLayer.java @@ -34,10 +34,11 @@ import java.util.UUID; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class JavaStorageLayer implements StorageLayer { - private static final Logger s_logger = Logger.getLogger(JavaStorageLayer.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String STD_TMP_DIR_PATH = "/tmp"; String _name; boolean _makeWorldWriteable = true; @@ -198,9 +199,9 @@ public File createUniqDir() throws IOException { if (dir.exists()) { if (isWorldReadable(dir)) { if (STD_TMP_DIR_PATH.equals(dir.getAbsolutePath())) { - s_logger.warn(String.format("The temp dir is %s", STD_TMP_DIR_PATH)); + logger.warn(String.format("The temp dir is %s", STD_TMP_DIR_PATH)); } else { - s_logger.warn("The temp dir " + dir.getAbsolutePath() + " is World Readable"); + logger.warn("The temp dir " + dir.getAbsolutePath() + " is World Readable"); } } String uniqDirName = dir.getAbsolutePath() + File.separator + UUID.randomUUID().toString(); diff --git a/core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java b/core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java index 75d5f49d4c6c..7d8225462cab 100644 --- a/core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java +++ b/core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.storage.command.StorageSubSystemCommand; import org.apache.cloudstack.storage.command.SyncVolumePathCommand; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -47,9 +46,11 @@ import com.cloud.storage.DataStoreRole; import com.cloud.storage.Volume; import com.google.gson.Gson; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class StorageSubsystemCommandHandlerBase implements StorageSubsystemCommandHandler { - private static final Logger s_logger = Logger.getLogger(StorageSubsystemCommandHandlerBase.class); + protected Logger logger = LogManager.getLogger(getClass()); protected static final Gson s_gogger = GsonHelper.getGsonLogger(); protected StorageProcessor processor; @@ -141,7 +142,7 @@ protected Answer execute(CreateObjectCommand cmd) { } return new CreateObjectAnswer("not supported type"); } catch (Exception e) { - s_logger.debug("Failed to create object: " + data.getObjectType() + ": " + e.toString()); + logger.debug("Failed to create object: " + data.getObjectType() + ": " + e.toString()); return new CreateObjectAnswer(e.toString()); } } @@ -184,9 +185,9 @@ protected Answer execute(QuerySnapshotZoneCopyCommand cmd) { private void logCommand(Command cmd) { try { - s_logger.debug(String.format("Executing command %s: [%s].", cmd.getClass().getSimpleName(), s_gogger.toJson(cmd))); + logger.debug(String.format("Executing command %s: [%s].", cmd.getClass().getSimpleName(), s_gogger.toJson(cmd))); } catch (Exception e) { - s_logger.debug(String.format("Executing command %s.", cmd.getClass().getSimpleName())); + logger.debug(String.format("Executing command %s.", cmd.getClass().getSimpleName())); } } } diff --git a/core/src/main/java/com/cloud/storage/template/FtpTemplateUploader.java b/core/src/main/java/com/cloud/storage/template/FtpTemplateUploader.java index eb0c4f846016..14bf6fe1b746 100644 --- a/core/src/main/java/com/cloud/storage/template/FtpTemplateUploader.java +++ b/core/src/main/java/com/cloud/storage/template/FtpTemplateUploader.java @@ -29,11 +29,12 @@ import java.net.URLConnection; import java.util.Date; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class FtpTemplateUploader implements TemplateUploader { - public static final Logger s_logger = Logger.getLogger(FtpTemplateUploader.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); public TemplateUploader.Status status = TemplateUploader.Status.NOT_STARTED; public String errorString = ""; public long totalBytes = 0; @@ -110,11 +111,11 @@ public long upload(UploadCompleteCallback callback) { } catch (MalformedURLException e) { status = TemplateUploader.Status.UNRECOVERABLE_ERROR; errorString = e.getMessage(); - s_logger.error(errorString); + logger.error(errorString); } catch (IOException e) { status = TemplateUploader.Status.UNRECOVERABLE_ERROR; errorString = e.getMessage(); - s_logger.error(errorString); + logger.error(errorString); } finally { try { if (inputStream != null) { @@ -124,7 +125,7 @@ public long upload(UploadCompleteCallback callback) { outputStream.close(); } } catch (IOException ioe) { - s_logger.error(" Caught exception while closing the resources"); + logger.error(" Caught exception while closing the resources"); } if (callback != null) { callback.uploadComplete(status); @@ -139,7 +140,7 @@ public void run() { try { upload(completionCallback); } catch (Throwable t) { - s_logger.warn("Caught exception during upload " + t.getMessage(), t); + logger.warn("Caught exception during upload " + t.getMessage(), t); errorString = "Failed to install: " + t.getMessage(); status = TemplateUploader.Status.UNRECOVERABLE_ERROR; } @@ -207,7 +208,7 @@ public boolean stopUpload() { inputStream.close(); } } catch (IOException e) { - s_logger.error(" Caught exception while closing the resources"); + logger.error(" Caught exception while closing the resources"); } status = TemplateUploader.Status.ABORTED; return true; diff --git a/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java index 7ad8070b6e5f..9b126846827e 100755 --- a/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java @@ -46,7 +46,6 @@ import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; -import org.apache.log4j.Logger; import com.cloud.storage.StorageLayer; import com.cloud.utils.Pair; @@ -59,7 +58,6 @@ * */ public class HttpTemplateDownloader extends ManagedContextRunnable implements TemplateDownloader { - public static final Logger s_logger = Logger.getLogger(HttpTemplateDownloader.class.getName()); private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); private static final int CHUNK_SIZE = 1024 * 1024; //1M @@ -104,9 +102,9 @@ public HttpTemplateDownloader(StorageLayer storageLayer, String downloadUrl, Str } catch (Exception ex) { errorString = "Unable to start download -- check url? "; status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; - s_logger.warn("Exception in constructor -- " + ex.toString()); + logger.warn("Exception in constructor -- " + ex.toString()); } catch (Throwable th) { - s_logger.warn("throwable caught ", th); + logger.warn("throwable caught ", th); } } @@ -129,7 +127,7 @@ private void checkTemporaryDestination(String toDir) { } catch (IOException ex) { errorString = "Unable to start download -- check url? "; status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; - s_logger.warn("Exception in constructor -- " + ex.toString()); + logger.warn("Exception in constructor -- " + ex.toString()); } } @@ -140,9 +138,9 @@ private void checkCredentials(String user, String password) { client.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); - s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); + logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); } else { - s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second()); + logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second()); } } catch (IllegalArgumentException iae) { errorString = iae.getMessage(); @@ -208,7 +206,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { ) { out.seek(localFileSize); - s_logger.info("Starting download from " + downloadUrl + " to " + toFile + " remoteSize=" + toHumanReadableSize(remoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes)); + logger.info("Starting download from " + downloadUrl + " to " + toFile + " remoteSize=" + toHumanReadableSize(remoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes)); if (copyBytes(file, in, out)) return 0; @@ -280,7 +278,7 @@ private void checkDowloadCompletion() { private boolean canHandleDownloadSize() { if (remoteSize > maxTemplateSizeInBytes) { - s_logger.info("Remote size is too large: " + toHumanReadableSize(remoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes)); + logger.info("Remote size is too large: " + toHumanReadableSize(remoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes)); status = Status.UNRECOVERABLE_ERROR; errorString = "Download file size is too large"; return false; @@ -343,7 +341,7 @@ private boolean checkServerResponse(long localFileSize) throws IOException { && !followRedirects) { errorString = String.format("Failed to download %s due to redirection, response code: %d", downloadUrl, responseCode); - s_logger.error(errorString); + logger.error(errorString); } return true; //FIXME: retry? } @@ -355,7 +353,7 @@ private long checkLocalFileSizeForResume(boolean resume, File file) { long localFileSize = 0; if (file.exists() && resume) { localFileSize = file.length(); - s_logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize)); + logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize)); } return localFileSize; } @@ -439,7 +437,7 @@ protected void runInContext() { try { download(resume, completionCallback); } catch (Throwable t) { - s_logger.warn("Caught exception during download " + t.getMessage(), t); + logger.warn("Caught exception during download " + t.getMessage(), t); errorString = "Failed to install: " + t.getMessage(); status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; } @@ -527,20 +525,20 @@ public VerifyFormat invoke() { URI str = new URI(downloadUrl); uripath = str.getPath(); } catch (URISyntaxException e) { - s_logger.warn("Invalid download url: " + downloadUrl + ", This should not happen since we have validated the url before!!"); + logger.warn("Invalid download url: " + downloadUrl + ", This should not happen since we have validated the url before!!"); } String unsupportedFormat = ImageStoreUtil.checkTemplateFormat(file.getAbsolutePath(), uripath); if (unsupportedFormat == null || !unsupportedFormat.isEmpty()) { try { request.abort(); } catch (Exception ex) { - s_logger.debug("Error on http connection : " + ex.getMessage()); + logger.debug("Error on http connection : " + ex.getMessage()); } status = Status.UNRECOVERABLE_ERROR; errorString = "Template content is unsupported, or mismatch between selected format and template content. Found : " + unsupportedFormat; throw new CloudRuntimeException(errorString); } else { - s_logger.debug("Verified format of downloading file " + file.getAbsolutePath() + " is supported"); + logger.debug("Verified format of downloading file " + file.getAbsolutePath() + " is supported"); verifiedFormat = true; } return this; diff --git a/core/src/main/java/com/cloud/storage/template/IsoProcessor.java b/core/src/main/java/com/cloud/storage/template/IsoProcessor.java index 4cd2f1a2a020..6ab42effb524 100644 --- a/core/src/main/java/com/cloud/storage/template/IsoProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/IsoProcessor.java @@ -24,14 +24,12 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageLayer; import com.cloud.utils.component.AdapterBase; public class IsoProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(IsoProcessor.class); StorageLayer _storage; @@ -43,14 +41,14 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) { if (format != null) { - s_logger.debug("We don't handle conversion from " + format + " to ISO."); + logger.debug("We don't handle conversion from " + format + " to ISO."); return null; } String isoPath = templatePath + File.separator + templateName + "." + ImageFormat.ISO.getFileExtension(); if (!_storage.exists(isoPath)) { - s_logger.debug("Unable to find the iso file: " + isoPath); + logger.debug("Unable to find the iso file: " + isoPath); return null; } diff --git a/core/src/main/java/com/cloud/storage/template/LocalTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/LocalTemplateDownloader.java index 564eba3d5ee1..e4044412c521 100644 --- a/core/src/main/java/com/cloud/storage/template/LocalTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/LocalTemplateDownloader.java @@ -29,12 +29,10 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import org.apache.log4j.Logger; import com.cloud.storage.StorageLayer; public class LocalTemplateDownloader extends TemplateDownloaderBase implements TemplateDownloader { - public static final Logger s_logger = Logger.getLogger(LocalTemplateDownloader.class); public LocalTemplateDownloader(StorageLayer storageLayer, String downloadUrl, String toDir, long maxTemplateSizeInBytes, DownloadCompleteCallback callback) { super(storageLayer, downloadUrl, toDir, maxTemplateSizeInBytes, callback); @@ -55,7 +53,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { try { src = new File(new URI(_downloadUrl)); } catch (URISyntaxException e1) { - s_logger.warn("Invalid URI " + _downloadUrl); + logger.warn("Invalid URI " + _downloadUrl); _status = Status.UNRECOVERABLE_ERROR; return 0; } @@ -77,7 +75,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { try { fis = new FileInputStream(src); } catch (FileNotFoundException e) { - s_logger.warn("Unable to find " + _downloadUrl); + logger.warn("Unable to find " + _downloadUrl); _errorString = "Unable to find " + _downloadUrl; return -1; } @@ -85,7 +83,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { try { fos = new FileOutputStream(dst); } catch (FileNotFoundException e) { - s_logger.warn("Unable to find " + _toFile); + logger.warn("Unable to find " + _toFile); return -1; } foc = fos.getChannel(); @@ -102,7 +100,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { buffer.clear(); } } catch (IOException e) { - s_logger.warn("Unable to download", e); + logger.warn("Unable to download", e); } String downloaded = "(incomplete download)"; @@ -123,7 +121,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { try { fic.close(); } catch (IOException e) { - s_logger.info("[ignore] error while closing file input channel."); + logger.info("[ignore] error while closing file input channel."); } } @@ -131,7 +129,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { try { foc.close(); } catch (IOException e) { - s_logger.info("[ignore] error while closing file output channel."); + logger.info("[ignore] error while closing file output channel."); } } @@ -139,7 +137,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { try { fis.close(); } catch (IOException e) { - s_logger.info("[ignore] error while closing file input stream."); + logger.info("[ignore] error while closing file input stream."); } } @@ -147,7 +145,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { try { fos.close(); } catch (IOException e) { - s_logger.info("[ignore] error while closing file output stream."); + logger.info("[ignore] error while closing file output stream."); } } diff --git a/core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java index a118a9ac40ff..2e62809dfeda 100644 --- a/core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java @@ -28,7 +28,6 @@ import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; import org.springframework.util.CollectionUtils; import java.io.File; @@ -47,7 +46,6 @@ public class MetalinkTemplateDownloader extends TemplateDownloaderBase implement protected GetMethod request; private boolean toFileSet = false; - private static final Logger LOGGER = Logger.getLogger(MetalinkTemplateDownloader.class.getName()); public MetalinkTemplateDownloader(StorageLayer storageLayer, String downloadUrl, String toDir, DownloadCompleteCallback callback, long maxTemplateSize) { super(storageLayer, downloadUrl, toDir, maxTemplateSize, callback); @@ -97,7 +95,7 @@ private boolean downloadTemplate() { try { client.executeMethod(request); } catch (IOException e) { - LOGGER.error("Error on HTTP request: " + e.getMessage()); + logger.error("Error on HTTP request: " + e.getMessage()); return false; } return performDownload(); @@ -110,7 +108,7 @@ private boolean performDownload() { ) { IOUtils.copy(in, out); } catch (IOException e) { - LOGGER.error("Error downloading template from: " + _downloadUrl + " due to: " + e.getMessage()); + logger.error("Error downloading template from: " + _downloadUrl + " due to: " + e.getMessage()); return false; } return true; @@ -121,13 +119,13 @@ public long download(boolean resume, DownloadCompleteCallback callback) { return 0; } - LOGGER.info("Starting metalink download from: " + _downloadUrl); + logger.info("Starting metalink download from: " + _downloadUrl); _start = System.currentTimeMillis(); status = Status.IN_PROGRESS; List metalinkUrls = UriUtils.getMetalinkUrls(_downloadUrl); if (CollectionUtils.isEmpty(metalinkUrls)) { - LOGGER.error("No URLs found for metalink: " + _downloadUrl); + logger.error("No URLs found for metalink: " + _downloadUrl); status = Status.UNRECOVERABLE_ERROR; return 0; } @@ -140,11 +138,11 @@ public long download(boolean resume, DownloadCompleteCallback callback) { i++; } if (!downloaded) { - LOGGER.error("Template couldn't be downloaded"); + logger.error("Template couldn't be downloaded"); status = Status.UNRECOVERABLE_ERROR; return 0; } - LOGGER.info("Template downloaded successfully on: " + _toFile); + logger.info("Template downloaded successfully on: " + _toFile); status = Status.DOWNLOAD_FINISHED; _downloadTime = System.currentTimeMillis() - _start; if (_callback != null) { diff --git a/core/src/main/java/com/cloud/storage/template/OVAProcessor.java b/core/src/main/java/com/cloud/storage/template/OVAProcessor.java index 33f7e28ac039..ab3aa0d0e3a5 100644 --- a/core/src/main/java/com/cloud/storage/template/OVAProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/OVAProcessor.java @@ -34,7 +34,6 @@ import com.cloud.agent.api.to.deployasis.OVFNetworkTO; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -52,7 +51,6 @@ * processes the content of an OVA for registration of a template */ public class OVAProcessor extends AdapterBase implements Processor { - private static final Logger LOGGER = Logger.getLogger(OVAProcessor.class); StorageLayer _storage; @Override @@ -66,11 +64,11 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa return null; } - LOGGER.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); + logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); String templateFilePath = templatePath + File.separator + templateName + "." + ImageFormat.OVA.getFileExtension(); if (!_storage.exists(templateFilePath)) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info("Unable to find the vmware template file: " + templateFilePath); + if (logger.isInfoEnabled()) { + logger.info("Unable to find the vmware template file: " + templateFilePath); } return null; } @@ -114,46 +112,46 @@ private OVFInformationTO createOvfInformationTO(OVFHelper ovfHelper, Document do List disks = ovfHelper.getOVFVolumeInfoFromFile(ovfFilePath, doc, null); if (CollectionUtils.isNotEmpty(disks)) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Found %d disks in template %s", disks.size(), ovfFilePath)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Found %d disks in template %s", disks.size(), ovfFilePath)); } ovfInformationTO.setDisks(disks); } List nets = ovfHelper.getNetPrerequisitesFromDocument(doc); if (CollectionUtils.isNotEmpty(nets)) { - LOGGER.info("Found " + nets.size() + " prerequisite networks"); + logger.info("Found " + nets.size() + " prerequisite networks"); ovfInformationTO.setNetworks(nets); - } else if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("no net prerequisites found in template %s", ovfFilePath)); + } else if (logger.isTraceEnabled()) { + logger.trace(String.format("no net prerequisites found in template %s", ovfFilePath)); } List ovfProperties = ovfHelper.getConfigurableOVFPropertiesFromDocument(doc); if (CollectionUtils.isNotEmpty(ovfProperties)) { - LOGGER.info("Found " + ovfProperties.size() + " configurable OVF properties"); + logger.info("Found " + ovfProperties.size() + " configurable OVF properties"); ovfInformationTO.setProperties(ovfProperties); - } else if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("no ovf properties found in template %s", ovfFilePath)); + } else if (logger.isTraceEnabled()) { + logger.trace(String.format("no ovf properties found in template %s", ovfFilePath)); } OVFVirtualHardwareSectionTO hardwareSection = ovfHelper.getVirtualHardwareSectionFromDocument(doc); List configurations = hardwareSection.getConfigurations(); if (CollectionUtils.isNotEmpty(configurations)) { - LOGGER.info("Found " + configurations.size() + " deployment option configurations"); + logger.info("Found " + configurations.size() + " deployment option configurations"); } List hardwareItems = hardwareSection.getCommonHardwareItems(); if (CollectionUtils.isNotEmpty(hardwareItems)) { - LOGGER.info("Found " + hardwareItems.size() + " virtual hardware items"); + logger.info("Found " + hardwareItems.size() + " virtual hardware items"); } if (StringUtils.isNotBlank(hardwareSection.getMinimiumHardwareVersion())) { - LOGGER.info("Found minimum hardware version " + hardwareSection.getMinimiumHardwareVersion()); + logger.info("Found minimum hardware version " + hardwareSection.getMinimiumHardwareVersion()); } ovfInformationTO.setHardwareSection(hardwareSection); List eulaSections = ovfHelper.getEulaSectionsFromDocument(doc); if (CollectionUtils.isNotEmpty(eulaSections)) { - LOGGER.info("Found " + eulaSections.size() + " license agreements"); + logger.info("Found " + eulaSections.size() + " license agreements"); ovfInformationTO.setEulaSections(eulaSections); } Pair guestOsPair = ovfHelper.getOperatingSystemInfoFromDocument(doc); if (guestOsPair != null) { - LOGGER.info("Found guest OS information: " + guestOsPair.first() + " - " + guestOsPair.second()); + logger.info("Found guest OS information: " + guestOsPair.first() + " - " + guestOsPair.second()); ovfInformationTO.setGuestOsInfo(guestOsPair); } return ovfInformationTO; @@ -163,33 +161,33 @@ private void setFileSystemAccessRights(String templatePath) { Script command; String result; - command = new Script("chmod", 0, LOGGER); + command = new Script("chmod", 0, logger); command.add("-R"); command.add("666", templatePath); result = command.execute(); if (result != null) { - LOGGER.warn("Unable to set permissions for files in " + templatePath + " due to " + result); + logger.warn("Unable to set permissions for files in " + templatePath + " due to " + result); } - command = new Script("chmod", 0, LOGGER); + command = new Script("chmod", 0, logger); command.add("777", templatePath); result = command.execute(); if (result != null) { - LOGGER.warn("Unable to set permissions for " + templatePath + " due to " + result); + logger.warn("Unable to set permissions for " + templatePath + " due to " + result); } } private String unpackOva(String templatePath, String templateName, long processTimeout) throws InternalErrorException { - LOGGER.info("Template processing - untar OVA package. templatePath: " + templatePath + ", templateName: " + templateName); + logger.info("Template processing - untar OVA package. templatePath: " + templatePath + ", templateName: " + templateName); String templateFileFullPath = templatePath + File.separator + templateName + "." + ImageFormat.OVA.getFileExtension(); File templateFile = new File(templateFileFullPath); - Script command = new Script("tar", processTimeout, LOGGER); + Script command = new Script("tar", processTimeout, logger); command.add("--no-same-owner"); command.add("--no-same-permissions"); command.add("-xf", templateFileFullPath); command.setWorkDir(templateFile.getParent()); String result = command.execute(); if (result != null) { - LOGGER.info("failed to untar OVA package due to " + result + ". templatePath: " + templatePath + ", templateName: " + templateName); + logger.info("failed to untar OVA package due to " + result + ". templatePath: " + templatePath + ", templateName: " + templateName); throw new InternalErrorException("failed to untar OVA package"); } return templateFileFullPath; @@ -197,13 +195,13 @@ private String unpackOva(String templatePath, String templateName, long processT private boolean conversionChecks(ImageFormat format) { if (format != null) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info("We currently don't handle conversion from " + format + " to OVA."); + if (logger.isInfoEnabled()) { + logger.info("We currently don't handle conversion from " + format + " to OVA."); } return false; } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("We are handling format " + format + "."); + if (logger.isTraceEnabled()) { + logger.trace("We are handling format " + format + "."); } return true; } @@ -214,7 +212,7 @@ public long getVirtualSize(File file) { long size = getTemplateVirtualSize(file.getParent(), file.getName()); return size; } catch (Exception e) { - LOGGER.info("[ignored]" + logger.info("[ignored]" + "failed to get virtual template size for ova: " + e.getLocalizedMessage()); } return file.length(); @@ -234,7 +232,7 @@ public long getTemplateVirtualSize(String templatePath, String templateName) thr OVFHelper ovfHelper = new OVFHelper(); if (ovfFileName == null) { String msg = "Unable to locate OVF file in template package directory: " + templatePath; - LOGGER.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } try { @@ -248,7 +246,7 @@ public long getTemplateVirtualSize(String templatePath, String templateName) thr diskSize = Long.parseLong(diskSizeValue); } catch (NumberFormatException e) { // ASSUMEably the diskSize contains a property for replacement - LOGGER.warn(String.format("the disksize for disk %s is not a valid number: %s", disk.getAttribute("diskId"), diskSizeValue)); + logger.warn(String.format("the disksize for disk %s is not a valid number: %s", disk.getAttribute("diskId"), diskSizeValue)); // TODO parse the property to get any value can not be done at registration time // and will have to be done at deploytime, so for orchestration purposes // we now assume, a value of one @@ -260,7 +258,7 @@ public long getTemplateVirtualSize(String templatePath, String templateName) thr return virtualSize; } catch (InternalErrorException | NumberFormatException e) { String msg = "getTemplateVirtualSize: Unable to parse OVF XML document " + templatePath + " to get the virtual disk " + templateName + " size due to " + e; - LOGGER.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } } diff --git a/core/src/main/java/com/cloud/storage/template/QCOW2Processor.java b/core/src/main/java/com/cloud/storage/template/QCOW2Processor.java index 56ae078dc519..df1722a0201d 100644 --- a/core/src/main/java/com/cloud/storage/template/QCOW2Processor.java +++ b/core/src/main/java/com/cloud/storage/template/QCOW2Processor.java @@ -27,7 +27,6 @@ import javax.naming.ConfigurationException; import com.cloud.exception.InternalErrorException; -import org.apache.log4j.Logger; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageLayer; @@ -35,7 +34,6 @@ import com.cloud.utils.component.AdapterBase; public class QCOW2Processor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(QCOW2Processor.class); private static final int VIRTUALSIZE_HEADER_LOCATION = 24; private StorageLayer _storage; @@ -48,14 +46,14 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) throws InternalErrorException { if (format != null) { - s_logger.debug("We currently don't handle conversion from " + format + " to QCOW2."); + logger.debug("We currently don't handle conversion from " + format + " to QCOW2."); return null; } String qcow2Path = templatePath + File.separator + templateName + "." + ImageFormat.QCOW2.getFileExtension(); if (!_storage.exists(qcow2Path)) { - s_logger.debug("Unable to find the qcow2 file: " + qcow2Path); + logger.debug("Unable to find the qcow2 file: " + qcow2Path); return null; } @@ -70,7 +68,7 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa try { info.virtualSize = getTemplateVirtualSize(qcow2File); } catch (IOException e) { - s_logger.error("Unable to get virtual size from " + qcow2File.getName()); + logger.error("Unable to get virtual size from " + qcow2File.getName()); throw new InternalErrorException("unable to get virtual size from qcow2 file"); } @@ -83,7 +81,7 @@ public long getVirtualSize(File file) throws IOException { long size = getTemplateVirtualSize(file); return size; } catch (Exception e) { - s_logger.info("[ignored]" + "failed to get template virtual size for QCOW2: " + e.getLocalizedMessage()); + logger.info("[ignored]" + "failed to get template virtual size for QCOW2: " + e.getLocalizedMessage()); } return file.length(); } diff --git a/core/src/main/java/com/cloud/storage/template/RawImageProcessor.java b/core/src/main/java/com/cloud/storage/template/RawImageProcessor.java index 5fbc626f271e..d6c1f7a808f6 100644 --- a/core/src/main/java/com/cloud/storage/template/RawImageProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/RawImageProcessor.java @@ -24,7 +24,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; import com.cloud.storage.Storage.ImageFormat; @@ -32,7 +31,6 @@ import com.cloud.utils.component.AdapterBase; public class RawImageProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(RawImageProcessor.class); StorageLayer _storage; @Override @@ -53,13 +51,13 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) throws InternalErrorException { if (format != null) { - s_logger.debug("We currently don't handle conversion from " + format + " to raw image."); + logger.debug("We currently don't handle conversion from " + format + " to raw image."); return null; } String imgPath = templatePath + File.separator + templateName + "." + ImageFormat.RAW.getFileExtension(); if (!_storage.exists(imgPath)) { - s_logger.debug("Unable to find raw image:" + imgPath); + logger.debug("Unable to find raw image:" + imgPath); return null; } FormatInfo info = new FormatInfo(); @@ -67,7 +65,7 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa info.filename = templateName + "." + ImageFormat.RAW.getFileExtension(); info.size = _storage.getSize(imgPath); info.virtualSize = info.size; - s_logger.debug("Process raw image " + info.filename + " successfully"); + logger.debug("Process raw image " + info.filename + " successfully"); return info; } diff --git a/core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java index a259e79fa421..c24a4cc221fc 100644 --- a/core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java @@ -39,7 +39,6 @@ import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.BufferedInputStream; import java.io.IOException; @@ -58,7 +57,6 @@ * Execution of the instance is started when runInContext() is called. */ public class S3TemplateDownloader extends ManagedContextRunnable implements TemplateDownloader { - private static final Logger LOGGER = Logger.getLogger(S3TemplateDownloader.class.getName()); private final String downloadUrl; private final String s3Key; @@ -112,7 +110,7 @@ public S3TemplateDownloader(S3TO s3TO, String downloadUrl, String installPath, D public long download(boolean resume, DownloadCompleteCallback callback) { if (!status.equals(Status.NOT_STARTED)) { // Only start downloading if we haven't started yet. - LOGGER.debug("Template download is already started, not starting again. Template: " + downloadUrl); + logger.debug("Template download is already started, not starting again. Template: " + downloadUrl); return 0; } @@ -120,7 +118,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { int responseCode; if ((responseCode = HTTPUtils.executeMethod(httpClient, getMethod)) == -1) { errorString = "Exception while executing HttpMethod " + getMethod.getName() + " on URL " + downloadUrl; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; @@ -130,7 +128,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { HttpStatus.SC_MOVED_TEMPORARILY).contains(responseCode) && !followRedirects; if (!HTTPUtils.verifyResponseCode(responseCode) || failedDueToRedirection) { errorString = "Response code for GetMethod of " + downloadUrl + " is incorrect, responseCode: " + responseCode; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; } @@ -142,7 +140,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { // Check the contentLengthHeader and transferEncodingHeader. if (contentLengthHeader == null) { errorString = "The ContentLengthHeader of " + downloadUrl + " isn't supplied"; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; @@ -153,7 +151,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { if (remoteSize > maxTemplateSizeInByte) { errorString = "Remote size is too large for template " + downloadUrl + " remote size is " + remoteSize + " max allowed is " + maxTemplateSizeInByte; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; @@ -165,13 +163,13 @@ public long download(boolean resume, DownloadCompleteCallback callback) { inputStream = new BufferedInputStream(getMethod.getResponseBodyAsStream()); } catch (IOException e) { errorString = "Exception occurred while opening InputStream for template " + downloadUrl; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; } - LOGGER.info("Starting download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " and size " + toHumanReadableSize(remoteSize) + " bytes"); + logger.info("Starting download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " and size " + toHumanReadableSize(remoteSize) + " bytes"); // Time the upload starts. final Date start = new Date(); @@ -200,7 +198,7 @@ public void progressChanged(ProgressEvent progressEvent) { // Record the amount of bytes transferred. totalBytes += progressEvent.getBytesTransferred(); - LOGGER.trace("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + ((new Date().getTime() - start.getTime()) / 1000) + " seconds"); + logger.trace("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + ((new Date().getTime() - start.getTime()) / 1000) + " seconds"); if (progressEvent.getEventType() == ProgressEventType.TRANSFER_STARTED_EVENT) { status = Status.IN_PROGRESS; @@ -219,15 +217,15 @@ public void progressChanged(ProgressEvent progressEvent) { upload.waitForCompletion(); } catch (InterruptedException e) { // Interruption while waiting for the upload to complete. - LOGGER.warn("Interruption occurred while waiting for upload of " + downloadUrl + " to complete"); + logger.warn("Interruption occurred while waiting for upload of " + downloadUrl + " to complete"); } downloadTime = new Date().getTime() - start.getTime(); if (status == Status.DOWNLOAD_FINISHED) { - LOGGER.info("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed successfully!"); + logger.info("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed successfully!"); } else { - LOGGER.warn("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed with status " + status.toString()); + logger.warn("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed with status " + status.toString()); } // Close input stream @@ -281,7 +279,7 @@ public InputStream getS3ObjectInputStream() { } public void cleanupAfterError() { - LOGGER.warn("Cleanup after error, trying to remove object: " + s3Key); + logger.warn("Cleanup after error, trying to remove object: " + s3Key); S3Utils.deleteObject(s3TO, s3TO.getBucketName(), s3Key); } diff --git a/core/src/main/java/com/cloud/storage/template/ScpTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/ScpTemplateDownloader.java index 912809ca722b..44379efcd553 100644 --- a/core/src/main/java/com/cloud/storage/template/ScpTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/ScpTemplateDownloader.java @@ -23,7 +23,6 @@ import java.net.URI; import java.net.URISyntaxException; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -31,7 +30,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class ScpTemplateDownloader extends TemplateDownloaderBase implements TemplateDownloader { - private static final Logger s_logger = Logger.getLogger(ScpTemplateDownloader.class); public ScpTemplateDownloader(StorageLayer storageLayer, String downloadUrl, String toDir, long maxTemplateSizeInBytes, DownloadCompleteCallback callback) { super(storageLayer, downloadUrl, toDir, maxTemplateSizeInBytes, callback); @@ -40,7 +38,7 @@ public ScpTemplateDownloader(StorageLayer storageLayer, String downloadUrl, Stri try { uri = new URI(_downloadUrl); } catch (URISyntaxException e) { - s_logger.warn("URI syntax error: " + _downloadUrl); + logger.warn("URI syntax error: " + _downloadUrl); _status = Status.UNRECOVERABLE_ERROR; return; } @@ -108,7 +106,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { if (!file.exists()) { _status = Status.UNRECOVERABLE_ERROR; - s_logger.debug("unable to scp the file " + _downloadUrl); + logger.debug("unable to scp the file " + _downloadUrl); return 0; } @@ -123,7 +121,7 @@ public long download(boolean resume, DownloadCompleteCallback callback) { return _totalBytes; } catch (Exception e) { - s_logger.warn("Unable to download " + _downloadUrl, e); + logger.warn("Unable to download " + _downloadUrl, e); _status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; _errorString = e.getMessage(); return 0; diff --git a/core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java b/core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java index 56cf76fb9f61..8719947cb4f0 100644 --- a/core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java @@ -42,12 +42,10 @@ import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.storage.StorageLayer; public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implements TemplateDownloader { - public static final Logger s_logger = Logger.getLogger(SimpleHttpMultiFileDownloader.class.getName()); private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); private static final int CHUNK_SIZE = 1024 * 1024; //1M @@ -110,7 +108,7 @@ private void checkTemporaryDestination(String toDir) { } catch (IOException ex) { errorString = "Unable to start download -- check url? "; currentStatus = TemplateDownloader.Status.UNRECOVERABLE_ERROR; - s_logger.warn("Exception in constructor -- " + ex.toString()); + logger.warn("Exception in constructor -- " + ex.toString()); } } @@ -153,7 +151,7 @@ private void tryAndGetTotalRemoteSize() { } totalRemoteSize += Long.parseLong(contentLengthHeader.getValue()); } catch (IOException e) { - s_logger.warn(String.format("Cannot reach URL: %s while trying to get remote sizes due to: %s", downloadUrl, e.getMessage()), e); + logger.warn(String.format("Cannot reach URL: %s while trying to get remote sizes due to: %s", downloadUrl, e.getMessage()), e); } finally { headMethod.releaseConnection(); } @@ -161,7 +159,7 @@ private void tryAndGetTotalRemoteSize() { } private long downloadFile(String downloadUrl) { - s_logger.debug("Starting download for " + downloadUrl); + logger.debug("Starting download for " + downloadUrl); currentTotalBytes = 0; currentRemoteSize = 0; File file = null; @@ -180,7 +178,7 @@ private long downloadFile(String downloadUrl) { RandomAccessFile out = new RandomAccessFile(file, "rw"); ) { out.seek(localFileSize); - s_logger.info("Starting download from " + downloadUrl + " to " + currentToFile + " remoteSize=" + toHumanReadableSize(currentRemoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes)); + logger.info("Starting download from " + downloadUrl + " to " + currentToFile + " remoteSize=" + toHumanReadableSize(currentRemoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes)); if (copyBytes(file, in, out)) return 0; checkDownloadCompletion(); } @@ -209,11 +207,11 @@ private long downloadFile(String downloadUrl) { public long download(boolean resume, DownloadCompleteCallback callback) { if (skipDownloadOnStatus()) return 0; if (resume) { - s_logger.error("Resume not allowed for this downloader"); + logger.error("Resume not allowed for this downloader"); status = Status.UNRECOVERABLE_ERROR; return 0; } - s_logger.debug("Starting downloads"); + logger.debug("Starting downloads"); status = Status.IN_PROGRESS; Date start = new Date(); tryAndGetTotalRemoteSize(); @@ -272,7 +270,7 @@ private void checkDownloadCompletion() { private boolean canHandleDownloadSize() { if (currentRemoteSize > maxTemplateSizeInBytes) { - s_logger.info("Remote size is too large: " + toHumanReadableSize(currentRemoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes)); + logger.info("Remote size is too large: " + toHumanReadableSize(currentRemoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes)); currentStatus = Status.UNRECOVERABLE_ERROR; errorString = "Download file size is too large"; return false; @@ -337,7 +335,7 @@ private boolean checkServerResponse(long localFileSize, String downloadUrl) thro && !followRedirects) { errorString = String.format("Failed to download %s due to redirection, response code: %d", downloadUrl, responseCode); - s_logger.error(errorString); + logger.error(errorString); } return true; //FIXME: retry? } @@ -349,7 +347,7 @@ private long checkLocalFileSizeForResume(boolean resume, File file) { long localFileSize = 0; if (file.exists() && resume) { localFileSize = file.length(); - s_logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize)); + logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize)); } return localFileSize; } @@ -433,7 +431,7 @@ protected void runInContext() { try { download(resume, completionCallback); } catch (Throwable t) { - s_logger.warn("Caught exception during download " + t.getMessage(), t); + logger.warn("Caught exception during download " + t.getMessage(), t); errorString = "Failed to install: " + t.getMessage(); currentStatus = TemplateDownloader.Status.UNRECOVERABLE_ERROR; } diff --git a/core/src/main/java/com/cloud/storage/template/TARProcessor.java b/core/src/main/java/com/cloud/storage/template/TARProcessor.java index 51aeb234c50d..70b59336323b 100644 --- a/core/src/main/java/com/cloud/storage/template/TARProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/TARProcessor.java @@ -22,14 +22,12 @@ import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageLayer; import com.cloud.utils.component.AdapterBase; -import org.apache.log4j.Logger; import javax.naming.ConfigurationException; import java.io.File; import java.util.Map; public class TARProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(TARProcessor.class); private StorageLayer _storage; @@ -41,14 +39,14 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) { if (format != null) { - s_logger.debug("We currently don't handle conversion from " + format + " to TAR."); + logger.debug("We currently don't handle conversion from " + format + " to TAR."); return null; } String tarPath = templatePath + File.separator + templateName + "." + ImageFormat.TAR.getFileExtension(); if (!_storage.exists(tarPath)) { - s_logger.debug("Unable to find the tar file: " + tarPath); + logger.debug("Unable to find the tar file: " + tarPath); return null; } diff --git a/core/src/main/java/com/cloud/storage/template/TemplateDownloaderBase.java b/core/src/main/java/com/cloud/storage/template/TemplateDownloaderBase.java index 66058bbf82e4..f1cb21a1815a 100644 --- a/core/src/main/java/com/cloud/storage/template/TemplateDownloaderBase.java +++ b/core/src/main/java/com/cloud/storage/template/TemplateDownloaderBase.java @@ -21,14 +21,12 @@ import java.io.File; -import org.apache.log4j.Logger; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import com.cloud.storage.StorageLayer; public abstract class TemplateDownloaderBase extends ManagedContextRunnable implements TemplateDownloader { - private static final Logger s_logger = Logger.getLogger(TemplateDownloaderBase.class); protected String _downloadUrl; protected String _toFile; @@ -134,7 +132,7 @@ protected void runInContext() { try { download(_resume, _callback); } catch (Exception e) { - s_logger.warn("Unable to complete download due to ", e); + logger.warn("Unable to complete download due to ", e); _errorString = "Failed to install: " + e.getMessage(); _status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; } diff --git a/core/src/main/java/com/cloud/storage/template/TemplateLocation.java b/core/src/main/java/com/cloud/storage/template/TemplateLocation.java index 6ff53a0410a9..563c642f292e 100644 --- a/core/src/main/java/com/cloud/storage/template/TemplateLocation.java +++ b/core/src/main/java/com/cloud/storage/template/TemplateLocation.java @@ -31,15 +31,16 @@ import java.util.Properties; import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType; -import org.apache.log4j.Logger; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageLayer; import com.cloud.storage.template.Processor.FormatInfo; import com.cloud.utils.NumbersUtil; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class TemplateLocation { - private static final Logger s_logger = Logger.getLogger(TemplateLocation.class); + protected Logger logger = LogManager.getLogger(getClass()); public final static String Filename = "template.properties"; StorageLayer _storage; @@ -90,8 +91,8 @@ public boolean purge() { if (!isRemoved) { purged = false; } - if (s_logger.isDebugEnabled()) { - s_logger.debug((isRemoved ? "Removed " : "Unable to remove") + file); + if (logger.isDebugEnabled()) { + logger.debug((isRemoved ? "Removed " : "Unable to remove") + file); } } @@ -102,27 +103,27 @@ public boolean load() throws IOException { try (FileInputStream strm = new FileInputStream(_file);) { _props.load(strm); } catch (IOException e) { - s_logger.warn("Unable to load the template properties for '" + _file + "': ", e); + logger.warn("Unable to load the template properties for '" + _file + "': ", e); } for (ImageFormat format : ImageFormat.values()) { String currentExtension = format.getFileExtension(); String ext = _props.getProperty(currentExtension); if (ext != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("File extension '" + currentExtension + "' was found in '" + _file + "'."); + if (logger.isDebugEnabled()) { + logger.debug("File extension '" + currentExtension + "' was found in '" + _file + "'."); } FormatInfo info = new FormatInfo(); info.format = format; info.filename = _props.getProperty(currentExtension + ".filename"); if (info.filename == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Property '" + currentExtension + ".filename' was not found in '" + _file + "'. Current format is ignored."); + if (logger.isDebugEnabled()) { + logger.debug("Property '" + currentExtension + ".filename' was not found in '" + _file + "'. Current format is ignored."); } continue; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Property '" + currentExtension + ".filename' was found in '" + _file + "'. Current format will be parsed."); + if (logger.isDebugEnabled()) { + logger.debug("Property '" + currentExtension + ".filename' was found in '" + _file + "'. Current format will be parsed."); } info.size = NumbersUtil.parseLong(_props.getProperty(currentExtension + ".size"), -1); _props.setProperty("physicalSize", Long.toString(info.size)); @@ -131,18 +132,18 @@ public boolean load() throws IOException { if (!checkFormatValidity(info)) { _isCorrupted = true; - s_logger.warn("Cleaning up inconsistent information for " + format); + logger.warn("Cleaning up inconsistent information for " + format); } } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Format extension '" + currentExtension + "' wasn't found in '" + _file + "'."); + if (logger.isDebugEnabled()) { + logger.debug("Format extension '" + currentExtension + "' wasn't found in '" + _file + "'."); } } } if (_props.getProperty("uniquename") == null || _props.getProperty("virtualsize") == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Property 'uniquename' or 'virtualsize' weren't found in '" + _file + "'. Loading failed."); + if (logger.isDebugEnabled()) { + logger.debug("Property 'uniquename' or 'virtualsize' weren't found in '" + _file + "'. Loading failed."); } return false; } @@ -160,7 +161,7 @@ public boolean save() { try (FileOutputStream strm = new FileOutputStream(_file);) { _props.store(strm, ""); } catch (IOException e) { - s_logger.warn("Unable to save the template properties ", e); + logger.warn("Unable to save the template properties ", e); return false; } return true; @@ -204,9 +205,9 @@ public boolean addFormat(FormatInfo newInfo) { deleteFormat(newInfo.format); if (!checkFormatValidity(newInfo)) { - s_logger.warn("Format is invalid"); - s_logger.debug("Format: " + newInfo.format + " size: " + toHumanReadableSize(newInfo.size) + " virtualsize: " + toHumanReadableSize(newInfo.virtualSize) + " filename: " + newInfo.filename); - s_logger.debug("format, filename cannot be null and size, virtual size should be > 0 "); + logger.warn("Format is invalid"); + logger.debug("Format: " + newInfo.format + " size: " + toHumanReadableSize(newInfo.size) + " virtualsize: " + toHumanReadableSize(newInfo.virtualSize) + " filename: " + newInfo.filename); + logger.debug("format, filename cannot be null and size, virtual size should be > 0 "); return false; } diff --git a/core/src/main/java/com/cloud/storage/template/VhdProcessor.java b/core/src/main/java/com/cloud/storage/template/VhdProcessor.java index baea7bf0db51..9f18d782b426 100644 --- a/core/src/main/java/com/cloud/storage/template/VhdProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/VhdProcessor.java @@ -27,7 +27,6 @@ import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; -import org.apache.log4j.Logger; import javax.naming.ConfigurationException; import java.io.BufferedInputStream; @@ -46,7 +45,6 @@ */ public class VhdProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(VhdProcessor.class); StorageLayer _storage; private int vhdFooterSize = 512; private int vhdCookieOffset = 8; @@ -64,13 +62,13 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) throws InternalErrorException { if (format != null) { - s_logger.debug("We currently don't handle conversion from " + format + " to VHD."); + logger.debug("We currently don't handle conversion from " + format + " to VHD."); return null; } String vhdPath = templatePath + File.separator + templateName + "." + ImageFormat.VHD.getFileExtension(); if (!_storage.exists(vhdPath)) { - s_logger.debug("Unable to find the vhd file: " + vhdPath); + logger.debug("Unable to find the vhd file: " + vhdPath); return null; } @@ -84,7 +82,7 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa try { info.virtualSize = getTemplateVirtualSize(vhdFile); } catch (IOException e) { - s_logger.error("Unable to get the virtual size for " + vhdPath); + logger.error("Unable to get the virtual size for " + vhdPath); throw new InternalErrorException("unable to get virtual size from vhd file"); } @@ -97,7 +95,7 @@ public long getVirtualSize(File file) throws IOException { long size = getTemplateVirtualSize(file); return size; } catch (Exception e) { - s_logger.info("[ignored]" + "failed to get template virtual size for VHD: " + e.getLocalizedMessage()); + logger.info("[ignored]" + "failed to get template virtual size for VHD: " + e.getLocalizedMessage()); } return file.length(); } @@ -117,7 +115,7 @@ protected long getTemplateVirtualSize(File file) throws IOException { try { strm = new CompressorStreamFactory().createCompressorInputStream(fileStream); } catch (CompressorException e) { - s_logger.info("error opening compressed VHD file " + file.getName()); + logger.info("error opening compressed VHD file " + file.getName()); return file.length(); } } try { @@ -146,7 +144,7 @@ protected long getTemplateVirtualSize(File file) throws IOException { throw new IOException("Unexpected end-of-file"); } } catch (IOException e) { - s_logger.warn("Error reading virtual size from VHD file " + e.getMessage() + " VHD: " + file.getName()); + logger.warn("Error reading virtual size from VHD file " + e.getMessage() + " VHD: " + file.getName()); return file.length(); } finally { if (strm != null) { @@ -180,11 +178,11 @@ private boolean checkCompressed(String fileName) throws IOException { cin = new CompressorStreamFactory().createCompressorInputStream(bin); } catch (CompressorException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); return false; } catch (FileNotFoundException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); return false; } finally { if (cin != null) diff --git a/core/src/main/java/com/cloud/storage/template/VmdkProcessor.java b/core/src/main/java/com/cloud/storage/template/VmdkProcessor.java index 927515f75441..4f53c556667f 100644 --- a/core/src/main/java/com/cloud/storage/template/VmdkProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/VmdkProcessor.java @@ -30,7 +30,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; import com.cloud.storage.Storage.ImageFormat; @@ -40,7 +39,6 @@ import static com.cloud.utils.NumbersUtil.toHumanReadableSize; public class VmdkProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(VmdkProcessor.class); StorageLayer _storage; @@ -52,17 +50,17 @@ public FormatInfo process(String templatePath, ImageFormat format, String templa @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) throws InternalErrorException { if (format != null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("We currently don't handle conversion from " + format + " to VMDK."); + if (logger.isInfoEnabled()) { + logger.info("We currently don't handle conversion from " + format + " to VMDK."); } return null; } - s_logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); + logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); String templateFilePath = templatePath + File.separator + templateName + "." + ImageFormat.VMDK.getFileExtension(); if (!_storage.exists(templateFilePath)) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Unable to find the vmware template file: " + templateFilePath); + if (logger.isInfoEnabled()) { + logger.info("Unable to find the vmware template file: " + templateFilePath); } return null; } @@ -82,7 +80,7 @@ public long getVirtualSize(File file) { long size = getTemplateVirtualSize(file.getParent(), file.getName()); return size; } catch (Exception e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "failed to get template virtual size for vmdk: " + e.getLocalizedMessage()); } return file.length(); @@ -108,15 +106,15 @@ public long getTemplateVirtualSize(String templatePath, String templateName) thr } } catch(FileNotFoundException ex) { String msg = "Unable to open file '" + templateFileFullPath + "' " + ex.toString(); - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } catch(IOException ex) { String msg = "Unable read open file '" + templateFileFullPath + "' " + ex.toString(); - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } - s_logger.debug("vmdk file had size=" + toHumanReadableSize(virtualSize)); + logger.debug("vmdk file had size=" + toHumanReadableSize(virtualSize)); return virtualSize; } diff --git a/core/src/main/java/org/apache/cloudstack/backup/BackupAnswer.java b/core/src/main/java/org/apache/cloudstack/backup/BackupAnswer.java new file mode 100644 index 000000000000..09f9c5621502 --- /dev/null +++ b/core/src/main/java/org/apache/cloudstack/backup/BackupAnswer.java @@ -0,0 +1,59 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package org.apache.cloudstack.backup; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; + +import java.util.Map; + +public class BackupAnswer extends Answer { + private Long size; + private Long virtualSize; + private Map volumes; + + public BackupAnswer(final Command command, final boolean success, final String details) { + super(command, success, details); + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public Long getVirtualSize() { + return virtualSize; + } + + public void setVirtualSize(Long virtualSize) { + this.virtualSize = virtualSize; + } + + public Map getVolumes() { + return volumes; + } + + public void setVolumes(Map volumes) { + this.volumes = volumes; + } +} diff --git a/core/src/main/java/org/apache/cloudstack/backup/DeleteBackupCommand.java b/core/src/main/java/org/apache/cloudstack/backup/DeleteBackupCommand.java new file mode 100644 index 000000000000..16c611af998e --- /dev/null +++ b/core/src/main/java/org/apache/cloudstack/backup/DeleteBackupCommand.java @@ -0,0 +1,76 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package org.apache.cloudstack.backup; + +import com.cloud.agent.api.Command; +import com.cloud.agent.api.LogLevel; + +public class DeleteBackupCommand extends Command { + private String backupPath; + private String backupRepoType; + private String backupRepoAddress; + @LogLevel(LogLevel.Log4jLevel.Off) + private String mountOptions; + + public DeleteBackupCommand(String backupPath, String backupRepoType, String backupRepoAddress, String mountOptions) { + super(); + this.backupPath = backupPath; + this.backupRepoType = backupRepoType; + this.backupRepoAddress = backupRepoAddress; + this.mountOptions = mountOptions; + } + + public String getBackupPath() { + return backupPath; + } + + public void setBackupPath(String backupPath) { + this.backupPath = backupPath; + } + + public String getBackupRepoType() { + return backupRepoType; + } + + public void setBackupRepoType(String backupRepoType) { + this.backupRepoType = backupRepoType; + } + + public String getBackupRepoAddress() { + return backupRepoAddress; + } + + public void setBackupRepoAddress(String backupRepoAddress) { + this.backupRepoAddress = backupRepoAddress; + } + + public String getMountOptions() { + return mountOptions == null ? "" : mountOptions; + } + + public void setMountOptions(String mountOptions) { + this.mountOptions = mountOptions; + } + + @Override + public boolean executeInSequence() { + return true; + } +} diff --git a/core/src/main/java/org/apache/cloudstack/backup/RestoreBackupCommand.java b/core/src/main/java/org/apache/cloudstack/backup/RestoreBackupCommand.java new file mode 100644 index 000000000000..7228e35147af --- /dev/null +++ b/core/src/main/java/org/apache/cloudstack/backup/RestoreBackupCommand.java @@ -0,0 +1,130 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package org.apache.cloudstack.backup; + +import com.cloud.agent.api.Command; +import com.cloud.agent.api.LogLevel; +import com.cloud.vm.VirtualMachine; + +import java.util.List; + +public class RestoreBackupCommand extends Command { + private String vmName; + private String backupPath; + private String backupRepoType; + private String backupRepoAddress; + private List volumePaths; + private String diskType; + private Boolean vmExists; + private String restoreVolumeUUID; + private VirtualMachine.State vmState; + + protected RestoreBackupCommand() { + super(); + } + + public String getVmName() { + return vmName; + } + + public void setVmName(String vmName) { + this.vmName = vmName; + } + + public String getBackupPath() { + return backupPath; + } + + public void setBackupPath(String backupPath) { + this.backupPath = backupPath; + } + + public String getBackupRepoType() { + return backupRepoType; + } + + public void setBackupRepoType(String backupRepoType) { + this.backupRepoType = backupRepoType; + } + + public String getBackupRepoAddress() { + return backupRepoAddress; + } + + public void setBackupRepoAddress(String backupRepoAddress) { + this.backupRepoAddress = backupRepoAddress; + } + + public List getVolumePaths() { + return volumePaths; + } + + public void setVolumePaths(List volumePaths) { + this.volumePaths = volumePaths; + } + + public Boolean isVmExists() { + return vmExists; + } + + public void setVmExists(Boolean vmExists) { + this.vmExists = vmExists; + } + + public String getDiskType() { + return diskType; + } + + public void setDiskType(String diskType) { + this.diskType = diskType; + } + + public String getMountOptions() { + return mountOptions; + } + + public void setMountOptions(String mountOptions) { + this.mountOptions = mountOptions; + } + + public String getRestoreVolumeUUID() { + return restoreVolumeUUID; + } + + public void setRestoreVolumeUUID(String restoreVolumeUUID) { + this.restoreVolumeUUID = restoreVolumeUUID; + } + + public VirtualMachine.State getVmState() { + return vmState; + } + + public void setVmState(VirtualMachine.State vmState) { + this.vmState = vmState; + } + + @LogLevel(LogLevel.Log4jLevel.Off) + private String mountOptions; + @Override + + public boolean executeInSequence() { + return true; + } +} diff --git a/core/src/main/java/org/apache/cloudstack/backup/TakeBackupCommand.java b/core/src/main/java/org/apache/cloudstack/backup/TakeBackupCommand.java new file mode 100644 index 000000000000..93855ea17211 --- /dev/null +++ b/core/src/main/java/org/apache/cloudstack/backup/TakeBackupCommand.java @@ -0,0 +1,94 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package org.apache.cloudstack.backup; + +import com.cloud.agent.api.Command; +import com.cloud.agent.api.LogLevel; + +import java.util.List; + +public class TakeBackupCommand extends Command { + private String vmName; + private String backupPath; + private String backupRepoType; + private String backupRepoAddress; + private List volumePaths; + @LogLevel(LogLevel.Log4jLevel.Off) + private String mountOptions; + + public TakeBackupCommand(String vmName, String backupPath) { + super(); + this.vmName = vmName; + this.backupPath = backupPath; + } + + public String getVmName() { + return vmName; + } + + public void setVmName(String vmName) { + this.vmName = vmName; + } + + public String getBackupPath() { + return backupPath; + } + + public void setBackupPath(String backupPath) { + this.backupPath = backupPath; + } + + public String getBackupRepoType() { + return backupRepoType; + } + + public void setBackupRepoType(String backupRepoType) { + this.backupRepoType = backupRepoType; + } + + public String getBackupRepoAddress() { + return backupRepoAddress; + } + + public void setBackupRepoAddress(String backupRepoAddress) { + this.backupRepoAddress = backupRepoAddress; + } + + public String getMountOptions() { + return mountOptions; + } + + public void setMountOptions(String mountOptions) { + this.mountOptions = mountOptions; + } + + public List getVolumePaths() { + return volumePaths; + } + + public void setVolumePaths(List volumePaths) { + this.volumePaths = volumePaths; + } + + @Override + public boolean executeInSequence() { + return true; + } +} diff --git a/core/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsAnswer.java b/core/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsAnswer.java index 7390e4fcdd2a..6421f45ed0a7 100644 --- a/core/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsAnswer.java +++ b/core/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsAnswer.java @@ -21,13 +21,11 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.lang3.StringUtils; import org.apache.cloudstack.api.ApiConstants; -import org.apache.log4j.Logger; import java.util.HashMap; import java.util.Map; public class DiagnosticsAnswer extends Answer { - public static final Logger LOGGER = Logger.getLogger(DiagnosticsAnswer.class); public DiagnosticsAnswer(DiagnosticsCommand cmd, boolean result, String details) { super(cmd, result, details); diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadHelper.java b/core/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadHelper.java index a00274e259e0..0e0e2f0b57b8 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadHelper.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadHelper.java @@ -24,11 +24,12 @@ import org.apache.cloudstack.agent.directdownload.HttpsDirectDownloadCommand; import org.apache.cloudstack.agent.directdownload.MetalinkDirectDownloadCommand; import org.apache.cloudstack.agent.directdownload.NfsDirectDownloadCommand; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class DirectDownloadHelper { - public static final Logger LOGGER = Logger.getLogger(DirectDownloadHelper.class.getName()); + protected static Logger LOGGER = LogManager.getLogger(DirectDownloadHelper.class); /** * Get direct template downloader from direct download command and destination pool diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/DirectTemplateDownloaderImpl.java b/core/src/main/java/org/apache/cloudstack/direct/download/DirectTemplateDownloaderImpl.java index 9431b8209b33..d22c803818be 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/DirectTemplateDownloaderImpl.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/DirectTemplateDownloaderImpl.java @@ -22,7 +22,8 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.utils.security.DigestHelper; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.io.File; import java.io.FileInputStream; @@ -44,7 +45,7 @@ public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDown protected String temporaryDownloadPath; private boolean followRedirects; - public static final Logger s_logger = Logger.getLogger(DirectTemplateDownloaderImpl.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); protected DirectTemplateDownloaderImpl(final String url, final String destPoolPath, final Long templateId, final String checksum, final String temporaryDownloadPath, @@ -146,16 +147,16 @@ public boolean validateChecksum() { try { while (!valid && retry > 0) { retry--; - s_logger.info("Performing checksum validation for downloaded template " + templateId + " using " + checksum + ", retries left: " + retry); + logger.info("Performing checksum validation for downloaded template " + templateId + " using " + checksum + ", retries left: " + retry); valid = DigestHelper.check(checksum, new FileInputStream(downloadedFilePath)); if (!valid && retry > 0) { - s_logger.info("Checksum validation failed, re-downloading template"); + logger.info("Checksum validation failed, re-downloading template"); redownload = true; resetDownloadFile(); downloadTemplate(); } } - s_logger.info("Checksum validation for template " + templateId + ": " + (valid ? "succeeded" : "failed")); + logger.info("Checksum validation for template " + templateId + ": " + (valid ? "succeeded" : "failed")); return valid; } catch (IOException e) { throw new CloudRuntimeException("could not check sum for file: " + downloadedFilePath, e); @@ -163,7 +164,7 @@ public boolean validateChecksum() { throw new CloudRuntimeException("Unknown checksum algorithm: " + checksum, e); } } - s_logger.info("No checksum provided, skipping checksum validation"); + logger.info("No checksum provided, skipping checksum validation"); return true; } @@ -172,14 +173,14 @@ public boolean validateChecksum() { */ private void resetDownloadFile() { File f = new File(getDownloadedFilePath()); - s_logger.info("Resetting download file: " + getDownloadedFilePath() + ", in order to re-download and persist template " + templateId + " on it"); + logger.info("Resetting download file: " + getDownloadedFilePath() + ", in order to re-download and persist template " + templateId + " on it"); try { if (f.exists()) { f.delete(); } f.createNewFile(); } catch (IOException e) { - s_logger.error("Error creating file to download on: " + getDownloadedFilePath() + " due to: " + e.getMessage()); + logger.error("Error creating file to download on: " + getDownloadedFilePath() + " due to: " + e.getMessage()); throw new CloudRuntimeException("Failed to create download file for direct download"); } } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java b/core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java index 068f6b08418a..8c4147fad606 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java @@ -40,13 +40,11 @@ import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { protected HttpClient client; private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); - public static final Logger s_logger = Logger.getLogger(HttpDirectTemplateDownloader.class.getName()); protected GetMethod request; protected Map reqHeaders = new HashMap<>(); @@ -84,7 +82,7 @@ public Pair downloadTemplate() { try { int status = client.executeMethod(request); if (status != HttpStatus.SC_OK) { - s_logger.warn("Not able to download template, status code: " + status); + logger.warn("Not able to download template, status code: " + status); return new Pair<>(false, null); } return performDownload(); @@ -96,14 +94,14 @@ public Pair downloadTemplate() { } protected Pair performDownload() { - s_logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); + logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); try ( InputStream in = request.getResponseBodyAsStream(); OutputStream out = new FileOutputStream(getDownloadedFilePath()) ) { IOUtils.copy(in, out); } catch (IOException e) { - s_logger.error("Error downloading template " + getTemplateId() + " due to: " + e.getMessage()); + logger.error("Error downloading template " + getTemplateId() + " due to: " + e.getMessage()); return new Pair<>(false, null); } return new Pair<>(true, getDownloadedFilePath()); @@ -116,12 +114,12 @@ public boolean checkUrl(String url) { try { int responseCode = client.executeMethod(httpHead); if (responseCode != HttpStatus.SC_OK) { - s_logger.error(String.format("HTTP HEAD request to URL: %s failed, response code: %d", url, responseCode)); + logger.error(String.format("HTTP HEAD request to URL: %s failed, response code: %d", url, responseCode)); return false; } return true; } catch (IOException e) { - s_logger.error(String.format("Cannot reach URL: %s due to: %s", url, e.getMessage()), e); + logger.error(String.format("Cannot reach URL: %s due to: %s", url, e.getMessage()), e); return false; } finally { httpHead.releaseConnection(); @@ -145,7 +143,7 @@ public List getMetalinkUrls(String metalinkUrl) { try { status = client.executeMethod(getMethod); } catch (IOException e) { - s_logger.error("Error retrieving urls form metalink: " + metalinkUrl); + logger.error("Error retrieving urls form metalink: " + metalinkUrl); getMethod.releaseConnection(); return null; } @@ -155,7 +153,7 @@ public List getMetalinkUrls(String metalinkUrl) { addMetalinkUrlsToListFromInputStream(is, urls); } } catch (IOException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); } finally { getMethod.releaseConnection(); } @@ -171,7 +169,7 @@ public List getMetalinkChecksums(String metalinkUrl) { return generateChecksumListFromInputStream(is); } } catch (IOException e) { - s_logger.error(String.format("Error obtaining metalink checksums on URL %s: %s", metalinkUrl, e.getMessage()), e); + logger.error(String.format("Error obtaining metalink checksums on URL %s: %s", metalinkUrl, e.getMessage()), e); } finally { getMethod.releaseConnection(); } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java b/core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java index 3a48ade4cd86..b8a25a11b5c4 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java @@ -125,7 +125,7 @@ private SSLContext getSSLContext() { sslContext.init(null, tm, null); return sslContext; } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | KeyManagementException e) { - s_logger.error(String.format("Failure getting SSL context for HTTPS downloader, using default SSL context: %s", e.getMessage()), e); + logger.error(String.format("Failure getting SSL context for HTTPS downloader, using default SSL context: %s", e.getMessage()), e); try { return SSLContext.getDefault(); } catch (NoSuchAlgorithmException ex) { @@ -150,7 +150,7 @@ public Pair downloadTemplate() { * Consume response and persist it on getDownloadedFilePath() file */ protected Pair consumeResponse(CloseableHttpResponse response) { - s_logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); + logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); if (response.getStatusLine().getStatusCode() != 200) { throw new CloudRuntimeException("Error on HTTPS response"); } @@ -160,7 +160,7 @@ protected Pair consumeResponse(CloseableHttpResponse response) OutputStream out = new FileOutputStream(getDownloadedFilePath()); IOUtils.copy(in, out); } catch (Exception e) { - s_logger.error("Error parsing response for template " + getTemplateId() + " due to: " + e.getMessage()); + logger.error("Error parsing response for template " + getTemplateId() + " due to: " + e.getMessage()); return new Pair<>(false, null); } return new Pair<>(true, getDownloadedFilePath()); @@ -173,12 +173,12 @@ public boolean checkUrl(String url) { CloseableHttpResponse response = httpsClient.execute(httpHead); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) { - s_logger.error(String.format("HTTP HEAD request to URL: %s failed, response code: %d", url, responseCode)); + logger.error(String.format("HTTP HEAD request to URL: %s failed, response code: %d", url, responseCode)); return false; } return true; } catch (IOException e) { - s_logger.error(String.format("Cannot reach URL: %s due to: %s", url, e.getMessage()), e); + logger.error(String.format("Cannot reach URL: %s due to: %s", url, e.getMessage()), e); return false; } finally { httpHead.releaseConnection(); @@ -223,11 +223,11 @@ public List getMetalinkUrls(String metalinkUrl) { response = httpsClient.execute(getMethod); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { String msg = String.format("Cannot access metalink content on URL %s", metalinkUrl); - s_logger.error(msg); + logger.error(msg); throw new IOException(msg); } } catch (IOException e) { - s_logger.error(String.format("Error retrieving urls form metalink URL %s: %s", metalinkUrl, e.getMessage()), e); + logger.error(String.format("Error retrieving urls form metalink URL %s: %s", metalinkUrl, e.getMessage()), e); getMethod.releaseConnection(); return null; } @@ -237,7 +237,7 @@ public List getMetalinkUrls(String metalinkUrl) { ByteArrayInputStream inputStream = new ByteArrayInputStream(responseStr.getBytes(StandardCharsets.UTF_8)); addMetalinkUrlsToListFromInputStream(inputStream, urls); } catch (IOException e) { - s_logger.warn(e.getMessage(), e); + logger.warn(e.getMessage(), e); } finally { getMethod.releaseConnection(); } @@ -254,7 +254,7 @@ public List getMetalinkChecksums(String metalinkUrl) { return generateChecksumListFromInputStream(is); } } catch (IOException e) { - s_logger.error(String.format("Error obtaining metalink checksums on URL %s: %s", metalinkUrl, e.getMessage()), e); + logger.error(String.format("Error obtaining metalink checksums on URL %s: %s", metalinkUrl, e.getMessage()), e); } finally { getMethod.releaseConnection(); } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloader.java b/core/src/main/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloader.java index 86b97880a857..5335da991506 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloader.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloader.java @@ -23,7 +23,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; import java.util.List; @@ -39,8 +38,6 @@ public class MetalinkDirectTemplateDownloader extends DirectTemplateDownloaderIm private Integer connectTimeout; private Integer soTimeout; - private static final Logger s_logger = Logger.getLogger(MetalinkDirectTemplateDownloader.class.getName()); - protected DirectTemplateDownloader createDownloaderForMetalinks(String url, Long templateId, String destPoolPath, String checksum, Map headers, Integer connectTimeout, Integer soTimeout, Integer connectionRequestTimeout, String temporaryDownloadPath) { @@ -54,7 +51,7 @@ protected DirectTemplateDownloader createDownloaderForMetalinks(String url, Long } else if (url.toLowerCase().startsWith("nfs:")) { return new NfsDirectTemplateDownloader(url); } else { - s_logger.error(String.format("Cannot find a suitable downloader to handle the metalink URL %s", url)); + logger.error(String.format("Cannot find a suitable downloader to handle the metalink URL %s", url)); return null; } } @@ -75,10 +72,10 @@ public MetalinkDirectTemplateDownloader(String url, String destPoolPath, Long te metalinkUrls = downloader.getMetalinkUrls(url); metalinkChecksums = downloader.getMetalinkChecksums(url); if (CollectionUtils.isEmpty(metalinkUrls)) { - s_logger.error(String.format("No urls found on metalink file: %s. Not possible to download template %s ", url, templateId)); + logger.error(String.format("No urls found on metalink file: %s. Not possible to download template %s ", url, templateId)); } else { setUrl(metalinkUrls.get(0)); - s_logger.info("Metalink downloader created, metalink url: " + url + " parsed - " + + logger.info("Metalink downloader created, metalink url: " + url + " parsed - " + metalinkUrls.size() + " urls and " + (CollectionUtils.isNotEmpty(metalinkChecksums) ? metalinkChecksums.size() : "0") + " checksums found"); } @@ -96,7 +93,7 @@ public Pair downloadTemplate() { if (!isRedownload()) { setUrl(metalinkUrls.get(i)); } - s_logger.info("Trying to download template from url: " + getUrl()); + logger.info("Trying to download template from url: " + getUrl()); DirectTemplateDownloader urlDownloader = createDownloaderForMetalinks(getUrl(), getTemplateId(), getDestPoolPath(), getChecksum(), headers, connectTimeout, soTimeout, null, temporaryDownloadPath); try { @@ -109,10 +106,10 @@ public Pair downloadTemplate() { Pair downloadResult = urlDownloader.downloadTemplate(); downloaded = downloadResult.first(); if (downloaded) { - s_logger.info("Successfully downloaded template from url: " + getUrl()); + logger.info("Successfully downloaded template from url: " + getUrl()); } } catch (Exception e) { - s_logger.error(String.format("Error downloading template: %s from URL: %s due to: %s", getTemplateId(), getUrl(), e.getMessage()), e); + logger.error(String.format("Error downloading template: %s from URL: %s due to: %s", getTemplateId(), getUrl(), e.getMessage()), e); } i++; } @@ -125,7 +122,7 @@ public boolean validateChecksum() { if (StringUtils.isBlank(getChecksum()) && CollectionUtils.isNotEmpty(metalinkChecksums)) { String chk = metalinkChecksums.get(random.nextInt(metalinkChecksums.size())); setChecksum(chk); - s_logger.info("Checksum not provided but " + metalinkChecksums.size() + " found on metalink file, performing checksum using one of them: " + chk); + logger.info("Checksum not provided but " + metalinkChecksums.size() + " found on metalink file, performing checksum using one of them: " + chk); } return super.validateChecksum(); } @@ -133,7 +130,7 @@ public boolean validateChecksum() { @Override public boolean checkUrl(String metalinkUrl) { if (!downloader.checkUrl(metalinkUrl)) { - s_logger.error(String.format("Metalink URL check failed for: %s", metalinkUrl)); + logger.error(String.format("Metalink URL check failed for: %s", metalinkUrl)); return false; } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/NfsDirectTemplateDownloader.java b/core/src/main/java/org/apache/cloudstack/direct/download/NfsDirectTemplateDownloader.java index e5ff533cc978..21184ef07fe9 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/NfsDirectTemplateDownloader.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/NfsDirectTemplateDownloader.java @@ -81,7 +81,7 @@ public boolean checkUrl(String url) { parseUrl(); return true; } catch (CloudRuntimeException e) { - s_logger.error(String.format("Cannot check URL %s is reachable due to: %s", url, e.getMessage()), e); + logger.error(String.format("Cannot check URL %s is reachable due to: %s", url, e.getMessage()), e); return false; } } diff --git a/core/src/main/java/org/apache/cloudstack/transport/HypervisorTypeAdaptor.java b/core/src/main/java/org/apache/cloudstack/transport/HypervisorTypeAdaptor.java new file mode 100644 index 000000000000..bc4d3c3a6e3b --- /dev/null +++ b/core/src/main/java/org/apache/cloudstack/transport/HypervisorTypeAdaptor.java @@ -0,0 +1,53 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.transport; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +/** + * {@link HypervisorType} acts as extendable set of singleton objects and should return same result when used "==" + * or {@link Object#equals(Object)}. + * To support that, need to return existing object for a given name instead of creating new. + */ +public class HypervisorTypeAdaptor implements JsonDeserializer, JsonSerializer { + @Override + public HypervisorType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if (json instanceof JsonPrimitive && ((JsonPrimitive) json).isString()) { + return HypervisorType.valueOf(json.getAsString()); + } + return null; + } + + @Override + public JsonElement serialize(HypervisorType src, Type typeOfSrc, JsonSerializationContext context) { + String name = src.name(); + if (name == null) { + return new JsonNull(); + } + return new JsonPrimitive(name); + } +} diff --git a/core/src/main/resources/META-INF/cloudstack/allocator/spring-core-allocator-context.xml b/core/src/main/resources/META-INF/cloudstack/allocator/spring-core-allocator-context.xml index a0d1b4cfd435..9f04a7fb6186 100644 --- a/core/src/main/resources/META-INF/cloudstack/allocator/spring-core-allocator-context.xml +++ b/core/src/main/resources/META-INF/cloudstack/allocator/spring-core-allocator-context.xml @@ -27,7 +27,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" - > + > diff --git a/core/src/main/resources/META-INF/cloudstack/allocator/spring-core-lifecycle-allocator-context-inheritable.xml b/core/src/main/resources/META-INF/cloudstack/allocator/spring-core-lifecycle-allocator-context-inheritable.xml index ec3bb63aeb66..6d05f8583036 100644 --- a/core/src/main/resources/META-INF/cloudstack/allocator/spring-core-lifecycle-allocator-context-inheritable.xml +++ b/core/src/main/resources/META-INF/cloudstack/allocator/spring-core-lifecycle-allocator-context-inheritable.xml @@ -27,7 +27,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" - > + > diff --git a/core/src/main/resources/META-INF/cloudstack/api/spring-core-lifecycle-api-context-inheritable.xml b/core/src/main/resources/META-INF/cloudstack/api/spring-core-lifecycle-api-context-inheritable.xml index 91a35f18a893..995ed30eb5e6 100644 --- a/core/src/main/resources/META-INF/cloudstack/api/spring-core-lifecycle-api-context-inheritable.xml +++ b/core/src/main/resources/META-INF/cloudstack/api/spring-core-lifecycle-api-context-inheritable.xml @@ -62,12 +62,12 @@ - + - + diff --git a/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml b/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml index dbca5deb739b..01c568d78916 100644 --- a/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml +++ b/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml @@ -262,7 +262,7 @@ - + @@ -276,11 +276,11 @@ class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry"> - + - + @@ -288,10 +288,10 @@ + class="org.apache.cloudstack.spring.lifecycle.registry.ExtensionRegistry"> - + @@ -350,4 +350,20 @@ + + + + + + + + + + + + + + + diff --git a/packaging/centos8/cloud.limits b/core/src/main/resources/META-INF/cloudstack/event/module.properties similarity index 94% rename from packaging/centos8/cloud.limits rename to core/src/main/resources/META-INF/cloudstack/event/module.properties index 7debeb290187..ab1f88e98448 100644 --- a/packaging/centos8/cloud.limits +++ b/core/src/main/resources/META-INF/cloudstack/event/module.properties @@ -1,3 +1,4 @@ +# # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -14,6 +15,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +# -cloud hard nofile 4096 -cloud soft nofile 4096 +name=event +parent=core diff --git a/core/src/main/resources/META-INF/cloudstack/event/spring-core-lifecycle-event-context-inheritable.xml b/core/src/main/resources/META-INF/cloudstack/event/spring-core-lifecycle-event-context-inheritable.xml new file mode 100644 index 000000000000..63d11c65bacb --- /dev/null +++ b/core/src/main/resources/META-INF/cloudstack/event/spring-core-lifecycle-event-context-inheritable.xml @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/core/src/main/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml b/core/src/main/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml index 8dbaf6105811..e5c232267ae6 100644 --- a/core/src/main/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml +++ b/core/src/main/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml @@ -92,7 +92,7 @@ - + + + + + + diff --git a/core/src/main/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml b/core/src/main/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml index 2771dfe415f8..a1c9055fd701 100644 --- a/core/src/main/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml +++ b/core/src/main/resources/META-INF/cloudstack/storage/spring-lifecycle-storage-context-inheritable.xml @@ -52,7 +52,7 @@ - + - - + + + + + diff --git a/core/src/main/resources/META-INF/cloudstack/system/spring-core-system-context-inheritable.xml b/core/src/main/resources/META-INF/cloudstack/system/spring-core-system-context-inheritable.xml index 4a59e95de35e..89442fc12b48 100644 --- a/core/src/main/resources/META-INF/cloudstack/system/spring-core-system-context-inheritable.xml +++ b/core/src/main/resources/META-INF/cloudstack/system/spring-core-system-context-inheritable.xml @@ -27,7 +27,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" - > + > @@ -44,8 +44,8 @@ - - diff --git a/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java b/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java index 50c82a764550..1ce3cfb06b95 100644 --- a/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java +++ b/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java @@ -27,7 +27,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.api.SecurityGroupRulesCmd.IpPortAndProto; diff --git a/core/src/test/java/com/cloud/agent/api/routing/SetBgpPeersAnswerTest.java b/core/src/test/java/com/cloud/agent/api/routing/SetBgpPeersAnswerTest.java new file mode 100644 index 000000000000..4cd15e4465a9 --- /dev/null +++ b/core/src/test/java/com/cloud/agent/api/routing/SetBgpPeersAnswerTest.java @@ -0,0 +1,54 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.api.routing; + +import org.apache.cloudstack.network.BgpPeerTO; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.ArrayList; +import java.util.List; + +public class SetBgpPeersAnswerTest { + + @Test + public void testSetBgpPeersAnswer() { + + String good = "good"; + String[] results = new String[1]; + results[0] = good; + + BgpPeerTO bgpPeerTO = Mockito.mock(BgpPeerTO.class); + List bgpPeerTOs = new ArrayList<>(); + bgpPeerTOs.add(bgpPeerTO); + SetBgpPeersCommand command = new SetBgpPeersCommand(bgpPeerTOs); + + SetBgpPeersAnswer answer = new SetBgpPeersAnswer(command, true, results); + + Assert.assertNotNull(answer.getResults()); + Assert.assertEquals(1, answer.getResults().length); + Assert.assertEquals(good, answer.getResults()[0]); + } + + @Test + public void testSetBgpPeersAnswer2() { + SetBgpPeersAnswer answer = new SetBgpPeersAnswer(); + + Assert.assertNull(answer.getResults()); + } +} diff --git a/core/src/test/java/com/cloud/agent/api/routing/SetBgpPeersCommandTest.java b/core/src/test/java/com/cloud/agent/api/routing/SetBgpPeersCommandTest.java new file mode 100644 index 000000000000..882c3b9da301 --- /dev/null +++ b/core/src/test/java/com/cloud/agent/api/routing/SetBgpPeersCommandTest.java @@ -0,0 +1,47 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.api.routing; + +import org.apache.cloudstack.network.BgpPeerTO; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.ArrayList; +import java.util.List; + +public class SetBgpPeersCommandTest { + + @Test + public void testSetBgpPeersCommand1() { + SetBgpPeersCommand command = new SetBgpPeersCommand(); + Assert.assertNull(command.getBpgPeers()); + } + + @Test + public void testSetBgpPeersCommand2() { + BgpPeerTO bgpPeerTO = Mockito.mock(BgpPeerTO.class); + + List bgpPeerTOs = new ArrayList<>(); + bgpPeerTOs.add(bgpPeerTO); + + SetBgpPeersCommand command = new SetBgpPeersCommand(bgpPeerTOs); + Assert.assertNotNull(command.getBpgPeers()); + Assert.assertEquals(1, command.getBpgPeers().length); + Assert.assertEquals(bgpPeerTO, command.getBpgPeers()[0]); + } +} diff --git a/core/src/test/java/com/cloud/agent/resource/virtualnetwork/facade/SetBgpPeersConfigItemTest.java b/core/src/test/java/com/cloud/agent/resource/virtualnetwork/facade/SetBgpPeersConfigItemTest.java new file mode 100644 index 000000000000..5f177c88abfc --- /dev/null +++ b/core/src/test/java/com/cloud/agent/resource/virtualnetwork/facade/SetBgpPeersConfigItemTest.java @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.resource.virtualnetwork.facade; + +import com.cloud.agent.api.routing.SetBgpPeersCommand; +import com.cloud.agent.resource.virtualnetwork.ConfigItem; +import com.cloud.agent.resource.virtualnetwork.FileConfigItem; +import com.cloud.agent.resource.virtualnetwork.ScriptConfigItem; +import com.cloud.agent.resource.virtualnetwork.VRScripts; + +import org.apache.cloudstack.network.BgpPeerTO; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.ArrayList; +import java.util.List; + +public class SetBgpPeersConfigItemTest { + + + @Test + public void testSetBgpPeersConfigItem() { + BgpPeerTO bgpPeerTO = Mockito.mock(BgpPeerTO.class); + List bgpPeerTOs = new ArrayList<>(); + bgpPeerTOs.add(bgpPeerTO); + SetBgpPeersCommand command = new SetBgpPeersCommand(bgpPeerTOs); + + SetBgpPeersConfigItem setBgpPeersConfigItem = new SetBgpPeersConfigItem(); + + List configItems = setBgpPeersConfigItem.generateConfig(command); + Assert.assertNotNull(configItems); + + Assert.assertEquals(2, configItems.size()); + Assert.assertTrue(configItems.get(0) instanceof FileConfigItem); + Assert.assertTrue(configItems.get(1) instanceof ScriptConfigItem); + + Assert.assertEquals(VRScripts.CONFIG_PERSIST_LOCATION, ((FileConfigItem) configItems.get(0)).getFilePath()); + Assert.assertTrue((((FileConfigItem) configItems.get(0)).getFileName().startsWith(VRScripts.BGP_PEERS_CONFIG))); + Assert.assertEquals(VRScripts.UPDATE_CONFIG, ((ScriptConfigItem) configItems.get(1)).getScript()); + } +} diff --git a/core/src/test/java/com/cloud/agent/resource/virtualnetwork/model/BgpPeersTest.java b/core/src/test/java/com/cloud/agent/resource/virtualnetwork/model/BgpPeersTest.java new file mode 100644 index 000000000000..eba423e55ed8 --- /dev/null +++ b/core/src/test/java/com/cloud/agent/resource/virtualnetwork/model/BgpPeersTest.java @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.resource.virtualnetwork.model; + +import org.apache.cloudstack.network.BgpPeerTO; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.ArrayList; +import java.util.List; + +public class BgpPeersTest { + + @Test + public void testBgpPeers() { + BgpPeerTO bgpPeerTO = Mockito.mock(BgpPeerTO.class); + List bgpPeerTOs = new ArrayList<>(); + bgpPeerTOs.add(bgpPeerTO); + + BgpPeers bgpPeers = new BgpPeers(bgpPeerTOs); + Assert.assertEquals(ConfigBase.BGP_PEERS, bgpPeers.getType()); + Assert.assertNotNull(bgpPeers.getPeers()); + Assert.assertEquals(1, bgpPeers.getPeers().size()); + Assert.assertEquals(bgpPeerTO, bgpPeers.getPeers().get(0)); + } + + @Test + public void testBgpPeers2() { + BgpPeers bgpPeers = new BgpPeers(); + Assert.assertEquals(ConfigBase.BGP_PEERS, bgpPeers.getType()); + + BgpPeerTO bgpPeerTO = Mockito.mock(BgpPeerTO.class); + List bgpPeerTOs = new ArrayList<>(); + bgpPeerTOs.add(bgpPeerTO); + bgpPeers.setPeers(bgpPeerTOs); + + Assert.assertNotNull(bgpPeers.getPeers()); + Assert.assertEquals(1, bgpPeers.getPeers().size()); + Assert.assertEquals(bgpPeerTO, bgpPeers.getPeers().get(0)); + } +} diff --git a/core/src/test/java/com/cloud/agent/transport/LoggingExclusionStrategyTest.java b/core/src/test/java/com/cloud/agent/transport/LoggingExclusionStrategyTest.java new file mode 100644 index 000000000000..e02fe4516ab7 --- /dev/null +++ b/core/src/test/java/com/cloud/agent/transport/LoggingExclusionStrategyTest.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.transport; + +import com.cloud.agent.api.BadCommand; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.GetStorageStatsCommand; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class LoggingExclusionStrategyTest { + + @Mock + Logger loggerMock; + @Spy + @InjectMocks + LoggingExclusionStrategy loggingExclusionStrategySpy; + + @Test + public void shouldSkipClassTestArrayClazz() { + List array = new ArrayList<>(); + + boolean result = loggingExclusionStrategySpy.shouldSkipClass(array.getClass()); + + Assert.assertFalse(result); + } + + @Test + public void shouldSkipClassTestNotSubclassOfCommand() { + Integer integer = 1; + + boolean result = loggingExclusionStrategySpy.shouldSkipClass(integer.getClass()); + + Assert.assertFalse(result); + } + + @Test + public void shouldSkipClassTestNullClassAnnotation() { + Command cmd = new BadCommand(); + Mockito.doReturn(true).when(loggerMock).isEnabled(Level.DEBUG); + + boolean result = loggingExclusionStrategySpy.shouldSkipClass(cmd.getClass()); + + Assert.assertFalse(result); + } + + @Test + public void shouldSkipClassTestWithClassAnnotation() { + Command cmd = new GetStorageStatsCommand(); + Mockito.doReturn(true).when(loggerMock).isEnabled(Level.TRACE); + + boolean result = loggingExclusionStrategySpy.shouldSkipClass(cmd.getClass()); + + Assert.assertFalse(result); + } + +} diff --git a/core/src/test/java/com/cloud/agent/transport/RequestTest.java b/core/src/test/java/com/cloud/agent/transport/RequestTest.java index 21766ba038fa..0fe42c7cede8 100644 --- a/core/src/test/java/com/cloud/agent/transport/RequestTest.java +++ b/core/src/test/java/com/cloud/agent/transport/RequestTest.java @@ -22,8 +22,8 @@ import java.nio.ByteBuffer; import junit.framework.TestCase; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.Assert; import org.mockito.Mockito; @@ -43,7 +43,6 @@ import com.cloud.agent.transport.Request.Version; import com.cloud.exception.UnsupportedVersionException; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.serializer.GsonHelper; import com.cloud.storage.DataStoreRole; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.TemplateType; @@ -58,47 +57,22 @@ */ public class RequestTest extends TestCase { - private static final Logger s_logger = Logger.getLogger(RequestTest.class); + protected Logger logger = LogManager.getLogger(getClass()); public void testSerDeser() { - s_logger.info("Testing serializing and deserializing works as expected"); + logger.info("Testing serializing and deserializing works as expected"); - s_logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging"); + logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging"); UpdateHostPasswordCommand cmd1 = new UpdateHostPasswordCommand("abc", "def"); - s_logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level"); + logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level"); SecStorageFirewallCfgCommand cmd2 = new SecStorageFirewallCfgCommand(); - s_logger.info("GetHostStatsCommand should not show up at all in debug level"); + logger.info("GetHostStatsCommand should not show up at all in debug level"); GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101); cmd2.addPortConfig("abc", "24", true, "eth0"); cmd2.addPortConfig("127.0.0.1", "44", false, "eth1"); Request sreq = new Request(2, 3, new Command[] {cmd1, cmd2, cmd3}, true, true); sreq.setSequence(892403717); - Logger logger = Logger.getLogger(GsonHelper.class); - Level level = logger.getLevel(); - - logger.setLevel(Level.DEBUG); - String log = sreq.log("Debug", true, Level.DEBUG); - assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName())); - assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName())); - assert (!log.contains(GetHostStatsCommand.class.getSimpleName())); - assert (!log.contains("username")); - assert (!log.contains("password")); - - logger.setLevel(Level.TRACE); - log = sreq.log("Trace", true, Level.TRACE); - assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName())); - assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName())); - assert (log.contains(GetHostStatsCommand.class.getSimpleName())); - assert (!log.contains("username")); - assert (!log.contains("password")); - - logger.setLevel(Level.INFO); - log = sreq.log("Info", true, Level.INFO); - assert (log == null); - - logger.setLevel(level); - byte[] bytes = sreq.getBytes(); assert Request.getSequence(bytes) == 892403717; @@ -109,9 +83,9 @@ public void testSerDeser() { try { creq = Request.parse(bytes); } catch (ClassNotFoundException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } catch (UnsupportedVersionException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } assert creq != null : "Couldn't get the request back"; @@ -127,9 +101,9 @@ public void testSerDeser() { try { sresp = Response.parse(bytes); } catch (ClassNotFoundException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } catch (UnsupportedVersionException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } assert sresp != null : "Couldn't get the response back"; @@ -138,7 +112,7 @@ public void testSerDeser() { } public void testSerDeserTO() { - s_logger.info("Testing serializing and deserializing interface TO works as expected"); + logger.info("Testing serializing and deserializing interface TO works as expected"); NfsTO nfs = new NfsTO("nfs://192.168.56.10/opt/storage/secondary", DataStoreRole.Image); // SecStorageSetupCommand cmd = new SecStorageSetupCommand(nfs, "nfs://192.168.56.10/opt/storage/secondary", null); @@ -156,9 +130,9 @@ public void testSerDeserTO() { try { creq = Request.parse(bytes); } catch (ClassNotFoundException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } catch (UnsupportedVersionException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } assert creq != null : "Couldn't get the request back"; @@ -168,7 +142,7 @@ public void testSerDeserTO() { } public void testDownload() { - s_logger.info("Testing Download answer"); + logger.info("Testing Download answer"); VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class); Mockito.when(template.getId()).thenReturn(1L); Mockito.when(template.getFormat()).thenReturn(ImageFormat.QCOW2); @@ -193,7 +167,7 @@ public void testDownload() { } public void testCompress() { - s_logger.info("testCompress"); + logger.info("testCompress"); int len = 800000; ByteBuffer inputBuffer = ByteBuffer.allocate(len); for (int i = 0; i < len; i++) { @@ -202,7 +176,7 @@ public void testCompress() { inputBuffer.limit(len); ByteBuffer compressedBuffer = ByteBuffer.allocate(len); compressedBuffer = Request.doCompress(inputBuffer, len); - s_logger.info("compressed length: " + compressedBuffer.limit()); + logger.info("compressed length: " + compressedBuffer.limit()); ByteBuffer decompressedBuffer = ByteBuffer.allocate(len); decompressedBuffer = Request.doDecompress(compressedBuffer, len); for (int i = 0; i < len; i++) { @@ -212,29 +186,6 @@ public void testCompress() { } } - public void testLogging() { - s_logger.info("Testing Logging"); - GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101); - Request sreq = new Request(2, 3, new Command[] {cmd3}, true, true); - sreq.setSequence(1); - Logger logger = Logger.getLogger(GsonHelper.class); - Level level = logger.getLevel(); - - logger.setLevel(Level.DEBUG); - String log = sreq.log("Debug", true, Level.DEBUG); - assert (log == null); - - log = sreq.log("Debug", false, Level.DEBUG); - assert (log != null); - - logger.setLevel(Level.TRACE); - log = sreq.log("Trace", true, Level.TRACE); - assert (log.contains(GetHostStatsCommand.class.getSimpleName())); - s_logger.debug(log); - - logger.setLevel(level); - } - protected void compareRequest(Request req1, Request req2) { assert req1.getSequence() == req2.getSequence(); assert req1.getAgentId() == req2.getAgentId(); @@ -253,24 +204,24 @@ protected void compareRequest(Request req1, Request req2) { } public void testGoodCommand() { - s_logger.info("Testing good Command"); + logger.info("Testing good Command"); String content = "[{\"com.cloud.agent.api.GetVolumeStatsCommand\":{\"volumeUuids\":[\"dcc860ac-4a20-498f-9cb3-bab4d57aa676\"]," - + "\"poolType\":\"NetworkFilesystem\",\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; + + "\"poolType\":{\"name\":\"NetworkFilesystem\"},\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; Request sreq = new Request(Version.v2, 1L, 2L, 3L, 1L, (short)1, content); sreq.setSequence(1); Command cmds[] = sreq.getCommands(); - s_logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); + logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); assert cmds[0].getClass().equals(GetVolumeStatsCommand.class); } public void testBadCommand() { - s_logger.info("Testing Bad Command"); + logger.info("Testing Bad Command"); String content = "[{\"com.cloud.agent.api.SomeJunkCommand\":{\"volumeUuids\":[\"dcc860ac-4a20-498f-9cb3-bab4d57aa676\"]," - + "\"poolType\":\"NetworkFilesystem\",\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; + + "\"poolType\":{\"name\":\"NetworkFilesystem\"},\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; Request sreq = new Request(Version.v2, 1L, 2L, 3L, 1L, (short)1, content); sreq.setSequence(1); Command cmds[] = sreq.getCommands(); - s_logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); + logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); assert cmds[0].getClass().equals(BadCommand.class); } diff --git a/core/src/test/java/com/cloud/serializer/GsonHelperTest.java b/core/src/test/java/com/cloud/serializer/GsonHelperTest.java new file mode 100644 index 000000000000..e8b0b373060b --- /dev/null +++ b/core/src/test/java/com/cloud/serializer/GsonHelperTest.java @@ -0,0 +1,81 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package com.cloud.serializer; + +import com.cloud.agent.api.to.NfsTO; +import com.cloud.storage.DataStoreRole; +import com.google.gson.Gson; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Test cases to verify working order of GsonHelper.java + * with regards to a concrete implementation of the DataStoreTO + * interface + */ +public class GsonHelperTest { + + private Gson gson; + private Gson gsonLogger; + private NfsTO nfsTO; + + @Before + public void setUp() { + gson = GsonHelper.getGson(); + gsonLogger = GsonHelper.getGsonLogger(); + nfsTO = new NfsTO("http://example.com", DataStoreRole.Primary); + } + + @Test + public void testGsonSerialization() { + String json = gson.toJson(nfsTO); + assertNotNull(json); + assertTrue(json.contains("\"_url\":\"http://example.com\"")); + assertTrue(json.contains("\"_role\":\"Primary\"")); + } + + @Test + public void testGsonDeserialization() { + String json = "{\"_url\":\"http://example.com\",\"_role\":\"Primary\"}"; + NfsTO deserializedNfsTO = gson.fromJson(json, NfsTO.class); + assertNotNull(deserializedNfsTO); + assertEquals("http://example.com", deserializedNfsTO.getUrl()); + assertEquals(DataStoreRole.Primary, deserializedNfsTO.getRole()); + } + + @Test + public void testGsonLoggerSerialization() { + String json = gsonLogger.toJson(nfsTO); + assertNotNull(json); + assertTrue(json.contains("\"_url\":\"http://example.com\"")); + assertTrue(json.contains("\"_role\":\"Primary\"")); + } + + @Test + public void testGsonLoggerDeserialization() { + String json ="{\"_url\":\"http://example.com\",\"_role\":\"Primary\"}"; + NfsTO deserializedNfsTO = gsonLogger.fromJson(json, NfsTO.class); + assertNotNull(deserializedNfsTO); + assertEquals("http://example.com", deserializedNfsTO.getUrl()); + assertEquals(DataStoreRole.Primary, deserializedNfsTO.getRole()); + } +} diff --git a/core/src/test/java/com/cloud/storage/template/OVAProcessorTest.java b/core/src/test/java/com/cloud/storage/template/OVAProcessorTest.java index 8ab546447182..8674a8df2861 100644 --- a/core/src/test/java/com/cloud/storage/template/OVAProcessorTest.java +++ b/core/src/test/java/com/cloud/storage/template/OVAProcessorTest.java @@ -131,5 +131,25 @@ public void testGetVirtualSize() throws Exception { Assert.assertEquals(virtualSize, processor.getVirtualSize(mockFile)); Mockito.verify(mockFile, Mockito.times(0)).length(); } + @Test + public void testProcessWithLargeFileSize() throws Exception { + String templatePath = "/tmp"; + String templateName = "large_template"; + long virtualSize = 10_000_000_000L; + long actualSize = 5_000_000_000L; + + Mockito.when(mockStorageLayer.exists(Mockito.anyString())).thenReturn(true); + Mockito.when(mockStorageLayer.getSize(Mockito.anyString())).thenReturn(actualSize); + Mockito.doReturn(virtualSize).when(processor).getTemplateVirtualSize(Mockito.anyString(), Mockito.anyString()); + try (MockedConstruction + @@ -87,25 +96,29 @@ execute - - def csVersion = pom.properties['cs.version'] - def patch = pom.properties['patch.version'] - def templateList = [] - templateList.add("systemvmtemplate-${csVersion}.${patch}-kvm") - templateList.add("systemvmtemplate-${csVersion}.${patch}-vmware") - templateList.add("systemvmtemplate-${csVersion}.${patch}-xen") - templateList.add("systemvmtemplate-${csVersion}.${patch}-ovm") - templateList.add("systemvmtemplate-${csVersion}.${patch}-hyperv") - File file = new File("./engine/schema/dist/systemvm-templates/md5sum.txt") - def lines = file.readLines() - for (template in templateList) { - def data = lines.findAll { it.contains(template) } - if (data != null) { - def hypervisor = template.tokenize('-')[-1] - pom.properties["$hypervisor" + ".checksum"] = data[0].tokenize(' ')[0] + + + @@ -133,7 +146,7 @@ org.codehaus.mojo exec-maven-plugin - 1.2.1 + ${cs.exec-maven-plugin.version} systemvm-template-metadata @@ -181,7 +194,7 @@ true - ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-kvm.qcow2.bz2 + ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-x86_64-kvm.qcow2.bz2 ${basedir}/dist/systemvm-templates/ ${kvm.checksum} @@ -217,7 +230,7 @@ true - ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-vmware.ova + ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-x86_64-vmware.ova ${basedir}/dist/systemvm-templates/ ${vmware.checksum} @@ -253,7 +266,7 @@ true - ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-xen.vhd.bz2 + ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-x86_64-xen.vhd.bz2 ${basedir}/dist/systemvm-templates/ ${xen.checksum} @@ -289,7 +302,7 @@ true - ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-ovm.raw.bz2 + ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-x86_64-ovm.raw.bz2 ${basedir}/dist/systemvm-templates/ ${ovm.checksum} @@ -325,7 +338,7 @@ true - ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-hyperv.vhd.zip + ${project.systemvm.template.location}/${cs.version}/systemvmtemplate-${cs.version}.${patch.version}-x86_64-hyperv.vhd.zip ${basedir}/dist/systemvm-templates/ ${hyperv.checksum} diff --git a/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java b/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java index 29b58ddccd4d..cd62935f17ee 100644 --- a/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java +++ b/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java @@ -80,6 +80,9 @@ public class CapacityVO implements Capacity { @Transient private Long allocatedCapacity; + @Transient + private String tag; + public CapacityVO() { } @@ -221,6 +224,15 @@ public void setAllocatedCapacity(Long allocatedCapacity) { this.allocatedCapacity = allocatedCapacity; } + @Override + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + @Override public String getUuid() { return null; //To change body of implemented methods use File | Settings | File Templates. diff --git a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java index 459a63a7ba13..9616f31d0c5c 100644 --- a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java +++ b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java @@ -44,6 +44,8 @@ public interface CapacityDao extends GenericDao { List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId); + List findFilteredCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, List hostIds, List poolIds); + List listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType); Pair, Map> orderPodsByAggregateCapacity(long zoneId, short capacityType); @@ -51,7 +53,8 @@ public interface CapacityDao extends GenericDao { List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, String resourceState); - List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit); + List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, + Long clusterId, int level, List hostIds, List poolIds, Long limit); void updateCapacityState(Long dcId, Long podId, Long clusterId, Long hostId, String capacityState, short[] capacityType); diff --git a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java index 302ffd8e760a..3acae985af4b 100644 --- a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java @@ -26,12 +26,11 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Component; - import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; import com.cloud.capacity.Capacity; import com.cloud.capacity.CapacityVO; @@ -51,7 +50,6 @@ @Component public class CapacityDaoImpl extends GenericDaoBase implements CapacityDao { - private static final Logger s_logger = Logger.getLogger(CapacityDaoImpl.class); private static final String ADD_ALLOCATED_SQL = "UPDATE `cloud`.`op_host_capacity` SET used_capacity = used_capacity + ? WHERE host_id = ? AND capacity_type = ?"; private static final String SUBTRACT_ALLOCATED_SQL = @@ -341,7 +339,8 @@ public List findCapacityBy(Integer capacityType, Long zoneId, Lo } @Override - public List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit) { + public List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, + Long clusterId, int level, List hostIds, List poolIds, Long limit) { StringBuilder finalQuery = new StringBuilder(); TransactionLegacy txn = TransactionLegacy.currentTxn(); @@ -380,6 +379,18 @@ public List listCapacitiesGroupedByLevelAndType(Integer capacity finalQuery.append(" AND capacity_type = ?"); resourceIdList.add(capacityType.longValue()); } + if (CollectionUtils.isNotEmpty(hostIds)) { + finalQuery.append(String.format(" AND capacity.host_id IN (%s)", StringUtils.join(hostIds, ","))); + if (capacityType == null) { + finalQuery.append(String.format(" AND capacity_type NOT IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ","))); + } + } + if (CollectionUtils.isNotEmpty(poolIds)) { + finalQuery.append(String.format(" AND capacity.host_id IN (%s)", StringUtils.join(poolIds, ","))); + if (capacityType == null) { + finalQuery.append(String.format(" AND capacity_type IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ","))); + } + } switch (level) { case 1: // List all the capacities grouped by zone, capacity Type @@ -463,8 +474,37 @@ public Ternary findCapacityByZoneAndHostTag(Long zoneId, Strin } } + protected String getHostAndPoolConditionForFilteredCapacity(Integer capacityType, List hostIds, List poolIds) { + StringBuilder sql = new StringBuilder(); + if (CollectionUtils.isEmpty(hostIds) && CollectionUtils.isEmpty(poolIds)) { + return ""; + } + sql.append(" AND ("); + boolean hostConditionAdded = false; + if (CollectionUtils.isNotEmpty(hostIds) && (capacityType == null || !Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue()))) { + sql.append(String.format("(capacity.host_id IN (%s)", StringUtils.join(hostIds, ","))); + if (capacityType == null) { + sql.append(String.format(" AND capacity_type NOT IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ","))); + } + sql.append(")"); + hostConditionAdded = true; + } + if (CollectionUtils.isNotEmpty(poolIds) && (capacityType == null || Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue()))) { + if (hostConditionAdded) { + sql.append(" OR "); + } + sql.append(String.format("(capacity.host_id IN (%s)", StringUtils.join(poolIds, ","))); + if (capacityType == null || Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue())) { + sql.append(String.format(" AND capacity_type IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ","))); + } + sql.append(")"); + } + sql.append(")"); + return sql.toString(); + } + @Override - public List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId) { + public List findFilteredCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, List hostIds, List poolIds) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; @@ -518,6 +558,8 @@ public List findCapacityBy(Integer capacityType, Long zoneId, Lo resourceIdList.add(capacityType.longValue()); } + sql.append(getHostAndPoolConditionForFilteredCapacity(capacityType, hostIds, poolIds)); + if (podId == null && clusterId == null) { sql.append(" GROUP BY capacity_type, data_center_id"); } else { @@ -593,6 +635,11 @@ public List findCapacityBy(Integer capacityType, Long zoneId, Lo } } + @Override + public List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId) { + return findFilteredCapacityBy(capacityType, zoneId, podId, clusterId, null, null); + } + public void updateAllocated(Long hostId, long allocatedAmount, short capacityType, boolean add) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; @@ -612,7 +659,7 @@ public void updateAllocated(Long hostId, long allocatedAmount, short capacityTyp txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Exception updating capacity for host: " + hostId, e); + logger.warn("Exception updating capacity for host: " + hostId, e); } } @@ -704,6 +751,7 @@ public static class SummedCapacity { public Long clusterId; public Long podId; public Long dcId; + public String tag; public SummedCapacity() { } @@ -792,6 +840,14 @@ public Long getAllocatedCapacity() { public void setAllocatedCapacity(Long sumAllocated) { this.sumAllocated = sumAllocated; } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } } @Override @@ -1126,7 +1182,7 @@ public void updateCapacityState(Long dcId, Long podId, Long clusterId, Long host pstmt.executeUpdate(); } catch (Exception e) { - s_logger.warn("Error updating CapacityVO", e); + logger.warn("Error updating CapacityVO", e); } } @@ -1146,7 +1202,7 @@ public float findClusterConsumption(Long clusterId, short capacityType, long com return rs.getFloat(1); } } catch (Exception e) { - s_logger.warn("Error checking cluster threshold", e); + logger.warn("Error checking cluster threshold", e); } return 0; } diff --git a/engine/schema/src/main/java/com/cloud/certificate/dao/CertificateDaoImpl.java b/engine/schema/src/main/java/com/cloud/certificate/dao/CertificateDaoImpl.java index 9544804284e9..99ba36f22b91 100644 --- a/engine/schema/src/main/java/com/cloud/certificate/dao/CertificateDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/certificate/dao/CertificateDaoImpl.java @@ -17,7 +17,6 @@ package com.cloud.certificate.dao; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.certificate.CertificateVO; @@ -28,7 +27,6 @@ @DB public class CertificateDaoImpl extends GenericDaoBase implements CertificateDao { - private static final Logger s_logger = Logger.getLogger(CertificateDaoImpl.class); public CertificateDaoImpl() { @@ -42,7 +40,7 @@ public Long persistCustomCertToDb(String certStr, CertificateVO cert, Long manag update(cert.getId(), cert); return cert.getId(); } catch (Exception e) { - s_logger.warn("Unable to read the certificate: " + e); + logger.warn("Unable to read the certificate: " + e); return new Long(0); } } diff --git a/engine/schema/src/main/java/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java b/engine/schema/src/main/java/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java index e1c0dbd9e472..861dbeb1df4a 100644 --- a/engine/schema/src/main/java/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java @@ -21,7 +21,6 @@ import javax.annotation.PostConstruct; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.cluster.agentlb.HostTransferMapVO; @@ -34,7 +33,6 @@ @Component @DB public class HostTransferMapDaoImpl extends GenericDaoBase implements HostTransferMapDao { - private static final Logger s_logger = Logger.getLogger(HostTransferMapDaoImpl.class); protected SearchBuilder AllFieldsSearch; protected SearchBuilder IntermediateStateSearch; diff --git a/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java b/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java index ae8f3822704c..9e39a608f9ec 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java +++ b/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java @@ -47,10 +47,13 @@ public class ResourceCountVO implements ResourceCount { @Column(name = "count") private long count; + @Column(name = "tag") + private String tag; + public ResourceCountVO() { } - public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType) { + public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType, String tag) { this.type = type; this.count = count; @@ -59,6 +62,11 @@ public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwne } else if (ownerType == ResourceOwnerType.Domain) { this.domainId = ownerId; } + this.tag = tag; + } + + public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType) { + this(type, count, ownerId, ownerType, null); } @Override @@ -99,7 +107,7 @@ public Long getAccountId() { @Override public String toString() { - return new StringBuilder("REsourceCount[").append("-") + return new StringBuilder("ResourceCount[").append("-") .append(id) .append("-") .append(type) @@ -107,6 +115,8 @@ public String toString() { .append(accountId) .append("-") .append(domainId) + .append("-") + .append(tag) .append("]") .toString(); } @@ -136,4 +146,13 @@ public void setDomainId(Long domainId) { public void setAccountId(Long accountId) { this.accountId = accountId; } + + @Override + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java b/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java index 392170919757..1619537ae744 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java +++ b/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java @@ -47,10 +47,13 @@ public class ResourceLimitVO implements ResourceLimit { @Column(name = "max") private Long max; + @Column(name = "tag") + private String tag; + public ResourceLimitVO() { } - public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType) { + public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType, String tag) { this.type = type; this.max = max; @@ -59,6 +62,11 @@ public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, } else if (ownerType == ResourceOwnerType.Domain) { this.domainId = ownerId; } + this.tag = tag; + } + + public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType) { + this(type, max, ownerId, ownerType, null); } @Override @@ -123,4 +131,12 @@ public void setAccountId(Long accountId) { this.accountId = accountId; } + @Override + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java index 28f2a5360716..b978cc04bfa7 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java +++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java @@ -26,18 +26,20 @@ public interface ResourceCountDao extends GenericDao { /** - * @param domainId the id of the domain to get the resource count + * @param ownerId the id of the owner to get the resource count * @param type the type of resource (e.g. user_vm, public_ip, volume) + * @param tag for the type of resource * @return the count of resources in use for the given type and domain */ - long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type); + long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag); /** - * @param domainId the id of the domain to set the resource count + * @param ownerId the id of the owner to set the resource count * @param type the type of resource (e.g. user_vm, public_ip, volume) - * @param the count of resources in use for the given type and domain + * @param tag the tag for the type of resource + * @param count the count of resources in use for the given type and domain */ - void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, long count); + void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag, long count); boolean updateById(long id, boolean increment, long delta); @@ -45,13 +47,18 @@ public interface ResourceCountDao extends GenericDao { List listByOwnerId(long ownerId, ResourceOwnerType ownerType); - ResourceCountVO findByOwnerAndType(long ownerId, ResourceOwnerType ownerType, ResourceType type); + ResourceCountVO findByOwnerAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag); + + List findByOwnersAndTypeAndTag(List ownerIdList, ResourceOwnerType ownerType, + ResourceType type, String tag); List listResourceCountByOwnerType(ResourceOwnerType ownerType); - Set listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type); + Set listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag); + + boolean updateCountByDeltaForIds(List ids, boolean increment, long delta); - Set listRowsToUpdateForDomain(long domainId, ResourceType type); + Set listRowsToUpdateForDomain(long domainId, ResourceType type, String tag); long removeEntriesByOwner(long ownerId, ResourceOwnerType ownerType); @@ -68,4 +75,8 @@ public interface ResourceCountDao extends GenericDao { * Side note: This method is not using the "resource_count" table. It is executing the actual count instead. */ long countMemoryAllocatedToAccount(long accountId); + + void removeResourceCountsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List types, List tags); + + List lockRows(Set ids); } diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java index ca6f13d2d645..65d7fed2d1a1 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java @@ -20,13 +20,18 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.inject.Inject; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import com.cloud.configuration.Resource; @@ -37,6 +42,7 @@ import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.user.AccountVO; +import com.cloud.user.ResourceLimitService; import com.cloud.user.dao.AccountDao; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; @@ -49,24 +55,49 @@ @Component public class ResourceCountDaoImpl extends GenericDaoBase implements ResourceCountDao { private final SearchBuilder TypeSearch; - + private final SearchBuilder TypeNullTagSearch; + private final SearchBuilder NonMatchingTagsSearch; private final SearchBuilder AccountSearch; private final SearchBuilder DomainSearch; + private final SearchBuilder IdsSearch; @Inject private DomainDao _domainDao; @Inject private AccountDao _accountDao; + protected static final String INCREMENT_COUNT_BY_IDS_SQL = "UPDATE `cloud`.`resource_count` SET `count` = `count` + ? WHERE `id` IN (?)"; + protected static final String DECREMENT_COUNT_BY_IDS_SQL = "UPDATE `cloud`.`resource_count` SET `count` = `count` - ? WHERE `id` IN (?)"; + public ResourceCountDaoImpl() { TypeSearch = createSearchBuilder(); TypeSearch.and("type", TypeSearch.entity().getType(), SearchCriteria.Op.EQ); - TypeSearch.and("accountId", TypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - TypeSearch.and("domainId", TypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + TypeSearch.and("accountId", TypeSearch.entity().getAccountId(), SearchCriteria.Op.IN); + TypeSearch.and("domainId", TypeSearch.entity().getDomainId(), SearchCriteria.Op.IN); + TypeSearch.and("tag", TypeSearch.entity().getTag(), SearchCriteria.Op.EQ); TypeSearch.done(); + TypeNullTagSearch = createSearchBuilder(); + TypeNullTagSearch.and("type", TypeNullTagSearch.entity().getType(), SearchCriteria.Op.EQ); + TypeNullTagSearch.and("accountId", TypeNullTagSearch.entity().getAccountId(), SearchCriteria.Op.IN); + TypeNullTagSearch.and("domainId", TypeNullTagSearch.entity().getDomainId(), SearchCriteria.Op.IN); + TypeNullTagSearch.and("tag", TypeNullTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + TypeNullTagSearch.done(); + + NonMatchingTagsSearch = createSearchBuilder(); + NonMatchingTagsSearch.and("accountId", NonMatchingTagsSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + NonMatchingTagsSearch.and("domainId", NonMatchingTagsSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + NonMatchingTagsSearch.and("types", NonMatchingTagsSearch.entity().getType(), SearchCriteria.Op.IN); + NonMatchingTagsSearch.and("tagNotNull", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NNULL); + NonMatchingTagsSearch.and("tags", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NIN); + NonMatchingTagsSearch.done(); + AccountSearch = createSearchBuilder(); DomainSearch = createSearchBuilder(); + + IdsSearch = createSearchBuilder(); + IdsSearch.and("id", IdsSearch.entity().getId(), SearchCriteria.Op.IN); + IdsSearch.done(); } @PostConstruct @@ -85,24 +116,40 @@ protected void configure() { } @Override - public ResourceCountVO findByOwnerAndType(long ownerId, ResourceOwnerType ownerType, ResourceType type) { - SearchCriteria sc = TypeSearch.create(); + public ResourceCountVO findByOwnerAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) { + List resourceCounts = findByOwnersAndTypeAndTag(List.of(ownerId), ownerType, type, tag); + if (CollectionUtils.isNotEmpty(resourceCounts)) { + return resourceCounts.get(0); + } else { + return null; + } + } + + @Override + public List findByOwnersAndTypeAndTag(List ownerIdList, ResourceOwnerType ownerType, ResourceType type, String tag) { + if (CollectionUtils.isEmpty(ownerIdList)) { + return new ArrayList<>(); + } + SearchCriteria sc = tag != null ? TypeSearch.create() : TypeNullTagSearch.create(); sc.setParameters("type", type); + if (tag != null) { + sc.setParameters("tag", tag); + } if (ownerType == ResourceOwnerType.Account) { - sc.setParameters("accountId", ownerId); - return findOneIncludingRemovedBy(sc); + sc.setParameters("accountId", ownerIdList.toArray()); + return listIncludingRemovedBy(sc); } else if (ownerType == ResourceOwnerType.Domain) { - sc.setParameters("domainId", ownerId); - return findOneIncludingRemovedBy(sc); + sc.setParameters("domainId", ownerIdList.toArray()); + return listIncludingRemovedBy(sc); } else { - return null; + return new ArrayList<>(); } } @Override - public long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type) { - ResourceCountVO vo = findByOwnerAndType(ownerId, ownerType, type); + public long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) { + ResourceCountVO vo = findByOwnerAndTypeAndTag(ownerId, ownerType, type, tag); if (vo != null) { return vo.getCount(); } else { @@ -111,8 +158,8 @@ public long getResourceCount(long ownerId, ResourceOwnerType ownerType, Resource } @Override - public void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, long count) { - ResourceCountVO resourceCountVO = findByOwnerAndType(ownerId, ownerType, type); + public void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag, long count) { + ResourceCountVO resourceCountVO = findByOwnerAndTypeAndTag(ownerId, ownerType, type, tag); if (resourceCountVO != null && count != resourceCountVO.getCount()) { resourceCountVO.setCount(count); update(resourceCountVO.getId(), resourceCountVO); @@ -129,38 +176,79 @@ public boolean updateById(long id, boolean increment, long delta) { } @Override - public Set listRowsToUpdateForDomain(long domainId, ResourceType type) { + public boolean updateCountByDeltaForIds(List ids, boolean increment, long delta) { + if (CollectionUtils.isEmpty(ids)) { + return false; + } + String updateSql = increment ? INCREMENT_COUNT_BY_IDS_SQL : DECREMENT_COUNT_BY_IDS_SQL; + + String poolIdsInStr = ids.stream().map(String::valueOf).collect(Collectors.joining(",", "(", ")")); + String sql = updateSql.replace("(?)", poolIdsInStr); + + final TransactionLegacy txn = TransactionLegacy.currentTxn(); + try(PreparedStatement pstmt = txn.prepareStatement(sql);) { + pstmt.setLong(1, delta); + pstmt.executeUpdate(); + return true; + } catch (SQLException e) { + throw new CloudRuntimeException(e); + } + } + + @Override + public Set listRowsToUpdateForDomain(long domainId, ResourceType type, String tag) { Set rowIds = new HashSet(); Set domainIdsToUpdate = _domainDao.getDomainParentIds(domainId); for (Long domainIdToUpdate : domainIdsToUpdate) { - ResourceCountVO domainCountRecord = findByOwnerAndType(domainIdToUpdate, ResourceOwnerType.Domain, type); + ResourceCountVO domainCountRecord = findByOwnerAndTypeAndTag(domainIdToUpdate, ResourceOwnerType.Domain, type, tag); if (domainCountRecord != null) { rowIds.add(domainCountRecord.getId()); + } else { + if (StringUtils.isNotEmpty(tag)) { + ResourceCountVO resourceCountVO = createTaggedResourceCount(domainIdToUpdate, ResourceOwnerType.Domain, type, tag); + rowIds.add(resourceCountVO.getId()); + } } } return rowIds; } @Override - public Set listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type) { + public Set listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) { Set rowIds = new HashSet(); if (ownerType == ResourceOwnerType.Account) { //get records for account - ResourceCountVO accountCountRecord = findByOwnerAndType(ownerId, ResourceOwnerType.Account, type); + ResourceCountVO accountCountRecord = findByOwnerAndTypeAndTag(ownerId, ResourceOwnerType.Account, type, tag); if (accountCountRecord != null) { rowIds.add(accountCountRecord.getId()); + } else { + if (StringUtils.isNotEmpty(tag)) { + ResourceCountVO resourceCountVO = createTaggedResourceCount(ownerId, ownerType, type, tag); + rowIds.add(resourceCountVO.getId()); + } } //get records for account's domain and all its parent domains - rowIds.addAll(listRowsToUpdateForDomain(_accountDao.findByIdIncludingRemoved(ownerId).getDomainId(), type)); + rowIds.addAll(listRowsToUpdateForDomain(_accountDao.findByIdIncludingRemoved(ownerId).getDomainId(), type, tag)); } else if (ownerType == ResourceOwnerType.Domain) { - return listRowsToUpdateForDomain(ownerId, type); + rowIds = listRowsToUpdateForDomain(ownerId, type, tag); } return rowIds; } + protected ResourceCountVO createTaggedResourceCount(long ownerId, ResourceLimit.ResourceOwnerType ownerType, ResourceType resourceType, String tag) { + ResourceCountVO taggedResourceCountVO = new ResourceCountVO(resourceType, 0, ownerId, ownerType, tag); + return persist(taggedResourceCountVO); + } + + protected void createTaggedResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType ownerType, ResourceType resourceType, List tags) { + for (String tag : tags) { + createTaggedResourceCount(ownerId, ownerType, resourceType, tag); + } + } + @Override @DB public void createResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType ownerType) { @@ -169,9 +257,23 @@ public void createResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType o txn.start(); ResourceType[] resourceTypes = Resource.ResourceType.values(); + List hostTags = new ArrayList<>(); + if (StringUtils.isNotEmpty(ResourceLimitService.ResourceLimitHostTags.value())) { + hostTags = Arrays.asList(ResourceLimitService.ResourceLimitHostTags.value().split(",")); + } + List storageTags = new ArrayList<>(); + if (StringUtils.isNotEmpty(ResourceLimitService.ResourceLimitStorageTags.value())) { + storageTags = Arrays.asList(ResourceLimitService.ResourceLimitStorageTags.value().split(",")); + } for (ResourceType resourceType : resourceTypes) { ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, ownerId, ownerType); persist(resourceCountVO); + if (ResourceLimitService.HostTagsSupportingTypes.contains(resourceType)) { + createTaggedResourceCounts(ownerId, ownerType, resourceType, hostTags); + } + if (ResourceLimitService.StorageTagsSupportingTypes.contains(resourceType)) { + createTaggedResourceCounts(ownerId, ownerType, resourceType, storageTags); + } } txn.commit(); @@ -266,4 +368,32 @@ private long executeSqlCountComputingResourcesForAccount(long accountId, String } } + @Override + public void removeResourceCountsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List types, List tags) { + SearchCriteria sc = NonMatchingTagsSearch.create(); + if (ObjectUtils.allNotNull(ownerId, ownerType)) { + if (ResourceOwnerType.Account.equals(ownerType)) { + sc.setParameters("accountId", ownerId); + } else { + sc.setParameters("domainId", ownerId); + } + } + if (CollectionUtils.isNotEmpty(types)) { + sc.setParameters("types", types.stream().map(ResourceType::getName).toArray()); + } + if (CollectionUtils.isNotEmpty(tags)) { + sc.setParameters("tags", tags.toArray()); + } + remove(sc); + } + + @Override + public List lockRows(Set ids) { + if (CollectionUtils.isEmpty(ids)) { + return new ArrayList<>(); + } + SearchCriteria sc = IdsSearch.create(); + sc.setParameters("id", ids.toArray()); + return lockRows(sc, null, true); + } } diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java index e47b38340c2b..7cdc2aacc3ba 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java +++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java @@ -18,6 +18,7 @@ import java.util.List; +import com.cloud.configuration.Resource; import com.cloud.configuration.Resource.ResourceOwnerType; import com.cloud.configuration.ResourceCount; import com.cloud.configuration.ResourceLimitVO; @@ -31,7 +32,8 @@ public interface ResourceLimitDao extends GenericDao { ResourceCount.ResourceType getLimitType(String type); - ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type); + ResourceLimitVO findByOwnerIdAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type, String tag); long removeEntriesByOwner(Long ownerId, ResourceOwnerType ownerType); + void removeResourceLimitsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List types, List tags); } diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java index 03c2d2a46247..96523ba9bea3 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java @@ -20,6 +20,8 @@ import java.util.List; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Component; import com.cloud.configuration.Resource; @@ -33,19 +35,36 @@ @Component public class ResourceLimitDaoImpl extends GenericDaoBase implements ResourceLimitDao { - private SearchBuilder IdTypeSearch; + private SearchBuilder IdTypeTagSearch; + private SearchBuilder IdTypeNullTagSearch; + private SearchBuilder NonMatchingTagsSearch; public ResourceLimitDaoImpl() { - IdTypeSearch = createSearchBuilder(); - IdTypeSearch.and("type", IdTypeSearch.entity().getType(), SearchCriteria.Op.EQ); - IdTypeSearch.and("domainId", IdTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ); - IdTypeSearch.and("accountId", IdTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - IdTypeSearch.done(); + IdTypeTagSearch = createSearchBuilder(); + IdTypeTagSearch.and("type", IdTypeTagSearch.entity().getType(), SearchCriteria.Op.EQ); + IdTypeTagSearch.and("domainId", IdTypeTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + IdTypeTagSearch.and("accountId", IdTypeTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + IdTypeTagSearch.and("tag", IdTypeTagSearch.entity().getTag(), SearchCriteria.Op.EQ); + + IdTypeNullTagSearch = createSearchBuilder(); + IdTypeNullTagSearch.and("type", IdTypeNullTagSearch.entity().getType(), SearchCriteria.Op.EQ); + IdTypeNullTagSearch.and("domainId", IdTypeNullTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + IdTypeNullTagSearch.and("accountId", IdTypeNullTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + IdTypeNullTagSearch.and("tag", IdTypeNullTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + IdTypeNullTagSearch.done(); + + NonMatchingTagsSearch = createSearchBuilder(); + NonMatchingTagsSearch.and("accountId", NonMatchingTagsSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + NonMatchingTagsSearch.and("domainId", NonMatchingTagsSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + NonMatchingTagsSearch.and("types", NonMatchingTagsSearch.entity().getType(), SearchCriteria.Op.IN); + NonMatchingTagsSearch.and("tagNotNull", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NNULL); + NonMatchingTagsSearch.and("tags", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NIN); + NonMatchingTagsSearch.done(); } @Override public List listByOwner(Long ownerId, ResourceOwnerType ownerType) { - SearchCriteria sc = IdTypeSearch.create(); + SearchCriteria sc = IdTypeTagSearch.create(); if (ownerType == ResourceOwnerType.Account) { sc.setParameters("accountId", ownerId); @@ -81,9 +100,12 @@ public ResourceCount.ResourceType getLimitType(String type) { } @Override - public ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type) { - SearchCriteria sc = IdTypeSearch.create(); + public ResourceLimitVO findByOwnerIdAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type, String tag) { + SearchCriteria sc = tag != null ? IdTypeTagSearch.create() : IdTypeNullTagSearch.create(); sc.setParameters("type", type); + if (tag != null) { + sc.setParameters("tag", tag); + } if (ownerType == ResourceOwnerType.Account) { sc.setParameters("accountId", ownerId); @@ -98,7 +120,7 @@ public ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType owne @Override public long removeEntriesByOwner(Long ownerId, ResourceOwnerType ownerType) { - SearchCriteria sc = IdTypeSearch.create(); + SearchCriteria sc = IdTypeTagSearch.create(); if (ownerType == ResourceOwnerType.Account) { sc.setParameters("accountId", ownerId); @@ -109,4 +131,23 @@ public long removeEntriesByOwner(Long ownerId, ResourceOwnerType ownerType) { } return 0; } + + @Override + public void removeResourceLimitsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List types, List tags) { + SearchCriteria sc = NonMatchingTagsSearch.create(); + if (ObjectUtils.allNotNull(ownerId, ownerType)) { + if (ResourceOwnerType.Account.equals(ownerType)) { + sc.setParameters("accountId", ownerId); + } else { + sc.setParameters("domainId", ownerId); + } + } + if (CollectionUtils.isNotEmpty(types)) { + sc.setParameters("types", types.stream().map(ResourceType::getName).toArray()); + } + if (CollectionUtils.isNotEmpty(tags)) { + sc.setParameters("tags", tags.toArray()); + } + remove(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/dc/ASNumberRangeVO.java b/engine/schema/src/main/java/com/cloud/dc/ASNumberRangeVO.java new file mode 100644 index 000000000000..3790213b3ade --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/dc/ASNumberRangeVO.java @@ -0,0 +1,104 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc; + +import com.cloud.bgp.ASNumberRange; +import com.cloud.utils.db.GenericDao; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.UUID; + +@Entity +@Table(name = "as_number_range") +public class ASNumberRangeVO implements ASNumberRange { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "data_center_id") + private long dataCenterId; + + @Column(name = "start_as_number") + private long startASNumber; + + @Column(name = "end_as_number") + private long endASNumber; + + @Column(name = GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + public ASNumberRangeVO() { + this.uuid = UUID.randomUUID().toString(); + this.created = GregorianCalendar.getInstance().getTime(); + } + + public ASNumberRangeVO(long dataCenterId, long startASNumber, long endASNumber) { + this(); + this.dataCenterId = dataCenterId; + this.startASNumber = startASNumber; + this.endASNumber = endASNumber; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public long getDataCenterId() { + return dataCenterId; + } + + @Override + public long getStartASNumber() { + return startASNumber; + } + + @Override + public long getEndASNumber() { + return endASNumber; + } + + public Date getRemoved() { + return removed; + } + + @Override + public Date getCreated() { + return created; + } +} diff --git a/engine/schema/src/main/java/com/cloud/dc/ASNumberVO.java b/engine/schema/src/main/java/com/cloud/dc/ASNumberVO.java new file mode 100644 index 000000000000..529d1cfb5fe8 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/dc/ASNumberVO.java @@ -0,0 +1,178 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc; + +import com.cloud.bgp.ASNumber; +import com.cloud.utils.db.GenericDao; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; +import java.util.UUID; + +@Entity +@Table(name = "as_number") +public class ASNumberVO implements ASNumber { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "account_id") + private Long accountId; + + @Column(name = "domain_id") + private Long domainId; + + @Column(name = "as_number") + private long asNumber; + + @Column(name = "as_number_range_id") + private long asNumberRangeId; + + @Column(name = "data_center_id") + private long dataCenterId; + + @Column(name = "allocated") + @Temporal(value = TemporalType.TIMESTAMP) + private Date allocatedTime; + + @Column(name = "is_allocated") + private boolean allocated; + + @Column(name = "network_id") + private Long networkId; + + @Column(name = "vpc_id") + private Long vpcId; + + @Column(name = GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + public ASNumberVO() { + this.uuid = UUID.randomUUID().toString(); + this.created = new Date(); + } + + public ASNumberVO(long asNumber, long asNumberRangeId, long dataCenterId) { + this(); + this.asNumber = asNumber; + this.asNumberRangeId = asNumberRangeId; + this.dataCenterId = dataCenterId; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setAccountId(Long accountId) { + this.accountId = accountId; + } + + @Override + public Long getAccountId() { + return accountId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + + @Override + public Long getDomainId() { + return domainId; + } + + @Override + public long getAsNumber() { + return asNumber; + } + + @Override + public long getAsNumberRangeId() { + return asNumberRangeId; + } + + @Override + public long getDataCenterId() { + return dataCenterId; + } + + public void setAllocatedTime(Date date) { + this.allocatedTime = date; + } + + @Override + public Date getAllocatedTime() { + return allocatedTime; + } + + public void setAllocated(boolean allocated) { + this.allocated = allocated; + } + + @Override + public boolean isAllocated() { + return allocated; + } + + public void setNetworkId(Long networkId) { + this.networkId = networkId; + } + + @Override + public Long getNetworkId() { + return networkId; + } + + @Override + public Date getRemoved() { + return removed; + } + + @Override + public Date getCreated() { + return created; + } + + public Long getVpcId() { + return vpcId; + } + + public void setVpcId(Long vpcId) { + this.vpcId = vpcId; + } +} diff --git a/engine/schema/src/main/java/com/cloud/dc/ClusterDetailsDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/ClusterDetailsDaoImpl.java index c2058ad5644b..0e40f8475c16 100644 --- a/engine/schema/src/main/java/com/cloud/dc/ClusterDetailsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/ClusterDetailsDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; - import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey.Scope; import org.apache.cloudstack.framework.config.ScopedConfigStorage; @@ -136,8 +135,8 @@ public Scope getScope() { } @Override - public String getConfigValue(long id, ConfigKey key) { - ClusterDetailsVO vo = findDetail(id, key.key()); + public String getConfigValue(long id, String key) { + ClusterDetailsVO vo = findDetail(id, key); return vo == null ? null : vo.getValue(); } diff --git a/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java b/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java index f60765e28566..434901ef5b3b 100644 --- a/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java +++ b/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java @@ -16,14 +16,18 @@ // under the License. package com.cloud.dc; +import com.cloud.cpu.CPU; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.org.Cluster; import com.cloud.org.Grouping; import com.cloud.org.Managed.ManagedState; import com.cloud.utils.NumbersUtil; import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.util.CPUArchConverter; +import org.apache.cloudstack.util.HypervisorTypeConverter; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -56,6 +60,7 @@ public class ClusterVO implements Cluster { long podId; @Column(name = "hypervisor_type") + @Convert(converter = HypervisorTypeConverter.class) String hypervisorType; @Column(name = "cluster_type") @@ -66,6 +71,10 @@ public class ClusterVO implements Cluster { @Enumerated(value = EnumType.STRING) AllocationState allocationState; + @Column(name = "arch") + @Convert(converter = CPUArchConverter.class) + private String arch; + @Column(name = "managed_state") @Enumerated(value = EnumType.STRING) ManagedState managedState; @@ -197,6 +206,15 @@ public PartitionType partitionType() { return PartitionType.Cluster; } + @Override + public CPU.CPUArch getArch() { + return CPU.CPUArch.fromType(arch); + } + + public void setArch(String arch) { + this.arch = arch; + } + @Override public String toString() { return String.format("Cluster {id: \"%s\", name: \"%s\", uuid: \"%s\"}", id, name, uuid); diff --git a/engine/schema/src/main/java/com/cloud/dc/DataCenterIpAddressVO.java b/engine/schema/src/main/java/com/cloud/dc/DataCenterIpAddressVO.java index 3d68cc3d9a86..874b05673eb1 100644 --- a/engine/schema/src/main/java/com/cloud/dc/DataCenterIpAddressVO.java +++ b/engine/schema/src/main/java/com/cloud/dc/DataCenterIpAddressVO.java @@ -55,7 +55,7 @@ public class DataCenterIpAddressVO implements InternalIdentity { String reservationId; @Column(name = "nic_id") - private Long instanceId; + private Long nicId; @Column(name = "mac_address") long macAddress; @@ -88,12 +88,12 @@ public long getId() { return id; } - public Long getInstanceId() { - return instanceId; + public Long getNicId() { + return nicId; } - public void setInstanceId(Long instanceId) { - this.instanceId = instanceId; + public void setNicId(Long nicId) { + this.nicId = nicId; } public long getPodId() { diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberDao.java b/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberDao.java new file mode 100644 index 000000000000..192f6bbaf315 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberDao.java @@ -0,0 +1,41 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc.dao; + +import com.cloud.dc.ASNumberVO; +import com.cloud.user.Account; +import com.cloud.utils.Pair; +import com.cloud.utils.db.GenericDao; + +import java.util.List; + +public interface ASNumberDao extends GenericDao { + + Pair, Integer> searchAndCountByZoneOrRangeOrAllocated(Long zoneId, Long asnRangeId, Integer asNumber, Long networkId, Long vpcId, + Boolean allocated, Long accountId, Long domainId, String keyword, Account caller, + Long startIndex, Long pageSizeVal); + ASNumberVO findByAsNumber(Long asNumber); + + ASNumberVO findOneByAllocationStateAndZone(long zoneId, boolean allocated); + + List listAllocatedByASRange(Long asRangeId); + + ASNumberVO findByZoneAndNetworkId(long zoneId, long networkId); + ASNumberVO findByZoneAndVpcId(long zoneId, long vpcId); + + int removeASRangeNumbers(long rangeId); +} diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberDaoImpl.java new file mode 100644 index 000000000000..1d2adf4d424d --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberDaoImpl.java @@ -0,0 +1,141 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc.dao; + +import com.cloud.dc.ASNumberVO; +import com.cloud.user.Account; +import com.cloud.utils.Pair; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +import java.util.Arrays; +import java.util.List; + +public class ASNumberDaoImpl extends GenericDaoBase implements ASNumberDao { + + private final SearchBuilder asNumberSearch; + + public ASNumberDaoImpl() { + asNumberSearch = createSearchBuilder(); + asNumberSearch.and("zoneId", asNumberSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + asNumberSearch.and("rangeId", asNumberSearch.entity().getAsNumberRangeId(), SearchCriteria.Op.EQ); + asNumberSearch.and("isAllocated", asNumberSearch.entity().isAllocated(), SearchCriteria.Op.EQ); + asNumberSearch.and("asNumber", asNumberSearch.entity().getAsNumber(), SearchCriteria.Op.EQ); + asNumberSearch.and("networkId", asNumberSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + asNumberSearch.and("vpcId", asNumberSearch.entity().getVpcId(), SearchCriteria.Op.EQ); + asNumberSearch.and("accountId", asNumberSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + asNumberSearch.and("domainId", asNumberSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + asNumberSearch.done(); + } + + @Override + public Pair, Integer> searchAndCountByZoneOrRangeOrAllocated(Long zoneId, Long asnRangeId, + Integer asNumber, Long networkId, Long vpcId, + Boolean allocated, + Long accountId, Long domainId, + String keyword, Account caller, + Long startIndex, Long pageSizeVal) { + SearchCriteria sc = asNumberSearch.create(); + if (zoneId != null) { + sc.setParameters("zoneId", zoneId); + } + if (asnRangeId != null) { + sc.setParameters("rangeId", asnRangeId); + } + if (networkId != null) { + sc.setParameters("networkId", networkId); + } + if (vpcId != null) { + sc.setParameters("vpcId", vpcId); + } + if (allocated != null) { + sc.setParameters("isAllocated", allocated); + } + if (asNumber != null) { + sc.setParameters("asNumber", asNumber); + } + if (accountId != null) { + sc.setParameters("accountId", accountId); + } + if (domainId != null) { + sc.setParameters("domainId", domainId); + } + if (keyword != null) { + sc.addAnd("asNumber", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + } + if (Arrays.asList(Account.Type.DOMAIN_ADMIN, Account.Type.RESOURCE_DOMAIN_ADMIN).contains(caller.getType())) { + SearchCriteria scc = asNumberSearch.create(); + scc.addOr("domainId", SearchCriteria.Op.NULL); + scc.addOr("domainId", SearchCriteria.Op.EQ, caller.getDomainId()); + sc.addAnd("domainId", SearchCriteria.Op.SC, scc); + } else if (Arrays.asList(Account.Type.NORMAL, Account.Type.PROJECT).contains(caller.getType())) { + SearchCriteria scc = asNumberSearch.create(); + scc.addOr("domainId", SearchCriteria.Op.NULL); + scc.addOr("accountId", SearchCriteria.Op.EQ, caller.getAccountId()); + sc.addAnd("domainId", SearchCriteria.Op.SC, scc); + } + Filter searchFilter = new Filter(ASNumberVO.class, "id", true, startIndex, pageSizeVal); + return searchAndCount(sc, searchFilter); + } + + @Override + public ASNumberVO findByAsNumber(Long asNumber) { + SearchCriteria sc = asNumberSearch.create(); + sc.setParameters("asNumber", asNumber); + return findOneBy(sc); + } + + @Override + public ASNumberVO findOneByAllocationStateAndZone(long zoneId, boolean allocated) { + SearchCriteria sc = asNumberSearch.create(); + sc.setParameters("zoneId", zoneId); + sc.setParameters("isAllocated", allocated); + return findOneBy(sc); + } + + @Override + public List listAllocatedByASRange(Long asRangeId) { + SearchCriteria sc = asNumberSearch.create(); + sc.setParameters("rangeId", asRangeId); + sc.setParameters("isAllocated", true); + return listBy(sc); + } + + public ASNumberVO findByZoneAndNetworkId(long zoneId, long networkId) { + SearchCriteria sc = asNumberSearch.create(); + sc.setParameters("zoneId", zoneId); + sc.setParameters("networkId", networkId); + return findOneBy(sc); + } + + @Override + public ASNumberVO findByZoneAndVpcId(long zoneId, long vpcId) { + SearchCriteria sc = asNumberSearch.create(); + sc.setParameters("zoneId", zoneId); + sc.setParameters("vpcId", vpcId); + return findOneBy(sc); + } + + @Override + public int removeASRangeNumbers(long rangeId) { + SearchCriteria sc = asNumberSearch.create(); + sc.setParameters("rangeId", rangeId); + return remove(sc); + } +} diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberRangeDao.java b/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberRangeDao.java new file mode 100644 index 000000000000..3309a6f5fe54 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberRangeDao.java @@ -0,0 +1,27 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc.dao; + +import com.cloud.dc.ASNumberRangeVO; +import com.cloud.utils.db.GenericDao; + +import java.util.List; + +public interface ASNumberRangeDao extends GenericDao { + + List listByZoneId(long zoneId); +} diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberRangeDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberRangeDaoImpl.java new file mode 100644 index 000000000000..4a4170685dc4 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/dc/dao/ASNumberRangeDaoImpl.java @@ -0,0 +1,42 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc.dao; + +import com.cloud.dc.ASNumberRangeVO; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +import java.util.List; + +public class ASNumberRangeDaoImpl extends GenericDaoBase implements ASNumberRangeDao { + + private final SearchBuilder searchBuilder; + + public ASNumberRangeDaoImpl() { + searchBuilder = createSearchBuilder(); + searchBuilder.and("zoneId", searchBuilder.entity().getDataCenterId(), SearchCriteria.Op.EQ); + searchBuilder.done(); + } + + @Override + public List listByZoneId(long zoneId) { + SearchCriteria sc = searchBuilder.create(); + sc.setParameters("zoneId", zoneId); + return listBy(sc); + } +} diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/ClusterDao.java b/engine/schema/src/main/java/com/cloud/dc/dao/ClusterDao.java index ab9c5cab8c4a..6ecfdaeb0584 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/ClusterDao.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/ClusterDao.java @@ -16,6 +16,7 @@ // under the License. package com.cloud.dc.dao; +import com.cloud.cpu.CPU; import com.cloud.dc.ClusterVO; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.db.GenericDao; @@ -50,4 +51,8 @@ public interface ClusterDao extends GenericDao { List listAllClusters(Long zoneId); boolean getSupportsResigning(long clusterId); + + List getClustersArchsByZone(long zoneId); + + List listClustersByArchAndZoneId(long zoneId, CPU.CPUArch arch); } diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java index 4d9bedba9669..9a56f0f2d949 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java @@ -16,6 +16,7 @@ // under the License. package com.cloud.dc.dao; +import com.cloud.cpu.CPU; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsVO; import com.cloud.dc.ClusterVO; @@ -43,6 +44,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; @Component public class ClusterDaoImpl extends GenericDaoBase implements ClusterDao { @@ -54,6 +56,8 @@ public class ClusterDaoImpl extends GenericDaoBase implements C protected final SearchBuilder ZoneHyTypeSearch; protected final SearchBuilder ZoneClusterSearch; protected final SearchBuilder ClusterSearch; + protected final SearchBuilder ClusterDistinctArchSearch; + protected final SearchBuilder ClusterArchSearch; protected GenericSearchBuilder ClusterIdSearch; @@ -104,6 +108,16 @@ public ClusterDaoImpl() { ClusterSearch = createSearchBuilder(); ClusterSearch.select(null, Func.DISTINCT, ClusterSearch.entity().getHypervisorType()); ClusterIdSearch.done(); + + ClusterDistinctArchSearch = createSearchBuilder(); + ClusterDistinctArchSearch.and("dataCenterId", ClusterDistinctArchSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + ClusterDistinctArchSearch.select(null, Func.DISTINCT, ClusterDistinctArchSearch.entity().getArch()); + ClusterDistinctArchSearch.done(); + + ClusterArchSearch = createSearchBuilder(); + ClusterArchSearch.and("dataCenterId", ClusterArchSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + ClusterArchSearch.and("arch", ClusterArchSearch.entity().getArch(), SearchCriteria.Op.EQ); + ClusterArchSearch.done(); } @Override @@ -301,4 +315,20 @@ public boolean getSupportsResigning(long clusterId) { return false; } + + @Override + public List getClustersArchsByZone(long zoneId) { + SearchCriteria sc = ClusterDistinctArchSearch.create(); + sc.setParameters("dataCenterId", zoneId); + List clusters = listBy(sc); + return clusters.stream().map(ClusterVO::getArch).collect(Collectors.toList()); + } + + @Override + public List listClustersByArchAndZoneId(long zoneId, CPU.CPUArch arch) { + SearchCriteria sc = ClusterArchSearch.create(); + sc.setParameters("dataCenterId", zoneId); + sc.setParameters("arch", arch); + return listBy(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java index 491919bbca73..7719e5adfc7e 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java @@ -26,7 +26,6 @@ import javax.naming.ConfigurationException; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenter; @@ -55,7 +54,6 @@ **/ @Component public class DataCenterDaoImpl extends GenericDaoBase implements DataCenterDao { - private static final Logger s_logger = Logger.getLogger(DataCenterDaoImpl.class); protected SearchBuilder NameSearch; protected SearchBuilder ListZonesByDomainIdSearch; @@ -166,8 +164,8 @@ public int countZoneVlans(long dcId, boolean onlyCountAllocated) { } @Override - public void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId) { - _ipAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); + public void releasePrivateIpAddress(String ipAddress, long dcId, Long nicId) { + _ipAllocDao.releaseIpAddress(ipAddress, dcId, nicId); } @Override @@ -181,8 +179,8 @@ public void releaseLinkLocalIpAddress(long nicId, String reservationId) { } @Override - public void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId) { - _linkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); + public void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long nicId) { + _linkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, nicId); } @Override @@ -228,9 +226,9 @@ public String allocatePodVlan(long podId, long accountId) { } @Override - public PrivateAllocationData allocatePrivateIpAddress(long dcId, long podId, long instanceId, String reservationId, boolean forSystemVms) { - _ipAllocDao.releaseIpAddress(instanceId); - DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId, forSystemVms); + public PrivateAllocationData allocatePrivateIpAddress(long dcId, long podId, long nicId, String reservationId, boolean forSystemVms) { + _ipAllocDao.releaseIpAddress(nicId); + DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dcId, podId, nicId, reservationId, forSystemVms); if (vo == null) { return null; } @@ -244,8 +242,8 @@ public DataCenterIpAddressVO allocatePrivateIpAddress(long dcId, String reservat } @Override - public String allocateLinkLocalIpAddress(long dcId, long podId, long instanceId, String reservationId) { - DataCenterLinkLocalIpAddressVO vo = _linkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId); + public String allocateLinkLocalIpAddress(long dcId, long podId, long nicId, String reservationId) { + DataCenterLinkLocalIpAddressVO vo = _linkLocalIpAllocDao.takeIpAddress(dcId, podId, nicId, reservationId); if (vo == null) { return null; } @@ -405,7 +403,7 @@ public DataCenterVO findByTokenOrIdOrName(String tokenOrIdOrName) { Long dcId = Long.parseLong(tokenOrIdOrName); return findById(dcId); } catch (NumberFormatException nfe) { - s_logger.debug("Cannot parse " + tokenOrIdOrName + " into long. " + nfe); + logger.debug("Cannot parse " + tokenOrIdOrName + " into long. " + nfe); } } } diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDetailsDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDetailsDaoImpl.java index e36c8ebd6c7c..bb03a96d02ee 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDetailsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDetailsDaoImpl.java @@ -44,8 +44,8 @@ public Scope getScope() { } @Override - public String getConfigValue(long id, ConfigKey key) { - ResourceDetail vo = findDetail(id, key.key()); + public String getConfigValue(long id, String key) { + ResourceDetail vo = findDetail(id, key); return vo == null ? null : vo.getValue(); } diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java index e58b08da4c18..48b9c83c64c6 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenterIpAddressVO; @@ -40,7 +39,6 @@ @Component @DB public class DataCenterIpAddressDaoImpl extends GenericDaoBase implements DataCenterIpAddressDao, Configurable { - private static final Logger s_logger = Logger.getLogger(DataCenterIpAddressDaoImpl.class); private final SearchBuilder AllFieldsSearch; private final GenericSearchBuilder AllIpCount; @@ -53,7 +51,7 @@ public class DataCenterIpAddressDaoImpl extends GenericDaoBase sc = AllFieldsSearch.create(); sc.setParameters("pod", podId); sc.setParameters("taken", (Date)null); @@ -73,7 +71,7 @@ public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceI return null; } vo.setTakenAt(new Date()); - vo.setInstanceId(instanceId); + vo.setNicId(nicId); vo.setReservationId(reservationId); update(vo.getId(), vo); txn.commit(); @@ -168,63 +166,63 @@ public void addIpRange(long dcId, long podId, String start, String end, boolean } @Override - public void releaseIpAddress(String ipAddress, long dcId, Long instanceId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId); + public void releaseIpAddress(String ipAddress, long dcId, Long nicId) { + if (logger.isDebugEnabled()) { + logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId); } SearchCriteria sc = AllFieldsSearch.create(); sc.setParameters("ip", ipAddress); sc.setParameters("dc", dcId); - sc.setParameters("instance", instanceId); + sc.setParameters("nic", nicId); DataCenterIpAddressVO vo = createForUpdate(); vo.setTakenAt(null); - vo.setInstanceId(null); + vo.setNicId(null); vo.setReservationId(null); update(vo, sc); } @Override public void releaseIpAddress(long nicId, String reservationId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing ip address for reservationId=" + reservationId + ", instance=" + nicId); + if (logger.isDebugEnabled()) { + logger.debug("Releasing ip address for reservationId=" + reservationId + ", nic=" + nicId); } SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("instance", nicId); + sc.setParameters("nic", nicId); sc.setParameters("reservation", reservationId); DataCenterIpAddressVO vo = createForUpdate(); vo.setTakenAt(null); - vo.setInstanceId(null); + vo.setNicId(null); vo.setReservationId(null); update(vo, sc); } @Override public void releasePodIpAddress(long id) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing ip address for ID=" + id); + if (logger.isDebugEnabled()) { + logger.debug("Releasing ip address for ID=" + id); } DataCenterIpAddressVO vo = this.findById(id); vo.setTakenAt(null); - vo.setInstanceId(null); + vo.setNicId(null); vo.setReservationId(null); persist(vo); } @Override public void releaseIpAddress(long nicId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing ip address for instance=" + nicId); + if (logger.isDebugEnabled()) { + logger.debug("Releasing ip address for nic=" + nicId); } SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("instance", nicId); + sc.setParameters("nic", nicId); DataCenterIpAddressVO vo = createForUpdate(); vo.setTakenAt(null); - vo.setInstanceId(null); + vo.setNicId(null); vo.setReservationId(null); update(vo, sc); } @@ -307,7 +305,7 @@ public DataCenterIpAddressDaoImpl() { AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ); - AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("nic", AllFieldsSearch.entity().getNicId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); AllFieldsSearch.and("reservation", AllFieldsSearch.entity().getReservationId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ); diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDaoImpl.java index 4fa3ad75ab50..517f02edde78 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDaoImpl.java @@ -24,7 +24,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenterLinkLocalIpAddressVO; @@ -41,7 +40,6 @@ @Component @DB public class DataCenterLinkLocalIpAddressDaoImpl extends GenericDaoBase implements DataCenterLinkLocalIpAddressDao { - private static final Logger s_logger = Logger.getLogger(DataCenterLinkLocalIpAddressDaoImpl.class); private final SearchBuilder AllFieldsSearch; private final GenericSearchBuilder AllIpCount; @@ -105,8 +103,8 @@ public void addIpRange(long dcId, long podId, String start, String end) { @Override public void releaseIpAddress(String ipAddress, long dcId, long instanceId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId); + if (logger.isDebugEnabled()) { + logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId); } SearchCriteria sc = AllFieldsSearch.create(); sc.setParameters("ip", ipAddress); diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/HostPodDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/HostPodDaoImpl.java index 3fbeb58c56ff..f1835067380f 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/HostPodDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/HostPodDaoImpl.java @@ -24,7 +24,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.HostPodVO; @@ -38,7 +37,6 @@ @Component public class HostPodDaoImpl extends GenericDaoBase implements HostPodDao { - private static final Logger s_logger = Logger.getLogger(HostPodDaoImpl.class); protected SearchBuilder DataCenterAndNameSearch; protected SearchBuilder DataCenterIdSearch; @@ -100,7 +98,7 @@ public HashMap> getCurrentPodCidrSubnets(long zoneId, long po currentPodCidrSubnets.put(podId, cidrPair); } } catch (SQLException ex) { - s_logger.warn("DB exception " + ex.getMessage(), ex); + logger.warn("DB exception " + ex.getMessage(), ex); return null; } diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/VsphereStoragePolicyDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/VsphereStoragePolicyDaoImpl.java index 0cdb6ad74220..c99fec5a17a5 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/VsphereStoragePolicyDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/VsphereStoragePolicyDaoImpl.java @@ -20,7 +20,6 @@ import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.util.List; @@ -28,7 +27,6 @@ @Component public class VsphereStoragePolicyDaoImpl extends GenericDaoBase implements VsphereStoragePolicyDao { - protected static final Logger LOGGER = Logger.getLogger(VsphereStoragePolicyDaoImpl.class); private final SearchBuilder zoneSearch; private final SearchBuilder policySearch; diff --git a/engine/schema/src/main/java/com/cloud/domain/DomainVO.java b/engine/schema/src/main/java/com/cloud/domain/DomainVO.java index 05cd4cc492e6..4c36a3401ca6 100644 --- a/engine/schema/src/main/java/com/cloud/domain/DomainVO.java +++ b/engine/schema/src/main/java/com/cloud/domain/DomainVO.java @@ -26,14 +26,15 @@ import javax.persistence.Id; import javax.persistence.Table; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.db.GenericDao; @Entity @Table(name = "domain") public class DomainVO implements Domain { - public static final Logger s_logger = Logger.getLogger(DomainVO.class.getName()); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java b/engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java index c020493d8f9c..74f2932ca433 100644 --- a/engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java @@ -25,7 +25,6 @@ import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.domain.Domain; @@ -40,7 +39,6 @@ @Component public class DomainDaoImpl extends GenericDaoBase implements DomainDao { - private static final Logger s_logger = Logger.getLogger(DomainDaoImpl.class); protected SearchBuilder DomainNameLikeSearch; protected SearchBuilder ParentDomainNameLikeSearch; @@ -112,7 +110,7 @@ public synchronized DomainVO create(DomainVO domain) { DomainVO parentDomain = findById(parent); if (parentDomain == null) { - s_logger.error("Unable to load parent domain: " + parent); + logger.error("Unable to load parent domain: " + parent); return null; } @@ -122,7 +120,7 @@ public synchronized DomainVO create(DomainVO domain) { parentDomain = this.lockRow(parent, true); if (parentDomain == null) { - s_logger.error("Unable to lock parent domain: " + parent); + logger.error("Unable to lock parent domain: " + parent); return null; } @@ -137,7 +135,7 @@ public synchronized DomainVO create(DomainVO domain) { txn.commit(); return domain; } catch (Exception e) { - s_logger.error("Unable to create domain due to " + e.getMessage(), e); + logger.error("Unable to create domain due to " + e.getMessage(), e); txn.rollback(); return null; } @@ -148,23 +146,23 @@ public synchronized DomainVO create(DomainVO domain) { public boolean remove(Long id) { // check for any active users / domains assigned to the given domain id and don't remove the domain if there are any if (id != null && id.longValue() == Domain.ROOT_DOMAIN) { - s_logger.error("Can not remove domain " + id + " as it is ROOT domain"); + logger.error("Can not remove domain " + id + " as it is ROOT domain"); return false; } else { if(id == null) { - s_logger.error("Can not remove domain without id."); + logger.error("Can not remove domain without id."); return false; } } DomainVO domain = findById(id); if (domain == null) { - s_logger.info("Unable to remove domain as domain " + id + " no longer exists"); + logger.info("Unable to remove domain as domain " + id + " no longer exists"); return true; } if (domain.getParent() == null) { - s_logger.error("Invalid domain " + id + ", orphan?"); + logger.error("Invalid domain " + id + ", orphan?"); return false; } @@ -177,7 +175,7 @@ public boolean remove(Long id) { txn.start(); DomainVO parentDomain = super.lockRow(domain.getParent(), true); if (parentDomain == null) { - s_logger.error("Unable to load parent domain: " + domain.getParent()); + logger.error("Unable to load parent domain: " + domain.getParent()); return false; } @@ -198,7 +196,7 @@ public boolean remove(Long id) { txn.commit(); } catch (SQLException ex) { success = false; - s_logger.error("error removing domain: " + id, ex); + logger.error("error removing domain: " + id, ex); txn.rollback(); } return success; @@ -310,7 +308,7 @@ public boolean domainIdListContainsAccessibleDomain(String domainIdList, Account return true; } } catch (NumberFormatException nfe) { - s_logger.debug(String.format("Unable to parse %s as domain ID from the list of domain IDs: %s", domainIdList.trim(), domainIdList), nfe); + logger.debug(String.format("Unable to parse %s as domain ID from the list of domain IDs: %s", domainIdList.trim(), domainIdList), nfe); } } return false; diff --git a/engine/schema/src/main/java/com/cloud/domain/dao/DomainDetailsDaoImpl.java b/engine/schema/src/main/java/com/cloud/domain/dao/DomainDetailsDaoImpl.java index 50097d154f5f..b9721a2e58c5 100644 --- a/engine/schema/src/main/java/com/cloud/domain/dao/DomainDetailsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/domain/dao/DomainDetailsDaoImpl.java @@ -22,6 +22,11 @@ import javax.inject.Inject; +import org.apache.cloudstack.framework.config.ConfigKey.Scope; +import org.apache.cloudstack.framework.config.ScopedConfigStorage; +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.cloudstack.framework.config.impl.ConfigurationVO; + import com.cloud.domain.DomainDetailVO; import com.cloud.domain.DomainVO; import com.cloud.utils.crypt.DBEncryptionUtil; @@ -31,11 +36,6 @@ import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.TransactionLegacy; -import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.cloudstack.framework.config.ConfigKey.Scope; -import org.apache.cloudstack.framework.config.ScopedConfigStorage; -import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.cloudstack.framework.config.impl.ConfigurationVO; public class DomainDetailsDaoImpl extends GenericDaoBase implements DomainDetailsDao, ScopedConfigStorage { protected final SearchBuilder domainSearch; @@ -108,17 +108,17 @@ public Scope getScope() { } @Override - public String getConfigValue(long id, ConfigKey key) { + public String getConfigValue(long id, String key) { DomainDetailVO vo = null; String enableDomainSettingsForChildDomain = _configDao.getValue("enable.domain.settings.for.child.domain"); if (!Boolean.parseBoolean(enableDomainSettingsForChildDomain)) { - vo = findDetail(id, key.key()); + vo = findDetail(id, key); return vo == null ? null : getActualValue(vo); } DomainVO domain = _domainDao.findById(id); // if value is not configured in domain then check its parent domain till ROOT while (domain != null) { - vo = findDetail(domain.getId(), key.key()); + vo = findDetail(domain.getId(), key); if (vo != null) { break; } else if (domain.getParent() != null) { diff --git a/engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java b/engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java index d4627904f0b4..e748e98900eb 100644 --- a/engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.event.Event.State; @@ -34,7 +33,6 @@ @Component public class EventDaoImpl extends GenericDaoBase implements EventDao { - public static final Logger s_logger = Logger.getLogger(EventDaoImpl.class.getName()); protected final SearchBuilder CompletedEventSearch; protected final SearchBuilder ToArchiveOrDeleteEventSearch; diff --git a/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDaoImpl.java b/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDaoImpl.java index 519b2ecfe736..fdef509da5bd 100644 --- a/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDaoImpl.java @@ -25,7 +25,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.Vlan; @@ -42,7 +41,6 @@ @Component public class UsageEventDaoImpl extends GenericDaoBase implements UsageEventDao { - public static final Logger s_logger = Logger.getLogger(UsageEventDaoImpl.class.getName()); private final SearchBuilder latestEventsSearch; private final SearchBuilder IpeventsSearch; @@ -101,8 +99,8 @@ public synchronized List getRecentEvents(Date endDate) { // Copy events from cloud db to usage db String sql = COPY_EVENTS; if (recentEventId == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("no recent event date, copying all events"); + if (logger.isDebugEnabled()) { + logger.debug("no recent event date, copying all events"); } sql = COPY_ALL_EVENTS; } @@ -120,7 +118,7 @@ public synchronized List getRecentEvents(Date endDate) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error copying events from cloud db to usage db", ex); + logger.error("error copying events from cloud db to usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); @@ -129,8 +127,8 @@ public synchronized List getRecentEvents(Date endDate) { // Copy event details from cloud db to usage db sql = COPY_EVENT_DETAILS; if (recentEventId == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("no recent event date, copying all event detailss"); + if (logger.isDebugEnabled()) { + logger.debug("no recent event date, copying all event detailss"); } sql = COPY_ALL_EVENT_DETAILS; } @@ -148,7 +146,7 @@ public synchronized List getRecentEvents(Date endDate) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error copying event details from cloud db to usage db", ex); + logger.error("error copying event details from cloud db to usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); @@ -171,7 +169,7 @@ private long getMostRecentEventId() { } return 0; } catch (Exception ex) { - s_logger.error("error getting most recent event id", ex); + logger.error("error getting most recent event id", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); @@ -183,7 +181,7 @@ private List findRecentEvents(Date endDate) { try { return listLatestEvents(endDate); } catch (Exception ex) { - s_logger.error("error getting most recent event date", ex); + logger.error("error getting most recent event date", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); @@ -203,7 +201,7 @@ private long getMaxEventId(Date endDate) { } return 0; } catch (Exception ex) { - s_logger.error("error getting max event id", ex); + logger.error("error getting max event id", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); diff --git a/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDetailsDaoImpl.java b/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDetailsDaoImpl.java index 43e00efc1ad3..37b203b2e88f 100644 --- a/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDetailsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDetailsDaoImpl.java @@ -20,7 +20,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.event.UsageEventDetailsVO; @@ -31,7 +30,6 @@ @Component public class UsageEventDetailsDaoImpl extends GenericDaoBase implements UsageEventDetailsDao { - public static final Logger s_logger = Logger.getLogger(UsageEventDetailsDaoImpl.class.getName()); protected final SearchBuilder EventDetailsSearch; protected final SearchBuilder DetailSearch; diff --git a/engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java b/engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java index 25f8d245a3b0..30535c7e27d5 100644 --- a/engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.gpu.HostGpuGroupsVO; @@ -30,7 +29,6 @@ @Component public class HostGpuGroupsDaoImpl extends GenericDaoBase implements HostGpuGroupsDao { - private static final Logger s_logger = Logger.getLogger(HostGpuGroupsDaoImpl.class); private final SearchBuilder _hostIdGroupNameSearch; private final SearchBuilder _searchByHostId; diff --git a/engine/schema/src/main/java/com/cloud/gpu/dao/VGPUTypesDaoImpl.java b/engine/schema/src/main/java/com/cloud/gpu/dao/VGPUTypesDaoImpl.java index d4e31d365d9e..edc5e1f67c86 100644 --- a/engine/schema/src/main/java/com/cloud/gpu/dao/VGPUTypesDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/gpu/dao/VGPUTypesDaoImpl.java @@ -27,7 +27,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.api.VgpuTypesInfo; @@ -41,7 +40,6 @@ @Component public class VGPUTypesDaoImpl extends GenericDaoBase implements VGPUTypesDao { - private static final Logger s_logger = Logger.getLogger(VGPUTypesDaoImpl.class); private final SearchBuilder _searchByGroupId; private final SearchBuilder _searchByGroupIdVGPUType; diff --git a/engine/schema/src/main/java/com/cloud/host/HostTagVO.java b/engine/schema/src/main/java/com/cloud/host/HostTagVO.java index cd4ac29738d5..98071a2c0732 100644 --- a/engine/schema/src/main/java/com/cloud/host/HostTagVO.java +++ b/engine/schema/src/main/java/com/cloud/host/HostTagVO.java @@ -40,6 +40,9 @@ public class HostTagVO implements InternalIdentity { @Column(name = "tag") private String tag; + @Column(name = "is_implicit") + private boolean isImplicit = false; + @Column(name = "is_tag_a_rule") private boolean isTagARule; @@ -74,6 +77,13 @@ public boolean getIsTagARule() { return isTagARule; } + public void setIsImplicit(boolean isImplicit) { + this.isImplicit = isImplicit; + } + + public boolean getIsImplicit() { + return isImplicit; + } @Override public long getId() { diff --git a/engine/schema/src/main/java/com/cloud/host/HostVO.java b/engine/schema/src/main/java/com/cloud/host/HostVO.java index 697401ad0696..b5b634a73a70 100644 --- a/engine/schema/src/main/java/com/cloud/host/HostVO.java +++ b/engine/schema/src/main/java/com/cloud/host/HostVO.java @@ -16,13 +16,17 @@ // under the License. package com.cloud.host; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; @@ -38,20 +42,25 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; +import com.cloud.cpu.CPU; +import org.apache.cloudstack.util.CPUArchConverter; +import org.apache.cloudstack.util.HypervisorTypeConverter; +import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang3.StringUtils; + import com.cloud.agent.api.VgpuTypesInfo; import com.cloud.host.dao.HostTagsDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.ServiceOffering; import com.cloud.resource.ResourceState; import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.util.StoragePoolTypeConverter; import com.cloud.utils.NumbersUtil; import com.cloud.utils.db.GenericDao; -import java.util.Arrays; - -import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper; -import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.commons.lang.BooleanUtils; -import org.apache.commons.lang3.StringUtils; @Entity @Table(name = "host") @@ -120,7 +129,7 @@ public class HostVO implements Host { private String storageMacAddressDeux; @Column(name = "hypervisor_type", updatable = true, nullable = false) - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) private HypervisorType hypervisorType; @Column(name = "proxy_port") @@ -130,6 +139,7 @@ public class HostVO implements Host { private String resource; @Column(name = "fs_type") + @Convert(converter = StoragePoolTypeConverter.class) private StoragePoolType fsType; @Column(name = "available") @@ -145,6 +155,10 @@ public class HostVO implements Host { @Column(name = "hypervisor_version") private String hypervisorVersion; + @Column(name = "arch") + @Convert(converter = CPUArchConverter.class) + private CPU.CPUArch arch; + @Column(name = "update_count", updatable = true, nullable = false) protected long updated; // This field should be updated everytime the state is updated. There's no set method in the vo object because it is done with in the dao code. @@ -730,6 +744,15 @@ public ResourceState getResourceState() { return resourceState; } + @Override + public CPU.CPUArch getArch() { + return arch; + } + + public void setArch(CPU.CPUArch arch) { + this.arch = arch; + } + public void setResourceState(ResourceState state) { resourceState = state; } @@ -761,7 +784,49 @@ public void setUuid(String uuid) { this.uuid = uuid; } - public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering){ + private Set getHostServiceOfferingAndTemplateStrictTags(ServiceOffering serviceOffering, VirtualMachineTemplate template, Set strictHostTags) { + if (StringUtils.isEmpty(serviceOffering.getHostTag()) && StringUtils.isEmpty(template.getTemplateTag())) { + return new HashSet<>(); + } + List hostTagsList = getHostTags(); + HashSet hostTagsSet = CollectionUtils.isNotEmpty(hostTagsList) ? new HashSet<>(hostTagsList) : new HashSet<>(); + HashSet tags = new HashSet<>(); + if (StringUtils.isNotEmpty(serviceOffering.getHostTag())) { + tags.addAll(Arrays.asList(serviceOffering.getHostTag().split(","))); + } + if (StringUtils.isNotEmpty(template.getTemplateTag())) { + tags.add(template.getTemplateTag()); + } + tags.removeIf(tag -> !strictHostTags.contains(tag)); + tags.removeAll(hostTagsSet); + return tags; + } + + public boolean checkHostServiceOfferingAndTemplateTags(ServiceOffering serviceOffering, VirtualMachineTemplate template, Set strictHostTags) { + if (serviceOffering == null || template == null) { + return false; + } + Set tags = getHostServiceOfferingAndTemplateStrictTags(serviceOffering, template, strictHostTags); + if (tags.isEmpty()) { + return true; + } + List hostTagsList = getHostTags(); + HashSet hostTagsSet = CollectionUtils.isNotEmpty(hostTagsList) ? new HashSet<>(hostTagsList) : new HashSet<>(); + return hostTagsSet.containsAll(tags); + } + + public Set getHostServiceOfferingAndTemplateMissingTags(ServiceOffering serviceOffering, VirtualMachineTemplate template, Set strictHostTags) { + Set tags = getHostServiceOfferingAndTemplateStrictTags(serviceOffering, template, strictHostTags); + if (tags.isEmpty()) { + return new HashSet<>(); + } + List hostTagsList = getHostTags(); + HashSet hostTagsSet = CollectionUtils.isNotEmpty(hostTagsList) ? new HashSet<>(hostTagsList) : new HashSet<>(); + tags.removeAll(hostTagsSet); + return tags; + } + + public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering) { if (serviceOffering == null) { return false; } @@ -773,7 +838,6 @@ public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering){ if (StringUtils.isEmpty(serviceOffering.getHostTag())) { return true; } - List serviceOfferingTags = Arrays.asList(serviceOffering.getHostTag().split(",")); return this.getHostTags() != null && this.getHostTags().containsAll(serviceOfferingTags); } diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java index 7e944291994b..a2df6db44e51 100644 --- a/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java +++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java @@ -63,7 +63,7 @@ public interface HostDao extends GenericDao, StateDao listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag); + List listByHostTag(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTag); List findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId); @@ -169,4 +169,6 @@ public interface HostDao extends GenericDao, StateDao findHostsWithTagRuleThatMatchComputeOferringTags(String computeOfferingTags); List findClustersThatMatchHostTagRule(String computeOfferingTags); + + List listSsvmHostsWithPendingMigrateJobsOrderedByJobCount(); } diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java index da829a5fe247..63950294654c 100644 --- a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.VgpuTypesInfo; import com.cloud.cluster.agentlb.HostTransferMapVO; @@ -74,14 +73,12 @@ import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.db.UpdateBuilder; import com.cloud.utils.exception.CloudRuntimeException; + import java.util.Arrays; @DB @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1) public class HostDaoImpl extends GenericDaoBase implements HostDao { //FIXME: , ExternalIdDao { - private static final Logger s_logger = Logger.getLogger(HostDaoImpl.class); - private static final Logger status_logger = Logger.getLogger(Status.class); - private static final Logger state_logger = Logger.getLogger(ResourceState.class); private static final String LIST_HOST_IDS_BY_COMPUTETAGS = "SELECT filtered.host_id, COUNT(filtered.tag) AS tag_count " + "FROM (SELECT host_id, tag, is_tag_a_rule FROM host_tags GROUP BY host_id,tag) AS filtered " @@ -356,7 +353,7 @@ public void init() { try { HostTransferSearch = _hostTransferDao.createSearchBuilder(); } catch (Throwable e) { - s_logger.debug("error", e); + logger.debug("error", e); } HostTransferSearch.and("id", HostTransferSearch.entity().getId(), SearchCriteria.Op.NULL); UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(), @@ -594,8 +591,8 @@ private void resetHosts(long managementServerId, long lastPingSecondsAfter) { sb.append(" "); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Following hosts got reset: " + sb.toString()); + if (logger.isTraceEnabled()) { + logger.trace("Following hosts got reset: " + sb.toString()); } } @@ -643,19 +640,19 @@ private boolean canOwnCluster(long clusterId) { public List findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Resetting hosts suitable for reconnect"); + if (logger.isDebugEnabled()) { + logger.debug("Resetting hosts suitable for reconnect"); } // reset hosts that are suitable candidates for reconnect resetHosts(managementServerId, lastPingSecondsAfter); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Completed resetting hosts suitable for reconnect"); + if (logger.isDebugEnabled()) { + logger.debug("Completed resetting hosts suitable for reconnect"); } List assignedHosts = new ArrayList(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Acquiring hosts for clusters already owned by this management server"); + if (logger.isDebugEnabled()) { + logger.debug("Acquiring hosts for clusters already owned by this management server"); } List clusters = findClustersOwnedByManagementServer(managementServerId); txn.start(); @@ -674,17 +671,17 @@ public List findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Lo sb.append(host.getId()); sb.append(" "); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Following hosts got acquired for clusters already owned: " + sb.toString()); + if (logger.isTraceEnabled()) { + logger.trace("Following hosts got acquired for clusters already owned: " + sb.toString()); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Completed acquiring hosts for clusters already owned by this management server"); + if (logger.isDebugEnabled()) { + logger.debug("Completed acquiring hosts for clusters already owned by this management server"); } if (assignedHosts.size() < limit) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Acquiring hosts for clusters not owned by any management server"); + if (logger.isDebugEnabled()) { + logger.debug("Acquiring hosts for clusters not owned by any management server"); } // for remaining hosts not owned by any MS check if they can be owned (by owning full cluster) clusters = findClustersForHostsNotOwnedByAnyManagementServer(); @@ -724,12 +721,12 @@ public List findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Lo break; } } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Following hosts got acquired from newly owned clusters: " + sb.toString()); + if (logger.isTraceEnabled()) { + logger.trace("Following hosts got acquired from newly owned clusters: " + sb.toString()); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Completed acquiring hosts for clusters not owned by any management server"); + if (logger.isDebugEnabled()) { + logger.debug("Completed acquiring hosts for clusters not owned by any management server"); } } txn.commit(); @@ -784,7 +781,7 @@ public void markHostsAsDisconnected(long msId, long lastPing) { } @Override - public List listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) { + public List listByHostTag(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTag) { SearchBuilder hostSearch = createSearchBuilder(); HostVO entity = hostSearch.entity(); hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ); @@ -802,7 +799,9 @@ public List listByHostTag(Host.Type type, Long clusterId, Long podId, lo if (clusterId != null) { sc.setParameters("cluster", clusterId); } - sc.setParameters("dc", dcId); + if (dcId != null) { + sc.setParameters("dc", dcId); + } sc.setParameters("status", Status.Up.toString()); sc.setParameters("resourceState", ResourceState.Enabled.toString()); @@ -900,7 +899,7 @@ public List findLostHosts(long timeout) { } } } catch (SQLException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); } return result; } @@ -1010,15 +1009,15 @@ public List getRunningHostCounts(Date cutTime) { l.add(info); } } catch (SQLException e) { - s_logger.debug("SQLException caught", e); + logger.debug("SQLException caught", e); } return l; } @Override public long getNextSequence(long hostId) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("getNextSequence(), hostId: " + hostId); + if (logger.isTraceEnabled()) { + logger.trace("getNextSequence(), hostId: " + hostId); } TableGenerator tg = _tgs.get("host_req_sq"); @@ -1088,7 +1087,7 @@ public boolean updateState(Status oldStatus, Event event, Status newStatus, Host HostVO ho = findById(host.getId()); assert ho != null : "How how how? : " + host.getId(); - if (status_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); str.append(". Name=").append(host.getName()); @@ -1098,7 +1097,7 @@ public boolean updateState(Status oldStatus, Event event, Status newStatus, Host .append("]"); str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()) .append(":old update count=").append(oldUpdateCount).append("]"); - status_logger.debug(str.toString()); + logger.debug(str.toString()); } else { StringBuilder msg = new StringBuilder("Agent status update: ["); msg.append("id = " + host.getId()); @@ -1108,11 +1107,11 @@ public boolean updateState(Status oldStatus, Event event, Status newStatus, Host msg.append("; new status = " + newStatus); msg.append("; old update count = " + oldUpdateCount); msg.append("; new update count = " + newUpdateCount + "]"); - status_logger.debug(msg.toString()); + logger.debug(msg.toString()); } if (ho.getState() == newStatus) { - status_logger.debug("Host " + ho.getName() + " state has already been updated to " + newStatus); + logger.debug("Host " + ho.getName() + " state has already been updated to " + newStatus); return true; } } @@ -1138,7 +1137,7 @@ public boolean updateResourceState(ResourceState oldState, ResourceState.Event e int result = update(ub, sc, null); assert result <= 1 : "How can this update " + result + " rows? "; - if (state_logger.isDebugEnabled() && result == 0) { + if (logger.isDebugEnabled() && result == 0) { HostVO ho = findById(host.getId()); assert ho != null : "How how how? : " + host.getId(); @@ -1148,7 +1147,7 @@ public boolean updateResourceState(ResourceState oldState, ResourceState.Event e str.append("; old state = " + oldState); str.append("; event = " + event); str.append("; new state = " + newState + "]"); - state_logger.debug(str.toString()); + logger.debug(str.toString()); } else { StringBuilder msg = new StringBuilder("Resource state update: ["); msg.append("id = " + host.getId()); @@ -1156,7 +1155,7 @@ public boolean updateResourceState(ResourceState oldState, ResourceState.Event e msg.append("; old state = " + oldState); msg.append("; event = " + event); msg.append("; new state = " + newState + "]"); - state_logger.debug(msg.toString()); + logger.debug(msg.toString()); } return result > 0; @@ -1372,6 +1371,31 @@ public List findClustersThatMatchHostTagRule(String computeOfferingTags) { return new ArrayList<>(result); } + @Override + public List listSsvmHostsWithPendingMigrateJobsOrderedByJobCount() { + String query = "SELECT cel.host_id, COUNT(*) " + + "FROM cmd_exec_log cel " + + "JOIN host h ON cel.host_id = h.id " + + "WHERE h.removed IS NULL " + + "GROUP BY cel.host_id " + + "ORDER BY 2"; + + TransactionLegacy txn = TransactionLegacy.currentTxn(); + List result = new ArrayList<>(); + + PreparedStatement pstmt; + try { + pstmt = txn.prepareAutoCloseStatement(query); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + result.add((long) rs.getInt(1)); + } + } catch (SQLException e) { + logger.warn("SQLException caught while listing SSVMs with least migrate jobs.", e); + } + return result; + } + private String getHostIdsByComputeTags(List offeringTags){ List questionMarks = new ArrayList(); offeringTags.forEach((tag) -> { questionMarks.add("?"); }); @@ -1420,7 +1444,7 @@ public List listOrderedHostsHypervisorVersionsInDatacenter(long datacent result.add(resultSet.getString(1)); } } catch (SQLException e) { - s_logger.error("Error trying to obtain hypervisor version on datacenter", e); + logger.error("Error trying to obtain hypervisor version on datacenter", e); } return result; } diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostTagsDao.java b/engine/schema/src/main/java/com/cloud/host/dao/HostTagsDao.java index d134db334035..7a00829fd44e 100644 --- a/engine/schema/src/main/java/com/cloud/host/dao/HostTagsDao.java +++ b/engine/schema/src/main/java/com/cloud/host/dao/HostTagsDao.java @@ -20,6 +20,7 @@ import com.cloud.host.HostTagVO; import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.api.response.HostTagResponse; import org.apache.cloudstack.framework.config.ConfigKey; public interface HostTagsDao extends GenericDao { @@ -35,6 +36,13 @@ public interface HostTagsDao extends GenericDao { void deleteTags(long hostId); + boolean updateImplicitTags(long hostId, List hostTags); + + List getExplicitHostTags(long hostId); + List findHostRuleTags(); + HostTagResponse newHostTagResponse(HostTagVO hostTag); + + List searchByIds(Long... hostTagIds); } diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostTagsDaoImpl.java b/engine/schema/src/main/java/com/cloud/host/dao/HostTagsDaoImpl.java index 65deb1d1c9b0..4aa14a31cfcf 100644 --- a/engine/schema/src/main/java/com/cloud/host/dao/HostTagsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/host/dao/HostTagsDaoImpl.java @@ -16,10 +16,14 @@ // under the License. package com.cloud.host.dao; +import java.util.ArrayList; import java.util.List; +import org.apache.cloudstack.api.response.HostTagResponse; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import com.cloud.host.HostTagVO; @@ -30,14 +34,23 @@ import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.db.SearchCriteria.Func; +import javax.inject.Inject; + @Component public class HostTagsDaoImpl extends GenericDaoBase implements HostTagsDao, Configurable { protected final SearchBuilder HostSearch; protected final GenericSearchBuilder DistinctImplictTagsSearch; + private final SearchBuilder stSearch; + private final SearchBuilder tagIdsearch; + private final SearchBuilder ImplicitTagsSearch; + + @Inject + private ConfigurationDao _configDao; public HostTagsDaoImpl() { HostSearch = createSearchBuilder(); HostSearch.and("hostId", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); + HostSearch.and("isImplicit", HostSearch.entity().getIsImplicit(), SearchCriteria.Op.EQ); HostSearch.and("isTagARule", HostSearch.entity().getIsTagARule(), SearchCriteria.Op.EQ); HostSearch.done(); @@ -46,6 +59,19 @@ public HostTagsDaoImpl() { DistinctImplictTagsSearch.and("hostIds", DistinctImplictTagsSearch.entity().getHostId(), SearchCriteria.Op.IN); DistinctImplictTagsSearch.and("implicitTags", DistinctImplictTagsSearch.entity().getTag(), SearchCriteria.Op.IN); DistinctImplictTagsSearch.done(); + + stSearch = createSearchBuilder(); + stSearch.and("idIN", stSearch.entity().getId(), SearchCriteria.Op.IN); + stSearch.done(); + + tagIdsearch = createSearchBuilder(); + tagIdsearch.and("id", tagIdsearch.entity().getId(), SearchCriteria.Op.EQ); + tagIdsearch.done(); + + ImplicitTagsSearch = createSearchBuilder(); + ImplicitTagsSearch.and("hostId", ImplicitTagsSearch.entity().getHostId(), SearchCriteria.Op.EQ); + ImplicitTagsSearch.and("isImplicit", ImplicitTagsSearch.entity().getIsImplicit(), SearchCriteria.Op.EQ); + ImplicitTagsSearch.done(); } @Override @@ -74,6 +100,36 @@ public void deleteTags(long hostId) { txn.commit(); } + @Override + public boolean updateImplicitTags(long hostId, List hostTags) { + TransactionLegacy txn = TransactionLegacy.currentTxn(); + txn.start(); + SearchCriteria sc = ImplicitTagsSearch.create(); + sc.setParameters("hostId", hostId); + sc.setParameters("isImplicit", true); + boolean expunged = expunge(sc) > 0; + boolean persisted = false; + for (String tag : hostTags) { + if (StringUtils.isNotBlank(tag)) { + HostTagVO vo = new HostTagVO(hostId, tag.trim()); + vo.setIsImplicit(true); + persist(vo); + persisted = true; + } + } + txn.commit(); + return expunged || persisted; + } + + @Override + public List getExplicitHostTags(long hostId) { + SearchCriteria sc = ImplicitTagsSearch.create(); + sc.setParameters("hostId", hostId); + sc.setParameters("isImplicit", false); + + return search(sc, null); + } + @Override public List findHostRuleTags() { SearchCriteria sc = HostSearch.create(); @@ -89,6 +145,7 @@ public void persist(long hostId, List hostTags, Boolean isTagARule) { txn.start(); SearchCriteria sc = HostSearch.create(); sc.setParameters("hostId", hostId); + sc.setParameters("isImplicit", false); expunge(sc); for (String tag : hostTags) { @@ -110,4 +167,72 @@ public ConfigKey[] getConfigKeys() { public String getConfigComponentName() { return HostTagsDaoImpl.class.getSimpleName(); } + + @Override + public HostTagResponse newHostTagResponse(HostTagVO tag) { + HostTagResponse tagResponse = new HostTagResponse(); + + tagResponse.setName(tag.getTag()); + tagResponse.setHostId(tag.getHostId()); + tagResponse.setImplicit(tag.getIsImplicit()); + + tagResponse.setObjectName("hosttag"); + + return tagResponse; + } + + @Override + public List searchByIds(Long... tagIds) { + String batchCfg = _configDao.getValue("detail.batch.query.size"); + + final int detailsBatchSize = batchCfg != null ? Integer.parseInt(batchCfg) : 2000; + + // query details by batches + List tagList = new ArrayList<>(); + int curr_index = 0; + + if (tagIds.length > detailsBatchSize) { + while ((curr_index + detailsBatchSize) <= tagIds.length) { + Long[] ids = new Long[detailsBatchSize]; + + for (int k = 0, j = curr_index; j < curr_index + detailsBatchSize; j++, k++) { + ids[k] = tagIds[j]; + } + + SearchCriteria sc = stSearch.create(); + + sc.setParameters("idIN", (Object[])ids); + + List vms = searchIncludingRemoved(sc, null, null, false); + + if (vms != null) { + tagList.addAll(vms); + } + + curr_index += detailsBatchSize; + } + } + + if (curr_index < tagIds.length) { + int batch_size = (tagIds.length - curr_index); + // set the ids value + Long[] ids = new Long[batch_size]; + + for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) { + ids[k] = tagIds[j]; + } + + SearchCriteria sc = stSearch.create(); + + sc.setParameters("idIN", (Object[])ids); + + List tags = searchIncludingRemoved(sc, null, null, false); + + if (tags != null) { + tagList.addAll(tags); + } + } + + return tagList; + } } diff --git a/engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java b/engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java index 118699c1f846..a3b03280fdf6 100644 --- a/engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java +++ b/engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java @@ -19,9 +19,8 @@ import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -29,6 +28,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.NumbersUtil; +import org.apache.cloudstack.util.HypervisorTypeConverter; @Entity @Table(name = "hypervisor_capabilities") @@ -39,7 +39,7 @@ public class HypervisorCapabilitiesVO implements HypervisorCapabilities { private long id; @Column(name = "hypervisor_type") - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) private HypervisorType hypervisorType; @Column(name = "hypervisor_version") diff --git a/engine/schema/src/main/java/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java b/engine/schema/src/main/java/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java index a4ec0a663609..f636c2eb7628 100644 --- a/engine/schema/src/main/java/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java @@ -21,7 +21,6 @@ import org.apache.cloudstack.utils.CloudStackVersion; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -33,7 +32,6 @@ @Component public class HypervisorCapabilitiesDaoImpl extends GenericDaoBase implements HypervisorCapabilitiesDao { - private static final Logger s_logger = Logger.getLogger(HypervisorCapabilitiesDaoImpl.class); protected final SearchBuilder HypervisorTypeSearch; protected final SearchBuilder HypervisorTypeAndVersionSearch; @@ -80,8 +78,8 @@ public HypervisorCapabilitiesVO findByHypervisorTypeAndVersion(HypervisorType hy parentVersion == null) { return result; } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Hypervisor capabilities for hypervisor: %s, version: %s can not be found. " + + if (logger.isDebugEnabled()) { + logger.debug(String.format("Hypervisor capabilities for hypervisor: %s, version: %s can not be found. " + "Trying to find capabilities for the parent version: %s", hypervisorType, hypervisorVersion, parentVersion)); } diff --git a/engine/schema/src/main/java/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java b/engine/schema/src/main/java/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java index b4bd56f5b4ee..73d21c3b15a7 100644 --- a/engine/schema/src/main/java/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java @@ -21,7 +21,7 @@ import com.cloud.dc.dao.VmwareDatacenterDao; -import org.apache.log4j.Logger; + import org.springframework.stereotype.Component; import com.cloud.dc.VmwareDatacenterVO; @@ -34,7 +34,6 @@ @Component @DB public class VmwareDatacenterDaoImpl extends GenericDaoBase implements VmwareDatacenterDao { - protected static final Logger s_logger = Logger.getLogger(VmwareDatacenterDaoImpl.class); final SearchBuilder nameSearch; final SearchBuilder guidSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java b/engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java index 4b25c63403e2..718511746c2f 100644 --- a/engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java +++ b/engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java @@ -35,4 +35,6 @@ public interface AutoScaleVmGroupVmMapDao extends GenericDao vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java index 8fca4c26f9a7..1ae55d97da2c 100644 --- a/engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java @@ -18,7 +18,10 @@ import java.util.List; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.network.as.AutoScaleVmGroupVmMapVO; @@ -31,9 +34,6 @@ import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.VMInstanceDao; -import javax.annotation.PostConstruct; -import javax.inject.Inject; - @Component public class AutoScaleVmGroupVmMapDaoImpl extends GenericDaoBase implements AutoScaleVmGroupVmMapDao { @@ -115,4 +115,16 @@ public boolean removeByGroup(long vmGroupId) { sc.setParameters("vmGroupId", vmGroupId); return remove(sc) >= 0; } + + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getInstanceId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java index f6185309972b..fdd1e0ec43ad 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.DB; @@ -31,7 +30,6 @@ @Component public class FirewallRulesCidrsDaoImpl extends GenericDaoBase implements FirewallRulesCidrsDao { - private static final Logger s_logger = Logger.getLogger(FirewallRulesCidrsDaoImpl.class); protected final SearchBuilder CidrsSearch; protected FirewallRulesCidrsDaoImpl() { diff --git a/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesDao.java b/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesDao.java index 21200dbf9b58..b80ccd9cd1b9 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesDao.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesDao.java @@ -72,4 +72,6 @@ public interface FirewallRulesDao extends GenericDao { void loadSourceCidrs(FirewallRuleVO rule); void loadDestinationCidrs(FirewallRuleVO rule); + + List listRoutingIngressFirewallRules(long networkId); } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesDaoImpl.java index 3ac860b08c5f..1698e0ed2da9 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesDaoImpl.java @@ -50,6 +50,7 @@ public class FirewallRulesDaoImpl extends GenericDaoBase i protected SearchBuilder VmSearch; protected final SearchBuilder SystemRuleSearch; protected final GenericSearchBuilder RulesByIpCount; + protected final SearchBuilder RoutingFirewallRulesSearch; @Inject protected FirewallRulesCidrsDao _firewallRulesCidrsDao; @@ -104,6 +105,13 @@ protected FirewallRulesDaoImpl() { RulesByIpCount.and("ipAddressId", RulesByIpCount.entity().getSourceIpAddressId(), Op.EQ); RulesByIpCount.and("state", RulesByIpCount.entity().getState(), Op.EQ); RulesByIpCount.done(); + + RoutingFirewallRulesSearch = createSearchBuilder(); + RoutingFirewallRulesSearch.and("networkId", RoutingFirewallRulesSearch.entity().getNetworkId(), Op.EQ); + RoutingFirewallRulesSearch.and("purpose", RoutingFirewallRulesSearch.entity().getPurpose(), Op.EQ); + RoutingFirewallRulesSearch.and("trafficType", RoutingFirewallRulesSearch.entity().getTrafficType(), Op.EQ); + RoutingFirewallRulesSearch.and("ipId", RoutingFirewallRulesSearch.entity().getSourceIpAddressId(), Op.NULL); + RoutingFirewallRulesSearch.done(); } @Override @@ -386,4 +394,12 @@ public void loadDestinationCidrs(FirewallRuleVO rule){ rule.setDestinationCidrsList(destCidrs); } + @Override + public List listRoutingIngressFirewallRules(long networkId) { + SearchCriteria sc = RoutingFirewallRulesSearch.create(); + sc.setParameters("networkId", networkId); + sc.setParameters("purpose", Purpose.Firewall); + sc.setParameters("trafficType", TrafficType.Ingress); + return listBy(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java b/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java index b1b1e1cf7571..3f8c36ac94ed 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java @@ -105,4 +105,6 @@ public interface IPAddressDao extends GenericDao { void buildQuarantineSearchCriteria(SearchCriteria sc); IPAddressVO findBySourceNetworkIdAndDatacenterIdAndState(long sourceNetworkId, long dataCenterId, State state); + + int expungeByVmList(List vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDaoImpl.java index d14275227158..aa143838c343 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDaoImpl.java @@ -26,7 +26,7 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.resourcedetail.dao.UserIpAddressDetailsDao; -import org.apache.log4j.Logger; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.dc.Vlan.VlanType; @@ -50,7 +50,6 @@ @Component @DB public class IPAddressDaoImpl extends GenericDaoBase implements IPAddressDao { - private static final Logger s_logger = Logger.getLogger(IPAddressDaoImpl.class); protected SearchBuilder AllFieldsSearch; protected SearchBuilder VlanDbIdSearchUnallocated; @@ -374,7 +373,7 @@ public int countIPs(long dcId, Long accountId, String vlanId, String vlanGateway ipCount = rs.getInt(1); } } catch (Exception e) { - s_logger.warn("Exception counting IP addresses", e); + logger.warn("Exception counting IP addresses", e); } return ipCount; @@ -563,4 +562,16 @@ public IPAddressVO findBySourceNetworkIdAndDatacenterIdAndState(long sourceNetwo sc.setParameters("state", State.Free); return findOneBy(sc); } + + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getAssociatedWithVmId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/InlineLoadBalancerNicMapDao.java b/engine/schema/src/main/java/com/cloud/network/dao/InlineLoadBalancerNicMapDao.java index ac3845beffe4..b1831b407a41 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/InlineLoadBalancerNicMapDao.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/InlineLoadBalancerNicMapDao.java @@ -16,10 +16,14 @@ // under the License. package com.cloud.network.dao; +import java.util.List; + import com.cloud.utils.db.GenericDao; public interface InlineLoadBalancerNicMapDao extends GenericDao { InlineLoadBalancerNicMapVO findByPublicIpAddress(String publicIpAddress); InlineLoadBalancerNicMapVO findByNicId(long nicId); + int expungeByNicList(List nicIds, Long batchSize); + } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImpl.java index 1c3f231f9c1d..d64ba8b4155f 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImpl.java @@ -17,9 +17,13 @@ package com.cloud.network.dao; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; @Component @@ -41,4 +45,15 @@ public InlineLoadBalancerNicMapVO findByNicId(long nicId) { return findOneBy(sc); } + @Override + public int expungeByNicList(List nicIds, Long batchSize) { + if (CollectionUtils.isEmpty(nicIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("nicIds", sb.entity().getNicId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("nicIds", nicIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVMMapDao.java b/engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVMMapDao.java index a25534b7010f..be2941d5cb2f 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVMMapDao.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVMMapDao.java @@ -42,4 +42,5 @@ public interface LoadBalancerVMMapDao extends GenericDao vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java index b32320a84cb0..dc37cdeefe3d 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java @@ -18,11 +18,12 @@ import java.util.List; - +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Func; @@ -135,4 +136,16 @@ public List listByLoadBalancerIdAndVmId(long loadBalancerId sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId); return listBy(sc); } + + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getInstanceId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NetworkDomainDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/NetworkDomainDaoImpl.java index ce86a8636a10..e8c55131ecdd 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/NetworkDomainDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/NetworkDomainDaoImpl.java @@ -26,7 +26,6 @@ import java.util.Map; import com.cloud.utils.db.TransactionLegacy; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.DB; @@ -38,7 +37,6 @@ @Component @DB() public class NetworkDomainDaoImpl extends GenericDaoBase implements NetworkDomainDao { - public static Logger logger = Logger.getLogger(NetworkDomainDaoImpl.class.getName()); final SearchBuilder AllFieldsSearch; final SearchBuilder DomainsSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NetworkServiceMapDao.java b/engine/schema/src/main/java/com/cloud/network/dao/NetworkServiceMapDao.java index e0509f80c2a4..1675c89811a5 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/NetworkServiceMapDao.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/NetworkServiceMapDao.java @@ -30,6 +30,8 @@ public interface NetworkServiceMapDao extends GenericDao { boolean areServicesSupportedInNetwork(long networkId, Service... services); + boolean isAnyServiceSupportedInNetwork(long networkId, Provider provider, Service... services); + boolean canProviderSupportServiceInNetwork(long networkId, Service service, Provider provider); List getServicesInNetwork(long networkId); diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NetworkServiceMapDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/NetworkServiceMapDaoImpl.java index 31e083075fa9..f25bee5da471 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/NetworkServiceMapDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/NetworkServiceMapDaoImpl.java @@ -90,6 +90,28 @@ public boolean areServicesSupportedInNetwork(long networkId, Service... services return false; } + @Override + public boolean isAnyServiceSupportedInNetwork(long networkId, Provider provider, Service... services) { + SearchCriteria sc = MultipleServicesSearch.create(); + sc.setParameters("networkId", networkId); + sc.setParameters("provider", provider.getName()); + + if (services != null) { + String[] servicesStr = new String[services.length]; + + int i = 0; + for (Service service : services) { + servicesStr[i] = service.getName(); + i++; + } + + sc.setParameters("service", (Object[])servicesStr); + } + + List networkServices = listBy(sc); + return !networkServices.isEmpty(); + } + @Override public boolean canProviderSupportServiceInNetwork(long networkId, Service service, Provider provider) { SearchCriteria sc = AllFieldsSearch.create(); diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java b/engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java index f24eec4931e3..02abaacd854e 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java @@ -39,7 +39,6 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.db.GenericDao; import com.cloud.utils.net.NetUtils; -import org.apache.log4j.Logger; /** * NetworkConfigurationVO contains information about a specific network. @@ -48,7 +47,6 @@ @Entity @Table(name = "networks") public class NetworkVO implements Network { - static final Logger s_logger = Logger.getLogger(NetworkVO.class); @Id @TableGenerator(name = "networks_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "networks_seq", allocationSize = 1) @Column(name = "id") @@ -205,6 +203,9 @@ public class NetworkVO implements Network { @Column(name = "private_mtu") Integer privateMtu; + @Transient + Integer networkCidrSize; + public NetworkVO() { uuid = UUID.randomUUID().toString(); } @@ -369,6 +370,10 @@ public Mode getMode() { return mode; } + public void setAccountId(long accountId) { + this.accountId = accountId; + } + @Override public long getAccountId() { return accountId; @@ -442,6 +447,7 @@ public String getGateway() { return gateway; } + @Override public void setGateway(String gateway) { this.gateway = gateway; } @@ -455,6 +461,7 @@ public String getCidr() { return cidr; } + @Override public void setCidr(String cidr) { this.cidr = cidr; } @@ -757,4 +764,13 @@ public Integer getPrivateMtu() { public void setPrivateMtu(Integer privateMtu) { this.privateMtu = privateMtu; } + + @Override + public Integer getNetworkCidrSize() { + return networkCidrSize; + } + + public void setNetworkCidrSize(Integer networkCidrSize) { + this.networkCidrSize = networkCidrSize; + } } diff --git a/server/src/main/java/com/cloud/api/query/dao/HostTagDao.java b/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDao.java similarity index 73% rename from server/src/main/java/com/cloud/api/query/dao/HostTagDao.java rename to engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDao.java index ab43e71221cf..0fc775377112 100644 --- a/server/src/main/java/com/cloud/api/query/dao/HostTagDao.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDao.java @@ -14,17 +14,17 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package com.cloud.api.query.dao; +package com.cloud.network.dao; -import java.util.List; +import com.cloud.network.element.NsxProviderVO; +import com.cloud.utils.db.GenericDao; -import org.apache.cloudstack.api.response.HostTagResponse; +import java.util.List; -import com.cloud.api.query.vo.HostTagVO; -import com.cloud.utils.db.GenericDao; +public interface NsxProviderDao extends GenericDao { + NsxProviderVO findByZoneId(long zoneId); -public interface HostTagDao extends GenericDao { - HostTagResponse newHostTagResponse(HostTagVO hostTag); + NsxProviderVO findByUuid(String uuid); - List searchByIds(Long... hostTagIds); + List findAll(); } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDaoImpl.java new file mode 100644 index 000000000000..cf7b5d405c00 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDaoImpl.java @@ -0,0 +1,65 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.dao; + +import com.cloud.network.element.NsxProviderVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@DB() +public class NsxProviderDaoImpl extends GenericDaoBase + implements NsxProviderDao { + + final SearchBuilder allFieldsSearch; + + public NsxProviderDaoImpl() { + super(); + allFieldsSearch = createSearchBuilder(); + allFieldsSearch.and("id", allFieldsSearch.entity().getId(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("uuid", allFieldsSearch.entity().getUuid(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("hostname", allFieldsSearch.entity().getHostname(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("provider_name", allFieldsSearch.entity().getProviderName(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("tier0_gateway", allFieldsSearch.entity().getTier0Gateway(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("zone_id", allFieldsSearch.entity().getZoneId(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("edge_cluster", allFieldsSearch.entity().getEdgeCluster(), + SearchCriteria.Op.EQ); + allFieldsSearch.done(); + } + @Override + public NsxProviderVO findByZoneId(long zoneId) { + SearchCriteria sc = allFieldsSearch.create(); + sc.setParameters("zone_id", zoneId); + return findOneBy(sc); + } + + @Override + public List findAll() { + return listAll(); + } +} diff --git a/engine/schema/src/main/java/com/cloud/network/dao/OpRouterMonitorServiceDao.java b/engine/schema/src/main/java/com/cloud/network/dao/OpRouterMonitorServiceDao.java index ebc0f1af2271..0516e26e13a7 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/OpRouterMonitorServiceDao.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/OpRouterMonitorServiceDao.java @@ -18,8 +18,12 @@ package com.cloud.network.dao; +import java.util.List; + import com.cloud.utils.db.GenericDao; public interface OpRouterMonitorServiceDao extends GenericDao { + int expungeByVmList(List vmIds, Long batchSize); + } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/OpRouterMonitorServiceDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/OpRouterMonitorServiceDaoImpl.java index 451320ac9b6c..a8e818cfb189 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/OpRouterMonitorServiceDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/OpRouterMonitorServiceDaoImpl.java @@ -17,10 +17,27 @@ package com.cloud.network.dao; -import com.cloud.utils.db.GenericDaoBase; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + @Component public class OpRouterMonitorServiceDaoImpl extends GenericDaoBase implements OpRouterMonitorServiceDao { + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/PortProfileDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/PortProfileDaoImpl.java index a90ce059c314..eb2a19681585 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/PortProfileDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/PortProfileDaoImpl.java @@ -22,7 +22,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.DB; @@ -36,7 +35,6 @@ @Component @DB() public class PortProfileDaoImpl extends GenericDaoBase implements PortProfileDao { - protected static final Logger s_logger = Logger.getLogger(PortProfileDaoImpl.class); final SearchBuilder nameSearch; final SearchBuilder accessVlanSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/RemoteAccessVpnDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/RemoteAccessVpnDaoImpl.java index 3aa2e749712e..484aa6f6631e 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/RemoteAccessVpnDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/RemoteAccessVpnDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.RemoteAccessVpn; @@ -29,7 +28,6 @@ @Component public class RemoteAccessVpnDaoImpl extends GenericDaoBase implements RemoteAccessVpnDao { - private static final Logger s_logger = Logger.getLogger(RemoteAccessVpnDaoImpl.class); private final SearchBuilder AllFieldsSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/RouterHealthCheckResultDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/RouterHealthCheckResultDaoImpl.java index 991365b5f540..b1292aebfd14 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/RouterHealthCheckResultDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/RouterHealthCheckResultDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -28,7 +27,6 @@ @Component public class RouterHealthCheckResultDaoImpl extends GenericDaoBase implements RouterHealthCheckResultDao { - private final static Logger s_logger = Logger.getLogger(RouterHealthCheckResultDaoImpl.class); private SearchBuilder RouterChecksSearchBuilder; private SearchBuilder IsRouterFailingSearchBuilder; @@ -69,7 +67,7 @@ public RouterHealthCheckResultVO getRouterHealthCheckResult(long routerId, Strin sc.setParameters("checkType", checkType); List checks = listBy(sc); if (checks.size() > 1) { - s_logger.error("Found multiple entries for router Id: " + routerId + ", check name: " + checkName); + logger.error("Found multiple entries for router Id: " + routerId + ", check name: " + checkName); } return checks.isEmpty() ? null : checks.get(0); } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java index b55f39ab31ba..f9c5ce089645 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java @@ -21,7 +21,6 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -31,7 +30,6 @@ @Component public class Site2SiteVpnConnectionDaoImpl extends GenericDaoBase implements Site2SiteVpnConnectionDao { - private static final Logger s_logger = Logger.getLogger(Site2SiteVpnConnectionDaoImpl.class); @Inject protected IPAddressDao _addrDao; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnGatewayDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnGatewayDaoImpl.java index 80465f9ee1e8..d1fde963217e 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnGatewayDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnGatewayDaoImpl.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -30,7 +29,6 @@ public class Site2SiteVpnGatewayDaoImpl extends GenericDaoBase AllFieldsSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/UserIpv6AddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/UserIpv6AddressDaoImpl.java index 08f0829f4acc..407d34fa3650 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/UserIpv6AddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/UserIpv6AddressDaoImpl.java @@ -20,7 +20,6 @@ import com.cloud.network.IpAddress; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.UserIpv6AddressVO; @@ -33,7 +32,6 @@ @Component public class UserIpv6AddressDaoImpl extends GenericDaoBase implements UserIpv6AddressDao { - private static final Logger s_logger = Logger.getLogger(IPAddressDaoImpl.class); protected final SearchBuilder AllFieldsSearch; protected GenericSearchBuilder CountFreePublicIps; diff --git a/engine/schema/src/main/java/com/cloud/network/element/NsxProviderVO.java b/engine/schema/src/main/java/com/cloud/network/element/NsxProviderVO.java new file mode 100644 index 000000000000..f08e08b1ca04 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/network/element/NsxProviderVO.java @@ -0,0 +1,285 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.element; + +import com.cloud.network.nsx.NsxProvider; +import com.cloud.utils.db.Encrypt; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; +import java.util.UUID; + +@Entity +@Table(name = "nsx_providers") +public class NsxProviderVO implements NsxProvider { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + long id; + + @Column(name = "zone_id") + private long zoneId; + + @Column(name = "host_id") + private long hostId; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "provider_name") + private String providerName; + + @Column(name = "hostname") + private String hostname; + + @Column(name = "port") + private String port = "443"; + + @Column(name = "username") + private String username; + + @Encrypt + @Column(name = "password") + private String password; + + @Column(name = "tier0_gateway") + private String tier0Gateway; + + @Column(name = "edge_cluster") + private String edgeCluster; + + @Column(name = "transport_zone") + private String transportZone; + + @Column(name = "created") + private Date created; + + @Column(name = "removed") + private Date removed; + public NsxProviderVO() { + this.uuid = UUID.randomUUID().toString(); + } + + @Override + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Override + public long getZoneId() { + return zoneId; + } + + public void setZoneId(long zoneId) { + this.zoneId = zoneId; + } + + public long getHostId() { + return hostId; + } + + public void setHostId(long hostId) { + this.hostId = hostId; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + @Override + public String getProviderName() { + return providerName; + } + + public void setProviderName(String providerName) { + this.providerName = providerName; + } + + @Override + public String getHostname() { + return hostname; + } + + public void setPort(String port) { + this.port = port; + } + + @Override + public String getPort() { + return port; + } + + public void setHostname(String hostname) { + this.hostname = hostname; + } + + @Override + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getTier0Gateway() { + return tier0Gateway; + } + + public void setTier0Gateway(String tier0Gateway) { + this.tier0Gateway = tier0Gateway; + } + + public String getEdgeCluster() { + return edgeCluster; + } + + public void setEdgeCluster(String edgeCluster) { + this.edgeCluster = edgeCluster; + } + + public String getTransportZone() { + return transportZone; + } + + public void setTransportZone(String transportZone) { + this.transportZone = transportZone; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public Date getRemoved() { + return removed; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public static final class Builder { + private long zoneId; + private long hostId; + private String providerName; + private String hostname; + private String port; + private String username; + private String password; + private String tier0Gateway; + private String edgeCluster; + private String transportZone; + + + public Builder() { + // Default constructor + } + + public Builder setZoneId(long zoneId) { + this.zoneId = zoneId; + return this; + } + + public Builder setHostId(long hostId) { + this.hostId = hostId; + return this; + } + + public Builder setProviderName(String providerName) { + this.providerName = providerName; + return this; + } + + public Builder setHostname(String hostname) { + this.hostname = hostname; + return this; + } + + public Builder setPort(String port) { + this.port = port; + return this; + } + + public Builder setUsername(String username) { + this.username = username; + return this; + } + + public Builder setPassword(String password) { + this.password = password; + return this; + } + + public Builder setTier0Gateway(String tier0Gateway) { + this.tier0Gateway = tier0Gateway; + return this; + } + + public Builder setEdgeCluster(String edgeCluster) { + this.edgeCluster = edgeCluster; + return this; + } + + public Builder setTransportZone(String transportZone) { + this.transportZone = transportZone; + return this; + } + public NsxProviderVO build() { + NsxProviderVO provider = new NsxProviderVO(); + provider.setZoneId(this.zoneId); + provider.setHostId(this.hostId); + provider.setUuid(UUID.randomUUID().toString()); + provider.setProviderName(this.providerName); + provider.setHostname(this.hostname); + provider.setPort(this.port); + provider.setUsername(this.username); + provider.setPassword(this.password); + provider.setTier0Gateway(this.tier0Gateway); + provider.setEdgeCluster(this.edgeCluster); + provider.setTransportZone(this.transportZone); + provider.setCreated(new Date()); + return provider; + } + } +} diff --git a/engine/schema/src/main/java/com/cloud/network/rules/dao/PortForwardingRulesDao.java b/engine/schema/src/main/java/com/cloud/network/rules/dao/PortForwardingRulesDao.java index b89d04ad15a0..8cd114b7fc4f 100644 --- a/engine/schema/src/main/java/com/cloud/network/rules/dao/PortForwardingRulesDao.java +++ b/engine/schema/src/main/java/com/cloud/network/rules/dao/PortForwardingRulesDao.java @@ -47,4 +47,5 @@ public interface PortForwardingRulesDao extends GenericDao listByNetworkAndDestIpAddr(String ip4Address, long networkId); + int expungeByVmList(List vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java index 29cba516d720..3a404b3f2df3 100644 --- a/engine/schema/src/main/java/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/rules/dao/PortForwardingRulesDaoImpl.java @@ -20,6 +20,7 @@ import javax.inject.Inject; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.network.dao.FirewallRulesCidrsDao; @@ -170,4 +171,16 @@ public PortForwardingRuleVO findByIdAndIp(long id, String secondaryIp) { sc.setParameters("dstIp", secondaryIp); return findOneBy(sc); } + + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getVirtualMachineId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupWorkDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupWorkDaoImpl.java index 9b0bf088a147..327d12c759a7 100644 --- a/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupWorkDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupWorkDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.security.SecurityGroupWork; @@ -37,7 +36,6 @@ @Component public class SecurityGroupWorkDaoImpl extends GenericDaoBase implements SecurityGroupWorkDao { - private static final Logger s_logger = Logger.getLogger(SecurityGroupWorkDaoImpl.class); private final SearchBuilder VmIdTakenSearch; private final SearchBuilder VmIdSeqNumSearch; @@ -107,8 +105,8 @@ public SecurityGroupWorkVO take(long serverId) { final List vos = lockRows(sc, filter, true); if (vos.size() == 0) { txn.commit(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Security Group take: no work found"); + if (logger.isTraceEnabled()) { + logger.trace("Security Group take: no work found"); } return null; } @@ -117,8 +115,8 @@ public SecurityGroupWorkVO take(long serverId) { if (findByVmIdStep(work.getInstanceId(), Step.Processing) != null) { //ensure that there is no job in Processing state for the same VM processing = true; - if (s_logger.isTraceEnabled()) { - s_logger.trace("Security Group work take: found a job in Scheduled and Processing vmid=" + work.getInstanceId()); + if (logger.isTraceEnabled()) { + logger.trace("Security Group work take: found a job in Scheduled and Processing vmid=" + work.getInstanceId()); } } work.setServerId(serverId); diff --git a/engine/schema/src/main/java/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java index d4d4f606a9aa..9a9ca80bce59 100644 --- a/engine/schema/src/main/java/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/security/dao/VmRulesetLogDaoImpl.java @@ -26,7 +26,6 @@ import java.util.Set; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.security.VmRulesetLogVO; @@ -37,7 +36,6 @@ @Component public class VmRulesetLogDaoImpl extends GenericDaoBase implements VmRulesetLogDao { - protected static final Logger s_logger = Logger.getLogger(VmRulesetLogDaoImpl.class); private SearchBuilder VmIdSearch; private String InsertOrUpdateSQl = "INSERT INTO op_vm_ruleset_log (instance_id, created, logsequence) " + " VALUES(?, now(), 1) ON DUPLICATE KEY UPDATE logsequence=logsequence+1"; @@ -98,19 +96,19 @@ private int executeWithRetryOnDeadlock(TransactionLegacy txn, String pstmt, List } catch (SQLTransactionRollbackException e1) { if (i < maxTries - 1) { int delayMs = (i + 1) * 1000; - s_logger.debug("Caught a deadlock exception while inserting security group rule log, retrying in " + delayMs); + logger.debug("Caught a deadlock exception while inserting security group rule log, retrying in " + delayMs); try { Thread.sleep(delayMs); } catch (InterruptedException ie) { - s_logger.debug("[ignored] interrupted while inserting security group rule log."); + logger.debug("[ignored] interrupted while inserting security group rule log."); } } else - s_logger.warn("Caught another deadlock exception while retrying inserting security group rule log, giving up"); + logger.warn("Caught another deadlock exception while retrying inserting security group rule log, giving up"); } } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Inserted or updated " + numUpdated + " rows"); + if (logger.isTraceEnabled()) { + logger.trace("Inserted or updated " + numUpdated + " rows"); } return numUpdated; } @@ -134,8 +132,8 @@ protected int createOrUpdateUsingMultiInsert(Set workItems) { vmIds.add(vmId); } int numUpdated = executeWithRetryOnDeadlock(txn, pstmt, vmIds); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Inserted or updated " + numUpdated + " rows"); + if (logger.isTraceEnabled()) { + logger.trace("Inserted or updated " + numUpdated + " rows"); } if (numUpdated > 0) count += stmtSize; @@ -145,7 +143,7 @@ protected int createOrUpdateUsingMultiInsert(Set workItems) { } } catch (SQLException sqe) { - s_logger.warn("Failed to execute multi insert ", sqe); + logger.warn("Failed to execute multi insert ", sqe); } return count; @@ -173,10 +171,10 @@ protected int createOrUpdateUsingBatch(Set workItems) { queryResult = stmtInsert.executeBatch(); txn.commit(); - if (s_logger.isTraceEnabled()) - s_logger.trace("Updated or inserted " + workItems.size() + " log items"); + if (logger.isTraceEnabled()) + logger.trace("Updated or inserted " + workItems.size() + " log items"); } catch (SQLException e) { - s_logger.warn("Failed to execute batch update statement for ruleset log: ", e); + logger.warn("Failed to execute batch update statement for ruleset log: ", e); txn.rollback(); success = false; } @@ -185,7 +183,7 @@ protected int createOrUpdateUsingBatch(Set workItems) { workItems.toArray(arrayItems); for (int i = 0; i < queryResult.length; i++) { if (queryResult[i] < 0) { - s_logger.debug("Batch query update failed for vm " + arrayItems[i]); + logger.debug("Batch query update failed for vm " + arrayItems[i]); } } } diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java b/engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java index aa26f16568a9..41254ba4a8ba 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java @@ -28,6 +28,7 @@ import javax.persistence.Id; import javax.persistence.Table; +import com.cloud.offering.NetworkOffering; import com.cloud.utils.db.GenericDao; @Entity @@ -58,6 +59,12 @@ public class VpcOfferingVO implements VpcOffering { @Column(name = "default") boolean isDefault = false; + @Column(name = "for_nsx") + boolean forNsx = false; + + @Column(name = "network_mode") + NetworkOffering.NetworkMode networkMode; + @Column(name = GenericDao.REMOVED_COLUMN) Date removed; @@ -79,6 +86,13 @@ public class VpcOfferingVO implements VpcOffering { @Column(name = "sort_key") int sortKey; + @Column(name="routing_mode") + @Enumerated(value = EnumType.STRING) + private NetworkOffering.RoutingMode routingMode; + + @Column(name = "specify_as_number") + private Boolean specifyAsNumber = false; + public VpcOfferingVO() { this.uuid = UUID.randomUUID().toString(); } @@ -144,6 +158,22 @@ public boolean isDefault() { return isDefault; } + public boolean isForNsx() { + return forNsx; + } + + public void setForNsx(boolean forNsx) { + this.forNsx = forNsx; + } + + public NetworkOffering.NetworkMode getNetworkMode() { + return networkMode; + } + + public void setNetworkMode(NetworkOffering.NetworkMode networkMode) { + this.networkMode = networkMode; + } + public void setUniqueName(String uniqueName) { this.uniqueName = uniqueName; } @@ -204,4 +234,21 @@ public int getSortKey() { return sortKey; } + @Override + public NetworkOffering.RoutingMode getRoutingMode() { + return routingMode; + } + + public void setRoutingMode(NetworkOffering.RoutingMode routingMode) { + this.routingMode = routingMode; + } + + @Override + public Boolean isSpecifyAsNumber() { + return specifyAsNumber; + } + + public void setSpecifyAsNumber(Boolean specifyAsNumber) { + this.specifyAsNumber = specifyAsNumber; + } } diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/VpcVO.java b/engine/schema/src/main/java/com/cloud/network/vpc/VpcVO.java index c2024e06c51b..27d8227284b1 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/VpcVO.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/VpcVO.java @@ -159,6 +159,10 @@ public String getCidr() { return cidr; } + public void setCidr(String cidr) { + this.cidr = cidr; + } + @Override public long getDomainId() { return domainId; diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/dao/NetworkACLItemCidrsDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/vpc/dao/NetworkACLItemCidrsDaoImpl.java index 4501f1493b57..1eb6482dd3af 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/dao/NetworkACLItemCidrsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/dao/NetworkACLItemCidrsDaoImpl.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.vpc.NetworkACLItemCidrsDao; @@ -37,7 +36,6 @@ */ @Component public class NetworkACLItemCidrsDaoImpl extends GenericDaoBase implements NetworkACLItemCidrsDao { - private static final Logger s_logger = Logger.getLogger(NetworkACLItemCidrsDaoImpl.class); protected final SearchBuilder cidrsSearch; protected NetworkACLItemCidrsDaoImpl() { diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java index 8b090fdfbc84..47b91b24c279 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.vpc.PrivateIpVO; @@ -36,7 +35,6 @@ @Component @DB() public class PrivateIpDaoImpl extends GenericDaoBase implements PrivateIpDao { - private static final Logger s_logger = Logger.getLogger(PrivateIpDaoImpl.class); private final SearchBuilder AllFieldsSearch; private final GenericSearchBuilder CountAllocatedByNetworkId; @@ -90,8 +88,8 @@ public PrivateIpVO allocateIpAddress(long dcId, long networkId, String requested @Override public void releaseIpAddress(String ipAddress, long networkId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing private ip address: " + ipAddress + " network id " + networkId); + if (logger.isDebugEnabled()) { + logger.debug("Releasing private ip address: " + ipAddress + " network id " + networkId); } SearchCriteria sc = AllFieldsSearch.create(); sc.setParameters("ip", ipAddress); diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/dao/VpcOfferingDao.java b/engine/schema/src/main/java/com/cloud/network/vpc/dao/VpcOfferingDao.java index 264a1ebc75e8..aa17723f0b17 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/dao/VpcOfferingDao.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/dao/VpcOfferingDao.java @@ -33,4 +33,6 @@ public interface VpcOfferingDao extends GenericDao { NetUtils.InternetProtocol getVpcOfferingInternetProtocol(long offeringId); boolean isIpv6Supported(long offeringId); + + boolean isRoutedVpc(long offeringId); } diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/dao/VpcOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/vpc/dao/VpcOfferingDaoImpl.java index 1cc6a21da76c..b83fd8913059 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/dao/VpcOfferingDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/dao/VpcOfferingDaoImpl.java @@ -19,6 +19,7 @@ import javax.inject.Inject; +import com.cloud.offering.NetworkOffering; import org.apache.cloudstack.api.ApiConstants; import org.springframework.stereotype.Component; @@ -84,4 +85,9 @@ public boolean isIpv6Supported(long offeringId) { NetUtils.InternetProtocol internetProtocol = getVpcOfferingInternetProtocol(offeringId); return NetUtils.InternetProtocol.isIpv6EnabledProtocol(internetProtocol); } + + @Override + public boolean isRoutedVpc(long offeringId) { + return NetworkOffering.NetworkMode.ROUTED.equals(findById(offeringId).getNetworkMode()); + } } diff --git a/engine/schema/src/main/java/com/cloud/offerings/NetworkOfferingVO.java b/engine/schema/src/main/java/com/cloud/offerings/NetworkOfferingVO.java index ae5e6fb95ea9..0bf110757d7c 100644 --- a/engine/schema/src/main/java/com/cloud/offerings/NetworkOfferingVO.java +++ b/engine/schema/src/main/java/com/cloud/offerings/NetworkOfferingVO.java @@ -136,6 +136,12 @@ public class NetworkOfferingVO implements NetworkOffering { @Column(name = "for_tungsten") boolean forTungsten = false; + @Column(name = "for_nsx") + boolean forNsx = false; + + @Column(name = "network_mode") + NetworkMode networkMode; + @Column(name = "egress_default_policy") boolean egressdefaultpolicy; @@ -168,6 +174,13 @@ public String getDisplayText() { @Column(name="service_package_id") String servicePackageUuid = null; + @Column(name="routing_mode") + @Enumerated(value = EnumType.STRING) + private RoutingMode routingMode; + + @Column(name = "specify_as_number") + private Boolean specifyAsNumber = false; + @Override public boolean isKeepAliveEnabled() { return keepAliveEnabled; @@ -195,6 +208,24 @@ public void setForTungsten(boolean forTungsten) { this.forTungsten = forTungsten; } + @Override + public boolean isForNsx() { + return forNsx; + } + + public void setForNsx(boolean forNsx) { + this.forNsx = forNsx; + } + + @Override + public NetworkMode getNetworkMode() { + return networkMode; + } + + public void setNetworkMode(NetworkMode networkMode) { + this.networkMode = networkMode; + } + @Override public long getId() { return id; @@ -558,4 +589,21 @@ public void setSupportsVmAutoScaling(boolean supportsVmAutoScaling) { public boolean isSupportsVmAutoScaling() { return supportsVmAutoScaling; } + + @Override + public RoutingMode getRoutingMode() { + return routingMode; + } + + public void setRoutingMode(RoutingMode routingMode) { + this.routingMode = routingMode; + } + + public Boolean isSpecifyAsNumber() { + return specifyAsNumber; + } + + public void setSpecifyAsNumber(Boolean specifyAsNumber) { + this.specifyAsNumber = specifyAsNumber; + } } diff --git a/engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDao.java b/engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDao.java index 381d2144df16..abb63a10d065 100644 --- a/engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDao.java +++ b/engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDao.java @@ -76,4 +76,6 @@ public interface NetworkOfferingDao extends GenericDao NetUtils.InternetProtocol getNetworkOfferingInternetProtocol(long offeringId, NetUtils.InternetProtocol defaultProtocol); boolean isIpv6Supported(long offeringId); + + boolean isRoutedNetwork(long offeringId); } diff --git a/engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java index 823ea36b97f5..9bc74b139320 100644 --- a/engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java @@ -292,4 +292,9 @@ public boolean isIpv6Supported(long offeringId) { NetUtils.InternetProtocol internetProtocol = getNetworkOfferingInternetProtocol(offeringId); return NetUtils.InternetProtocol.isIpv6EnabledProtocol(internetProtocol); } + + @Override + public boolean isRoutedNetwork(long offeringId) { + return NetworkOffering.NetworkMode.ROUTED.equals(findById(offeringId).getNetworkMode()); + } } diff --git a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java index d2ba49e9408b..8947cc600b38 100644 --- a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java @@ -18,7 +18,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.projects.ProjectAccount; @@ -39,7 +38,6 @@ public class ProjectAccountDaoImpl extends GenericDaoBase ProjectAccountsSearch; final GenericSearchBuilder CountByRoleSearch; - public static final Logger s_logger = Logger.getLogger(ProjectAccountDaoImpl.class.getName()); protected ProjectAccountDaoImpl() { AllFieldsSearch = createSearchBuilder(); @@ -190,7 +188,7 @@ public void removeAccountFromProjects(long accountId) { int rowsRemoved = remove(sc); if (rowsRemoved > 0) { - s_logger.debug("Removed account id=" + accountId + " from " + rowsRemoved + " projects"); + logger.debug("Removed account id=" + accountId + " from " + rowsRemoved + " projects"); } } diff --git a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectDaoImpl.java b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectDaoImpl.java index 5deb85861208..46bf36ae397b 100644 --- a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectDaoImpl.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.projects.Project; @@ -36,7 +35,6 @@ @Component public class ProjectDaoImpl extends GenericDaoBase implements ProjectDao { - private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class); protected final SearchBuilder AllFieldsSearch; protected GenericSearchBuilder CountByDomain; protected GenericSearchBuilder ProjectAccountSearch; diff --git a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectInvitationDaoImpl.java b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectInvitationDaoImpl.java index f8d153740ab7..d30b1c9f1f10 100644 --- a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectInvitationDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectInvitationDaoImpl.java @@ -19,7 +19,6 @@ import java.sql.Date; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.projects.ProjectInvitation.State; @@ -31,7 +30,6 @@ @Component public class ProjectInvitationDaoImpl extends GenericDaoBase implements ProjectInvitationDao { - private static final Logger s_logger = Logger.getLogger(ProjectInvitationDaoImpl.class); protected final SearchBuilder AllFieldsSearch; protected final SearchBuilder InactiveSearch; protected final SearchBuilder ProjectAccountInviteSearch; @@ -111,7 +109,7 @@ public boolean expirePendingInvitations(long timeout) { for (ProjectInvitationVO invitationToExpire : invitationsToExpire) { invitationToExpire.setState(State.Expired); if (!update(invitationToExpire.getId(), invitationToExpire)) { - s_logger.warn("Fail to expire invitation " + invitationToExpire.toString()); + logger.warn("Fail to expire invitation " + invitationToExpire.toString()); success = false; } } @@ -133,7 +131,7 @@ public boolean isActive(long id, long timeout) { sc.setParameters("id", id); if (findOneBy(sc) == null) { - s_logger.warn("Unable to find project invitation by id " + id); + logger.warn("Unable to find project invitation by id " + id); return false; } @@ -185,7 +183,7 @@ public void cleanupInvitations(long projectId) { sc.setParameters("projectId", projectId); int numberRemoved = remove(sc); - s_logger.debug("Removed " + numberRemoved + " invitations for project id=" + projectId); + logger.debug("Removed " + numberRemoved + " invitations for project id=" + projectId); } } diff --git a/engine/schema/src/main/java/com/cloud/resource/icon/dao/ResourceIconDaoImpl.java b/engine/schema/src/main/java/com/cloud/resource/icon/dao/ResourceIconDaoImpl.java index 41eba40c01f5..1ae01bfc1ec2 100644 --- a/engine/schema/src/main/java/com/cloud/resource/icon/dao/ResourceIconDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/resource/icon/dao/ResourceIconDaoImpl.java @@ -24,13 +24,11 @@ import com.cloud.utils.db.SearchCriteria; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; public class ResourceIconDaoImpl extends GenericDaoBase implements ResourceIconDao { - public static final Logger s_logger = Logger.getLogger(ResourceIconDaoImpl.class); private final SearchBuilder AllFieldsSearch; protected ResourceIconDaoImpl() { diff --git a/engine/schema/src/main/java/com/cloud/secstorage/CommandExecLogDao.java b/engine/schema/src/main/java/com/cloud/secstorage/CommandExecLogDao.java index 98fc8c8687b8..5023aaa3794c 100644 --- a/engine/schema/src/main/java/com/cloud/secstorage/CommandExecLogDao.java +++ b/engine/schema/src/main/java/com/cloud/secstorage/CommandExecLogDao.java @@ -17,10 +17,12 @@ package com.cloud.secstorage; import java.util.Date; +import java.util.List; import com.cloud.utils.db.GenericDao; public interface CommandExecLogDao extends GenericDao { public void expungeExpiredRecords(Date cutTime); public Integer getCopyCmdCountForSSVM(Long id); + int expungeByVmList(List vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/secstorage/CommandExecLogDaoImpl.java b/engine/schema/src/main/java/com/cloud/secstorage/CommandExecLogDaoImpl.java index f89a1bbf4ccb..a37acdf60298 100644 --- a/engine/schema/src/main/java/com/cloud/secstorage/CommandExecLogDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/secstorage/CommandExecLogDaoImpl.java @@ -19,6 +19,7 @@ import java.util.Date; import java.util.List; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -57,4 +58,16 @@ public Integer getCopyCmdCountForSSVM(Long id) { List copyCmds = customSearch(sc, null); return copyCmds.size(); } + + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getInstanceId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDao.java b/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDao.java index 3b6fa8fa1033..48e63d8e2b55 100644 --- a/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDao.java +++ b/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDao.java @@ -54,5 +54,7 @@ List createSystemServiceOfferings(String name, String uniqueN List listPublicByCpuAndMemory(Integer cpus, Integer memory); + List listByHostTag(String tag); + ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(long diskOfferingId, boolean includingRemoved); } diff --git a/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDaoImpl.java index ef6d4e719899..706dcdc1b7b5 100644 --- a/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/service/dao/ServiceOfferingDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.dao.DiskOfferingDao; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.event.UsageEventVO; @@ -44,7 +43,6 @@ @Component @DB() public class ServiceOfferingDaoImpl extends GenericDaoBase implements ServiceOfferingDao { - protected static final Logger s_logger = Logger.getLogger(ServiceOfferingDaoImpl.class); @Inject protected ServiceOfferingDetailsDao detailsDao; @@ -268,7 +266,7 @@ public ServiceOfferingVO findDefaultSystemOffering(String offeringName, Boolean ServiceOfferingVO serviceOffering = findByName(name); if (serviceOffering == null) { String message = "System service offering " + name + " not found"; - s_logger.error(message); + logger.error(message); throw new CloudRuntimeException(message); } return serviceOffering; @@ -293,4 +291,22 @@ public ServiceOfferingVO findServiceOfferingByComputeOnlyDiskOffering(long diskO } return vos.get(0); } + + @Override + public List listByHostTag(String tag) { + SearchBuilder sb = createSearchBuilder(); + sb.and("tagNotNull", sb.entity().getHostTag(), SearchCriteria.Op.NNULL); + sb.and().op("tagEq", sb.entity().getHostTag(), SearchCriteria.Op.EQ); + sb.or("tagStartLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE); + sb.or("tagMidLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE); + sb.or("tagEndLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE); + sb.cp(); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("tagEq", tag); + sc.setParameters("tagStartLike", tag + ",%"); + sc.setParameters("tagMidLike", "%," + tag + ",%"); + sc.setParameters("tagEndLike", "%," + tag); + return listBy(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/storage/BucketVO.java b/engine/schema/src/main/java/com/cloud/storage/BucketVO.java index 181b02e5a1b0..53017447c078 100644 --- a/engine/schema/src/main/java/com/cloud/storage/BucketVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/BucketVO.java @@ -97,17 +97,23 @@ public class BucketVO implements Bucket { String uuid; public BucketVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public BucketVO(String name) { + this.uuid = UUID.randomUUID().toString(); + this.name = name; + this.state = State.Allocated; } public BucketVO(long accountId, long domainId, long objectStoreId, String name, Integer quota, boolean versioning, - boolean encryption, boolean objectLock, String policy) - { + boolean encryption, boolean objectLock, String policy) { this.accountId = accountId; this.domainId = domainId; this.objectStoreId = objectStoreId; this.name = name; - state = State.Allocated; - uuid = UUID.randomUUID().toString(); + this.state = State.Allocated; + this.uuid = UUID.randomUUID().toString(); this.quota = quota; this.versioning = versioning; this.encryption = encryption; diff --git a/engine/schema/src/main/java/com/cloud/storage/GuestOSHypervisorVO.java b/engine/schema/src/main/java/com/cloud/storage/GuestOSHypervisorVO.java index e900d28a8641..cae1e1b7eeed 100644 --- a/engine/schema/src/main/java/com/cloud/storage/GuestOSHypervisorVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/GuestOSHypervisorVO.java @@ -20,6 +20,7 @@ import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -28,6 +29,7 @@ import com.cloud.hypervisor.Hypervisor; import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.util.HypervisorTypeConverter; @Entity @Table(name = "guest_os_hypervisor") @@ -44,6 +46,7 @@ public class GuestOSHypervisorVO implements GuestOSHypervisor { String guestOsName; @Column(name = "hypervisor_type") + @Convert(converter = HypervisorTypeConverter.class) String hypervisorType; @Column(name = "hypervisor_version") diff --git a/engine/schema/src/main/java/com/cloud/storage/SnapshotScheduleVO.java b/engine/schema/src/main/java/com/cloud/storage/SnapshotScheduleVO.java index 80a890aacad6..86e0da53666f 100644 --- a/engine/schema/src/main/java/com/cloud/storage/SnapshotScheduleVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/SnapshotScheduleVO.java @@ -29,6 +29,8 @@ import javax.persistence.TemporalType; import com.cloud.storage.snapshot.SnapshotSchedule; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; @Entity @Table(name = "snapshot_schedule") @@ -132,4 +134,11 @@ public String getUuid() { public void setUuid(String uuid) { this.uuid = uuid; } + + @Override + public String toString() { + ReflectionToStringBuilder reflectionToStringBuilder = new ReflectionToStringBuilder(this, ToStringStyle.JSON_STYLE); + reflectionToStringBuilder.setExcludeFieldNames("id"); + return reflectionToStringBuilder.toString(); + } } diff --git a/engine/schema/src/main/java/com/cloud/storage/SnapshotVO.java b/engine/schema/src/main/java/com/cloud/storage/SnapshotVO.java index e9d6df85c2f2..39d2cdd0b773 100644 --- a/engine/schema/src/main/java/com/cloud/storage/SnapshotVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/SnapshotVO.java @@ -20,6 +20,7 @@ import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -28,6 +29,7 @@ import javax.persistence.Id; import javax.persistence.Table; +import org.apache.cloudstack.util.HypervisorTypeConverter; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -89,7 +91,7 @@ public class SnapshotVO implements Snapshot { Date removed; @Column(name = "hypervisor_type") - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) HypervisorType hypervisorType; @Expose diff --git a/engine/schema/src/main/java/com/cloud/storage/VMTemplateVO.java b/engine/schema/src/main/java/com/cloud/storage/VMTemplateVO.java index 44e4dc920abf..9dc9734f8ab3 100644 --- a/engine/schema/src/main/java/com/cloud/storage/VMTemplateVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/VMTemplateVO.java @@ -21,6 +21,7 @@ import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -31,7 +32,10 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; +import com.cloud.cpu.CPU; import com.cloud.user.UserData; +import org.apache.cloudstack.util.CPUArchConverter; +import org.apache.cloudstack.util.HypervisorTypeConverter; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -108,7 +112,7 @@ public class VMTemplateVO implements VirtualMachineTemplate { private boolean crossZones = false; @Column(name = "hypervisor_type") - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) private HypervisorType hypervisorType; @Column(name = "extractable") @@ -165,6 +169,10 @@ public class VMTemplateVO implements VirtualMachineTemplate { @Enumerated(value = EnumType.STRING) UserData.UserDataOverridePolicy userDataLinkPolicy; + @Column(name = "arch") + @Convert(converter = CPUArchConverter.class) + private CPU.CPUArch arch; + @Override public String getUniqueName() { return uniqueName; @@ -207,7 +215,7 @@ private VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType, String templateTag, Map details, boolean sshKeyEnabled, boolean isDynamicallyScalable, boolean directDownload, - boolean deployAsIs) { + boolean deployAsIs, CPU.CPUArch arch) { this(id, name, format, @@ -233,6 +241,7 @@ public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, state = State.Active; this.directDownload = directDownload; this.deployAsIs = deployAsIs; + this.arch = arch; } public static VMTemplateVO createPreHostIso(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, TemplateType type, @@ -671,4 +680,13 @@ public void setUserDataLinkPolicy(UserData.UserDataOverridePolicy userDataLinkPo this.userDataLinkPolicy = userDataLinkPolicy; } + @Override + public CPU.CPUArch getArch() { + return arch; + } + + public void setArch(CPU.CPUArch arch) { + this.arch = arch; + } + } diff --git a/engine/schema/src/main/java/com/cloud/storage/VolumeVO.java b/engine/schema/src/main/java/com/cloud/storage/VolumeVO.java index 0bd71ea6d866..c105acf40b8d 100644 --- a/engine/schema/src/main/java/com/cloud/storage/VolumeVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/VolumeVO.java @@ -20,6 +20,7 @@ import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -32,6 +33,7 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; +import com.cloud.util.StoragePoolTypeConverter; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import com.cloud.storage.Storage.ProvisioningType; @@ -114,7 +116,7 @@ public class VolumeVO implements Volume { Type volumeType = Volume.Type.UNKNOWN; @Column(name = "pool_type") - @Enumerated(EnumType.STRING) + @Convert(converter = StoragePoolTypeConverter.class) StoragePoolType poolType; @Column(name = GenericDao.REMOVED_COLUMN) @@ -180,6 +182,10 @@ public class VolumeVO implements Volume { @Column(name = "encrypt_format") private String encryptFormat; + @Column(name = "delete_protection") + private boolean deleteProtection; + + // Real Constructor public VolumeVO(Type type, String name, long dcId, long domainId, long accountId, long diskOfferingId, Storage.ProvisioningType provisioningType, long size, @@ -331,9 +337,7 @@ public void setPoolType(StoragePoolType poolType) { this.poolType = poolType; } - public StoragePoolType getPoolType() { - return poolType; - } + public StoragePoolType getPoolType() { return poolType; } @Override public long getDomainId() { @@ -677,4 +681,13 @@ public void setExternalUuid(String externalUuid) { public String getEncryptFormat() { return encryptFormat; } public void setEncryptFormat(String encryptFormat) { this.encryptFormat = encryptFormat; } + + @Override + public boolean isDeleteProtection() { + return deleteProtection; + } + + public void setDeleteProtection(boolean deleteProtection) { + this.deleteProtection = deleteProtection; + } } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/BucketDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/BucketDaoImpl.java index 83b5f6bdb747..98bef6201a15 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/BucketDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/BucketDaoImpl.java @@ -20,7 +20,6 @@ import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import javax.naming.ConfigurationException; @@ -29,7 +28,6 @@ @Component public class BucketDaoImpl extends GenericDaoBase implements BucketDao { - public static final Logger s_logger = Logger.getLogger(BucketDaoImpl.class.getName()); private SearchBuilder searchFilteringStoreId; private SearchBuilder bucketSearch; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java index 5a49d0b5192f..f726bca3c5d6 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java @@ -31,5 +31,6 @@ public interface DiskOfferingDao extends GenericDao { List listAllBySizeAndProvisioningType(long size, Storage.ProvisioningType provisioningType); List findCustomDiskOfferings(); + List listByStorageTag(String tag); } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java index d04353ec480b..93e747662775 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java @@ -146,4 +146,22 @@ public boolean remove(Long id) { return update(id, diskOffering); } + + @Override + public List listByStorageTag(String tag) { + SearchBuilder sb = createSearchBuilder(); + sb.and("tagNotNull", sb.entity().getTags(), SearchCriteria.Op.NNULL); + sb.and().op("tagEq", sb.entity().getTags(), SearchCriteria.Op.EQ); + sb.or("tagStartLike", sb.entity().getTags(), SearchCriteria.Op.LIKE); + sb.or("tagMidLike", sb.entity().getTags(), SearchCriteria.Op.LIKE); + sb.or("tagEndLike", sb.entity().getTags(), SearchCriteria.Op.LIKE); + sb.cp(); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("tagEq", tag); + sc.setParameters("tagStartLike", tag + ",%"); + sc.setParameters("tagMidLike", "%," + tag + ",%"); + sc.setParameters("tagEndLike", "%," + tag); + return listBy(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java index 69f4d4a3ceb0..1aaa277a358b 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.utils.CloudStackVersion; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.hypervisor.Hypervisor; @@ -35,7 +34,6 @@ @Component public class GuestOSHypervisorDaoImpl extends GenericDaoBase implements GuestOSHypervisorDao { - private static final Logger s_logger = Logger.getLogger(GuestOSHypervisorDaoImpl.class); protected final SearchBuilder guestOsSearch; protected final SearchBuilder mappingSearch; @@ -92,14 +90,14 @@ private GuestOSHypervisorVO getMappingForHypervisorVersionOrParentVersionIfNeede String guestOs = guestOsId != null ? String.format("guest OS ID: %d", guestOsId) : String.format("guest OS ID: %s", guestOsName); String parentVersion = CloudStackVersion.getVMwareParentVersion(hypervisorVersion); if (parentVersion == null) { - if (s_logger.isDebugEnabled()) { - s_logger.info(String.format("Mapping for %s for hypervisor: %s with version: %s can not be found. Parent version is also null", + if (logger.isDebugEnabled()) { + logger.info(String.format("Mapping for %s for hypervisor: %s with version: %s can not be found. Parent version is also null", guestOs, hypervisorType, hypervisorVersion)); } return null; } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Mapping for %s for hypervisor: %s with version: %s can not be found. " + + if (logger.isDebugEnabled()) { + logger.debug(String.format("Mapping for %s for hypervisor: %s with version: %s can not be found. " + "Trying to find one for the parent version: %s", guestOs, hypervisorType, hypervisorVersion, parentVersion)); } return guestOsId != null ? diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/LaunchPermissionDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/LaunchPermissionDaoImpl.java index ec1a3a267c60..b4fdb4b6394e 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/LaunchPermissionDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/LaunchPermissionDaoImpl.java @@ -23,7 +23,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.storage.LaunchPermissionVO; @@ -39,7 +38,6 @@ @Component public class LaunchPermissionDaoImpl extends GenericDaoBase implements LaunchPermissionDao { - private static final Logger s_logger = Logger.getLogger(LaunchPermissionDaoImpl.class); private static final String REMOVE_LAUNCH_PERMISSION = "DELETE FROM `cloud`.`launch_permission`" + " WHERE template_id = ? AND account_id = ?"; private static final String LIST_PERMITTED_TEMPLATES = @@ -80,7 +78,7 @@ public void removePermissions(long templateId, List accountIds) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error removing launch permissions", e); + logger.warn("Error removing launch permissions", e); throw new CloudRuntimeException("Error removing launch permissions", e); } } @@ -145,7 +143,7 @@ public List listPermittedTemplates(long accountId) { permittedTemplates.add(template); } } catch (Exception e) { - s_logger.warn("Error listing permitted templates", e); + logger.warn("Error listing permitted templates", e); } return permittedTemplates; } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDao.java index 998d0bbd724c..171634fb1044 100755 --- a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDao.java @@ -57,4 +57,5 @@ public interface SnapshotDao extends GenericDao, StateDao listByIds(Object... ids); + List searchByVolumes(List volumeIds); } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDaoImpl.java index f5ebf4bcf3d0..f5fc9c47d036 100755 --- a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDaoImpl.java @@ -18,12 +18,13 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.util.ArrayList; import java.util.List; import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.server.ResourceTag.ResourceObjectType; @@ -51,7 +52,6 @@ @Component public class SnapshotDaoImpl extends GenericDaoBase implements SnapshotDao { - public static final Logger s_logger = Logger.getLogger(SnapshotDaoImpl.class.getName()); // TODO: we should remove these direct sqls private static final String GET_LAST_SNAPSHOT = "SELECT snapshots.id FROM snapshot_store_ref, snapshots where snapshots.id = snapshot_store_ref.snapshot_id AND snapshosts.volume_id = ? AND snapshot_store_ref.role = ? ORDER BY created DESC"; @@ -197,7 +197,7 @@ public long getLastSnapshot(long volumeId, DataStoreRole role) { return rs.getLong(1); } } catch (Exception ex) { - s_logger.error("error getting last snapshot", ex); + logger.error("error getting last snapshot", ex); } return 0; } @@ -287,4 +287,16 @@ public List listByStatusNotIn(long volumeId, Snapshot.State... statu sc.setParameters("status", (Object[]) status); return listBy(sc, null); } + + @Override + public List searchByVolumes(List volumeIds) { + if (CollectionUtils.isEmpty(volumeIds)) { + return new ArrayList<>(); + } + SearchBuilder sb = createSearchBuilder(); + sb.and("volumeIds", sb.entity().getVolumeId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("volumeIds", volumeIds.toArray()); + return search(sc, null); + } } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotScheduleDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotScheduleDao.java index 7ca0a3915f54..284a42cf9e1d 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotScheduleDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotScheduleDao.java @@ -27,13 +27,11 @@ */ public interface SnapshotScheduleDao extends GenericDao { - List getCoincidingSnapshotSchedules(long volumeId, Date date); - List getSchedulesToExecute(Date currentTimestamp); - SnapshotScheduleVO getCurrentSchedule(Long volumeId, Long policyId, boolean executing); + List getSchedulesAssignedWithAsyncJob(); - SnapshotScheduleVO findOneByVolume(long volumeId); + SnapshotScheduleVO getCurrentSchedule(Long volumeId, Long policyId, boolean executing); SnapshotScheduleVO findOneByVolumePolicy(long volumeId, long policyId); diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotScheduleDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotScheduleDaoImpl.java index 925d02dd90b4..14669ce1d438 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotScheduleDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotScheduleDaoImpl.java @@ -32,7 +32,7 @@ public class SnapshotScheduleDaoImpl extends GenericDaoBase implements SnapshotScheduleDao { protected final SearchBuilder executableSchedulesSearch; protected final SearchBuilder coincidingSchedulesSearch; - private final SearchBuilder VolumeIdSearch; + protected final SearchBuilder schedulesAssignedWithAsyncJob; private final SearchBuilder VolumeIdPolicyIdSearch; protected SnapshotScheduleDaoImpl() { @@ -48,36 +48,14 @@ protected SnapshotScheduleDaoImpl() { coincidingSchedulesSearch.and("asyncJobId", coincidingSchedulesSearch.entity().getAsyncJobId(), SearchCriteria.Op.NULL); coincidingSchedulesSearch.done(); - VolumeIdSearch = createSearchBuilder(); - VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); - VolumeIdSearch.done(); - VolumeIdPolicyIdSearch = createSearchBuilder(); VolumeIdPolicyIdSearch.and("volumeId", VolumeIdPolicyIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); VolumeIdPolicyIdSearch.and("policyId", VolumeIdPolicyIdSearch.entity().getPolicyId(), SearchCriteria.Op.EQ); VolumeIdPolicyIdSearch.done(); - } - - /** - * {@inheritDoc} - */ - @Override - public List getCoincidingSnapshotSchedules(long volumeId, Date date) { - SearchCriteria sc = coincidingSchedulesSearch.create(); - sc.setParameters("volumeId", volumeId); - sc.setParameters("scheduledTimestamp", date); - // Don't return manual snapshots. They will be executed through another - // code path. - sc.addAnd("policyId", SearchCriteria.Op.NEQ, 1L); - return listBy(sc); - } - - @Override - public SnapshotScheduleVO findOneByVolume(long volumeId) { - SearchCriteria sc = VolumeIdSearch.create(); - sc.setParameters("volumeId", volumeId); - return findOneBy(sc); + schedulesAssignedWithAsyncJob = createSearchBuilder(); + schedulesAssignedWithAsyncJob.and("asyncJobId", schedulesAssignedWithAsyncJob.entity().getAsyncJobId(), SearchCriteria.Op.NNULL); + schedulesAssignedWithAsyncJob.done(); } @Override @@ -98,6 +76,11 @@ public List getSchedulesToExecute(Date currentTimestamp) { return listBy(sc); } + @Override + public List getSchedulesAssignedWithAsyncJob() { + return listBy(schedulesAssignedWithAsyncJob.create()); + } + /** * {@inheritDoc} */ diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotZoneDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotZoneDaoImpl.java index 1ed8a547a105..5f8ded6665bb 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotZoneDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotZoneDaoImpl.java @@ -20,7 +20,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.storage.SnapshotZoneVO; import com.cloud.utils.db.GenericDaoBase; @@ -28,7 +27,6 @@ import com.cloud.utils.db.SearchCriteria; public class SnapshotZoneDaoImpl extends GenericDaoBase implements SnapshotZoneDao { - public static final Logger s_logger = Logger.getLogger(SnapshotZoneDaoImpl.class.getName()); protected final SearchBuilder ZoneSnapshotSearch; public SnapshotZoneDaoImpl() { diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java index 0c39a8c581aa..376933f92e7c 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolDetailsDaoImpl.java @@ -17,6 +17,10 @@ package com.cloud.storage.dao; +import java.util.List; + +import javax.inject.Inject; + import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey.Scope; import org.apache.cloudstack.framework.config.ScopedConfigStorage; @@ -26,9 +30,6 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import javax.inject.Inject; -import java.util.List; - public class StoragePoolDetailsDaoImpl extends ResourceDetailsDaoBase implements StoragePoolDetailsDao, ScopedConfigStorage { @Inject @@ -43,8 +44,8 @@ public Scope getScope() { } @Override - public String getConfigValue(long id, ConfigKey key) { - StoragePoolDetailVO vo = findDetail(id, key.key()); + public String getConfigValue(long id, String key) { + StoragePoolDetailVO vo = findDetail(id, key); return vo == null ? null : vo.getValue(); } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolHostDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolHostDaoImpl.java index 03da0405142c..987a42f410e7 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolHostDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolHostDaoImpl.java @@ -26,7 +26,6 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.host.HostVO; @@ -42,7 +41,6 @@ @Component public class StoragePoolHostDaoImpl extends GenericDaoBase implements StoragePoolHostDao { - public static final Logger s_logger = Logger.getLogger(StoragePoolHostDaoImpl.class.getName()); protected final SearchBuilder PoolSearch; protected final SearchBuilder HostSearch; @@ -135,10 +133,10 @@ public List listByHostStatus(long poolId, Status hostStatus) result.add(findById(id)); } }catch (SQLException e) { - s_logger.warn("listByHostStatus:Exception: ", e); + logger.warn("listByHostStatus:Exception: ", e); } } catch (Exception e) { - s_logger.warn("listByHostStatus:Exception: ", e); + logger.warn("listByHostStatus:Exception: ", e); } return result; } @@ -161,10 +159,10 @@ public List findHostsConnectedToPools(List poolIds) { hosts.add(hostId); } } catch (SQLException e) { - s_logger.warn("findHostsConnectedToPools:Exception: ", e); + logger.warn("findHostsConnectedToPools:Exception: ", e); } } catch (Exception e) { - s_logger.warn("findHostsConnectedToPools:Exception: ", e); + logger.warn("findHostsConnectedToPools:Exception: ", e); } return hosts; @@ -185,7 +183,7 @@ public List> getDatacenterStoragePoolHostInfo(long dcId, boo l.add(new Pair(rs.getLong(1), rs.getInt(2))); } } catch (SQLException e) { - s_logger.debug("SQLException: ", e); + logger.debug("SQLException: ", e); } return l; } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java index 9352ee21858c..a4b87ef025f3 100755 --- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java @@ -34,5 +34,6 @@ public interface StoragePoolTagsDao extends GenericDao { StorageTagResponse newStorageTagResponse(StoragePoolTagVO tag); List findStoragePoolTags(long poolId); + List listPoolIdsByTag(String tag); } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java index c01c66763af1..c4d7ed886072 100755 --- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java @@ -18,12 +18,10 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.inject.Inject; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.db.TransactionCallbackNoReturn; -import com.cloud.utils.db.TransactionStatus; import org.apache.cloudstack.api.response.StorageTagResponse; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; @@ -31,7 +29,10 @@ import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallbackNoReturn; import com.cloud.utils.db.TransactionLegacy; +import com.cloud.utils.db.TransactionStatus; public class StoragePoolTagsDaoImpl extends GenericDaoBase implements StoragePoolTagsDao { @@ -178,4 +179,15 @@ public List findStoragePoolTags(long poolId) { return search(sc, null); } + @Override + public List listPoolIdsByTag(String tag) { + SearchBuilder sb = createSearchBuilder(); + sb.and("tag", sb.entity().getTag(), SearchCriteria.Op.EQ); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("tag", tag); + List poolRefs = search(sc, null); + return poolRefs.stream().map(StoragePoolTagVO::getPoolId).collect(Collectors.toList()); + } + } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/UploadDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/UploadDaoImpl.java index fb296be4d35a..8ee4a21a3c0e 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/UploadDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/UploadDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.storage.Upload.Mode; @@ -31,7 +30,6 @@ @Component public class UploadDaoImpl extends GenericDaoBase implements UploadDao { - public static final Logger s_logger = Logger.getLogger(UploadDaoImpl.class.getName()); protected final SearchBuilder typeUploadStatusSearch; protected final SearchBuilder typeHostAndUploadStatusSearch; protected final SearchBuilder typeModeAndStatusSearch; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java index 708a77a8f9ec..1c5a2cb4256a 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java @@ -90,4 +90,7 @@ public interface VMTemplateDao extends GenericDao, StateDao< List findTemplatesLinkedToUserdata(long userdataId); List listByIds(List ids); + + List listByTemplateTag(String tag); + } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java index 031bcb3af7b8..4665f6602512 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.dao.DataCenterDao; @@ -62,7 +61,6 @@ @Component public class VMTemplateDaoImpl extends GenericDaoBase implements VMTemplateDao { - private static final Logger s_logger = Logger.getLogger(VMTemplateDaoImpl.class); @Inject VMTemplateZoneDao _templateZoneDao; @@ -293,7 +291,7 @@ public boolean configure(String name, Map params) throws Configu routerTmpltName = (String)params.get("routing.uniquename"); - s_logger.debug("Found parameter routing unique name " + routerTmpltName); + logger.debug("Found parameter routing unique name " + routerTmpltName); if (routerTmpltName == null) { routerTmpltName = "routing"; } @@ -302,8 +300,8 @@ public boolean configure(String name, Map params) throws Configu if (consoleProxyTmpltName == null) { consoleProxyTmpltName = "routing"; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Use console proxy template : " + consoleProxyTmpltName); + if (logger.isDebugEnabled()) { + logger.debug("Use console proxy template : " + consoleProxyTmpltName); } UniqueNameSearch = createSearchBuilder(); @@ -688,6 +686,16 @@ public boolean remove(Long id) { return result; } + @Override + public List listByTemplateTag(String tag) { + SearchBuilder sb = createSearchBuilder(); + sb.and("tag", sb.entity().getTemplateTag(), SearchCriteria.Op.EQ); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("tag", tag); + return listIncludingRemovedBy(sc); + } + @Override public boolean updateState( com.cloud.template.VirtualMachineTemplate.State currentState, @@ -710,7 +718,7 @@ public boolean updateState( builder.set(vo, "updated", new Date()); int rows = update((VMTemplateVO)vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { VMTemplateVO dbTemplate = findByIdIncludingRemoved(vo.getId()); if (dbTemplate != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -743,7 +751,7 @@ public boolean updateState( .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update template: id=" + vo.getId() + ", as no such template exists in the database anymore"); + logger.debug("Unable to update template: id=" + vo.getId() + ", as no such template exists in the database anymore"); } } return rows > 0; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java index d938bebb18ec..5a2ec1163fb0 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; @@ -49,7 +48,6 @@ @Component public class VMTemplatePoolDaoImpl extends GenericDaoBase implements VMTemplatePoolDao { - public static final Logger s_logger = Logger.getLogger(VMTemplatePoolDaoImpl.class.getName()); @Inject DataStoreManager dataStoreManager; @@ -193,7 +191,7 @@ public List listByTemplateStatus(long templateId, long result.add(toEntityBean(rs, false)); } } catch (Exception e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); } return result; @@ -217,10 +215,10 @@ public List listByTemplateStatus(long templateId, long result.add(findById(id)); } }catch (Exception e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); } } catch (Exception e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); } return result; @@ -245,10 +243,10 @@ public List listByHostTemplate(long hostId, long templa result.add(findById(id)); } }catch (Exception e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); } } catch (Exception e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); } return result; @@ -335,7 +333,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat builder.set(vo, "updated", new Date()); int rows = update((VMTemplateStoragePoolVO)vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { VMTemplateStoragePoolVO dbVol = findByIdIncludingRemoved(templatePool.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -368,7 +366,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update objectIndatastore: id=" + templatePool.getId() + ", as there is no such object exists in the database anymore"); + logger.debug("Unable to update objectIndatastore: id=" + templatePool.getId() + ", as there is no such object exists in the database anymore"); } } return rows > 0; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java index 489ac130eafd..12835d184ea6 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.storage.VMTemplateZoneVO; @@ -30,7 +29,6 @@ @Component public class VMTemplateZoneDaoImpl extends GenericDaoBase implements VMTemplateZoneDao { - public static final Logger s_logger = Logger.getLogger(VMTemplateZoneDaoImpl.class.getName()); protected final SearchBuilder ZoneSearch; protected final SearchBuilder TemplateSearch; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java index 8e3bbf68dea7..e6ffca06f9e0 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java @@ -157,5 +157,9 @@ public interface VolumeDao extends GenericDao, StateDao listByIds(List ids); + List listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(long accountId, List diskOfferingIds, List vmIds); + + List searchRemovedByVms(List vmIds, Long batchSize); + VolumeVO findOneByIScsiName(String iScsiName); } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java index 9907af76769f..0c4d707635aa 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java @@ -23,13 +23,16 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import javax.inject.Inject; +import org.apache.cloudstack.reservation.ReservationVO; +import org.apache.cloudstack.reservation.dao.ReservationDao; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; +import com.cloud.configuration.Resource; import com.cloud.exception.InvalidParameterValueException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.server.ResourceTag.ResourceObjectType; @@ -43,19 +46,21 @@ import com.cloud.tags.dao.ResourceTagDao; import com.cloud.utils.Pair; import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.db.UpdateBuilder; import com.cloud.utils.exception.CloudRuntimeException; @Component public class VolumeDaoImpl extends GenericDaoBase implements VolumeDao { - private static final Logger s_logger = Logger.getLogger(VolumeDaoImpl.class); protected final SearchBuilder DetachedAccountIdSearch; protected final SearchBuilder TemplateZoneSearch; protected final GenericSearchBuilder TotalSizeByPoolSearch; @@ -73,6 +78,8 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol protected GenericSearchBuilder secondaryStorageSearch; private final SearchBuilder poolAndPathSearch; + @Inject + ReservationDao reservationDao; @Inject ResourceTagDao tagsDao; @@ -337,7 +344,7 @@ public HypervisorType getHypervisorType(long volumeId) { } else if (scope == ScopeType.ZONE) { sql = SELECT_HYPERTYPE_FROM_ZONE_VOLUME; } else { - s_logger.error("Unhandled scope type '" + scope + "' when running getHypervisorType on volume id " + volumeId); + logger.error("Unhandled scope type '" + scope + "' when running getHypervisorType on volume id " + volumeId); } pstmt = txn.prepareAutoCloseStatement(sql); @@ -367,7 +374,7 @@ public ImageFormat getImageFormat(Long volumeId) { } else if (type.equals(HypervisorType.VMware)) { return ImageFormat.OVA; } else { - s_logger.warn("Do not support hypervisor " + type.toString()); + logger.warn("Do not support hypervisor " + type.toString()); return null; } } @@ -446,6 +453,7 @@ public VolumeDaoImpl() { CountByAccount.and("account", CountByAccount.entity().getAccountId(), SearchCriteria.Op.EQ); CountByAccount.and("state", CountByAccount.entity().getState(), SearchCriteria.Op.NIN); CountByAccount.and("displayVolume", CountByAccount.entity().isDisplayVolume(), Op.EQ); + CountByAccount.and("idNIN", CountByAccount.entity().getId(), Op.NIN); CountByAccount.done(); primaryStorageSearch = createSearchBuilder(SumCount.class); @@ -457,6 +465,7 @@ public VolumeDaoImpl() { primaryStorageSearch.and("displayVolume", primaryStorageSearch.entity().isDisplayVolume(), Op.EQ); primaryStorageSearch.and("isRemoved", primaryStorageSearch.entity().getRemoved(), Op.NULL); primaryStorageSearch.and("NotCountStates", primaryStorageSearch.entity().getState(), Op.NIN); + primaryStorageSearch.and("idNIN", primaryStorageSearch.entity().getId(), Op.NIN); primaryStorageSearch.done(); primaryStorageSearch2 = createSearchBuilder(SumCount.class); @@ -471,6 +480,7 @@ public VolumeDaoImpl() { primaryStorageSearch2.and("displayVolume", primaryStorageSearch2.entity().isDisplayVolume(), Op.EQ); primaryStorageSearch2.and("isRemoved", primaryStorageSearch2.entity().getRemoved(), Op.NULL); primaryStorageSearch2.and("NotCountStates", primaryStorageSearch2.entity().getState(), Op.NIN); + primaryStorageSearch2.and("idNIN", primaryStorageSearch2.entity().getId(), Op.NIN); primaryStorageSearch2.done(); secondaryStorageSearch = createSearchBuilder(SumCount.class); @@ -508,15 +518,24 @@ public Pair getCountAndTotalByPool(long poolId) { @Override public Long countAllocatedVolumesForAccount(long accountId) { + List reservations = reservationDao.getReservationsForAccount(accountId, Resource.ResourceType.volume, null); + List reservedResourceIds = reservations.stream().filter(reservation -> reservation.getReservedAmount() > 0).map(ReservationVO::getResourceId).collect(Collectors.toList()); + SearchCriteria sc = CountByAccount.create(); sc.setParameters("account", accountId); - sc.setParameters("state", Volume.State.Destroy, Volume.State.Expunged); + sc.setParameters("state", State.Destroy, State.Expunged); sc.setParameters("displayVolume", 1); + if (CollectionUtils.isNotEmpty(reservedResourceIds)) { + sc.setParameters("idNIN", reservedResourceIds.toArray()); + } return customSearch(sc, null).get(0); } @Override public long primaryStorageUsedForAccount(long accountId, List virtualRouters) { + List reservations = reservationDao.getReservationsForAccount(accountId, Resource.ResourceType.volume, null); + List reservedResourceIds = reservations.stream().filter(reservation -> reservation.getReservedAmount() > 0).map(ReservationVO::getResourceId).collect(Collectors.toList()); + SearchCriteria sc; if (!virtualRouters.isEmpty()) { sc = primaryStorageSearch2.create(); @@ -528,6 +547,9 @@ public long primaryStorageUsedForAccount(long accountId, List virtualRoute sc.setParameters("states", State.Allocated); sc.setParameters("NotCountStates", State.Destroy, State.Expunged); sc.setParameters("displayVolume", 1); + if (CollectionUtils.isNotEmpty(reservedResourceIds)) { + sc.setParameters("idNIN", reservedResourceIds.toArray()); + } List storageSpace = customSearch(sc, null); if (storageSpace != null) { return storageSpace.get(0).sum; @@ -592,7 +614,7 @@ public boolean updateState(com.cloud.storage.Volume.State currentState, Event ev builder.set(vo, "updated", new Date()); int rows = update((VolumeVO)vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { VolumeVO dbVol = findByIdIncludingRemoved(vo.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -603,7 +625,7 @@ public boolean updateState(com.cloud.storage.Volume.State currentState, Event ev str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated) .append("; updatedTime=").append(oldUpdatedTime); } else { - s_logger.debug("Unable to update volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore"); + logger.debug("Unable to update volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore"); } } return rows > 0; @@ -641,10 +663,10 @@ public List listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId } return result; } catch (SQLException e) { - s_logger.debug("DB Exception on: " + sql.toString(), e); + logger.debug("DB Exception on: " + sql.toString(), e); throw new CloudRuntimeException(e); } catch (Throwable e) { - s_logger.debug("Caught: " + sql.toString(), e); + logger.debug("Caught: " + sql.toString(), e); throw new CloudRuntimeException(e); } } @@ -716,7 +738,7 @@ public List listVolumesByPassphraseId(long passphraseId) { public boolean remove(Long id) { TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); - s_logger.debug(String.format("Removing volume %s from DB", id)); + logger.debug(String.format("Removing volume %s from DB", id)); VolumeVO entry = findById(id); if (entry != null) { tagsDao.removeByIdAndType(id, ResourceObjectType.Volume); @@ -842,6 +864,54 @@ public List listByIds(List ids) { return listBy(sc, null); } + @Override + public List listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(long accountId, List diskOfferingIds, List vmIds) { + SearchBuilder sb = createSearchBuilder(); + sb.and("account", sb.entity().getAccountId(), SearchCriteria.Op.EQ); + sb.and("state", sb.entity().getState(), SearchCriteria.Op.NIN); + sb.and("diskOfferingIds", sb.entity().getDiskOfferingId(), SearchCriteria.Op.IN); + sb.and("displayVolume", sb.entity().isDisplayVolume(), Op.EQ); + if (CollectionUtils.isNotEmpty(vmIds)) { + sb.and().op("instanceId", sb.entity().getInstanceId(), Op.NULL); + sb.or("notVmIds", sb.entity().getInstanceId(), Op.NIN); + sb.cp(); + } + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("account", accountId); + sc.setParameters("state", Volume.State.Destroy, Volume.State.Expunged); + sc.setParameters("diskOfferingIds", diskOfferingIds.toArray()); + sc.setParameters("displayVolume", 1); + if (CollectionUtils.isNotEmpty(vmIds)) { + sc.setParameters("notVmIds", vmIds.toArray()); + } + return listBy(sc); + } + + @Override + public VolumeVO persist(VolumeVO entity) { + return Transaction.execute((TransactionCallback) status -> { + VolumeVO volume = super.persist(entity); + reservationDao.setResourceId(Resource.ResourceType.volume, volume.getId()); + reservationDao.setResourceId(Resource.ResourceType.primary_storage, volume.getId()); + return volume; + }); + } + + @Override + public List searchRemovedByVms(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return new ArrayList<>(); + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getInstanceId(), SearchCriteria.Op.IN); + sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NNULL); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + Filter filter = new Filter(VolumeVO.class, "id", true, 0L, batchSize); + return searchIncludingRemoved(sc, filter, null, false); + } + public VolumeVO findOneByIScsiName(String iScsiName) { SearchCriteria sc = AllFieldsSearch.create(); sc.setParameters("iScsiName", iScsiName); diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeStatsDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeStatsDaoImpl.java index 002310125af6..d1149e474085 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeStatsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeStatsDaoImpl.java @@ -21,7 +21,8 @@ import javax.annotation.PostConstruct; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Filter; @@ -34,7 +35,7 @@ @Component public class VolumeStatsDaoImpl extends GenericDaoBase implements VolumeStatsDao { - protected Logger logger = Logger.getLogger(getClass()); + protected Logger logger = LogManager.getLogger(getClass()); protected SearchBuilder volumeIdSearch; protected SearchBuilder volumeIdTimestampGreaterThanEqualSearch; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/ConfigurationGroupsAggregator.java b/engine/schema/src/main/java/com/cloud/upgrade/ConfigurationGroupsAggregator.java index 34de1bccb82f..03857137ded6 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/ConfigurationGroupsAggregator.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/ConfigurationGroupsAggregator.java @@ -30,13 +30,14 @@ import org.apache.cloudstack.framework.config.impl.ConfigurationVO; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ConfigurationGroupsAggregator { - static final Logger LOG = Logger.getLogger(ConfigurationGroupsAggregator.class); + protected Logger LOG = LogManager.getLogger(getClass()); @Inject ConfigurationDao configDao; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java index 154a8d118878..384826227af7 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java @@ -116,10 +116,6 @@ private static void initDB(String dbPropsFile, String rootPassword, String[] dat } public static void main(String[] args) { - - ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"/com/cloud/upgrade/databaseCreatorContext.xml"}); - appContext.getBean(ComponentContext.class); - String dbPropsFile = ""; List sqlFiles = new ArrayList(); List upgradeClasses = new ArrayList(); @@ -166,13 +162,17 @@ public static void main(String[] args) { System.exit(1); } + initDB(dbPropsFile, rootPassword, databases, dryRun); + + ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"/com/cloud/upgrade/databaseCreatorContext.xml"}); + appContext.getBean(ComponentContext.class); + try { TransactionLegacy.initDataSource(dbPropsFile); } catch (IOException e) { e.printStackTrace(); System.exit(1); } - initDB(dbPropsFile, rootPassword, databases, dryRun); // Process sql files for (String sqlFile : sqlFiles) { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseIntegrityChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseIntegrityChecker.java index 1fc8b7e3d842..e7ea6025ad76 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseIntegrityChecker.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseIntegrityChecker.java @@ -23,7 +23,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.utils.CloudStackVersion; @@ -38,7 +37,6 @@ @Component public class DatabaseIntegrityChecker extends AdapterBase implements SystemIntegrityChecker { - private static final Logger s_logger = Logger.getLogger(DatabaseIntegrityChecker.class); @Inject VersionDao _dao; @@ -102,32 +100,32 @@ private Boolean checkDuplicateHostWithTheSameLocalStorage() { } catch (Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage(),e); } } catch (Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage(),e); } } if (noDuplicate) { - s_logger.debug("No duplicate hosts with the same local storage found in database"); + logger.debug("No duplicate hosts with the same local storage found in database"); } else { - s_logger.error(helpInfo.toString()); + logger.error(helpInfo.toString()); } txn.commit(); return noDuplicate; }catch (Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage(),e); } } catch (Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage(),e); } finally @@ -138,7 +136,7 @@ private Boolean checkDuplicateHostWithTheSameLocalStorage() { } }catch(Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception:"+ e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception:"+ e.getMessage()); } } } @@ -151,7 +149,7 @@ private boolean check21to22PremiumUprage(Connection conn) throws SQLException { String tableName = rs.getString(1); if (tableName.equalsIgnoreCase("usage_event") || tableName.equalsIgnoreCase("usage_port_forwarding") || tableName.equalsIgnoreCase("usage_network_offering")) { num++; - s_logger.debug("Checking 21to22PremiumUprage table " + tableName + " found"); + logger.debug("Checking 21to22PremiumUprage table " + tableName + " found"); } if (num == 3) { return true; @@ -167,7 +165,7 @@ private boolean isColumnExisted(Connection conn, String dbName, String tableName boolean found = false; while (rs.next()) { if (column.equalsIgnoreCase(rs.getString(1))) { - s_logger.debug(String.format("Column %1$s.%2$s.%3$s found", dbName, tableName, column)); + logger.debug(String.format("Column %1$s.%2$s.%3$s found", dbName, tableName, column)); found = true; break; } @@ -224,33 +222,33 @@ private boolean checkMissedPremiumUpgradeFor228() { } } if (!hasUsage) { - s_logger.debug("No cloud_usage found in database, no need to check missed premium upgrade"); + logger.debug("No cloud_usage found in database, no need to check missed premium upgrade"); txn.commit(); return true; } if (!check21to22PremiumUprage(conn)) { - s_logger.error("21to22 premium upgrade missed"); + logger.error("21to22 premium upgrade missed"); txn.commit(); return false; } if (!check221to222PremiumUprage(conn)) { - s_logger.error("221to222 premium upgrade missed"); + logger.error("221to222 premium upgrade missed"); txn.commit(); return false; } if (!check222to224PremiumUpgrade(conn)) { - s_logger.error("222to224 premium upgrade missed"); + logger.error("222to224 premium upgrade missed"); txn.commit(); return false; } txn.commit(); return true; } catch (Exception e) { - s_logger.error("checkMissedPremiumUpgradeFor228: Exception:" + e.getMessage()); + logger.error("checkMissedPremiumUpgradeFor228: Exception:" + e.getMessage()); throw new CloudRuntimeException("checkMissedPremiumUpgradeFor228: Exception:" + e.getMessage(), e); } }catch (Exception e) { - s_logger.error("checkMissedPremiumUpgradeFor228: Exception:"+ e.getMessage()); + logger.error("checkMissedPremiumUpgradeFor228: Exception:"+ e.getMessage()); throw new CloudRuntimeException("checkMissedPremiumUpgradeFor228: Exception:" + e.getMessage(),e); } finally @@ -261,7 +259,7 @@ private boolean checkMissedPremiumUpgradeFor228() { } }catch(Exception e) { - s_logger.error("checkMissedPremiumUpgradeFor228: Exception:"+ e.getMessage()); + logger.error("checkMissedPremiumUpgradeFor228: Exception:"+ e.getMessage()); } } } @@ -270,19 +268,19 @@ private boolean checkMissedPremiumUpgradeFor228() { public void check() { GlobalLock lock = GlobalLock.getInternLock("DatabaseIntegrity"); try { - s_logger.info("Grabbing lock to check for database integrity."); + logger.info("Grabbing lock to check for database integrity."); if (!lock.lock(20 * 60)) { throw new CloudRuntimeException("Unable to acquire lock to check for database integrity."); } try { - s_logger.info("Performing database integrity check"); + logger.info("Performing database integrity check"); if (!checkDuplicateHostWithTheSameLocalStorage()) { throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage detected error"); } if (!checkMissedPremiumUpgradeFor228()) { - s_logger.error("Your current database version is 2.2.8, management server detected some missed premium upgrade, please contact CloudStack support and attach log file. Thank you!"); + logger.error("Your current database version is 2.2.8, management server detected some missed premium upgrade, please contact CloudStack support and attach log file. Thank you!"); throw new CloudRuntimeException("Detected missed premium upgrade"); } } finally { @@ -298,7 +296,7 @@ public boolean start() { try { check(); } catch (Exception e) { - s_logger.error("System integrity check exception", e); + logger.error("System integrity check exception", e); System.exit(1); } return true; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java index b908455c1fee..cb2190073254 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java @@ -36,7 +36,8 @@ import com.cloud.utils.FileUtil; import org.apache.cloudstack.utils.CloudStackVersion; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.upgrade.dao.DbUpgrade; import com.cloud.upgrade.dao.DbUpgradeSystemVmTemplate; @@ -86,6 +87,7 @@ import com.cloud.upgrade.dao.Upgrade41800to41810; import com.cloud.upgrade.dao.Upgrade41810to41900; import com.cloud.upgrade.dao.Upgrade41900to41910; +import com.cloud.upgrade.dao.Upgrade41910to42000; import com.cloud.upgrade.dao.Upgrade420to421; import com.cloud.upgrade.dao.Upgrade421to430; import com.cloud.upgrade.dao.Upgrade430to440; @@ -125,7 +127,7 @@ import com.google.common.annotations.VisibleForTesting; public class DatabaseUpgradeChecker implements SystemIntegrityChecker { - private static final Logger s_logger = Logger.getLogger(DatabaseUpgradeChecker.class); + protected static Logger LOGGER = LogManager.getLogger(DatabaseUpgradeChecker.class); private final DatabaseVersionHierarchy hierarchy; private static final String VIEWS_DIRECTORY = Paths.get("META-INF", "db", "views").toString(); private static final String PROCEDURES_DIRECTORY = Paths.get("META-INF", "db", "procedures").toString(); @@ -227,6 +229,7 @@ public DatabaseUpgradeChecker() { .next("4.18.0.0", new Upgrade41800to41810()) .next("4.18.1.0", new Upgrade41810to41900()) .next("4.19.0.0", new Upgrade41900to41910()) + .next("4.19.1.0", new Upgrade41910to42000()) .build(); } @@ -236,10 +239,10 @@ protected void runScript(Connection conn, InputStream file) { ScriptRunner runner = new ScriptRunner(conn, false, true); runner.runScript(reader); } catch (IOException e) { - s_logger.error("Unable to read upgrade script", e); + LOGGER.error("Unable to read upgrade script", e); throw new CloudRuntimeException("Unable to read upgrade script", e); } catch (SQLException e) { - s_logger.error("Unable to execute upgrade script", e); + LOGGER.error("Unable to execute upgrade script", e); throw new CloudRuntimeException("Unable to execute upgrade script", e); } @@ -278,7 +281,7 @@ private void updateSystemVmTemplates(DbUpgrade[] upgrades) { conn = txn.getConnection(); } catch (SQLException e) { String errorMessage = "Unable to upgrade the database"; - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } ((DbUpgradeSystemVmTemplate)upgrade).updateSystemVmTemplates(conn); @@ -286,7 +289,7 @@ private void updateSystemVmTemplates(DbUpgrade[] upgrades) { break; } catch (CloudRuntimeException e) { String errorMessage = "Unable to upgrade the database"; - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } finally { txn.close(); @@ -304,29 +307,29 @@ protected void upgrade(CloudStackVersion dbVersion, CloudStackVersion currentVer } protected void executeProcedureScripts() { - s_logger.info(String.format("Executing Stored Procedure scripts that are under resource directory [%s].", PROCEDURES_DIRECTORY)); + LOGGER.info(String.format("Executing Stored Procedure scripts that are under resource directory [%s].", PROCEDURES_DIRECTORY)); List filesPathUnderViewsDirectory = FileUtil.getFilesPathsUnderResourceDirectory(PROCEDURES_DIRECTORY); try (TransactionLegacy txn = TransactionLegacy.open("execute-procedure-scripts")) { Connection conn = txn.getConnection(); for (String filePath : filesPathUnderViewsDirectory) { - s_logger.debug(String.format("Executing PROCEDURE script [%s].", filePath)); + LOGGER.debug(String.format("Executing PROCEDURE script [%s].", filePath)); InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath); runScript(conn, viewScript); } - s_logger.info(String.format("Finished execution of PROCEDURE scripts that are under resource directory [%s].", PROCEDURES_DIRECTORY)); + LOGGER.info(String.format("Finished execution of PROCEDURE scripts that are under resource directory [%s].", PROCEDURES_DIRECTORY)); } catch (SQLException e) { String message = String.format("Unable to execute PROCEDURE scripts due to [%s].", e.getMessage()); - s_logger.error(message, e); + LOGGER.error(message, e); throw new CloudRuntimeException(message, e); } } private DbUpgrade[] executeUpgrades(CloudStackVersion dbVersion, CloudStackVersion currentVersion) { - s_logger.info("Database upgrade must be performed from " + dbVersion + " to " + currentVersion); + LOGGER.info("Database upgrade must be performed from " + dbVersion + " to " + currentVersion); final DbUpgrade[] upgrades = calculateUpgradePath(dbVersion, currentVersion); @@ -339,7 +342,7 @@ private DbUpgrade[] executeUpgrades(CloudStackVersion dbVersion, CloudStackVersi private VersionVO executeUpgrade(DbUpgrade upgrade) { VersionVO version; - s_logger.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade + LOGGER.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade .getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion()); TransactionLegacy txn = TransactionLegacy.open("Upgrade"); txn.start(); @@ -349,7 +352,7 @@ private VersionVO executeUpgrade(DbUpgrade upgrade) { conn = txn.getConnection(); } catch (SQLException e) { String errorMessage = "Unable to upgrade the database"; - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } InputStream[] scripts = upgrade.getPrepareScripts(); @@ -367,7 +370,7 @@ private VersionVO executeUpgrade(DbUpgrade upgrade) { txn.commit(); } catch (CloudRuntimeException e) { String errorMessage = "Unable to upgrade the database"; - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } finally { txn.close(); @@ -380,7 +383,7 @@ private void executeUpgradeCleanup(DbUpgrade upgrade, VersionVO version) { // Run the corresponding '-cleanup.sql' script txn = TransactionLegacy.open("Cleanup"); try { - s_logger.info("Cleanup upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade + LOGGER.info("Cleanup upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade .getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion()); txn.start(); @@ -388,7 +391,7 @@ private void executeUpgradeCleanup(DbUpgrade upgrade, VersionVO version) { try { conn = txn.getConnection(); } catch (SQLException e) { - s_logger.error("Unable to cleanup the database", e); + LOGGER.error("Unable to cleanup the database", e); throw new CloudRuntimeException("Unable to cleanup the database", e); } @@ -396,7 +399,7 @@ private void executeUpgradeCleanup(DbUpgrade upgrade, VersionVO version) { if (scripts != null) { for (InputStream script : scripts) { runScript(conn, script); - s_logger.debug("Cleanup script " + upgrade.getClass().getSimpleName() + " is executed successfully"); + LOGGER.debug("Cleanup script " + upgrade.getClass().getSimpleName() + " is executed successfully"); } } txn.commit(); @@ -406,30 +409,30 @@ private void executeUpgradeCleanup(DbUpgrade upgrade, VersionVO version) { version.setUpdated(new Date()); _dao.update(version.getId(), version); txn.commit(); - s_logger.debug("Upgrade completed for version " + version.getVersion()); + LOGGER.debug("Upgrade completed for version " + version.getVersion()); } finally { txn.close(); } } protected void executeViewScripts() { - s_logger.info(String.format("Executing VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY)); + LOGGER.info(String.format("Executing VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY)); List filesPathUnderViewsDirectory = FileUtil.getFilesPathsUnderResourceDirectory(VIEWS_DIRECTORY); try (TransactionLegacy txn = TransactionLegacy.open("execute-view-scripts")) { Connection conn = txn.getConnection(); for (String filePath : filesPathUnderViewsDirectory) { - s_logger.debug(String.format("Executing VIEW script [%s].", filePath)); + LOGGER.debug(String.format("Executing VIEW script [%s].", filePath)); InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath); runScript(conn, viewScript); } - s_logger.info(String.format("Finished execution of VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY)); + LOGGER.info(String.format("Finished execution of VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY)); } catch (SQLException e) { String message = String.format("Unable to execute VIEW scripts due to [%s].", e.getMessage()); - s_logger.error(message, e); + LOGGER.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -438,7 +441,7 @@ protected void executeViewScripts() { public void check() { GlobalLock lock = GlobalLock.getInternLock("DatabaseUpgrade"); try { - s_logger.info("Grabbing lock to check for database upgrade."); + LOGGER.info("Grabbing lock to check for database upgrade."); if (!lock.lock(20 * 60)) { throw new CloudRuntimeException("Unable to acquire lock to check for database integrity."); } @@ -459,14 +462,14 @@ public void check() { SystemVmTemplateRegistration.CS_MAJOR_VERSION = String.valueOf(sysVmVersion.getMajorRelease()) + "." + String.valueOf(sysVmVersion.getMinorRelease()); SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(sysVmVersion.getPatchRelease()); - s_logger.info("DB version = " + dbVersion + " Code Version = " + currentVersion); + LOGGER.info("DB version = " + dbVersion + " Code Version = " + currentVersion); if (dbVersion.compareTo(currentVersion) > 0) { throw new CloudRuntimeException("Database version " + dbVersion + " is higher than management software version " + currentVersionValue); } if (dbVersion.compareTo(currentVersion) == 0) { - s_logger.info("DB version and code version matches so no upgrade needed."); + LOGGER.info("DB version and code version matches so no upgrade needed."); return; } @@ -489,13 +492,13 @@ private void initializeDatabaseEncryptors() { decryptInit(conn); txn.commit(); } catch (CloudRuntimeException e) { - s_logger.error(e.getMessage()); + LOGGER.error(e.getMessage()); errorMessage = String.format("Unable to initialize the database encryptors due to %s. " + "Please check if database encryption key and database encryptor version are correct.", errorMessage); - s_logger.error(errorMessage); + LOGGER.error(errorMessage); throw new CloudRuntimeException(errorMessage, e); } catch (SQLException e) { - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } finally { txn.close(); @@ -508,7 +511,7 @@ private void decryptInit(Connection conn) throws SQLException { ResultSet result = pstmt.executeQuery()) { if (result.next()) { String init = result.getString(1); - s_logger.info("init = " + DBEncryptionUtil.decrypt(init)); + LOGGER.info("init = " + DBEncryptionUtil.decrypt(init)); } } } @@ -565,7 +568,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - s_logger.debug("Updating System Vm template IDs"); + LOGGER.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/GuestOsMapper.java b/engine/schema/src/main/java/com/cloud/upgrade/GuestOsMapper.java index 4aabaa3e182b..abb0d7f76690 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/GuestOsMapper.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/GuestOsMapper.java @@ -18,7 +18,8 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.sql.Connection; import java.sql.PreparedStatement; @@ -40,7 +41,7 @@ public class GuestOsMapper { - final static Logger LOG = Logger.getLogger(GuestOsMapper.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject GuestOSHypervisorDao guestOSHypervisorDao; @@ -56,15 +57,15 @@ public GuestOsMapper() { } public void mergeDuplicates() { - LOG.info("merging duplicate guest osses"); + logger.info("merging duplicate guest osses"); Set> duplicates = findDuplicates(); - LOG.debug(String.format("merging %d sets of duplicates", duplicates.size())); + logger.debug(String.format("merging %d sets of duplicates", duplicates.size())); for (Set setOfGuestOSes : duplicates) { // decide which to (mark as) remove(d) // # highest/lowest id // # or is user_defined == false GuestOSVO guestOSVO = highestIdFrom(setOfGuestOSes); - LOG.info(String.format("merging %d duplicates for %s ", setOfGuestOSes.size(), guestOSVO.getDisplayName())); + logger.info(String.format("merging %d duplicates for %s ", setOfGuestOSes.size(), guestOSVO.getDisplayName())); makeNormative(guestOSVO, setOfGuestOSes); } @@ -144,7 +145,7 @@ private long getGuestOsId(long categoryId, String displayName) { if (guestOS != null) { id = guestOS.getId(); } else { - LOG.warn(String.format("Unable to find the guest OS details with category id: %d and display name: %s", + categoryId, displayName)); + logger.warn(String.format("Unable to find the guest OS details with category id: %d and display name: %s", + categoryId, displayName)); } return id; } @@ -155,7 +156,7 @@ private long getGuestOsIdFromHypervisorMapping(GuestOSHypervisorMapping mapping) if (guestOSHypervisorVO != null) { id = guestOSHypervisorVO.getGuestOsId(); } else { - LOG.warn(String.format("Unable to find the guest OS hypervisor mapping details for %s", mapping.toString())); + logger.warn(String.format("Unable to find the guest OS hypervisor mapping details for %s", mapping.toString())); } return id; } @@ -163,9 +164,9 @@ private long getGuestOsIdFromHypervisorMapping(GuestOSHypervisorMapping mapping) public void addGuestOsAndHypervisorMappings(long categoryId, String displayName, List mappings) { long guestOsId = getGuestOsId(categoryId, displayName); if (guestOsId == 0) { - LOG.debug("No guest OS found with category id: " + categoryId + " and display name: " + displayName); + logger.debug("No guest OS found with category id: " + categoryId + " and display name: " + displayName); if (!addGuestOs(categoryId, displayName)) { - LOG.warn("Couldn't add the guest OS with category id: " + categoryId + " and display name: " + displayName); + logger.warn("Couldn't add the guest OS with category id: " + categoryId + " and display name: " + displayName); return; } guestOsId = getGuestOsId(categoryId, displayName); @@ -189,7 +190,7 @@ private void updateToSystemDefined(long guestOsId) { } public boolean addGuestOs(long categoryId, String displayName) { - LOG.debug("Adding guest OS with category id: " + categoryId + " and display name: " + displayName); + logger.debug("Adding guest OS with category id: " + categoryId + " and display name: " + displayName); GuestOSVO guestOS = new GuestOSVO(); guestOS.setCategoryId(categoryId); guestOS.setDisplayName(displayName); @@ -199,7 +200,7 @@ public boolean addGuestOs(long categoryId, String displayName) { public void addGuestOsHypervisorMapping(GuestOSHypervisorMapping mapping, long category, String displayName) { long guestOsId = getGuestOsId(category, displayName); if (guestOsId == 0) { - LOG.error(String.format("no guest os found for category %d and name %s, skipping mapping it to %s/%s", guestOsId, displayName, mapping.getHypervisorType(), mapping.getHypervisorVersion())); + logger.error(String.format("no guest os found for category %d and name %s, skipping mapping it to %s/%s", guestOsId, displayName, mapping.getHypervisorType(), mapping.getHypervisorVersion())); } else { addGuestOsHypervisorMapping(mapping, guestOsId); } @@ -210,7 +211,7 @@ private void addGuestOsHypervisorMapping(GuestOSHypervisorMapping mapping, long return; } - LOG.debug("Adding guest OS hypervisor mapping - " + mapping.toString() + ", for guest OS with id - " + guestOsId); + logger.debug("Adding guest OS hypervisor mapping - " + mapping.toString() + ", for guest OS with id - " + guestOsId); GuestOSHypervisorVO guestOsMapping = new GuestOSHypervisorVO(); guestOsMapping.setHypervisorType(mapping.getHypervisorType()); guestOsMapping.setHypervisorVersion(mapping.getHypervisorVersion()); @@ -222,7 +223,7 @@ private void addGuestOsHypervisorMapping(GuestOSHypervisorMapping mapping, long public void updateGuestOsName(long categoryId, String oldDisplayName, String newDisplayName) { GuestOSVO guestOS = guestOSDao.findByCategoryIdAndDisplayNameOrderByCreatedDesc(categoryId, oldDisplayName); if (guestOS == null) { - LOG.debug("Unable to update guest OS name, as there is no guest OS with category id: " + categoryId + " and display name: " + oldDisplayName); + logger.debug("Unable to update guest OS name, as there is no guest OS with category id: " + categoryId + " and display name: " + oldDisplayName); return; } @@ -237,7 +238,7 @@ public void updateGuestOsNameFromMapping(String newDisplayName, GuestOSHyperviso GuestOSHypervisorVO guestOSHypervisorVO = guestOSHypervisorDao.findByOsNameAndHypervisorOrderByCreatedDesc(mapping.getGuestOsName(), mapping.getHypervisorType(), mapping.getHypervisorVersion()); if (guestOSHypervisorVO == null) { - LOG.debug("Unable to update guest OS name, as there is no guest os hypervisor mapping"); + logger.debug("Unable to update guest OS name, as there is no guest os hypervisor mapping"); return; } @@ -256,13 +257,13 @@ public void updateGuestOsIdInHypervisorMapping(Connection conn, long categoryId, long oldGuestOsId = getGuestOsIdFromHypervisorMapping(mapping); if (oldGuestOsId == 0) { - LOG.debug("Unable to update guest OS in hypervisor mapping, as there is no guest os hypervisor mapping - " + mapping.toString()); + logger.debug("Unable to update guest OS in hypervisor mapping, as there is no guest os hypervisor mapping - " + mapping.toString()); return; } long newGuestOsId = getGuestOsId(categoryId, displayName); if (newGuestOsId == 0) { - LOG.debug("Unable to update guest OS id in hypervisor mapping, as there is no guest OS with category id: " + categoryId + " and display name: " + displayName); + logger.debug("Unable to update guest OS id in hypervisor mapping, as there is no guest OS with category id: " + categoryId + " and display name: " + displayName); return; } @@ -270,7 +271,7 @@ public void updateGuestOsIdInHypervisorMapping(Connection conn, long categoryId, } private void updateGuestOsIdInMapping(Connection conn, long oldGuestOsId, long newGuestOsId, GuestOSHypervisorMapping mapping) { - LOG.debug("Updating guest os id: " + oldGuestOsId + " to id: " + newGuestOsId + " in hypervisor mapping - " + mapping.toString()); + logger.debug("Updating guest os id: " + oldGuestOsId + " to id: " + newGuestOsId + " in hypervisor mapping - " + mapping.toString()); try { PreparedStatement pstmt = conn.prepareStatement(updateGuestOsHypervisorSql); pstmt.setLong(1, newGuestOsId); @@ -280,7 +281,7 @@ private void updateGuestOsIdInMapping(Connection conn, long oldGuestOsId, long n pstmt.setString(5, mapping.getGuestOsName()); pstmt.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to update guest OS id in hypervisor mapping due to: " + e.getMessage(), e); + logger.error("Failed to update guest OS id in hypervisor mapping due to: " + e.getMessage(), e); } } @@ -289,7 +290,7 @@ private boolean isValidGuestOSHypervisorMapping(GuestOSHypervisorMapping mapping return true; } - LOG.warn("Invalid Guest OS hypervisor mapping"); + logger.warn("Invalid Guest OS hypervisor mapping"); return false; } @@ -299,22 +300,22 @@ private boolean isValidGuestOSHypervisorMapping(GuestOSHypervisorMapping mapping */ public boolean copyGuestOSHypervisorMappings(HypervisorType hypervisorType, String srcVersion, String destVersion) { if (hypervisorType == HypervisorType.None || hypervisorType == HypervisorType.Any) { - LOG.warn("Unable to copy, invalid hypervisor"); + logger.warn("Unable to copy, invalid hypervisor"); return false; } if (StringUtils.isAnyBlank(srcVersion, destVersion)) { - LOG.warn("Unable to copy, invalid hypervisor version details"); + logger.warn("Unable to copy, invalid hypervisor version details"); return false; } List guestOSHypervisorMappingsForSrcVersion = guestOSHypervisorDao.listByHypervisorTypeAndVersion(hypervisorType.toString(), srcVersion); if (CollectionUtils.isEmpty(guestOSHypervisorMappingsForSrcVersion)) { - LOG.warn(String.format("Unable to copy, couldn't find guest OS mappings for hypervisor: %s and src version: %s", hypervisorType.toString(), srcVersion)); + logger.warn(String.format("Unable to copy, couldn't find guest OS mappings for hypervisor: %s and src version: %s", hypervisorType.toString(), srcVersion)); return false; } - LOG.debug(String.format("Adding guest OS mappings for hypervisor: %s and version: %s, from version: %s ", hypervisorType.toString(), destVersion, srcVersion)); + logger.debug(String.format("Adding guest OS mappings for hypervisor: %s and version: %s, from version: %s ", hypervisorType.toString(), destVersion, srcVersion)); for (GuestOSHypervisorVO guestOSHypervisorMapping : guestOSHypervisorMappingsForSrcVersion) { GuestOSHypervisorMapping mapping = new GuestOSHypervisorMapping(hypervisorType.toString(), destVersion, guestOSHypervisorMapping.getGuestOsName()); addGuestOsHypervisorMapping(mapping, guestOSHypervisorMapping.getGuestOsId()); @@ -329,7 +330,7 @@ public void updateGuestOsNameInHypervisorMapping(long categoryId, String display long guestOsId = getGuestOsId(categoryId, displayName); if (guestOsId == 0) { - LOG.error(String.format("no guest os found for category %d and name %s, skipping mapping it to %s/%s", guestOsId, displayName, mapping.getHypervisorType(), mapping.getHypervisorVersion())); + logger.error(String.format("no guest os found for category %d and name %s, skipping mapping it to %s/%s", guestOsId, displayName, mapping.getHypervisorType(), mapping.getHypervisorVersion())); return; } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/RolePermissionChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/RolePermissionChecker.java index 6d434cda755c..370b85e37bec 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/RolePermissionChecker.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/RolePermissionChecker.java @@ -16,7 +16,8 @@ // under the License. package com.cloud.upgrade; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.sql.Connection; import java.sql.PreparedStatement; @@ -25,7 +26,7 @@ public class RolePermissionChecker { - final static Logger LOG = Logger.getLogger(RolePermissionChecker.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String checkAnnotationRulesPermissionPreparedStatement = "SELECT permission FROM `cloud`.`role_permissions` WHERE role_id = ? AND rule = ?"; @@ -43,7 +44,7 @@ public boolean existsRolePermissionByRoleIdAndRule(Connection conn, long roleId, ResultSet rs = pstmt.executeQuery(); return rs != null && rs.next(); } catch (SQLException e) { - LOG.error("Error on existsRolePermissionByRoleIdAndRule: " + e.getMessage(), e); + logger.error("Error on existsRolePermissionByRoleIdAndRule: " + e.getMessage(), e); return false; } } @@ -55,7 +56,7 @@ public void insertAnnotationRulePermission(Connection conn, long roleId, String pstmt.setString(2, rule); pstmt.executeUpdate(); } catch (SQLException e) { - LOG.error("Error on insertAnnotationRulePermission: " + e.getMessage(), e); + logger.error("Error on insertAnnotationRulePermission: " + e.getMessage(), e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java b/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java index 671fb8c95d53..7314937ff5b2 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java @@ -59,7 +59,8 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.utils.security.DigestHelper; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.ini4j.Ini; import javax.inject.Inject; @@ -85,7 +86,8 @@ import java.util.stream.Collectors; public class SystemVmTemplateRegistration { - private static final Logger LOGGER = Logger.getLogger(SystemVmTemplateRegistration.class); + protected static Logger LOGGER = LogManager.getLogger(SystemVmTemplateRegistration.class); + private static final String MOUNT_COMMAND = "sudo mount -t nfs %s %s"; private static final String UMOUNT_COMMAND = "sudo umount %s"; private static final String RELATIVE_TEMPLATE_PATH = "./engine/schema/dist/systemvm-templates/"; private static final String ABSOLUTE_TEMPLATE_PATH = "/usr/share/cloudstack-management/templates/systemvm/"; @@ -457,7 +459,7 @@ public static void mountStore(String storeUrl, String path, String nfsVersion) { private List fetchAllHypervisors(Long zoneId) { List hypervisorList = new ArrayList<>(); List hypervisorTypes = clusterDao.getAvailableHypervisorInZone(zoneId); - hypervisorList = hypervisorTypes.stream().distinct().map(Enum::name).collect(Collectors.toList()); + hypervisorList = hypervisorTypes.stream().distinct().map(Hypervisor.HypervisorType::name).collect(Collectors.toList()); return hypervisorList; } @@ -731,8 +733,8 @@ private static void cleanupStore(Long templateId, String filePath) { } private void validateTemplates(Set hypervisorsInUse) { - Set hypervisors = hypervisorsInUse.stream().map(Enum::name). - map(name -> name.toLowerCase(Locale.ROOT)).map(this::getHypervisorName).collect(Collectors.toSet()); + Set hypervisors = hypervisorsInUse.stream(). + map(Hypervisor.HypervisorType::name).map(name -> name.toLowerCase(Locale.ROOT)).map(this::getHypervisorName).collect(Collectors.toSet()); List templates = new ArrayList<>(); for (Hypervisor.HypervisorType hypervisorType : hypervisorsInUse) { templates.add(FileNames.get(hypervisorType)); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java index de161afea071..1c2c4b3c7ce7 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java @@ -22,20 +22,21 @@ import java.sql.SQLException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class DatabaseAccessObject { - private static Logger s_logger = Logger.getLogger(DatabaseAccessObject.class); + protected Logger logger = LogManager.getLogger(DatabaseAccessObject.class); public void addForeignKey(Connection conn, String tableName, String tableColumn, String foreignTableName, String foreignColumnName) { String addForeignKeyStmt = String.format("ALTER TABLE `cloud`.`%s` ADD CONSTRAINT `fk_%s__%s` FOREIGN KEY `fk_%s__%s`(`%s`) REFERENCES `%s`(`%s`)", tableName, tableName, tableColumn, tableName, tableColumn, tableColumn, foreignTableName, foreignColumnName); try(PreparedStatement pstmt = conn.prepareStatement(addForeignKeyStmt);) { pstmt.executeUpdate(); - s_logger.debug(String.format("Foreign key is added successfully from the table %s", tableName)); + logger.debug(String.format("Foreign key is added successfully from the table %s", tableName)); } catch (SQLException e) { - s_logger.error("Ignored SQL Exception when trying to add foreign key on table " + tableName + " exception: " + e.getMessage()); + logger.error("Ignored SQL Exception when trying to add foreign key on table " + tableName + " exception: " + e.getMessage()); } } @@ -50,9 +51,9 @@ public void dropKey(Connection conn, String tableName, String key, boolean isFor try(PreparedStatement pstmt = conn.prepareStatement(alter_sql_str);) { pstmt.executeUpdate(); - s_logger.debug("Key " + key + " is dropped successfully from the table " + tableName); + logger.debug("Key " + key + " is dropped successfully from the table " + tableName); } catch (SQLException e) { - s_logger.debug("Ignored SQL Exception when trying to drop " + (isForeignKey ? "foreign " : "") + "key " + key + " on table " + tableName + " exception: " + e.getMessage()); + logger.debug("Ignored SQL Exception when trying to drop " + (isForeignKey ? "foreign " : "") + "key " + key + " on table " + tableName + " exception: " + e.getMessage()); } } @@ -60,18 +61,18 @@ public void dropKey(Connection conn, String tableName, String key, boolean isFor public void dropPrimaryKey(Connection conn, String tableName) { try(PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE " + tableName + " DROP PRIMARY KEY ");) { pstmt.executeUpdate(); - s_logger.debug("Primary key is dropped successfully from the table " + tableName); + logger.debug("Primary key is dropped successfully from the table " + tableName); } catch (SQLException e) { - s_logger.debug("Ignored SQL Exception when trying to drop primary key on table " + tableName + " exception: " + e.getMessage()); + logger.debug("Ignored SQL Exception when trying to drop primary key on table " + tableName + " exception: " + e.getMessage()); } } public void dropColumn(Connection conn, String tableName, String columnName) { try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE " + tableName + " DROP COLUMN " + columnName);){ pstmt.executeUpdate(); - s_logger.debug("Column " + columnName + " is dropped successfully from the table " + tableName); + logger.debug("Column " + columnName + " is dropped successfully from the table " + tableName); } catch (SQLException e) { - s_logger.warn("Unable to drop column " + columnName + " due to exception", e); + logger.warn("Unable to drop column " + columnName + " due to exception", e); } } @@ -81,7 +82,7 @@ public boolean columnExists(Connection conn, String tableName, String columnName pstmt.executeQuery(); columnExists = true; } catch (SQLException e) { - s_logger.debug("Field " + columnName + " doesn't exist in " + tableName + " ignoring exception: " + e.getMessage()); + logger.debug("Field " + columnName + " doesn't exist in " + tableName + " ignoring exception: " + e.getMessage()); } return columnExists; } @@ -97,29 +98,29 @@ public boolean indexExists(Connection conn, String tableName, String indexName) return true; } } catch (SQLException e) { - s_logger.debug(String.format("Index %s doesn't exist, ignoring exception:", indexName, e.getMessage())); + logger.debug(String.format("Index %s doesn't exist, ignoring exception:", indexName, e.getMessage())); } return false; } public void createIndex(Connection conn, String tableName, String indexName, String... columnNames) { String stmt = String.format("CREATE INDEX %s ON %s (%s)", indexName, tableName, StringUtils.join(columnNames, ", ")); - s_logger.debug("Statement: " + stmt); + logger.debug("Statement: " + stmt); try (PreparedStatement pstmt = conn.prepareStatement(stmt)) { pstmt.execute(); - s_logger.debug(String.format("Created index %s", indexName)); + logger.debug(String.format("Created index %s", indexName)); } catch (SQLException e) { - s_logger.warn(String.format("Unable to create index %s", indexName), e); + logger.warn(String.format("Unable to create index %s", indexName), e); } } - protected static void closePreparedStatement(PreparedStatement pstmt, String errorMessage) { + protected void closePreparedStatement(PreparedStatement pstmt, String errorMessage) { try { if (pstmt != null) { pstmt.close(); } } catch (SQLException e) { - s_logger.warn(errorMessage, e); + logger.warn(errorMessage, e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeAbstractImpl.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeAbstractImpl.java new file mode 100644 index 000000000000..c96365dd6f50 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeAbstractImpl.java @@ -0,0 +1,24 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.upgrade.dao; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + +public abstract class DbUpgradeAbstractImpl implements DbUpgrade { + protected Logger logger = LogManager.getLogger(getClass()); +} diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/LegacyDbUpgrade.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/LegacyDbUpgrade.java index d058943f4395..2a64ff496a2a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/LegacyDbUpgrade.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/LegacyDbUpgrade.java @@ -16,11 +16,9 @@ // under the License. package com.cloud.upgrade.dao; -import org.apache.log4j.Logger; -public abstract class LegacyDbUpgrade implements DbUpgrade{ +public abstract class LegacyDbUpgrade extends DbUpgradeAbstractImpl{ - final static Logger s_logger = Logger.getLogger(LegacyDbUpgrade.class); public LegacyDbUpgrade() { super(); @@ -34,7 +32,7 @@ protected void closeAutoCloseable(AutoCloseable closable) { try { closable.close(); } catch (Exception e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade217to218.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade217to218.java index 2ca4e794fb84..5441f8fb02f8 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade217to218.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade217to218.java @@ -21,7 +21,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade217to218 implements DbUpgrade { +public class Upgrade217to218 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22.java index bc58794e8bd2..171357578ee9 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22.java @@ -34,7 +34,6 @@ import java.util.TimeZone; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.configuration.Resource.ResourceType; import com.cloud.event.EventTypes; @@ -45,8 +44,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; -public class Upgrade218to22 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade218to22.class); +public class Upgrade218to22 extends DbUpgradeAbstractImpl { boolean _basicZone; @Override @@ -212,7 +210,7 @@ protected long insertNic(Connection conn, long networkId, long instanceId, boole protected void upgradeDomR(Connection conn, long dcId, long domrId, Long publicNetworkId, long guestNetworkId, long controlNetworkId, String zoneType, String vnet) throws SQLException { - s_logger.debug("Upgrading domR" + domrId); + logger.debug("Upgrading domR" + domrId); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT vm_instance.id, vm_instance.state, vm_instance.private_mac_address, vm_instance.private_ip_address, vm_instance.private_netmask, domain_router.public_mac_address, domain_router.public_ip_address, domain_router.public_netmask, domain_router.guest_mac_address, domain_router.guest_ip_address, domain_router.guest_netmask, domain_router.vnet, domain_router.gateway FROM vm_instance INNER JOIN domain_router ON vm_instance.id=domain_router.id WHERE vm_instance.removed is NULL AND vm_instance.id=?"); @@ -274,7 +272,7 @@ protected void upgradeDomR(Connection conn, long dcId, long domrId, Long publicN protected void upgradeSsvm(Connection conn, long dataCenterId, long publicNetworkId, long managementNetworkId, long controlNetworkId, String zoneType) throws SQLException { - s_logger.debug("Upgrading ssvm in " + dataCenterId); + logger.debug("Upgrading ssvm in " + dataCenterId); //select instance try ( PreparedStatement selectInstance = @@ -284,7 +282,7 @@ protected void upgradeSsvm(Connection conn, long dataCenterId, long publicNetwor try (ResultSet instanceResult = selectInstance.executeQuery();) { if (!instanceResult.next()) { - s_logger.debug("Unable to find ssvm in data center " + dataCenterId); + logger.debug("Unable to find ssvm in data center " + dataCenterId); return; } @@ -309,7 +307,7 @@ protected void upgradeSsvm(Connection conn, long dataCenterId, long publicNetwor try (ResultSet hostResult = selectHost.executeQuery();) { if (!hostResult.next()) { - s_logger.debug("Unable to find ssvm in data center " + dataCenterId); + logger.debug("Unable to find ssvm in data center " + dataCenterId); return; } @@ -365,7 +363,7 @@ protected void upgradeSsvm(Connection conn, long dataCenterId, long publicNetwor protected void upgradeConsoleProxy(Connection conn, long dcId, long cpId, long publicNetworkId, long managementNetworkId, long controlNetworkId, String zoneType) throws SQLException { - s_logger.debug("Upgrading cp" + cpId); + logger.debug("Upgrading cp" + cpId); try (PreparedStatement pstmt = conn.prepareStatement("SELECT vm_instance.id, vm_instance.state, vm_instance.private_mac_address, vm_instance.private_ip_address, vm_instance.private_netmask, console_proxy.public_mac_address, console_proxy.public_ip_address, console_proxy.public_netmask, console_proxy.guest_mac_address, console_proxy.guest_ip_address, console_proxy.guest_netmask, console_proxy.gateway, vm_instance.type FROM vm_instance INNER JOIN console_proxy ON vm_instance.id=console_proxy.id WHERE vm_instance.removed is NULL AND vm_instance.id=?");) { pstmt.setLong(1, cpId); @@ -466,7 +464,7 @@ protected void upgradeUserVms(Connection conn, long domainRouterId, long network vm[4] = rs.getString(5); // vm state vms.add(vm); } - s_logger.debug("Upgrading " + vms.size() + " vms for router " + domainRouterId); + logger.debug("Upgrading " + vms.size() + " vms for router " + domainRouterId); for (Object[] vm : vms) { String state = (String)vm[4]; @@ -617,7 +615,7 @@ protected void upgradeManagementIpAddress(Connection conn, long dcId) throws SQL } protected void upgradeDirectUserIpAddress(Connection conn, long dcId, long networkId, String vlanType) throws SQLException { - s_logger.debug("Upgrading user ip address for data center " + dcId + " network " + networkId + " vlan type " + vlanType); + logger.debug("Upgrading user ip address for data center " + dcId + " network " + networkId + " vlan type " + vlanType); try (PreparedStatement pstmt = conn.prepareStatement("UPDATE user_ip_address INNER JOIN vlan ON user_ip_address.vlan_db_id=vlan.id SET user_ip_address.source_network_id=vlan.network_id WHERE user_ip_address.data_center_id=? AND vlan.vlan_type=?");) { pstmt.setLong(1, dcId); @@ -638,8 +636,8 @@ protected void upgradeDirectUserIpAddress(Connection conn, long dcId, long netwo ip[3] = rs.getDate(4); // allocated allocatedIps.add(ip); } - s_logger.debug("Marking " + allocatedIps.size() + " ip addresses to belong to network " + networkId); - s_logger.debug("Updating mac addresses for data center id=" + dcId + ". Found " + allocatedIps.size() + " ip addresses to update"); + logger.debug("Marking " + allocatedIps.size() + " ip addresses to belong to network " + networkId); + logger.debug("Updating mac addresses for data center id=" + dcId + ". Found " + allocatedIps.size() + " ip addresses to update"); for (Object[] allocatedIp : allocatedIps) { try (PreparedStatement selectMacAddresses = conn.prepareStatement("SELECT mac_address FROM data_center WHERE id = ?");) { selectMacAddresses.setLong(1, dcId); @@ -665,7 +663,7 @@ protected void upgradeDirectUserIpAddress(Connection conn, long dcId, long netwo } protected void upgradePublicUserIpAddress(Connection conn, long dcId, long networkId, String vlanType) throws SQLException { - s_logger.debug("Upgrading user ip address for data center " + dcId + " network " + networkId + " vlan type " + vlanType); + logger.debug("Upgrading user ip address for data center " + dcId + " network " + networkId + " vlan type " + vlanType); try (PreparedStatement pstmt = conn.prepareStatement("UPDATE user_ip_address INNER JOIN vlan ON user_ip_address.vlan_db_id=vlan.id SET source_network_id=? WHERE user_ip_address.data_center_id=? AND vlan.vlan_type=?");) { pstmt.setLong(1, networkId); @@ -763,7 +761,7 @@ protected void upgradeDataCenter(Connection conn) { } } catch (SQLException e) { - s_logger.error("Can't update data center ", e); + logger.error("Can't update data center ", e); throw new CloudRuntimeException("Can't update data center ", e); } } @@ -832,7 +830,7 @@ private long retrieveNetworkOfferingId(Connection conn, String type) throws SQLE pstmt.setString(1, type); try (ResultSet rs = pstmt.executeQuery();) { if (!rs.next()) { - s_logger.error("Unable to find the network offering for networktype '" + type + "'"); + logger.error("Unable to find the network offering for networktype '" + type + "'"); throw new CloudRuntimeException("Unable to find the storage network offering."); } networkOfferingId = rs.getLong(1); @@ -970,7 +968,7 @@ private void updateRouters(Connection conn, Object[] dc, Long dcId, long control private void updateRouters(Connection conn, Long dcId, long controlNetworkId, long basicDefaultDirectNetworkId, ArrayList routers) throws SQLException { for (Object[] router : routers) { - s_logger.debug("Updating domR with network id in basic zone id=" + dcId); + logger.debug("Updating domR with network id in basic zone id=" + dcId); updateNetworkForRouter(conn, router, basicDefaultDirectNetworkId); upgradeUserVms(conn, (Long)router[0], basicDefaultDirectNetworkId, (String)router[1], "untagged", "DirectPodBasedNetworkGuru", "Create"); upgradeDomR(conn, dcId, (Long)router[0], null, basicDefaultDirectNetworkId, controlNetworkId, "Basic", "untagged"); @@ -1007,7 +1005,7 @@ private void updateNetworkForRouter(Connection conn, Object[] router, long virtu updateDomainRouter.setLong(2, (Long)router[0]); updateDomainRouter.executeUpdate(); } - s_logger.debug("Network inserted for " + router[0] + " id = " + virtualNetworkId); + logger.debug("Network inserted for " + router[0] + " id = " + virtualNetworkId); } private void createDirectNetworks(Connection conn, Object[] dc, Long dcId) throws SQLException { @@ -1029,7 +1027,7 @@ private void createDirectNetworks(Connection conn, Object[] dc, Long dcId) throw updateNetworkInVlanTableforTag(conn, vlanNetworkMap, vlanId, tag); upgradeDirectUserIpAddress(conn, dcId, vlanNetworkMap.get(tag), "DirectAttached"); - s_logger.debug("Created Direct networks and upgraded Direct ip addresses"); + logger.debug("Created Direct networks and upgraded Direct ip addresses"); } } } @@ -1118,11 +1116,11 @@ private void updateDhcpServerData(Connection conn, Long dcId, long controlNetwor String gateway = retrieveGateway(conn, directNetworkId); updateDomainRouter(conn, routerId, directNetworkId); - s_logger.debug("NetworkId updated for router id=" + routerId + "with network id = " + directNetworkId); + logger.debug("NetworkId updated for router id=" + routerId + "with network id = " + directNetworkId); upgradeUserVms(conn, routerId, directNetworkId, gateway, vnet, "DirectNetworkGuru", "Create"); - s_logger.debug("Upgraded Direct vms in Advance zone id=" + dcId); + logger.debug("Upgraded Direct vms in Advance zone id=" + dcId); upgradeDomR(conn, dcId, routerId, null, directNetworkId, controlNetworkId, "Advanced", vnet); - s_logger.debug("Upgraded Direct domRs in Advance zone id=" + dcId); + logger.debug("Upgraded Direct domRs in Advance zone id=" + dcId); } } } @@ -1166,7 +1164,7 @@ private void updateUserStats(Connection conn) { PreparedStatement pstmt = conn.prepareStatement("UPDATE user_statistics SET device_type='DomainRouter'"); ){ pstmt.executeUpdate(); - s_logger.debug("Upgraded userStatistcis with device_type=DomainRouter"); + logger.debug("Upgraded userStatistcis with device_type=DomainRouter"); // update device_id information try ( @@ -1182,7 +1180,7 @@ private void updateUserStats(Connection conn) { selectNetworkType.setLong(1, dataCenterId); try (ResultSet dcSet = selectNetworkType.executeQuery();) { if (!dcSet.next()) { - s_logger.error("Unable to get data_center information as a part of user_statistics update"); + logger.error("Unable to get data_center information as a part of user_statistics update"); throw new CloudRuntimeException("Unable to get data_center information as a part of user_statistics update"); } String dataCenterType = dcSet.getString(1); @@ -1204,7 +1202,7 @@ private void updateUserStats(Connection conn) { selectnonRemovedVms.setLong(2, dataCenterId); try (ResultSet nonRemovedVms = selectnonRemovedVms.executeQuery();) { if (nonRemovedVms.next()) { - s_logger.warn("Failed to find domR for account id=" + accountId + " in zone id=" + dataCenterId + + logger.warn("Failed to find domR for account id=" + accountId + " in zone id=" + dataCenterId + "; will try to locate domR based on user_vm info"); //try to get domR information from the user_vm belonging to the account try (PreparedStatement selectNetworkType = @@ -1213,14 +1211,14 @@ private void updateUserStats(Connection conn) { selectNetworkType.setLong(2, dataCenterId); try (ResultSet userVmSet = selectNetworkType.executeQuery();) { if (!userVmSet.next()) { - s_logger.warn("Skipping user_statistics upgrade for account id=" + accountId + " in datacenter id=" + dataCenterId); + logger.warn("Skipping user_statistics upgrade for account id=" + accountId + " in datacenter id=" + dataCenterId); continue; } deviceId = userVmSet.getLong(1); } } } else { - s_logger.debug("Account id=" + accountId + " doesn't own any user vms and domRs, so skipping user_statistics update"); + logger.debug("Account id=" + accountId + " doesn't own any user vms and domRs, so skipping user_statistics update"); continue; } } @@ -1237,7 +1235,7 @@ private void updateUserStats(Connection conn) { } } } - s_logger.debug("Upgraded userStatistcis with deviceId(s)"); + logger.debug("Upgraded userStatistcis with deviceId(s)"); } catch (Exception e) { throw new CloudRuntimeException("Failed to migrate usage events: ", e); @@ -1263,7 +1261,7 @@ public void upgradePortForwardingRules(Connection conn) { } if (!rules.isEmpty()) { - s_logger.debug("Found " + rules.size() + " port forwarding rules to upgrade"); + logger.debug("Found " + rules.size() + " port forwarding rules to upgrade"); for (Object[] rule : rules) { long id = (Long)rule[0]; String sourcePort = (String)rule[2]; @@ -1275,7 +1273,7 @@ public void upgradePortForwardingRules(Connection conn) { try (ResultSet userIpAddressData = selectUserIpAddressData.executeQuery();) { if (!userIpAddressData.next()) { - s_logger.error("Unable to find public IP address " + publicIp); + logger.error("Unable to find public IP address " + publicIp); throw new CloudRuntimeException("Unable to find public IP address " + publicIp); } int ipAddressId = userIpAddressData.getInt(1); @@ -1285,7 +1283,7 @@ public void upgradePortForwardingRules(Connection conn) { String privateIp = (String)rule[3]; // update port_forwarding_rules table - s_logger.trace("Updating port_forwarding_rules table..."); + logger.trace("Updating port_forwarding_rules table..."); try (PreparedStatement selectInstanceId = conn.prepareStatement("SELECT instance_id FROM nics where network_id=? AND ip4_address=?");) { selectInstanceId.setLong(1, networkId); selectInstanceId.setString(2, privateIp); @@ -1293,14 +1291,14 @@ public void upgradePortForwardingRules(Connection conn) { if (!selectedInstanceId.next()) { // the vm might be expunged already...so just give the warning - s_logger.warn("Unable to find vmId for private ip address " + privateIp + " for account id=" + accountId + "; assume that the vm is expunged"); + logger.warn("Unable to find vmId for private ip address " + privateIp + " for account id=" + accountId + "; assume that the vm is expunged"); // throw new CloudRuntimeException("Unable to find vmId for private ip address " + privateIp + // " for account id=" + accountId); } else { long instanceId = selectedInstanceId.getLong(1); - s_logger.debug("Instance id is " + instanceId); + logger.debug("Instance id is " + instanceId); // update firewall_rules table - s_logger.trace("Updating firewall_rules table as a part of PF rules upgrade..."); + logger.trace("Updating firewall_rules table as a part of PF rules upgrade..."); try ( PreparedStatement insertFirewallRules = conn.prepareStatement("INSERT INTO firewall_rules (id, ip_address_id, start_port, end_port, state, protocol, purpose, account_id, domain_id, network_id, xid, is_static_nat, created) VALUES (?, ?, ?, ?, 'Active', ?, 'PortForwarding', ?, ?, ?, ?, 0, now())"); @@ -1315,7 +1313,7 @@ public void upgradePortForwardingRules(Connection conn) { insertFirewallRules.setLong(8, networkId); insertFirewallRules.setString(9, UUID.randomUUID().toString()); insertFirewallRules.executeUpdate(); - s_logger.trace("firewall_rules table is updated as a part of PF rules upgrade"); + logger.trace("firewall_rules table is updated as a part of PF rules upgrade"); } String privatePort = (String)rule[4]; try (PreparedStatement insertPortForwardingRules = conn.prepareStatement("INSERT INTO port_forwarding_rules VALUES (?, ?, ?, ?, ?)");) { @@ -1326,7 +1324,7 @@ public void upgradePortForwardingRules(Connection conn) { insertPortForwardingRules.setInt(5, Integer.parseInt(privatePort.trim())); insertPortForwardingRules.executeUpdate(); } - s_logger.trace("port_forwarding_rules table is updated"); + logger.trace("port_forwarding_rules table is updated"); } } } @@ -1334,7 +1332,7 @@ public void upgradePortForwardingRules(Connection conn) { } } } - s_logger.debug("Port forwarding rules are updated"); + logger.debug("Port forwarding rules are updated"); } catch (SQLException e) { throw new CloudRuntimeException("Can't update port forwarding rules ", e); } @@ -1358,7 +1356,7 @@ public void upgradeLoadBalancingRules(Connection conn) { } if (!lbs.isEmpty()) { - s_logger.debug("Found " + lbs.size() + " lb rules to upgrade"); + logger.debug("Found " + lbs.size() + " lb rules to upgrade"); long newLbId = 0; try ( PreparedStatement selectFWRules = conn.prepareStatement("SELECT max(id) FROM firewall_rules order by id"); @@ -1382,7 +1380,7 @@ public void upgradeLoadBalancingRules(Connection conn) { try (ResultSet ipData = selectIpData.executeQuery();) { if (!ipData.next()) { - s_logger.warn("Unable to find public IP address " + publicIp + "; skipping lb rule id=" + originalLbId + + logger.warn("Unable to find public IP address " + publicIp + "; skipping lb rule id=" + originalLbId + " from update. Cleaning it up from load_balancer_vm_map and load_balancer table"); try (PreparedStatement deleteLbVmMap = conn.prepareStatement("DELETE from load_balancer_vm_map where load_balancer_id=?");) { deleteLbVmMap.setLong(1, originalLbId); @@ -1399,7 +1397,7 @@ public void upgradeLoadBalancingRules(Connection conn) { long domainId = ipData.getLong(3); long networkId = ipData.getLong(4); // update firewall_rules table - s_logger.trace("Updating firewall_rules table as a part of LB rules upgrade..."); + logger.trace("Updating firewall_rules table as a part of LB rules upgrade..."); try (PreparedStatement insertFirewallRules = conn.prepareStatement("INSERT INTO firewall_rules (id, ip_address_id, start_port, end_port, state, protocol, purpose, account_id, domain_id, network_id, xid, is_static_nat, created) VALUES (?, ?, ?, ?, 'Active', ?, 'LoadBalancing', ?, ?, ?, ?, 0, now())");) { insertFirewallRules.setLong(1, newLbId); @@ -1413,13 +1411,13 @@ public void upgradeLoadBalancingRules(Connection conn) { insertFirewallRules.setString(9, UUID.randomUUID().toString()); insertFirewallRules.executeUpdate(); } - s_logger.trace("firewall_rules table is updated as a part of LB rules upgrade"); + logger.trace("firewall_rules table is updated as a part of LB rules upgrade"); } } // update load_balancing_rules - s_logger.trace("Updating load_balancing_rules table as a part of LB rules upgrade..."); + logger.trace("Updating load_balancing_rules table as a part of LB rules upgrade..."); try (PreparedStatement insertLoadBalancer = conn.prepareStatement("INSERT INTO load_balancing_rules VALUES (?, ?, NULL, ?, ?, ?)");) { insertLoadBalancer.setLong(1, newLbId); insertLoadBalancer.setString(2, name); @@ -1428,10 +1426,10 @@ public void upgradeLoadBalancingRules(Connection conn) { insertLoadBalancer.setString(5, algorithm); insertLoadBalancer.executeUpdate(); } - s_logger.trace("load_balancing_rules table is updated as a part of LB rules upgrade"); + logger.trace("load_balancing_rules table is updated as a part of LB rules upgrade"); // update load_balancer_vm_map table - s_logger.trace("Updating load_balancer_vm_map table as a part of LB rules upgrade..."); + logger.trace("Updating load_balancer_vm_map table as a part of LB rules upgrade..."); try ( PreparedStatement selectInstance = conn.prepareStatement("SELECT instance_id FROM load_balancer_vm_map WHERE load_balancer_id=?"); ) { @@ -1451,10 +1449,10 @@ public void upgradeLoadBalancingRules(Connection conn) { updateLoadBalancer.setLong(2, originalLbId); updateLoadBalancer.executeUpdate(); } - s_logger.trace("load_balancer_vm_map table is updated as a part of LB rules upgrade"); + logger.trace("load_balancer_vm_map table is updated as a part of LB rules upgrade"); } } - s_logger.debug("LB rules are upgraded"); + logger.debug("LB rules are upgraded"); } catch (SQLException e) { throw new CloudRuntimeException("Can't update LB rules ", e); } @@ -1724,7 +1722,7 @@ private void migrateEvents(Connection conn) { ResultSet rs1 = pstmt1.executeQuery(); ) { if (!rs1.next()) { - s_logger.debug("cloud_usage db doesn't exist. Skipping events migration"); + logger.debug("cloud_usage db doesn't exist. Skipping events migration"); return; } @@ -1734,7 +1732,7 @@ private void migrateEvents(Connection conn) { String sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.id > ? and vmevt.state = 'Completed' "; if (lastProcessedEvent == null) { - s_logger.trace("no events are processed earlier, copying all events"); + logger.trace("no events are processed earlier, copying all events"); sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.state = 'Completed' "; } @@ -1744,7 +1742,7 @@ private void migrateEvents(Connection conn) { pstmt.setLong(i++, lastProcessedEvent); } try (ResultSet rs = pstmt.executeQuery();) { - s_logger.debug("Begin Migrating events"); + logger.debug("Begin Migrating events"); while (rs.next()) { EventVO event = new EventVO(); event.setType(rs.getString(1)); @@ -1758,7 +1756,7 @@ private void migrateEvents(Connection conn) { } } } - s_logger.debug("Migrating events completed"); + logger.debug("Migrating events completed"); } catch (Exception e) { throw new CloudRuntimeException("Failed to migrate usage events: ", e); } @@ -2142,7 +2140,7 @@ public void performDataMigration(Connection conn) { cleanupLbVmMaps(conn); } catch (SQLException e) { - s_logger.error("Can't perform data migration ", e); + logger.error("Can't perform data migration ", e); throw new CloudRuntimeException("Can't perform data migration ", e); } @@ -2180,7 +2178,7 @@ private void deleteOrphanedTemplateRef(Connection conn) { ResultSet rs = selectStoragePoolRef.executeQuery(); ) { if (!rs.next()) { - s_logger.debug("No records in template_spool_ref, skipping this upgrade part"); + logger.debug("No records in template_spool_ref, skipping this upgrade part"); return; } while (rs.next()) { @@ -2192,7 +2190,7 @@ private void deleteOrphanedTemplateRef(Connection conn) { try (ResultSet selectedStoragePool = selectStoragePool.executeQuery();) { if (!selectedStoragePool.next()) { - s_logger.debug("Orphaned template_spool_ref record is found (storage pool doesn't exist any more0) id=" + id + "; so removing the record"); + logger.debug("Orphaned template_spool_ref record is found (storage pool doesn't exist any more0) id=" + id + "; so removing the record"); try (PreparedStatement delete = conn.prepareStatement("DELETE FROM template_spool_ref where id=?");) { delete.setLong(1, id); delete.executeUpdate(); @@ -2201,9 +2199,9 @@ private void deleteOrphanedTemplateRef(Connection conn) { } } } - s_logger.debug("Finished deleting orphaned template_spool_ref(s)"); + logger.debug("Finished deleting orphaned template_spool_ref(s)"); } catch (Exception e) { - s_logger.error("Failed to delete orphaned template_spool_ref(s): ", e); + logger.error("Failed to delete orphaned template_spool_ref(s): ", e); throw new CloudRuntimeException("Failed to delete orphaned template_spool_ref(s): ", e); } } @@ -2215,7 +2213,7 @@ private void cleanupVolumes(Connection conn) { ){ while (selectedVolumes.next()) { Long id = selectedVolumes.getLong(1); - s_logger.debug("Volume id is " + id); + logger.debug("Volume id is " + id); Long instanceId = selectedVolumes.getLong(2); Long accountId = selectedVolumes.getLong(3); @@ -2245,15 +2243,15 @@ private void cleanupVolumes(Connection conn) { try(PreparedStatement pstmt = conn.prepareStatement("UPDATE volumes SET state='Destroy' WHERE id=?");) { pstmt.setLong(1, id); pstmt.executeUpdate(); - s_logger.debug("Volume with id=" + id + " is marked with Destroy state as a part of volume cleanup (it's Destroyed had 127 value)"); + logger.debug("Volume with id=" + id + " is marked with Destroy state as a part of volume cleanup (it's Destroyed had 127 value)"); } } } } } - s_logger.debug("Finished cleaning up volumes with incorrect Destroyed field (127)"); + logger.debug("Finished cleaning up volumes with incorrect Destroyed field (127)"); } catch (Exception e) { - s_logger.error("Failed to cleanup volumes with incorrect Destroyed field (127):", e); + logger.error("Failed to cleanup volumes with incorrect Destroyed field (127):", e); throw new CloudRuntimeException("Failed to cleanup volumes with incorrect Destroyed field (127):", e); } } @@ -2267,7 +2265,7 @@ private void modifyIndexes(Connection conn) { if (result__index.next()) { try (PreparedStatement alterTable = conn.prepareStatement("ALTER TABLE `cloud`.`security_group` DROP INDEX `fk_network_group__account_id`");) { alterTable.executeUpdate(); - s_logger.debug("Unique key 'fk_network_group__account_id' is removed successfully"); + logger.debug("Unique key 'fk_network_group__account_id' is removed successfully"); } } @@ -2278,7 +2276,7 @@ private void modifyIndexes(Connection conn) { if (result___index.next()) { try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`security_group` DROP INDEX `fk_network_group___account_id`");) { pstmt.executeUpdate(); - s_logger.debug("Unique key 'fk_network_group___account_id' is removed successfully"); + logger.debug("Unique key 'fk_network_group___account_id' is removed successfully"); } } } @@ -2310,7 +2308,7 @@ private void cleanupLbVmMaps(Connection conn) { ResultSet rs2 = pstmt2.executeQuery(); ) { if (!rs1.next() && rs2.next()) { - s_logger.debug("Removing load balancer vm mappings for lb id=" + lbId + " as a part of cleanup"); + logger.debug("Removing load balancer vm mappings for lb id=" + lbId + " as a part of cleanup"); try (PreparedStatement delete = conn.prepareStatement("DELETE FROM load_balancer_vm_map where load_balancer_id=?");) { delete.setLong(1, lbId); delete.executeUpdate(); @@ -2329,7 +2327,7 @@ private void cleanupLbVmMaps(Connection conn) { * Create usage events for existing port forwarding rules */ private void createPortForwardingEvents(Connection conn) { - s_logger.debug("Creating Port Forwarding usage events"); + logger.debug("Creating Port Forwarding usage events"); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT fw.account_id, ip.data_center_id, fw.id FROM firewall_rules fw, user_ip_address ip where purpose = 'PortForwarding' and " @@ -2354,7 +2352,7 @@ private void createPortForwardingEvents(Connection conn) { pstmt1.executeUpdate(); } } - s_logger.debug("Completed creating Port Forwarding usage events"); + logger.debug("Completed creating Port Forwarding usage events"); } catch (SQLException e) { throw new CloudRuntimeException("Failed to add port forwarding usage events due to:", e); } @@ -2364,7 +2362,7 @@ private void createPortForwardingEvents(Connection conn) { * Create usage events for existing load balancer rules */ private void createLoadBalancerEvents(Connection conn) { - s_logger.debug("Creating load balancer usage events"); + logger.debug("Creating load balancer usage events"); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT fw.account_id, ip.data_center_id, fw.id FROM firewall_rules fw, user_ip_address ip where purpose = 'LoadBalancing' and " @@ -2389,7 +2387,7 @@ private void createLoadBalancerEvents(Connection conn) { pstmt1.executeUpdate(); } } - s_logger.debug("Completed creating load balancer usage events"); + logger.debug("Completed creating load balancer usage events"); } catch (SQLException e) { throw new CloudRuntimeException("Failed to add Load Balancer usage events due to:", e); } @@ -2399,7 +2397,7 @@ private void createLoadBalancerEvents(Connection conn) { * Create usage events for network offerings */ private void createNetworkOfferingEvents(Connection conn) { - s_logger.debug("Creating network offering usage events"); + logger.debug("Creating network offering usage events"); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT vm.account_id, vm.data_center_id, ni.instance_id, vm.name, nw.network_offering_id, nw.is_default FROM nics ni, " @@ -2429,7 +2427,7 @@ private void createNetworkOfferingEvents(Connection conn) { pstmt1.executeUpdate(); } } - s_logger.debug("Completed creating network offering usage events"); + logger.debug("Completed creating network offering usage events"); } catch (SQLException e) { throw new CloudRuntimeException("Failed to add network offering usage events due to:", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java index 5f66728e6d9f..65a71993e912 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java @@ -23,12 +23,10 @@ import java.sql.SQLException; import java.util.HashMap; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade218to224DomainVlans implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade218to224DomainVlans.class); +public class Upgrade218to224DomainVlans extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { @@ -42,7 +40,7 @@ public void performDataMigration(Connection conn) { try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM networks WHERE shared=1 AND traffic_type='Guest' AND guest_type='Direct'"); ResultSet rs = pstmt.executeQuery(); - s_logger.debug("query is " + pstmt); + logger.debug("query is " + pstmt); while (rs.next()) { Long networkId = rs.getLong(1); Long vlanId = null; @@ -50,7 +48,7 @@ public void performDataMigration(Connection conn) { pstmt = conn.prepareStatement("SELECT id FROM vlan WHERE network_id=? LIMIT 0,1"); pstmt.setLong(1, networkId); - s_logger.debug("query is " + pstmt); + logger.debug("query is " + pstmt); rs = pstmt.executeQuery(); while (rs.next()) { @@ -60,7 +58,7 @@ public void performDataMigration(Connection conn) { if (vlanId != null) { pstmt = conn.prepareStatement("SELECT domain_id FROM account_vlan_map WHERE domain_id IS NOT NULL AND vlan_db_id=? LIMIT 0,1"); pstmt.setLong(1, vlanId); - s_logger.debug("query is " + pstmt); + logger.debug("query is " + pstmt); rs = pstmt.executeQuery(); while (rs.next()) { @@ -118,7 +116,7 @@ private void performDbCleanup(Connection conn) { try { pstmt.executeQuery(); } catch (SQLException e) { - s_logger.debug("Assuming that domain_id field doesn't exist in account_vlan_map table, no need to upgrade"); + logger.debug("Assuming that domain_id field doesn't exist in account_vlan_map table, no need to upgrade"); return; } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22Premium.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22Premium.java index d21d1ce4e662..d5106925e998 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22Premium.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22Premium.java @@ -52,7 +52,7 @@ private void updateUserStats(Connection conn) { ) { pstmt.executeUpdate(); - s_logger.debug("Upgraded cloud_usage user_statistics with deviceId"); + logger.debug("Upgraded cloud_usage user_statistics with deviceId"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade user stats: ", e); } @@ -64,7 +64,7 @@ private void updateUserStats(Connection conn) { ) { pstmt1.executeUpdate(); - s_logger.debug("Upgraded cloud_usage usage_network with hostId"); + logger.debug("Upgraded cloud_usage usage_network with hostId"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade network usage stats: ", e); } @@ -78,7 +78,7 @@ private void updateUsageIpAddress(Connection conn) { ) { pstmt.executeUpdate(); - s_logger.debug("Upgraded cloud_usage usage_ip_address with Id"); + logger.debug("Upgraded cloud_usage usage_ip_address with Id"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade usage_ip_address: ", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2210to2211.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2210to2211.java index db1452270805..ba456a62953e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2210to2211.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2210to2211.java @@ -21,7 +21,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2210to2211 implements DbUpgrade { +public class Upgrade2210to2211 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212.java index f8175386df52..1c4868d61b0e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212.java @@ -24,12 +24,10 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2211to2212 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade2211to2212.class); +public class Upgrade2211to2212 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -68,7 +66,7 @@ public InputStream[] getCleanupScripts() { } private void createResourceCount(Connection conn) { - s_logger.debug("Creating missing resource_count records as a part of 2.2.11-2.2.12 upgrade"); + logger.debug("Creating missing resource_count records as a part of 2.2.11-2.2.12 upgrade"); try { //Get all non removed accounts @@ -99,7 +97,7 @@ private void createResourceCount(Connection conn) { pstmt.setLong(2, accountId); rs = pstmt.executeQuery(); if (!rs.next()) { - s_logger.debug("Inserting resource_count record of type " + resourceType + " for account id=" + accountId); + logger.debug("Inserting resource_count record of type " + resourceType + " for account id=" + accountId); pstmt = conn.prepareStatement("INSERT INTO resource_count (account_id, domain_id, type, count) VALUES (?, null, ?, 0)"); pstmt.setLong(1, accountId); pstmt.setString(2, resourceType); @@ -117,7 +115,7 @@ private void createResourceCount(Connection conn) { pstmt.setLong(2, domainId); rs = pstmt.executeQuery(); if (!rs.next()) { - s_logger.debug("Inserting resource_count record of type " + resourceType + " for domain id=" + domainId); + logger.debug("Inserting resource_count record of type " + resourceType + " for domain id=" + domainId); pstmt = conn.prepareStatement("INSERT INTO resource_count (account_id, domain_id, type, count) VALUES (null, ?, ?, 0)"); pstmt.setLong(1, domainId); pstmt.setString(2, resourceType); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212Premium.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212Premium.java index 374483811368..d2f0f00ee0a3 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212Premium.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212Premium.java @@ -18,12 +18,10 @@ import java.io.InputStream; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade2211to2212Premium extends Upgrade2211to2212 { - final static Logger s_logger = Logger.getLogger(Upgrade2211to2212Premium.class); @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2212to2213.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2212to2213.java index 7debe2ec378a..809e23c1b5a0 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2212to2213.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2212to2213.java @@ -24,12 +24,10 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2212to2213 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade2212to2213.class); +public class Upgrade2212to2213 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -74,7 +72,7 @@ private void fixForeignKeys(Connection conn) { foreignKeys.put("networks", keys); // drop all foreign keys - s_logger.debug("Dropping old key fk_networks__data_center_id..."); + logger.debug("Dropping old key fk_networks__data_center_id..."); for (String tableName : foreignKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, foreignKeys.get(tableName), true); } @@ -95,7 +93,7 @@ private void fixForeignKeys(Connection conn) { try { PreparedStatement pstmt = conn.prepareStatement("drop index network_offering_id on cloud_usage.usage_network_offering"); pstmt.executeUpdate(); - s_logger.debug("Dropped usage_network_offering unique key"); + logger.debug("Dropped usage_network_offering unique key"); } catch (Exception e) { // Ignore error if the usage_network_offering table or the unique key doesn't exist } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2213to2214.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2213to2214.java index 9dc3f5be2d8f..6299abf10304 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2213to2214.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2213to2214.java @@ -23,12 +23,10 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2213to2214 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade2213to2214.class); +public class Upgrade2213to2214 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2214to30.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2214to30.java index d806490d87df..524b6a34893b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2214to30.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2214to30.java @@ -29,7 +29,6 @@ import java.util.Map; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.offering.NetworkOffering; import com.cloud.utils.crypt.DBEncryptionUtil; @@ -37,8 +36,7 @@ import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade2214to30.class); +public class Upgrade2214to30 extends Upgrade30xBase { @Override public String[] getUpgradableVersionRange() { @@ -183,7 +181,7 @@ private void setupPhysicalNetworks(Connection conn) { pstmt2.setLong(1, zoneId); ResultSet rsTags = pstmt2.executeQuery(); if (rsTags.next()) { - s_logger.debug("Network tags are not empty, might have to create more than one physical network..."); + logger.debug("Network tags are not empty, might have to create more than one physical network..."); //make sure setup does not use guest vnets if (vnet != null) { @@ -214,7 +212,7 @@ private void setupPhysicalNetworks(Connection conn) { + "6. Reconfigure the vnet ranges for each physical network as desired by using updatePhysicalNetwork API \n" + "7. Start all your VMs"; - s_logger.error(message); + logger.error(message); throw new CloudRuntimeException( "Cannot upgrade this setup since it uses guest vnet and will have multiple physical networks. Please check the logs for details on how to proceed"); @@ -263,7 +261,7 @@ private void setupPhysicalNetworks(Connection conn) { if (crtPbNtwk) { addTrafficType(conn, physicalNetworkId, "Public", xenPublicLabel, kvmPublicLabel, vmwarePublicLabel); } else { - s_logger.debug("Skip adding public traffic type to zone id=" + zoneId); + logger.debug("Skip adding public traffic type to zone id=" + zoneId); } addTrafficType(conn, physicalNetworkId, "Management", xenPrivateLabel, kvmPrivateLabel, vmwarePrivateLabel); addTrafficType(conn, physicalNetworkId, "Storage", xenStorageLabel, null, null); @@ -276,9 +274,9 @@ private void setupPhysicalNetworks(Connection conn) { PreparedStatement pstmt3 = conn.prepareStatement("SELECT network_id FROM `cloud`.`network_tags` where tag= ?"); pstmt3.setString(1,guestNetworkTag); ResultSet rsNet = pstmt3.executeQuery(); - s_logger.debug("Adding PhysicalNetwork to VLAN"); - s_logger.debug("Adding PhysicalNetwork to user_ip_address"); - s_logger.debug("Adding PhysicalNetwork to networks"); + logger.debug("Adding PhysicalNetwork to VLAN"); + logger.debug("Adding PhysicalNetwork to user_ip_address"); + logger.debug("Adding PhysicalNetwork to networks"); while (rsNet.next()) { Long networkId = rsNet.getLong(1); addPhysicalNtwk_To_Ntwk_IP_Vlan(conn, physicalNetworkId, networkId); @@ -288,7 +286,7 @@ private void setupPhysicalNetworks(Connection conn) { // add the reference to this physical network for the default public network entries in vlan / user_ip_address tables // add first physicalNetworkId to op_dc_vnet_alloc for this zone - just a placeholder since direct networking don't need this if (isFirstPhysicalNtwk) { - s_logger.debug("Adding PhysicalNetwork to default Public network entries in vlan and user_ip_address"); + logger.debug("Adding PhysicalNetwork to default Public network entries in vlan and user_ip_address"); pstmt3 = conn.prepareStatement("SELECT id FROM `cloud`.`networks` where traffic_type = 'Public' and data_center_id = " + zoneId); ResultSet rsPubNet = pstmt3.executeQuery(); if (rsPubNet.next()) { @@ -297,7 +295,7 @@ private void setupPhysicalNetworks(Connection conn) { } pstmt3.close(); - s_logger.debug("Adding PhysicalNetwork to op_dc_vnet_alloc"); + logger.debug("Adding PhysicalNetwork to op_dc_vnet_alloc"); String updateVnet = "UPDATE `cloud`.`op_dc_vnet_alloc` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId; pstmtUpdate = conn.prepareStatement(updateVnet); pstmtUpdate.executeUpdate(); @@ -314,7 +312,7 @@ private void setupPhysicalNetworks(Connection conn) { if (crtPbNtwk) { addTrafficType(conn, physicalNetworkId, "Public", xenPublicLabel, kvmPublicLabel, vmwarePublicLabel); } else { - s_logger.debug("Skip adding public traffic type to zone id=" + zoneId); + logger.debug("Skip adding public traffic type to zone id=" + zoneId); } addTrafficType(conn, physicalNetworkId, "Management", xenPrivateLabel, kvmPrivateLabel, vmwarePrivateLabel); addTrafficType(conn, physicalNetworkId, "Storage", xenStorageLabel, null, null); @@ -323,28 +321,28 @@ private void setupPhysicalNetworks(Connection conn) { addDefaultSGProvider(conn, physicalNetworkId, zoneId, networkType, false); // add physicalNetworkId to op_dc_vnet_alloc for this zone - s_logger.debug("Adding PhysicalNetwork to op_dc_vnet_alloc"); + logger.debug("Adding PhysicalNetwork to op_dc_vnet_alloc"); String updateVnet = "UPDATE `cloud`.`op_dc_vnet_alloc` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId; pstmtUpdate = conn.prepareStatement(updateVnet); pstmtUpdate.executeUpdate(); pstmtUpdate.close(); // add physicalNetworkId to vlan for this zone - s_logger.debug("Adding PhysicalNetwork to VLAN"); + logger.debug("Adding PhysicalNetwork to VLAN"); String updateVLAN = "UPDATE `cloud`.`vlan` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId; pstmtUpdate = conn.prepareStatement(updateVLAN); pstmtUpdate.executeUpdate(); pstmtUpdate.close(); // add physicalNetworkId to user_ip_address for this zone - s_logger.debug("Adding PhysicalNetwork to user_ip_address"); + logger.debug("Adding PhysicalNetwork to user_ip_address"); String updateUsrIp = "UPDATE `cloud`.`user_ip_address` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId; pstmtUpdate = conn.prepareStatement(updateUsrIp); pstmtUpdate.executeUpdate(); pstmtUpdate.close(); // add physicalNetworkId to guest networks for this zone - s_logger.debug("Adding PhysicalNetwork to networks"); + logger.debug("Adding PhysicalNetwork to networks"); String updateNet = "UPDATE `cloud`.`networks` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId + " AND traffic_type = 'Guest'"; pstmtUpdate = conn.prepareStatement(updateNet); @@ -370,17 +368,17 @@ private void setupPhysicalNetworks(Connection conn) { } private void encryptData(Connection conn) { - s_logger.debug("Encrypting the data..."); + logger.debug("Encrypting the data..."); encryptConfigValues(conn); encryptHostDetails(conn); encryptVNCPassword(conn); encryptUserCredentials(conn); encryptVPNPassword(conn); - s_logger.debug("Done encrypting the data"); + logger.debug("Done encrypting the data"); } private void encryptConfigValues(Connection conn) { - s_logger.debug("Encrypting Config values"); + logger.debug("Encrypting Config values"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -412,14 +410,14 @@ private void encryptConfigValues(Connection conn) { pstmt.close(); } } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } - s_logger.debug("Done encrypting Config values"); + logger.debug("Done encrypting Config values"); } private void encryptHostDetails(Connection conn) { - s_logger.debug("Encrypting host details"); + logger.debug("Encrypting host details"); List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; ResultSet rs = null; @@ -447,11 +445,11 @@ private void encryptHostDetails(Connection conn) { } finally { TransactionLegacy.closePstmts(pstmt2Close); } - s_logger.debug("Done encrypting host details"); + logger.debug("Done encrypting host details"); } private void encryptVNCPassword(Connection conn) { - s_logger.debug("Encrypting vm_instance vnc_password"); + logger.debug("Encrypting vm_instance vnc_password"); List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; ResultSet rs = null; @@ -493,11 +491,11 @@ private void encryptVNCPassword(Connection conn) { } finally { TransactionLegacy.closePstmts(pstmt2Close); } - s_logger.debug("Done encrypting vm_instance vnc_password"); + logger.debug("Done encrypting vm_instance vnc_password"); } private void encryptUserCredentials(Connection conn) { - s_logger.debug("Encrypting user keys"); + logger.debug("Encrypting user keys"); List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; ResultSet rs = null; @@ -526,11 +524,11 @@ private void encryptUserCredentials(Connection conn) { } finally { TransactionLegacy.closePstmts(pstmt2Close); } - s_logger.debug("Done encrypting user keys"); + logger.debug("Done encrypting user keys"); } private void encryptVPNPassword(Connection conn) { - s_logger.debug("Encrypting vpn_users password"); + logger.debug("Encrypting vpn_users password"); List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; ResultSet rs = null; @@ -559,7 +557,7 @@ private void encryptVPNPassword(Connection conn) { } finally { TransactionLegacy.closePstmts(pstmt2Close); } - s_logger.debug("Done encrypting vpn_users password"); + logger.debug("Done encrypting vpn_users password"); } private void dropKeysIfExist(Connection conn) { @@ -570,7 +568,7 @@ private void dropKeysIfExist(Connection conn) { uniqueKeys.put("secondary_storage_vm", keys); // drop keys - s_logger.debug("Dropping public_ip_address keys from `cloud`.`secondary_storage_vm` and console_proxy tables..."); + logger.debug("Dropping public_ip_address keys from `cloud`.`secondary_storage_vm` and console_proxy tables..."); for (String tableName : uniqueKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, uniqueKeys.get(tableName), false); } @@ -697,7 +695,7 @@ private void updateDomainNetworkRef(Connection conn) { pstmt2Close.add(pstmt); pstmt.setBoolean(1, subdomainAccess); pstmt.executeUpdate(); - s_logger.debug("Successfully updated subdomain_access field in network_domain table with value " + subdomainAccess); + logger.debug("Successfully updated subdomain_access field in network_domain table with value " + subdomainAccess); } // convert zone level 2.2.x networks to ROOT domain 3.0 access networks @@ -710,7 +708,7 @@ private void updateDomainNetworkRef(Connection conn) { pstmt2Close.add(pstmt); pstmt.setLong(1, networkId); pstmt.executeUpdate(); - s_logger.debug("Successfully converted zone specific network id=" + networkId + " to the ROOT domain level network with subdomain access set to true"); + logger.debug("Successfully converted zone specific network id=" + networkId + " to the ROOT domain level network with subdomain access set to true"); } } catch (SQLException e) { @@ -745,7 +743,7 @@ protected void createNetworkServices(Connection conn) { pstmt.setString(3, provider); pstmt.executeUpdate(); } - s_logger.debug("Created service/provider map for network id=" + networkId); + logger.debug("Created service/provider map for network id=" + networkId); } } catch (SQLException e) { throw new CloudRuntimeException("Unable to create service/provider map for networks", e); @@ -757,7 +755,7 @@ protected void createNetworkServices(Connection conn) { protected void updateRouters(Connection conn) { PreparedStatement pstmt = null; try { - s_logger.debug("Updating domain_router table"); + logger.debug("Updating domain_router table"); pstmt = conn.prepareStatement("UPDATE domain_router, virtual_router_providers vrp LEFT JOIN (physical_network_service_providers pnsp INNER JOIN physical_network pntwk INNER JOIN vm_instance vm INNER JOIN domain_router vr) ON (vrp.nsp_id = pnsp.id AND pnsp.physical_network_id = pntwk.id AND pntwk.data_center_id = vm.data_center_id AND vm.id=vr.id) SET vr.element_id=vrp.id;"); pstmt.executeUpdate(); @@ -793,7 +791,7 @@ protected void updateReduntantRouters(Connection conn) { ntwkOffCount = rs1.getLong(1); } - s_logger.debug("Have " + ntwkOffCount + " networkOfferings"); + logger.debug("Have " + ntwkOffCount + " networkOfferings"); pstmt = conn.prepareStatement("CREATE TEMPORARY TABLE `cloud`.`network_offerings2` ENGINE=MEMORY SELECT * FROM `cloud`.`network_offerings` WHERE id=1"); pstmt2Close.add(pstmt); pstmt.executeUpdate(); @@ -803,7 +801,7 @@ protected void updateReduntantRouters(Connection conn) { while (rs.next()) { long networkId = rs.getLong(1); long networkOfferingId = rs.getLong(2); - s_logger.debug("Updating network offering for the network id=" + networkId + " as it has redundant routers"); + logger.debug("Updating network offering for the network id=" + networkId + " as it has redundant routers"); Long newNetworkOfferingId = null; if (!newNetworkOfferingMap.containsKey(networkOfferingId)) { @@ -852,7 +850,7 @@ protected void updateReduntantRouters(Connection conn) { pstmt.executeUpdate(); } - s_logger.debug("Successfully updated network offering id=" + networkId + " with new network offering id " + newNetworkOfferingId); + logger.debug("Successfully updated network offering id=" + networkId + " with new network offering id " + newNetworkOfferingId); } } catch (SQLException e) { @@ -863,7 +861,7 @@ protected void updateReduntantRouters(Connection conn) { pstmt.executeUpdate(); pstmt.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } TransactionLegacy.closePstmts(pstmt2Close); } @@ -873,7 +871,7 @@ protected void updateHostCapacity(Connection conn) { List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; try { - s_logger.debug("Updating op_host_capacity table, column capacity_state"); + logger.debug("Updating op_host_capacity table, column capacity_state"); pstmt = conn.prepareStatement("UPDATE op_host_capacity, host SET op_host_capacity.capacity_state='Disabled' where host.id=op_host_capacity.host_id and op_host_capacity.capacity_type in (0,1) and host.resource_state='Disabled';"); pstmt2Close.add(pstmt); @@ -912,7 +910,7 @@ protected void switchAccountSpecificNetworksToIsolated(Connection conn) { pstmt2Close.add(pstmt); rs = pstmt.executeQuery(); } catch (Exception ex) { - s_logger.debug("switch_to_isolated field is not present in networks table"); + logger.debug("switch_to_isolated field is not present in networks table"); if (pstmt != null) { pstmt.close(); } @@ -932,7 +930,7 @@ protected void switchAccountSpecificNetworksToIsolated(Connection conn) { ntwkOffCount = rs1.getLong(1); } - s_logger.debug("Have " + ntwkOffCount + " networkOfferings"); + logger.debug("Have " + ntwkOffCount + " networkOfferings"); pstmt = conn.prepareStatement("CREATE TEMPORARY TABLE `cloud`.`network_offerings2` ENGINE=MEMORY SELECT * FROM `cloud`.`network_offerings` WHERE id=1"); pstmt2Close.add(pstmt); pstmt.executeUpdate(); @@ -942,7 +940,7 @@ protected void switchAccountSpecificNetworksToIsolated(Connection conn) { while (rs.next()) { long networkId = rs.getLong(1); long networkOfferingId = rs.getLong(2); - s_logger.debug("Updating network offering for the network id=" + networkId + " as it has switch_to_isolated=1"); + logger.debug("Updating network offering for the network id=" + networkId + " as it has switch_to_isolated=1"); Long newNetworkOfferingId = null; if (!newNetworkOfferingMap.containsKey(networkOfferingId)) { @@ -983,7 +981,7 @@ protected void switchAccountSpecificNetworksToIsolated(Connection conn) { pstmt.executeUpdate(); } - s_logger.debug("Successfully updated network offering id=" + networkId + " with new network offering id " + newNetworkOfferingId); + logger.debug("Successfully updated network offering id=" + networkId + " with new network offering id " + newNetworkOfferingId); } try { @@ -992,7 +990,7 @@ protected void switchAccountSpecificNetworksToIsolated(Connection conn) { pstmt.executeUpdate(); } catch (SQLException ex) { // do nothing here - s_logger.debug("Caught SQLException when trying to drop switch_to_isolated column ", ex); + logger.debug("Caught SQLException when trying to drop switch_to_isolated column ", ex); } } catch (SQLException e) { @@ -1003,7 +1001,7 @@ protected void switchAccountSpecificNetworksToIsolated(Connection conn) { pstmt.executeUpdate(); pstmt.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } TransactionLegacy.closePstmts(pstmt2Close); } @@ -1057,7 +1055,7 @@ private void migrateUserConcentratedPlannerChoice(Connection conn) { pstmt.close(); } } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } } @@ -1107,7 +1105,7 @@ protected String fixNetworksWithExternalDevices(Connection conn) { while (rs.next()) { long networkId = rs.getLong(1); long networkOfferingId = rs.getLong(2); - s_logger.debug("Updating network offering for the network id=" + networkId + " as it has switch_to_isolated=1"); + logger.debug("Updating network offering for the network id=" + networkId + " as it has switch_to_isolated=1"); Long newNetworkOfferingId = null; if (!newNetworkOfferingMap.containsKey(networkOfferingId)) { uniqueName = "Isolated with external providers"; @@ -1150,7 +1148,7 @@ protected String fixNetworksWithExternalDevices(Connection conn) { pstmt.executeUpdate(); } - s_logger.debug("Successfully updated network id=" + networkId + " with new network offering id " + newNetworkOfferingId); + logger.debug("Successfully updated network id=" + networkId + " with new network offering id " + newNetworkOfferingId); } } catch (SQLException e) { @@ -1159,7 +1157,7 @@ protected String fixNetworksWithExternalDevices(Connection conn) { try (PreparedStatement dropStatement = conn.prepareStatement("DROP TABLE `cloud`.`network_offerings2`");){ dropStatement.executeUpdate(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } TransactionLegacy.closePstmts(pstmt2Close); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade221to222.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade221to222.java index 41198adb14bd..307b72c61ea5 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade221to222.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade221to222.java @@ -21,7 +21,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade221to222 implements DbUpgrade { +public class Upgrade221to222 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224.java index 51a929d0377e..b891b02ea572 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224.java @@ -25,13 +25,11 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.capacity.Capacity; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade222to224 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade222to224.class); +public class Upgrade222to224 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -64,7 +62,7 @@ private void fixRelatedFkeyOnNetworksTable(Connection conn) throws SQLException try { pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.debug("Ignore if the key is not there."); + logger.debug("Ignore if the key is not there."); } pstmt.close(); @@ -130,11 +128,11 @@ private void checkForDuplicatePublicNetworks(Connection conn) { } if (zonesWithDuplicateNetworks.size() > 0) { - s_logger.warn(errorMsg + zonesWithDuplicateNetworks); + logger.warn(errorMsg + zonesWithDuplicateNetworks); } } catch (SQLException e) { - s_logger.warn(e); + logger.warn(e); throw new CloudRuntimeException("Unable to check for duplicate public networks as part of 222 to 224 upgrade."); } } @@ -208,21 +206,21 @@ private void updateClusterIdInOpHostCapacity(Connection conn) { try { pstmtUpdate.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } if (rs != null) { try { rs.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } @@ -275,7 +273,7 @@ private void updateUserStatsWithNetwork(Connection conn) { ResultSet rs1 = pstmt.executeQuery(); if (rs1.next()) { - s_logger.debug("Not updating user_statistics table for domR id=" + instanceId + " as domR is already expunged"); + logger.debug("Not updating user_statistics table for domR id=" + instanceId + " as domR is already expunged"); continue; } @@ -301,7 +299,7 @@ private void updateUserStatsWithNetwork(Connection conn) { rs.close(); pstmt.close(); - s_logger.debug("Upgraded user_statistics with networkId for DomainRouter device type"); + logger.debug("Upgraded user_statistics with networkId for DomainRouter device type"); // update network_id information for ExternalFirewall and ExternalLoadBalancer device types PreparedStatement pstmt1 = @@ -310,9 +308,9 @@ private void updateUserStatsWithNetwork(Connection conn) { pstmt1.executeUpdate(); pstmt1.close(); - s_logger.debug("Upgraded user_statistics with networkId for ExternalFirewall and ExternalLoadBalancer device types"); + logger.debug("Upgraded user_statistics with networkId for ExternalFirewall and ExternalLoadBalancer device types"); - s_logger.debug("Successfully update user_statistics table with network_ids as a part of 222 to 224 upgrade"); + logger.debug("Successfully update user_statistics table with network_ids as a part of 222 to 224 upgrade"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to update user_statistics table with network_ids as a part of 222 to 224 upgrade", e); @@ -327,7 +325,7 @@ private void dropIndexIfExists(Connection conn) { if (rs.next()) { pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`domain` DROP INDEX `path`"); pstmt.executeUpdate(); - s_logger.debug("Unique key 'path' is removed successfully"); + logger.debug("Unique key 'path' is removed successfully"); } rs.close(); @@ -346,7 +344,7 @@ private void fixBasicZoneNicCount(Connection conn) { Long zoneId = rs.getLong(1); Long networkId = null; Long vmCount = 0L; - s_logger.debug("Updating basic zone id=" + zoneId + " with correct nic count"); + logger.debug("Updating basic zone id=" + zoneId + " with correct nic count"); pstmt = conn.prepareStatement("SELECT id from networks where data_center_id=? AND guest_type='Direct'"); pstmt.setLong(1, zoneId); @@ -372,7 +370,7 @@ private void fixBasicZoneNicCount(Connection conn) { } - s_logger.debug("Basic zones are updated with correct nic counts successfully"); + logger.debug("Basic zones are updated with correct nic counts successfully"); rs.close(); pstmt.close(); } catch (SQLException e) { @@ -386,7 +384,7 @@ private void updateTotalCPUInOpHostCapacity(Connection conn) { PreparedStatement pstmtUpdate = null; try { // Load all Routing hosts - s_logger.debug("Updating total CPU capacity entries in op_host_capacity"); + logger.debug("Updating total CPU capacity entries in op_host_capacity"); pstmt = conn.prepareStatement("SELECT id, cpus, speed FROM host WHERE type = 'Routing'"); rs = pstmt.executeQuery(); while (rs.next()) { @@ -410,21 +408,21 @@ private void updateTotalCPUInOpHostCapacity(Connection conn) { try { pstmtUpdate.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } if (rs != null) { try { rs.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } @@ -439,7 +437,7 @@ private void upgradeGuestOs(Connection conn) { if (!rs.next()) { pstmt = conn.prepareStatement("INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (138, 7, 'None')"); pstmt.executeUpdate(); - s_logger.debug("Inserted NONE category to guest_os table"); + logger.debug("Inserted NONE category to guest_os table"); } rs.close(); @@ -488,7 +486,7 @@ private void updateFkeysAndIndexes(Connection conn) throws SQLException { try { pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.debug("Ignore if the key is not there."); + logger.debug("Ignore if the key is not there."); } pstmt.close(); } @@ -499,7 +497,7 @@ private void updateFkeysAndIndexes(Connection conn) throws SQLException { try { pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.debug("Ignore if the index is not there."); + logger.debug("Ignore if the index is not there."); } pstmt.close(); } @@ -613,7 +611,7 @@ private void fixIPResourceCount(Connection conn) throws SQLException { pstmt.close(); - s_logger.debug("Resource limit is cleaned up successfully as a part of db upgrade"); + logger.debug("Resource limit is cleaned up successfully as a part of db upgrade"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224Premium.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224Premium.java index ac7bd120c3da..cc5d3399fa6d 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224Premium.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224Premium.java @@ -20,12 +20,10 @@ import java.sql.Connection; import java.sql.PreparedStatement; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade222to224Premium extends Upgrade222to224 { - final static Logger s_logger = Logger.getLogger(Upgrade222to224Premium.class); @Override public InputStream[] getPrepareScripts() { @@ -55,7 +53,7 @@ private void updateUserStats(Connection conn) { ) { pstmt.executeUpdate(); - s_logger.debug("Upgraded cloud_usage user_statistics with networkId"); + logger.debug("Upgraded cloud_usage user_statistics with networkId"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade user stats: ", e); } @@ -66,7 +64,7 @@ private void updateUserStats(Connection conn) { + "us.network_id where us.account_id = un.account_id and us.data_center_id = un.zone_id and us.device_id = un.host_id"); ) { pstmt1.executeUpdate(); - s_logger.debug("Upgraded cloud_usage usage_network with networkId"); + logger.debug("Upgraded cloud_usage usage_network with networkId"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade user stats: ", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade224to225.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade224to225.java index 48908f5c7d53..4d88e1a6f401 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade224to225.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade224to225.java @@ -25,12 +25,10 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade224to225 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade224to225.class); +public class Upgrade224to225 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { @@ -80,7 +78,7 @@ public boolean supportsRollingUpgrade() { } private void createSecurityGroups(Connection conn) { - s_logger.debug("Creating missing default security group as a part of 224-225 upgrade"); + logger.debug("Creating missing default security group as a part of 224-225 upgrade"); try { List accounts = new ArrayList(); PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM account WHERE removed IS NULL and id != 1"); @@ -95,7 +93,7 @@ private void createSecurityGroups(Connection conn) { pstmt.setLong(1, accountId); rs = pstmt.executeQuery(); if (!rs.next()) { - s_logger.debug("Default security group is missing for account id=" + accountId + " so adding it"); + logger.debug("Default security group is missing for account id=" + accountId + " so adding it"); // get accountName/domainId information @@ -208,7 +206,7 @@ private void dropTableColumnsIfExist(Connection conn) { columns.add("guest_ip_type"); tablesToModify.put("service_offering", columns); - s_logger.debug("Dropping columns that don't exist in 2.2.5 version of the DB..."); + logger.debug("Dropping columns that don't exist in 2.2.5 version of the DB..."); for (String tableName : tablesToModify.keySet()) { DbUpgradeUtils.dropTableColumnsIfExist(conn, tableName, tablesToModify.get(tableName)); } @@ -277,7 +275,7 @@ private void dropKeysIfExist(Connection conn) { indexes.put("remote_access_vpn", keys); // drop all foreign keys first - s_logger.debug("Dropping keys that don't exist in 2.2.5 version of the DB..."); + logger.debug("Dropping keys that don't exist in 2.2.5 version of the DB..."); for (String tableName : foreignKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, foreignKeys.get(tableName), true); } @@ -291,7 +289,7 @@ private void dropKeysIfExist(Connection conn) { private void addMissingKeys(Connection conn) { PreparedStatement pstmt = null; try { - s_logger.debug("Adding missing foreign keys"); + logger.debug("Adding missing foreign keys"); HashMap keyToTableMap = new HashMap(); keyToTableMap.put("fk_console_proxy__id", "console_proxy"); @@ -325,13 +323,13 @@ private void addMissingKeys(Connection conn) { pstmt = conn.prepareStatement("ALTER TABLE " + tableName + " ADD CONSTRAINT " + key + " FOREIGN KEY " + keyToStatementMap.get(key)); pstmt.executeUpdate(); - s_logger.debug("Added missing key " + key + " to table " + tableName); + logger.debug("Added missing key " + key + " to table " + tableName); rs.close(); } - s_logger.debug("Missing keys were added successfully as a part of 224 to 225 upgrade"); + logger.debug("Missing keys were added successfully as a part of 224 to 225 upgrade"); pstmt.close(); } catch (SQLException e) { - s_logger.error("Unable to add missing foreign key; following statement was executed:" + pstmt); + logger.error("Unable to add missing foreign key; following statement was executed:" + pstmt); throw new CloudRuntimeException("Unable to add missing keys due to exception", e); } } @@ -341,13 +339,13 @@ private void addMissingOvsAccount(Connection conn) { PreparedStatement pstmt = conn.prepareStatement("SELECT * from ovs_tunnel_account"); ResultSet rs = pstmt.executeQuery(); if (!rs.next()) { - s_logger.debug("Adding missing ovs tunnel account"); + logger.debug("Adding missing ovs tunnel account"); pstmt = conn.prepareStatement("INSERT INTO `cloud`.`ovs_tunnel_account` (`from`, `to`, `account`, `key`, `port_name`, `state`) VALUES (0, 0, 0, 0, 'lock', 'SUCCESS')"); pstmt.executeUpdate(); } } catch (SQLException e) { - s_logger.error("Unable to add missing ovs tunnel account due to ", e); + logger.error("Unable to add missing ovs tunnel account due to ", e); throw new CloudRuntimeException("Unable to add missing ovs tunnel account due to ", e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade225to226.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade225to226.java index f606d6e756f4..99bf1f981daa 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade225to226.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade225to226.java @@ -22,12 +22,10 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade225to226 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade225to226.class); +public class Upgrade225to226 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { @@ -75,7 +73,7 @@ private void dropTableColumnsIfExist(Connection conn) { columns.add("domain_id"); tablesToModify.put("domain_router", columns); - s_logger.debug("Dropping columns that don't exist in 2.2.6 version of the DB..."); + logger.debug("Dropping columns that don't exist in 2.2.6 version of the DB..."); for (String tableName : tablesToModify.keySet()) { DbUpgradeUtils.dropTableColumnsIfExist(conn, tableName, tablesToModify.get(tableName)); } @@ -95,7 +93,7 @@ private void dropKeysIfExist(Connection conn) { indexes.put("domain_router", keys); // drop all foreign keys first - s_logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); + logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); for (String tableName : foreignKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, foreignKeys.get(tableName), true); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228.java index 7d665718db44..3c85ee21d1bd 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228.java @@ -23,12 +23,10 @@ import java.sql.SQLException; import java.util.ArrayList; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade227to228 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade227to228.class); +public class Upgrade227to228 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -79,7 +77,7 @@ public void performDataMigration(Connection conn) { pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.error("Failed to DB migration for multiple secondary storages", e); + logger.error("Failed to DB migration for multiple secondary storages", e); throw new CloudRuntimeException("Failed to DB migration for multiple secondary storages", e); } @@ -93,7 +91,7 @@ public InputStream[] getCleanupScripts() { } private void updateDomainLevelNetworks(Connection conn) { - s_logger.debug("Updating domain level specific networks..."); + logger.debug("Updating domain level specific networks..."); try { PreparedStatement pstmt = conn.prepareStatement("SELECT n.id FROM networks n, network_offerings o WHERE n.shared=1 AND o.system_only=0 AND o.id=n.network_offering_id"); @@ -113,7 +111,7 @@ private void updateDomainLevelNetworks(Connection conn) { pstmt.setLong(1, networkId); rs = pstmt.executeQuery(); if (rs.next()) { - s_logger.debug("Setting network id=" + networkId + " as domain specific shared network"); + logger.debug("Setting network id=" + networkId + " as domain specific shared network"); pstmt = conn.prepareStatement("UPDATE networks set is_domain_specific=1 where id=?"); pstmt.setLong(1, networkId); pstmt.executeUpdate(); @@ -122,9 +120,9 @@ private void updateDomainLevelNetworks(Connection conn) { pstmt.close(); } - s_logger.debug("Successfully updated domain level specific networks"); + logger.debug("Successfully updated domain level specific networks"); } catch (SQLException e) { - s_logger.error("Failed to set domain specific shared networks due to ", e); + logger.error("Failed to set domain specific shared networks due to ", e); throw new CloudRuntimeException("Failed to set domain specific shared networks due to ", e); } } @@ -132,7 +130,7 @@ private void updateDomainLevelNetworks(Connection conn) { //this method inserts missing volume.delete events (events were missing when vm failed to create) private void updateVolumeUsageRecords(Connection conn) { try { - s_logger.debug("Inserting missing usage_event records for destroyed volumes..."); + logger.debug("Inserting missing usage_event records for destroyed volumes..."); PreparedStatement pstmt = conn.prepareStatement("select id, account_id, data_center_id, name from volumes where state='Destroy' and id in (select resource_id from usage_event where type='volume.create') and id not in (select resource_id from usage_event where type='volume.delete')"); ResultSet rs = pstmt.executeQuery(); @@ -151,9 +149,9 @@ private void updateVolumeUsageRecords(Connection conn) { pstmt.executeUpdate(); } - s_logger.debug("Successfully inserted missing usage_event records for destroyed volumes"); + logger.debug("Successfully inserted missing usage_event records for destroyed volumes"); } catch (SQLException e) { - s_logger.error("Failed to insert missing delete usage records ", e); + logger.error("Failed to insert missing delete usage records ", e); throw new CloudRuntimeException("Failed to insert missing delete usage records ", e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228Premium.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228Premium.java index 032fb58da862..4787017ce4b5 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228Premium.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228Premium.java @@ -22,12 +22,10 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade227to228Premium extends Upgrade227to228 { - final static Logger s_logger = Logger.getLogger(Upgrade227to228Premium.class); @Override public InputStream[] getPrepareScripts() { @@ -59,7 +57,7 @@ private void addSourceIdColumn(Connection conn) { ResultSet rs = pstmt.executeQuery(); if (rs.next()) { - s_logger.info("The source id field already exist, not adding it"); + logger.info("The source id field already exist, not adding it"); } } catch (Exception e) { @@ -68,21 +66,21 @@ private void addSourceIdColumn(Connection conn) { } if (insertField) { - s_logger.debug("Adding source_id to usage_storage..."); + logger.debug("Adding source_id to usage_storage..."); pstmt = conn.prepareStatement("ALTER TABLE `cloud_usage`.`usage_storage` ADD COLUMN `source_id` bigint unsigned"); pstmt.executeUpdate(); - s_logger.debug("Column source_id was added successfully to usage_storage table"); + logger.debug("Column source_id was added successfully to usage_storage table"); pstmt.close(); } } catch (SQLException e) { - s_logger.error("Failed to add source_id to usage_storage due to ", e); + logger.error("Failed to add source_id to usage_storage due to ", e); throw new CloudRuntimeException("Failed to add source_id to usage_storage due to ", e); } } private void addNetworkIdsToUserStats(Connection conn) { - s_logger.debug("Adding network IDs to user stats..."); + logger.debug("Adding network IDs to user stats..."); try { String stmt = "SELECT DISTINCT public_ip_address FROM `cloud`.`user_statistics` WHERE public_ip_address IS NOT null"; PreparedStatement pstmt = conn.prepareStatement(stmt); @@ -112,10 +110,10 @@ private void addNetworkIdsToUserStats(Connection conn) { rs.close(); pstmt.close(); - s_logger.debug("Successfully added network IDs to user stats."); + logger.debug("Successfully added network IDs to user stats."); } catch (SQLException e) { String errorMsg = "Failed to add network IDs to user stats."; - s_logger.error(errorMsg, e); + logger.error(errorMsg, e); throw new CloudRuntimeException(errorMsg, e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade228to229.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade228to229.java index c556cd900896..bd95a0671298 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade228to229.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade228to229.java @@ -24,12 +24,10 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade228to229 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade228to229.class); +public class Upgrade228to229 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -126,7 +124,7 @@ private void dropKeysIfExist(Connection conn) { foreignKeys.put("network_tags", keys); // drop all foreign keys first - s_logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); + logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); for (String tableName : foreignKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, foreignKeys.get(tableName), true); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade229to2210.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade229to2210.java index 1ad7e6d2b4c5..3d4725c108f2 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade229to2210.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade229to2210.java @@ -23,12 +23,10 @@ import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade229to2210 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade229to2210.class); +public class Upgrade229to2210 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -128,7 +126,7 @@ private void updateFirewallRules(Connection conn) { pstmt.setString(8, UUID.randomUUID().toString()); pstmt.setLong(9, id); - s_logger.debug("Updating firewall rule with the statement " + pstmt); + logger.debug("Updating firewall rule with the statement " + pstmt); pstmt.executeUpdate(); //get new FirewallRule update @@ -159,12 +157,12 @@ private void updateFirewallRules(Connection conn) { pstmt = conn.prepareStatement("update firewall_rules_cidrs set firewall_rule_id=? where firewall_rule_id=?"); pstmt.setLong(1, firewallRuleId); pstmt.setLong(2, id); - s_logger.debug("Updating existing cidrs for the rule id=" + id + " with the new Firewall rule id=" + firewallRuleId + " with statement" + pstmt); + logger.debug("Updating existing cidrs for the rule id=" + id + " with the new Firewall rule id=" + firewallRuleId + " with statement" + pstmt); pstmt.executeUpdate(); } else { pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')"); pstmt.setLong(1, firewallRuleId); - s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); + logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); pstmt.executeUpdate(); } } @@ -180,7 +178,7 @@ private void updateFirewallRules(Connection conn) { pstmt.close(); } } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade301to302.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade301to302.java index ba479b52f89f..28e8d89dff08 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade301to302.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade301to302.java @@ -26,12 +26,10 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade301to302 extends LegacyDbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade301to302.class); @Override public String[] getUpgradableVersionRange() { @@ -66,7 +64,7 @@ private void dropKeysIfExists(Connection conn) { keys.add("i_host__allocation_state"); uniqueKeys.put("host", keys); - s_logger.debug("Dropping i_host__allocation_state key in host table"); + logger.debug("Dropping i_host__allocation_state key in host table"); for (String tableName : uniqueKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, uniqueKeys.get(tableName), false); } @@ -129,7 +127,7 @@ protected void updateSharedNetworks(Connection conn) { pstmt = conn.prepareStatement("DELETE FROM `cloud`.`ntwk_offering_service_map` WHERE id=?"); pstmt.setLong(1, mapId); pstmt.executeUpdate(); - s_logger.debug("Deleted lb service for network offering id=" + ntwkOffId + " as it doesn't have source nat service enabled"); + logger.debug("Deleted lb service for network offering id=" + ntwkOffId + " as it doesn't have source nat service enabled"); //delete lb service for the network pstmt = @@ -144,7 +142,7 @@ protected void updateSharedNetworks(Connection conn) { pstmt = conn.prepareStatement("DELETE FROM `cloud`.`ntwk_service_map` WHERE id=?"); pstmt.setLong(1, mapId); pstmt.executeUpdate(); - s_logger.debug("Deleted lb service for network id=" + ntwkId + " as it doesn't have source nat service enabled"); + logger.debug("Deleted lb service for network id=" + ntwkId + " as it doesn't have source nat service enabled"); } } @@ -180,14 +178,14 @@ private void fixLastHostIdKey(Connection conn) { } private void changeEngine(Connection conn) { - s_logger.debug("Fixing engine and row_format for op_lock and op_nwgrp_work tables"); + logger.debug("Fixing engine and row_format for op_lock and op_nwgrp_work tables"); String sqlOpLock = "ALTER TABLE `cloud`.`op_lock` ENGINE=MEMORY, ROW_FORMAT = FIXED"; try ( PreparedStatement pstmt = conn.prepareStatement(sqlOpLock); ) { pstmt.executeUpdate(); } catch (Exception e) { - s_logger.debug("Failed do execute the statement " + sqlOpLock + ", moving on as it's not critical fix"); + logger.debug("Failed do execute the statement " + sqlOpLock + ", moving on as it's not critical fix"); } String sqlOpNwgrpWork = "ALTER TABLE `cloud`.`op_nwgrp_work` ENGINE=MEMORY, ROW_FORMAT = FIXED"; @@ -196,7 +194,7 @@ private void changeEngine(Connection conn) { ) { pstmt.executeUpdate(); } catch (Exception e) { - s_logger.debug("Failed do execute the statement " + sqlOpNwgrpWork + ", moving on as it's not critical fix"); + logger.debug("Failed do execute the statement " + sqlOpNwgrpWork + ", moving on as it's not critical fix"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to303.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to303.java index e07c98dd4489..91b9b3849a8d 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to303.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to303.java @@ -28,14 +28,12 @@ import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade302to303 extends LegacyDbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade302to303.class); @Override public String[] getUpgradableVersionRange() { @@ -142,7 +140,7 @@ private void setupExternalNetworkDevices(Connection conn) { private void addF5LoadBalancer(Connection conn, long hostId, long physicalNetworkId) { PreparedStatement pstmtUpdate = null; try { - s_logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); String insertF5 = "INSERT INTO `cloud`.`external_load_balancer_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, is_inline, is_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -169,7 +167,7 @@ private void addF5LoadBalancer(Connection conn, long hostId, long physicalNetwor private void addSrxFirewall(Connection conn, long hostId, long physicalNetworkId) { PreparedStatement pstmtUpdate = null; try { - s_logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); String insertSrx = "INSERT INTO `cloud`.`external_firewall_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -195,7 +193,7 @@ private void addF5ServiceProvider(Connection conn, long physicalNetworkId, long PreparedStatement pstmtUpdate = null; try { // add physical network service provider - F5BigIp - s_logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); + logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -219,7 +217,7 @@ private void addSrxServiceProvider(Connection conn, long physicalNetworkId, long PreparedStatement pstmtUpdate = null; try { // add physical network service provider - JuniperSRX - s_logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); + logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -241,7 +239,7 @@ private void addSrxServiceProvider(Connection conn, long physicalNetworkId, long private void encryptConfig(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Encrypting Config values"); + logger.debug("Encrypting Config values"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -268,7 +266,7 @@ private void encryptConfig(Connection conn) { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done encrypting Config values"); + logger.debug("Done encrypting Config values"); } @Override diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to40.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to40.java index eb0492cd288b..aa427252585f 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to40.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to40.java @@ -27,14 +27,12 @@ import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade302to40 extends Upgrade30xBase { - final static Logger s_logger = Logger.getLogger(Upgrade302to40.class); @Override public String[] getUpgradableVersionRange() { @@ -211,9 +209,9 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { if (rsSameLabel.next()) { Long sameLabelcount = rsSameLabel.getLong(1); if (sameLabelcount > 0) { - s_logger.error("There are untagged networks for which we need to add a physical network with Xen traffic label = 'xen.guest.network.device' config value, which is: " + + logger.error("There are untagged networks for which we need to add a physical network with Xen traffic label = 'xen.guest.network.device' config value, which is: " + xenGuestLabel); - s_logger.error("However already there are " + sameLabelcount + " physical networks setup with same traffic label, cannot upgrade"); + logger.error("However already there are " + sameLabelcount + " physical networks setup with same traffic label, cannot upgrade"); throw new CloudRuntimeException("Cannot upgrade this setup since a physical network with same traffic label: " + xenGuestLabel + " already exists, Please check logs and contact Support."); } @@ -230,9 +228,9 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { conn.prepareStatement("SELECT n.id FROM networks n WHERE n.physical_network_id IS NULL AND n.traffic_type = 'Guest' and n.data_center_id = ? and n.removed is null"); pstmt3.setLong(1, zoneId); ResultSet rsNet = pstmt3.executeQuery(); - s_logger.debug("Adding PhysicalNetwork to VLAN"); - s_logger.debug("Adding PhysicalNetwork to user_ip_address"); - s_logger.debug("Adding PhysicalNetwork to networks"); + logger.debug("Adding PhysicalNetwork to VLAN"); + logger.debug("Adding PhysicalNetwork to user_ip_address"); + logger.debug("Adding PhysicalNetwork to networks"); while (rsNet.next()) { Long networkId = rsNet.getLong(1); addPhysicalNtwk_To_Ntwk_IP_Vlan(conn, physicalNetworkId, networkId); @@ -253,7 +251,7 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { if (rs.next()) { Long count = rs.getLong(1); if (count > 1) { - s_logger.debug("There are " + count + " physical networks setup"); + logger.debug("There are " + count + " physical networks setup"); multiplePhysicalNetworks = true; } } @@ -272,7 +270,7 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { String networkId = rsVNet.getString(5); String vpid = rsVNet.getString(4); String npid = rsVNet.getString(6); - s_logger.error("Guest Vnet assignment is set wrongly . Cannot upgrade until that is corrected. Example- Vnet: " + vnet + + logger.error("Guest Vnet assignment is set wrongly . Cannot upgrade until that is corrected. Example- Vnet: " + vnet + " has physical network id: " + vpid + " ,but the guest network: " + networkId + " that uses it has physical network id: " + npid); String message = "Cannot upgrade. Your setup has multiple Physical Networks and is using guest Vnet that is assigned wrongly. " @@ -291,7 +289,7 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { + "5. Run upgrade. This will allocate all your guest vnet range to first physical network. \n" + "6. Reconfigure the vnet ranges for each physical network as desired by using updatePhysicalNetwork API \n" + "7. Start all your VMs"; - s_logger.error(message); + logger.error(message); throw new CloudRuntimeException("Cannot upgrade this setup since Guest Vnet assignment to the multiple physical " + "networks is incorrect. Please check the logs for details on how to proceed"); @@ -470,26 +468,26 @@ private void cloneOfferingAndAddTag(Connection conn, long networkOfferingId, lon pstmt = conn.prepareStatement("DROP TEMPORARY TABLE `cloud`.`network_offerings2`"); pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.info("[ignored] ",e); + logger.info("[ignored] ",e); } closeAutoCloseable(pstmt); } } private void addHostDetailsUniqueKey(Connection conn) { - s_logger.debug("Checking if host_details unique key exists, if not we will add it"); + logger.debug("Checking if host_details unique key exists, if not we will add it"); try ( PreparedStatement pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'"); ResultSet rs = pstmt.executeQuery(); ) { if (rs.next()) { - s_logger.debug("Unique key already exists on host_details - not adding new one"); + logger.debug("Unique key already exists on host_details - not adding new one"); } else { //add the key PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER IGNORE TABLE `cloud`.`host_details` ADD CONSTRAINT UNIQUE KEY `uk_host_id_name` (`host_id`, `name`)"); pstmtUpdate.executeUpdate(); - s_logger.debug("Unique key did not exist on host_details - added new one"); + logger.debug("Unique key did not exist on host_details - added new one"); pstmtUpdate.close(); } } catch (SQLException e) { @@ -499,7 +497,7 @@ private void addHostDetailsUniqueKey(Connection conn) { private void addVpcProvider(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Adding vpc provider to all physical networks in the system"); + logger.debug("Adding vpc provider to all physical networks in the system"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -534,7 +532,7 @@ private void addVpcProvider(Connection conn) { pstmt.setLong(1, providerId); pstmt.executeUpdate(); - s_logger.debug("Added VPC Virtual router provider for physical network id=" + pNtwkId); + logger.debug("Added VPC Virtual router provider for physical network id=" + pNtwkId); } } catch (SQLException e) { @@ -543,12 +541,12 @@ private void addVpcProvider(Connection conn) { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done adding VPC physical network service providers to all physical networks"); + logger.debug("Done adding VPC physical network service providers to all physical networks"); } private void updateRouterNetworkRef(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Updating router network ref"); + logger.debug("Updating router network ref"); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT d.id, d.network_id FROM `cloud`.`domain_router` d, `cloud`.`vm_instance` v " + "WHERE d.id=v.id AND v.removed is NULL"); PreparedStatement pstmt1 = conn.prepareStatement("SELECT guest_type from `cloud`.`networks` where id=?"); @@ -571,13 +569,13 @@ private void updateRouterNetworkRef(Connection conn) { pstmt2.setString(3, networkType); pstmt2.executeUpdate(); } - s_logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId); + logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId); } } catch (SQLException e) { throw new CloudRuntimeException("Failed to update the router/network reference ", e); } - s_logger.debug("Done updating router/network references"); + logger.debug("Done updating router/network references"); } private void fixForeignKeys(Connection conn) { @@ -693,7 +691,7 @@ private void setupExternalNetworkDevices(Connection conn) { } private void addF5LoadBalancer(Connection conn, long hostId, long physicalNetworkId) { - s_logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); String insertF5 = "INSERT INTO `cloud`.`external_load_balancer_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, is_inline, is_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -716,7 +714,7 @@ private void addF5LoadBalancer(Connection conn, long hostId, long physicalNetwor } private void addSrxFirewall(Connection conn, long hostId, long physicalNetworkId) { - s_logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); String insertSrx = "INSERT INTO `cloud`.`external_firewall_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -738,7 +736,7 @@ private void addSrxFirewall(Connection conn, long hostId, long physicalNetworkId private void addF5ServiceProvider(Connection conn, long physicalNetworkId, long zoneId) { // add physical network service provider - F5BigIp - s_logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); + logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -757,7 +755,7 @@ private void addF5ServiceProvider(Connection conn, long physicalNetworkId, long private void addSrxServiceProvider(Connection conn, long physicalNetworkId, long zoneId) { // add physical network service provider - JuniperSRX - s_logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); + logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -875,7 +873,7 @@ private void fixZoneUsingExternalDevices(Connection conn) { pstmtUpdate.setLong(2, networkId); pstmtUpdate.setLong(3, f5DeviceId); pstmtUpdate.executeUpdate(); - s_logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); + logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); // add mapping for the network in network_external_firewall_device_map String insertFwMapping = @@ -885,11 +883,11 @@ private void fixZoneUsingExternalDevices(Connection conn) { pstmtUpdate.setLong(2, networkId); pstmtUpdate.setLong(3, srxDevivceId); pstmtUpdate.executeUpdate(); - s_logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); + logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); } // update host details for F5 and SRX devices - s_logger.debug("Updating the host details for F5 and SRX devices"); + logger.debug("Updating the host details for F5 and SRX devices"); pstmt = conn.prepareStatement("SELECT host_id, name FROM `cloud`.`host_details` WHERE host_id=? OR host_id=?"); pstmt.setLong(1, f5HostId); pstmt.setLong(2, srxHostId); @@ -908,20 +906,20 @@ private void fixZoneUsingExternalDevices(Connection conn) { pstmt.setString(3, camlCaseName); pstmt.executeUpdate(); } - s_logger.debug("Successfully updated host details for F5 and SRX devices"); + logger.debug("Successfully updated host details for F5 and SRX devices"); } catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } finally { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.info("Successfully upgraded networks using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); + logger.info("Successfully upgraded networks using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); } } private void encryptConfig(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Encrypting Config values"); + logger.debug("Encrypting Config values"); try ( PreparedStatement pstmt = conn.prepareStatement("select name, value from `cloud`.`configuration` where name in ('router.ram.size', 'secondary.storage.vm', 'security.hash.key') and category <> 'Hidden'"); PreparedStatement pstmt1 = conn.prepareStatement("update `cloud`.`configuration` set value=?, category = 'Hidden' where name=?"); @@ -943,11 +941,11 @@ private void encryptConfig(Connection conn) { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt configuration values ", e); } - s_logger.debug("Done encrypting Config values"); + logger.debug("Done encrypting Config values"); } private void encryptClusterDetails(Connection conn) { - s_logger.debug("Encrypting cluster details"); + logger.debug("Encrypting cluster details"); try ( PreparedStatement pstmt = conn.prepareStatement("select id, value from `cloud`.`cluster_details` where name = 'password'"); PreparedStatement pstmt1 = conn.prepareStatement("update `cloud`.`cluster_details` set value=? where id=?"); @@ -969,6 +967,6 @@ private void encryptClusterDetails(Connection conn) { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt cluster_details values ", e); } - s_logger.debug("Done encrypting cluster_details"); + logger.debug("Done encrypting cluster_details"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade303to304.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade303to304.java index 03f69ddefc90..d713a1c85921 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade303to304.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade303to304.java @@ -24,13 +24,11 @@ import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade303to304.class); +public class Upgrade303to304 extends Upgrade30xBase { @Override public String[] getUpgradableVersionRange() { @@ -171,9 +169,9 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { if (rsSameLabel.next()) { Long sameLabelcount = rsSameLabel.getLong(1); if (sameLabelcount > 0) { - s_logger.error("There are untagged networks for which we need to add a physical network with Xen traffic label = 'xen.guest.network.device' config value, which is: " + + logger.error("There are untagged networks for which we need to add a physical network with Xen traffic label = 'xen.guest.network.device' config value, which is: " + xenGuestLabel); - s_logger.error("However already there are " + sameLabelcount + " physical networks setup with same traffic label, cannot upgrade"); + logger.error("However already there are " + sameLabelcount + " physical networks setup with same traffic label, cannot upgrade"); throw new CloudRuntimeException("Cannot upgrade this setup since a physical network with same traffic label: " + xenGuestLabel + " already exists, Please check logs and contact Support."); } @@ -188,9 +186,9 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { pstmt_network_id.setLong(1, zoneId); try (ResultSet rsNet = pstmt_network_id.executeQuery();) { - s_logger.debug("Adding PhysicalNetwork to VLAN"); - s_logger.debug("Adding PhysicalNetwork to user_ip_address"); - s_logger.debug("Adding PhysicalNetwork to networks"); + logger.debug("Adding PhysicalNetwork to VLAN"); + logger.debug("Adding PhysicalNetwork to user_ip_address"); + logger.debug("Adding PhysicalNetwork to networks"); while (rsNet.next()) { Long networkId = rsNet.getLong(1); addPhysicalNtwk_To_Ntwk_IP_Vlan(conn, physicalNetworkId, networkId); @@ -207,7 +205,7 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { if (rs.next()) { Long count = rs.getLong(1); if (count > 1) { - s_logger.debug("There are " + count + " physical networks setup"); + logger.debug("There are " + count + " physical networks setup"); multiplePhysicalNetworks = true; } } @@ -223,7 +221,7 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { String networkId = rsVNet.getString(5); String vpid = rsVNet.getString(4); String npid = rsVNet.getString(6); - s_logger.error("Guest Vnet assignment is set wrongly . Cannot upgrade until that is corrected. Example- Vnet: " + vnet + + logger.error("Guest Vnet assignment is set wrongly . Cannot upgrade until that is corrected. Example- Vnet: " + vnet + " has physical network id: " + vpid + " ,but the guest network: " + networkId + " that uses it has physical network id: " + npid); String message = "Cannot upgrade. Your setup has multiple Physical Networks and is using guest Vnet that is assigned wrongly. " @@ -242,7 +240,7 @@ private void correctMultiplePhysicaNetworkSetups(Connection conn) { + "5. Run upgrade. This will allocate all your guest vnet range to first physical network. \n" + "6. Reconfigure the vnet ranges for each physical network as desired by using updatePhysicalNetwork API \n" + "7. Start all your VMs"; - s_logger.error(message); + logger.error(message); throw new CloudRuntimeException("Cannot upgrade this setup since Guest Vnet assignment to the multiple physical networks " + "is incorrect. Please check the logs for details on how to proceed"); @@ -383,7 +381,7 @@ private void cloneOfferingAndAddTag(Connection conn, long networkOfferingId, lon try (PreparedStatement pstmt_drop_table = conn.prepareStatement("DROP TEMPORARY TABLE `cloud`.`network_offerings2`");) { pstmt_drop_table.executeUpdate(); } catch (SQLException e) { - s_logger.debug("drop of temp table 'network_offerings2' failed", e); + logger.debug("drop of temp table 'network_offerings2' failed", e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade304to305.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade304to305.java index a8009630976a..bb4c73f67b68 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade304to305.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade304to305.java @@ -27,13 +27,11 @@ import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade304to305 extends Upgrade30xBase { - final static Logger s_logger = Logger.getLogger(Upgrade304to305.class); @Override public String[] getUpgradableVersionRange() { @@ -99,7 +97,7 @@ private void updateSystemVms(Connection conn) { throw new CloudRuntimeException("Error while iterating through list of hypervisors in use", e); } // Just update the VMware system template. Other hypervisor templates are unchanged from previous 3.0.x versions. - s_logger.debug("Updating VMware System Vms"); + logger.debug("Updating VMware System Vms"); try { //Get 3.0.5 VMware system Vm template Id pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-vmware-3.0.5' and removed is null"); @@ -122,18 +120,18 @@ private void updateSystemVms(Connection conn) { if (VMware) { throw new CloudRuntimeException("3.0.5 VMware SystemVm template not found. Cannot upgrade system Vms"); } else { - s_logger.warn("3.0.5 VMware SystemVm template not found. VMware hypervisor is not used, so not failing upgrade"); + logger.warn("3.0.5 VMware SystemVm template not found. VMware hypervisor is not used, so not failing upgrade"); } } } catch (SQLException e) { throw new CloudRuntimeException("Error while updating VMware systemVm template", e); } - s_logger.debug("Updating System Vm Template IDs Complete"); + logger.debug("Updating System Vm Template IDs Complete"); } private void addVpcProvider(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Adding vpc provider to all physical networks in the system"); + logger.debug("Adding vpc provider to all physical networks in the system"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -168,7 +166,7 @@ private void addVpcProvider(Connection conn) { pstmt.setLong(1, providerId); pstmt.executeUpdate(); - s_logger.debug("Added VPC Virtual router provider for physical network id=" + pNtwkId); + logger.debug("Added VPC Virtual router provider for physical network id=" + pNtwkId); } } catch (SQLException e) { @@ -177,12 +175,12 @@ private void addVpcProvider(Connection conn) { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done adding VPC physical network service providers to all physical networks"); + logger.debug("Done adding VPC physical network service providers to all physical networks"); } private void updateRouterNetworkRef(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Updating router network ref"); + logger.debug("Updating router network ref"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -207,7 +205,7 @@ private void updateRouterNetworkRef(Connection conn) { pstmt.setString(3, networkType); pstmt.executeUpdate(); - s_logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId); + logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId); } } catch (SQLException e) { @@ -216,24 +214,24 @@ private void updateRouterNetworkRef(Connection conn) { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done updating router/network references"); + logger.debug("Done updating router/network references"); } private void addHostDetailsUniqueKey(Connection conn) { - s_logger.debug("Checking if host_details unique key exists, if not we will add it"); + logger.debug("Checking if host_details unique key exists, if not we will add it"); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'"); rs = pstmt.executeQuery(); if (rs.next()) { - s_logger.debug("Unique key already exists on host_details - not adding new one"); + logger.debug("Unique key already exists on host_details - not adding new one"); } else { //add the key PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER IGNORE TABLE `cloud`.`host_details` ADD CONSTRAINT UNIQUE KEY `uk_host_id_name` (`host_id`, `name`)"); pstmtUpdate.executeUpdate(); - s_logger.debug("Unique key did not exist on host_details - added new one"); + logger.debug("Unique key did not exist on host_details - added new one"); pstmtUpdate.close(); } } catch (SQLException e) { @@ -347,7 +345,7 @@ private void fixZoneUsingExternalDevices(Connection conn) { pstmtUpdate.setLong(2, networkId); pstmtUpdate.setLong(3, f5DeviceId); pstmtUpdate.executeUpdate(); - s_logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); + logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); // add mapping for the network in network_external_firewall_device_map String insertFwMapping = @@ -357,11 +355,11 @@ private void fixZoneUsingExternalDevices(Connection conn) { pstmtUpdate.setLong(2, networkId); pstmtUpdate.setLong(3, srxDevivceId); pstmtUpdate.executeUpdate(); - s_logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); + logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); } // update host details for F5 and SRX devices - s_logger.debug("Updating the host details for F5 and SRX devices"); + logger.debug("Updating the host details for F5 and SRX devices"); pstmt = conn.prepareStatement("SELECT host_id, name FROM `cloud`.`host_details` WHERE host_id=? OR host_id=?"); pstmt.setLong(1, f5HostId); pstmt.setLong(2, srxHostId); @@ -380,19 +378,19 @@ private void fixZoneUsingExternalDevices(Connection conn) { pstmt.setString(3, camlCaseName); pstmt.executeUpdate(); } - s_logger.debug("Successfully updated host details for F5 and SRX devices"); + logger.debug("Successfully updated host details for F5 and SRX devices"); } catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } finally { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); + logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); } } private void fixForeignKeys(Connection conn) { - s_logger.debug("Fixing foreign keys' names in ssh_keypairs table"); + logger.debug("Fixing foreign keys' names in ssh_keypairs table"); //Drop the keys (if exist) List keys = new ArrayList(); keys.add("fk_ssh_keypair__account_id"); @@ -434,7 +432,7 @@ private void fixForeignKeys(Connection conn) { } private void encryptClusterDetails(Connection conn) { - s_logger.debug("Encrypting cluster details"); + logger.debug("Encrypting cluster details"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -460,6 +458,6 @@ private void encryptClusterDetails(Connection conn) { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done encrypting cluster_details"); + logger.debug("Done encrypting cluster_details"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade305to306.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade305to306.java index 796287697a90..52aab2a13e9b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade305to306.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade305to306.java @@ -27,12 +27,10 @@ import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade305to306 extends Upgrade30xBase { - final static Logger s_logger = Logger.getLogger(Upgrade305to306.class); @Override public String[] getUpgradableVersionRange() { @@ -78,14 +76,14 @@ private void addIndexForAlert(Connection conn) { //First drop if it exists. (Due to patches shipped to customers some will have the index and some won't.) List indexList = new ArrayList(); - s_logger.debug("Dropping index i_alert__last_sent if it exists"); + logger.debug("Dropping index i_alert__last_sent if it exists"); indexList.add("i_alert__last_sent"); DbUpgradeUtils.dropKeysIfExist(conn, "alert", indexList, false); //Now add index. try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`alert` ADD INDEX `i_alert__last_sent`(`last_sent`)");) { pstmt.executeUpdate(); - s_logger.debug("Added index i_alert__last_sent for table alert"); + logger.debug("Added index i_alert__last_sent for table alert"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add index i_alert__last_sent to alert table for the column last_sent", e); } @@ -117,14 +115,14 @@ private void addIndexForHostDetails(Connection conn) { //First drop if it exists. (Due to patches shipped to customers some will have the index and some won't.) List indexList = new ArrayList(); - s_logger.debug("Dropping index fk_host_details__host_id if it exists"); + logger.debug("Dropping index fk_host_details__host_id if it exists"); indexList.add("fk_host_details__host_id"); DbUpgradeUtils.dropKeysIfExist(conn, "host_details", indexList, false); //Now add index. try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD INDEX `fk_host_details__host_id`(`host_id`)");) { pstmt.executeUpdate(); - s_logger.debug("Added index fk_host_details__host_id for table host_details"); + logger.debug("Added index fk_host_details__host_id for table host_details"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add index fk_host_details__host_id to host_details table for the column host_id", e); } @@ -140,7 +138,7 @@ private void upgradeEgressFirewallRules(Connection conn) { // update the existing ingress rules traffic type pstmt = conn.prepareStatement("update `cloud`.`firewall_rules`" + " set traffic_type='Ingress' where purpose='Firewall' and ip_address_id is not null and traffic_type is null"); - s_logger.debug("Updating firewall Ingress rule traffic type: " + pstmt); + logger.debug("Updating firewall Ingress rule traffic type: " + pstmt); pstmt.executeUpdate(); pstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='VirtualRouter' "); @@ -152,7 +150,7 @@ private void upgradeEgressFirewallRules(Connection conn) { pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='" + "Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? "); pstmt.setLong(1, netId); - s_logger.debug("Getting account_id, domain_id from networks table: " + pstmt); + logger.debug("Getting account_id, domain_id from networks table: " + pstmt); rsNw = pstmt.executeQuery(); if (rsNw.next()) { @@ -160,7 +158,7 @@ private void upgradeEgressFirewallRules(Connection conn) { long domainId = rsNw.getLong(2); //Add new rule for the existing networks - s_logger.debug("Adding default egress firewall rule for network " + netId); + logger.debug("Adding default egress firewall rule for network " + netId); pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created, traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')"); pstmt.setString(1, UUID.randomUUID().toString()); @@ -168,7 +166,7 @@ private void upgradeEgressFirewallRules(Connection conn) { pstmt.setLong(3, domainId); pstmt.setLong(4, netId); pstmt.setString(5, UUID.randomUUID().toString()); - s_logger.debug("Inserting default egress firewall rule " + pstmt); + logger.debug("Inserting default egress firewall rule " + pstmt); pstmt.executeUpdate(); pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?"); @@ -180,7 +178,7 @@ private void upgradeEgressFirewallRules(Connection conn) { firewallRuleId = rsId.getLong(1); pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')"); pstmt.setLong(1, firewallRuleId); - s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); + logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); pstmt.executeUpdate(); } } @@ -218,7 +216,7 @@ private void removeFirewallServiceFromSharedNetworkOfferingWithSGService(Connect private void fix22xKVMSnapshots(Connection conn) { PreparedStatement pstmt = null; ResultSet rs = null; - s_logger.debug("Updating KVM snapshots"); + logger.debug("Updating KVM snapshots"); try { pstmt = conn.prepareStatement("select id, backup_snap_id from `cloud`.`snapshots` where hypervisor_type='KVM' and removed is null and backup_snap_id is not null"); @@ -232,14 +230,14 @@ private void fix22xKVMSnapshots(Connection conn) { int index = backUpPath.indexOf("snapshots" + File.separator); if (index > 1) { String correctedPath = File.separator + backUpPath.substring(index); - s_logger.debug("Updating Snapshot with id: " + id + " original backup path: " + backUpPath + " updated backup path: " + correctedPath); + logger.debug("Updating Snapshot with id: " + id + " original backup path: " + backUpPath + " updated backup path: " + correctedPath); pstmt = conn.prepareStatement("UPDATE `cloud`.`snapshots` set backup_snap_id=? where id = ?"); pstmt.setString(1, correctedPath); pstmt.setLong(2, id); pstmt.executeUpdate(); } } - s_logger.debug("Done updating KVM snapshots"); + logger.debug("Done updating KVM snapshots"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to update backup id for KVM snapshots", e); } finally { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade306to307.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade306to307.java index 4eb39af51d7c..3d28d73031ac 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade306to307.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade306to307.java @@ -23,12 +23,10 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade306to307 extends Upgrade30xBase { - final static Logger s_logger = Logger.getLogger(Upgrade306to307.class); @Override public String[] getUpgradableVersionRange() { @@ -96,7 +94,7 @@ protected void updateConcurrentConnectionsInNetworkOfferings(Connection conn) { pstmt = conn.prepareStatement("drop table `cloud`.`network_details`"); pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.info("[ignored] error during network offering update:" + e.getLocalizedMessage(), e); + logger.info("[ignored] error during network offering update:" + e.getLocalizedMessage(), e); } finally { closeAutoCloseable(rs); closeAutoCloseable(rs1); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade307to410.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade307to410.java index 1554ff04f701..1d47717a2de5 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade307to410.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade307to410.java @@ -23,13 +23,11 @@ import java.sql.SQLException; import java.util.Properties; -import org.apache.log4j.Logger; import com.cloud.utils.db.DbProperties; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade307to410 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade307to410.class); +public class Upgrade307to410 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -71,7 +69,7 @@ private void updateRegionEntries(Connection conn) { } try (PreparedStatement pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");){ //Update regionId in region table - s_logger.debug("Updating region table with Id: " + region_id); + logger.debug("Updating region table with Id: " + region_id); pstmt.setInt(1, region_id); pstmt.executeUpdate(); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30to301.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30to301.java index 806cabb12eb2..ba17082bab52 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30to301.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30to301.java @@ -22,13 +22,11 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.configuration.Resource.ResourceType; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade30to301 extends LegacyDbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade30to301.class); @Override public String[] getUpgradableVersionRange() { @@ -95,7 +93,7 @@ protected void udpateAccountNetworkResourceCount(Connection conn) { pstmt.setLong(1, accountId); pstmt.setLong(2, count); pstmt.executeUpdate(); - s_logger.debug("Updated network resource count for account id=" + accountId + " to be " + count); + logger.debug("Updated network resource count for account id=" + accountId + " to be " + count); } } catch (SQLException e) { throw new CloudRuntimeException("Unable to update network resource count for account id=" + accountId, e); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30xBase.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30xBase.java index 47b877d5aa5b..d2dd77365339 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30xBase.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30xBase.java @@ -23,13 +23,11 @@ import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public abstract class Upgrade30xBase extends LegacyDbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade30xBase.class); protected String getNetworkLabelFromConfig(Connection conn, String name) { String sql = "SELECT value FROM `cloud`.`configuration` where name = ?"; @@ -72,7 +70,7 @@ protected long addPhysicalNetworkToZone(Connection conn, long zoneId, String zon broadcastDomainRange = "ZONE"; } - s_logger.debug("Adding PhysicalNetwork " + physicalNetworkId + " for Zone id " + zoneId); + logger.debug("Adding PhysicalNetwork " + physicalNetworkId + " for Zone id " + zoneId); String sql = "INSERT INTO `cloud`.`physical_network` (id, uuid, data_center_id, vnet, broadcast_domain_range, state, name) VALUES (?,?,?,?,?,?,?)"; pstmtUpdate = conn.prepareStatement(sql); @@ -84,12 +82,12 @@ protected long addPhysicalNetworkToZone(Connection conn, long zoneId, String zon pstmtUpdate.setString(6, "Enabled"); zoneName = zoneName + "-pNtwk" + physicalNetworkId; pstmtUpdate.setString(7, zoneName); - s_logger.warn("Statement is " + pstmtUpdate.toString()); + logger.warn("Statement is " + pstmtUpdate.toString()); pstmtUpdate.executeUpdate(); pstmtUpdate.close(); if (domainId != null && domainId.longValue() != 0) { - s_logger.debug("Updating domain_id for physical network id=" + physicalNetworkId); + logger.debug("Updating domain_id for physical network id=" + physicalNetworkId); sql = "UPDATE `cloud`.`physical_network` set domain_id=? where id=?"; pstmtUpdate = conn.prepareStatement(sql); pstmtUpdate.setLong(1, domainId); @@ -111,7 +109,7 @@ protected void addTrafficType(Connection conn, long physicalNetworkId, String tr // add traffic types PreparedStatement pstmtUpdate = null; try { - s_logger.debug("Adding PhysicalNetwork traffic types"); + logger.debug("Adding PhysicalNetwork traffic types"); String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` (physical_network_id, traffic_type, xen_network_label, kvm_network_label, vmware_network_label, uuid) VALUES ( ?, ?, ?, ?, ?, ?)"; pstmtUpdate = conn.prepareStatement(insertTraficType); @@ -154,7 +152,7 @@ protected void addDefaultSGProvider(Connection conn, long physicalNetworkId, lon pstmt2.close(); if (isSGServiceEnabled) { - s_logger.debug("Adding PhysicalNetworkServiceProvider SecurityGroupProvider to the physical network id=" + physicalNetworkId); + logger.debug("Adding PhysicalNetworkServiceProvider SecurityGroupProvider to the physical network id=" + physicalNetworkId); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -182,7 +180,7 @@ protected void addDefaultVRProvider(Connection conn, long physicalNetworkId, lon PreparedStatement pstmtUpdate = null, pstmt2 = null; try { // add physical network service provider - VirtualRouter - s_logger.debug("Adding PhysicalNetworkServiceProvider VirtualRouter"); + logger.debug("Adding PhysicalNetworkServiceProvider VirtualRouter"); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade40to41.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade40to41.java index 3e15ff6782b3..6dc58fdda792 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade40to41.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade40to41.java @@ -25,13 +25,11 @@ import java.util.Properties; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.db.DbProperties; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade40to41 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade40to41.class); +public class Upgrade40to41 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -85,7 +83,7 @@ private void updateRegionEntries(Connection conn) { } try (PreparedStatement pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");) { //Update regionId in region table - s_logger.debug("Updating region table with Id: " + region_id); + logger.debug("Updating region table with Id: " + region_id); pstmt.setInt(1, region_id); pstmt.executeUpdate(); @@ -101,7 +99,7 @@ private void upgradeEgressFirewallRules(Connection conn) { "not null and traffic_type is null");) { updateNwpstmt.executeUpdate(); - s_logger.debug("Updating firewall Ingress rule traffic type: " + updateNwpstmt); + logger.debug("Updating firewall Ingress rule traffic type: " + updateNwpstmt); } catch (SQLException e) { throw new CloudRuntimeException("Unable to update ingress firewall rules ", e); } @@ -120,13 +118,13 @@ private void upgradeEgressFirewallRules(Connection conn) { NwAcctDomIdpstmt.setLong(1, netId); try (ResultSet NwAcctDomIdps = NwAcctDomIdpstmt.executeQuery();) { - s_logger.debug("Getting account_id, domain_id from networks table: " + NwAcctDomIdpstmt); + logger.debug("Getting account_id, domain_id from networks table: " + NwAcctDomIdpstmt); if (NwAcctDomIdps.next()) { long accountId = NwAcctDomIdps.getLong(1); long domainId = NwAcctDomIdps.getLong(2); //Add new rule for the existing networks - s_logger.debug("Adding default egress firewall rule for network " + netId); + logger.debug("Adding default egress firewall rule for network " + netId); try (PreparedStatement fwRulespstmt = conn.prepareStatement("INSERT INTO firewall_rules "+ " (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created," + " traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), " @@ -137,7 +135,7 @@ private void upgradeEgressFirewallRules(Connection conn) { fwRulespstmt.setLong(3, domainId); fwRulespstmt.setLong(4, netId); fwRulespstmt.setString(5, UUID.randomUUID().toString()); - s_logger.debug("Inserting default egress firewall rule " + fwRulespstmt); + logger.debug("Inserting default egress firewall rule " + fwRulespstmt); fwRulespstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("failed to insert default egress firewall rule ", e); @@ -154,7 +152,7 @@ private void upgradeEgressFirewallRules(Connection conn) { try (PreparedStatement fwCidrsPstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");) { fwCidrsPstmt.setLong(1, firewallRuleId); - s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + fwCidrsPstmt); + logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + fwCidrsPstmt); fwCidrsPstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Unable to set egress firewall rules ", e); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41000to41100.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41000to41100.java index 3900cf0bf82d..9b2a7fcc0bb3 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41000to41100.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41000to41100.java @@ -25,14 +25,12 @@ import java.util.Map; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; import com.cloud.utils.PropertiesUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41000to41100 implements DbUpgrade { +public class Upgrade41000to41100 extends DbUpgradeAbstractImpl { - final static Logger LOG = Logger.getLogger(Upgrade41000to41100.class); @Override public String[] getUpgradableVersionRange() { @@ -69,16 +67,16 @@ public void performDataMigration(Connection conn) { private void checkAndEnableDynamicRoles(final Connection conn) { final Map apiMap = PropertiesUtil.processConfigFile(new String[] { "commands.properties" }); if (apiMap == null || apiMap.isEmpty()) { - if (LOG.isDebugEnabled()) { - LOG.debug("No commands.properties file was found, enabling dynamic roles by setting dynamic.apichecker.enabled to true if not already enabled."); + if (logger.isDebugEnabled()) { + logger.debug("No commands.properties file was found, enabling dynamic roles by setting dynamic.apichecker.enabled to true if not already enabled."); } try (final PreparedStatement updateStatement = conn.prepareStatement("INSERT INTO cloud.configuration (category, instance, name, default_value, value) VALUES ('Advanced', 'DEFAULT', 'dynamic.apichecker.enabled', 'false', 'true') ON DUPLICATE KEY UPDATE value='true'")) { updateStatement.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to set dynamic.apichecker.enabled to true, please run migrate-dynamicroles.py script to manually migrate to dynamic roles.", e); + logger.error("Failed to set dynamic.apichecker.enabled to true, please run migrate-dynamicroles.py script to manually migrate to dynamic roles.", e); } } else { - LOG.warn("Old commands.properties static checker is deprecated, please use migrate-dynamicroles.py to migrate to dynamic roles. Refer http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/latest/accounts.html#using-dynamic-roles"); + logger.warn("Old commands.properties static checker is deprecated, please use migrate-dynamicroles.py to migrate to dynamic roles. Refer http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/latest/accounts.html#using-dynamic-roles"); } } @@ -96,19 +94,19 @@ private void validateUserDataInBase64(Connection conn) { updateStatement.setLong(2, userVmId); updateStatement.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " with exception: " + e.getMessage()); + logger.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " with exception: " + e.getMessage()); throw new CloudRuntimeException("Exception while updating cloud.user_vm for id " + userVmId, e); } } } else { // Update to NULL since it's invalid - LOG.warn("Removing user_data for vm id " + userVmId + " because it's invalid"); - LOG.warn("Removed data was: " + userData); + logger.warn("Removing user_data for vm id " + userVmId + " because it's invalid"); + logger.warn("Removed data was: " + userData); try (final PreparedStatement updateStatement = conn.prepareStatement("UPDATE `cloud`.`user_vm` SET `user_data` = NULL WHERE `id` = ? ;")) { updateStatement.setLong(1, userVmId); updateStatement.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " to NULL with exception: " + e.getMessage()); + logger.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " to NULL with exception: " + e.getMessage()); throw new CloudRuntimeException("Exception while updating cloud.user_vm for id " + userVmId + " to NULL", e); } } @@ -116,8 +114,8 @@ private void validateUserDataInBase64(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Exception while validating existing user_vm table's user_data column to be base64 valid with padding", e); } - if (LOG.isDebugEnabled()) { - LOG.debug("Done validating base64 content of user data"); + if (logger.isDebugEnabled()) { + logger.debug("Done validating base64 content of user data"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade410to420.java index 2e7eee13a5ad..b78aed3119a4 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade410to420.java @@ -33,7 +33,6 @@ import java.util.Map; import java.util.UUID; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; @@ -44,8 +43,7 @@ import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade410to420 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade410to420.class); +public class Upgrade410to420 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -194,15 +192,15 @@ private void persistVswitchConfiguration(Connection conn) { detailsMap.put(clusterId, detailsList); updateClusterDetails(conn, detailsMap); - s_logger.debug("Persist vSwitch Configuration: Successfully persisted vswitch configuration for cluster " + clusterId); + logger.debug("Persist vSwitch Configuration: Successfully persisted vswitch configuration for cluster " + clusterId); } else { - s_logger.debug("Persist vSwitch Configuration: Ignoring cluster " + clusterId + " with hypervisor type " + clusterHypervisorType); + logger.debug("Persist vSwitch Configuration: Ignoring cluster " + clusterId + " with hypervisor type " + clusterHypervisorType); continue; } } // End cluster iteration }catch (SQLException e) { String msg = "Unable to persist vswitch configuration of VMware clusters." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } @@ -212,7 +210,7 @@ private void persistVswitchConfiguration(Connection conn) { } } catch (SQLException e) { String msg = "Unable to persist vswitch configuration of VMware clusters." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } } @@ -238,7 +236,7 @@ private void updateClusterDetails(Connection conn, Map indexList = new ArrayList(); - s_logger.debug("Dropping index i_alert__last_sent if it exists"); + logger.debug("Dropping index i_alert__last_sent if it exists"); indexList.add("last_sent"); // in 4.1, we created this index that is not in convention. indexList.add("i_alert__last_sent"); DbUpgradeUtils.dropKeysIfExist(conn, "alert", indexList, false); @@ -453,7 +451,7 @@ private void addIndexForAlert(Connection conn) { try(PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`alert` ADD INDEX `i_alert__last_sent`(`last_sent`)");) { pstmt.executeUpdate(); - s_logger.debug("Added index i_alert__last_sent for table alert"); + logger.debug("Added index i_alert__last_sent for table alert"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add index i_alert__last_sent to alert table for the column last_sent", e); } @@ -462,7 +460,7 @@ private void addIndexForAlert(Connection conn) { private void dropUploadTable(Connection conn) { try(PreparedStatement pstmt0 = conn.prepareStatement("SELECT url, created, type_id, host_id from upload where type=?");) { // Read upload table - Templates - s_logger.debug("Populating template_store_ref table"); + logger.debug("Populating template_store_ref table"); pstmt0.setString(1, "TEMPLATE"); try(ResultSet rs0 = pstmt0.executeQuery();) { @@ -476,7 +474,7 @@ private void dropUploadTable(Connection conn) { pstmt1.executeUpdate(); } // Read upload table - Volumes - s_logger.debug("Populating volume store ref table"); + logger.debug("Populating volume store ref table"); try(PreparedStatement pstmt2 = conn.prepareStatement("SELECT url, created, type_id, host_id, install_path from upload where type=?");) { pstmt2.setString(1, "VOLUME"); try(ResultSet rs2 = pstmt2.executeQuery();) { @@ -518,7 +516,7 @@ private void dropUploadTable(Connection conn) { //KVM snapshot flag: only turn on if Customers is using snapshot; private void setKVMSnapshotFlag(Connection conn) { - s_logger.debug("Verify and set the KVM snapshot flag if snapshot was used. "); + logger.debug("Verify and set the KVM snapshot flag if snapshot was used. "); try(PreparedStatement pstmt = conn.prepareStatement("select count(*) from `cloud`.`snapshots` where hypervisor_type = 'KVM'");) { int numRows = 0; @@ -541,7 +539,7 @@ private void setKVMSnapshotFlag(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Failed to read the snapshot table for KVM upgrade. ", e); } - s_logger.debug("Done set KVM snapshot flag. "); + logger.debug("Done set KVM snapshot flag. "); } private void updatePrimaryStore(Connection conn) { @@ -633,7 +631,7 @@ private String getNewLabel(ResultSet rs, String oldParamValue) { } } } catch (SQLException e) { - s_logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e)); + logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e)); } return newGuestLabel; } @@ -667,7 +665,7 @@ private void upgradeVmwareLabels(Connection conn) { newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue); try(PreparedStatement update_pstmt = conn.prepareStatement("update physical_network_traffic_types set vmware_network_label = ? where traffic_type = ? and vmware_network_label is not NULL;");) { - s_logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt); + logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt); pstmt.setString(1, newLabel); pstmt.setString(2, trafficType); update_pstmt.executeUpdate(); @@ -748,7 +746,7 @@ private void persistLegacyZones(Connection conn) { if (count > 0) { if (!dcOfPreviousCluster.equalsIgnoreCase(dcOfCurrentCluster)) { legacyZone = true; - s_logger.debug("Marking the zone " + zoneId + " as legacy zone."); + logger.debug("Marking the zone " + zoneId + " as legacy zone."); } } } catch (SQLException e) { @@ -758,7 +756,7 @@ private void persistLegacyZones(Connection conn) { throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e); } } else { - s_logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType); + logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType); break; } count++; @@ -798,11 +796,11 @@ private void persistLegacyZones(Connection conn) { updateLegacyZones(conn, listOfLegacyZones); updateNonLegacyZones(conn, listOfNonLegacyZones); } catch (SQLException e) { - s_logger.error("Unable to discover legacy zones." + e.getMessage(),e); + logger.error("Unable to discover legacy zones." + e.getMessage(),e); throw new CloudRuntimeException("Unable to discover legacy zones." + e.getMessage(), e); } }catch (SQLException e) { - s_logger.error("Unable to discover legacy zones." + e.getMessage(),e); + logger.error("Unable to discover legacy zones." + e.getMessage(),e); throw new CloudRuntimeException("Unable to discover legacy zones." + e.getMessage(), e); } } @@ -813,7 +811,7 @@ private void updateLegacyZones(Connection conn, List zones) { for (Long zoneId : zones) { legacyZonesQuery.setLong(1, zoneId); legacyZonesQuery.executeUpdate(); - s_logger.debug("Inserted zone " + zoneId + " into cloud.legacyzones table"); + logger.debug("Inserted zone " + zoneId + " into cloud.legacyzones table"); } } catch (SQLException e) { throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e); @@ -823,7 +821,7 @@ private void updateLegacyZones(Connection conn, List zones) { private void updateNonLegacyZones(Connection conn, List zones) { try { for (Long zoneId : zones) { - s_logger.debug("Discovered non-legacy zone " + zoneId + ". Processing the zone to associate with VMware datacenter."); + logger.debug("Discovered non-legacy zone " + zoneId + ". Processing the zone to associate with VMware datacenter."); // All clusters in a non legacy zone will belong to the same VMware DC, hence pick the first cluster try (PreparedStatement clustersQuery = conn.prepareStatement("select id from `cloud`.`cluster` where removed is NULL AND data_center_id=?");) { @@ -888,7 +886,7 @@ private void updateNonLegacyZones(Connection conn, List zones) { } } catch (SQLException e) { String msg = "Unable to update non legacy zones." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } } @@ -914,7 +912,7 @@ private void createPlaceHolderNics(Connection conn) { }catch (SQLException e) { throw new CloudRuntimeException("Unable to create placeholder nics", e); } - s_logger.debug("Created placeholder nic for the ipAddress " + ip + " and network " + networkId); + logger.debug("Created placeholder nic for the ipAddress " + ip + " and network " + networkId); } }catch (SQLException e) { throw new CloudRuntimeException("Unable to create placeholder nics", e); @@ -959,7 +957,7 @@ private void addEgressFwRulesForSRXGuestNw(Connection conn) { try(PreparedStatement sel_net_pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? ");) { sel_net_pstmt.setLong(1, netId); - s_logger.debug("Getting account_id, domain_id from networks table: "); + logger.debug("Getting account_id, domain_id from networks table: "); try(ResultSet rsNw = pstmt.executeQuery();) { if (rsNw.next()) { @@ -967,7 +965,7 @@ private void addEgressFwRulesForSRXGuestNw(Connection conn) { long domainId = rsNw.getLong(2); //Add new rule for the existing networks - s_logger.debug("Adding default egress firewall rule for network " + netId); + logger.debug("Adding default egress firewall rule for network " + netId); try (PreparedStatement insert_pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created, traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')");) { insert_pstmt.setString(1, UUID.randomUUID().toString()); @@ -975,7 +973,7 @@ private void addEgressFwRulesForSRXGuestNw(Connection conn) { insert_pstmt.setLong(3, domainId); insert_pstmt.setLong(4, netId); insert_pstmt.setString(5, UUID.randomUUID().toString()); - s_logger.debug("Inserting default egress firewall rule " + insert_pstmt); + logger.debug("Inserting default egress firewall rule " + insert_pstmt); insert_pstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Unable to set egress firewall rules ", e); @@ -988,7 +986,7 @@ private void addEgressFwRulesForSRXGuestNw(Connection conn) { firewallRuleId = rsId.getLong(1); try (PreparedStatement insert_pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");) { insert_pstmt.setLong(1, firewallRuleId); - s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + insert_pstmt); + logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + insert_pstmt); insert_pstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Unable to set egress firewall rules ", e); @@ -1040,7 +1038,7 @@ private void updateNetworkACLs(Connection conn) { //For each tier create a network ACL and move all the acl_items to network_acl_item table // If there are no acl_items for a tier, associate it with default ACL - s_logger.debug("Updating network ACLs"); + logger.debug("Updating network ACLs"); //1,2 are default acl Ids, start acl Ids from 3 long nextAclId = 3; @@ -1066,7 +1064,7 @@ private void updateNetworkACLs(Connection conn) { //Get all VPC tiers while (rsNetworkIds.next()) { Long networkId = rsNetworkIds.getLong(1); - s_logger.debug("Updating network ACLs for network: " + networkId); + logger.debug("Updating network ACLs for network: " + networkId); Long vpcId = rsNetworkIds.getLong(2); String tierUuid = rsNetworkIds.getString(3); pstmtSelectFirewallRules.setLong(1, networkId); @@ -1079,7 +1077,7 @@ private void updateNetworkACLs(Connection conn) { hasAcls = true; aclId = nextAclId++; //create ACL for the tier - s_logger.debug("Creating network ACL for tier: " + tierUuid); + logger.debug("Creating network ACL for tier: " + tierUuid); pstmtInsertNetworkAcl.setLong(1, aclId); pstmtInsertNetworkAcl.setLong(2, vpcId); pstmtInsertNetworkAcl.setString(3, "ACL for tier " + tierUuid); @@ -1107,7 +1105,7 @@ private void updateNetworkACLs(Connection conn) { } String aclItemUuid = rsAcls.getString(2); //Move acl to network_acl_item table - s_logger.debug("Moving firewall rule: " + aclItemUuid); + logger.debug("Moving firewall rule: " + aclItemUuid); //uuid pstmtInsertNetworkAclItem.setString(1, aclItemUuid); //aclId @@ -1178,7 +1176,7 @@ private void updateNetworkACLs(Connection conn) { pstmtUpdate.setLong(2, networkId); pstmtUpdate.executeUpdate(); } - s_logger.debug("Done updating network ACLs "); + logger.debug("Done updating network ACLs "); } catch (SQLException e) { throw new CloudRuntimeException("Unable to move network acls from firewall rules table to network_acl_item table", e); } @@ -1292,17 +1290,17 @@ private void upgradePhysicalNtwksWithInternalLbProvider(Connection conn) { } private void addHostDetailsIndex(Connection conn) { - s_logger.debug("Checking if host_details index exists, if not we will add it"); + logger.debug("Checking if host_details index exists, if not we will add it"); try(PreparedStatement pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` where KEY_NAME = 'fk_host_details__host_id'");) { try(ResultSet rs = pstmt.executeQuery();) { if (rs.next()) { - s_logger.debug("Index already exists on host_details - not adding new one"); + logger.debug("Index already exists on host_details - not adding new one"); } else { // add the index try(PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD INDEX `fk_host_details__host_id` (`host_id`)");) { pstmtUpdate.executeUpdate(); - s_logger.debug("Index did not exist on host_details - added new one"); + logger.debug("Index did not exist on host_details - added new one"); }catch (SQLException e) { throw new CloudRuntimeException("Failed to check/update the host_details index ", e); } @@ -1363,7 +1361,7 @@ private void removeFirewallServiceFromSharedNetworkOfferingWithSGService(Connect } private void fix22xKVMSnapshots(Connection conn) { - s_logger.debug("Updating KVM snapshots"); + logger.debug("Updating KVM snapshots"); try (PreparedStatement pstmt = conn.prepareStatement("select id, backup_snap_id from `cloud`.`snapshots` where hypervisor_type='KVM' and removed is null and backup_snap_id is not null");) { try(ResultSet rs = pstmt.executeQuery();) { @@ -1376,7 +1374,7 @@ private void fix22xKVMSnapshots(Connection conn) { int index = backUpPath.indexOf("snapshots" + File.separator); if (index > 1) { String correctedPath = backUpPath.substring(index); - s_logger.debug("Updating Snapshot with id: " + id + " original backup path: " + backUpPath + " updated backup path: " + correctedPath); + logger.debug("Updating Snapshot with id: " + id + " original backup path: " + backUpPath + " updated backup path: " + correctedPath); try(PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`snapshots` set backup_snap_id=? where id = ?");) { update_pstmt.setString(1, correctedPath); update_pstmt.setLong(2, id); @@ -1386,7 +1384,7 @@ private void fix22xKVMSnapshots(Connection conn) { } } } - s_logger.debug("Done updating KVM snapshots"); + logger.debug("Done updating KVM snapshots"); }catch (SQLException e) { throw new CloudRuntimeException("Unable to update backup id for KVM snapshots", e); } @@ -1480,7 +1478,7 @@ private void addF5LoadBalancer(Connection conn, long hostId, long physicalNetwor "INSERT INTO `cloud`.`external_load_balancer_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, is_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; try(PreparedStatement pstmtUpdate = conn.prepareStatement(insertF5);) { - s_logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); pstmtUpdate.setLong(1, physicalNetworkId); pstmtUpdate.setLong(2, hostId); pstmtUpdate.setString(3, "F5BigIp"); @@ -1502,7 +1500,7 @@ private void addSrxFirewall(Connection conn, long hostId, long physicalNetworkId "INSERT INTO `cloud`.`external_firewall_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)"; try(PreparedStatement pstmtUpdate = conn.prepareStatement(insertSrx);) { - s_logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); pstmtUpdate.setLong(1, physicalNetworkId); pstmtUpdate.setLong(2, hostId); pstmtUpdate.setString(3, "JuniperSRX"); @@ -1526,7 +1524,7 @@ private void addF5ServiceProvider(Connection conn, long physicalNetworkId, long + "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,0,0,0,0,0,0,1,0,0,0,0)"; try(PreparedStatement pstmtUpdate = conn.prepareStatement(insertPNSP);) { // add physical network service provider - F5BigIp - s_logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); + logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); pstmtUpdate.setString(1, UUID.randomUUID().toString()); pstmtUpdate.setLong(2, physicalNetworkId); pstmtUpdate.setString(3, "F5BigIp"); @@ -1545,7 +1543,7 @@ private void addSrxServiceProvider(Connection conn, long physicalNetworkId, long + "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,0,0,0,1,1,1,0,1,1,0,0)"; try( PreparedStatement pstmtUpdate = conn.prepareStatement(insertPNSP);) { // add physical network service provider - JuniperSRX - s_logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); + logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); pstmtUpdate.setString(1, UUID.randomUUID().toString()); pstmtUpdate.setLong(2, physicalNetworkId); pstmtUpdate.setString(3, "JuniperSRX"); @@ -1690,7 +1688,7 @@ private void fixZoneUsingExternalDevices(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } - s_logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); + logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); // add mapping for the network in network_external_firewall_device_map String insertFwMapping = @@ -1703,7 +1701,7 @@ private void fixZoneUsingExternalDevices(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } - s_logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); + logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); } }catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); @@ -1712,7 +1710,7 @@ private void fixZoneUsingExternalDevices(Connection conn) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } // update host details for F5 and SRX devices - s_logger.debug("Updating the host details for F5 and SRX devices"); + logger.debug("Updating the host details for F5 and SRX devices"); try(PreparedStatement sel_pstmt = conn.prepareStatement("SELECT host_id, name FROM `cloud`.`host_details` WHERE host_id=? OR host_id=?");) { sel_pstmt.setLong(1, f5HostId); sel_pstmt.setLong(2, srxHostId); @@ -1740,11 +1738,11 @@ private void fixZoneUsingExternalDevices(Connection conn) { }catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } - s_logger.debug("Successfully updated host details for F5 and SRX devices"); + logger.debug("Successfully updated host details for F5 and SRX devices"); } catch (RuntimeException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } - s_logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); + logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); } } @@ -1755,7 +1753,7 @@ private void migrateSecondaryStorageToImageStore(Connection conn) { String sqlInsertStoreDetail = "INSERT INTO `cloud`.`image_store_details` (store_id, name, value) values(?, ?, ?)"; String sqlUpdateHostAsRemoved = "UPDATE `cloud`.`host` SET removed = now() WHERE type = 'SecondaryStorage' and removed is null"; - s_logger.debug("Migrating secondary storage to image store"); + logger.debug("Migrating secondary storage to image store"); boolean hasS3orSwift = false; try ( PreparedStatement pstmtSelectS3Count = conn.prepareStatement(sqlSelectS3Count); @@ -1770,7 +1768,7 @@ private void migrateSecondaryStorageToImageStore(Connection conn) { ResultSet rsSelectSwiftCount = pstmtSelectSwiftCount.executeQuery(); ResultSet rsNfs = nfsQuery.executeQuery(); ) { - s_logger.debug("Checking if we need to migrate NFS secondary storage to image store or staging store"); + logger.debug("Checking if we need to migrate NFS secondary storage to image store or staging store"); int numRows = 0; if (rsSelectS3Count.next()) { numRows = rsSelectS3Count.getInt(1); @@ -1788,7 +1786,7 @@ private void migrateSecondaryStorageToImageStore(Connection conn) { store_role = "ImageCache"; } - s_logger.debug("Migrating NFS secondary storage to " + store_role + " store"); + logger.debug("Migrating NFS secondary storage to " + store_role + " store"); // migrate NFS secondary storage, for nfs, keep previous host_id as the store_id while (rsNfs.next()) { @@ -1820,84 +1818,84 @@ private void migrateSecondaryStorageToImageStore(Connection conn) { storeInsert.executeUpdate(); } - s_logger.debug("Marking NFS secondary storage in host table as removed"); + logger.debug("Marking NFS secondary storage in host table as removed"); pstmtUpdateHostAsRemoved.executeUpdate(); } catch (SQLException e) { String msg = "Unable to migrate secondary storages." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } - s_logger.debug("Completed migrating secondary storage to image store"); + logger.debug("Completed migrating secondary storage to image store"); } // migrate volume_host_ref to volume_store_ref private void migrateVolumeHostRef(Connection conn) { - s_logger.debug("Updating volume_store_ref table from volume_host_ref table"); + logger.debug("Updating volume_store_ref table from volume_host_ref table"); try(PreparedStatement volStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`volume_store_ref` (store_id, volume_id, zone_id, created, last_updated, job_id, download_pct, size, physical_size, download_state, checksum, error_str, local_path, install_path, url, destroyed, update_count, ref_cnt, state) select host_id, volume_id, zone_id, created, last_updated, job_id, download_pct, size, physical_size, download_state, checksum, error_str, local_path, install_path, url, destroyed, 0, 0, 'Allocated' from `cloud`.`volume_host_ref`");) { int rowCount = volStoreInsert.executeUpdate(); - s_logger.debug("Insert modified " + rowCount + " rows"); + logger.debug("Insert modified " + rowCount + " rows"); try(PreparedStatement volStoreUpdate = conn.prepareStatement("update `cloud`.`volume_store_ref` set state = 'Ready' where download_state = 'DOWNLOADED'");) { rowCount = volStoreUpdate.executeUpdate(); - s_logger.debug("Update modified " + rowCount + " rows"); + logger.debug("Update modified " + rowCount + " rows"); }catch (SQLException e) { - s_logger.error("Unable to migrate volume_host_ref." + e.getMessage(),e); + logger.error("Unable to migrate volume_host_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate volume_host_ref." + e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("Unable to migrate volume_host_ref." + e.getMessage(),e); + logger.error("Unable to migrate volume_host_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate volume_host_ref." + e.getMessage(),e); } - s_logger.debug("Completed updating volume_store_ref table from volume_host_ref table"); + logger.debug("Completed updating volume_store_ref table from volume_host_ref table"); } // migrate template_host_ref to template_store_ref private void migrateTemplateHostRef(Connection conn) { - s_logger.debug("Updating template_store_ref table from template_host_ref table"); + logger.debug("Updating template_store_ref table from template_host_ref table"); try (PreparedStatement tmplStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`template_store_ref` (store_id, template_id, created, last_updated, job_id, download_pct, size, physical_size, download_state, error_str, local_path, install_path, url, destroyed, is_copy, update_count, ref_cnt, store_role, state) select host_id, template_id, created, last_updated, job_id, download_pct, size, physical_size, download_state, error_str, local_path, install_path, url, destroyed, is_copy, 0, 0, 'Image', 'Allocated' from `cloud`.`template_host_ref`");) { int rowCount = tmplStoreInsert.executeUpdate(); - s_logger.debug("Insert modified " + rowCount + " rows"); + logger.debug("Insert modified " + rowCount + " rows"); try(PreparedStatement tmplStoreUpdate = conn.prepareStatement("update `cloud`.`template_store_ref` set state = 'Ready' where download_state = 'DOWNLOADED'");) { rowCount = tmplStoreUpdate.executeUpdate(); }catch (SQLException e) { - s_logger.error("Unable to migrate template_host_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_host_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_host_ref." + e.getMessage(), e); } - s_logger.debug("Update modified " + rowCount + " rows"); + logger.debug("Update modified " + rowCount + " rows"); } catch (SQLException e) { - s_logger.error("Unable to migrate template_host_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_host_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_host_ref." + e.getMessage(), e); } - s_logger.debug("Completed updating template_store_ref table from template_host_ref table"); + logger.debug("Completed updating template_store_ref table from template_host_ref table"); } // migrate some entry contents of snapshots to snapshot_store_ref private void migrateSnapshotStoreRef(Connection conn) { - s_logger.debug("Updating snapshot_store_ref table from snapshots table"); + logger.debug("Updating snapshot_store_ref table from snapshots table"); try(PreparedStatement snapshotStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) select sechost_id, id, created, size, prev_snap_id, CONCAT('snapshots', '/', account_id, '/', volume_id, '/', backup_snap_id), volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and hypervisor_type <> 'KVM' and sechost_id is not null and removed is null"); ) { //Update all snapshots except KVM snapshots int rowCount = snapshotStoreInsert.executeUpdate(); - s_logger.debug("Inserted " + rowCount + " snapshots into snapshot_store_ref"); + logger.debug("Inserted " + rowCount + " snapshots into snapshot_store_ref"); //backsnap_id for KVM snapshots is complete path. CONCAT is not required try(PreparedStatement snapshotStoreInsert_2 = conn.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) select sechost_id, id, created, size, prev_snap_id, backup_snap_id, volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and hypervisor_type = 'KVM' and sechost_id is not null and removed is null");) { rowCount = snapshotStoreInsert_2.executeUpdate(); - s_logger.debug("Inserted " + rowCount + " KVM snapshots into snapshot_store_ref"); + logger.debug("Inserted " + rowCount + " KVM snapshots into snapshot_store_ref"); }catch (SQLException e) { - s_logger.error("Unable to migrate snapshot_store_ref." + e.getMessage(),e); + logger.error("Unable to migrate snapshot_store_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate snapshot_store_ref." + e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("Unable to migrate snapshot_store_ref." + e.getMessage(),e); + logger.error("Unable to migrate snapshot_store_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate snapshot_store_ref." + e.getMessage(),e); } - s_logger.debug("Completed updating snapshot_store_ref table from snapshots table"); + logger.debug("Completed updating snapshot_store_ref table from snapshots table"); } // migrate secondary storages S3 from s3 tables to image_store table @@ -1905,7 +1903,7 @@ private void migrateS3ToImageStore(Connection conn) { Long storeId = null; Map s3_store_id_map = new HashMap(); - s_logger.debug("Migrating S3 to image store"); + logger.debug("Migrating S3 to image store"); try ( PreparedStatement storeQuery = conn.prepareStatement("select id from `cloud`.`image_store` where uuid = ?"); PreparedStatement storeDetailInsert = conn.prepareStatement("INSERT INTO `cloud`.`image_store_details` (store_id, name, value) values(?, ?, ?)"); @@ -1976,22 +1974,22 @@ private void migrateS3ToImageStore(Connection conn) { } } catch (SQLException e) { String msg = "Unable to migrate S3 secondary storages." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } - s_logger.debug("Migrating template_s3_ref to template_store_ref"); + logger.debug("Migrating template_s3_ref to template_store_ref"); migrateTemplateS3Ref(conn, s3_store_id_map); - s_logger.debug("Migrating s3 backedup snapshots to snapshot_store_ref"); + logger.debug("Migrating s3 backedup snapshots to snapshot_store_ref"); migrateSnapshotS3Ref(conn, s3_store_id_map); - s_logger.debug("Completed migrating S3 secondary storage to image store"); + logger.debug("Completed migrating S3 secondary storage to image store"); } // migrate template_s3_ref to template_store_ref private void migrateTemplateS3Ref(Connection conn, Map s3StoreMap) { - s_logger.debug("Updating template_store_ref table from template_s3_ref table"); + logger.debug("Updating template_store_ref table from template_s3_ref table"); try(PreparedStatement tmplStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`template_store_ref` (store_id, template_id, created, download_pct, size, physical_size, download_state, local_path, install_path, update_count, ref_cnt, store_role, state) values(?, ?, ?, 100, ?, ?, 'DOWNLOADED', '?', '?', 0, 0, 'Image', 'Ready')"); ) { @@ -2024,23 +2022,23 @@ private void migrateTemplateS3Ref(Connection conn, Map s3StoreMap) { tmplStoreInsert.executeUpdate(); } }catch (SQLException e) { - s_logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_s3_ref." + e.getMessage(),e); } }catch (SQLException e) { - s_logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_s3_ref." + e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_s3_ref." + e.getMessage(),e); } - s_logger.debug("Completed migrating template_s3_ref table."); + logger.debug("Completed migrating template_s3_ref table."); } // migrate some entry contents of snapshots to snapshot_store_ref private void migrateSnapshotS3Ref(Connection conn, Map s3StoreMap) { - s_logger.debug("Updating snapshot_store_ref table from snapshots table for s3"); + logger.debug("Updating snapshot_store_ref table from snapshots table for s3"); try(PreparedStatement snapshotStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) values(?, ?, ?, ?, ?, ?, ?, 0, 0, 'Image', 'Ready')"); ) { @@ -2074,18 +2072,18 @@ private void migrateSnapshotS3Ref(Connection conn, Map s3StoreMap) { snapshotStoreInsert.executeUpdate(); } }catch (SQLException e) { - s_logger.error("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); } }catch (SQLException e) { - s_logger.error("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("Unable to migrate s3 backedup snapshots to snapshot_store_ref." + e.getMessage()); + logger.error("Unable to migrate s3 backedup snapshots to snapshot_store_ref." + e.getMessage()); throw new CloudRuntimeException("Unable to migrate s3 backedup snapshots to snapshot_store_ref." + e.getMessage(), e); } - s_logger.debug("Completed updating snapshot_store_ref table from s3 snapshots entries"); + logger.debug("Completed updating snapshot_store_ref table from s3 snapshots entries"); } // migrate secondary storages Swift from swift tables to image_store table @@ -2093,7 +2091,7 @@ private void migrateSwiftToImageStore(Connection conn) { Long storeId = null; Map swift_store_id_map = new HashMap(); - s_logger.debug("Migrating Swift to image store"); + logger.debug("Migrating Swift to image store"); try ( PreparedStatement storeQuery = conn.prepareStatement("select id from `cloud`.`image_store` where uuid = ?"); PreparedStatement storeDetailInsert = conn.prepareStatement("INSERT INTO `cloud`.`image_store_details` (store_id, name, value) values(?, ?, ?)"); @@ -2146,22 +2144,22 @@ private void migrateSwiftToImageStore(Connection conn) { } } catch (SQLException e) { String msg = "Unable to migrate swift secondary storages." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } - s_logger.debug("Migrating template_swift_ref to template_store_ref"); + logger.debug("Migrating template_swift_ref to template_store_ref"); migrateTemplateSwiftRef(conn, swift_store_id_map); - s_logger.debug("Migrating swift backedup snapshots to snapshot_store_ref"); + logger.debug("Migrating swift backedup snapshots to snapshot_store_ref"); migrateSnapshotSwiftRef(conn, swift_store_id_map); - s_logger.debug("Completed migrating Swift secondary storage to image store"); + logger.debug("Completed migrating Swift secondary storage to image store"); } // migrate template_s3_ref to template_store_ref private void migrateTemplateSwiftRef(Connection conn, Map swiftStoreMap) { - s_logger.debug("Updating template_store_ref table from template_swift_ref table"); + logger.debug("Updating template_store_ref table from template_swift_ref table"); try ( PreparedStatement tmplStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`template_store_ref` (store_id, template_id, created, download_pct, size, physical_size, download_state, local_path, install_path, update_count, ref_cnt, store_role, state) values(?, ?, ?, 100, ?, ?, 'DOWNLOADED', '?', '?', 0, 0, 'Image', 'Ready')"); @@ -2195,15 +2193,15 @@ private void migrateTemplateSwiftRef(Connection conn, Map swiftStore } } catch (SQLException e) { String msg = "Unable to migrate template_swift_ref." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } - s_logger.debug("Completed migrating template_swift_ref table."); + logger.debug("Completed migrating template_swift_ref table."); } // migrate some entry contents of snapshots to snapshot_store_ref private void migrateSnapshotSwiftRef(Connection conn, Map swiftStoreMap) { - s_logger.debug("Updating snapshot_store_ref table from snapshots table for swift"); + logger.debug("Updating snapshot_store_ref table from snapshots table for swift"); try (PreparedStatement snapshotStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) values(?, ?, ?, ?, ?, ?, ?, 0, 0, 'Image', 'Ready')"); ){ @@ -2229,31 +2227,31 @@ private void migrateSnapshotSwiftRef(Connection conn, Map swiftStore snapshotStoreInsert.executeUpdate(); } }catch (SQLException e) { - s_logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); } }catch (SQLException e) { - s_logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); } - s_logger.debug("Completed updating snapshot_store_ref table from swift snapshots entries"); + logger.debug("Completed updating snapshot_store_ref table from swift snapshots entries"); } private void fixNiciraKeys(Connection conn) { //First drop the key if it exists. List keys = new ArrayList(); - s_logger.debug("Dropping foreign key fk_nicira_nvp_nic_map__nic from the table nicira_nvp_nic_map if it exists"); + logger.debug("Dropping foreign key fk_nicira_nvp_nic_map__nic from the table nicira_nvp_nic_map if it exists"); keys.add("fk_nicira_nvp_nic_map__nic"); DbUpgradeUtils.dropKeysIfExist(conn, "nicira_nvp_nic_map", keys, true); //Now add foreign key. try(PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`nicira_nvp_nic_map` ADD CONSTRAINT `fk_nicira_nvp_nic_map__nic` FOREIGN KEY (`nic`) REFERENCES `nics` (`uuid`) ON DELETE CASCADE");) { pstmt.executeUpdate(); - s_logger.debug("Added foreign key fk_nicira_nvp_nic_map__nic to the table nicira_nvp_nic_map"); + logger.debug("Added foreign key fk_nicira_nvp_nic_map__nic to the table nicira_nvp_nic_map"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add foreign key fk_nicira_nvp_nic_map__nic to the table nicira_nvp_nic_map", e); } @@ -2262,7 +2260,7 @@ private void fixNiciraKeys(Connection conn) { private void fixRouterKeys(Connection conn) { //First drop the key if it exists. List keys = new ArrayList(); - s_logger.debug("Dropping foreign key fk_router_network_ref__router_id from the table router_network_ref if it exists"); + logger.debug("Dropping foreign key fk_router_network_ref__router_id from the table router_network_ref if it exists"); keys.add("fk_router_network_ref__router_id"); DbUpgradeUtils.dropKeysIfExist(conn, "router_network_ref", keys, true); //Now add foreign key. @@ -2270,14 +2268,14 @@ private void fixRouterKeys(Connection conn) { conn.prepareStatement("ALTER TABLE `cloud`.`router_network_ref` ADD CONSTRAINT `fk_router_network_ref__router_id` FOREIGN KEY (`router_id`) REFERENCES `domain_router` (`id`) ON DELETE CASCADE");) { pstmt.executeUpdate(); - s_logger.debug("Added foreign key fk_router_network_ref__router_id to the table router_network_ref"); + logger.debug("Added foreign key fk_router_network_ref__router_id to the table router_network_ref"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add foreign key fk_router_network_ref__router_id to the table router_network_ref", e); } } private void encryptSite2SitePSK(Connection conn) { - s_logger.debug("Encrypting Site2Site Customer Gateway pre-shared key"); + logger.debug("Encrypting Site2Site Customer Gateway pre-shared key"); try (PreparedStatement select_pstmt = conn.prepareStatement("select id, ipsec_psk from `cloud`.`s2s_customer_gateway`");){ try(ResultSet rs = select_pstmt.executeQuery();) { @@ -2304,7 +2302,7 @@ private void encryptSite2SitePSK(Connection conn) { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable to encrypt Site2Site Customer Gateway pre-shared key ", e); } - s_logger.debug("Done encrypting Site2Site Customer Gateway pre-shared key"); + logger.debug("Done encrypting Site2Site Customer Gateway pre-shared key"); } protected void updateConcurrentConnectionsInNetworkOfferings(Connection conn) { @@ -2388,31 +2386,31 @@ private void migrateDatafromIsoIdInVolumesTable(Connection conn) { conn.prepareStatement("ALTER TABLE `cloud`.`volumes` CHANGE COLUMN `iso_id1` `iso_id` bigint(20) unsigned COMMENT 'The id of the iso from which the volume was created'");) { alter_iso_pstmt.executeUpdate(); }catch (SQLException e) { - s_logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); - if (s_logger.isTraceEnabled()) { - s_logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); + logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); + if (logger.isTraceEnabled()) { + logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); } //implies iso_id1 is not present, so do nothing. } }catch (SQLException e) { - s_logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); - if (s_logger.isTraceEnabled()) { - s_logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); + logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); + if (logger.isTraceEnabled()) { + logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); } //implies iso_id1 is not present, so do nothing. } } }catch (SQLException e) { - s_logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); - if (s_logger.isTraceEnabled()) { - s_logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); + logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); + if (logger.isTraceEnabled()) { + logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); } //implies iso_id1 is not present, so do nothing. } } catch (SQLException e) { - s_logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); - if (s_logger.isTraceEnabled()) { - s_logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); + logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); + if (logger.isTraceEnabled()) { + logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); } //implies iso_id1 is not present, so do nothing. } @@ -2421,7 +2419,7 @@ private void migrateDatafromIsoIdInVolumesTable(Connection conn) { protected void setRAWformatForRBDVolumes(Connection conn) { try(PreparedStatement pstmt = conn.prepareStatement("UPDATE volumes SET format = 'RAW' WHERE pool_id IN(SELECT id FROM storage_pool WHERE pool_type = 'RBD')");) { - s_logger.debug("Setting format to RAW for all volumes on RBD primary storage pools"); + logger.debug("Setting format to RAW for all volumes on RBD primary storage pools"); pstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Failed to update volume format to RAW for volumes on RBD pools due to exception ", e); @@ -2429,7 +2427,7 @@ protected void setRAWformatForRBDVolumes(Connection conn) { } private void upgradeVpcServiceMap(Connection conn) { - s_logger.debug("Upgrading VPC service Map"); + logger.debug("Upgrading VPC service Map"); try(PreparedStatement listVpc = conn.prepareStatement("SELECT id, vpc_offering_id FROM `cloud`.`vpc` where removed is NULL");) { //Get all vpc Ids along with vpc offering Id @@ -2461,7 +2459,7 @@ private void upgradeVpcServiceMap(Connection conn) { }catch (SQLException e) { throw new CloudRuntimeException("Error during VPC service map upgrade", e); } - s_logger.debug("Upgraded service map for VPC: " + vpc_id); + logger.debug("Upgraded service map for VPC: " + vpc_id); } } } catch (SQLException e) { @@ -2470,7 +2468,7 @@ private void upgradeVpcServiceMap(Connection conn) { } private void upgradeResourceCount(Connection conn) { - s_logger.debug("upgradeResourceCount start"); + logger.debug("upgradeResourceCount start"); try( PreparedStatement sel_dom_pstmt = conn.prepareStatement("select id, domain_id FROM `cloud`.`account` where removed is NULL "); ResultSet rsAccount = sel_dom_pstmt.executeQuery(); @@ -2599,7 +2597,7 @@ private void upgradeResourceCount(Connection conn) { throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage) ", e); } } - s_logger.debug("upgradeResourceCount finish"); + logger.debug("upgradeResourceCount finish"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage) ", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41100to41110.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41100to41110.java index 3703040771bd..1df197b4fcf5 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41100to41110.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41100to41110.java @@ -25,13 +25,11 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41100to41110 implements DbUpgrade { - final static Logger LOG = Logger.getLogger(Upgrade41000to41100.class); +public class Upgrade41100to41110 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -105,8 +103,8 @@ private void uncrypt(Connection conn, String name) try ( ResultSet resultSet = prepSelStmt.executeQuery(); ) { - if (LOG.isInfoEnabled()) { - LOG.info("updating setting '" + name + "'"); + if (logger.isInfoEnabled()) { + logger.info("updating setting '" + name + "'"); } if (resultSet.next()) { if ("Secure".equals(resultSet.getString(1))) { @@ -118,10 +116,10 @@ private void uncrypt(Connection conn, String name) prepUpdStmt.setString(2, name); prepUpdStmt.execute(); } catch (SQLException e) { - if (LOG.isInfoEnabled()) { - LOG.info("failed to update configuration item '" + name + "' with value '" + value + "'"); - if (LOG.isDebugEnabled()) { - LOG.debug("no update because ", e); + if (logger.isInfoEnabled()) { + logger.info("failed to update configuration item '" + name + "' with value '" + value + "'"); + if (logger.isDebugEnabled()) { + logger.debug("no update because ", e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41110to41120.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41110to41120.java index f7782cebf464..85be41fc6f2e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41110to41120.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41110to41120.java @@ -20,12 +20,10 @@ import java.io.InputStream; import java.sql.Connection; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41110to41120 implements DbUpgrade { - final static Logger LOG = Logger.getLogger(Upgrade41110to41120.class); +public class Upgrade41110to41120 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41130.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41130.java index d9eec476628d..d011f4fb0fc4 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41130.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41130.java @@ -20,7 +20,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade41120to41130 implements DbUpgrade { +public class Upgrade41120to41130 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java index f68f04a53aa8..ce0e1e39c2ef 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java @@ -23,11 +23,9 @@ import java.sql.SQLException; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; -public class Upgrade41120to41200 implements DbUpgrade { +public class Upgrade41120to41200 extends DbUpgradeAbstractImpl { - final static Logger LOG = Logger.getLogger(Upgrade41120to41200.class); @Override public String[] getUpgradableVersionRange() { @@ -64,7 +62,7 @@ private void updateManagementServerHostUuid(Connection conn) { try (final PreparedStatement updateStatement = conn.prepareStatement("UPDATE cloud.mshost SET uuid=UUID()")) { updateStatement.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to add an UUID to each management server.", e); + logger.error("Failed to add an UUID to each management server.", e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41200to41300.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41200to41300.java index 2de8dc983587..dd6f2cf30367 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41200to41300.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41200to41300.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41200to41300 implements DbUpgrade { +public class Upgrade41200to41300 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41300to41310.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41300to41310.java index ac6149f78447..4cae3d445c7c 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41300to41310.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41300to41310.java @@ -19,7 +19,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade41300to41310 implements DbUpgrade { +public class Upgrade41300to41310 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { return new String[] {"4.13.0.0", "4.13.1.0"}; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41310to41400.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41310to41400.java index f1a333e7d48b..91fd5b6d57f0 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41310to41400.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41310to41400.java @@ -20,13 +20,11 @@ import java.io.InputStream; import java.sql.Connection; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41310to41400 implements DbUpgrade { +public class Upgrade41310to41400 extends DbUpgradeAbstractImpl { - final static Logger LOG = Logger.getLogger(Upgrade41310to41400.class); @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java index ba969ae879e2..4750915baa60 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java @@ -27,13 +27,10 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41400to41500 implements DbUpgrade { - - final static Logger LOG = Logger.getLogger(Upgrade41400to41500.class); +public class Upgrade41400to41500 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -74,7 +71,7 @@ private void addRolePermissionsForNewReadOnlyAndSupportRoles(final Connection co } private void addRolePermissionsForReadOnlyAdmin(final Connection conn) { - LOG.debug("Adding role permissions for new read-only admin role"); + logger.debug("Adding role permissions for new read-only admin role"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only Admin - Default' AND is_default = 1"); ResultSet rs = pstmt.executeQuery(); @@ -108,15 +105,15 @@ private void addRolePermissionsForReadOnlyAdmin(final Connection conn) { if (pstmt != null && !pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully added role permissions for new read-only admin role"); + logger.debug("Successfully added role permissions for new read-only admin role"); } catch (final SQLException e) { - LOG.error("Exception while adding role permissions for read-only admin role: " + e.getMessage()); + logger.error("Exception while adding role permissions for read-only admin role: " + e.getMessage()); throw new CloudRuntimeException("Exception while adding role permissions for read-only admin role: " + e.getMessage(), e); } } private void addRolePermissionsForReadOnlyUser(final Connection conn) { - LOG.debug("Adding role permissions for new read-only user role"); + logger.debug("Adding role permissions for new read-only user role"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only User - Default' AND is_default = 1"); ResultSet rs = pstmt.executeQuery(); @@ -179,15 +176,15 @@ private void addRolePermissionsForReadOnlyUser(final Connection conn) { if (pstmt != null && !pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully added role permissions for new read-only user role"); + logger.debug("Successfully added role permissions for new read-only user role"); } catch (final SQLException e) { - LOG.error("Exception while adding role permissions for read-only user role: " + e.getMessage()); + logger.error("Exception while adding role permissions for read-only user role: " + e.getMessage()); throw new CloudRuntimeException("Exception while adding role permissions for read-only user role: " + e.getMessage(), e); } } private void addRolePermissionsForSupportAdmin(final Connection conn) { - LOG.debug("Adding role permissions for new support admin role"); + logger.debug("Adding role permissions for new support admin role"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Support Admin - Default' AND is_default = 1"); ResultSet rs = pstmt.executeQuery(); @@ -264,15 +261,15 @@ private void addRolePermissionsForSupportAdmin(final Connection conn) { if (pstmt != null && !pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully added role permissions for new support admin role"); + logger.debug("Successfully added role permissions for new support admin role"); } catch (final SQLException e) { - LOG.error("Exception while adding role permissions for support admin role: " + e.getMessage()); + logger.error("Exception while adding role permissions for support admin role: " + e.getMessage()); throw new CloudRuntimeException("Exception while adding role permissions for support admin role: " + e.getMessage(), e); } } private void addRolePermissionsForSupportUser(final Connection conn) { - LOG.debug("Adding role permissions for new support user role"); + logger.debug("Adding role permissions for new support user role"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Support User - Default' AND is_default = 1"); ResultSet rs = pstmt.executeQuery(); @@ -341,9 +338,9 @@ private void addRolePermissionsForSupportUser(final Connection conn) { if (pstmt != null && !pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully added role permissions for new support user role"); + logger.debug("Successfully added role permissions for new support user role"); } catch (final SQLException e) { - LOG.error("Exception while adding role permissions for support user role: " + e.getMessage()); + logger.error("Exception while adding role permissions for support user role: " + e.getMessage()); throw new CloudRuntimeException("Exception while adding role permissions for support user role: " + e.getMessage(), e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41500to41510.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41500to41510.java index 344bbccc95b2..a6b77813fa15 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41500to41510.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41500to41510.java @@ -27,14 +27,18 @@ import java.util.Map; import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.hypervisor.Hypervisor; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate { +import static com.cloud.hypervisor.Hypervisor.HypervisorType.Hyperv; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.KVM; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.LXC; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.Ovm3; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.VMware; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.XenServer; - final static Logger LOG = Logger.getLogger(Upgrade41500to41510.class); +public class Upgrade41500to41510 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { @Override public String[] getUpgradableVersionRange() { @@ -70,84 +74,76 @@ public void performDataMigration(Connection conn) { @Override @SuppressWarnings("serial") public void updateSystemVmTemplates(final Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); final Set hypervisorsListInUse = new HashSet(); try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { - switch (Hypervisor.HypervisorType.getType(rs.getString(1))) { - case XenServer: - hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer); - break; - case KVM: - hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM); - break; - case VMware: - hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware); - break; - case Hyperv: - hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv); - break; - case LXC: - hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC); - break; - case Ovm3: - hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3); - break; - default: - break; + Hypervisor.HypervisorType type = Hypervisor.HypervisorType.getType(rs.getString(1)); + if (type.equals(XenServer)) { + hypervisorsListInUse.add(XenServer); + } else if (type.equals(KVM)) { + hypervisorsListInUse.add(KVM); + } else if (type.equals(VMware)) { + hypervisorsListInUse.add(VMware); + } else if (type.equals(Hyperv)) { + hypervisorsListInUse.add(Hyperv); + } else if (type.equals(LXC)) { + hypervisorsListInUse.add(LXC); + } else if (type.equals(Ovm3)) { + hypervisorsListInUse.add(Ovm3); } } } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates: Exception caught while getting hypervisor types from clusters: " + e.getMessage()); + logger.error("updateSystemVmTemplates: Exception caught while getting hypervisor types from clusters: " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e); } final Map NewTemplateNameList = new HashMap() { { - put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.15.1"); - put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.15.1"); - put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.15.1"); - put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.15.1"); - put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.15.1"); - put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.15.1"); + put(KVM, "systemvm-kvm-4.15.1"); + put(VMware, "systemvm-vmware-4.15.1"); + put(XenServer, "systemvm-xenserver-4.15.1"); + put(Hyperv, "systemvm-hyperv-4.15.1"); + put(LXC, "systemvm-lxc-4.15.1"); + put(Ovm3, "systemvm-ovm3-4.15.1"); } }; final Map routerTemplateConfigurationNames = new HashMap() { { - put(Hypervisor.HypervisorType.KVM, "router.template.kvm"); - put(Hypervisor.HypervisorType.VMware, "router.template.vmware"); - put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver"); - put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv"); - put(Hypervisor.HypervisorType.LXC, "router.template.lxc"); - put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3"); + put(KVM, "router.template.kvm"); + put(VMware, "router.template.vmware"); + put(XenServer, "router.template.xenserver"); + put(Hyperv, "router.template.hyperv"); + put(LXC, "router.template.lxc"); + put(Ovm3, "router.template.ovm3"); } }; final Map newTemplateUrl = new HashMap() { { - put(Hypervisor.HypervisorType.KVM, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); - put(Hypervisor.HypervisorType.VMware, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-vmware.ova"); - put(Hypervisor.HypervisorType.XenServer, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-xen.vhd.bz2"); - put(Hypervisor.HypervisorType.Hyperv, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-hyperv.vhd.zip"); - put(Hypervisor.HypervisorType.LXC, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); - put(Hypervisor.HypervisorType.Ovm3, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-ovm.raw.bz2"); + put(KVM, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); + put(VMware, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-vmware.ova"); + put(XenServer, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-xen.vhd.bz2"); + put(Hyperv, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-hyperv.vhd.zip"); + put(LXC, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); + put(Ovm3, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-ovm.raw.bz2"); } }; final Map newTemplateChecksum = new HashMap() { { - put(Hypervisor.HypervisorType.KVM, "0e9f9a7d0957c3e0a2088e41b2da2cec"); - put(Hypervisor.HypervisorType.XenServer, "86373992740b1eca8aff8b08ebf3aea5"); - put(Hypervisor.HypervisorType.VMware, "4006982765846d373eb3719b2fe4d720"); - put(Hypervisor.HypervisorType.Hyperv, "0b9514e4b6cba1f636fea2125f0f7a5f"); - put(Hypervisor.HypervisorType.LXC, "0e9f9a7d0957c3e0a2088e41b2da2cec"); - put(Hypervisor.HypervisorType.Ovm3, "ae3977e696b3e6c81bdcbb792d514d29"); + put(KVM, "0e9f9a7d0957c3e0a2088e41b2da2cec"); + put(XenServer, "86373992740b1eca8aff8b08ebf3aea5"); + put(VMware, "4006982765846d373eb3719b2fe4d720"); + put(Hyperv, "0b9514e4b6cba1f636fea2125f0f7a5f"); + put(LXC, "0e9f9a7d0957c3e0a2088e41b2da2cec"); + put(Ovm3, "ae3977e696b3e6c81bdcbb792d514d29"); } }; for (final Map.Entry hypervisorAndTemplateName : NewTemplateNameList.entrySet()) { - LOG.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); + logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null and account_id in (select id from account where type = 1 and removed is NULL) order by id desc limit 1")) { // Get systemvm template id for corresponding hypervisor long templateId = -1; @@ -157,7 +153,7 @@ public void updateSystemVmTemplates(final Connection conn) { templateId = rs.getLong(1); } } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage()); + logger.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates: Exception caught while getting ids of templates", e); } @@ -167,7 +163,7 @@ public void updateSystemVmTemplates(final Connection conn) { templ_type_pstmt.setLong(1, templateId); templ_type_pstmt.executeUpdate(); } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage()); + logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e); } // update template ID of system Vms @@ -177,7 +173,7 @@ public void updateSystemVmTemplates(final Connection conn) { update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); update_templ_id_pstmt.executeUpdate(); } catch (final Exception e) { - LOG.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId + logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId + ": " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId, e); @@ -190,7 +186,7 @@ public void updateSystemVmTemplates(final Connection conn) { update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); update_pstmt.executeUpdate(); } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + logger.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue() + ": " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e); @@ -203,14 +199,14 @@ public void updateSystemVmTemplates(final Connection conn) { update_pstmt.setString(2, "minreq.sysvmtemplate.version"); update_pstmt.executeUpdate(); } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.1: " + e.getMessage()); + logger.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.1: " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.1", e); } } else { if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) { throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); } else { - LOG.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + logger.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade"); // Update the latest template URLs for corresponding // hypervisor @@ -221,7 +217,7 @@ public void updateSystemVmTemplates(final Connection conn) { update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); update_templ_url_pstmt.executeUpdate(); } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + logger.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + hypervisorAndTemplateName.getKey().toString(), e); @@ -229,11 +225,11 @@ public void updateSystemVmTemplates(final Connection conn) { } } } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage()); + logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e); } } - LOG.debug("Updating System Vm Template IDs Complete"); + logger.debug("Updating System Vm Template IDs Complete"); } @Override diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41520.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41520.java index bf91c8f7aceb..41b362c4bf7d 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41520.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41520.java @@ -21,11 +21,8 @@ import java.io.InputStream; import java.sql.Connection; -import org.apache.log4j.Logger; -public class Upgrade41510to41520 implements DbUpgrade { - - final static Logger LOG = Logger.getLogger(Upgrade41510to41520.class); +public class Upgrade41510to41520 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java index 107742076fd2..76227d434173 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java @@ -28,14 +28,12 @@ import com.cloud.upgrade.RolePermissionChecker; import com.cloud.upgrade.SystemVmTemplateRegistration; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41520to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41520to41600 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41520to41600.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; private RolePermissionChecker rolePermissionChecker = new RolePermissionChecker(); @@ -82,21 +80,21 @@ private void populateAnnotationPermissions(Connection conn) { } private void checkAndPersistAnnotationPermissions(Connection conn, RoleType roleType, List rules) { - LOG.debug("Checking the annotation permissions for the role: " + roleType.getId()); + logger.debug("Checking the annotation permissions for the role: " + roleType.getId()); for (String rule : rules) { - LOG.debug("Checking the annotation permissions for the role: " + roleType.getId() + " and rule: " + rule); + logger.debug("Checking the annotation permissions for the role: " + roleType.getId() + " and rule: " + rule); if (!rolePermissionChecker.existsRolePermissionByRoleIdAndRule(conn, roleType.getId(), rule)) { - LOG.debug("Inserting role permission for role: " + roleType.getId() + " and rule: " + rule); + logger.debug("Inserting role permission for role: " + roleType.getId() + " and rule: " + rule); rolePermissionChecker.insertAnnotationRulePermission(conn, roleType.getId(), rule); } else { - LOG.debug("Found existing role permission for role: " + roleType.getId() + " and rule: " + rule + + logger.debug("Found existing role permission for role: " + roleType.getId() + " and rule: " + rule + ", not updating it"); } } } private void generateUuidForExistingSshKeyPairs(Connection conn) { - LOG.debug("Generating uuid for existing ssh key-pairs"); + logger.debug("Generating uuid for existing ssh key-pairs"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`ssh_keypairs` WHERE uuid is null"); ResultSet rs = pstmt.executeQuery(); @@ -112,10 +110,10 @@ private void generateUuidForExistingSshKeyPairs(Connection conn) { if (!pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully generated uuid for existing ssh key-pairs"); + logger.debug("Successfully generated uuid for existing ssh key-pairs"); } catch (SQLException e) { String errMsg = "Exception while generating uuid for existing ssh key-pairs: " + e.getMessage(); - LOG.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg, e); } } @@ -127,7 +125,7 @@ private void initSystemVmTemplateRegistration() { @Override @SuppressWarnings("serial") public void updateSystemVmTemplates(final Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41600to41610.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41600to41610.java index 8094a2e9a3c1..3208b4ad8f97 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41600to41610.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41600to41610.java @@ -19,14 +19,12 @@ import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; -public class Upgrade41600to41610 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41600to41610 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41600to41610.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; @Override @@ -77,7 +75,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java index bb4e70567c62..0a0ab0b9f5a9 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java @@ -24,14 +24,12 @@ import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41610to41700 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41610to41700 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41700to41710.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; @Override @@ -82,7 +80,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); @@ -92,7 +90,7 @@ public void updateSystemVmTemplates(Connection conn) { } public void fixWrongDatastoreClusterPoolUuid(Connection conn) { - LOG.debug("Replacement of faulty pool uuids on datastorecluster"); + logger.debug("Replacement of faulty pool uuids on datastorecluster"); try (PreparedStatement pstmt = conn.prepareStatement("SELECT id,uuid FROM storage_pool " + "WHERE uuid NOT LIKE \"%-%-%-%\" AND removed IS NULL " + "AND pool_type = 'DatastoreCluster';"); ResultSet rs = pstmt.executeQuery()) { @@ -109,7 +107,7 @@ public void fixWrongDatastoreClusterPoolUuid(Connection conn) { updateStmt.executeBatch(); } catch (SQLException ex) { String errorMsg = "fixWrongPoolUuid:Exception while updating faulty pool uuids"; - LOG.error(errorMsg,ex); + logger.error(errorMsg,ex); throw new CloudRuntimeException(errorMsg, ex); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41700to41710.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41700to41710.java index a228a01b9e80..e3eb2bf514df 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41700to41710.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41700to41710.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.VolumeVO; @@ -32,9 +31,8 @@ import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41700to41710 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41700to41710 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41700to41710.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; private PrimaryDataStoreDao storageDao; @@ -88,7 +86,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41710to41720.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41710to41720.java index 91b7cfe978dc..9854268c1ff1 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41710to41720.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41710to41720.java @@ -18,14 +18,12 @@ import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; -public class Upgrade41710to41720 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41710to41720 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41710to41720.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; @@ -64,7 +62,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41720to41800.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41720to41800.java index 77fffb17ddd0..6a90396deb0b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41720to41800.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41720to41800.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.usage.UsageTypes; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.lang3.time.DateUtils; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; @@ -39,9 +38,8 @@ import java.util.List; import java.util.Map; -public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41720to41800 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41720to41800.class); private GuestOsMapper guestOsMapper = new GuestOsMapper(); @@ -101,7 +99,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); @@ -111,7 +109,7 @@ public void updateSystemVmTemplates(Connection conn) { } protected void convertQuotaTariffsToNewParadigm(Connection conn) { - LOG.info("Converting quota tariffs to new paradigm."); + logger.info("Converting quota tariffs to new paradigm."); List usageTypeResponses = UsageTypes.listUsageTypes(); @@ -120,14 +118,14 @@ protected void convertQuotaTariffsToNewParadigm(Connection conn) { String tariffTypeDescription = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(usageTypeResponse, "description", "usageType"); - LOG.info(String.format("Converting quota tariffs of type %s to new paradigm.", tariffTypeDescription)); + logger.info(String.format("Converting quota tariffs of type %s to new paradigm.", tariffTypeDescription)); for (boolean previousTariff : Arrays.asList(true, false)) { Map tariffs = selectTariffs(conn, usageType, previousTariff, tariffTypeDescription); int tariffsSize = tariffs.size(); if (tariffsSize < 2) { - LOG.info(String.format("Quota tariff of type %s has [%s] %s register(s). Tariffs with less than 2 register do not need to be converted to new paradigm.", + logger.info(String.format("Quota tariff of type %s has [%s] %s register(s). Tariffs with less than 2 register do not need to be converted to new paradigm.", tariffTypeDescription, tariffsSize, previousTariff ? "previous of current" : "next to current")); continue; } @@ -143,7 +141,7 @@ protected Map selectTariffs(Connection conn, Integer usageType, bool String selectQuotaTariffs = String.format("SELECT id, effective_on FROM cloud_usage.quota_tariff WHERE %s AND usage_type = ? ORDER BY effective_on, updated_on;", previousTariff ? "usage_name = name" : "removed is null"); - LOG.info(String.format("Selecting %s quota tariffs of type [%s] according to SQL [%s].", previousTariff ? "previous of current" : "next to current", + logger.info(String.format("Selecting %s quota tariffs of type [%s] according to SQL [%s].", previousTariff ? "previous of current" : "next to current", tariffTypeDescription, selectQuotaTariffs)); try (PreparedStatement pstmt = conn.prepareStatement(selectQuotaTariffs)) { @@ -158,7 +156,7 @@ protected Map selectTariffs(Connection conn, Integer usageType, bool } catch (SQLException e) { String message = String.format("Unable to retrieve %s quota tariffs of type [%s] due to [%s].", previousTariff ? "previous" : "next", tariffTypeDescription, e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -168,7 +166,7 @@ protected void executeUpdateQuotaTariffSetEndDateAndRemoved(Connection conn, Int Object[] ids = tariffs.keySet().toArray(); - LOG.info(String.format("Updating %s registers of %s quota tariffs of type [%s] with SQL [%s].", tariffs.size() - 1, setRemoved ? "previous of current" : + logger.info(String.format("Updating %s registers of %s quota tariffs of type [%s] with SQL [%s].", tariffs.size() - 1, setRemoved ? "previous of current" : "next to current", tariffTypeDescription, updateQuotaTariff)); for (int i = 0; i < tariffs.size() - 1; i++) { @@ -195,19 +193,19 @@ protected void executeUpdateQuotaTariffSetEndDateAndRemoved(Connection conn, Int pstmt.setLong(2, id); } - LOG.info(String.format("Updating \"end_date\" to [%s] %sof quota tariff with ID [%s].", sqlEndDate, updateRemoved, id)); + logger.info(String.format("Updating \"end_date\" to [%s] %sof quota tariff with ID [%s].", sqlEndDate, updateRemoved, id)); pstmt.executeUpdate(); } catch (SQLException e) { String message = String.format("Unable to update \"end_date\" %s of quota tariffs of usage type [%s] due to [%s].", setRemoved ? "and \"removed\"" : "", usageType, e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } } protected void convertVmResourcesQuotaTypesToRunningVmQuotaType(Connection conn) { - LOG.info("Converting quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\" to \"RUNNING_VM\"."); + logger.info("Converting quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\" to \"RUNNING_VM\"."); String insertSql = "INSERT INTO cloud_usage.quota_tariff (usage_type, usage_name, usage_unit, usage_discriminator, currency_value, effective_on, updated_on," + " updated_by, uuid, name, description, removed, end_date, activation_rule)\n" @@ -225,11 +223,11 @@ protected void convertVmResourcesQuotaTypesToRunningVmQuotaType(Connection conn) pstmt.executeUpdate(); } catch (SQLException e) { String message = String.format("Failed to convert quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\" to \"RUNNING_VM\" due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } - LOG.info("Disabling unused quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\"."); + logger.info("Disabling unused quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\"."); String updateSql = "UPDATE cloud_usage.quota_tariff SET removed = now() WHERE usage_type in (15, 16, 17) and removed is null;"; @@ -237,7 +235,7 @@ protected void convertVmResourcesQuotaTypesToRunningVmQuotaType(Connection conn) pstmt.executeUpdate(); } catch (SQLException e) { String message = String.format("Failed disable quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\" due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -251,7 +249,7 @@ private void correctGuestOsNames() { } private void updateGuestOsMappings() { - LOG.debug("Updating guest OS mappings"); + logger.debug("Updating guest OS mappings"); // Add support for SUSE Linux Enterprise Desktop 12 SP3 (64-bit) for Xenserver 8.1.0 List mappings = new ArrayList(); @@ -708,7 +706,7 @@ private void updateGuestOsMappings() { } private void correctGuestOsIdsInHypervisorMapping(final Connection conn) { - LOG.debug("Correcting guest OS ids in hypervisor mappings"); + logger.debug("Correcting guest OS ids in hypervisor mappings"); guestOsMapper.updateGuestOsIdInHypervisorMapping(conn, 10, "Ubuntu 20.04 LTS", new GuestOSHypervisorMapping("Xenserver", "8.2.0", "Ubuntu Focal Fossa 20.04")); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java index a58d9965259a..b8d2e6180681 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java @@ -22,7 +22,6 @@ import com.cloud.storage.GuestOSVO; import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; @@ -30,8 +29,7 @@ import java.util.HashSet; import java.util.List; -public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41800to41810.class); +public class Upgrade41800to41810 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { private GuestOsMapper guestOsMapper = new GuestOsMapper(); private SystemVmTemplateRegistration systemVmTemplateRegistration; @@ -96,7 +94,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); @@ -106,12 +104,12 @@ public void updateSystemVmTemplates(Connection conn) { } private void updateGuestOsMappings(Connection conn) { - LOG.debug("Updating guest OS mappings"); + logger.debug("Updating guest OS mappings"); GuestOsMapper guestOsMapper = new GuestOsMapper(); List mappings = new ArrayList<>(); - LOG.debug("Adding Ubuntu 20.04 support for VMware 6.5+"); + logger.debug("Adding Ubuntu 20.04 support for VMware 6.5+"); guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "6.5", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "6.7", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "6.7.1", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); @@ -123,7 +121,7 @@ private void updateGuestOsMappings(Connection conn) { guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "7.0.3.0", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "8.0", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); - LOG.debug("Adding Ubuntu 22.04 support for KVM and VMware 6.5+"); + logger.debug("Adding Ubuntu 22.04 support for KVM and VMware 6.5+"); mappings.add(new GuestOSHypervisorMapping("KVM", "default", "Ubuntu 22.04 LTS")); mappings.add(new GuestOSHypervisorMapping("VMware", "6.5", "ubuntu64Guest")); mappings.add(new GuestOSHypervisorMapping("VMware", "6.7", "ubuntu64Guest")); @@ -138,7 +136,7 @@ private void updateGuestOsMappings(Connection conn) { guestOsMapper.addGuestOsAndHypervisorMappings(10, "Ubuntu 22.04 LTS", mappings); mappings.clear(); - LOG.debug("Correcting guest OS names in hypervisor mappings for VMware 8.0 ad 8.0.0.1"); + logger.debug("Correcting guest OS names in hypervisor mappings for VMware 8.0 ad 8.0.0.1"); final String hypervisorVMware = Hypervisor.HypervisorType.VMware.name(); final String hypervisorVersionVmware8 = "8.0"; guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "AlmaLinux 9", new GuestOSHypervisorMapping(hypervisorVMware, hypervisorVersionVmware8, "almalinux_64Guest")); @@ -148,7 +146,7 @@ private void updateGuestOsMappings(Connection conn) { guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Oracle Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "8.0.0.1", "oracleLinux9_64Guest")); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Rocky Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "8.0.0.1", "rockylinux_64Guest")); - LOG.debug("Correcting guest OS names in hypervisor mappings for Red Hat Enterprise Linux 9"); + logger.debug("Correcting guest OS names in hypervisor mappings for Red Hat Enterprise Linux 9"); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "7.0", "rhel9_64Guest")); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "7.0.1.0", "rhel9_64Guest")); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "7.0.2.0", "rhel9_64Guest")); @@ -156,7 +154,7 @@ private void updateGuestOsMappings(Connection conn) { guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, hypervisorVersionVmware8, "rhel9_64Guest")); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "8.0.0.1", "rhel9_64Guest")); - LOG.debug("Adding new guest OS ids in hypervisor mappings for VMware 8.0"); + logger.debug("Adding new guest OS ids in hypervisor mappings for VMware 8.0"); // Add support for darwin22_64Guest from VMware 8.0 mappings.add(new GuestOSHypervisorMapping(hypervisorVMware, hypervisorVersionVmware8, "darwin22_64Guest")); guestOsMapper.addGuestOsAndHypervisorMappings(7, "macOS 13 (64-bit)", mappings); @@ -209,7 +207,7 @@ private void updateGuestOsMappings(Connection conn) { } private void copyGuestOsMappingsToVMware80u1() { - LOG.debug("Copying guest OS mappings from VMware 8.0 to VMware 8.0.1"); + logger.debug("Copying guest OS mappings from VMware 8.0 to VMware 8.0.1"); GuestOsMapper guestOsMapper = new GuestOsMapper(); guestOsMapper.copyGuestOSHypervisorMappings(Hypervisor.HypervisorType.VMware, "8.0", "8.0.1"); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41810to41900.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41810to41900.java index 13e30c0f6e2d..e2b1ae1399b6 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41810to41900.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41810to41900.java @@ -20,7 +20,6 @@ import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.DateUtil; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import org.jasypt.exceptions.EncryptionOperationNotPossibleException; import java.io.InputStream; @@ -34,8 +33,7 @@ import java.text.SimpleDateFormat; import java.util.Date; -public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41810to41900.class); +public class Upgrade41810to41900 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { private SystemVmTemplateRegistration systemVmTemplateRegistration; private static final String ACCOUNT_DETAILS = "account_details"; @@ -97,7 +95,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); @@ -107,15 +105,15 @@ public void updateSystemVmTemplates(Connection conn) { } protected void decryptConfigurationValuesFromAccountAndDomainScopesNotInSecureHiddenCategories(Connection conn) { - LOG.info("Decrypting global configuration values from the following tables: account_details and domain_details."); + logger.info("Decrypting global configuration values from the following tables: account_details and domain_details."); Map accountsMap = getConfigsWithScope(conn, ACCOUNT_DETAILS); updateConfigValuesWithScope(conn, accountsMap, ACCOUNT_DETAILS); - LOG.info("Successfully decrypted configurations from account_details table."); + logger.info("Successfully decrypted configurations from account_details table."); Map domainsMap = getConfigsWithScope(conn, DOMAIN_DETAILS); updateConfigValuesWithScope(conn, domainsMap, DOMAIN_DETAILS); - LOG.info("Successfully decrypted configurations from domain_details table."); + logger.info("Successfully decrypted configurations from domain_details table."); } protected Map getConfigsWithScope(Connection conn, String table) { @@ -132,19 +130,19 @@ protected Map getConfigsWithScope(Connection conn, String table) { return configsToBeUpdated; } catch (SQLException e) { String message = String.format("Unable to retrieve data from table [%s] due to [%s].", table, e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } public void migrateBackupDates(Connection conn) { - LOG.info("Trying to convert backups' date column from varchar(255) to datetime type."); + logger.info("Trying to convert backups' date column from varchar(255) to datetime type."); modifyDateColumnNameAndCreateNewOne(conn); fetchDatesAndMigrateToNewColumn(conn); dropOldColumn(conn); - LOG.info("Finished converting backups' date column from varchar(255) to datetime."); + logger.info("Finished converting backups' date column from varchar(255) to datetime."); } private void modifyDateColumnNameAndCreateNewOne(Connection conn) { @@ -153,7 +151,7 @@ private void modifyDateColumnNameAndCreateNewOne(Connection conn) { pstmt.execute(); } catch (SQLException e) { String message = String.format("Unable to alter backups' date column name due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } @@ -162,7 +160,7 @@ private void modifyDateColumnNameAndCreateNewOne(Connection conn) { pstmt.execute(); } catch (SQLException e) { String message = String.format("Unable to crate new backups' column date due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -177,12 +175,12 @@ protected void updateConfigValuesWithScope(Connection conn, Map co pstmt.setString(1, decryptedValue); pstmt.setLong(2, config.getKey()); - LOG.info(String.format("Updating config with ID [%s] to value [%s].", config.getKey(), decryptedValue)); + logger.info(String.format("Updating config with ID [%s] to value [%s].", config.getKey(), decryptedValue)); pstmt.executeUpdate(); } catch (SQLException | EncryptionOperationNotPossibleException e) { String message = String.format("Unable to update config value with ID [%s] on table [%s] due to [%s]. The config value may already be decrypted.", config.getKey(), table, e); - LOG.error(message); + logger.error(message); throw new CloudRuntimeException(message, e); } } @@ -203,7 +201,7 @@ private void fetchDatesAndMigrateToNewColumn(Connection conn) { } } catch (SQLException e) { String message = String.format("Unable to retrieve backup dates due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -224,7 +222,7 @@ private java.sql.Date tryToTransformStringToDate(String date) { } if (parsedDate == null) { String msg = String.format("Unable to parse date [%s]. Will change backup date to null.", date); - LOG.error(msg); + logger.error(msg); return null; } @@ -240,7 +238,7 @@ private void updateBackupDate(Connection conn, long id, java.sql.Date date) { pstmt.executeUpdate(); } catch (SQLException e) { String message = String.format("Unable to update backup date with id [%s] to date [%s] due to [%s].", id, date, e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -251,7 +249,7 @@ private void dropOldColumn(Connection conn) { pstmt.execute(); } catch (SQLException e) { String message = String.format("Unable to drop old_date column due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to41910.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to41910.java index 4cdd1c3364df..4eb8e9bdb2a6 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to41910.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to41910.java @@ -16,16 +16,13 @@ // under the License. package com.cloud.upgrade.dao; -import org.apache.log4j.Logger; - import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade41900to41910 implements DbUpgrade, DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41900to41910.class); +public class Upgrade41900to41910 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { private SystemVmTemplateRegistration systemVmTemplateRegistration; @Override @@ -80,7 +77,7 @@ private void initSystemVmTemplateRegistration() { @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41910to42000.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41910to42000.java new file mode 100644 index 000000000000..4c26c6bde50b --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41910to42000.java @@ -0,0 +1,116 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.upgrade.dao; + +import java.io.InputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import com.cloud.upgrade.SystemVmTemplateRegistration; +import com.cloud.utils.exception.CloudRuntimeException; + +public class Upgrade41910to42000 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { + private SystemVmTemplateRegistration systemVmTemplateRegistration; + private static final int MAX_INDEXED_CHARS_IN_CHAR_SET_UTF8MB4 = 191; + + @Override + public String[] getUpgradableVersionRange() { + return new String[] {"4.19.1.0", "4.20.0.0"}; + } + + @Override + public String getUpgradedVersion() { + return "4.20.0.0"; + } + + @Override + public boolean supportsRollingUpgrade() { + return false; + } + + @Override + public InputStream[] getPrepareScripts() { + final String scriptFile = "META-INF/db/schema-41910to42000.sql"; + final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); + if (script == null) { + throw new CloudRuntimeException("Unable to find " + scriptFile); + } + + return new InputStream[] {script}; + } + + @Override + public void performDataMigration(Connection conn) { + checkAndUpdateAffinityGroupNameCharSetToUtf8mb4(conn); + } + + @Override + public InputStream[] getCleanupScripts() { + final String scriptFile = "META-INF/db/schema-41910to42000-cleanup.sql"; + final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); + if (script == null) { + throw new CloudRuntimeException("Unable to find " + scriptFile); + } + + return new InputStream[] {script}; + } + + private void initSystemVmTemplateRegistration() { + systemVmTemplateRegistration = new SystemVmTemplateRegistration(""); + } + + @Override + public void updateSystemVmTemplates(Connection conn) { + logger.debug("Updating System Vm template IDs"); + initSystemVmTemplateRegistration(); + try { + systemVmTemplateRegistration.updateSystemVmTemplates(conn); + } catch (Exception e) { + throw new CloudRuntimeException("Failed to find / register SystemVM template(s)"); + } + } + + private void checkAndUpdateAffinityGroupNameCharSetToUtf8mb4(Connection conn) { + logger.debug("Check and update char set for affinity group name to utf8mb4"); + try { + PreparedStatement pstmt = conn.prepareStatement("SELECT MAX(LENGTH(name)) FROM `cloud`.`affinity_group`"); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + long maxLengthOfName = rs.getLong(1); + if (maxLengthOfName <= MAX_INDEXED_CHARS_IN_CHAR_SET_UTF8MB4) { + pstmt = conn.prepareStatement(String.format("ALTER TABLE `cloud`.`affinity_group` MODIFY `name` VARCHAR(%d) CHARACTER SET utf8mb4 NOT NULL", MAX_INDEXED_CHARS_IN_CHAR_SET_UTF8MB4)); + pstmt.executeUpdate(); + logger.debug("Successfully updated char set for affinity group name to utf8mb4"); + } else { + logger.warn("Unable to update char set for affinity group name, as there are some names with more than " + MAX_INDEXED_CHARS_IN_CHAR_SET_UTF8MB4 + + " chars (max supported chars for index)"); + } + } + + if (rs != null && !rs.isClosed()) { + rs.close(); + } + if (pstmt != null && !pstmt.isClosed()) { + pstmt.close(); + } + } catch (final SQLException e) { + logger.warn("Exception while updating char set for affinity group name to utf8mb4: " + e.getMessage()); + } + } +} diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade420to421.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade420to421.java index d7ba2ed20da3..9ca342d7f4ad 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade420to421.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade420to421.java @@ -23,13 +23,11 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.hypervisor.Hypervisor; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade420to421 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade420to421.class); +public class Upgrade420to421 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -89,7 +87,7 @@ private void updateOverprovisioningPerVm(Connection conn) { } } // Need to populate only when overprovisioning factor doesn't pre exist. - s_logger.debug("Starting updating user_vm_details with cpu/memory overprovisioning factors"); + logger.debug("Starting updating user_vm_details with cpu/memory overprovisioning factors"); try ( PreparedStatement pstmt2 = conn .prepareStatement("select id, hypervisor_type from `cloud`.`vm_instance` where removed is null and id not in (select vm_id from `cloud`.`user_vm_details` where name='cpuOvercommitRatio')"); @@ -123,14 +121,14 @@ private void updateOverprovisioningPerVm(Connection conn) { } } } - s_logger.debug("Done updating user_vm_details with cpu/memory overprovisioning factors"); + logger.debug("Done updating user_vm_details with cpu/memory overprovisioning factors"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to update cpu/memory overprovisioning factors", e); } } private void upgradeResourceCount(Connection conn) { - s_logger.debug("upgradeResourceCount start"); + logger.debug("upgradeResourceCount start"); String sqlSelectAccountIds = "select id, domain_id FROM `cloud`.`account` where removed is NULL "; String sqlSelectOfferingTotals = "SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)" + " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" @@ -236,7 +234,7 @@ private void upgradeResourceCount(Connection conn) { } } } - s_logger.debug("upgradeResourceCount finish"); + logger.debug("upgradeResourceCount finish"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage) ", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade421to430.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade421to430.java index 55e7d3bdac22..88428f455f3b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade421to430.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade421to430.java @@ -24,13 +24,11 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade421to430 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade421to430.class); +public class Upgrade421to430 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -88,11 +86,11 @@ private void upgradeMemoryOfSsvmOffering(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for secondary storage vm. ", e); } - s_logger.debug("Done upgrading RAM for service offering of Secondary Storage VM to " + newRamSize); + logger.debug("Done upgrading RAM for service offering of Secondary Storage VM to " + newRamSize); } private void encryptImageStoreDetails(Connection conn) { - s_logger.debug("Encrypting image store details"); + logger.debug("Encrypting image store details"); try ( PreparedStatement selectPstmt = conn.prepareStatement("select id, value from `cloud`.`image_store_details` where name = 'key' or name = 'secretkey'"); ResultSet rs = selectPstmt.executeQuery(); @@ -115,7 +113,7 @@ private void encryptImageStoreDetails(Connection conn) { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt image_store_details values ", e); } - s_logger.debug("Done encrypting image_store_details"); + logger.debug("Done encrypting image_store_details"); } @Override diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade430to440.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade430to440.java index 43d4d877361e..9a2077471e62 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade430to440.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade430to440.java @@ -23,14 +23,12 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.network.Network; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade430to440 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade430to440.class); +public class Upgrade430to440 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -163,12 +161,12 @@ private void secondaryIpsAccountAndDomainIdsUpdate(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Exception while Moving private zone information to dedicated resources", e); } - s_logger.debug("Done updating vm nic secondary ip account and domain ids"); + logger.debug("Done updating vm nic secondary ip account and domain ids"); } private void moveCidrsToTheirOwnTable(Connection conn) { - s_logger.debug("Moving network acl item cidrs to a row per cidr"); + logger.debug("Moving network acl item cidrs to a row per cidr"); String networkAclItemSql = "SELECT id, cidr FROM `cloud`.`network_acl_item`"; String networkAclItemCidrSql = "INSERT INTO `cloud`.`network_acl_item_cidrs` (network_acl_item_id, cidr) VALUES (?,?)"; @@ -184,7 +182,7 @@ private void moveCidrsToTheirOwnTable(Connection conn) { long itemId = rsItems.getLong(1); // get the source cidr list String cidrList = rsItems.getString(2); - s_logger.debug("Moving '" + cidrList + "' to a row per cidr"); + logger.debug("Moving '" + cidrList + "' to a row per cidr"); // split it String[] cidrArray = cidrList.split(","); // insert a record per cidr @@ -197,11 +195,11 @@ private void moveCidrsToTheirOwnTable(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Exception while Moving network acl item cidrs to a row per cidr", e); } - s_logger.debug("Done moving network acl item cidrs to a row per cidr"); + logger.debug("Done moving network acl item cidrs to a row per cidr"); } private void updateVlanUris(Connection conn) { - s_logger.debug("updating vlan URIs"); + logger.debug("updating vlan URIs"); try(PreparedStatement selectstatement = conn.prepareStatement("SELECT id, vlan_id FROM `cloud`.`vlan` where vlan_id not like '%:%'"); ResultSet results = selectstatement.executeQuery()) { @@ -224,7 +222,7 @@ private void updateVlanUris(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Unable to update vlan URIs ", e); } - s_logger.debug("Done updating vlan URIs"); + logger.debug("Done updating vlan URIs"); } @Override diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade431to440.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade431to440.java index 98b52ac0aa96..54aa3b76d6f9 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade431to440.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade431to440.java @@ -17,10 +17,8 @@ package com.cloud.upgrade.dao; -import org.apache.log4j.Logger; -public class Upgrade431to440 extends Upgrade430to440 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade431to440.class); +public class Upgrade431to440 extends Upgrade430to440 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade432to440.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade432to440.java index ded0db474d5e..3b934c1f3447 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade432to440.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade432to440.java @@ -17,10 +17,8 @@ package com.cloud.upgrade.dao; -import org.apache.log4j.Logger; -public class Upgrade432to440 extends Upgrade431to440 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade432to440.class); +public class Upgrade432to440 extends Upgrade431to440 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade440to441.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade440to441.java index a51f464a797f..4309a1a53c5e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade440to441.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade440to441.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade440to441 implements DbUpgrade { +public class Upgrade440to441 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade441to442.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade441to442.java index 4234428f72b0..1993b15b6403 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade441to442.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade441to442.java @@ -23,7 +23,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade441to442 implements DbUpgrade { +public class Upgrade441to442 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade442to450.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade442to450.java index 54e8da5f6e9e..803d521ac24c 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade442to450.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade442to450.java @@ -28,13 +28,11 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade442to450 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade442to450.class); +public class Upgrade442to450 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -82,7 +80,7 @@ private void updateMaxRouterSizeConfig(Connection conn) { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt configuration values ", e); } - s_logger.debug("Done updating router.ram.size config to 256"); + logger.debug("Done updating router.ram.size config to 256"); } private void upgradeMemoryOfVirtualRoutervmOffering(Connection conn) { @@ -109,7 +107,7 @@ private void upgradeMemoryOfVirtualRoutervmOffering(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for domain router. ", e); } - s_logger.debug("Done upgrading RAM for service offering of domain router to " + newRamSize); + logger.debug("Done upgrading RAM for service offering of domain router to " + newRamSize); } private void upgradeMemoryOfInternalLoadBalancervmOffering(Connection conn) { @@ -134,7 +132,7 @@ private void upgradeMemoryOfInternalLoadBalancervmOffering(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for internal loadbalancer vm. ", e); } - s_logger.debug("Done upgrading RAM for service offering of internal loadbalancer vm to " + newRamSize); + logger.debug("Done upgrading RAM for service offering of internal loadbalancer vm to " + newRamSize); } @Override @@ -155,7 +153,7 @@ private void dropInvalidKeyFromStoragePoolTable(Connection conn) { keys.add("id_2"); uniqueKeys.put("storage_pool", keys); - s_logger.debug("Dropping id_2 key from storage_pool table"); + logger.debug("Dropping id_2 key from storage_pool table"); for (Map.Entry> entry: uniqueKeys.entrySet()) { DbUpgradeUtils.dropKeysIfExist(conn,entry.getKey(), entry.getValue(), false); } @@ -168,7 +166,7 @@ private void dropDuplicatedForeignKeyFromAsyncJobTable(Connection conn) { keys.add("fk_async_job_join_map__join_job_id"); foreignKeys.put("async_job_join_map", keys); - s_logger.debug("Dropping fk_async_job_join_map__join_job_id key from async_job_join_map table"); + logger.debug("Dropping fk_async_job_join_map__join_job_id key from async_job_join_map table"); for (Map.Entry> entry: foreignKeys.entrySet()) { DbUpgradeUtils.dropKeysIfExist(conn,entry.getKey(), entry.getValue(), true); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to444.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to444.java index b8110546a13c..61674d9870f6 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to444.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to444.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade443to444 implements DbUpgrade { +public class Upgrade443to444 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to450.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to450.java index 80b2c14e00c7..9f571fedc2c8 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to450.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to450.java @@ -17,7 +17,7 @@ package com.cloud.upgrade.dao; -public class Upgrade443to450 extends Upgrade442to450 implements DbUpgrade { +public class Upgrade443to450 extends Upgrade442to450 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade444to450.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade444to450.java index 52fc7299810a..d393e73f59a9 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade444to450.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade444to450.java @@ -17,7 +17,7 @@ package com.cloud.upgrade.dao; -public class Upgrade444to450 extends Upgrade442to450 implements DbUpgrade { +public class Upgrade444to450 extends Upgrade442to450 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade450to451.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade450to451.java index 015d463347ae..ffdf2cc12738 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade450to451.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade450to451.java @@ -26,13 +26,11 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade450to451 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade450to451.class); +public class Upgrade450to451 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -97,7 +95,7 @@ private void encryptKeyInKeyStore(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Exception while encrypting key column in keystore table", e); } - s_logger.debug("Done encrypting keystore's key column"); + logger.debug("Done encrypting keystore's key column"); } private void encryptIpSecPresharedKeysOfRemoteAccessVpn(Connection conn) { @@ -111,7 +109,7 @@ private void encryptIpSecPresharedKeysOfRemoteAccessVpn(Connection conn) { try { preSharedKey = DBEncryptionUtil.decrypt(preSharedKey); } catch (CloudRuntimeException ignored) { - s_logger.debug("The ipsec_psk preshared key id=" + rowId + "in remote_access_vpn is not encrypted, encrypting it."); + logger.debug("The ipsec_psk preshared key id=" + rowId + "in remote_access_vpn is not encrypted, encrypting it."); } try (PreparedStatement updateStatement = conn.prepareStatement("UPDATE `cloud`.`remote_access_vpn` SET ipsec_psk=? WHERE id=?");) { updateStatement.setString(1, DBEncryptionUtil.encrypt(preSharedKey)); @@ -122,7 +120,7 @@ private void encryptIpSecPresharedKeysOfRemoteAccessVpn(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Unable to update the remote_access_vpn's preshared key ipsec_psk column", e); } - s_logger.debug("Done encrypting remote_access_vpn's ipsec_psk column"); + logger.debug("Done encrypting remote_access_vpn's ipsec_psk column"); } private void encryptStoragePoolUserInfo(Connection conn) { @@ -151,7 +149,7 @@ private void encryptStoragePoolUserInfo(Connection conn) { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt storage pool user info ", e); } - s_logger.debug("Done encrypting storage_pool's user_info column"); + logger.debug("Done encrypting storage_pool's user_info column"); } private void updateUserVmDetailsWithNicAdapterType(Connection conn) { @@ -160,13 +158,13 @@ private void updateUserVmDetailsWithNicAdapterType(Connection conn) { } catch (SQLException e) { throw new CloudRuntimeException("Failed to update user_vm_details table with nicAdapter entries by copying from vm_template_detail table", e); } - s_logger.debug("Done. Updated user_vm_details table with nicAdapter entries by copying from vm_template_detail table. This affects only VM/templates with hypervisor_type as VMware."); + logger.debug("Done. Updated user_vm_details table with nicAdapter entries by copying from vm_template_detail table. This affects only VM/templates with hypervisor_type as VMware."); } private void upgradeVMWareLocalStorage(Connection conn) { try (PreparedStatement updatePstmt = conn.prepareStatement("UPDATE storage_pool SET pool_type='VMFS',host_address=@newaddress WHERE (@newaddress:=concat('VMFS datastore: ', path)) IS NOT NULL AND scope = 'HOST' AND pool_type = 'LVM' AND id IN (SELECT * FROM (SELECT storage_pool.id FROM storage_pool,cluster WHERE storage_pool.cluster_id = cluster.id AND cluster.hypervisor_type='VMware') AS t);");) { updatePstmt.executeUpdate(); - s_logger.debug("Done, upgraded VMWare local storage pool type to VMFS and host_address to the VMFS format"); + logger.debug("Done, upgraded VMWare local storage pool type to VMFS and host_address to the VMFS format"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade VMWare local storage pool type", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade451to452.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade451to452.java index 788b6f28ef1e..d019558a33ca 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade451to452.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade451to452.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade451to452 implements DbUpgrade { +public class Upgrade451to452 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to453.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to453.java index 3bc39ebc68fd..17ec3414896b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to453.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to453.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade452to453 implements DbUpgrade { +public class Upgrade452to453 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to460.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to460.java index 91fe345f4a12..d14d6c9e5435 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to460.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to460.java @@ -25,12 +25,10 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade452to460 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade452to460.class); +public class Upgrade452to460 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -67,7 +65,7 @@ public void performDataMigration(final Connection conn) { public void updateVMInstanceUserId(final Connection conn) { // For schemas before this, copy first user from an account_id which // deployed already running VMs - s_logger.debug("Updating vm_instance column user_id using first user in vm_instance's account_id"); + logger.debug("Updating vm_instance column user_id using first user in vm_instance's account_id"); final String vmInstanceSql = "SELECT id, account_id FROM `cloud`.`vm_instance`"; final String userSql = "SELECT id FROM `cloud`.`user` where account_id=?"; final String userIdUpdateSql = "update `cloud`.`vm_instance` set user_id=? where id=?"; @@ -97,7 +95,7 @@ public void updateVMInstanceUserId(final Connection conn) { } catch (final SQLException e) { throw new CloudRuntimeException("Unable to update user Ids for previously deployed VMs", e); } - s_logger.debug("Done updating user Ids for previously deployed VMs"); + logger.debug("Done updating user Ids for previously deployed VMs"); addRedundancyForNwAndVpc(conn); removeBumPriorityColumn(conn); } @@ -142,14 +140,14 @@ private void removeBumPriorityColumn(final Connection conn) { private void addIndexForVMInstance(final Connection conn) { // Drop index if it exists final List indexList = new ArrayList(); - s_logger.debug("Dropping index i_vm_instance__instance_name from vm_instance table if it exists"); + logger.debug("Dropping index i_vm_instance__instance_name from vm_instance table if it exists"); indexList.add("i_vm_instance__instance_name"); DbUpgradeUtils.dropKeysIfExist(conn, "vm_instance", indexList, false); // Now add index try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`vm_instance` ADD INDEX `i_vm_instance__instance_name`(`instance_name`)");) { pstmt.executeUpdate(); - s_logger.debug("Added index i_vm_instance__instance_name to vm_instance table"); + logger.debug("Added index i_vm_instance__instance_name to vm_instance table"); } catch (final SQLException e) { throw new CloudRuntimeException("Unable to add index i_vm_instance__instance_name to vm_instance table for the column instance_name", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade453to460.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade453to460.java index 2dd4b0aad27b..321d0304f9d0 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade453to460.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade453to460.java @@ -17,7 +17,7 @@ package com.cloud.upgrade.dao; -public class Upgrade453to460 extends Upgrade452to460 implements DbUpgrade { +public class Upgrade453to460 extends Upgrade452to460 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade460to461.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade460to461.java index 88bda4616c80..3642a59e516c 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade460to461.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade460to461.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade460to461 implements DbUpgrade { +public class Upgrade460to461 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade461to470.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade461to470.java index e7922cebf0ac..d2241e0498c8 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade461to470.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade461to470.java @@ -18,15 +18,13 @@ package com.cloud.upgrade.dao; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; -public class Upgrade461to470 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade461to470.class); +public class Upgrade461to470 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -58,10 +56,10 @@ public void alterAddColumnToCloudUsage(final Connection conn) { final String alterTableSql = "ALTER TABLE `cloud_usage`.`cloud_usage` ADD COLUMN `quota_calculated` tinyint(1) DEFAULT 0 NOT NULL COMMENT 'quota calculation status'"; try (PreparedStatement pstmt = conn.prepareStatement(alterTableSql)) { pstmt.executeUpdate(); - s_logger.info("Altered cloud_usage.cloud_usage table and added column quota_calculated"); + logger.info("Altered cloud_usage.cloud_usage table and added column quota_calculated"); } catch (SQLException e) { if (e.getMessage().contains("quota_calculated")) { - s_logger.warn("cloud_usage.cloud_usage table already has a column called quota_calculated"); + logger.warn("cloud_usage.cloud_usage table already has a column called quota_calculated"); } else { throw new CloudRuntimeException("Unable to create column quota_calculated in table cloud_usage.cloud_usage", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade470to471.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade470to471.java index 08cdfdd53f55..0464381dd602 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade470to471.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade470to471.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade470to471 implements DbUpgrade { +public class Upgrade470to471 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade471to480.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade471to480.java index 3b3a0bba03ec..614e1d8779ec 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade471to480.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade471to480.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade471to480 implements DbUpgrade { +public class Upgrade471to480 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade480to481.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade480to481.java index be33709dd921..d1aa4214837f 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade480to481.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade480to481.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade480to481 implements DbUpgrade { +public class Upgrade480to481 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade481to490.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade481to490.java index 2165d809f852..5c950a86b0e3 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade481to490.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade481to490.java @@ -27,13 +27,11 @@ import com.cloud.user.Account; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import com.cloud.utils.db.ScriptRunner; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade481to490 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade481to490.class); +public class Upgrade481to490 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -74,7 +72,7 @@ private void migrateAccountsToDefaultRoles(final Connection conn) { final Integer accountType = selectResultSet.getInt(2); final Long roleId = RoleType.getByAccountType(Account.Type.getFromValue(accountType)).getId(); if (roleId < 1L || roleId > 4L) { - s_logger.warn("Skipping role ID migration due to invalid role_id resolved for account id=" + accountId); + logger.warn("Skipping role ID migration due to invalid role_id resolved for account id=" + accountId); continue; } try (final PreparedStatement updateStatement = conn.prepareStatement("UPDATE `cloud`.`account` SET account.role_id = ? WHERE account.id = ? ;")) { @@ -82,14 +80,14 @@ private void migrateAccountsToDefaultRoles(final Connection conn) { updateStatement.setLong(2, accountId); updateStatement.executeUpdate(); } catch (SQLException e) { - s_logger.error("Failed to update cloud.account role_id for account id:" + accountId + " with exception: " + e.getMessage()); + logger.error("Failed to update cloud.account role_id for account id:" + accountId + " with exception: " + e.getMessage()); throw new CloudRuntimeException("Exception while updating cloud.account role_id", e); } } } catch (SQLException e) { throw new CloudRuntimeException("Exception while migrating existing account table's role_id column to a role based on account type", e); } - s_logger.debug("Done migrating existing accounts to use one of default roles based on account type"); + logger.debug("Done migrating existing accounts to use one of default roles based on account type"); } private void setupRolesAndPermissionsForDynamicChecker(final Connection conn) { @@ -101,7 +99,7 @@ private void setupRolesAndPermissionsForDynamicChecker(final Connection conn) { pstmt.executeUpdate(); } catch (SQLException e) { if (e.getMessage().contains("role_id")) { - s_logger.warn("cloud.account table already has the role_id column, skipping altering table and migration of accounts"); + logger.warn("cloud.account table already has the role_id column, skipping altering table and migration of accounts"); return; } else { throw new CloudRuntimeException("Unable to create column role_id in table cloud.account", e); @@ -116,20 +114,20 @@ private void setupRolesAndPermissionsForDynamicChecker(final Connection conn) { migrateAccountsToDefaultRoles(conn); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Configuring default role-api mappings, use migrate-dynamicroles.py instead if you want to migrate rules from an existing commands.properties file"); + if (logger.isDebugEnabled()) { + logger.debug("Configuring default role-api mappings, use migrate-dynamicroles.py instead if you want to migrate rules from an existing commands.properties file"); } final String scriptFile = "META-INF/db/create-default-role-api-mappings.sql"; final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); if (script == null) { - s_logger.error("Unable to find default role-api mapping sql file, please configure api per role manually"); + logger.error("Unable to find default role-api mapping sql file, please configure api per role manually"); return; } try(final InputStreamReader reader = new InputStreamReader(script)) { ScriptRunner runner = new ScriptRunner(conn, false, true); runner.runScript(reader); } catch (SQLException | IOException e) { - s_logger.error("Unable to insert default api-role mappings from file: " + script + ". Please configure api per role manually, giving up!", e); + logger.error("Unable to insert default api-role mappings from file: " + script + ". Please configure api per role manually, giving up!", e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade490to4910.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade490to4910.java index 8757d7fa5395..fdb5fd261b91 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade490to4910.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade490to4910.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade490to4910 implements DbUpgrade { +public class Upgrade490to4910 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4910to4920.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4910to4920.java index 1950c8f28b88..69cd5b796a8e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4910to4920.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4910to4920.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade4910to4920 implements DbUpgrade { +public class Upgrade4910to4920 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4920to4930.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4920to4930.java index bc02c95064c8..9f5437e8d87e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4920to4930.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4920to4930.java @@ -22,7 +22,7 @@ import java.io.InputStream; import java.sql.Connection; -public class Upgrade4920to4930 implements DbUpgrade { +public class Upgrade4920to4930 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4930to41000.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4930to41000.java index 46abd44aa6a0..631308a975ea 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4930to41000.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4930to41000.java @@ -23,12 +23,10 @@ import java.sql.SQLException; import java.util.HashMap; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade4930to41000 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade4930to41000.class); +public class Upgrade4930to41000 extends DbUpgradeAbstractImpl { public static class MemoryValues { long max; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java index 3e39f81f761c..4c856ab154e0 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java @@ -21,7 +21,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class UpgradeSnapshot217to224 implements DbUpgrade { +public class UpgradeSnapshot217to224 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java index 8e546e7dd4d5..7a5b7de17b5d 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java @@ -21,7 +21,7 @@ import com.cloud.utils.exception.CloudRuntimeException; -public class UpgradeSnapshot223to224 implements DbUpgrade { +public class UpgradeSnapshot223to224 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDaoImpl.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDaoImpl.java index 67fe70fdb29e..90e1912408c8 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDaoImpl.java @@ -23,7 +23,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.upgrade.dao.VersionVO.Step; @@ -40,7 +39,6 @@ @Component @DB() public class VersionDaoImpl extends GenericDaoBase implements VersionDao { - private static final Logger s_logger = Logger.getLogger(VersionDaoImpl.class); final GenericSearchBuilder CurrentVersionSearch; final SearchBuilder AllFieldsSearch; @@ -74,7 +72,7 @@ public VersionVO findByVersion(final String version, final Step step) { @DB public String getCurrentVersion() { try (Connection conn = TransactionLegacy.getStandaloneConnection();) { - s_logger.debug("Checking to see if the database is at a version before it was the version table is created"); + logger.debug("Checking to see if the database is at a version before it was the version table is created"); try ( PreparedStatement pstmt = conn.prepareStatement("SHOW TABLES LIKE 'version'"); @@ -89,8 +87,8 @@ public String getCurrentVersion() { pstmt_domain.executeQuery(); return "2.1.8"; } catch (final SQLException e) { - s_logger.debug("Assuming the exception means domain_id is not there."); - s_logger.debug("No version table and no nics table, returning 2.1.7"); + logger.debug("Assuming the exception means domain_id is not there."); + logger.debug("No version table and no nics table, returning 2.1.7"); return "2.1.7"; } } else { @@ -98,7 +96,7 @@ public String getCurrentVersion() { ResultSet rs_static_nat = pstmt_static_nat.executeQuery();){ return "2.2.1"; } catch (final SQLException e) { - s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); + logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); return "2.2.2"; } } @@ -125,7 +123,7 @@ public String getCurrentVersion() { } // Use nics table information and is_static_nat field from firewall_rules table to determine version information - s_logger.debug("Version table exists, but it's empty; have to confirm that version is 2.2.2"); + logger.debug("Version table exists, but it's empty; have to confirm that version is 2.2.2"); try (PreparedStatement pstmt = conn.prepareStatement("SHOW TABLES LIKE 'nics'"); ResultSet rs = pstmt.executeQuery();){ if (!rs.next()) { @@ -136,7 +134,7 @@ public String getCurrentVersion() { throw new CloudRuntimeException("Unable to determine the current version, version table exists and empty, " + "nics table doesn't exist, is_static_nat field exists in firewall_rules table"); } catch (final SQLException e) { - s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); + logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); return "2.2.2"; } } diff --git a/engine/schema/src/main/java/com/cloud/usage/UsageVO.java b/engine/schema/src/main/java/com/cloud/usage/UsageVO.java index 054ec52e2812..b1f6d295fdd6 100644 --- a/engine/schema/src/main/java/com/cloud/usage/UsageVO.java +++ b/engine/schema/src/main/java/com/cloud/usage/UsageVO.java @@ -17,6 +17,7 @@ package com.cloud.usage; import java.util.Date; +import java.util.TimeZone; import javax.persistence.Column; import javax.persistence.Entity; @@ -27,9 +28,11 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.api.InternalIdentity; import org.apache.cloudstack.usage.Usage; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; +import org.apache.commons.lang3.StringUtils; @Entity @Table(name = "cloud_usage") @@ -411,6 +414,12 @@ public void setState(String state) { @Override public String toString() { - return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "usageId", "usageType", "startDate", "endDate"); + return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "usageId", "usageType"); + } + + public String toString(TimeZone timeZone) { + String startDateString = DateUtil.displayDateInTimezone(timeZone, getStartDate()); + String endDateString = DateUtil.displayDateInTimezone(timeZone, getEndDate()); + return String.format("%s,\"startDate\":\"%s\",\"endDate\":\"%s\"}", StringUtils.chop(this.toString()), startDateString, endDateString); } } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/BucketStatisticsDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/BucketStatisticsDaoImpl.java index 2261389eab6b..1df24079cee1 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/BucketStatisticsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/BucketStatisticsDaoImpl.java @@ -20,14 +20,12 @@ import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.util.List; @Component public class BucketStatisticsDaoImpl extends GenericDaoBase implements BucketStatisticsDao { - private static final Logger s_logger = Logger.getLogger(BucketStatisticsDaoImpl.class); private final SearchBuilder AllFieldsSearch; private final SearchBuilder AccountSearch; diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java index 712f81807c72..3403a8dfe5bb 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.exception.CloudException; @@ -37,7 +36,6 @@ @Component public class UsageBackupDaoImpl extends GenericDaoBase implements UsageBackupDao { - public static final Logger LOGGER = Logger.getLogger(UsageBackupDaoImpl.class); protected static final String UPDATE_DELETED = "UPDATE usage_backup SET removed = ? WHERE account_id = ? AND vm_id = ? and removed IS NULL"; protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT id, zone_id, account_id, domain_id, vm_id, backup_offering_id, size, protected_size, created, removed FROM usage_backup WHERE " + " account_id = ? AND ((removed IS NULL AND created <= ?) OR (created BETWEEN ? AND ?) OR (removed BETWEEN ? AND ?) " + @@ -55,7 +53,7 @@ public void updateMetrics(final Long vmId, final Long size, final Long virtualSi update(vo.getId(), vo); } } catch (final Exception e) { - LOGGER.error("Error updating backup metrics: " + e.getMessage(), e); + logger.error("Error updating backup metrics: " + e.getMessage(), e); } } @@ -72,13 +70,13 @@ public void removeUsage(Long accountId, Long vmId, Date eventDate) { pstmt.executeUpdate(); } } catch (SQLException e) { - LOGGER.error("Error removing UsageBackupVO: " + e.getMessage(), e); + logger.error("Error removing UsageBackupVO: " + e.getMessage(), e); throw new CloudException("Remove backup usage exception: " + e.getMessage(), e); } txn.commit(); } catch (Exception e) { txn.rollback(); - LOGGER.error("Exception caught while removing UsageBackupVO: " + e.getMessage(), e); + logger.error("Exception caught while removing UsageBackupVO: " + e.getMessage(), e); } finally { txn.close(); } @@ -128,7 +126,7 @@ public List getUsageRecords(Long accountId, Date startDate, Date } } catch (Exception e) { txn.rollback(); - LOGGER.warn("Error getting VM backup usage records", e); + logger.warn("Error getting VM backup usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java index bc98652c95d2..fb925a285136 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java @@ -35,7 +35,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -50,7 +49,6 @@ @Component public class UsageDaoImpl extends GenericDaoBase implements UsageDao { - public static final Logger s_logger = Logger.getLogger(UsageDaoImpl.class.getName()); private static final String DELETE_ALL = "DELETE FROM cloud_usage"; private static final String DELETE_ALL_BY_ACCOUNTID = "DELETE FROM cloud_usage WHERE account_id = ?"; private static final String DELETE_ALL_BY_INTERVAL = "DELETE FROM cloud_usage WHERE end_date < DATE_SUB(CURRENT_DATE(), INTERVAL ? DAY)"; @@ -109,7 +107,7 @@ public void deleteRecordsForAccount(Long accountId) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error retrieving usage vm instances for account id: " + accountId, ex); + logger.error("error retrieving usage vm instances for account id: " + accountId, ex); } finally { txn.close(); } @@ -157,7 +155,7 @@ public void saveAccounts(List accounts) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving account to cloud_usage db", ex); + logger.error("error saving account to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -187,7 +185,7 @@ public void updateAccounts(List accounts) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating account to cloud_usage db", ex); + logger.error("error updating account to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -228,7 +226,7 @@ public void saveUserStats(List userStats) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving user stats to cloud_usage db", ex); + logger.error("error saving user stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -255,7 +253,7 @@ public void updateUserStats(List userStats) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating user stats to cloud_usage db", ex); + logger.error("error updating user stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -272,7 +270,7 @@ public Long getLastAccountId() { return Long.valueOf(rs.getLong(1)); } } catch (Exception ex) { - s_logger.error("error getting last account id", ex); + logger.error("error getting last account id", ex); } return null; } @@ -289,7 +287,7 @@ public Long getLastUserStatsId() { return Long.valueOf(rs.getLong(1)); } } catch (Exception ex) { - s_logger.error("error getting last user stats id", ex); + logger.error("error getting last user stats id", ex); } return null; } @@ -306,7 +304,7 @@ public Long getLastBucketStatsId() { return Long.valueOf(rs.getLong(1)); } } catch (Exception ex) { - s_logger.error("error getting last bucket stats id", ex); + logger.error("error getting last bucket stats id", ex); } return null; } @@ -330,7 +328,7 @@ public void saveBucketStats(List bucketStats) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving bucket stats to cloud_usage db", ex); + logger.error("error saving bucket stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -352,7 +350,7 @@ public void updateBucketStats(List bucketStats) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating bucket stats to cloud_usage db", ex); + logger.error("error updating bucket stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -371,7 +369,7 @@ public List listPublicTemplatesByAccount(long accountId) { templateList.add(Long.valueOf(rs.getLong(1))); } } catch (Exception ex) { - s_logger.error("error listing public templates", ex); + logger.error("error listing public templates", ex); } return templateList; } @@ -388,7 +386,7 @@ public Long getLastVmDiskStatsId() { return Long.valueOf(rs.getLong(1)); } } catch (Exception ex) { - s_logger.error("error getting last vm disk stats id", ex); + logger.error("error getting last vm disk stats id", ex); } return null; } @@ -421,7 +419,7 @@ public void updateVmDiskStats(List vmDiskStats) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating vm disk stats to cloud_usage db", ex); + logger.error("error updating vm disk stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } @@ -467,7 +465,7 @@ public void saveVmDiskStats(List vmDiskStats) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving vm disk stats to cloud_usage db", ex); + logger.error("error saving vm disk stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } @@ -534,7 +532,7 @@ public void saveUsageRecords(List usageRecords) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving usage records to cloud_usage db", ex); + logger.error("error saving usage records to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -551,7 +549,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { pstmt.setLong(1, days); pstmt.executeUpdate(); } catch (Exception ex) { - s_logger.error("error removing old cloud_usage records for interval: " + days); + logger.error("error removing old cloud_usage records for interval: " + days); } } }); @@ -568,7 +566,7 @@ public UsageVO doInTransaction(final TransactionStatus status) { @Override public Pair, Integer> listUsageRecordsPendingForQuotaAggregation(long accountId, long domainId) { - s_logger.debug(String.format("Retrieving pending usage records for accountId [%s] and domainId [%s].", accountId, domainId)); + logger.debug(String.format("Retrieving pending usage records for accountId [%s] and domainId [%s].", accountId, domainId)); return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback, Integer>>) status -> { Filter usageFilter = new Filter(UsageVO.class, "startDate", true, null, null); @@ -594,7 +592,7 @@ public List> listAccountResourcesInThePeriod(long accountId String startDateString = DateUtil.getOutputString(startDate); String endDateString = DateUtil.getOutputString(endDate); - s_logger.debug(String.format("Retrieving account resources between [%s] and [%s] for accountId [%s] and usageType [%s].", startDateString, endDateString, accountId, + logger.debug(String.format("Retrieving account resources between [%s] and [%s] for accountId [%s] and usageType [%s].", startDateString, endDateString, accountId, usageType)); TransactionLegacy txn = TransactionLegacy.currentTxn(); @@ -617,7 +615,7 @@ public List> listAccountResourcesInThePeriod(long accountId return accountResourcesOfTheLastDay; } catch (SQLException e) { - s_logger.error(String.format("Failed to retrieve account resources between [%s] and [%s] for accountId [%s] and usageType [%s] due to [%s]. Returning an empty list of" + logger.error(String.format("Failed to retrieve account resources between [%s] and [%s] for accountId [%s] and usageType [%s] due to [%s]. Returning an empty list of" + " resources.", startDateString, endDateString, accountId, usageType, e.getMessage()), e); return new ArrayList<>(); diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageIPAddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageIPAddressDaoImpl.java index 2dcb181c6c77..9c0b8f87ab0e 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageIPAddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageIPAddressDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageIPAddressVO; @@ -36,7 +35,6 @@ @Component public class UsageIPAddressDaoImpl extends GenericDaoBase implements UsageIPAddressDao { - public static final Logger s_logger = Logger.getLogger(UsageIPAddressDaoImpl.class.getName()); protected static final String UPDATE_RELEASED = "UPDATE usage_ip_address SET released = ? WHERE account_id = ? AND public_ip_address = ? and released IS NULL"; protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = @@ -79,7 +77,7 @@ public void update(UsageIPAddressVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.error("Error updating usageIPAddressVO:"+e.getMessage(), e); + logger.error("Error updating usageIPAddressVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -145,7 +143,7 @@ public List getUsageRecords(Long accountId, Long domainId, Dat } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java index 065dc309ebea..6d460aadd093 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageJobDaoImpl.java @@ -22,7 +22,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageJobVO; @@ -34,7 +33,6 @@ @Component public class UsageJobDaoImpl extends GenericDaoBase implements UsageJobDao { - private static final Logger s_logger = Logger.getLogger(UsageJobDaoImpl.class.getName()); private static final String GET_LAST_JOB_SUCCESS_DATE_MILLIS = "SELECT end_millis FROM cloud_usage.usage_job WHERE end_millis > 0 and success = 1 ORDER BY end_millis DESC LIMIT 1"; @@ -51,7 +49,7 @@ public long getLastJobSuccessDateMillis() { return rs.getLong(1); } } catch (Exception ex) { - s_logger.error("error getting last usage job success date", ex); + logger.error("error getting last usage job success date", ex); } finally { txn.close(); } @@ -77,7 +75,7 @@ public void updateJobSuccess(Long jobId, long startMillis, long endMillis, long txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating job success date", ex); + logger.error("error updating job success date", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageLoadBalancerPolicyDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageLoadBalancerPolicyDaoImpl.java index 7260caecd1aa..ba5c70fbc32e 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageLoadBalancerPolicyDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageLoadBalancerPolicyDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageLoadBalancerPolicyVO; @@ -36,7 +35,6 @@ @Component public class UsageLoadBalancerPolicyDaoImpl extends GenericDaoBase implements UsageLoadBalancerPolicyDao { - public static final Logger s_logger = Logger.getLogger(UsageLoadBalancerPolicyDaoImpl.class.getName()); protected static final String REMOVE_BY_USERID_LBID = "DELETE FROM usage_load_balancer_policy WHERE account_id = ? AND lb_id = ?"; protected static final String UPDATE_DELETED = "UPDATE usage_load_balancer_policy SET deleted = ? WHERE account_id = ? AND lb_id = ? and deleted IS NULL"; @@ -64,7 +62,7 @@ public void removeBy(long accountId, long lbId) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error removing UsageLoadBalancerPolicyVO", e); + logger.warn("Error removing UsageLoadBalancerPolicyVO", e); } finally { txn.close(); } @@ -90,7 +88,7 @@ public void update(UsageLoadBalancerPolicyVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error updating UsageLoadBalancerPolicyVO"+e.getMessage(), e); + logger.warn("Error updating UsageLoadBalancerPolicyVO"+e.getMessage(), e); } finally { txn.close(); } @@ -159,7 +157,7 @@ public List getUsageRecords(Long accountId, Long doma } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkDaoImpl.java index c4c5076878e8..27060cfe672d 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkDaoImpl.java @@ -23,7 +23,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageNetworkVO; @@ -33,7 +32,6 @@ @Component public class UsageNetworkDaoImpl extends GenericDaoBase implements UsageNetworkDao { - private static final Logger s_logger = Logger.getLogger(UsageNetworkDaoImpl.class.getName()); private static final String SELECT_LATEST_STATS = "SELECT u.account_id, u.zone_id, u.host_id, u.host_type, u.network_id, u.bytes_sent, u.bytes_received, u.agg_bytes_received, u.agg_bytes_sent, u.event_time_millis " + "FROM cloud_usage.usage_network u INNER JOIN (SELECT netusage.account_id as acct_id, netusage.zone_id as z_id, max(netusage.event_time_millis) as max_date " @@ -77,7 +75,7 @@ public Map getRecentNetworkStats() { } return returnMap; } catch (Exception ex) { - s_logger.error("error getting recent usage network stats", ex); + logger.error("error getting recent usage network stats", ex); } finally { txn.close(); } @@ -97,7 +95,7 @@ public void deleteOldStats(long maxEventTime) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error deleting old usage network stats", ex); + logger.error("error deleting old usage network stats", ex); } } @@ -126,7 +124,7 @@ public void saveUsageNetworks(List usageNetworks) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving usage_network to cloud_usage db", ex); + logger.error("error saving usage_network to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java index 23931f0a84e3..b3bc06e8af40 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageNetworkOfferingVO; @@ -36,7 +35,6 @@ @Component public class UsageNetworkOfferingDaoImpl extends GenericDaoBase implements UsageNetworkOfferingDao { - public static final Logger s_logger = Logger.getLogger(UsageNetworkOfferingDaoImpl.class.getName()); protected static final String UPDATE_DELETED = "UPDATE usage_network_offering SET deleted = ? WHERE account_id = ? AND vm_instance_id = ? AND network_offering_id = ? and deleted IS NULL"; @@ -74,7 +72,7 @@ public void update(UsageNetworkOfferingVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error updating UsageNetworkOfferingVO:"+e.getMessage(), e); + logger.warn("Error updating UsageNetworkOfferingVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -146,7 +144,7 @@ public List getUsageRecords(Long accountId, Long domainI } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworksDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworksDaoImpl.java index 8829414f3f26..f8ffbf74f85d 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworksDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworksDaoImpl.java @@ -22,8 +22,10 @@ import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.TransactionLegacy; -import org.apache.log4j.Logger; + import org.springframework.stereotype.Component; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -34,7 +36,7 @@ @Component public class UsageNetworksDaoImpl extends GenericDaoBase implements UsageNetworksDao { - private static final Logger LOGGER = Logger.getLogger(UsageNetworksDaoImpl.class); + private static final Logger LOGGER = LogManager.getLogger(UsageNetworksDaoImpl.class); protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT id, network_id, network_offering_id, zone_id, account_id, domain_id, state, created, removed FROM usage_networks WHERE " + " account_id = ? AND ((removed IS NULL AND created <= ?) OR (created BETWEEN ? AND ?) OR (removed BETWEEN ? AND ?) " + " OR ((created <= ?) AND (removed >= ?)))"; diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsagePortForwardingRuleDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsagePortForwardingRuleDaoImpl.java index 99216420a0df..e66b47f74fa9 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsagePortForwardingRuleDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsagePortForwardingRuleDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsagePortForwardingRuleVO; @@ -36,7 +35,6 @@ @Component public class UsagePortForwardingRuleDaoImpl extends GenericDaoBase implements UsagePortForwardingRuleDao { - public static final Logger s_logger = Logger.getLogger(UsagePortForwardingRuleDaoImpl.class.getName()); protected static final String REMOVE_BY_USERID_PFID = "DELETE FROM usage_port_forwarding WHERE account_id = ? AND pf_id = ?"; protected static final String UPDATE_DELETED = "UPDATE usage_port_forwarding SET deleted = ? WHERE account_id = ? AND pf_id = ? and deleted IS NULL"; @@ -64,7 +62,7 @@ public void removeBy(long accountId, long pfId) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error removing UsagePortForwardingRuleVO", e); + logger.warn("Error removing UsagePortForwardingRuleVO", e); } finally { txn.close(); } @@ -90,7 +88,7 @@ public void update(UsagePortForwardingRuleVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error updating UsagePortForwardingRuleVO:"+e.getMessage(), e); + logger.warn("Error updating UsagePortForwardingRuleVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -159,7 +157,7 @@ public List getUsageRecords(Long accountId, Long doma } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageSecurityGroupDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageSecurityGroupDaoImpl.java index f98133f54390..43224918f0c4 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageSecurityGroupDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageSecurityGroupDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageSecurityGroupVO; @@ -36,7 +35,6 @@ @Component public class UsageSecurityGroupDaoImpl extends GenericDaoBase implements UsageSecurityGroupDao { - public static final Logger s_logger = Logger.getLogger(UsageSecurityGroupDaoImpl.class.getName()); protected static final String UPDATE_DELETED = "UPDATE usage_security_group SET deleted = ? WHERE account_id = ? AND vm_instance_id = ? AND security_group_id = ? and deleted IS NULL"; @@ -74,7 +72,7 @@ public void update(UsageSecurityGroupVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error updating UsageSecurityGroupVO:"+e.getMessage(), e); + logger.warn("Error updating UsageSecurityGroupVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -142,7 +140,7 @@ public List getUsageRecords(Long accountId, Long domainId, } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records:"+e.getMessage(), e); + logger.warn("Error getting usage records:"+e.getMessage(), e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageStorageDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageStorageDaoImpl.java index 680429b315b1..1da533493997 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageStorageDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageStorageDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageStorageVO; @@ -38,7 +37,6 @@ @Component public class UsageStorageDaoImpl extends GenericDaoBase implements UsageStorageDao { - public static final Logger s_logger = Logger.getLogger(UsageStorageDaoImpl.class.getName()); protected static final String REMOVE_BY_USERID_STORAGEID = "DELETE FROM usage_storage WHERE account_id = ? AND entity_id = ? AND storage_type = ?"; protected static final String UPDATE_DELETED = "UPDATE usage_storage SET deleted = ? WHERE account_id = ? AND entity_id = ? AND storage_type = ? AND zone_id = ? and deleted IS NULL"; @@ -108,7 +106,7 @@ public void removeBy(long accountId, long volId, int storageType) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.error("Error removing usageStorageVO", e); + logger.error("Error removing usageStorageVO", e); } finally { txn.close(); } @@ -137,7 +135,7 @@ public void update(UsageStorageVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.error("Error updating UsageStorageVO:"+e.getMessage(), e); + logger.error("Error updating UsageStorageVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -211,7 +209,7 @@ public List getUsageRecords(Long accountId, Long domainId, Date } }catch (Exception e) { txn.rollback(); - s_logger.error("getUsageRecords:Exception:"+e.getMessage(), e); + logger.error("getUsageRecords:Exception:"+e.getMessage(), e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMInstanceDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMInstanceDaoImpl.java index d330267d0b47..2fd453013bd1 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMInstanceDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMInstanceDaoImpl.java @@ -24,7 +24,6 @@ import java.util.TimeZone; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVMInstanceVO; @@ -34,7 +33,6 @@ @Component public class UsageVMInstanceDaoImpl extends GenericDaoBase implements UsageVMInstanceDao { - public static final Logger s_logger = Logger.getLogger(UsageVMInstanceDaoImpl.class.getName()); protected static final String UPDATE_USAGE_INSTANCE_SQL = "UPDATE usage_vm_instance SET end_date = ? " + "WHERE account_id = ? and vm_instance_id = ? and usage_type = ? and end_date IS NULL"; @@ -62,7 +60,7 @@ public void update(UsageVMInstanceVO instance) { pstmt.executeUpdate(); txn.commit(); } catch (Exception e) { - s_logger.warn(e); + logger.warn(e); } finally { txn.close(); } @@ -83,7 +81,7 @@ public void delete(UsageVMInstanceVO instance) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error deleting usage vm instance with vmId: " + instance.getVmInstanceId() + ", for account with id: " + instance.getAccountId()); + logger.error("error deleting usage vm instance with vmId: " + instance.getVmInstanceId() + ", for account with id: " + instance.getAccountId()); } finally { txn.close(); } @@ -141,7 +139,7 @@ public List getUsageRecords(long accountId, Date startDate, D usageInstances.add(usageInstance); } } catch (Exception ex) { - s_logger.error("error retrieving usage vm instances for account id: " + accountId, ex); + logger.error("error retrieving usage vm instances for account id: " + accountId, ex); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMSnapshotDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMSnapshotDaoImpl.java index fdd852d706b5..fbb5f7fae722 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMSnapshotDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMSnapshotDaoImpl.java @@ -26,7 +26,6 @@ import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVMSnapshotVO; @@ -36,7 +35,6 @@ @Component public class UsageVMSnapshotDaoImpl extends GenericDaoBase implements UsageVMSnapshotDao { - public static final Logger s_logger = Logger.getLogger(UsageVMSnapshotDaoImpl.class.getName()); protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT volume_id, zone_id, account_id, domain_id, vm_id, disk_offering_id, size, created, processed, vm_snapshot_id " + " FROM usage_vmsnapshot" + " WHERE account_id = ? " + " AND ( (created BETWEEN ? AND ?) OR " + " (created < ? AND processed is NULL) ) ORDER BY created asc"; @@ -61,7 +59,7 @@ public void update(UsageVMSnapshotVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error updating UsageVMSnapshotVO", e); + logger.warn("Error updating UsageVMSnapshotVO", e); } finally { txn.close(); } @@ -115,7 +113,7 @@ public List getUsageRecords(Long accountId, Long domainId, Da } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } @@ -170,7 +168,7 @@ public UsageVMSnapshotVO getPreviousUsageRecord(UsageVMSnapshotVO rec) { } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMSnapshotOnPrimaryDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMSnapshotOnPrimaryDaoImpl.java index f6628511564a..34a8af4da63d 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMSnapshotOnPrimaryDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMSnapshotOnPrimaryDaoImpl.java @@ -26,7 +26,6 @@ import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageSnapshotOnPrimaryVO; @@ -36,7 +35,6 @@ @Component public class UsageVMSnapshotOnPrimaryDaoImpl extends GenericDaoBase implements UsageVMSnapshotOnPrimaryDao { - public static final Logger s_logger = Logger.getLogger(UsageVMSnapshotOnPrimaryDaoImpl.class.getName()); protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT volume_id, zone_id, account_id, domain_id, vm_id, name, type, physicalsize, virtualsize, created, deleted, vm_snapshot_id " + " FROM usage_snapshot_on_primary" + " WHERE account_id = ? " + " AND ( (created < ? AND deleted is NULL)" + " OR ( deleted BETWEEN ? AND ?)) ORDER BY created asc"; @@ -58,7 +56,7 @@ public void updateDeleted(UsageSnapshotOnPrimaryVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error updating UsageSnapshotOnPrimaryVO", e); + logger.warn("Error updating UsageSnapshotOnPrimaryVO", e); } finally { txn.close(); } @@ -79,7 +77,7 @@ public List getUsageRecords(Long accountId, Long domai pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate)); pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), startDate)); pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate)); - s_logger.debug("GET_USAGE_RECORDS_BY_ACCOUNT " + pstmt); + logger.debug("GET_USAGE_RECORDS_BY_ACCOUNT " + pstmt); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { //id, zone_id, account_id, domain_iVMSnapshotVOd, vm_id, disk_offering_id, size, created, deleted @@ -111,7 +109,7 @@ public List getUsageRecords(Long accountId, Long domai } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVPNUserDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVPNUserDaoImpl.java index 9be0ca5d59a6..fa6f896df4a4 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVPNUserDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVPNUserDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVPNUserVO; @@ -36,7 +35,6 @@ @Component public class UsageVPNUserDaoImpl extends GenericDaoBase implements UsageVPNUserDao { - public static final Logger s_logger = Logger.getLogger(UsageVPNUserDaoImpl.class.getName()); protected static final String UPDATE_DELETED = "UPDATE usage_vpn_user SET deleted = ? WHERE account_id = ? AND user_id = ? and deleted IS NULL"; protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT zone_id, account_id, domain_id, user_id, user_name, created, deleted " + "FROM usage_vpn_user " @@ -69,7 +67,7 @@ public void update(UsageVPNUserVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.error("Error updating UsageVPNUserVO:"+e.getMessage(), e); + logger.error("Error updating UsageVPNUserVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -139,7 +137,7 @@ public List getUsageRecords(Long accountId, Long domainId, Date } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVmDiskDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVmDiskDaoImpl.java index 2b934770b7de..bc1cb06cfec0 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVmDiskDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVmDiskDaoImpl.java @@ -23,7 +23,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVmDiskVO; @@ -33,7 +32,6 @@ @Component public class UsageVmDiskDaoImpl extends GenericDaoBase implements UsageVmDiskDao { - private static final Logger s_logger = Logger.getLogger(UsageVmDiskDaoImpl.class.getName()); private static final String SELECT_LATEST_STATS = "SELECT uvd.account_id, uvd.zone_id, uvd.vm_id, uvd.volume_id, uvd.io_read, uvd.io_write, uvd.agg_io_read, uvd.agg_io_write, " + "uvd.bytes_read, uvd.bytes_write, uvd.agg_bytes_read, uvd.agg_bytes_write, uvd.event_time_millis " @@ -81,7 +79,7 @@ public Map getRecentVmDiskStats() { } return returnMap; } catch (Exception ex) { - s_logger.error("error getting recent usage disk stats", ex); + logger.error("error getting recent usage disk stats", ex); } finally { txn.close(); } @@ -101,7 +99,7 @@ public void deleteOldStats(long maxEventTime) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error deleting old usage disk stats", ex); + logger.error("error deleting old usage disk stats", ex); } } @@ -133,7 +131,7 @@ public void saveUsageVmDisks(List usageVmDisks) { txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving usage_vm_disk to cloud_usage db", ex); + logger.error("error saving usage_vm_disk to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java index 0c35c118006b..4662a6f26ce8 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java @@ -26,7 +26,6 @@ import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVolumeVO; @@ -36,7 +35,6 @@ @Component public class UsageVolumeDaoImpl extends GenericDaoBase implements UsageVolumeDao { - public static final Logger s_logger = Logger.getLogger(UsageVolumeDaoImpl.class.getName()); protected static final String REMOVE_BY_USERID_VOLID = "DELETE FROM usage_volume WHERE account_id = ? AND volume_id = ?"; protected static final String UPDATE_DELETED = "UPDATE usage_volume SET deleted = ? WHERE account_id = ? AND volume_id = ? and deleted IS NULL"; @@ -69,7 +67,7 @@ public void removeBy(long accountId, long volId) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error removing usageVolumeVO:"+e.getMessage(), e); + logger.warn("Error removing usageVolumeVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -91,7 +89,7 @@ public void update(UsageVolumeVO usage) { txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error updating UsageVolumeVO", e); + logger.warn("Error updating UsageVolumeVO", e); } finally { txn.close(); } @@ -169,7 +167,7 @@ public List getUsageRecords(Long accountId, Long domainId, Date s } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVpcDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVpcDaoImpl.java index a42b96486a54..45ae845e58f3 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVpcDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVpcDaoImpl.java @@ -22,7 +22,6 @@ import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.TransactionLegacy; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -34,7 +33,6 @@ @Component public class UsageVpcDaoImpl extends GenericDaoBase implements UsageVpcDao { - private static final Logger LOGGER = Logger.getLogger(UsageVpcDaoImpl.class); protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT id, vpc_id, zone_id, account_id, domain_id, state, created, removed FROM usage_vpc WHERE " + " account_id = ? AND ((removed IS NULL AND created <= ?) OR (created BETWEEN ? AND ?) OR (removed BETWEEN ? AND ?) " + " OR ((created <= ?) AND (removed >= ?)))"; @@ -52,7 +50,7 @@ public void update(UsageVpcVO usage) { update(vo.getId(), vo); } } catch (final Exception e) { - LOGGER.error(String.format("Error updating usage of VPC due to [%s].", e.getMessage()), e); + logger.error(String.format("Error updating usage of VPC due to [%s].", e.getMessage()), e); txn.rollback(); } finally { txn.close(); @@ -74,7 +72,7 @@ public void remove(long vpcId, Date removed) { } } catch (final Exception e) { txn.rollback(); - LOGGER.error(String.format("Error updating usage of VPC due to [%s].", e.getMessage()), e); + logger.error(String.format("Error updating usage of VPC due to [%s].", e.getMessage()), e); } finally { txn.close(); } @@ -121,7 +119,7 @@ public List getUsageRecords(Long accountId, Date startDate, Date end } } catch (Exception e) { txn.rollback(); - LOGGER.warn("Error getting VPC usage records", e); + logger.warn("Error getting VPC usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/user/AccountDetailsDaoImpl.java b/engine/schema/src/main/java/com/cloud/user/AccountDetailsDaoImpl.java index de562e27f9e5..510270ad7bf1 100644 --- a/engine/schema/src/main/java/com/cloud/user/AccountDetailsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/user/AccountDetailsDaoImpl.java @@ -23,25 +23,24 @@ import javax.inject.Inject; -import com.cloud.utils.crypt.DBEncryptionUtil; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey.Scope; import org.apache.cloudstack.framework.config.ScopedConfigStorage; +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.cloudstack.framework.config.impl.ConfigurationVO; import com.cloud.domain.DomainDetailVO; import com.cloud.domain.DomainVO; -import com.cloud.domain.dao.DomainDetailsDao; import com.cloud.domain.dao.DomainDao; +import com.cloud.domain.dao.DomainDetailsDao; import com.cloud.user.dao.AccountDao; - +import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.QueryBuilder; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.TransactionLegacy; -import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.cloudstack.framework.config.impl.ConfigurationVO; public class AccountDetailsDaoImpl extends GenericDaoBase implements AccountDetailsDao, ScopedConfigStorage { protected final SearchBuilder accountSearch; @@ -118,9 +117,9 @@ public Scope getScope() { } @Override - public String getConfigValue(long id, ConfigKey key) { + public String getConfigValue(long id, String key) { // check if account level setting is configured - AccountDetailVO vo = findDetail(id, key.key()); + AccountDetailVO vo = findDetail(id, key); String value = vo == null ? null : getActualValue(vo); if (value != null) { return value; @@ -140,7 +139,7 @@ public String getConfigValue(long id, ConfigKey key) { if (account.isPresent()) { DomainVO domain = _domainDao.findById(account.get().getDomainId()); while (domain != null) { - DomainDetailVO domainVO = _domainDetailsDao.findDetail(domain.getId(), key.key()); + DomainDetailVO domainVO = _domainDetailsDao.findDetail(domain.getId(), key); if (domainVO != null) { value = _domainDetailsDao.getActualValue(domainVO); break; diff --git a/engine/schema/src/main/java/com/cloud/user/UserAccountVO.java b/engine/schema/src/main/java/com/cloud/user/UserAccountVO.java index c18ca53f7abe..1da7d52a366a 100644 --- a/engine/schema/src/main/java/com/cloud/user/UserAccountVO.java +++ b/engine/schema/src/main/java/com/cloud/user/UserAccountVO.java @@ -17,6 +17,7 @@ package com.cloud.user; import java.util.Date; +import java.util.HashMap; import java.util.Map; import javax.persistence.Column; @@ -361,6 +362,9 @@ public void setUser2faProvider(String user2faProvider) { @Override public Map getDetails() { + if (details == null) { + details = new HashMap<>(); + } return details; } diff --git a/engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java b/engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java index 3dacbb70f394..eed5572a0b24 100644 --- a/engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java @@ -32,7 +32,6 @@ import com.cloud.utils.db.SearchCriteria.Op; import org.apache.commons.lang3.StringUtils; import com.cloud.utils.db.TransactionLegacy; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -42,7 +41,6 @@ @Component public class AccountDaoImpl extends GenericDaoBase implements AccountDao { - private static final Logger s_logger = Logger.getLogger(AccountDaoImpl.class); private static final String FIND_USER_ACCOUNT_BY_API_KEY = "SELECT u.id, u.username, u.account_id, u.secret_key, u.state, " + "a.id, a.account_name, a.type, a.role_id, a.domain_id, a.state " + "FROM `cloud`.`user` u, `cloud`.`account` a " + "WHERE u.account_id = a.id AND u.api_key = ? and u.removed IS NULL"; @@ -161,7 +159,7 @@ public Pair findUserAccountByApiKey(String apiKey) { userAcctPair = new Pair(u, a); } } catch (Exception e) { - s_logger.warn("Exception finding user/acct by api key: " + apiKey, e); + logger.warn("Exception finding user/acct by api key: " + apiKey, e); } return userAcctPair; } @@ -300,7 +298,7 @@ public void markForCleanup(long accountId) { if (!account.getNeedsCleanup()) { account.setNeedsCleanup(true); if (!update(accountId, account)) { - s_logger.warn("Failed to mark account id=" + accountId + " for cleanup"); + logger.warn("Failed to mark account id=" + accountId + " for cleanup"); } } } @@ -320,7 +318,7 @@ public long getDomainIdForGivenAccountId(long id) { domain_id = account_vo.getDomainId(); } catch (Exception e) { - s_logger.warn("getDomainIdForGivenAccountId: Exception :" + e.getMessage()); + logger.warn("getDomainIdForGivenAccountId: Exception :" + e.getMessage()); } finally { return domain_id; diff --git a/engine/schema/src/main/java/com/cloud/user/dao/UserStatisticsDaoImpl.java b/engine/schema/src/main/java/com/cloud/user/dao/UserStatisticsDaoImpl.java index acadc2f09086..6f10c5d2a1b2 100644 --- a/engine/schema/src/main/java/com/cloud/user/dao/UserStatisticsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/user/dao/UserStatisticsDaoImpl.java @@ -24,7 +24,6 @@ import java.util.TimeZone; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.user.UserStatisticsVO; @@ -36,7 +35,6 @@ @Component public class UserStatisticsDaoImpl extends GenericDaoBase implements UserStatisticsDao { - private static final Logger s_logger = Logger.getLogger(UserStatisticsDaoImpl.class); private static final String ACTIVE_AND_RECENTLY_DELETED_SEARCH = "SELECT us.id, us.data_center_id, us.account_id, us.public_ip_address, us.device_id, us.device_type, us.network_id, us.agg_bytes_received, us.agg_bytes_sent " + "FROM user_statistics us, account a " + "WHERE us.account_id = a.id AND (a.removed IS NULL OR a.removed >= ?) " + "ORDER BY us.id"; @@ -109,7 +107,7 @@ public List listActiveAndRecentlyDeleted(Date minRemovedDate, userStats.add(toEntityBean(rs, false)); } } catch (Exception ex) { - s_logger.error("error saving user stats to cloud_usage db", ex); + logger.error("error saving user stats to cloud_usage db", ex); } return userStats; } @@ -127,7 +125,7 @@ public List listUpdatedStats() { userStats.add(toEntityBean(rs, false)); } } catch (Exception ex) { - s_logger.error("error lisitng updated user stats", ex); + logger.error("error lisitng updated user stats", ex); } return userStats; } diff --git a/engine/schema/src/main/java/com/cloud/user/dao/VmDiskStatisticsDaoImpl.java b/engine/schema/src/main/java/com/cloud/user/dao/VmDiskStatisticsDaoImpl.java index 34fa2e79e98b..3f2a239a157c 100644 --- a/engine/schema/src/main/java/com/cloud/user/dao/VmDiskStatisticsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/user/dao/VmDiskStatisticsDaoImpl.java @@ -24,7 +24,6 @@ import java.util.TimeZone; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.user.VmDiskStatisticsVO; @@ -36,7 +35,6 @@ @Component public class VmDiskStatisticsDaoImpl extends GenericDaoBase implements VmDiskStatisticsDao { - private static final Logger s_logger = Logger.getLogger(VmDiskStatisticsDaoImpl.class); private static final String ACTIVE_AND_RECENTLY_DELETED_SEARCH = "SELECT bcf.id, bcf.data_center_id, bcf.account_id, bcf.vm_id, bcf.volume_id, bcf.agg_io_read, bcf.agg_io_write, bcf.agg_bytes_read, bcf.agg_bytes_write " + "FROM vm_disk_statistics bcf, account a " + "WHERE bcf.account_id = a.id AND (a.removed IS NULL OR a.removed >= ?) " + "ORDER BY bcf.id"; @@ -104,7 +102,7 @@ public List listActiveAndRecentlyDeleted(Date minRemovedDate vmDiskStats.add(toEntityBean(rs, false)); } } catch (Exception ex) { - s_logger.error("error saving vm disk stats to cloud_usage db", ex); + logger.error("error saving vm disk stats to cloud_usage db", ex); } return vmDiskStats; } @@ -122,7 +120,7 @@ public List listUpdatedStats() { vmDiskStats.add(toEntityBean(rs, false)); } } catch (Exception ex) { - s_logger.error("error lisitng updated vm disk stats", ex); + logger.error("error lisitng updated vm disk stats", ex); } return vmDiskStats; } diff --git a/engine/schema/src/main/java/com/cloud/util/StoragePoolTypeConverter.java b/engine/schema/src/main/java/com/cloud/util/StoragePoolTypeConverter.java new file mode 100644 index 000000000000..ab4148ec8341 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/util/StoragePoolTypeConverter.java @@ -0,0 +1,40 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.util; + +import com.cloud.storage.Storage.StoragePoolType; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +/** + * Converts {@link StoragePoolType} to and from {@link String} using {@link StoragePoolType#name()}. + * + * @author mprokopchuk + */ +@Converter +public class StoragePoolTypeConverter implements AttributeConverter { + @Override + public String convertToDatabaseColumn(StoragePoolType attribute) { + return attribute != null ? attribute.name() : null; + } + + @Override + public StoragePoolType convertToEntityAttribute(String dbData) { + return dbData != null ? StoragePoolType.valueOf(dbData) : null; + } +} diff --git a/engine/schema/src/main/java/com/cloud/vm/ItWorkDao.java b/engine/schema/src/main/java/com/cloud/vm/ItWorkDao.java index 2d4a5e138fea..ab07d6989fae 100644 --- a/engine/schema/src/main/java/com/cloud/vm/ItWorkDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/ItWorkDao.java @@ -41,5 +41,6 @@ public interface ItWorkDao extends GenericDao { boolean updateStep(ItWorkVO work, Step step); List listWorkInProgressFor(long nodeId); + int expungeByVmList(List vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/vm/ItWorkDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/ItWorkDaoImpl.java index ff727904dcb7..0cc0a0844431 100644 --- a/engine/schema/src/main/java/com/cloud/vm/ItWorkDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/ItWorkDaoImpl.java @@ -18,7 +18,7 @@ import java.util.List; - +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -103,4 +103,16 @@ public List listWorkInProgressFor(long nodeId) { return search(sc, null); } + + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getInstanceId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java b/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java index f3560d68f495..a1d9f4a8089a 100644 --- a/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java +++ b/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java @@ -26,6 +26,7 @@ import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; @@ -41,9 +42,11 @@ import javax.persistence.Transient; import org.apache.cloudstack.backup.Backup; +import org.apache.cloudstack.util.HypervisorTypeConverter; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.db.Encrypt; @@ -59,7 +62,7 @@ @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, length = 32) public class VMInstanceVO implements VirtualMachine, FiniteStateObject { - private static final Logger s_logger = Logger.getLogger(VMInstanceVO.class); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @TableGenerator(name = "vm_instance_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "vm_instance_seq", allocationSize = 1) @Column(name = "id", updatable = false, nullable = false) @@ -158,16 +161,14 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject details; @@ -225,7 +226,7 @@ public VMInstanceVO(long id, long serviceOfferingId, String name, String instanc random.nextBytes(randomBytes); vncPassword = Base64.encodeBase64URLSafeString(randomBytes); } catch (NoSuchAlgorithmException e) { - s_logger.error("Unexpected exception in SecureRandom Algorithm selection ", e); + logger.error("Unexpected exception in SecureRandom Algorithm selection ", e); } } @@ -539,6 +540,14 @@ public boolean isDynamicallyScalable() { return dynamicallyScalable; } + public boolean isDeleteProtection() { + return deleteProtection; + } + + public void setDeleteProtection(boolean deleteProtection) { + this.deleteProtection = deleteProtection; + } + @Override public Class getEntityType() { return VirtualMachine.class; diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleProxyDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleProxyDaoImpl.java index 5b5c3505cb32..ef94a4d9f72e 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleProxyDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleProxyDaoImpl.java @@ -24,7 +24,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.info.ConsoleProxyLoadInfo; @@ -40,7 +39,6 @@ @Component public class ConsoleProxyDaoImpl extends GenericDaoBase implements ConsoleProxyDao { - private static final Logger s_logger = Logger.getLogger(ConsoleProxyDaoImpl.class); // // query SQL for returning console proxy assignment info as following @@ -215,7 +213,7 @@ public List> getProxyLoadMatrix() { l.add(new Pair(rs.getLong(1), rs.getInt(2))); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return l; } @@ -240,7 +238,7 @@ public List> getDatacenterStoragePoolHostInfo(long dcId, boo l.add(new Pair(rs.getLong(1), rs.getInt(2))); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return l; } @@ -259,7 +257,7 @@ public int getProxyStaticLoad(long proxyVmId) { return rs.getInt(1); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return 0; } @@ -277,7 +275,7 @@ public int getProxyActiveLoad(long proxyVmId) { return rs.getInt(1); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return 0; } @@ -299,7 +297,7 @@ private List getDatacenterLoadMatrix(String sql) { l.add(info); } } catch (SQLException e) { - s_logger.debug("Exception: ", e); + logger.debug("Exception: ", e); } return l; } @@ -321,7 +319,7 @@ public List getRunningProxyListByMsid(long msid) { l.add(rs.getLong(1)); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return l; } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDao.java b/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDao.java index 71b1aed1938d..79158dd13b26 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDao.java @@ -23,6 +23,7 @@ import com.cloud.utils.db.GenericDao; import java.util.Date; +import java.util.List; public interface ConsoleSessionDao extends GenericDao { @@ -33,4 +34,6 @@ public interface ConsoleSessionDao extends GenericDao { int expungeSessionsOlderThanDate(Date date); void acquireSession(String sessionUuid); + + int expungeByVmList(List vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java index 8e7e229622e8..487096744512 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java @@ -20,6 +20,9 @@ package com.cloud.vm.dao; import java.util.Date; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; @@ -65,5 +68,15 @@ public void acquireSession(String sessionUuid) { update(consoleSessionVO.getId(), consoleSessionVO); } - + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getInstanceId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java b/engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java index 68f57329d779..d34b03c4cb08 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java @@ -44,6 +44,8 @@ public interface NicDao extends GenericDao { NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType); + NicVO findByNetworkIdAndTypeIncludingRemoved(long networkId, VirtualMachine.Type vmType); + NicVO findByIp4AddressAndNetworkId(String ip4Address, long networkId); NicVO findByNetworkIdAndMacAddress(long networkId, String mac); @@ -98,4 +100,5 @@ public interface NicDao extends GenericDao { NicVO findByIpAddressAndVmType(String ip, VirtualMachine.Type vmType); List listByNetworkIdAndType(long networkId, VirtualMachine.Type vmType); + List searchRemovedByVms(List vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java index 59d2417b073c..7d1af1982ae1 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java @@ -17,11 +17,13 @@ package com.cloud.vm.dao; import java.net.URI; +import java.util.ArrayList; import java.util.List; import javax.annotation.PostConstruct; import javax.inject.Inject; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.utils.db.Filter; @@ -176,12 +178,21 @@ public NicVO findByInstanceIdAndNetworkIdIncludingRemoved(long networkId, long i return findOneIncludingRemovedBy(sc); } - @Override - public NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType) { + private NicVO findByNetworkIdAndTypeInternal(long networkId, VirtualMachine.Type vmType, boolean includingRemoved) { SearchCriteria sc = AllFieldsSearch.create(); sc.setParameters("network", networkId); sc.setParameters("vmType", vmType); - return findOneBy(sc); + return includingRemoved ? findOneIncludingRemovedBy(sc) : findOneBy(sc); + } + + @Override + public NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType) { + return findByNetworkIdAndTypeInternal(networkId, vmType, false); + } + + @Override + public NicVO findByNetworkIdAndTypeIncludingRemoved(long networkId, VirtualMachine.Type vmType) { + return findByNetworkIdAndTypeInternal(networkId, vmType, true); } @Override @@ -419,4 +430,18 @@ public List listByNetworkIdAndType(long networkId, VirtualMachine.Type vm sc.setParameters("vmType", vmType); return listBy(sc); } + + @Override + public List searchRemovedByVms(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return new ArrayList<>(); + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getInstanceId(), SearchCriteria.Op.IN); + sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NNULL); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + Filter filter = new Filter(NicVO.class, "id", true, 0L, batchSize); + return searchIncludingRemoved(sc, filter, null, false); + } } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/NicExtraDhcpOptionDao.java b/engine/schema/src/main/java/com/cloud/vm/dao/NicExtraDhcpOptionDao.java index 69d9c00e1e0b..7bae64a6acbd 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/NicExtraDhcpOptionDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/NicExtraDhcpOptionDao.java @@ -29,4 +29,5 @@ public interface NicExtraDhcpOptionDao extends GenericDao extraDhcpOptions); + int expungeByNicList(List nicIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/NicExtraDhcpOptionDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/NicExtraDhcpOptionDaoImpl.java index 3056c73938e7..0f3679d66a37 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/NicExtraDhcpOptionDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/NicExtraDhcpOptionDaoImpl.java @@ -16,13 +16,13 @@ // under the License. package com.cloud.vm.dao; -import org.springframework.stereotype.Component; - import java.util.List; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.stereotype.Component; + import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; - import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.vm.NicExtraDhcpOption; @@ -74,4 +74,15 @@ public void removeByNicId(long nicId) { expunge(sc); } + @Override + public int expungeByNicList(List nicIds, Long batchSize) { + if (CollectionUtils.isEmpty(nicIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("nicIds", sb.entity().getNicId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("nicIds", nicIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpDao.java b/engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpDao.java index cbb52e57282b..ff7089ca4276 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpDao.java @@ -55,4 +55,5 @@ public interface NicSecondaryIpDao extends GenericDao { List listSecondaryIpUsingKeyword(long nicId, String keyword); int moveSecondaryIps(long fromNicId, long toNicId); + int expungeByVmList(List vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java index a56d35d5a63d..563b3279520c 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; @@ -192,4 +193,16 @@ public int moveSecondaryIps(long fromNicId, long toNicId) { return update(update, sc); } + + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getVmId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java index 2b3c0289b23e..b2b719cd12ed 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java @@ -23,7 +23,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Attribute; @@ -38,7 +37,6 @@ @Component public class SecondaryStorageVmDaoImpl extends GenericDaoBase implements SecondaryStorageVmDao { - private static final Logger s_logger = Logger.getLogger(SecondaryStorageVmDaoImpl.class); protected SearchBuilder DataCenterStatusSearch; protected SearchBuilder StateSearch; @@ -193,7 +191,7 @@ public List getRunningSecStorageVmListByMsid(SecondaryStorageVm.Role role, l.add(rs.getLong(1)); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return l; } @@ -263,7 +261,7 @@ public List listRunningSecStorageOrderByLoad(SecondaryStorageVm.Role role, l.add(rs.getLong(1)); } } catch (SQLException e) { - s_logger.error("Unexpected exception ", e); + logger.error("Unexpected exception ", e); } return l; diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/UserVmCloneSettingDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/UserVmCloneSettingDaoImpl.java index 0761f56917b3..344f4e86fed5 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/UserVmCloneSettingDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/UserVmCloneSettingDaoImpl.java @@ -20,7 +20,6 @@ import javax.annotation.PostConstruct; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.DB; @@ -33,7 +32,6 @@ @Component @DB() public class UserVmCloneSettingDaoImpl extends GenericDaoBase implements UserVmCloneSettingDao { - public static final Logger s_logger = Logger.getLogger(UserVmCloneSettingDaoImpl.class); protected SearchBuilder vmIdSearch; protected SearchBuilder cloneTypeSearch; diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDao.java b/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDao.java index 39c65866658f..7de543e69d31 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDao.java @@ -53,7 +53,11 @@ public interface UserVmDao extends GenericDao { * @param hostName TODO * @param instanceName */ - void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData, Long userDataId, String userDataDetails, boolean displayVm, boolean isDynamicallyScalable, String customId, String hostName, String instanceName); + void updateVM(long id, String displayName, boolean enable, Long osTypeId, + String userData, Long userDataId, String userDataDetails, + boolean displayVm, boolean isDynamicallyScalable, + boolean deleteProtection, String customId, String hostName, + String instanceName); List findDestroyedVms(Date date); diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java index 80fabf6a7f7b..cc8b9fc59a8d 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java @@ -26,12 +26,17 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.inject.Inject; +import com.cloud.configuration.Resource; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import org.apache.cloudstack.reservation.ReservationVO; +import org.apache.cloudstack.reservation.dao.ReservationDao; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.network.Network; import com.cloud.network.dao.NetworkDao; @@ -60,7 +65,6 @@ import com.cloud.vm.dao.UserVmData.SecurityGroupData; public class UserVmDaoImpl extends GenericDaoBase implements UserVmDao { - public static final Logger s_logger = Logger.getLogger(UserVmDaoImpl.class); protected SearchBuilder AccountPodSearch; protected SearchBuilder AccountDataCenterSearch; @@ -93,6 +97,8 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use NetworkDao networkDao; @Inject NetworkOfferingServiceMapDao networkOfferingServiceMapDao; + @Inject + ReservationDao reservationDao; private static final String LIST_PODS_HAVING_VMS_FOR_ACCOUNT = "SELECT pod_id FROM cloud.vm_instance WHERE data_center_id = ? AND account_id = ? AND pod_id IS NOT NULL AND (state = 'Running' OR state = 'Stopped') " @@ -200,6 +206,7 @@ void init() { CountByAccount.and("type", CountByAccount.entity().getType(), SearchCriteria.Op.EQ); CountByAccount.and("state", CountByAccount.entity().getState(), SearchCriteria.Op.NIN); CountByAccount.and("displayVm", CountByAccount.entity().isDisplayVm(), SearchCriteria.Op.EQ); + CountByAccount.and("idNIN", CountByAccount.entity().getId(), SearchCriteria.Op.NIN); CountByAccount.done(); CountActiveAccount = createSearchBuilder(Long.class); @@ -267,8 +274,11 @@ public List listByAccountAndDataCenter(long accountId, long dcId) { } @Override - public void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData, Long userDataId, String userDataDetails, boolean displayVm, - boolean isDynamicallyScalable, String customId, String hostName, String instanceName) { + public void updateVM(long id, String displayName, boolean enable, Long osTypeId, + String userData, Long userDataId, String userDataDetails, + boolean displayVm, boolean isDynamicallyScalable, + boolean deleteProtection, String customId, String hostName, + String instanceName) { UserVmVO vo = createForUpdate(); vo.setDisplayName(displayName); vo.setHaEnabled(enable); @@ -278,6 +288,7 @@ public void updateVM(long id, String displayName, boolean enable, Long osTypeId, vo.setUserDataDetails(userDataDetails); vo.setDisplayVm(displayVm); vo.setDynamicallyScalable(isDynamicallyScalable); + vo.setDeleteProtection(deleteProtection); if (hostName != null) { vo.setHostName(hostName); } @@ -459,13 +470,13 @@ public List listPodIdsHavingVmsforAccount(long zoneId, long accountId) { } } catch (Exception e) { - s_logger.error("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage()); + logger.error("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage()); throw new CloudRuntimeException("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage(), e); } txn.commit(); return result; } catch (Exception e) { - s_logger.error("listPodIdsHavingVmsforAccount:Exception : " + e.getMessage()); + logger.error("listPodIdsHavingVmsforAccount:Exception : " + e.getMessage()); throw new CloudRuntimeException("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage(), e); } finally { @@ -477,7 +488,7 @@ public List listPodIdsHavingVmsforAccount(long zoneId, long accountId) { } catch (Exception e) { - s_logger.error("listPodIdsHavingVmsforAccount:Exception:" + e.getMessage()); + logger.error("listPodIdsHavingVmsforAccount:Exception:" + e.getMessage()); } } @@ -514,7 +525,7 @@ public Hashtable listVmDetails(Hashtable use } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } curr_index += VM_DETAILS_BATCH_SIZE; @@ -522,7 +533,7 @@ public Hashtable listVmDetails(Hashtable use } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } } @@ -550,20 +561,20 @@ public Hashtable listVmDetails(Hashtable use } catch (Exception e) { - s_logger.error("listVmDetails: Exception:" + e.getMessage()); + logger.error("listVmDetails: Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } } txn.commit(); return userVmDataHash; } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails:Exception : ", e); } finally { @@ -575,7 +586,7 @@ public Hashtable listVmDetails(Hashtable use } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); } } @@ -699,6 +710,9 @@ public String getQueryBatchAppender(int count) { @Override public Long countAllocatedVMsForAccount(long accountId, boolean runningVMsonly) { + List reservations = reservationDao.getReservationsForAccount(accountId, Resource.ResourceType.user_vm, null); + List reservedResourceIds = reservations.stream().filter(reservation -> reservation.getReservedAmount() > 0).map(ReservationVO::getResourceId).collect(Collectors.toList()); + SearchCriteria sc = CountByAccount.create(); sc.setParameters("account", accountId); sc.setParameters("type", VirtualMachine.Type.User); @@ -707,6 +721,11 @@ public Long countAllocatedVMsForAccount(long accountId, boolean runningVMsonly) else sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging}); sc.setParameters("displayVm", 1); + + if (CollectionUtils.isNotEmpty(reservedResourceIds)) { + sc.setParameters("idNIN", reservedResourceIds.toArray()); + } + return customSearch(sc, null).get(0); } @@ -740,7 +759,7 @@ public List, Pair>> getVmsD } } } catch (SQLException e) { - s_logger.error("GetVmsDetailsByNames: Exception in sql: " + e.getMessage()); + logger.error("GetVmsDetailsByNames: Exception in sql: " + e.getMessage()); throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage()); } @@ -763,7 +782,7 @@ public List> countVmsBySize(long dcId, int li result.add(new Ternary(rs.getInt(1), rs.getInt(2), rs.getInt(3))); } } catch (Exception e) { - s_logger.warn("Error counting vms by size for dcId= " + dcId, e); + logger.warn("Error counting vms by size for dcId= " + dcId, e); } return result; } @@ -794,4 +813,15 @@ public List listByIds(List ids) { sc.setParameters("ids", ids.toArray()); return listBy(sc); } + + @Override + public UserVmVO persist(UserVmVO entity) { + return Transaction.execute((TransactionCallback) status -> { + UserVmVO userVM = super.persist(entity); + reservationDao.setResourceId(Resource.ResourceType.user_vm, userVM.getId()); + reservationDao.setResourceId(Resource.ResourceType.cpu, userVM.getId()); + reservationDao.setResourceId(Resource.ResourceType.memory, userVM.getId()); + return userVM; + }); + } } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java index 63f7ad974e68..52bc5aac7e25 100755 --- a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDao.java @@ -166,5 +166,8 @@ public interface VMInstanceDao extends GenericDao, StateDao< List listByHostOrLastHostOrHostPod(List hostIds, long podId); + List searchRemovedByRemoveDate(final Date startDate, final Date endDate, final Long batchSize, + List skippedVmIds); + Pair, Integer> listByVmsNotInClusterUsingPool(long clusterId, long poolId); } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java index a1bd25c2fbc0..744518ba7433 100755 --- a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -29,7 +29,7 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.host.HostVO; @@ -43,6 +43,7 @@ import com.cloud.utils.Pair; import com.cloud.utils.db.Attribute; import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; import com.cloud.utils.db.JoinBuilder; @@ -68,7 +69,6 @@ @Component public class VMInstanceDaoImpl extends GenericDaoBase implements VMInstanceDao { - public static final Logger s_logger = Logger.getLogger(VMInstanceDaoImpl.class); static final int MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT = 3; protected SearchBuilder VMClusterSearch; @@ -522,8 +522,8 @@ public void updateProxyId(long id, Long proxyId, Date time) { @Override public boolean updateState(State oldState, Event event, State newState, VirtualMachine vm, Object opaque) { if (newState == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString()); + if (logger.isDebugEnabled()) { + logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString()); } return false; } @@ -565,7 +565,7 @@ public boolean updateState(State oldState, Event event, State newState, VirtualM if (result == 0) { VMInstanceVO vo = findByIdIncludingRemoved(vm.getId()); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (vo != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated()) @@ -574,16 +574,16 @@ public boolean updateState(State oldState, Event event, State newState, VirtualM .append("; time=").append(vo.getUpdateTime()); str.append("} Stale Data: {Host=").append(oldHostId).append("; State=").append(oldState).append("; updated=").append(oldUpdated).append("; time=") .append(oldUpdateDate).append("}"); - s_logger.debug(str.toString()); + logger.debug(str.toString()); } else { - s_logger.debug("Unable to update the vm id=" + vm.getId() + "; the vm either doesn't exist or already removed"); + logger.debug("Unable to update the vm id=" + vm.getId() + "; the vm either doesn't exist or already removed"); } } if (vo != null && vo.getState() == newState) { // allow for concurrent update if target state has already been matched - s_logger.debug("VM " + vo.getInstanceName() + " state has been already been updated to " + newState); + logger.debug("VM " + vo.getInstanceName() + " state has been already been updated to " + newState); return true; } } @@ -845,7 +845,7 @@ public Long countByZoneAndStateAndHostTag(long dcId, State state, String hostTag return rs.getLong(1); } } catch (Exception e) { - s_logger.warn(String.format("Error counting vms by host tag for dcId= %s, hostTag= %s", dcId, hostTag), e); + logger.warn(String.format("Error counting vms by host tag for dcId= %s, hostTag= %s", dcId, hostTag), e); } return 0L; } @@ -954,7 +954,7 @@ private boolean isPowerStateInSyncWithInstanceState(final VirtualMachine.PowerSt State instanceState = instance.getState(); if ((powerState == VirtualMachine.PowerState.PowerOff && instanceState == State.Running) || (powerState == VirtualMachine.PowerState.PowerOn && instanceState == State.Stopped)) { - s_logger.debug(String.format("VM id: %d on host id: %d and power host id: %d is in %s state, but power state is %s", + logger.debug(String.format("VM id: %d on host id: %d and power host id: %d is in %s state, but power state is %s", instance.getId(), instance.getHostId(), powerHostId, instanceState, powerState)); return false; } @@ -1039,6 +1039,27 @@ public List listByHostOrLastHostOrHostPod(List hostIds, long } @Override + public List searchRemovedByRemoveDate(Date startDate, Date endDate, Long batchSize, + List skippedVmIds) { + SearchBuilder sb = createSearchBuilder(); + sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NNULL); + sb.and("startDate", sb.entity().getRemoved(), SearchCriteria.Op.GTEQ); + sb.and("endDate", sb.entity().getRemoved(), SearchCriteria.Op.LTEQ); + sb.and("skippedVmIds", sb.entity().getId(), Op.NOTIN); + SearchCriteria sc = sb.create(); + if (startDate != null) { + sc.setParameters("startDate", startDate); + } + if (endDate != null) { + sc.setParameters("endDate", endDate); + } + if (CollectionUtils.isNotEmpty(skippedVmIds)) { + sc.setParameters("skippedVmIds", skippedVmIds.toArray()); + } + Filter filter = new Filter(VMInstanceVO.class, "id", true, 0L, batchSize); + return searchIncludingRemoved(sc, filter, null, false); + } + public Pair, Integer> listByVmsNotInClusterUsingPool(long clusterId, long poolId) { SearchCriteria sc = VmsNotInClusterUsingPool.create(); sc.setParameters("vmStates", State.Starting, State.Running, State.Stopping, State.Migrating, State.Restoring); diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/VmStatsDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/VmStatsDaoImpl.java index a98302e21360..aa58e489364a 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/VmStatsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/VmStatsDaoImpl.java @@ -21,7 +21,8 @@ import javax.annotation.PostConstruct; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Filter; @@ -34,7 +35,7 @@ @Component public class VmStatsDaoImpl extends GenericDaoBase implements VmStatsDao { - protected Logger logger = Logger.getLogger(getClass()); + protected Logger logger = LogManager.getLogger(getClass()); protected SearchBuilder vmIdSearch; protected SearchBuilder vmIdTimestampGreaterThanEqualSearch; diff --git a/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDao.java b/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDao.java index 31999ef15d66..0143aaa1e735 100644 --- a/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDao.java @@ -38,4 +38,6 @@ public interface VMSnapshotDao extends GenericDao, StateDao< VMSnapshotVO findByName(Long vmId, String name); List listByAccountId(Long accountId); + List searchByVms(List vmIds); + List searchRemovedByVms(List vmIds, Long batchSize); } diff --git a/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java index 1b1842dfd894..ab8f5f2cd849 100644 --- a/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java @@ -17,13 +17,14 @@ package com.cloud.vm.snapshot.dao; +import java.util.ArrayList; import java.util.Date; import java.util.List; - -import org.apache.log4j.Logger; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; +import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; @@ -36,7 +37,6 @@ @Component public class VMSnapshotDaoImpl extends GenericDaoBase implements VMSnapshotDao { - private static final Logger s_logger = Logger.getLogger(VMSnapshotDaoImpl.class); private final SearchBuilder SnapshotSearch; private final SearchBuilder ExpungingSnapshotSearch; private final SearchBuilder SnapshotStatusSearch; @@ -143,7 +143,7 @@ public boolean updateState(State currentState, Event event, State nextState, VMS builder.set(vo, "updated", new Date()); int rows = update((VMSnapshotVO)vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { VMSnapshotVO dbVol = findByIdIncludingRemoved(vo.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -176,10 +176,35 @@ public boolean updateState(State currentState, Event event, State nextState, VMS .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update VM snapshot: id=" + vo.getId() + ", as there is no such snapshot exists in the database anymore"); + logger.debug("Unable to update VM snapshot: id=" + vo.getId() + ", as there is no such snapshot exists in the database anymore"); } } return rows > 0; } + @Override + public List searchByVms(List vmIds) { + if (CollectionUtils.isEmpty(vmIds)) { + return new ArrayList<>(); + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getVmId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return search(sc, null); + } + + @Override + public List searchRemovedByVms(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return new ArrayList<>(); + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getVmId(), SearchCriteria.Op.IN); + sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NNULL); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + Filter filter = new Filter(VMSnapshotVO.class, "id", true, 0L, batchSize); + return searchIncludingRemoved(sc, filter, null, false); + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/RoleVO.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/RoleVO.java index d4647255fc67..084df29fa427 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/RoleVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/RoleVO.java @@ -58,11 +58,16 @@ public class RoleVO implements Role { @Column(name = "public_role") private boolean publicRole = true; + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + private State state; + @Column(name = GenericDao.REMOVED_COLUMN) private Date removed; public RoleVO() { this.uuid = UUID.randomUUID().toString(); + this.state = State.ENABLED; } public RoleVO(final String name, final RoleType roleType, final String description) { @@ -131,4 +136,12 @@ public boolean isPublicRole() { public void setPublicRole(boolean publicRole) { this.publicRole = publicRole; } + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ProjectRolePermissionsDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ProjectRolePermissionsDaoImpl.java index d88a6f5453dc..d028ca58b32d 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ProjectRolePermissionsDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ProjectRolePermissionsDaoImpl.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.acl.RolePermissionEntity.Permission; import org.apache.cloudstack.acl.ProjectRolePermission; import org.apache.cloudstack.acl.ProjectRolePermissionVO; -import org.apache.log4j.Logger; import com.cloud.utils.db.Attribute; import com.cloud.utils.db.Filter; @@ -42,7 +41,6 @@ public class ProjectRolePermissionsDaoImpl extends GenericDaoBase implements ProjectRolePermissionsDao{ - private static final Logger LOGGER = Logger.getLogger(ProjectRolePermissionsDaoImpl.class); private final SearchBuilder ProjectRolePermissionsSearch; private Attribute sortOrderAttribute; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java index 2d4151afc7db..f4fdb6a2b161 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java @@ -28,15 +28,15 @@ public interface RoleDao extends GenericDao { List findAllByName(String roleName, boolean showPrivateRole); - Pair, Integer> findAllByName(final String roleName, String keyword, Long offset, Long limit, boolean showPrivateRole); + Pair, Integer> findAllByName(final String roleName, String keyword, String state, Long offset, Long limit, boolean showPrivateRole); List findAllByRoleType(RoleType type, boolean showPrivateRole); List findByName(String roleName, boolean showPrivateRole); RoleVO findByNameAndType(String roleName, RoleType type, boolean showPrivateRole); - Pair, Integer> findAllByRoleType(RoleType type, Long offset, Long limit, boolean showPrivateRole); + Pair, Integer> findAllByRoleType(RoleType type, String state, Long offset, Long limit, boolean showPrivateRole); - Pair, Integer> listAllRoles(Long startIndex, Long limit, boolean showPrivateRole); + Pair, Integer> listAllRoles(String state, Long startIndex, Long limit, boolean showPrivateRole); List searchByIds(Long... ids); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java index 2e8fdd5fcc20..48c0d828a415 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java @@ -50,11 +50,13 @@ public RoleDaoImpl() { RoleByNameSearch = createSearchBuilder(); RoleByNameSearch.and("roleName", RoleByNameSearch.entity().getName(), SearchCriteria.Op.LIKE); RoleByNameSearch.and("isPublicRole", RoleByNameSearch.entity().isPublicRole(), SearchCriteria.Op.EQ); + RoleByNameSearch.and("state", RoleByNameSearch.entity().getState(), SearchCriteria.Op.EQ); RoleByNameSearch.done(); RoleByTypeSearch = createSearchBuilder(); RoleByTypeSearch.and("roleType", RoleByTypeSearch.entity().getRoleType(), SearchCriteria.Op.EQ); RoleByTypeSearch.and("isPublicRole", RoleByTypeSearch.entity().isPublicRole(), SearchCriteria.Op.EQ); + RoleByTypeSearch.and("state", RoleByTypeSearch.entity().getState(), SearchCriteria.Op.EQ); RoleByTypeSearch.done(); RoleByNameAndTypeSearch = createSearchBuilder(); @@ -65,16 +67,17 @@ public RoleDaoImpl() { RoleByIsPublicSearch = createSearchBuilder(); RoleByIsPublicSearch.and("isPublicRole", RoleByIsPublicSearch.entity().isPublicRole(), SearchCriteria.Op.EQ); + RoleByIsPublicSearch.and("state", RoleByIsPublicSearch.entity().getState(), SearchCriteria.Op.EQ); RoleByIsPublicSearch.done(); } @Override public List findAllByName(final String roleName, boolean showPrivateRole) { - return findAllByName(roleName, null, null, null, showPrivateRole).first(); + return findAllByName(roleName, null, null, null, null, showPrivateRole).first(); } @Override - public Pair, Integer> findAllByName(final String roleName, String keyword, Long offset, Long limit, boolean showPrivateRole) { + public Pair, Integer> findAllByName(final String roleName, String keyword, String state, Long offset, Long limit, boolean showPrivateRole) { SearchCriteria sc = RoleByNameSearch.create(); filterPrivateRolesIfNeeded(sc, showPrivateRole); if (StringUtils.isNotEmpty(roleName)) { @@ -83,19 +86,25 @@ public Pair, Integer> findAllByName(final String roleName, String k if (StringUtils.isNotEmpty(keyword)) { sc.setParameters("roleName", "%" + keyword + "%"); } + if (StringUtils.isNotEmpty(state)) { + sc.setParameters("state", state); + } return searchAndCount(sc, new Filter(RoleVO.class, "id", true, offset, limit)); } @Override public List findAllByRoleType(final RoleType type, boolean showPrivateRole) { - return findAllByRoleType(type, null, null, showPrivateRole).first(); + return findAllByRoleType(type, null, null, null, showPrivateRole).first(); } - public Pair, Integer> findAllByRoleType(final RoleType type, Long offset, Long limit, boolean showPrivateRole) { + public Pair, Integer> findAllByRoleType(final RoleType type, String state, Long offset, Long limit, boolean showPrivateRole) { SearchCriteria sc = RoleByTypeSearch.create(); filterPrivateRolesIfNeeded(sc, showPrivateRole); sc.setParameters("roleType", type); + if (StringUtils.isNotEmpty(state)) { + sc.setParameters("state", state); + } return searchAndCount(sc, new Filter(RoleVO.class, "id", true, offset, limit)); } @@ -117,8 +126,11 @@ public RoleVO findByNameAndType(String roleName, RoleType type, boolean showPriv } @Override - public Pair, Integer> listAllRoles(Long startIndex, Long limit, boolean showPrivateRole) { + public Pair, Integer> listAllRoles(String state, Long startIndex, Long limit, boolean showPrivateRole) { SearchCriteria sc = RoleByIsPublicSearch.create(); + if (StringUtils.isNotEmpty(state)) { + sc.setParameters("state", state); + } filterPrivateRolesIfNeeded(sc, showPrivateRole); return searchAndCount(sc, new Filter(RoleVO.class, "id", true, startIndex, limit)); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RolePermissionsDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RolePermissionsDaoImpl.java index b63dd502ee7b..7802265928ed 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RolePermissionsDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RolePermissionsDaoImpl.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.acl.RolePermission; import org.apache.cloudstack.acl.RolePermissionEntity.Permission; import org.apache.cloudstack.acl.RolePermissionVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Attribute; @@ -43,7 +42,6 @@ @Component public class RolePermissionsDaoImpl extends GenericDaoBase implements RolePermissionsDao { - protected static final Logger LOGGER = Logger.getLogger(RolePermissionsDaoImpl.class); private final SearchBuilder RolePermissionsSearchByRoleAndRule; private final SearchBuilder RolePermissionsSearch; @@ -90,7 +88,7 @@ private boolean updateSortOrder(final RolePermissionVO permissionBeingMoved, fin for (final RolePermissionVO permission : newOrderedPermissionsList) { permission.setSortOrder(sortOrder++); if (!update(permission.getId(), permission)) { - LOGGER.warn("Failed to update item's sort order with id:" + permission.getId() + " while moving permission with id:" + permissionBeingMoved.getId() + " to a new position"); + logger.warn("Failed to update item's sort order with id:" + permission.getId() + " while moving permission with id:" + permissionBeingMoved.getId() + " to a new position"); return false; } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/affinity/dao/AffinityGroupDomainMapDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/affinity/dao/AffinityGroupDomainMapDaoImpl.java index 1dd22df46d71..3efedd826dca 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/affinity/dao/AffinityGroupDomainMapDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/affinity/dao/AffinityGroupDomainMapDaoImpl.java @@ -27,9 +27,7 @@ import javax.annotation.PostConstruct; import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO; -import org.apache.log4j.Logger; -import com.cloud.network.dao.NetworkDomainDaoImpl; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; @@ -37,7 +35,6 @@ import com.cloud.utils.db.TransactionLegacy; public class AffinityGroupDomainMapDaoImpl extends GenericDaoBase implements AffinityGroupDomainMapDao { - public static Logger logger = Logger.getLogger(NetworkDomainDaoImpl.class.getName()); private SearchBuilder ListByAffinityGroup; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupRepositoryVO.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupRepositoryVO.java new file mode 100644 index 000000000000..e8364520ed05 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupRepositoryVO.java @@ -0,0 +1,155 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.backup; + +import com.cloud.utils.db.Encrypt; + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name = "backup_repository") +public class BackupRepositoryVO implements BackupRepository { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "name") + private String name; + + @Column(name = "zone_id", nullable = false) + private long zoneId; + + @Column(name = "provider", nullable = false) + private String provider; + + @Column(name = "type", nullable = false) + private String type; + + @Column(name = "address", nullable = false) + private String address; + + @Encrypt + @Column(name = "mount_opts") + private String mountOptions; + + @Column(name = "used_bytes",nullable = true) + private Long usedBytes; + + @Column(name = "capacity_bytes", nullable = true) + private Long capacityBytes; + + @Column(name = "created") + @Temporal(value = TemporalType.TIMESTAMP) + private Date created; + + @Column(name = "removed") + @Temporal(value = TemporalType.TIMESTAMP) + private Date removed; + + public BackupRepositoryVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public BackupRepositoryVO(final long zoneId, final String provider, final String name, final String type, final String address, final String mountOptions, final Long capacityBytes) { + this(); + this.zoneId = zoneId; + this.provider = provider; + this.name = name; + this.type = type; + this.address = address; + this.mountOptions = mountOptions; + this.capacityBytes = capacityBytes; + this.created = new Date(); + } + + public String getUuid() { + return uuid; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public long getZoneId() { + return zoneId; + } + + @Override + public String getProvider() { + return provider; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String getAddress() { + return address; + } + + @Override + public String getMountOptions() { + return mountOptions; + } + + @Override + public Long getUsedBytes() { + return usedBytes; + } + + @Override + public Long getCapacityBytes() { + return capacityBytes; + } + + public Date getCreated() { + return created; + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java index b6ad0e7cb8fa..9b285e66cab9 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java @@ -18,8 +18,13 @@ package org.apache.cloudstack.backup; import com.cloud.utils.db.GenericDao; +import com.google.gson.Gson; +import org.apache.commons.lang3.StringUtils; +import java.util.Arrays; +import java.util.Collections; import java.util.Date; +import java.util.List; import java.util.UUID; import javax.persistence.Column; @@ -82,6 +87,9 @@ public class BackupVO implements Backup { @Column(name = "zone_id") private long zoneId; + @Column(name = "backed_volumes", length = 65535) + protected String backedUpVolumes; + public BackupVO() { this.uuid = UUID.randomUUID().toString(); } @@ -203,6 +211,17 @@ public String getName() { return null; } + public List getBackedUpVolumes() { + if (StringUtils.isEmpty(this.backedUpVolumes)) { + return Collections.emptyList(); + } + return Arrays.asList(new Gson().fromJson(this.backedUpVolumes, Backup.VolumeInfo[].class)); + } + + public void setBackedUpVolumes(String backedUpVolumes) { + this.backedUpVolumes = backedUpVolumes; + } + public Date getRemoved() { return removed; } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDao.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDao.java index 5d2f5ac64d61..89a13245b0a0 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDao.java @@ -32,9 +32,8 @@ public interface BackupDao extends GenericDao { List listByVmId(Long zoneId, Long vmId); List listByAccountId(Long accountId); - List listByOfferingId(Long offeringId); List syncBackups(Long zoneId, Long vmId, List externalBackups); BackupVO getBackupVO(Backup backup); - + List listByOfferingId(Long backupOfferingId); BackupResponse newBackupResponse(Backup backup); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDaoImpl.java index 8628fe8e01b2..5a9cd0620374 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupDaoImpl.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import javax.annotation.PostConstruct; import javax.inject.Inject; @@ -68,6 +69,8 @@ protected void init() { backupSearch = createSearchBuilder(); backupSearch.and("vm_id", backupSearch.entity().getVmId(), SearchCriteria.Op.EQ); backupSearch.and("external_id", backupSearch.entity().getExternalId(), SearchCriteria.Op.EQ); + backupSearch.and("backup_offering_id", backupSearch.entity().getBackupOfferingId(), SearchCriteria.Op.EQ); + backupSearch.and("zone_id", backupSearch.entity().getZoneId(), SearchCriteria.Op.EQ); backupSearch.done(); } @@ -102,13 +105,6 @@ public List listByVmId(Long zoneId, Long vmId) { return new ArrayList<>(listBy(sc)); } - @Override - public List listByOfferingId(Long offeringId) { - SearchCriteria sc = backupSearch.create(); - sc.setParameters("offering_id", offeringId); - return new ArrayList<>(listBy(sc)); - } - private Backup findByExternalId(Long zoneId, String externalId) { SearchCriteria sc = backupSearch.create(); sc.setParameters("external_id", externalId); @@ -123,6 +119,13 @@ public BackupVO getBackupVO(Backup backup) { return backupVO; } + @Override + public List listByOfferingId(Long backupOfferingId) { + SearchCriteria sc = backupSearch.create(); + sc.setParameters("backup_offering_id", backupOfferingId); + return new ArrayList<>(listBy(sc)); + } + public void removeExistingBackups(Long zoneId, Long vmId) { SearchCriteria sc = backupSearch.create(); sc.setParameters("vm_id", vmId); @@ -145,9 +148,9 @@ public BackupResponse newBackupResponse(Backup backup) { AccountVO account = accountDao.findByIdIncludingRemoved(vm.getAccountId()); DomainVO domain = domainDao.findByIdIncludingRemoved(vm.getDomainId()); DataCenterVO zone = dataCenterDao.findByIdIncludingRemoved(vm.getDataCenterId()); - Long offeringId = vm.getBackupOfferingId(); + Long offeringId = backup.getBackupOfferingId(); if (offeringId == null) { - offeringId = backup.getBackupOfferingId(); + offeringId = vm.getBackupOfferingId(); } BackupOffering offering = backupOfferingDao.findByIdIncludingRemoved(offeringId); @@ -161,7 +164,14 @@ public BackupResponse newBackupResponse(Backup backup) { response.setSize(backup.getSize()); response.setProtectedSize(backup.getProtectedSize()); response.setStatus(backup.getStatus()); - response.setVolumes(new Gson().toJson(vm.getBackupVolumeList().toArray(), Backup.VolumeInfo[].class)); + // ACS 4.20: For backups taken prior this release the backup.backed_volumes column would be empty hence use vm_instance.backup_volumes + String backedUpVolumes; + if (Objects.isNull(backup.getBackedUpVolumes())) { + backedUpVolumes = new Gson().toJson(vm.getBackupVolumeList().toArray(), Backup.VolumeInfo[].class); + } else { + backedUpVolumes = new Gson().toJson(backup.getBackedUpVolumes().toArray(), Backup.VolumeInfo[].class); + } + response.setVolumes(backedUpVolumes); response.setBackupOfferingId(offering.getUuid()); response.setBackupOffering(offering.getName()); response.setAccountId(account.getUuid()); diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupRepositoryDao.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupRepositoryDao.java new file mode 100644 index 000000000000..0034bfb30ab6 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupRepositoryDao.java @@ -0,0 +1,31 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.backup.dao; + +import java.util.List; + +import org.apache.cloudstack.backup.BackupRepository; +import org.apache.cloudstack.backup.BackupRepositoryVO; + +import com.cloud.utils.db.GenericDao; + +public interface BackupRepositoryDao extends GenericDao { + List listByZoneAndProvider(Long zoneId, String provider); + + BackupRepository findByBackupOfferingId(Long backupOfferingId); +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupRepositoryDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupRepositoryDaoImpl.java new file mode 100644 index 000000000000..460b6d8aba45 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupRepositoryDaoImpl.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.backup.dao; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.apache.cloudstack.backup.BackupOfferingVO; +import org.apache.cloudstack.backup.BackupRepository; +import org.apache.cloudstack.backup.BackupRepositoryVO; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +public class BackupRepositoryDaoImpl extends GenericDaoBase implements BackupRepositoryDao { + @Inject + BackupOfferingDao backupOfferingDao; + + private SearchBuilder backupRepoSearch; + + public BackupRepositoryDaoImpl() { + } + + @PostConstruct + protected void init() { + backupRepoSearch = createSearchBuilder(); + backupRepoSearch.and("zone_id", backupRepoSearch.entity().getZoneId(), SearchCriteria.Op.EQ); + backupRepoSearch.and("provider", backupRepoSearch.entity().getProvider(), SearchCriteria.Op.EQ); + backupRepoSearch.done(); + } + + @Override + public List listByZoneAndProvider(Long zoneId, String provider) { + SearchCriteria sc = backupRepoSearch.create(); + sc.setParameters("zone_id", zoneId); + sc.setParameters("provider", provider); + return new ArrayList<>(listBy(sc)); + } + + @Override + public BackupRepository findByBackupOfferingId(Long backupOfferingId) { + BackupOfferingVO offering = backupOfferingDao.findByIdIncludingRemoved(backupOfferingId); + if (offering == null) { + return null; + } + return findByUuid(offering.getExternalId()); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDao.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDao.java index 516b0112c986..ee1783a9c896 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDao.java @@ -20,6 +20,7 @@ import java.util.Date; import java.util.List; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.api.response.BackupScheduleResponse; import org.apache.cloudstack.backup.BackupSchedule; import org.apache.cloudstack.backup.BackupScheduleVO; @@ -29,6 +30,10 @@ public interface BackupScheduleDao extends GenericDao { BackupScheduleVO findByVM(Long vmId); + List listByVM(Long vmId); + + BackupScheduleVO findByVMAndIntervalType(Long vmId, DateUtil.IntervalType intervalType); + List getSchedulesToExecute(Date currentTimestamp); BackupScheduleResponse newBackupScheduleResponse(BackupSchedule schedule); diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDaoImpl.java index 7a58679e7e53..e00ccc5abd77 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/dao/BackupScheduleDaoImpl.java @@ -23,6 +23,7 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.api.response.BackupScheduleResponse; import org.apache.cloudstack.backup.BackupSchedule; import org.apache.cloudstack.backup.BackupScheduleVO; @@ -49,6 +50,7 @@ protected void init() { backupScheduleSearch = createSearchBuilder(); backupScheduleSearch.and("vm_id", backupScheduleSearch.entity().getVmId(), SearchCriteria.Op.EQ); backupScheduleSearch.and("async_job_id", backupScheduleSearch.entity().getAsyncJobId(), SearchCriteria.Op.EQ); + backupScheduleSearch.and("interval_type", backupScheduleSearch.entity().getScheduleType(), SearchCriteria.Op.EQ); backupScheduleSearch.done(); executableSchedulesSearch = createSearchBuilder(); @@ -64,6 +66,21 @@ public BackupScheduleVO findByVM(Long vmId) { return findOneBy(sc); } + @Override + public List listByVM(Long vmId) { + SearchCriteria sc = backupScheduleSearch.create(); + sc.setParameters("vm_id", vmId); + return listBy(sc, null); + } + + @Override + public BackupScheduleVO findByVMAndIntervalType(Long vmId, DateUtil.IntervalType intervalType) { + SearchCriteria sc = backupScheduleSearch.create(); + sc.setParameters("vm_id", vmId); + sc.setParameters("interval_type", intervalType.ordinal()); + return findOneBy(sc); + } + @Override public List getSchedulesToExecute(Date currentTimestamp) { SearchCriteria sc = executableSchedulesSearch.create(); diff --git a/engine/schema/src/main/java/org/apache/cloudstack/datacenter/DataCenterIpv4GuestSubnetVO.java b/engine/schema/src/main/java/org/apache/cloudstack/datacenter/DataCenterIpv4GuestSubnetVO.java new file mode 100644 index 000000000000..828e7b39e9a4 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/datacenter/DataCenterIpv4GuestSubnetVO.java @@ -0,0 +1,123 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.datacenter; + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "dc_ip4_guest_subnets") +public class DataCenterIpv4GuestSubnetVO implements DataCenterIpv4GuestSubnet { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + String uuid; + + @Column(name = "data_center_id") + private long dataCenterId; + + @Column(name = "subnet") + private String subnet; + + @Column(name = "domain_id") + Long domainId; + + @Column(name = "account_id") + Long accountId; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name= GenericDao.REMOVED_COLUMN) + private Date removed; + + public DataCenterIpv4GuestSubnetVO(long dcId, String subnet) { + this(); + this.dataCenterId = dcId; + this.subnet = subnet; + this.created = new Date(); + } + + protected DataCenterIpv4GuestSubnetVO() { + this.uuid = UUID.randomUUID().toString(); + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public Long getDataCenterId() { + return dataCenterId; + } + + public void setDataCenterId(long dcId) { + this.dataCenterId = dcId; + } + + public String getSubnet() { + return subnet; + } + + public void setSubnet(String subnet) { + this.subnet = subnet; + } + + @Override + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + + @Override + public Long getAccountId() { + return accountId; + } + + public void setAccountId(Long accountId) { + this.accountId = accountId; + } + + @Override + public Date getCreated() { + return created; + } + + +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/datacenter/dao/DataCenterIpv4GuestSubnetDao.java b/engine/schema/src/main/java/org/apache/cloudstack/datacenter/dao/DataCenterIpv4GuestSubnetDao.java new file mode 100644 index 000000000000..e231b267fda9 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/datacenter/dao/DataCenterIpv4GuestSubnetDao.java @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.datacenter.dao; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnetVO; + +import java.util.List; + +public interface DataCenterIpv4GuestSubnetDao extends GenericDao { + + List listByDataCenterId(long dcId); + List listByDataCenterIdAndAccountId(long dcId, long accountId); + List listByDataCenterIdAndDomainId(long dcId, long domainId); + List listNonDedicatedByDataCenterId(long dcId); + List listByAccountId(long accountId); + List listByDomainId(long domainId); +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/datacenter/dao/DataCenterIpv4GuestSubnetDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/datacenter/dao/DataCenterIpv4GuestSubnetDaoImpl.java new file mode 100644 index 000000000000..49e8a6ef6626 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/datacenter/dao/DataCenterIpv4GuestSubnetDaoImpl.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.datacenter.dao; + +import java.util.List; + +import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnetVO; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.QueryBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Component +@DB +public class DataCenterIpv4GuestSubnetDaoImpl extends GenericDaoBase implements DataCenterIpv4GuestSubnetDao { + + public DataCenterIpv4GuestSubnetDaoImpl() { + } + + @Override + public List listByDataCenterId(long dcId) { + QueryBuilder sc = QueryBuilder.create(DataCenterIpv4GuestSubnetVO.class); + sc.and(sc.entity().getDataCenterId(), SearchCriteria.Op.EQ, dcId); + return sc.list(); + } + + @Override + public List listByDataCenterIdAndAccountId(long dcId, long accountId) { + QueryBuilder sc = QueryBuilder.create(DataCenterIpv4GuestSubnetVO.class); + sc.and(sc.entity().getDataCenterId(), SearchCriteria.Op.EQ, dcId); + sc.and(sc.entity().getAccountId(), SearchCriteria.Op.EQ, accountId); + return sc.list(); + } + + @Override + public List listByDataCenterIdAndDomainId(long dcId, long domainId) { + QueryBuilder sc = QueryBuilder.create(DataCenterIpv4GuestSubnetVO.class); + sc.and(sc.entity().getDataCenterId(), SearchCriteria.Op.EQ, dcId); + sc.and(sc.entity().getDomainId(), SearchCriteria.Op.EQ, domainId); + sc.and(sc.entity().getAccountId(), SearchCriteria.Op.NULL); + return sc.list(); + } + + @Override + public List listNonDedicatedByDataCenterId(long dcId) { + QueryBuilder sc = QueryBuilder.create(DataCenterIpv4GuestSubnetVO.class); + sc.and(sc.entity().getDataCenterId(), SearchCriteria.Op.EQ, dcId); + sc.and(sc.entity().getDomainId(), SearchCriteria.Op.NULL); + sc.and(sc.entity().getAccountId(), SearchCriteria.Op.NULL); + return sc.list(); + } + + @Override + public List listByAccountId(long accountId) { + QueryBuilder sc = QueryBuilder.create(DataCenterIpv4GuestSubnetVO.class); + sc.and(sc.entity().getAccountId(), SearchCriteria.Op.EQ, accountId); + return sc.list(); + } + + @Override + public List listByDomainId(long domainId) { + QueryBuilder sc = QueryBuilder.create(DataCenterIpv4GuestSubnetVO.class); + sc.and(sc.entity().getDomainId(), SearchCriteria.Op.EQ, domainId); + return sc.list(); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadCertificateVO.java b/engine/schema/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadCertificateVO.java index 1e43e164ba40..36aefa201f37 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadCertificateVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadCertificateVO.java @@ -17,8 +17,10 @@ package org.apache.cloudstack.direct.download; import com.cloud.hypervisor.Hypervisor; +import org.apache.cloudstack.util.HypervisorTypeConverter; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -45,6 +47,7 @@ public class DirectDownloadCertificateVO implements DirectDownloadCertificate { private String certificate; @Column(name = "hypervisor_type") + @Convert(converter = HypervisorTypeConverter.class) private Hypervisor.HypervisorType hypervisorType; @Column(name = "zone_id") diff --git a/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java b/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java index 4b96dd1641a8..af48e5e04acd 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java @@ -24,6 +24,7 @@ import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; @@ -48,6 +49,7 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; import com.google.gson.Gson; +import org.apache.cloudstack.util.HypervisorTypeConverter; @Entity @Table(name = "vm_instance") @@ -146,7 +148,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject implements VMEntityDao { - public static final Logger s_logger = Logger.getLogger(VMEntityDaoImpl.class); @Inject protected VMReservationDao _vmReservationDao; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/ha/dao/HAConfigDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/ha/dao/HAConfigDaoImpl.java index 4d74e2e66566..1a27bb1de67f 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/ha/dao/HAConfigDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/ha/dao/HAConfigDaoImpl.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.ha.HAConfig; import org.apache.cloudstack.ha.HAConfigVO; import org.apache.cloudstack.ha.HAResource; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -42,7 +41,6 @@ @DB @Component public class HAConfigDaoImpl extends GenericDaoBase implements HAConfigDao { - private static final Logger LOG = Logger.getLogger(HAConfigDaoImpl.class); private static final String EXPIRE_OWNERSHIP = "UPDATE ha_config set mgmt_server_id=NULL where mgmt_server_id=?"; @@ -77,8 +75,8 @@ public HAConfigDaoImpl() { public boolean updateState(HAConfig.HAState currentState, HAConfig.Event event, HAConfig.HAState nextState, HAConfig vo, Object data) { HAConfigVO haConfig = (HAConfigVO) vo; if (haConfig == null) { - if (LOG.isTraceEnabled()) { - LOG.trace("Invalid ha config view object provided"); + if (logger.isTraceEnabled()) { + logger.trace("Invalid ha config view object provided"); } return false; } @@ -104,8 +102,8 @@ public boolean updateState(HAConfig.HAState currentState, HAConfig.Event event, ub.set(haConfig, MsIdAttr, newManagementServerId); int result = update(ub, sc, null); - if (LOG.isTraceEnabled() && result <= 0) { - LOG.trace(String.format("Failed to update HA state from:%s to:%s due to event:%s for the ha_config id:%d", currentState, nextState, event, haConfig.getId())); + if (logger.isTraceEnabled() && result <= 0) { + logger.trace(String.format("Failed to update HA state from:%s to:%s due to event:%s for the ha_config id:%d", currentState, nextState, event, haConfig.getId())); } return result > 0; } @@ -141,7 +139,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { pstmt.executeUpdate(); } catch (SQLException e) { txn.rollback(); - LOG.warn("Failed to expire HA ownership of management server id: " + serverId); + logger.warn("Failed to expire HA ownership of management server id: " + serverId); } } }); diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerDetailsVO.java b/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerDetailsVO.java new file mode 100644 index 000000000000..9e3378870113 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerDetailsVO.java @@ -0,0 +1,103 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.cloudstack.api.ResourceDetail; + +@Entity +@Table(name = "bgp_peer_details") +public class BgpPeerDetailsVO implements ResourceDetail { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "bgp_peer_id") + private long resourceId; + + @Enumerated(value = EnumType.STRING) + @Column(name = "name") + private BgpPeer.Detail name; + + @Column(name = "value", length = 1024) + private String value; + + @Column(name = "display") + private boolean display; + + public BgpPeerDetailsVO() { + } + + public BgpPeerDetailsVO(long resourceId, BgpPeer.Detail detailName, String value, boolean display) { + this.resourceId = resourceId; + this.name = detailName; + this.value = value; + this.display = display; + } + + @Override + public long getId() { + return id; + } + + @Override + public long getResourceId() { + return resourceId; + } + + public void setResourceId(long resourceId) { + this.resourceId = resourceId; + } + + public String getName() { + return name.name(); + } + + public BgpPeer.Detail getDetailName() { + return name; + } + + public String getValue() { + return value; + } + + @Override + public boolean isDisplay() { + return display; + } + + public void setId(long id) { + this.id = id; + } + + public void setName(BgpPeer.Detail name) { + this.name = name; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerNetworkMapVO.java b/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerNetworkMapVO.java new file mode 100644 index 000000000000..b520ecd5cd1a --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerNetworkMapVO.java @@ -0,0 +1,104 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.api.InternalIdentity; + +import java.util.Date; + +@Entity +@Table(name = "bgp_peer_network_map") +public class BgpPeerNetworkMapVO implements InternalIdentity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "bgp_peer_id") + private long bgpPeerId; + + @Column(name = "network_id") + private Long networkId; + + @Column(name = "vpc_id") + private Long vpcId; + + @Column(name = "state") + private BgpPeer.State state; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name= GenericDao.REMOVED_COLUMN) + private Date removed; + + /** + * There should never be a public constructor for this class. Since it's + * only here to define the table for the DAO class. + */ + protected BgpPeerNetworkMapVO() { + } + + public BgpPeerNetworkMapVO(long bgpPeerId, Long networkId, Long vpcId, BgpPeer.State state) { + this.bgpPeerId = bgpPeerId; + this.networkId = networkId; + this.vpcId = vpcId; + this.state = state; + } + + @Override + public long getId() { + return id; + } + + public long getBgpPeerId() { + return bgpPeerId; + } + + public Long getNetworkId() { + return networkId; + } + + public Long getVpcId() { + return vpcId; + } + + public BgpPeer.State getState() { + return state; + } + + public void setState(BgpPeer.State state) { + this.state = state; + } + + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerVO.java b/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerVO.java new file mode 100644 index 000000000000..0203b34fb1e2 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/BgpPeerVO.java @@ -0,0 +1,170 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.network; + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "bgp_peers") +public class BgpPeerVO implements BgpPeer { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "data_center_id") + private long dataCenterId; + + @Column(name = "ip4_address") + private String ip4Address; + + @Column(name = "ip6_address") + private String ip6Address; + + @Column(name = "as_number") + private Long asNumber; + + @Column(name = "password") + private String password; + + @Column(name = "domain_id") + Long domainId; + + @Column(name = "account_id") + Long accountId; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name= GenericDao.REMOVED_COLUMN) + private Date removed; + + protected BgpPeerVO() { + uuid = UUID.randomUUID().toString(); + } + + public BgpPeerVO(long dcId, String ip4Address, String ip6Address, Long asNumber, String password) { + this(); + this.dataCenterId = dcId; + this.ip4Address = ip4Address; + this.ip6Address = ip6Address; + this.asNumber = asNumber; + this.password = password; + } + + @Override + public String toString() { + return String.format("BgpPeerVO [%s|%s|%s]", asNumber, ip4Address, ip6Address); + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public long getDataCenterId() { + return dataCenterId; + } + + public void setDataCenterId(long dataCenterId) { + this.dataCenterId = dataCenterId; + } + + @Override + public String getIp4Address() { + return ip4Address; + } + + public void setIp4Address(String ip4Address) { + this.ip4Address = ip4Address; + } + + @Override + public String getIp6Address() { + return ip6Address; + } + + public void setIp6Address(String ip6Address) { + this.ip6Address = ip6Address; + } + + @Override + public Long getAsNumber() { + return asNumber; + } + + public void setAsNumber(Long asNumber) { + this.asNumber = asNumber; + } + + @Override + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public Long getDomainId() { + return domainId; + } + + public void setDomainId(Long domainId) { + this.domainId = domainId; + } + + @Override + public Long getAccountId() { + return accountId; + } + + public void setAccountId(Long accountId) { + this.accountId = accountId; + } + + @Override + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/Ipv4GuestSubnetNetworkMapVO.java b/engine/schema/src/main/java/org/apache/cloudstack/network/Ipv4GuestSubnetNetworkMapVO.java new file mode 100644 index 000000000000..cc726ba3d357 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/Ipv4GuestSubnetNetworkMapVO.java @@ -0,0 +1,143 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.network; + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "ip4_guest_subnet_network_map") +public class Ipv4GuestSubnetNetworkMapVO implements Ipv4GuestSubnetNetworkMap { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "parent_id") + private Long parentId; + + @Column(name = "subnet") + private String subnet; + + @Column(name = "vpc_id") + private Long vpcId; + + @Column(name = "network_id") + private Long networkId; + + @Column(name = "state") + private State state; + + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "allocated") + Date allocated; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name= GenericDao.REMOVED_COLUMN) + private Date removed; + + protected Ipv4GuestSubnetNetworkMapVO() { + uuid = UUID.randomUUID().toString(); + } + + protected Ipv4GuestSubnetNetworkMapVO(Long parentId, String subnet, Long networkId, Ipv4GuestSubnetNetworkMap.State state) { + this.parentId = parentId; + this.subnet = subnet; + this.networkId = networkId; + this.state = state; + uuid = UUID.randomUUID().toString(); + } + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public Long getParentId() { + return parentId; + } + + @Override + public String getSubnet() { + return subnet; + } + + @Override + public Long getVpcId() { + return vpcId; + } + + public void setVpcId(Long vpcId) { + this.vpcId = vpcId; + } + + @Override + public Long getNetworkId() { + return networkId; + } + + public void setNetworkId(Long networkId) { + this.networkId = networkId; + } + + @Override + public State getState() { + return state; + } + + public void setState(Ipv4GuestSubnetNetworkMap.State state) { + this.state = state; + } + + public void setAllocated(Date allocated) { + this.allocated = allocated; + } + + @Override + public Date getAllocated() { + return allocated; + } + + @Override + public Date getCreated() { + return created; + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDao.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDao.java new file mode 100644 index 000000000000..8ca4c2d86da7 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDao.java @@ -0,0 +1,40 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.network.dao; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.BgpPeerVO; + +import java.util.List; +import java.util.Map; + +public interface BgpPeerDao extends GenericDao { + List listNonRevokeByNetworkId(long networkId); + + List listNonRevokeByVpcId(long vpcId); + + BgpPeerVO findByZoneAndAsNumberAndAddress(long zoneId, Long asNumber, String ip4Address, String ip6Address); + + BgpPeerVO persist(BgpPeerVO bgpPeerVO, Map details); + + List listAvailableBgpPeerIdsForAccount(long zoneId, long domainId, long accountId, boolean useSystemBgpPeers); + + int removeByAccountId(long accountId); + int removeByDomainId(long domainId); +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDaoImpl.java new file mode 100644 index 000000000000..0f95f7c3cd58 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDaoImpl.java @@ -0,0 +1,193 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.network.dao; + +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +import com.cloud.utils.db.TransactionLegacy; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.BgpPeerDetailsVO; +import org.apache.cloudstack.network.BgpPeerNetworkMapVO; +import org.apache.cloudstack.network.BgpPeerVO; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Component +@DB +public class BgpPeerDaoImpl extends GenericDaoBase implements BgpPeerDao { + protected SearchBuilder NetworkIdSearch; + protected SearchBuilder VpcIdSearch; + protected SearchBuilder AllFieldsSearch; + + private static final String LIST_ALL_BGP_PEERS_IDS_FOR_ACCOUNT = "SELECT id FROM `cloud`.`bgp_peers` WHERE removed IS NULL AND data_center_id = ? " + + "AND ((domain_id IS NULL AND account_id IS NULL) " + + "OR (domain_id = ? AND account_id IS NULL) " + + "OR (domain_id = ? AND account_id = ?))"; + + private static final String LIST_DEDICATED_BGP_PEERS_IDS_FOR_ACCOUNT = "SELECT id FROM `cloud`.`bgp_peers` WHERE removed IS NULL AND data_center_id = ? " + + "AND ((domain_id = ? AND account_id IS NULL) " + + "OR (domain_id = ? AND account_id = ?))"; + + @Inject + BgpPeerNetworkMapDao bgpPeerNetworkMapDao; + @Inject + BgpPeerDetailsDao bgpPeerDetailsDao; + + @PostConstruct + public void init() { + final SearchBuilder networkSearchBuilder = bgpPeerNetworkMapDao.createSearchBuilder(); + networkSearchBuilder.and("networkId", networkSearchBuilder.entity().getNetworkId(), SearchCriteria.Op.EQ); + networkSearchBuilder.and("state", networkSearchBuilder.entity().getState(), SearchCriteria.Op.IN); + networkSearchBuilder.and("removed", networkSearchBuilder.entity().getRemoved(), SearchCriteria.Op.NULL); + NetworkIdSearch = createSearchBuilder(); + NetworkIdSearch.join("network", networkSearchBuilder, networkSearchBuilder.entity().getBgpPeerId(), + NetworkIdSearch.entity().getId(), JoinBuilder.JoinType.INNER); + NetworkIdSearch.done(); + + final SearchBuilder vpcSearchBuilder = bgpPeerNetworkMapDao.createSearchBuilder(); + vpcSearchBuilder.and("vpcId", vpcSearchBuilder.entity().getVpcId(), SearchCriteria.Op.EQ); + vpcSearchBuilder.and("state", vpcSearchBuilder.entity().getState(), SearchCriteria.Op.IN); + vpcSearchBuilder.and("removed", vpcSearchBuilder.entity().getRemoved(), SearchCriteria.Op.NULL); + VpcIdSearch = createSearchBuilder(); + VpcIdSearch.join("vpc", vpcSearchBuilder, vpcSearchBuilder.entity().getBgpPeerId(), + VpcIdSearch.entity().getId(), JoinBuilder.JoinType.INNER); + VpcIdSearch.done(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("zoneId", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("domainId", AllFieldsSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("asNumber", AllFieldsSearch.entity().getAsNumber(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("ip4Address", AllFieldsSearch.entity().getIp4Address(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("ip6Address", AllFieldsSearch.entity().getIp6Address(), SearchCriteria.Op.EQ); + AllFieldsSearch.done(); + } + + @Override + public List listNonRevokeByNetworkId(long networkId) { + SearchCriteria sc = NetworkIdSearch.create(); + sc.setJoinParameters("network", "networkId", networkId); + sc.setJoinParameters("network", "state", BgpPeer.State.Active, BgpPeer.State.Add); + return listBy(sc); + } + + @Override + public List listNonRevokeByVpcId(long vpcId) { + SearchCriteria sc = VpcIdSearch.create(); + sc.setJoinParameters("vpc", "vpcId", vpcId); + sc.setJoinParameters("vpc", "state", BgpPeer.State.Active, BgpPeer.State.Add); + return listBy(sc); + } + + @Override + public BgpPeerVO findByZoneAndAsNumberAndAddress(long zoneId, Long asNumber, String ip4Address, String ip6Address) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters( "zoneId", zoneId); + sc.setParameters( "asNumber", asNumber); + if (ip4Address != null) { + sc.setParameters( "ip4Address", ip4Address); + } + if (ip6Address != null) { + sc.setParameters( "ip6Address", ip6Address); + } + return findOneBy(sc); + } + + @Override + public BgpPeerVO persist(BgpPeerVO bgpPeerVO, Map details) { + TransactionLegacy txn = TransactionLegacy.currentTxn(); + txn.start(); + BgpPeerVO vo = super.persist(bgpPeerVO); + + // persist the details + if (details != null && !details.isEmpty()) { + for (BgpPeer.Detail detail : details.keySet()) { + bgpPeerDetailsDao.persist(new BgpPeerDetailsVO(bgpPeerVO.getId(), detail, details.get(detail), true)); + } + } + + txn.commit(); + return vo; + } + + @Override + public List listAvailableBgpPeerIdsForAccount(long zoneId, long domainId, long accountId, boolean useSystemBgpPeers) { + if (useSystemBgpPeers) { + return listBgpPeerIdsForAccount(zoneId, domainId, accountId, false); + } else { + List dedicatedBgpPeerIds = listBgpPeerIdsForAccount(zoneId, domainId, accountId, true); + if (CollectionUtils.isNotEmpty(dedicatedBgpPeerIds)) { + return dedicatedBgpPeerIds; + } + return listBgpPeerIdsForAccount(zoneId, domainId, accountId, false); + } + } + + private List listBgpPeerIdsForAccount(long zoneId, long domainId, long accountId, boolean isDedicated) { + TransactionLegacy txn = TransactionLegacy.currentTxn(); + PreparedStatement pstmt = null; + List result = new ArrayList(); + + StringBuilder sql = isDedicated ? new StringBuilder(LIST_DEDICATED_BGP_PEERS_IDS_FOR_ACCOUNT): new StringBuilder(LIST_ALL_BGP_PEERS_IDS_FOR_ACCOUNT); + + try { + pstmt = txn.prepareAutoCloseStatement(sql.toString()); + pstmt.setLong(1, zoneId); + pstmt.setLong(2, domainId); + pstmt.setLong(3, domainId); + pstmt.setLong(4, accountId); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + result.add(rs.getLong(1)); + } + return result; + } catch (SQLException e) { + throw new CloudRuntimeException("DB Exception on: " + sql, e); + } catch (Throwable e) { + throw new CloudRuntimeException("Caught: " + sql, e); + } + } + + @Override + public int removeByAccountId(long accountId) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); + return remove(sc); + } + + @Override + public int removeByDomainId(long domainId) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); + return remove(sc); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDetailsDao.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDetailsDao.java new file mode 100644 index 000000000000..377bc45ebfe2 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDetailsDao.java @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network.dao; + +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.BgpPeerDetailsVO; +import org.apache.cloudstack.resourcedetail.ResourceDetailsDao; + +import java.util.List; +import java.util.Map; + +public interface BgpPeerDetailsDao extends ResourceDetailsDao { + Map getBgpPeerDetails(long bgpPeerId); + String getDetail(long offeringId, BgpPeer.Detail detailName); + List findDomainIds(final long resourceId); + List findZoneIds(final long resourceId); + + int removeByBgpPeerId(long bgpPeerId); +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDetailsDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDetailsDaoImpl.java new file mode 100644 index 000000000000..a974cf5e2769 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerDetailsDaoImpl.java @@ -0,0 +1,123 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network.dao; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.api.ApiConstants; + +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.BgpPeerDetailsVO; +import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase; +import org.apache.commons.lang3.EnumUtils; + +public class BgpPeerDetailsDaoImpl extends ResourceDetailsDaoBase implements BgpPeerDetailsDao { + protected final SearchBuilder DetailSearch; + private final GenericSearchBuilder ValueSearch; + + public BgpPeerDetailsDaoImpl() { + + DetailSearch = createSearchBuilder(); + DetailSearch.and("resourceId", DetailSearch.entity().getResourceId(), SearchCriteria.Op.EQ); + DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ); + DetailSearch.and("value", DetailSearch.entity().getValue(), SearchCriteria.Op.EQ); + DetailSearch.and("display", DetailSearch.entity().isDisplay(), SearchCriteria.Op.EQ); + DetailSearch.done(); + + ValueSearch = createSearchBuilder(String.class); + ValueSearch.select(null, Func.DISTINCT, ValueSearch.entity().getValue()); + ValueSearch.and("resourceId", ValueSearch.entity().getResourceId(), SearchCriteria.Op.EQ); + ValueSearch.and("name", ValueSearch.entity().getName(), Op.EQ); + ValueSearch.and("display", ValueSearch.entity().isDisplay(), SearchCriteria.Op.EQ); + ValueSearch.done(); + } + + @Override + public Map getBgpPeerDetails(long bgpPeerId) { + SearchCriteria sc = DetailSearch.create(); + sc.setParameters("resourceId", bgpPeerId); + sc.setParameters("display", true); + + List results = search(sc, null); + if (results.size() == 0) { + return null; + } + Map details = new HashMap<>(results.size()); + for (BgpPeerDetailsVO result : results) { + details.put(result.getDetailName(), result.getValue()); + } + + return details; + } + + @Override + public String getDetail(long bgpPeerId, BgpPeer.Detail detailName) { + SearchCriteria sc = ValueSearch.create(); + sc.setParameters("name", detailName); + sc.setParameters("resourceId", bgpPeerId); + List results = customSearch(sc, null); + if (results.isEmpty()) { + return null; + } else { + return results.get(0); + } + } + + @Override + public void addDetail(long resourceId, String key, String value, boolean display) { + persist(new BgpPeerDetailsVO(resourceId, EnumUtils.getEnumIgnoreCase(BgpPeer.Detail.class, key), value, display)); + } + + @Override + public List findDomainIds(long resourceId) { + final List domainIds = new ArrayList<>(); + for (final BgpPeerDetailsVO detail: findDetails(resourceId, ApiConstants.DOMAIN_ID)) { + final Long domainId = Long.valueOf(detail.getValue()); + if (domainId > 0) { + domainIds.add(domainId); + } + } + return domainIds; + } + + @Override + public List findZoneIds(long resourceId) { + final List zoneIds = new ArrayList<>(); + for (final BgpPeerDetailsVO detail: findDetails(resourceId, ApiConstants.ZONE_ID)) { + final Long zoneId = Long.valueOf(detail.getValue()); + if (zoneId > 0) { + zoneIds.add(zoneId); + } + } + return zoneIds; + } + + @Override + public int removeByBgpPeerId(long bgpPeerId) { + SearchCriteria sc = DetailSearch.create(); + sc.setParameters("resourceId", bgpPeerId); + return remove(sc); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerNetworkMapDao.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerNetworkMapDao.java new file mode 100644 index 000000000000..8d8ec8c998a4 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerNetworkMapDao.java @@ -0,0 +1,48 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network.dao; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.network.BgpPeerNetworkMapVO; + +import java.util.List; + + +public interface BgpPeerNetworkMapDao extends GenericDao { + + void persistForNetwork(long networkId, List bgpPeerIds); + + List listByBgpPeerId(long bgpPeerId); + + List listByNetworkId(long networkId); + + List listUsedNetworksByOtherDomains(long bgpPeerId, Long domainId); + + List listUsedNetworksByOtherAccounts(long bgpPeerId, Long accountId); + + int removeByNetworkId(long networkId); + + void persistForVpc(long vpcId, List bgpPeerIds); + + List listByVpcId(long vpcId); + + List listUsedVpcsByOtherDomains(long bgpPeerId, Long domainId); + + List listUsedVpcsByOtherAccounts(long bgpPeerId, Long accountId); + + int removeByVpcId(long vpcId); +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerNetworkMapDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerNetworkMapDaoImpl.java new file mode 100644 index 000000000000..a5e5f47684a6 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/BgpPeerNetworkMapDaoImpl.java @@ -0,0 +1,185 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.network.dao; + +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.utils.db.JoinBuilder; +import org.apache.cloudstack.network.BgpPeer; +import org.apache.cloudstack.network.BgpPeerNetworkMapVO; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.TransactionLegacy; + +@Component +public class BgpPeerNetworkMapDaoImpl extends GenericDaoBase implements BgpPeerNetworkMapDao { + + protected SearchBuilder BgpPeerNetworkVpcSearch; + protected SearchBuilder NetworkDomainAccountNeqSearch; + protected SearchBuilder VpcDomainAccountNeqSearch; + + @Inject + NetworkDao networkDao; + @Inject + VpcDao vpcDao; + + public BgpPeerNetworkMapDaoImpl() { + } + + @PostConstruct + public void init() { + BgpPeerNetworkVpcSearch = createSearchBuilder(); + BgpPeerNetworkVpcSearch.and("bgpPeerId", BgpPeerNetworkVpcSearch.entity().getBgpPeerId(), SearchCriteria.Op.EQ); + BgpPeerNetworkVpcSearch.and("networkId", BgpPeerNetworkVpcSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + BgpPeerNetworkVpcSearch.and("vpcId", BgpPeerNetworkVpcSearch.entity().getVpcId(), SearchCriteria.Op.EQ); + BgpPeerNetworkVpcSearch.done(); + + final SearchBuilder networkSearchBuilder = networkDao.createSearchBuilder(); + networkSearchBuilder.and("domainId", networkSearchBuilder.entity().getDomainId(), SearchCriteria.Op.NEQ); + networkSearchBuilder.and("accountId", networkSearchBuilder.entity().getAccountId(), SearchCriteria.Op.NEQ); + NetworkDomainAccountNeqSearch = createSearchBuilder(); + NetworkDomainAccountNeqSearch.and("bgpPeerId", NetworkDomainAccountNeqSearch.entity().getBgpPeerId(), SearchCriteria.Op.EQ); + NetworkDomainAccountNeqSearch.join("network", networkSearchBuilder, networkSearchBuilder.entity().getId(), + NetworkDomainAccountNeqSearch.entity().getNetworkId(), JoinBuilder.JoinType.INNER); + NetworkDomainAccountNeqSearch.done(); + + final SearchBuilder vpcSearchBuilder = vpcDao.createSearchBuilder(); + vpcSearchBuilder.and("domainId", vpcSearchBuilder.entity().getDomainId(), SearchCriteria.Op.NEQ); + vpcSearchBuilder.and("accountId", vpcSearchBuilder.entity().getAccountId(), SearchCriteria.Op.NEQ); + VpcDomainAccountNeqSearch = createSearchBuilder(); + VpcDomainAccountNeqSearch.and("bgpPeerId", VpcDomainAccountNeqSearch.entity().getBgpPeerId(), SearchCriteria.Op.EQ); + VpcDomainAccountNeqSearch.join("vpc", vpcSearchBuilder, vpcSearchBuilder.entity().getId(), + VpcDomainAccountNeqSearch.entity().getVpcId(), JoinBuilder.JoinType.INNER); + VpcDomainAccountNeqSearch.done(); + } + + @Override + public void persistForNetwork(long networkId, List bgpPeerIds) { + TransactionLegacy txn = TransactionLegacy.currentTxn(); + + txn.start(); + SearchCriteria sc = BgpPeerNetworkVpcSearch.create(); + sc.setParameters("networkId", networkId); + expunge(sc); + + for (Long bgpPeerId : bgpPeerIds) { + BgpPeerNetworkMapVO vo = new BgpPeerNetworkMapVO(bgpPeerId, networkId, null, BgpPeer.State.Active); + persist(vo); + } + + txn.commit(); + } + + @Override + public List listByBgpPeerId(long bgpPeerId) { + SearchCriteria sc = BgpPeerNetworkVpcSearch.create(); + sc.setParameters("bgpPeerId", bgpPeerId); + + return search(sc, null); + } + + @Override + public List listByNetworkId(long networkId) { + SearchCriteria sc = BgpPeerNetworkVpcSearch.create(); + sc.setParameters("networkId", networkId); + + return search(sc, null); + } + + @Override + public List listUsedNetworksByOtherDomains(long bgpPeerId, Long domainId) { + SearchCriteria sc = NetworkDomainAccountNeqSearch.create(); + sc.setParameters("bgpPeerId", bgpPeerId); + sc.setJoinParameters("network", "domainId", domainId); + return listBy(sc); + } + + @Override + public List listUsedNetworksByOtherAccounts(long bgpPeerId, Long accountId) { + SearchCriteria sc = NetworkDomainAccountNeqSearch.create(); + sc.setParameters("bgpPeerId", bgpPeerId); + sc.setJoinParameters("network", "accountId", accountId); + return listBy(sc); + } + + @Override + public int removeByNetworkId(long networkId) { + SearchCriteria sc = BgpPeerNetworkVpcSearch.create(); + sc.setParameters("networkId", networkId); + + return remove(sc); + } + + @Override + public void persistForVpc(long vpcId, List bgpPeerIds) { + TransactionLegacy txn = TransactionLegacy.currentTxn(); + + txn.start(); + SearchCriteria sc = BgpPeerNetworkVpcSearch.create(); + sc.setParameters("vpcId", vpcId); + expunge(sc); + + for (Long bgpPeerId : bgpPeerIds) { + BgpPeerNetworkMapVO vo = new BgpPeerNetworkMapVO(bgpPeerId, null, vpcId, BgpPeer.State.Active); + persist(vo); + } + + txn.commit(); + } + + @Override + public List listByVpcId(long vpcId) { + SearchCriteria sc = BgpPeerNetworkVpcSearch.create(); + sc.setParameters("vpcId", vpcId); + + return search(sc, null); + } + + @Override + public List listUsedVpcsByOtherDomains(long bgpPeerId, Long domainId) { + SearchCriteria sc = VpcDomainAccountNeqSearch.create(); + sc.setParameters("bgpPeerId", bgpPeerId); + sc.setJoinParameters("vpc", "domainId", domainId); + return listBy(sc); + } + + @Override + public List listUsedVpcsByOtherAccounts(long bgpPeerId, Long accountId) { + SearchCriteria sc = VpcDomainAccountNeqSearch.create(); + sc.setParameters("bgpPeerId", bgpPeerId); + sc.setJoinParameters("vpc", "accountId", accountId); + return listBy(sc); + } + + @Override + public int removeByVpcId(long vpcId) { + SearchCriteria sc = BgpPeerNetworkVpcSearch.create(); + sc.setParameters("vpcId", vpcId); + + return remove(sc); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/Ipv4GuestSubnetNetworkMapDao.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/Ipv4GuestSubnetNetworkMapDao.java new file mode 100644 index 000000000000..c3f860009db9 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/Ipv4GuestSubnetNetworkMapDao.java @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.network.dao; + +import java.util.List; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMapVO; + +public interface Ipv4GuestSubnetNetworkMapDao extends GenericDao { + List listByParent(long parentId); + List listUsedByParent(long parentId); + List listUsedByOtherDomains(long parentId, Long domainId); + List listUsedByOtherAccounts(long parentId, Long accountId); + Ipv4GuestSubnetNetworkMapVO findFirstAvailable(long parentId, long cidrSize); + Ipv4GuestSubnetNetworkMapVO findByNetworkId(long networkId); + Ipv4GuestSubnetNetworkMapVO findByVpcId(long vpcId); + Ipv4GuestSubnetNetworkMapVO findBySubnet(String subnet); + List findSubnetsInStates(Ipv4GuestSubnetNetworkMap.State... states); + void deleteByParentId(long parentId); + List listAllNoParent(); +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/Ipv4GuestSubnetNetworkMapDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/Ipv4GuestSubnetNetworkMapDaoImpl.java new file mode 100644 index 000000000000..95e53448907e --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/Ipv4GuestSubnetNetworkMapDaoImpl.java @@ -0,0 +1,170 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.network.dao; + +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; +import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMapVO; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.stereotype.Component; + +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Component +@DB +public class Ipv4GuestSubnetNetworkMapDaoImpl extends GenericDaoBase implements Ipv4GuestSubnetNetworkMapDao { + + protected SearchBuilder ParentStateSearch; + protected SearchBuilder ParentIdSearch; + protected SearchBuilder NoParentSearch; + protected SearchBuilder NetworkIdSearch; + protected SearchBuilder SubnetSearch; + protected SearchBuilder StatesSearch; + protected SearchBuilder DomainAccountNeqSearch; + + @Inject + NetworkDao networkDao; + + @PostConstruct + public void init() { + ParentStateSearch = createSearchBuilder(); + ParentStateSearch.and("parentId", ParentStateSearch.entity().getParentId(), SearchCriteria.Op.EQ); + ParentStateSearch.and("state", ParentStateSearch.entity().getState(), SearchCriteria.Op.IN); + ParentStateSearch.and("subnet", ParentStateSearch.entity().getSubnet(), SearchCriteria.Op.LIKE); + ParentStateSearch.done(); + ParentIdSearch = createSearchBuilder(); + ParentIdSearch.and("parentId", ParentIdSearch.entity().getParentId(), SearchCriteria.Op.EQ); + ParentIdSearch.done(); + NoParentSearch = createSearchBuilder(); + NoParentSearch.and("parentId", NoParentSearch.entity().getParentId(), SearchCriteria.Op.NULL); + NoParentSearch.done(); + NetworkIdSearch = createSearchBuilder(); + NetworkIdSearch.and("networkId", NetworkIdSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + NetworkIdSearch.and("vpcId", NetworkIdSearch.entity().getVpcId(), SearchCriteria.Op.EQ); + NetworkIdSearch.done(); + SubnetSearch = createSearchBuilder(); + SubnetSearch.and("subnet", SubnetSearch.entity().getSubnet(), SearchCriteria.Op.EQ); + SubnetSearch.done(); + StatesSearch = createSearchBuilder(); + StatesSearch.and("state", StatesSearch.entity().getState(), SearchCriteria.Op.IN); + StatesSearch.done(); + + final SearchBuilder networkSearchBuilder = networkDao.createSearchBuilder(); + networkSearchBuilder.and("domainId", networkSearchBuilder.entity().getDomainId(), SearchCriteria.Op.NEQ); + networkSearchBuilder.and("accountId", networkSearchBuilder.entity().getAccountId(), SearchCriteria.Op.NEQ); + DomainAccountNeqSearch = createSearchBuilder(); + DomainAccountNeqSearch.and("parentId", DomainAccountNeqSearch.entity().getParentId(), SearchCriteria.Op.EQ); + DomainAccountNeqSearch.join("network", networkSearchBuilder, networkSearchBuilder.entity().getId(), + DomainAccountNeqSearch.entity().getNetworkId(), JoinBuilder.JoinType.INNER); + DomainAccountNeqSearch.done(); + } + + @Override + public List listByParent(long parentId) { + SearchCriteria sc = ParentIdSearch.create(); + sc.setParameters("parentId", parentId); + return listBy(sc, null); + } + + @Override + public List listUsedByParent(long parentId) { + SearchCriteria sc = ParentStateSearch.create(); + sc.setParameters("parentId", parentId); + sc.setParameters("state", (Object[]) new Ipv4GuestSubnetNetworkMap.State[]{Ipv4GuestSubnetNetworkMap.State.Allocated, Ipv4GuestSubnetNetworkMap.State.Allocating}); + return listBy(sc, null); + } + + @Override + public List listUsedByOtherDomains(long parentId, Long domainId) { + SearchCriteria sc = DomainAccountNeqSearch.create(); + sc.setParameters("parentId", parentId); + sc.setJoinParameters("network", "domainId", domainId); + return listBy(sc); + } + + @Override + public List listUsedByOtherAccounts(long parentId, Long accountId) { + SearchCriteria sc = DomainAccountNeqSearch.create(); + sc.setParameters("parentId", parentId); + sc.setJoinParameters("network", "accountId", accountId); + return listBy(sc); + } + + @Override + public Ipv4GuestSubnetNetworkMapVO findFirstAvailable(long parentId, long cidrSize) { + SearchCriteria sc = ParentStateSearch.create(); + sc.setParameters("parentId", parentId); + sc.setParameters("subnet", "%/" + cidrSize); + sc.setParameters("state", (Object[]) new Ipv4GuestSubnetNetworkMap.State[]{Ipv4GuestSubnetNetworkMap.State.Free}); + Filter searchFilter = new Filter(Ipv4GuestSubnetNetworkMapVO.class, "id", true, null, 1L); + List list = listBy(sc, searchFilter); + return CollectionUtils.isNotEmpty(list) ? list.get(0) : null; + } + + @Override + public Ipv4GuestSubnetNetworkMapVO findByNetworkId(long networkId) { + SearchCriteria sc = NetworkIdSearch.create(); + sc.setParameters("networkId", networkId); + return findOneBy(sc); + } + + @Override + public Ipv4GuestSubnetNetworkMapVO findByVpcId(long vpcId) { + SearchCriteria sc = NetworkIdSearch.create(); + sc.setParameters("vpcId", vpcId); + return findOneBy(sc); + } + + @Override + public Ipv4GuestSubnetNetworkMapVO findBySubnet(String subnet) { + SearchCriteria sc = SubnetSearch.create(); + sc.setParameters("subnet", subnet); + return findOneBy(sc); + } + + @Override + public List findSubnetsInStates(Ipv4GuestSubnetNetworkMap.State... states) { + SearchCriteria sc = StatesSearch.create(); + sc.setParameters("state", (Object[])states); + return listBy(sc); + } + + @Override + public void deleteByParentId(long parentId) { + SearchCriteria sc = ParentIdSearch.create(); + sc.setParameters("parentId", parentId); + remove(sc); + } + + @Override + public List listAllNoParent() { + SearchCriteria sc = NoParentSearch.create(); + return listBy(sc, null); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java index ffc62b15dc2e..c4214e8dfce9 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.network.NetworkPermissionVO; @@ -31,7 +30,6 @@ @Component public class NetworkPermissionDaoImpl extends GenericDaoBase implements NetworkPermissionDao { - private static final Logger s_logger = Logger.getLogger(NetworkPermissionDaoImpl.class); private SearchBuilder NetworkAndAccountSearch; private SearchBuilder NetworkIdSearch; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java index af164326da70..375bb43e40eb 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java @@ -31,7 +31,6 @@ import com.cloud.utils.db.UpdateBuilder; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -41,7 +40,6 @@ @DB @Component public class OutOfBandManagementDaoImpl extends GenericDaoBase implements OutOfBandManagementDao { - private static final Logger LOG = Logger.getLogger(OutOfBandManagementDaoImpl.class); private SearchBuilder HostSearch; private SearchBuilder ManagementServerSearch; @@ -109,7 +107,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { pstmt.executeUpdate(); } catch (SQLException e) { txn.rollback(); - LOG.warn("Failed to expire ownership for out-of-band management server id: " + resource); + logger.warn("Failed to expire ownership for out-of-band management server id: " + resource); } } }); @@ -119,8 +117,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) { public void expireServerOwnership(long serverId) { final String resetOwnerSql = "UPDATE oobm set mgmt_server_id=NULL, power_state=NULL where mgmt_server_id=?"; executeExpireOwnershipSql(resetOwnerSql, serverId); - if (LOG.isDebugEnabled()) { - LOG.debug("Expired out-of-band management ownership for hosts owned by management server id:" + serverId); + if (logger.isDebugEnabled()) { + logger.debug("Expired out-of-band management ownership for hosts owned by management server id:" + serverId); } } @@ -128,8 +126,8 @@ public void expireServerOwnership(long serverId) { public boolean updateState(OutOfBandManagement.PowerState oldStatus, OutOfBandManagement.PowerState.Event event, OutOfBandManagement.PowerState newStatus, OutOfBandManagement vo, Object data) { OutOfBandManagementVO oobmHost = (OutOfBandManagementVO) vo; if (oobmHost == null) { - if (LOG.isTraceEnabled()) { - LOG.trace("Invalid out-of-band management host view object provided"); + if (logger.isTraceEnabled()) { + logger.trace("Invalid out-of-band management host view object provided"); } return false; } @@ -156,8 +154,8 @@ public boolean updateState(OutOfBandManagement.PowerState oldStatus, OutOfBandMa ub.set(oobmHost, MsIdAttr, newManagementServerId); int result = update(ub, sc, null); - if (LOG.isDebugEnabled() && result <= 0) { - LOG.debug(String.format("Failed to update out-of-band management power state from:%s to:%s due to event:%s for the host id:%d", oldStatus, newStatus, event, oobmHost.getHostId())); + if (logger.isDebugEnabled() && result <= 0) { + logger.debug(String.format("Failed to update out-of-band management power state from:%s to:%s due to event:%s for the host id:%d", oldStatus, newStatus, event, oobmHost.getHostId())); } return result > 0; } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/region/dao/RegionDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/region/dao/RegionDaoImpl.java index e2ad5d9ed239..1e53c925e082 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/region/dao/RegionDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/region/dao/RegionDaoImpl.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.region.dao; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.region.RegionVO; @@ -28,7 +27,6 @@ @Component public class RegionDaoImpl extends GenericDaoBase implements RegionDao { - private static final Logger s_logger = Logger.getLogger(RegionDaoImpl.class); protected SearchBuilder NameSearch; protected SearchBuilder AllFieldsSearch; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java index e5636f0bfc99..df0ede6821ad 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java @@ -18,10 +18,6 @@ // package org.apache.cloudstack.reservation; -import com.cloud.configuration.Resource; -import org.apache.cloudstack.user.ResourceReservation; -import com.cloud.utils.exception.CloudRuntimeException; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -29,6 +25,15 @@ import javax.persistence.Id; import javax.persistence.Table; +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.user.ResourceReservation; + +import com.cloud.configuration.Resource; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.utils.identity.ManagementServerNode; + +import java.util.Date; + @Entity @Table(name = "resource_reservation") public class ReservationVO implements ResourceReservation { @@ -47,20 +52,38 @@ public class ReservationVO implements ResourceReservation { @Column(name = "resource_type", nullable = false) Resource.ResourceType resourceType; + @Column(name = "tag") + String tag; + + @Column(name = "resource_id") + Long resourceId; + @Column(name = "amount") long amount; - protected ReservationVO() - {} + @Column(name = "mgmt_server_id") + Long managementServerId; - public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, Long delta) { - if (delta == null || delta <= 0) { - throw new CloudRuntimeException("resource reservations can not be made for no resources"); + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + protected ReservationVO() { + } + + public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, String tag, Long delta) { + if (delta == null) { + throw new CloudRuntimeException("resource reservations can not be made for null resources"); } this.accountId = accountId; this.domainId = domainId; this.resourceType = resourceType; + this.tag = tag; this.amount = delta; + this.managementServerId = ManagementServerNode.getManagementServerId(); + } + + public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, Long delta) { + this(accountId, domainId, resourceType, null, delta); } @Override @@ -83,8 +106,35 @@ public Resource.ResourceType getResourceType() { return resourceType; } + @Override + public String getTag() { + return tag; + } + @Override public Long getReservedAmount() { return amount; } + + @Override + public Long getResourceId() { + return resourceId; + } + + public void setResourceId(long resourceId) { + this.resourceId = resourceId; + } + + @Override + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public Long getManagementServerId() { + return managementServerId; + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java index eead91c7b8e9..d6d494f61f92 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java @@ -18,11 +18,22 @@ // package org.apache.cloudstack.reservation.dao; -import com.cloud.configuration.Resource; import org.apache.cloudstack.reservation.ReservationVO; + +import com.cloud.configuration.Resource; import com.cloud.utils.db.GenericDao; +import java.util.Date; +import java.util.List; + public interface ReservationDao extends GenericDao { - long getAccountReservation(Long account, Resource.ResourceType resourceType); - long getDomainReservation(Long domain, Resource.ResourceType resourceType); + long getAccountReservation(Long account, Resource.ResourceType resourceType, String tag); + long getDomainReservation(Long domain, Resource.ResourceType resourceType, String tag); + void setResourceId(Resource.ResourceType type, Long resourceId); + List getReservationsForAccount(long accountId, Resource.ResourceType type, String tag); + void removeByIds(List reservationIds); + + int removeByMsId(long managementServerId); + + int removeStaleReservations(Long accountId, Resource.ResourceType resourceType, String tag, Date createdBefore); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java index 6703de0b13c4..3b17f4e4294e 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java @@ -18,39 +18,103 @@ // package org.apache.cloudstack.reservation.dao; +import java.util.Date; +import java.util.List; + +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.reservation.ReservationVO; + import com.cloud.configuration.Resource; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.cloudstack.reservation.ReservationVO; - -import java.util.List; +import org.apache.cloudstack.user.ResourceReservation; +import org.apache.commons.collections.CollectionUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ReservationDaoImpl extends GenericDaoBase implements ReservationDao { + protected transient Logger logger = LogManager.getLogger(getClass()); private static final String RESOURCE_TYPE = "resourceType"; + private static final String RESOURCE_TAG = "resourceTag"; + private static final String RESOURCE_ID = "resourceId"; private static final String ACCOUNT_ID = "accountId"; private static final String DOMAIN_ID = "domainId"; + private static final String IDS = "ids"; + private static final String MS_ID = "managementServerId"; + private static final String CREATED = "created"; + private final SearchBuilder listResourceByAccountAndTypeSearch; private final SearchBuilder listAccountAndTypeSearch; + private final SearchBuilder listAccountAndTypeAndNoTagSearch; private final SearchBuilder listDomainAndTypeSearch; + private final SearchBuilder listDomainAndTypeAndNoTagSearch; + private final SearchBuilder listResourceByAccountAndTypeAndNoTagSearch; + private final SearchBuilder listIdsSearch; + private final SearchBuilder listMsIdSearch; public ReservationDaoImpl() { + + listResourceByAccountAndTypeSearch = createSearchBuilder(); + listResourceByAccountAndTypeSearch.and(ACCOUNT_ID, listResourceByAccountAndTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeSearch.and(RESOURCE_TYPE, listResourceByAccountAndTypeSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeSearch.and(RESOURCE_ID, listResourceByAccountAndTypeSearch.entity().getResourceId(), SearchCriteria.Op.NNULL); + listResourceByAccountAndTypeSearch.and(RESOURCE_TAG, listResourceByAccountAndTypeSearch.entity().getTag(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeSearch.done(); + + listResourceByAccountAndTypeAndNoTagSearch = createSearchBuilder(); + listResourceByAccountAndTypeAndNoTagSearch.and(ACCOUNT_ID, listResourceByAccountAndTypeAndNoTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeAndNoTagSearch.and(RESOURCE_TYPE, listResourceByAccountAndTypeAndNoTagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeAndNoTagSearch.and(RESOURCE_ID, listResourceByAccountAndTypeAndNoTagSearch.entity().getResourceId(), SearchCriteria.Op.NNULL); + listResourceByAccountAndTypeAndNoTagSearch.and(RESOURCE_TAG, listResourceByAccountAndTypeAndNoTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + listResourceByAccountAndTypeAndNoTagSearch.done(); + listAccountAndTypeSearch = createSearchBuilder(); listAccountAndTypeSearch.and(ACCOUNT_ID, listAccountAndTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); listAccountAndTypeSearch.and(RESOURCE_TYPE, listAccountAndTypeSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listAccountAndTypeSearch.and(RESOURCE_TAG, listAccountAndTypeSearch.entity().getTag(), SearchCriteria.Op.EQ); + listAccountAndTypeSearch.and(CREATED, listAccountAndTypeSearch.entity().getCreated(), SearchCriteria.Op.LT); listAccountAndTypeSearch.done(); + listAccountAndTypeAndNoTagSearch = createSearchBuilder(); + listAccountAndTypeAndNoTagSearch.and(ACCOUNT_ID, listAccountAndTypeAndNoTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + listAccountAndTypeAndNoTagSearch.and(RESOURCE_TYPE, listAccountAndTypeAndNoTagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listAccountAndTypeAndNoTagSearch.and(RESOURCE_TAG, listAccountAndTypeAndNoTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + listAccountAndTypeAndNoTagSearch.and(CREATED, listAccountAndTypeAndNoTagSearch.entity().getCreated(), SearchCriteria.Op.LT); + listAccountAndTypeAndNoTagSearch.done(); + listDomainAndTypeSearch = createSearchBuilder(); listDomainAndTypeSearch.and(DOMAIN_ID, listDomainAndTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ); listDomainAndTypeSearch.and(RESOURCE_TYPE, listDomainAndTypeSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listDomainAndTypeSearch.and(RESOURCE_TAG, listDomainAndTypeSearch.entity().getTag(), SearchCriteria.Op.EQ); listDomainAndTypeSearch.done(); + + listDomainAndTypeAndNoTagSearch = createSearchBuilder(); + listDomainAndTypeAndNoTagSearch.and(DOMAIN_ID, listDomainAndTypeAndNoTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + listDomainAndTypeAndNoTagSearch.and(RESOURCE_TYPE, listDomainAndTypeAndNoTagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listDomainAndTypeAndNoTagSearch.and(RESOURCE_TAG, listDomainAndTypeAndNoTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + listDomainAndTypeAndNoTagSearch.done(); + + listIdsSearch = createSearchBuilder(); + listIdsSearch.and(IDS, listIdsSearch.entity().getId(), SearchCriteria.Op.IN); + listIdsSearch.done(); + + listMsIdSearch = createSearchBuilder(); + listMsIdSearch.and(MS_ID, listMsIdSearch.entity().getManagementServerId(), SearchCriteria.Op.EQ); + listMsIdSearch.done(); } @Override - public long getAccountReservation(Long accountId, Resource.ResourceType resourceType) { + public long getAccountReservation(Long accountId, Resource.ResourceType resourceType, String tag) { long total = 0; - SearchCriteria sc = listAccountAndTypeSearch.create(); + SearchCriteria sc; + if (tag == null) { + sc = listAccountAndTypeAndNoTagSearch.create(); + } else { + sc = listAccountAndTypeSearch.create(); + sc.setParameters(RESOURCE_TAG, tag); + } sc.setParameters(ACCOUNT_ID, accountId); sc.setParameters(RESOURCE_TYPE, resourceType); List reservations = listBy(sc); @@ -61,9 +125,15 @@ public long getAccountReservation(Long accountId, Resource.ResourceType resource } @Override - public long getDomainReservation(Long domainId, Resource.ResourceType resourceType) { + public long getDomainReservation(Long domainId, Resource.ResourceType resourceType, String tag) { long total = 0; - SearchCriteria sc = listDomainAndTypeSearch.create(); + SearchCriteria sc; + if (tag == null) { + sc = listDomainAndTypeAndNoTagSearch.create(); + } else { + sc = listDomainAndTypeSearch.create(); + sc.setParameters(RESOURCE_TAG, tag); + } sc.setParameters(DOMAIN_ID, domainId); sc.setParameters(RESOURCE_TYPE, resourceType); List reservations = listBy(sc); @@ -72,4 +142,70 @@ public long getDomainReservation(Long domainId, Resource.ResourceType resourceTy } return total; } + + @Override + public void setResourceId(Resource.ResourceType type, Long resourceId) { + Object obj = CallContext.current().getContextParameter(String.format("%s-%s", ResourceReservation.class.getSimpleName(), type.getName())); + if (obj instanceof List) { + try { + List reservationIds = (List)obj; + for (Long reservationId : reservationIds) { + ReservationVO reservation = findById(reservationId); + if (reservation != null) { + reservation.setResourceId(resourceId); + persist(reservation); + } + } + } catch (Exception e) { + logger.warn("Failed to persist reservation for resource type " + type.getName() + " for resource id " + resourceId, e); + } + } + } + + @Override + public List getReservationsForAccount(long accountId, Resource.ResourceType type, String tag) { + SearchCriteria sc; + if (tag == null) { + sc = listResourceByAccountAndTypeAndNoTagSearch.create(); + } else { + sc = listResourceByAccountAndTypeSearch.create(); + sc.setParameters(RESOURCE_TAG, tag); + } + sc.setParameters(ACCOUNT_ID, accountId); + sc.setParameters(RESOURCE_TYPE, type); + return listBy(sc); + } + + @Override + public void removeByIds(List reservationIds) { + if (CollectionUtils.isNotEmpty(reservationIds)) { + SearchCriteria sc = listIdsSearch.create(); + sc.setParameters(IDS, reservationIds.toArray()); + remove(sc); + } + } + + @Override + public int removeByMsId(long managementServerId) { + SearchCriteria sc = listMsIdSearch.create(); + sc.setParameters(MS_ID, managementServerId); + return remove(sc); + } + + @Override + public int removeStaleReservations(Long accountId, Resource.ResourceType resourceType, String tag, + Date createdBefore) { + SearchCriteria sc; + if (tag == null) { + sc = listAccountAndTypeAndNoTagSearch.create(); + } else { + sc = listAccountAndTypeSearch.create(); + sc.setParameters(RESOURCE_TAG, tag); + } + sc.setParameters(ACCOUNT_ID, accountId); + sc.setParameters(RESOURCE_TYPE, resourceType); + sc.setParameters(CREATED, createdBefore); + return remove(sc); + } + } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/FirewallRuleDetailVO.java b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/FirewallRuleDetailVO.java index 636d889fafe8..1149d0b13e77 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/FirewallRuleDetailVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/FirewallRuleDetailVO.java @@ -79,4 +79,8 @@ public long getResourceId() { public boolean isDisplay() { return display; } + + public void setValue(String value) { + this.value = value; + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/ResourceDetailsDao.java b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/ResourceDetailsDao.java index 5a173191be1f..8f3d264da981 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/ResourceDetailsDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/ResourceDetailsDao.java @@ -97,4 +97,6 @@ public interface ResourceDetailsDao extends GenericDao public void addDetail(long resourceId, String key, String value, boolean display); public List findResourceIdsByNameAndValueIn(String name, Object[] values); + + public long batchExpungeForResources(List ids, Long batchSize); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java index 37ebfebf5ddd..4205a7823e44 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/ResourceDetailsDaoBase.java @@ -21,13 +21,14 @@ import java.util.Map; import org.apache.cloudstack.api.ResourceDetail; +import org.apache.commons.collections.CollectionUtils; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.TransactionLegacy; public abstract class ResourceDetailsDaoBase extends GenericDaoBase implements ResourceDetailsDao { private SearchBuilder AllFieldsSearch; @@ -201,4 +202,17 @@ public List findResourceIdsByNameAndValueIn(String name, Object[] values) return customSearch(sc, null); } + + @Override + public long batchExpungeForResources(final List ids, final Long batchSize) { + if (CollectionUtils.isEmpty(ids)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("ids", sb.entity().getResourceId(), Op.IN); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("ids", ids.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/UserDetailVO.java b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/UserDetailVO.java index 1b430e806e29..d0cfcc3d4396 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/UserDetailVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/UserDetailVO.java @@ -46,6 +46,8 @@ public class UserDetailVO implements ResourceDetail { private boolean display = true; public static final String Setup2FADetail = "2FASetupStatus"; + public static final String PasswordResetToken = "PasswordResetToken"; + public static final String PasswordResetTokenExpiryDate = "PasswordResetTokenExpiryDate"; public UserDetailVO() { } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailsDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailsDaoImpl.java index 8e5ce770f450..148304906009 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailsDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDetailsDaoImpl.java @@ -20,6 +20,11 @@ import java.util.List; import java.util.Map; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.ConfigKey.Scope; +import org.apache.cloudstack.framework.config.ScopedConfigStorage; +import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase; import org.springframework.stereotype.Component; import com.cloud.utils.crypt.DBEncryptionUtil; @@ -29,12 +34,6 @@ import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.TransactionLegacy; -import org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.cloudstack.framework.config.ConfigKey.Scope; -import org.apache.cloudstack.framework.config.ScopedConfigStorage; -import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase; - @Component public class ImageStoreDetailsDaoImpl extends ResourceDetailsDaoBase implements ImageStoreDetailsDao, ScopedConfigStorage { @@ -106,8 +105,8 @@ public ImageStoreDetailVO findDetail(long storeId, String name) { } @Override - public String getConfigValue(long id, ConfigKey key) { - ImageStoreDetailVO vo = findDetail(id, key.key()); + public String getConfigValue(long id, String key) { + ImageStoreDetailVO vo = findDetail(id, key); return vo == null ? null : vo.getValue(); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java index 2fce0628554c..f0c235e842c1 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java @@ -143,7 +143,7 @@ public interface PrimaryDataStoreDao extends GenericDao { Integer countAll(); - List findPoolsByStorageType(String storageType); + List findPoolsByStorageType(Storage.StoragePoolType storageType); StoragePoolVO findPoolByZoneAndPath(long zoneId, String datastorePath); diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java index 9b03bfe29a7a..1658fe0a537e 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -676,7 +676,7 @@ public List findPoolsInClusters(List clusterIds, String key } @Override - public List findPoolsByStorageType(String storageType) { + public List findPoolsByStorageType(Storage.StoragePoolType storageType) { SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("poolType", storageType); return listBy(sc); @@ -755,7 +755,7 @@ private SearchCriteria createStoragePoolSearchCriteria(Long stora if (keyword != null) { SearchCriteria ssc = createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("poolType", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("poolType", SearchCriteria.Op.LIKE, new Storage.StoragePoolType("%" + keyword + "%")); sc.addAnd("name", SearchCriteria.Op.SC, ssc); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java index 344ff8b2a699..4cd29b465eeb 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java @@ -106,4 +106,6 @@ public interface SnapshotDataStoreDao extends GenericDao snapshotIds, Long batchSize); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java index 98cb6ca5b42d..5bf67eb38819 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.hypervisor.Hypervisor; @@ -50,7 +49,6 @@ @Component public class SnapshotDataStoreDaoImpl extends GenericDaoBase implements SnapshotDataStoreDao { - private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreDaoImpl.class); private static final String STORE_ID = "store_id"; private static final String STORE_ROLE = "store_role"; private static final String STATE = "state"; @@ -188,7 +186,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat message = String.format("Unable to update objectIndatastore: id=%s, as there is no such object exists in the database anymore", dataObj.getId()); } - s_logger.debug(message); + logger.debug(message); return false; } @@ -277,7 +275,7 @@ protected SnapshotDataStoreVO findOldestOrLatestSnapshotForVolume(long volumeId, } } } catch (SQLException e) { - s_logger.warn(String.format("Failed to find %s snapshot for volume [%s] in %s store due to [%s].", oldest ? "oldest" : "latest", volumeId, role, e.getMessage()), e); + logger.warn(String.format("Failed to find %s snapshot for volume [%s] in %s store due to [%s].", oldest ? "oldest" : "latest", volumeId, role, e.getMessage()), e); } return null; } @@ -286,7 +284,7 @@ protected SnapshotDataStoreVO findOldestOrLatestSnapshotForVolume(long volumeId, @DB public SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, Long volumeId) { if (!isSnapshotChainingRequired(volumeId)) { - s_logger.trace(String.format("Snapshot chaining is not required for snapshots of volume [%s]. Returning null as parent.", volumeId)); + logger.trace(String.format("Snapshot chaining is not required for snapshots of volume [%s]. Returning null as parent.", volumeId)); return null; } @@ -378,21 +376,21 @@ public void duplicateCacheRecordsOnRegionStore(long storeId) { List snapshots = listBy(sc); if (snapshots == null) { - s_logger.debug(String.format("There are no snapshots on cache store to duplicate to region store [%s].", storeId)); + logger.debug(String.format("There are no snapshots on cache store to duplicate to region store [%s].", storeId)); return; } - s_logger.info(String.format("Duplicating [%s] snapshot cache store records to region store [%s].", snapshots.size(), storeId)); + logger.info(String.format("Duplicating [%s] snapshot cache store records to region store [%s].", snapshots.size(), storeId)); for (SnapshotDataStoreVO snap : snapshots) { SnapshotDataStoreVO snapStore = findByStoreSnapshot(DataStoreRole.Image, storeId, snap.getSnapshotId()); if (snapStore != null) { - s_logger.debug(String.format("There is already an entry for snapshot [%s] on region store [%s].", snap.getSnapshotId(), storeId)); + logger.debug(String.format("There is already an entry for snapshot [%s] on region store [%s].", snap.getSnapshotId(), storeId)); continue; } - s_logger.info(String.format("Persisting an entry for snapshot [%s] on region store [%s].", snap.getSnapshotId(), storeId)); + logger.info(String.format("Persisting an entry for snapshot [%s] on region store [%s].", snap.getSnapshotId(), storeId)); SnapshotDataStoreVO ss = new SnapshotDataStoreVO(); ss.setSnapshotId(snap.getSnapshotId()); ss.setDataStoreId(storeId); @@ -434,9 +432,9 @@ public void updateStoreRoleToCache(long storeId) { sc.setParameters("destroyed", false); List snaps = listBy(sc); if (snaps != null) { - s_logger.info(String.format("Updating role to cache store for [%s] entries in snapshot_store_ref.", snaps.size())); + logger.info(String.format("Updating role to cache store for [%s] entries in snapshot_store_ref.", snaps.size())); for (SnapshotDataStoreVO snap : snaps) { - s_logger.debug(String.format("Updating role to cache store for entry [%s].", snap)); + logger.debug(String.format("Updating role to cache store for entry [%s].", snap)); snap.setRole(DataStoreRole.ImageCache); update(snap.getId(), snap); } @@ -561,4 +559,16 @@ public void updateDisplayForSnapshotStoreRole(long snapshotId, long storeId, Dat ref.setDisplay(display); update(ref.getId(), ref); } + + @Override + public int expungeBySnapshotList(final List snapshotIds, final Long batchSize) { + if (CollectionUtils.isEmpty(snapshotIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("snapshotIds", sb.entity().getSnapshotId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("snapshotIds", snapshotIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java index 6f6ed4e08f27..7a466c1f5055 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java @@ -29,7 +29,8 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; @@ -47,7 +48,7 @@ @Entity @Table(name = "snapshot_store_ref") public class SnapshotDataStoreVO implements StateObject, DataObjectInStore { - private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreVO.class); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -85,6 +86,13 @@ public class SnapshotDataStoreVO implements StateObject, DataObjectInStore { - private static final Logger s_logger = Logger.getLogger(TemplateDataStoreVO.class); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -382,7 +383,7 @@ public void decrRefCnt() { refCnt--; } else{ - s_logger.warn("We should not try to decrement a zero reference count even though our code has guarded"); + logger.warn("We should not try to decrement a zero reference count even though our code has guarded"); } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java index c3a4b58fbd50..3381391e70e4 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java @@ -59,4 +59,6 @@ public interface VolumeDataStoreDao extends GenericDao, List listByVolume(long volumeId, long storeId); List listByStoreIdAndInstallPaths(Long storeId, List paths); + + int expungeByVolumeList(List volumeIds, Long batchSize); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java index bb21abbe44b3..d57dec8fbfd5 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreVO.java @@ -29,7 +29,8 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; @@ -46,7 +47,7 @@ @Entity @Table(name = "volume_store_ref") public class VolumeDataStoreVO implements StateObject, DataObjectInStore { - private static final Logger s_logger = Logger.getLogger(VolumeDataStoreVO.class); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -362,7 +363,7 @@ public void decrRefCnt() { refCnt--; } else { - s_logger.warn("We should not try to decrement a zero reference count even though our code has guarded"); + logger.warn("We should not try to decrement a zero reference count even though our code has guarded"); } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSVO.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSVO.java new file mode 100644 index 000000000000..3b869a5429fe --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/SharedFSVO.java @@ -0,0 +1,238 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.sharedfs; + + +import java.util.Date; +import java.util.UUID; + +import com.cloud.utils.db.GenericDao; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@Table(name = "shared_filesystem") +public class SharedFSVO implements SharedFS { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "name") + private String name; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "description") + private String description; + + @Column(name = "domain_id") + private long domainId; + + @Column(name = "account_id") + private long accountId; + + @Column(name = "data_center_id") + private long dataCenterId; + + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + private State state; + + @Column(name = "fs_provider_name") + private String fsProviderName; + + @Column(name = "protocol") + @Enumerated(value = EnumType.STRING) + private Protocol protocol; + + @Column(name = "volume_id") + private Long volumeId; + + @Column(name = "vm_id") + private Long vmId; + + @Column(name = "fs_type") + @Enumerated(value = EnumType.STRING) + private FileSystemType fsType; + + @Column(name = "service_offering_id") + private Long serviceOfferingId; + + @Column(name = "updated") + @Temporal(value = TemporalType.TIMESTAMP) + Date updated; + + @Column(name = "update_count", updatable = true, nullable = false) + protected long updatedCount; // This field should be updated everytime the + // state is updated. There's no set method in + // the vo object because it is done with in the + // dao code. + + @Column(name = GenericDao.CREATED_COLUMN) + protected Date created; + + @Column(name = GenericDao.REMOVED_COLUMN) + protected Date removed; + + public SharedFSVO() { + } + + public SharedFSVO(String name, String description, long domainId, long accountId, long dataCenterId, + String fsProviderName, Protocol protocol, FileSystemType fsType, Long serviceOfferingId) { + this.name = name; + this.description = description; + this.domainId = domainId; + this.accountId = accountId; + this.dataCenterId = dataCenterId; + this.fsProviderName = fsProviderName; + this.protocol = protocol; + this.state = State.Allocated; + this.fsType = fsType; + this.serviceOfferingId = serviceOfferingId; + this.uuid = UUID.randomUUID().toString(); + } + + @Override + public Class getEntityType() { + return SharedFS.class; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public void setDescription(String description) { + this.description = description; + } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public Long getDataCenterId() { + return dataCenterId; + } + + @Override + public State getState() { + return state; + } + + @Override + public String getFsProviderName() { + return fsProviderName; + } + + @Override + public Protocol getProtocol() { + return protocol; + } + + @Override + public Long getVolumeId() { + return volumeId; + } + + @Override + public void setVolumeId(Long volumeId) { + this.volumeId = volumeId; + } + + @Override + public Long getVmId() { + return vmId; + } + + @Override + public void setVmId(Long vmId) { + this.vmId = vmId; + } + + @Override + public FileSystemType getFsType() { + return fsType; + } + + @Override + public Long getServiceOfferingId() { + return serviceOfferingId; + } + + @Override + public void setServiceOfferingId(Long serviceOfferingId) { + this.serviceOfferingId = serviceOfferingId; + } + + @Override + public Date getUpdated() { + return updated; + } + + @Override + public long getUpdatedCount() { + return updatedCount; + } + + @Override + public void incrUpdatedCount() { + updatedCount++; + } + +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/dao/SharedFSDao.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/dao/SharedFSDao.java new file mode 100644 index 000000000000..4735202a7623 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/dao/SharedFSDao.java @@ -0,0 +1,32 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.sharedfs.dao; + +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSVO; + +import com.cloud.utils.db.GenericDao; +import com.cloud.utils.fsm.StateDao; + +import java.util.Date; +import java.util.List; + +public interface SharedFSDao extends GenericDao, StateDao { + List listSharedFSToBeDestroyed(Date date); + + SharedFSVO findSharedFSByNameAccountDomain(String name, Long accountId, Long domainId); +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/dao/SharedFSDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/dao/SharedFSDaoImpl.java new file mode 100644 index 000000000000..da6220716715 --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/sharedfs/dao/SharedFSDaoImpl.java @@ -0,0 +1,117 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.sharedfs.dao; + +import com.cloud.network.dao.NetworkDao; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.UpdateBuilder; + +import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMNetworkMapDao; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSVO; + +import javax.inject.Inject; +import java.util.Date; +import java.util.List; + +public class SharedFSDaoImpl extends GenericDaoBase implements SharedFSDao { + + @Inject + VMNetworkMapDao vmNetworkMapDao; + + @Inject + NetworkDao networkDao; + + protected final SearchBuilder StateUpdateCountSearch; + + protected final SearchBuilder DestroyedByTimeSearch; + + protected final SearchBuilder NameAccountDomainSearch; + + public SharedFSDaoImpl() { + StateUpdateCountSearch = createSearchBuilder(); + StateUpdateCountSearch.and("id", StateUpdateCountSearch.entity().getId(), SearchCriteria.Op.EQ); + StateUpdateCountSearch.and("state", StateUpdateCountSearch.entity().getState(), SearchCriteria.Op.EQ); + StateUpdateCountSearch.and("updatedCount", StateUpdateCountSearch.entity().getUpdatedCount(), SearchCriteria.Op.EQ); + StateUpdateCountSearch.done(); + + DestroyedByTimeSearch = createSearchBuilder(); + DestroyedByTimeSearch.and("state", DestroyedByTimeSearch.entity().getState(), SearchCriteria.Op.IN); + DestroyedByTimeSearch.and("accountId", DestroyedByTimeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + DestroyedByTimeSearch.done(); + + NameAccountDomainSearch = createSearchBuilder(); + NameAccountDomainSearch.and("name", NameAccountDomainSearch.entity().getName(), SearchCriteria.Op.EQ); + NameAccountDomainSearch.and("accountId", NameAccountDomainSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + NameAccountDomainSearch.and("domainId", NameAccountDomainSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + NameAccountDomainSearch.done(); + } + + @Override + public boolean updateState(SharedFS.State currentState, SharedFS.Event event, SharedFS.State nextState, SharedFS vo, Object data) { + + Long oldUpdated = vo.getUpdatedCount(); + Date oldUpdatedTime = vo.getUpdated(); + + SearchCriteria sc = StateUpdateCountSearch.create(); + sc.setParameters("id", vo.getId()); + sc.setParameters("state", currentState); + sc.setParameters("updatedCount", vo.getUpdatedCount()); + + vo.incrUpdatedCount(); + + UpdateBuilder builder = getUpdateBuilder(vo); + builder.set(vo, "state", nextState); + builder.set(vo, "updated", new Date()); + + int rows = update((SharedFSVO) vo, sc); + if (rows == 0 && logger.isDebugEnabled()) { + SharedFSVO dbSharedFS = findByIdIncludingRemoved(vo.getId()); + if (dbSharedFS != null) { + StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); + str.append(": DB Data={id=").append(dbSharedFS.getId()).append("; state=").append(dbSharedFS.getState()).append("; updatecount=").append(dbSharedFS.getUpdatedCount()).append(";updatedTime=") + .append(dbSharedFS.getUpdated()); + str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount()) + .append("; updatedTime=").append(vo.getUpdated()); + str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated) + .append("; updatedTime=").append(oldUpdatedTime); + } else { + logger.debug("Unable to update sharedfs: id=" + vo.getId() + ", as it is not present in the database anymore"); + } + } + return rows > 0; + } + + @Override + public List listSharedFSToBeDestroyed(Date date) { + SearchCriteria sc = DestroyedByTimeSearch.create(); + sc.setParameters("state", SharedFS.State.Destroyed, SharedFS.State.Expunging, SharedFS.State.Error); + sc.setParameters("updateTime", date); + return listBy(sc); + } + + @Override + public SharedFSVO findSharedFSByNameAccountDomain(String name, Long accountId, Long domainId) { + SearchCriteria sc = NameAccountDomainSearch.create(); + sc.setParameters("name", name); + sc.setParameters("accountId", accountId); + sc.setParameters("domainId", domainId); + return findOneBy(sc); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/util/CPUArchConverter.java b/engine/schema/src/main/java/org/apache/cloudstack/util/CPUArchConverter.java new file mode 100644 index 000000000000..e278809fb96b --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/util/CPUArchConverter.java @@ -0,0 +1,36 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.util; + +import com.cloud.cpu.CPU; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +@Converter +public class CPUArchConverter implements AttributeConverter { + + @Override + public String convertToDatabaseColumn(CPU.CPUArch cpuArch) { + return cpuArch == null ? CPU.CPUArch.amd64.getType() : cpuArch.getType(); + } + + @Override + public CPU.CPUArch convertToEntityAttribute(String attribute) { + return CPU.CPUArch.fromType(attribute); + } +} diff --git a/engine/schema/src/main/java/org/apache/cloudstack/util/HypervisorTypeConverter.java b/engine/schema/src/main/java/org/apache/cloudstack/util/HypervisorTypeConverter.java new file mode 100644 index 000000000000..57c12a9b7faa --- /dev/null +++ b/engine/schema/src/main/java/org/apache/cloudstack/util/HypervisorTypeConverter.java @@ -0,0 +1,38 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.util; + +import com.cloud.hypervisor.Hypervisor; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +/** + * Converts {@link com.cloud.hypervisor.Hypervisor.HypervisorType} to and from {@link String} using {@link com.cloud.hypervisor.Hypervisor.HypervisorType#name()}. + */ +@Converter +public class HypervisorTypeConverter implements AttributeConverter { + @Override + public String convertToDatabaseColumn(Hypervisor.HypervisorType attribute) { + return attribute != null ? attribute.name() : null; + } + + @Override + public Hypervisor.HypervisorType convertToEntityAttribute(String dbData) { + return dbData != null ? Hypervisor.HypervisorType.valueOf(dbData) : null; + } +} diff --git a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-common-daos-between-management-and-usage-context.xml b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-common-daos-between-management-and-usage-context.xml index 2b6361c81268..d6d72f9228e1 100644 --- a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-common-daos-between-management-and-usage-context.xml +++ b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-common-daos-between-management-and-usage-context.xml @@ -70,5 +70,6 @@ + diff --git a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml index ba25f1a91aec..171685ce413e 100644 --- a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml +++ b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -136,6 +136,7 @@ + @@ -157,7 +158,6 @@ - @@ -187,7 +187,6 @@ - @@ -270,6 +269,7 @@ + @@ -290,4 +290,13 @@ + + + + + + + + + diff --git a/engine/schema/src/main/resources/META-INF/db/data-217to218.sql b/engine/schema/src/main/resources/META-INF/db/data-217to218.sql index 5c1253143f45..1a03e9b79981 100755 --- a/engine/schema/src/main/resources/META-INF/db/data-217to218.sql +++ b/engine/schema/src/main/resources/META-INF/db/data-217to218.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-20to21.sql b/engine/schema/src/main/resources/META-INF/db/schema-20to21.sql index 7013046ca439..000d0f077cc3 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-20to21.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-20to21.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -141,14 +141,14 @@ ALTER TABLE `cloud`.`host` ADD COLUMN `cluster_id` bigint unsigned; -- -- enforced in postporcess-20to21.sql -ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `gateway` varchar(255); -- need to migrage data with user input +ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `gateway` varchar(255); -- need to migrage data with user input -ALTER TABLE `cloud`.`service_offering` ADD COLUMN `recreatable` tinyint(1) unsigned NOT NULL DEFAULT 0; +ALTER TABLE `cloud`.`service_offering` ADD COLUMN `recreatable` tinyint(1) unsigned NOT NULL DEFAULT 0; ALTER TABLE `cloud`.`service_offering` ADD COLUMN `tags` varchar(255); -ALTER TABLE `cloud`.`user_vm` MODIFY COLUMN `domain_router_id` bigint unsigned; -- change from NOT NULL to NULL +ALTER TABLE `cloud`.`user_vm` MODIFY COLUMN `domain_router_id` bigint unsigned; -- change from NOT NULL to NULL -ALTER TABLE `cloud`.`event` ADD COLUMN `state` varchar(32) NOT NULL DEFAULT 'Completed'; +ALTER TABLE `cloud`.`event` ADD COLUMN `state` varchar(32) NOT NULL DEFAULT 'Completed'; ALTER TABLE `cloud`.`event` ADD COLUMN `start_id` bigint unsigned NOT NULL DEFAULT 0; ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `tags` varchar(4096); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-217to218.sql b/engine/schema/src/main/resources/META-INF/db/schema-217to218.sql index f2b6b291f782..006a3f1cd7b3 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-217to218.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-217to218.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-21to22-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-21to22-cleanup.sql index c8757833fabf..8a3ca39d5e7a 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-21to22-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-21to22-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-21to22-premium.sql b/engine/schema/src/main/resources/META-INF/db/schema-21to22-premium.sql index 45202840565f..a34b65dc8ab5 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-21to22-premium.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-21to22-premium.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -50,7 +50,7 @@ CREATE TABLE `cloud_usage`.`usage_event` ( `resource_name` varchar(255), `offering_id` bigint unsigned, `template_id` bigint unsigned, - `size` bigint unsigned, + `size` bigint unsigned, `processed` tinyint NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-21to22.sql b/engine/schema/src/main/resources/META-INF/db/schema-21to22.sql index eb473cfc7f6b..8da29caae53b 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-21to22.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-21to22.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -22,7 +22,7 @@ ALTER TABLE `cloud`.`cluster` ADD COLUMN `guid` varchar(255) UNIQUE DEFAULT NULL ALTER TABLE `cloud`.`cluster` ADD COLUMN `cluster_type` varchar(64) DEFAULT 'CloudManaged'; ALTER TABLE `cloud`.`vm_template` ADD COLUMN `hypervisor_type` varchar(32) COMMENT 'hypervisor that the template is belonged to'; ALTER TABLE `cloud`.`vm_template` ADD COLUMN `extractable` int(1) unsigned NOT NULL default 0 COMMENT 'Is this template extractable'; -ALTER TABLE `cloud`.`template_spool_ref` ADD CONSTRAINT `fk_template_spool_ref__template_id` FOREIGN KEY (`template_id`) REFERENCES `vm_template`(`id`); +ALTER TABLE `cloud`.`template_spool_ref` ADD CONSTRAINT `fk_template_spool_ref__template_id` FOREIGN KEY (`template_id`) REFERENCES `vm_template`(`id`); ALTER TABLE `cloud`.`guest_os` modify `name` varchar(255) ; @@ -104,7 +104,7 @@ CREATE TABLE `cloud`.`networks` ( `broadcast_domain_type` varchar(32) NOT NULL COMMENT 'type of broadcast domain used', `broadcast_uri` varchar(255) COMMENT 'broadcast domain specifier', `gateway` varchar(15) COMMENT 'gateway for this network configuration', - `cidr` varchar(18) COMMENT 'network cidr', + `cidr` varchar(18) COMMENT 'network cidr', `mode` varchar(32) COMMENT 'How to retrieve ip address in this network', `network_offering_id` bigint unsigned NOT NULL COMMENT 'network offering id that this configuration is created from', `data_center_id` bigint unsigned NOT NULL COMMENT 'data center id that this configuration is used in', @@ -167,7 +167,7 @@ CREATE TABLE `cloud`.`nics` ( `ip_type` varchar(32) COMMENT 'type of ip', `broadcast_uri` varchar(255) COMMENT 'broadcast uri', `network_id` bigint unsigned NOT NULL COMMENT 'network configuration id', - `mode` varchar(32) COMMENT 'mode of getting ip address', + `mode` varchar(32) COMMENT 'mode of getting ip address', `state` varchar(32) NOT NULL COMMENT 'state of the creation', `strategy` varchar(32) NOT NULL COMMENT 'reservation strategy', `reserver_name` varchar(255) COMMENT 'Name of the component that reserved the ip address', @@ -176,7 +176,7 @@ CREATE TABLE `cloud`.`nics` ( `update_time` timestamp NOT NULL COMMENT 'time the state was changed', `isolation_uri` varchar(255) COMMENT 'id for isolation', `ip6_address` char(40) COMMENT 'ip6 address', - `default_nic` tinyint NOT NULL COMMENT "None", + `default_nic` tinyint NOT NULL COMMENT "None", `created` datetime NOT NULL COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', PRIMARY KEY (`id`), @@ -253,7 +253,7 @@ CREATE TABLE `cloud`.`op_host` ( `id` bigint unsigned NOT NULL UNIQUE COMMENT 'host id', `sequence` bigint unsigned DEFAULT 1 NOT NULL COMMENT 'sequence for the host communication', PRIMARY KEY (`id`), - CONSTRAINT `fk_op_host__id` FOREIGN KEY (`id`) REFERENCES `host`(`id`) ON DELETE CASCADE + CONSTRAINT `fk_op_host__id` FOREIGN KEY (`id`) REFERENCES `host`(`id`) ON DELETE CASCADE ) ENGINE = InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`guest_os_hypervisor` ( @@ -261,7 +261,7 @@ CREATE TABLE `cloud`.`guest_os_hypervisor` ( `hypervisor_type` varchar(32) NOT NULL, `guest_os_name` varchar(255) NOT NULL, `guest_os_id` bigint unsigned NOT NULL, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; INSERT INTO op_host(id, sequence) select id, sequence from host; @@ -269,7 +269,7 @@ INSERT INTO op_host(id, sequence) select id, sequence from host; -- Alter Tables to add Columns; ALTER TABLE `cloud`.`cluster` ADD COLUMN `hypervisor_type` varchar(32); -UPDATE `cloud`.`cluster` SET hypervisor_type=(SELECT DISTINCT host.hypervisor_type from host where host.cluster_id = cluster.id GROUP BY host.hypervisor_type); +UPDATE `cloud`.`cluster` SET hypervisor_type=(SELECT DISTINCT host.hypervisor_type from host where host.cluster_id = cluster.id GROUP BY host.hypervisor_type); ALTER TABLE `cloud`.`volumes` ADD COLUMN `attached` datetime; UPDATE `cloud`.`volumes` SET attached=now() WHERE removed IS NULL AND instance_id IS NOT NULL; @@ -286,7 +286,7 @@ ALTER TABLE `cloud`.`vlan` ADD COLUMN `network_id` bigint unsigned NOT NULL; ALTER TABLE `cloud`.`data_center` ADD COLUMN `domain` varchar(100); ALTER TABLE `cloud`.`data_center` ADD COLUMN `domain_id` bigint unsigned; -ALTER TABLE `cloud`.`data_center` ADD COLUMN `networktype` varchar(255) NOT NULL DEFAULT 'Basic'; +ALTER TABLE `cloud`.`data_center` ADD COLUMN `networktype` varchar(255) NOT NULL DEFAULT 'Basic'; ALTER TABLE `cloud`.`data_center` ADD COLUMN `dns_provider` char(64) DEFAULT 'VirtualRouter'; ALTER TABLE `cloud`.`data_center` ADD COLUMN `gateway_provider` char(64) DEFAULT 'VirtualRouter'; ALTER TABLE `cloud`.`data_center` ADD COLUMN `firewall_provider` char(64) DEFAULT 'VirtualRouter'; @@ -306,7 +306,7 @@ UPDATE `cloud`.`op_dc_link_local_ip_address_alloc` SET reservation_id=concat(cas ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `enabled` tinyint NOT NULL DEFAULT 1; ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD COLUMN `reservation_id` char(40) NULL; -UPDATE op_dc_vnet_alloc set reservation_id=concat(cast(data_center_id as CHAR), concat("-", vnet)) WHERE taken is NOT NULL; +UPDATE op_dc_vnet_alloc set reservation_id=concat(cast(data_center_id as CHAR), concat("-", vnet)) WHERE taken is NOT NULL; ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `service_offering_id` bigint unsigned NOT NULL; ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `reservation_id` char(40); @@ -326,7 +326,7 @@ ALTER TABLE `cloud`.`user_vm` ADD COLUMN `display_name` varchar(255); UPDATE user_vm inner join vm_instance on user_vm.id=vm_instance.id set user_vm.iso_id=vm_instance.iso_id, user_vm.display_name=vm_instance.display_name where vm_instance.type='User'; ALTER TABLE `cloud`.`template_host_ref` ADD COLUMN `physical_size` bigint unsigned DEFAULT 0; -UPDATE template_host_ref INNER JOIN template_spool_ref ON template_host_ref.template_id=template_spool_ref.template_id SET template_host_ref.physical_size=template_spool_ref.template_size; +UPDATE template_host_ref INNER JOIN template_spool_ref ON template_host_ref.template_id=template_spool_ref.template_id SET template_host_ref.physical_size=template_spool_ref.template_size; CREATE TABLE `cloud`.`user_vm_details` ( @@ -412,7 +412,7 @@ CREATE TABLE `cloud`.`vpn_users` ( CONSTRAINT `fk_vpn_users__owner_id` FOREIGN KEY (`owner_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_vpn_users__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE, INDEX `i_vpn_users_username`(`username`), - UNIQUE `i_vpn_users__account_id__username`(`owner_id`, `username`) + UNIQUE `i_vpn_users__account_id__username`(`owner_id`, `username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `cloud`.`storage_pool` ADD COLUMN `status` varchar(32); @@ -490,7 +490,7 @@ CREATE TABLE `cloud`.`usage_event` ( `resource_name` varchar(255), `offering_id` bigint unsigned, `template_id` bigint unsigned, - `size` bigint unsigned, + `size` bigint unsigned, `processed` tinyint NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-2210to2211.sql b/engine/schema/src/main/resources/META-INF/db/schema-2210to2211.sql index 01bec020d63d..f352f5ef44d6 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-2210to2211.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-2210to2211.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-2211to2212-premium.sql b/engine/schema/src/main/resources/META-INF/db/schema-2211to2212-premium.sql index 0cb187e2b9d4..eae13acc78cb 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-2211to2212-premium.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-2211to2212-premium.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-2211to2212.sql b/engine/schema/src/main/resources/META-INF/db/schema-2211to2212.sql index 94c3d75a29ff..00d0fcaac76e 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-2211to2212.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-2211to2212.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-2212to2213.sql b/engine/schema/src/main/resources/META-INF/db/schema-2212to2213.sql index 2e86599f7924..c69809e8205b 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-2212to2213.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-2212to2213.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-2213to2214.sql b/engine/schema/src/main/resources/META-INF/db/schema-2213to2214.sql index 6c0cc4b6c708..41e3944dc180 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-2213to2214.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-2213to2214.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -29,7 +29,7 @@ CREATE TABLE `cloud`.`mshost_peer` ( `peer_runid` bigint NOT NULL, `peer_state` varchar(10) NOT NULL DEFAULT 'Down', `last_update` DATETIME NULL COMMENT 'Last record update time', - + PRIMARY KEY (`id`), CONSTRAINT `fk_mshost_peer__owner_mshost` FOREIGN KEY (`owner_mshost`) REFERENCES `mshost`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_mshost_peer__peer_mshost` FOREIGN KEY (`peer_mshost`) REFERENCES `mshost`(`id`), diff --git a/engine/schema/src/main/resources/META-INF/db/schema-2214to30-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-2214to30-cleanup.sql index c90707c75b71..844280d29b64 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-2214to30-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-2214to30-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -22,7 +22,7 @@ ALTER TABLE `cloud_usage`.`usage_network` DROP COLUMN `current_bytes_sent`; ALTER TABLE `cloud`.`template_host_ref` DROP COLUMN `pool_id`; DELETE from `cloud`.`op_host_capacity` where capacity_type in (2,4,6); -ALTER TABLE `cloud`.`vm_instance` DROP COLUMN `private_netmask`; +ALTER TABLE `cloud`.`vm_instance` DROP COLUMN `private_netmask`; ALTER TABLE `cloud`.`security_group_rule` drop foreign key `fk_security_ingress_rule___security_group_id`; ALTER TABLE `cloud`.`security_group_rule` drop foreign key `fk_security_ingress_rule___allowed_network_id`; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-2214to30.sql b/engine/schema/src/main/resources/META-INF/db/schema-2214to30.sql index 22fda616649b..8be481e47368 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-2214to30.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-2214to30.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -54,7 +54,7 @@ CREATE TABLE `cloud`.`projects` ( PRIMARY KEY (`id`), CONSTRAINT `fk_projects__project_account_id` FOREIGN KEY(`project_account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_projects__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE, - INDEX `i_projects__removed`(`removed`) + INDEX `i_projects__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -177,97 +177,97 @@ ALTER TABLE `cloud`.`alert` ADD `cluster_id` bigint unsigned; ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `agg_bytes_received` bigint unsigned NOT NULL default '0'; ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `agg_bytes_sent` bigint unsigned NOT NULL default '0'; -ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `uc_vm_instance_uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`async_job` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`async_job` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`async_job` ADD CONSTRAINT `uc_async__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`domain` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`domain` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`domain` ADD CONSTRAINT `uc_domain__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`account` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`account` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`account` ADD CONSTRAINT `uc_account__uuid` UNIQUE (`uuid`); ALTER TABLE `cloud_usage`.`account` ADD COLUMN `uuid` varchar(40); -ALTER TABLE `cloud`.`user` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`user` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`user` ADD CONSTRAINT `uc_user__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`projects` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`projects` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`projects` ADD CONSTRAINT `uc_projects__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`data_center` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`data_center` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`data_center` ADD CONSTRAINT `uc_data_center__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`host` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`host` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`host` ADD CONSTRAINT `uc_host__uuid` UNIQUE (`uuid`); ALTER TABLE `cloud`.`host` ADD COLUMN `update_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'atomic increase count making status update operation atomical'; -ALTER TABLE `cloud`.`vm_template` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`vm_template` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`vm_template` ADD CONSTRAINT `uc_vm_template__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`disk_offering` ADD CONSTRAINT `uc_disk_offering__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`networks` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`networks` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`networks` ADD CONSTRAINT `uc_networks__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`security_group` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`security_group` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`security_group` ADD CONSTRAINT `uc_security_group__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`instance_group` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`instance_group` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `uc_instance_group__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`host_pod_ref` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`host_pod_ref` ADD CONSTRAINT `uc_host_pod_ref__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`snapshots` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`snapshots` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`snapshots` ADD CONSTRAINT `uc_snapshots__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`snapshot_policy` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`snapshot_policy` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`snapshot_policy` ADD CONSTRAINT `uc_snapshot_policy__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`snapshot_schedule` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`snapshot_schedule` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`snapshot_schedule` ADD CONSTRAINT `uc_snapshot_schedule__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`volumes` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`volumes` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`volumes` ADD CONSTRAINT `uc_volumes__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`vlan` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`vlan` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`vlan` ADD CONSTRAINT `uc_vlan__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`user_ip_address` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`user_ip_address` ADD CONSTRAINT `uc_user_ip_address__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`firewall_rules` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`firewall_rules` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`firewall_rules` ADD CONSTRAINT `uc_firewall_rules__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`cluster` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`cluster` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`cluster` ADD CONSTRAINT `uc_cluster__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`network_offerings` ADD CONSTRAINT `uc_network_offerings__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`hypervisor_capabilities` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`hypervisor_capabilities` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`hypervisor_capabilities` ADD CONSTRAINT `uc_hypervisor_capabilities__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`vpn_users` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`vpn_users` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`vpn_users` ADD CONSTRAINT `uc_vpn_users__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`event` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`event` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`event` ADD CONSTRAINT `uc_event__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`alert` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`alert` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`alert` ADD CONSTRAINT `uc_alert__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`guest_os` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`guest_os` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`guest_os` ADD CONSTRAINT `uc_guest_os__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`guest_os_category` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`guest_os_category` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`guest_os_category` ADD CONSTRAINT `uc_guest_os_category__uuid` UNIQUE (`uuid`); -ALTER TABLE `cloud`.`nics` ADD COLUMN `uuid` varchar(40); +ALTER TABLE `cloud`.`nics` ADD COLUMN `uuid` varchar(40); ALTER TABLE `cloud`.`nics` ADD CONSTRAINT `uc_nics__uuid` UNIQUE (`uuid`); ALTER TABLE `cloud`.`op_host_capacity` ADD COLUMN `created` datetime; @@ -304,7 +304,7 @@ ALTER TABLE `cloud_usage`.`usage_ip_address` ADD COLUMN `is_system` smallint(1) INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Premium', 'DEFAULT', 'management-server', 'usage.sanity.check.interval', null, 'Interval (in days) to check sanity of usage data'); DELETE FROM `cloud`.`configuration` WHERE name='host.capacity.checker.wait'; -DELETE FROM `cloud`.`configuration` WHERE name='host.capacity.checker.interval'; +DELETE FROM `cloud`.`configuration` WHERE name='host.capacity.checker.interval'; INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'disable.extraction' , 'false', 'Flag for disabling extraction of template, isos and volumes'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.check.interval' , '30', 'Interval (in seconds) to report redundant router status.'); @@ -362,9 +362,9 @@ CREATE TABLE `cloud`.`physical_network` ( `name` varchar(255) NOT NULL, `data_center_id` bigint unsigned NOT NULL COMMENT 'data center id that this physical network belongs to', `vnet` varchar(255), - `speed` varchar(32), + `speed` varchar(32), `domain_id` bigint unsigned COMMENT 'foreign key to domain id', - `broadcast_domain_range` varchar(32) NOT NULL DEFAULT 'POD' COMMENT 'range of broadcast domain : POD/ZONE', + `broadcast_domain_range` varchar(32) NOT NULL DEFAULT 'POD' COMMENT 'range of broadcast domain : POD/ZONE', `state` varchar(32) NOT NULL DEFAULT 'Disabled' COMMENT 'what state is this configuration in', `created` datetime COMMENT 'date created', `removed` datetime COMMENT 'date removed if not null', @@ -372,7 +372,7 @@ CREATE TABLE `cloud`.`physical_network` ( CONSTRAINT `fk_physical_network__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_physical_network__domain_id` FOREIGN KEY(`domain_id`) REFERENCES `domain`(`id`), CONSTRAINT `uc_physical_networks__uuid` UNIQUE (`uuid`), - INDEX `i_physical_network__removed`(`removed`) + INDEX `i_physical_network__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cloud`.`physical_network_tags` ( @@ -690,7 +690,7 @@ CREATE TABLE `cloud_usage`.`usage_security_group` ( `vm_instance_id` bigint unsigned NOT NULL, `security_group_id` bigint unsigned NOT NULL, `created` DATETIME NOT NULL, - `deleted` DATETIME NULL + `deleted` DATETIME NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `cloud_usage`.`usage_security_group` ADD INDEX `i_usage_security_group__account_id`(`account_id`); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-221to222-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-221to222-cleanup.sql index d999b9391031..5ed5f834f682 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-221to222-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-221to222-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-221to222-premium.sql b/engine/schema/src/main/resources/META-INF/db/schema-221to222-premium.sql index 5477fd8a348b..01603a406588 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-221to222-premium.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-221to222-premium.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-221to222.sql b/engine/schema/src/main/resources/META-INF/db/schema-221to222.sql index 0c663b1ca033..d07b71fb6cbe 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-221to222.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-221to222.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -23,7 +23,7 @@ update network_offerings set firewall_service=1, lb_service=1,vpn_service=1,gate alter table domain add column `state` char(32) NOT NULL default 'Active' COMMENT 'state of the domain'; alter table nics add column `vm_type` char(32); update nics set vm_type=(select type from vm_instance where vm_instance.id=nics.instance_id); -INSERT INTO configuration (`category`, `instance`, `component`, `name`, `value`, `description`) VALUES ('Network','DEFAULT','none','network.guest.cidr.limit','22','size limit for guest cidr; cant be less than this value'); +INSERT INTO configuration (`category`, `instance`, `component`, `name`, `value`, `description`) VALUES ('Network','DEFAULT','none','network.guest.cidr.limit','22','size limit for guest cidr; cant be less than this value'); alter table user_statistics add column `network_id` bigint unsigned; update op_networks set nics_count=(nics_count-1) where id in (select d.network_id from domain_router d, vm_instance i where i.state='Running' and i.id=d.id); update network_offerings set traffic_type='Guest' where system_only=0; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-222to224-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-222to224-cleanup.sql index 1bcd5d4c5f0a..31f6eefb5fa5 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-222to224-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-222to224-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-222to224-premium.sql b/engine/schema/src/main/resources/META-INF/db/schema-222to224-premium.sql index 9a5f62794c48..33d954d3a884 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-222to224-premium.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-222to224-premium.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-222to224.sql b/engine/schema/src/main/resources/META-INF/db/schema-222to224.sql index 8be64169b448..abbaf447bba6 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-222to224.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-222to224.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -99,7 +99,7 @@ ALTER TABLE `cloud`.`op_host_capacity` MODIFY `used_capacity` bigint signed NOT ALTER TABLE `cloud`.`op_host_capacity` MODIFY `reserved_capacity` bigint signed NOT NULL; ALTER TABLE `cloud`.`op_host_capacity` MODIFY `total_capacity` bigint signed NOT NULL; -INSERT IGNORE INTO `cloud`.`configuration` VALUES +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced','DEFAULT','management-server','control.cidr','169.254.0.0/16','Changes the cidr for the control network traffic. Defaults to using link local. Must be unique within pods'), ('Advanced','DEFAULT','management-server','control.gateway','169.254.0.1','gateway for the control network traffic'), ('Advanced','DEFAULT','AgentManager','cmd.wait','7200','Time (in seconds) to wait for some heavy time-consuming commands'), @@ -110,7 +110,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Console Proxy','DEFAULT','AgentManager','consoleproxy.url.domain','realhostip.com','Console proxy url domain'), ('Advanced','DEFAULT','management-server','extract.url.cleanup.interval','120','The interval (in seconds) to wait before cleaning up the extract URL\'s '), ('Network','DEFAULT','AgentManager','guest.ip.network','10.1.1.1','The network address of the guest virtual network. Virtual machines will be assigned an IP in this subnet.'), -('Network','DEFAULT','AgentManager','guest.netmask','255.255.255.0','The netmask of the guest virtual network.'), +('Network','DEFAULT','AgentManager','guest.netmask','255.255.255.0','The netmask of the guest virtual network.'), ('Network','DEFAULT','management-server','guest.vlan.bits','12','The number of bits to reserve for the VLAN identifier in the guest subnet.'), ('Advanced','DEFAULT','management-server','host.capacity.checker.interval','3600','Time (in seconds) to wait before recalculating host\'s capacity'), ('Advanced','DEFAULT','management-server','host.capacity.checker.wait','3600','Time (in seconds) to wait before starting host capacity background checker'), @@ -175,7 +175,7 @@ ALTER TABLE `cloud`.`snapshot_schedule` ADD UNIQUE KEY `volume_id` (`volume_id` ALTER TABLE `cloud`.`storage_pool` MODIFY COLUMN `uuid` varchar(255) UNIQUE; ALTER TABLE `cloud`.`user_statistics` DROP KEY `account_id`; -ALTER TABLE `cloud`.`user_statistics` ADD UNIQUE KEY `account_id` (`account_id`,`data_center_id`, `public_ip_address`, `device_id`,`device_type`); +ALTER TABLE `cloud`.`user_statistics` ADD UNIQUE KEY `account_id` (`account_id`,`data_center_id`, `public_ip_address`, `device_id`,`device_type`); ALTER TABLE `cloud`.`usage_event` ADD INDEX `i_usage_event__created`(`created`); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-224to225-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-224to225-cleanup.sql index b018d7f280e7..5f24290a1fd2 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-224to225-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-224to225-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-224to225.sql b/engine/schema/src/main/resources/META-INF/db/schema-224to225.sql index 65334af306fb..735c30a943c0 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-224to225.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-224to225.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-225to226.sql b/engine/schema/src/main/resources/META-INF/db/schema-225to226.sql index ec1baae2e69e..3527921af840 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-225to226.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-225to226.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-227to228-premium.sql b/engine/schema/src/main/resources/META-INF/db/schema-227to228-premium.sql index 40fcbfa68380..2e21f0c249ef 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-227to228-premium.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-227to228-premium.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-227to228.sql b/engine/schema/src/main/resources/META-INF/db/schema-227to228.sql index 343c7663fd29..ac3c014894dd 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-227to228.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-227to228.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -136,9 +136,9 @@ ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `vm_type` varchar(32) NOT NULL; UPDATE vm_instance set vm_type=type; ALTER TABLE `cloud`.`networks` ADD COLUMN `is_domain_specific` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if network is domain specific, 0 false otherwise'; -INSERT INTO configuration (`category`, `instance`, `component`, `name`, `value`, `description`) VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'allow.subdomain.network.access', 'true', 'Allow subdomains to use networks dedicated to their parent domain(s)'); +INSERT INTO configuration (`category`, `instance`, `component`, `name`, `value`, `description`) VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'allow.subdomain.network.access', 'true', 'Allow subdomains to use networks dedicated to their parent domain(s)'); -INSERT INTO configuration (`category`, `instance`, `component`, `name`, `value`, `description`) VALUES ('Advanced', 'DEFAULT', 'management-server', 'encode.api.response', 'false', 'Do UTF-8 encoding for the api response, false by default'); +INSERT INTO configuration (`category`, `instance`, `component`, `name`, `value`, `description`) VALUES ('Advanced', 'DEFAULT', 'management-server', 'encode.api.response', 'false', 'Do UTF-8 encoding for the api response, false by default'); DELETE FROM load_balancer_vm_map WHERE instance_id IN (SELECT id FROM vm_instance WHERE removed IS NOT NULL); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-228to229.sql b/engine/schema/src/main/resources/META-INF/db/schema-228to229.sql index 9d5baa4c4032..2496dd4c472f 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-228to229.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-228to229.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-229to2210.sql b/engine/schema/src/main/resources/META-INF/db/schema-229to2210.sql index 9c5c46242af8..1d2980f65640 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-229to2210.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-229to2210.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-22beta1to22beta2.sql b/engine/schema/src/main/resources/META-INF/db/schema-22beta1to22beta2.sql index 1b7c6a64eb0b..dd03e61e17e5 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-22beta1to22beta2.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-22beta1to22beta2.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-22beta3to22beta4.sql b/engine/schema/src/main/resources/META-INF/db/schema-22beta3to22beta4.sql index c73d16537acb..a93d6d5d7e53 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-22beta3to22beta4.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-22beta3to22beta4.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -83,7 +83,7 @@ CREATE TABLE `cloud`.`user_vm_details` ( `value` varchar(1024) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - + CREATE TABLE `cloud`.`cluster_details` ( `id` bigint unsigned NOT NULL auto_increment, `cluster_id` bigint unsigned NOT NULL COMMENT 'cluster id', @@ -99,9 +99,9 @@ ALTER TABLE `cloud`.`service_offering` ADD COLUMN `host_tag` varchar(255); ALTER TABLE `cloud`.`op_it_work` change created created_at bigint unsigned NOT NULL COMMENT 'when was this work detail created'; ALTER TABLE `cloud`.`op_it_work` change state step char(32) NOT NULL COMMENT 'state'; ALTER TABLE `cloud`.`op_it_work` change cancel_taken updated_at bigint unsigned NOT NULL COMMENT 'time it was taken over'; -ALTER TABLE `cloud`.`op_it_work` ADD COLUMN `instance_id` bigint unsigned NOT NULL COMMENT 'vm instance'; -ALTER TABLE `cloud`.`op_it_work` ADD COLUMN `resource_id` bigint unsigned COMMENT 'resource id being worked on'; -ALTER TABLE `cloud`.`op_it_work` ADD COLUMN `resource_type` char(32) COMMENT 'type of resource being worked on'; +ALTER TABLE `cloud`.`op_it_work` ADD COLUMN `instance_id` bigint unsigned NOT NULL COMMENT 'vm instance'; +ALTER TABLE `cloud`.`op_it_work` ADD COLUMN `resource_id` bigint unsigned COMMENT 'resource id being worked on'; +ALTER TABLE `cloud`.`op_it_work` ADD COLUMN `resource_type` char(32) COMMENT 'type of resource being worked on'; ALTER TABLE `cloud`.`hypervsior_properties` ADD COLUMN `is_default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if network is default'; ALTER TABLE `cloud`.`network_offerings` drop column TYPE; ALTER TABLE `cloud`.`domain_router` ADD COLUMN `host_tag` varchar(255) COMMENT 'host tag specified by the service_offering'; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-301to302-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-301to302-cleanup.sql index 7922d98ea99a..d32644f471c9 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-301to302-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-301to302-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-301to302.sql b/engine/schema/src/main/resources/META-INF/db/schema-301to302.sql index 4532757d052b..99a555dedcab 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-301to302.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-301to302.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -41,7 +41,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Hidden', 'DEFAULT', 'managem INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'network.disable.rpfilter', 'true', 'disable rp_filter on Domain Router VM public interfaces.'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'network.securitygroups.work.cleanup.interval', '120', 'Time interval (seconds) in which finished work is cleaned up from the work table'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'network.securitygroups.work.lock.timeout', '300', 'Lock wait timeout (seconds) while updating the security group work queues'); -INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'network.securitygroups.work.per.agent.queue.size', '100', +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'network.securitygroups.work.per.agent.queue.size', '100', 'The number of outstanding security group work items that can be queued to a host. If exceeded, work items will get dropped to conserve memory. Security Group Sync will take care of ensuring that the host gets updated eventually'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'network.securitygroups.workers.pool.size', '50', 'Number of worker threads processing the security group update work queue'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Hidden', 'DEFAULT', 'management-server', 'ovm.guest.network.device', null, 'Specify the private bridge on host for private network'); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-302to303.sql b/engine/schema/src/main/resources/META-INF/db/schema-302to303.sql index b475a8e99580..07faf98cf743 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-302to303.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-302to303.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -55,7 +55,7 @@ CREATE TABLE `cloud`.`volume_host_ref` ( `local_path` varchar(255), `install_path` varchar(255), `url` varchar(255), - `format` varchar(32) NOT NULL COMMENT 'format for the volume', + `format` varchar(32) NOT NULL COMMENT 'format for the volume', `destroyed` tinyint(1) COMMENT 'indicates whether the volume_host entry was destroyed by the user or not', PRIMARY KEY (`id`), CONSTRAINT `fk_volume_host_ref__host_id` FOREIGN KEY `fk_volume_host_ref__host_id` (`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE, diff --git a/engine/schema/src/main/resources/META-INF/db/schema-302to40-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-302to40-cleanup.sql index 4d89a078b2d5..540c77161893 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-302to40-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-302to40-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-302to40.sql b/engine/schema/src/main/resources/META-INF/db/schema-302to40.sql index ca99f0106d2c..47e4c3fd6d5d 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-302to40.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-302to40.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -59,7 +59,7 @@ CREATE TABLE `cloud`.`volume_host_ref` ( `local_path` varchar(255), `install_path` varchar(255), `url` varchar(255), - `format` varchar(32) NOT NULL COMMENT 'format for the volume', + `format` varchar(32) NOT NULL COMMENT 'format for the volume', `destroyed` tinyint(1) COMMENT 'indicates whether the volume_host entry was destroyed by the user or not', PRIMARY KEY (`id`), CONSTRAINT `fk_volume_host_ref__host_id` FOREIGN KEY `fk_volume_host_ref__host_id` (`host_id`) REFERENCES `host` (`id`) ON DELETE CASCADE, @@ -236,9 +236,9 @@ from information_schema.key_column_usage A JOIN information_schema.key_column_usage B ON B.table_name = 'physical_network_service_providers' AND B.COLUMN_NAME = 'provider_name' AND A.COLUMN_NAME ='physical_network_id' AND B.CONSTRAINT_NAME=A.CONSTRAINT_NAME where A.table_name = 'physical_network_service_providers' LIMIT 1); -PREPARE stmt1 FROM @constraintname; -EXECUTE stmt1; -DEALLOCATE PREPARE stmt1; +PREPARE stmt1 FROM @constraintname; +EXECUTE stmt1; +DEALLOCATE PREPARE stmt1; AlTER TABLE `cloud`.`physical_network_service_providers` ADD CONSTRAINT `fk_pnetwork_service_providers__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE; UPDATE `cloud`.`configuration` SET description='In second, timeout for creating volume from snapshot' WHERE name='create.volume.from.snapshot.wait'; @@ -299,7 +299,7 @@ CREATE TABLE `cloud`.`vpc` ( PRIMARY KEY (`id`), INDEX `i_vpc__removed`(`removed`), CONSTRAINT `fk_vpc__zone_id` FOREIGN KEY `fk_vpc__zone_id` (`zone_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE, - CONSTRAINT `fk_vpc__vpc_offering_id` FOREIGN KEY (`vpc_offering_id`) REFERENCES `vpc_offerings`(`id`), + CONSTRAINT `fk_vpc__vpc_offering_id` FOREIGN KEY (`vpc_offering_id`) REFERENCES `vpc_offerings`(`id`), CONSTRAINT `fk_vpc__account_id` FOREIGN KEY `fk_vpc__account_id` (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_vpc__domain_id` FOREIGN KEY `fk_vpc__domain_id` (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -360,7 +360,7 @@ CREATE TABLE `cloud`.`static_routes` ( `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', `uuid` varchar(40), `vpc_gateway_id` bigint unsigned COMMENT 'id of the corresponding ip address', - `cidr` varchar(18) COMMENT 'cidr for the static route', + `cidr` varchar(18) COMMENT 'cidr for the static route', `state` char(32) NOT NULL COMMENT 'current state of this rule', `vpc_id` bigint unsigned COMMENT 'vpc the firewall rule is associated with', `account_id` bigint unsigned NOT NULL COMMENT 'owner id', @@ -468,7 +468,7 @@ UPDATE `cloud`.`configuration` SET description='Comma separated list of cidrs in INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'site2site.vpn.vpngateway.connection.limit', '4', 'The maximum number of VPN connection per VPN gateway'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'site2site.vpn.customergateway.subnets.limit', '10', 'The maximum number of subnets per customer gateway'); -INSERT IGNORE INTO `cloud`.`guest_os_category` VALUES ('11','None',NULL); +INSERT IGNORE INTO `cloud`.`guest_os_category` VALUES ('11','None',NULL); ALTER TABLE `cloud`.`user` ADD COLUMN `incorrect_login_attempts` integer unsigned NOT NULL DEFAULT '0'; INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'incorrect.login.attempts.allowed', '5', 'Incorrect login attempts allowed before the user is disabled'); UPDATE `cloud`.`configuration` set description ='Uuid of the service offering used by console proxy; if NULL - system offering will be used' where name ='consoleproxy.service.offering'; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-304to305-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-304to305-cleanup.sql index 3b5c8f5a3565..1184c98e1824 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-304to305-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-304to305-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-304to305.sql b/engine/schema/src/main/resources/META-INF/db/schema-304to305.sql index dfeff3f683bd..cb2efb3edd02 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-304to305.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-304to305.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -80,7 +80,7 @@ CREATE TABLE `cloud`.`vpc` ( PRIMARY KEY (`id`), INDEX `i_vpc__removed`(`removed`), CONSTRAINT `fk_vpc__zone_id` FOREIGN KEY `fk_vpc__zone_id` (`zone_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE, - CONSTRAINT `fk_vpc__vpc_offering_id` FOREIGN KEY (`vpc_offering_id`) REFERENCES `vpc_offerings`(`id`), + CONSTRAINT `fk_vpc__vpc_offering_id` FOREIGN KEY (`vpc_offering_id`) REFERENCES `vpc_offerings`(`id`), CONSTRAINT `fk_vpc__account_id` FOREIGN KEY `fk_vpc__account_id` (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_vpc__domain_id` FOREIGN KEY `fk_vpc__domain_id` (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -141,7 +141,7 @@ CREATE TABLE `cloud`.`static_routes` ( `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', `uuid` varchar(40), `vpc_gateway_id` bigint unsigned COMMENT 'id of the corresponding ip address', - `cidr` varchar(18) COMMENT 'cidr for the static route', + `cidr` varchar(18) COMMENT 'cidr for the static route', `state` char(32) NOT NULL COMMENT 'current state of this rule', `vpc_id` bigint unsigned COMMENT 'vpc the firewall rule is associated with', `account_id` bigint unsigned NOT NULL COMMENT 'owner id', diff --git a/engine/schema/src/main/resources/META-INF/db/schema-305to306-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-305to306-cleanup.sql index f15ad4fbc5cb..850d48b6526d 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-305to306-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-305to306-cleanup.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-305to306.sql b/engine/schema/src/main/resources/META-INF/db/schema-305to306.sql index b1294a21054f..e9a620bb4ccd 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-305to306.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-305to306.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-306to307.sql b/engine/schema/src/main/resources/META-INF/db/schema-306to307.sql index a43833efa437..0ddee9ec5db4 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-306to307.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-306to307.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-307to410.sql b/engine/schema/src/main/resources/META-INF/db/schema-307to410.sql index 944d910fec40..55d78b594377 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-307to410.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-307to410.sql @@ -22,7 +22,7 @@ SET foreign_key_checks = 0; --- DB upgrade steps from 302-40 +-- DB upgrade steps from 302-40 CREATE TABLE `cloud`.`external_nicira_nvp_devices` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `uuid` varchar(255) UNIQUE, @@ -59,9 +59,9 @@ from information_schema.key_column_usage A JOIN information_schema.key_column_usage B ON B.table_name = 'physical_network_service_providers' AND B.COLUMN_NAME = 'provider_name' AND A.COLUMN_NAME ='physical_network_id' AND B.CONSTRAINT_NAME=A.CONSTRAINT_NAME where A.table_name = 'physical_network_service_providers' LIMIT 1); -PREPARE stmt1 FROM @constraintname; -EXECUTE stmt1; -DEALLOCATE PREPARE stmt1; +PREPARE stmt1 FROM @constraintname; +EXECUTE stmt1; +DEALLOCATE PREPARE stmt1; AlTER TABLE physical_network_service_providers ADD CONSTRAINT `fk_pnetwork_service_providers__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE; UPDATE `cloud`.`configuration` SET description='Do URL encoding for the api response, false by default' WHERE name='encode.api.response'; @@ -351,8 +351,8 @@ ALTER TABLE `cloud`.`vlan` ADD COLUMN `ip6_range` varchar(255); ALTER TABLE `cloud`.`data_center` ADD COLUMN `ip6_dns1` varchar(255); ALTER TABLE `cloud`.`data_center` ADD COLUMN `ip6_dns2` varchar(255); -UPDATE `cloud`.`networks` INNER JOIN `cloud`.`vlan` ON networks.id = vlan.network_id -SET networks.gateway = vlan.vlan_gateway, networks.ip6_gateway = vlan.ip6_gateway, networks.ip6_cidr = vlan.ip6_cidr +UPDATE `cloud`.`networks` INNER JOIN `cloud`.`vlan` ON networks.id = vlan.network_id +SET networks.gateway = vlan.vlan_gateway, networks.ip6_gateway = vlan.ip6_gateway, networks.ip6_cidr = vlan.ip6_cidr WHERE networks.data_center_id = vlan.data_center_id AND networks.physical_network_id = vlan.physical_network_id; -- DB views for list api diff --git a/engine/schema/src/main/resources/META-INF/db/schema-30to301.sql b/engine/schema/src/main/resources/META-INF/db/schema-30to301.sql index 0cc51e7d08f7..81339bf2a53d 100755 --- a/engine/schema/src/main/resources/META-INF/db/schema-30to301.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-30to301.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-40to410.sql b/engine/schema/src/main/resources/META-INF/db/schema-40to410.sql index 1b3a29b27a45..845b31ca04ac 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-40to410.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-40to410.sql @@ -457,15 +457,15 @@ ALTER TABLE `cloud`.`vlan` ADD COLUMN `ip6_range` varchar(255); ALTER TABLE `cloud`.`data_center` ADD COLUMN `ip6_dns1` varchar(255); ALTER TABLE `cloud`.`data_center` ADD COLUMN `ip6_dns2` varchar(255); -UPDATE `cloud`.`networks` INNER JOIN `cloud`.`vlan` ON networks.id = vlan.network_id -SET networks.gateway = vlan.vlan_gateway, networks.ip6_gateway = vlan.ip6_gateway, networks.ip6_cidr = vlan.ip6_cidr +UPDATE `cloud`.`networks` INNER JOIN `cloud`.`vlan` ON networks.id = vlan.network_id +SET networks.gateway = vlan.vlan_gateway, networks.ip6_gateway = vlan.ip6_gateway, networks.ip6_cidr = vlan.ip6_cidr WHERE networks.data_center_id = vlan.data_center_id AND networks.physical_network_id = vlan.physical_network_id; -- DB views for list api DROP VIEW IF EXISTS `cloud`.`user_vm_view`; CREATE VIEW `cloud`.`user_vm_view` AS - select + select vm_instance.id id, vm_instance.name name, user_vm.display_name display_name, @@ -504,7 +504,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS vm_instance.vm_type vm_type, data_center.id data_center_id, data_center.uuid data_center_uuid, - data_center.name data_center_name, + data_center.name data_center_name, data_center.is_security_group_enabled security_group_enabled, host.id host_id, host.uuid host_uuid, @@ -634,7 +634,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS DROP VIEW IF EXISTS `cloud`.`domain_router_view`; CREATE VIEW `cloud`.`domain_router_view` AS - select + select vm_instance.id id, vm_instance.name name, account.id account_id, @@ -740,7 +740,7 @@ CREATE VIEW `cloud`.`domain_router_view` AS DROP VIEW IF EXISTS `cloud`.`security_group_view`; CREATE VIEW `cloud`.`security_group_view` AS - select + select security_group.id id, security_group.name name, security_group.description description, @@ -799,7 +799,7 @@ CREATE VIEW `cloud`.`security_group_view` AS DROP VIEW IF EXISTS `cloud`.`resource_tag_view`; CREATE VIEW `cloud`.`resource_tag_view` AS - select + select resource_tags.id, resource_tags.uuid, resource_tags.key, @@ -831,7 +831,7 @@ CREATE VIEW `cloud`.`resource_tag_view` AS DROP VIEW IF EXISTS `cloud`.`event_view`; CREATE VIEW `cloud`.`event_view` AS - select + select event.id, event.uuid, event.type, @@ -870,7 +870,7 @@ CREATE VIEW `cloud`.`event_view` AS DROP VIEW IF EXISTS `cloud`.`instance_group_view`; CREATE VIEW `cloud`.`instance_group_view` AS - select + select instance_group.id, instance_group.uuid, instance_group.name, @@ -898,7 +898,7 @@ CREATE VIEW `cloud`.`instance_group_view` AS DROP VIEW IF EXISTS `cloud`.`user_view`; CREATE VIEW `cloud`.`user_view` AS - select + select user.id, user.uuid, user.username, @@ -941,7 +941,7 @@ CREATE VIEW `cloud`.`user_view` AS DROP VIEW IF EXISTS `cloud`.`project_view`; CREATE VIEW `cloud`.`project_view` AS - select + select projects.id, projects.uuid, projects.name, @@ -982,7 +982,7 @@ CREATE VIEW `cloud`.`project_view` AS DROP VIEW IF EXISTS `cloud`.`project_account_view`; CREATE VIEW `cloud`.`project_account_view` AS - select + select project_account.id, account.id account_id, account.uuid account_uuid, @@ -1007,7 +1007,7 @@ CREATE VIEW `cloud`.`project_account_view` AS DROP VIEW IF EXISTS `cloud`.`project_invitation_view`; CREATE VIEW `cloud`.`project_invitation_view` AS - select + select project_invitations.id, project_invitations.uuid, project_invitations.email, @@ -1035,7 +1035,7 @@ CREATE VIEW `cloud`.`project_invitation_view` AS DROP VIEW IF EXISTS `cloud`.`host_view`; CREATE VIEW `cloud`.`host_view` AS - select + select host.id, host.uuid, host.name, @@ -1105,7 +1105,7 @@ CREATE VIEW `cloud`.`host_view` AS DROP VIEW IF EXISTS `cloud`.`volume_view`; CREATE VIEW `cloud`.`volume_view` AS - select + select volumes.id, volumes.uuid, volumes.name, @@ -1206,7 +1206,7 @@ CREATE VIEW `cloud`.`volume_view` AS DROP VIEW IF EXISTS `cloud`.`account_netstats_view`; CREATE VIEW `cloud`.`account_netstats_view` AS - SELECT + SELECT account_id, sum(net_bytes_received) + sum(current_bytes_received) as bytesReceived, sum(net_bytes_sent) + sum(current_bytes_sent) as bytesSent @@ -1217,7 +1217,7 @@ CREATE VIEW `cloud`.`account_netstats_view` AS DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`; CREATE VIEW `cloud`.`account_vmstats_view` AS - SELECT + SELECT account_id, state, count(*) as vmcount from `cloud`.`vm_instance` @@ -1225,7 +1225,7 @@ CREATE VIEW `cloud`.`account_vmstats_view` AS DROP VIEW IF EXISTS `cloud`.`free_ip_view`; CREATE VIEW `cloud`.`free_ip_view` AS - select + select count(user_ip_address.id) free_ip from `cloud`.`user_ip_address` @@ -1237,7 +1237,7 @@ CREATE VIEW `cloud`.`free_ip_view` AS DROP VIEW IF EXISTS `cloud`.`account_view`; CREATE VIEW `cloud`.`account_view` AS - select + select account.id, account.uuid, account.account_name, @@ -1348,7 +1348,7 @@ CREATE VIEW `cloud`.`account_view` AS DROP VIEW IF EXISTS `cloud`.`async_job_view`; CREATE VIEW `cloud`.`async_job_view` AS - select + select account.id account_id, account.uuid account_uuid, account.account_name account_name, @@ -1457,7 +1457,7 @@ CREATE VIEW `cloud`.`async_job_view` AS DROP VIEW IF EXISTS `cloud`.`storage_pool_view`; CREATE VIEW `cloud`.`storage_pool_view` AS - select + select storage_pool.id, storage_pool.uuid, storage_pool.name, @@ -1475,7 +1475,7 @@ CREATE VIEW `cloud`.`storage_pool_view` AS cluster.cluster_type, data_center.id data_center_id, data_center.uuid data_center_uuid, - data_center.name data_center_name, + data_center.name data_center_name, host_pod_ref.id pod_id, host_pod_ref.uuid pod_uuid, host_pod_ref.name pod_name, @@ -1507,7 +1507,7 @@ CREATE VIEW `cloud`.`storage_pool_view` AS DROP VIEW IF EXISTS `cloud`.`disk_offering_view`; CREATE VIEW `cloud`.`disk_offering_view` AS - select + select disk_offering.id, disk_offering.uuid, disk_offering.name, @@ -1532,7 +1532,7 @@ CREATE VIEW `cloud`.`disk_offering_view` AS DROP VIEW IF EXISTS `cloud`.`service_offering_view`; CREATE VIEW `cloud`.`service_offering_view` AS - select + select service_offering.id, disk_offering.uuid, disk_offering.name, @@ -1563,10 +1563,10 @@ CREATE VIEW `cloud`.`service_offering_view` AS `cloud`.`disk_offering` ON service_offering.id = disk_offering.id left join `cloud`.`domain` ON disk_offering.domain_id = domain.id; - + DROP VIEW IF EXISTS `cloud`.`data_center_view`; CREATE VIEW `cloud`.`data_center_view` AS - select + select data_center.id, data_center.uuid, data_center.name, @@ -1593,8 +1593,8 @@ CREATE VIEW `cloud`.`data_center_view` AS from `cloud`.`data_center` left join - `cloud`.`domain` ON data_center.domain_id = domain.id; - + `cloud`.`domain` ON data_center.domain_id = domain.id; + CREATE TABLE `cloud`.`baremetal_dhcp_devices` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', diff --git a/engine/schema/src/main/resources/META-INF/db/schema-410to420.sql b/engine/schema/src/main/resources/META-INF/db/schema-410to420.sql index 3556e7e1b4a2..35f73b35d3ca 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-410to420.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-410to420.sql @@ -113,7 +113,7 @@ CREATE TABLE `cloud`.`image_store` ( `uuid` varchar(255) COMMENT 'uuid of data store', `parent` varchar(255) COMMENT 'parent path for the storage server', `created` datetime COMMENT 'date the image store first signed on', - `removed` datetime COMMENT 'date removed if not null', + `removed` datetime COMMENT 'date removed if not null', `total_size` bigint unsigned COMMENT 'storage total size statistics', `used_bytes` bigint unsigned COMMENT 'storage available bytes statistics', PRIMARY KEY(`id`) @@ -131,7 +131,7 @@ CREATE TABLE `cloud`.`image_store_details` ( DROP VIEW IF EXISTS `cloud`.`image_store_view`; CREATE VIEW `cloud`.`image_store_view` AS - select + select image_store.id, image_store.uuid, image_store.name, @@ -153,9 +153,9 @@ CREATE VIEW `cloud`.`image_store_view` AS left join `cloud`.`image_store_details` ON image_store_details.store_id = image_store.id; - + -- here we have to allow null for store_id to accommodate baremetal case to search for ready templates since template state is only stored in this table --- FK also commented out due to this +-- FK also commented out due to this CREATE TABLE `cloud`.`template_store_ref` ( `id` bigint unsigned NOT NULL auto_increment, `store_id` bigint unsigned, @@ -165,7 +165,7 @@ CREATE TABLE `cloud`.`template_store_ref` ( `job_id` varchar(255), `download_pct` int(10) unsigned, `size` bigint unsigned, - `store_role` varchar(255), + `store_role` varchar(255), `physical_size` bigint unsigned DEFAULT 0, `download_state` varchar(255), `error_str` varchar(255), @@ -177,7 +177,7 @@ CREATE TABLE `cloud`.`template_store_ref` ( `is_copy` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'indicates whether this was copied ', `update_count` bigint unsigned, `ref_cnt` bigint unsigned DEFAULT 0, - `updated` datetime, + `updated` datetime, PRIMARY KEY (`id`), -- CONSTRAINT `fk_template_store_ref__store_id` FOREIGN KEY `fk_template_store_ref__store_id` (`store_id`) REFERENCES `image_store` (`id`) ON DELETE CASCADE, INDEX `i_template_store_ref__store_id`(`store_id`), @@ -193,7 +193,7 @@ CREATE TABLE `cloud`.`template_store_ref` ( -- ALTER TABLE `cloud`.`snapshots` DROP COLUMN `sechost_id`; -- change upload host_id FK to point to image_store table -ALTER TABLE `cloud`.`upload` DROP FOREIGN KEY `fk_upload__host_id`; +ALTER TABLE `cloud`.`upload` DROP FOREIGN KEY `fk_upload__host_id`; ALTER TABLE `cloud`.`upload` ADD CONSTRAINT `fk_upload__store_id` FOREIGN KEY(`host_id`) REFERENCES `image_store` (`id`) ON DELETE CASCADE; CREATE TABLE `cloud`.`snapshot_store_ref` ( @@ -208,11 +208,11 @@ CREATE TABLE `cloud`.`snapshot_store_ref` ( `physical_size` bigint unsigned DEFAULT 0, `parent_snapshot_id` bigint unsigned DEFAULT 0, `install_path` varchar(255), - `state` varchar(255) NOT NULL, - -- `removed` datetime COMMENT 'date removed if not null', + `state` varchar(255) NOT NULL, + -- `removed` datetime COMMENT 'date removed if not null', `update_count` bigint unsigned, `ref_cnt` bigint unsigned, - `updated` datetime, + `updated` datetime, `volume_id` bigint unsigned, PRIMARY KEY (`id`), INDEX `i_snapshot_store_ref__store_id`(`store_id`), @@ -238,11 +238,11 @@ CREATE TABLE `cloud`.`volume_store_ref` ( `install_path` varchar(255), `url` varchar(255), `download_url` varchar(255), - `state` varchar(255) NOT NULL, + `state` varchar(255) NOT NULL, `destroyed` tinyint(1) COMMENT 'indicates whether the volume_host entry was destroyed by the user or not', `update_count` bigint unsigned, `ref_cnt` bigint unsigned, - `updated` datetime, + `updated` datetime, PRIMARY KEY (`id`), CONSTRAINT `fk_volume_store_ref__store_id` FOREIGN KEY `fk_volume_store_ref__store_id` (`store_id`) REFERENCES `image_store` (`id`) ON DELETE CASCADE, INDEX `i_volume_store_ref__store_id`(`store_id`), @@ -662,12 +662,12 @@ ALTER TABLE `cloud`.`remote_access_vpn` ADD COLUMN `id` bigint unsigned NOT NULL ALTER TABLE `cloud`.`remote_access_vpn` ADD COLUMN `uuid` varchar(40) UNIQUE; -- START: support for LXC - + INSERT IGNORE INTO `cloud`.`hypervisor_capabilities`(uuid, hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled) VALUES (UUID(), 'LXC', 'default', 50, 1); ALTER TABLE `cloud`.`physical_network_traffic_types` ADD COLUMN `lxc_network_label` varchar(255) DEFAULT 'cloudbr0' COMMENT 'The network name label of the physical device dedicated to this traffic on a LXC host'; - + UPDATE configuration SET value='KVM,XenServer,VMware,BareMetal,Ovm,LXC' WHERE name='hypervisor.list'; - + INSERT INTO `cloud`.`vm_template` (id, uuid, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones, hypervisor_type) VALUES (10, UUID(), 'routing-10', 'SystemVM Template (LXC)', 0, now(), 'SYSTEM', 0, 64, 1, 'http://download.cloudstack.org/templates/acton/acton-systemvm-02062012.qcow2.bz2', '2755de1f9ef2ce4d6f2bee2efbb4da92', 0, 'SystemVM Template (LXC)', 'QCOW2', 15, 0, 1, 'LXC'); @@ -717,10 +717,10 @@ CREATE TABLE `cloud`.`service_offering_details` ( CONSTRAINT `fk_service_offering_details__service_offering_id` FOREIGN KEY (`service_offering_id`) REFERENCES `service_offering`(`id`) ON DELETE CASCADE, CONSTRAINT UNIQUE KEY `uk_service_offering_id_name` (`service_offering_id`, `name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - + DROP VIEW IF EXISTS `cloud`.`user_vm_view`; CREATE VIEW `cloud`.`user_vm_view` AS - select + select vm_instance.id id, vm_instance.name name, user_vm.display_name display_name, @@ -898,7 +898,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS DROP VIEW IF EXISTS `cloud`.`affinity_group_view`; CREATE VIEW `cloud`.`affinity_group_view` AS - select + select affinity_group.id id, affinity_group.name name, affinity_group.type type, @@ -933,7 +933,7 @@ CREATE VIEW `cloud`.`affinity_group_view` AS DROP VIEW IF EXISTS `cloud`.`host_view`; CREATE VIEW `cloud`.`host_view` AS - select + select host.id, host.uuid, host.name, @@ -1001,10 +1001,10 @@ CREATE VIEW `cloud`.`host_view` AS `cloud`.`async_job` ON async_job.instance_id = host.id and async_job.instance_type = 'Host' and async_job.job_status = 0; - + DROP VIEW IF EXISTS `cloud`.`storage_pool_view`; CREATE VIEW `cloud`.`storage_pool_view` AS - select + select storage_pool.id, storage_pool.uuid, storage_pool.name, @@ -1024,7 +1024,7 @@ CREATE VIEW `cloud`.`storage_pool_view` AS cluster.cluster_type, data_center.id data_center_id, data_center.uuid data_center_uuid, - data_center.name data_center_name, + data_center.name data_center_name, data_center.networktype data_center_type, host_pod_ref.id pod_id, host_pod_ref.uuid pod_uuid, @@ -1054,11 +1054,11 @@ CREATE VIEW `cloud`.`storage_pool_view` AS `cloud`.`async_job` ON async_job.instance_id = storage_pool.id and async_job.instance_type = 'StoragePool' and async_job.job_status = 0; - + DROP VIEW IF EXISTS `cloud`.`domain_router_view`; CREATE VIEW `cloud`.`domain_router_view` AS - select + select vm_instance.id id, vm_instance.name name, account.id account_id, @@ -1157,7 +1157,7 @@ CREATE VIEW `cloud`.`domain_router_view` AS `cloud`.`async_job` ON async_job.instance_id = vm_instance.id and async_job.instance_type = 'DomainRouter' and async_job.job_status = 0; - + CREATE TABLE `cloud`.`external_cisco_vnmc_devices` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `uuid` varchar(255) UNIQUE, @@ -1242,7 +1242,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag DROP VIEW IF EXISTS `cloud`.`service_offering_view`; CREATE VIEW `cloud`.`service_offering_view` AS - select + select service_offering.id, disk_offering.uuid, disk_offering.name, @@ -1289,7 +1289,7 @@ UPDATE `cloud_usage`.`account` SET `default`=1 WHERE id IN (1,2); UPDATE `cloud`.`user` SET `cloud`.`user`.`default`=1 WHERE id IN (1,2); CREATE OR REPLACE VIEW `cloud`.`user_view` AS - select + select user.id, user.uuid, user.username, @@ -1329,7 +1329,7 @@ CREATE OR REPLACE VIEW `cloud`.`user_view` AS `cloud`.`async_job` ON async_job.instance_id = user.id and async_job.instance_type = 'User' and async_job.job_status = 0; - + DROP VIEW IF EXISTS `cloud`.`account_view`; CREATE VIEW `cloud`.`account_view` AS @@ -1879,7 +1879,7 @@ ALTER TABLE `cloud`.`account_details` MODIFY value varchar(255); DROP VIEW IF EXISTS `cloud`.`template_view`; CREATE VIEW `cloud`.`template_view` AS - select + select vm_template.id, vm_template.uuid, vm_template.unique_name, @@ -1920,7 +1920,7 @@ CREATE VIEW `cloud`.`template_view` AS domain.path domain_path, projects.id project_id, projects.uuid project_uuid, - projects.name project_name, + projects.name project_name, data_center.id data_center_id, data_center.uuid data_center_uuid, data_center.name data_center_name, @@ -1950,23 +1950,23 @@ CREATE VIEW `cloud`.`template_view` AS from `cloud`.`vm_template` inner join - `cloud`.`guest_os` ON guest_os.id = vm_template.guest_os_id + `cloud`.`guest_os` ON guest_os.id = vm_template.guest_os_id inner join `cloud`.`account` ON account.id = vm_template.account_id inner join `cloud`.`domain` ON domain.id = account.domain_id left join - `cloud`.`projects` ON projects.project_account_id = account.id + `cloud`.`projects` ON projects.project_account_id = account.id left join - `cloud`.`vm_template_details` ON vm_template_details.template_id = vm_template.id + `cloud`.`vm_template_details` ON vm_template_details.template_id = vm_template.id left join - `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id + `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id left join `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id and template_store_ref.store_role = 'Image' left join - `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id is not NULL AND image_store.id = template_store_ref.store_id + `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id is not NULL AND image_store.id = template_store_ref.store_id left join - `cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id AND template_store_ref.store_id is NULL AND template_zone_ref.removed is null + `cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id AND template_store_ref.store_id is NULL AND template_zone_ref.removed is null left join `cloud`.`data_center` ON (image_store.data_center_id = data_center.id OR template_zone_ref.zone_id = data_center.id) left join @@ -1974,7 +1974,7 @@ CREATE VIEW `cloud`.`template_view` AS left join `cloud`.`resource_tags` ON resource_tags.resource_id = vm_template.id and (resource_tags.resource_type = 'Template' or resource_tags.resource_type='ISO'); - + INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'midonet.apiserver.address', 'http://localhost:8081', 'Specify the address at which the Midonet API server can be contacted (if using Midonet)'); INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'management-server', 'midonet.providerrouter.id', 'd7c5e6a3-e2f4-426b-b728-b7ce6a0448e5', 'Specifies the UUID of the Midonet provider router (if using Midonet)'); @@ -1996,7 +1996,7 @@ CREATE TABLE `cloud`.`account_vnet_map` ( ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD COLUMN account_vnet_map_id bigint unsigned; ALTER TABLE `cloud`.`op_dc_vnet_alloc` ADD CONSTRAINT `fk_op_dc_vnet_alloc__account_vnet_map_id` FOREIGN KEY `fk_op_dc_vnet_alloc__account_vnet_map_id` (`account_vnet_map_id`) REFERENCES `account_vnet_map` (`id`); - + update `cloud`.`vm_template` set state='Allocated' where state is NULL; update `cloud`.`vm_template` set update_count=0 where update_count is NULL; @@ -2100,7 +2100,7 @@ CREATE TABLE `cloud`.`vm_disk_statistics` ( CONSTRAINT `fk_vm_disk_statistics__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; -insert into `cloud`.`vm_disk_statistics`(data_center_id,account_id,vm_id,volume_id) +insert into `cloud`.`vm_disk_statistics`(data_center_id,account_id,vm_id,volume_id) select volumes.data_center_id, volumes.account_id, vm_instance.id, volumes.id from volumes,vm_instance where vm_instance.vm_type="User" and vm_instance.state<>"Expunging" and volumes.instance_id=vm_instance.id order by vm_instance.id; DROP TABLE IF EXISTS `cloud`.`ovs_providers`; @@ -2166,7 +2166,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'vm.disk.throttling.bytes_write_rate', 0, 'Default disk I/O write rate in bytes per second allowed in User vm\'s disk. '); -- Re-enable foreign key checking, at the end of the upgrade path -SET foreign_key_checks = 1; +SET foreign_key_checks = 1; UPDATE `cloud`.`snapshot_policy` set uuid=id WHERE uuid is NULL; #update shared sg enabled network with not null name in Advance Security Group enabled network @@ -2220,7 +2220,7 @@ CREATE TABLE `cloud`.`external_stratosphere_ssp_credentials` ( DROP VIEW IF EXISTS `cloud`.`project_view`; CREATE VIEW `cloud`.`project_view` AS - select + select projects.id, projects.uuid, projects.name, @@ -2264,7 +2264,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Network', 'DEFAULT', 'manage ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `concurrent_connections` int(10) unsigned COMMENT 'Load Balancer(haproxy) maximum number of concurrent connections(global max)'; - + ALTER TABLE `cloud`.`sync_queue` MODIFY `queue_size` smallint(6) NOT NULL DEFAULT '0' COMMENT 'number of items being processed by the queue'; ALTER TABLE `cloud`.`sync_queue` MODIFY `queue_size_limit` smallint(6) NOT NULL DEFAULT '1' COMMENT 'max number of items the queue can process concurrently'; @@ -2280,7 +2280,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'manag #update the account_vmstats_view - count only user vms DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`; CREATE VIEW `cloud`.`account_vmstats_view` AS - SELECT + SELECT account_id, state, count(*) as vmcount from `cloud`.`vm_instance` @@ -2329,7 +2329,7 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ("Advanced", 'DEFAULT', 'manag DROP VIEW IF EXISTS `cloud`.`data_center_view`; CREATE VIEW `cloud`.`data_center_view` AS - select + select data_center.id, data_center.uuid, data_center.name, diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql b/engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql index fbbf0a2aef8a..603e7712ebc0 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41310to41400.sql @@ -19,7 +19,7 @@ -- Schema upgrade from 4.13.1.0 to 4.14.0.0 --; --- Update the description to indicate this only works with KVM + Ceph +-- Update the description to indicate this only works with KVM + Ceph -- (not implemented properly atm for KVM+NFS/local, and it accidentally works with XS + NFS. Not applicable for VMware) UPDATE `cloud`.`configuration` SET `description`='Indicates whether to always backup primary storage snapshot to secondary storage. Keeping snapshots only on Primary storage is applicable for KVM + Ceph only.' WHERE `name`='snapshot.backup.to.secondary'; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41910to42000-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-41910to42000-cleanup.sql new file mode 100644 index 000000000000..4bbeadaf8118 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/schema-41910to42000-cleanup.sql @@ -0,0 +1,20 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +--; +-- Schema upgrade cleanup from 4.19.0.0 to 4.20.0.0 +--; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41910to42000.sql b/engine/schema/src/main/resources/META-INF/db/schema-41910to42000.sql new file mode 100644 index 000000000000..c36b71c2f250 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/schema-41910to42000.sql @@ -0,0 +1,427 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +--; +-- Schema upgrade from 4.19.0.0 to 4.20.0.0 +--; + +-- Add tag column to tables +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_limit', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the limit" '); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_count', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the resource count" '); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_reservation', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the resource reservation" '); +CALL `cloud`.`IDEMPOTENT_DROP_INDEX`('i_resource_count__type_accountId', 'cloud.resource_count'); +CALL `cloud`.`IDEMPOTENT_DROP_INDEX`('i_resource_count__type_domaintId', 'cloud.resource_count'); + +DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_UNIQUE_INDEX`; +CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_UNIQUE_INDEX` ( + IN in_table_name VARCHAR(200), + IN in_index_name VARCHAR(200), + IN in_index_definition VARCHAR(1000) +) +BEGIN + DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name, ' ', 'ADD UNIQUE INDEX ', in_index_name, ' ', in_index_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END; + +CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_INDEX`('cloud.resource_count', 'i_resource_count__type_tag_accountId', '(type, tag, account_id)'); +CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_INDEX`('cloud.resource_count', 'i_resource_count__type_tag_domainId', '(type, tag, domain_id)'); + +ALTER TABLE `cloud`.`resource_reservation` + MODIFY COLUMN `amount` bigint NOT NULL; + +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_reservation', 'resource_id', 'bigint unsigned NULL COMMENT "id of the resource" '); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_reservation', 'mgmt_server_id', 'bigint unsigned NULL COMMENT "management server id" '); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_reservation', 'created', 'datetime DEFAULT NULL COMMENT "date when the reservation was created" '); + +UPDATE `cloud`.`resource_reservation` SET `created` = now() WHERE created IS NULL; + + +-- Update Default System offering for Router to 512MiB +UPDATE `cloud`.`service_offering` SET ram_size = 512 WHERE unique_name IN ("Cloud.Com-SoftwareRouter", "Cloud.Com-SoftwareRouter-Local", + "Cloud.Com-InternalLBVm", "Cloud.Com-InternalLBVm-Local", + "Cloud.Com-ElasticLBVm", "Cloud.Com-ElasticLBVm-Local") + AND system_use = 1 AND ram_size < 512; + +-- NSX Plugin -- +CREATE TABLE `cloud`.`nsx_providers` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `uuid` varchar(40), + `zone_id` bigint unsigned NOT NULL COMMENT 'Zone ID', + `host_id` bigint unsigned NOT NULL COMMENT 'Host ID', + `provider_name` varchar(40), + `hostname` varchar(255) NOT NULL, + `port` varchar(255), + `username` varchar(255) NOT NULL, + `password` varchar(255) NOT NULL, + `tier0_gateway` varchar(255), + `edge_cluster` varchar(255), + `transport_zone` varchar(255), + `created` datetime NOT NULL COMMENT 'date created', + `removed` datetime COMMENT 'date removed if not null', + PRIMARY KEY (`id`), + CONSTRAINT `fk_nsx_providers__zone_id` FOREIGN KEY `fk_nsx_providers__zone_id` (`zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE, + INDEX `i_nsx_providers__zone_id`(`zone_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- NSX Plugin -- +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','for_nsx', 'int(1) unsigned DEFAULT "0" COMMENT "is nsx enabled for the resource"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','nsx_mode', 'varchar(32) COMMENT "mode in which the network would route traffic"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','for_nsx', 'int(1) unsigned DEFAULT "0" COMMENT "is nsx enabled for the resource"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','nsx_mode', 'varchar(32) COMMENT "mode in which the network would route traffic"'); + +-- Create table to persist quota email template configurations +CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_email_configuration`( + `account_id` int(11) NOT NULL, + `email_template_id` bigint(20) NOT NULL, + `enabled` int(1) UNSIGNED NOT NULL, + PRIMARY KEY (`account_id`, `email_template_id`), + CONSTRAINT `FK_quota_email_configuration_account_id` FOREIGN KEY (`account_id`) REFERENCES `cloud_usage`.`quota_account`(`account_id`), + CONSTRAINT `FK_quota_email_configuration_email_template_id` FOREIGN KEY (`email_template_id`) REFERENCES `cloud_usage`.`quota_email_templates`(`id`)); + +-- Remove on delete cascade from snapshot schedule +ALTER TABLE `cloud`.`snapshot_schedule` DROP CONSTRAINT `fk__snapshot_schedule_async_job_id`; + +-- Add `is_implicit` column to `host_tags` table +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.host_tags', 'is_implicit', 'int(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT "If host tag is implicit or explicit" '); + +-- Fields related to Snapshot Extraction +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.snapshot_store_ref', 'download_url', 'varchar(2048) DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.snapshot_store_ref', 'download_url_created', 'datetime DEFAULT NULL'); + +-- Webhooks feature +DROP TABLE IF EXISTS `cloud`.`webhook`; +CREATE TABLE `cloud`.`webhook` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the webhook', + `uuid` varchar(255) COMMENT 'uuid of the webhook', + `name` varchar(255) NOT NULL COMMENT 'name of the webhook', + `description` varchar(4096) COMMENT 'description for the webhook', + `state` char(32) NOT NULL COMMENT 'state of the webhook - Enabled or Disabled', + `domain_id` bigint unsigned NOT NULL COMMENT 'id of the owner domain of the webhook', + `account_id` bigint unsigned NOT NULL COMMENT 'id of the owner account of the webhook', + `payload_url` varchar(255) COMMENT 'payload URL for the webhook', + `secret_key` varchar(255) COMMENT 'secret key for the webhook', + `ssl_verification` boolean COMMENT 'for https payload url, if true then strict ssl verification', + `scope` char(32) NOT NULL COMMENT 'scope for the webhook - Local, Domain, Global', + `created` datetime COMMENT 'date the webhook was created', + `removed` datetime COMMENT 'date removed if not null', + PRIMARY KEY(`id`), + INDEX `i_webhook__account_id`(`account_id`), + CONSTRAINT `fk_webhook__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +DROP TABLE IF EXISTS `cloud`.`webhook_delivery`; +CREATE TABLE `cloud`.`webhook_delivery` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the webhook delivery', + `uuid` varchar(255) COMMENT 'uuid of the webhook', + `event_id` bigint unsigned NOT NULL COMMENT 'id of the event', + `webhook_id` bigint unsigned NOT NULL COMMENT 'id of the webhook', + `mshost_msid` bigint unsigned NOT NULL COMMENT 'msid of the management server', + `headers` TEXT COMMENT 'headers for the webhook delivery', + `payload` TEXT COMMENT 'payload for the webhook delivery', + `success` boolean COMMENT 'webhook delivery succeeded or not', + `response` TEXT COMMENT 'response of the webhook delivery', + `start_time` datetime COMMENT 'start timestamp of the webhook delivery', + `end_time` datetime COMMENT 'end timestamp of the webhook delivery', + PRIMARY KEY(`id`), + INDEX `i_webhook__event_id`(`event_id`), + INDEX `i_webhook__webhook_id`(`webhook_id`), + CONSTRAINT `fk_webhook__event_id` FOREIGN KEY (`event_id`) REFERENCES `event`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_webhook__webhook_id` FOREIGN KEY (`webhook_id`) REFERENCES `webhook`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Normalize quota.usage.smtp.useStartTLS, quota.usage.smtp.useAuth, alert.smtp.useAuth and project.smtp.useAuth values +UPDATE + `cloud`.`configuration` +SET + value = "true" +WHERE + name IN ("quota.usage.smtp.useStartTLS", "quota.usage.smtp.useAuth", "alert.smtp.useAuth", "project.smtp.useAuth") + AND value IN ("true", "y", "t", "1", "on", "yes"); + +UPDATE + `cloud`.`configuration` +SET + value = "false" +WHERE + name IN ("quota.usage.smtp.useStartTLS", "quota.usage.smtp.useAuth", "alert.smtp.useAuth", "project.smtp.useAuth") + AND value NOT IN ("true", "y", "t", "1", "on", "yes"); + +-- Create tables for static and dynamic routing +CREATE TABLE `cloud`.`dc_ip4_guest_subnets` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `uuid` varchar(40) DEFAULT NULL, + `data_center_id` bigint(20) unsigned NOT NULL COMMENT 'zone it belongs to', + `subnet` varchar(255) NOT NULL COMMENT 'subnet of the ip4 network', + `domain_id` bigint unsigned DEFAULT NULL COMMENT 'domain the subnet belongs to', + `account_id` bigint unsigned DEFAULT NULL COMMENT 'owner of this subnet', + `created` datetime DEFAULT NULL, + `removed` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `fk_dc_ip4_guest_subnets__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`), + CONSTRAINT `fk_dc_ip4_guest_subnets__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`), + CONSTRAINT `fk_dc_ip4_guest_subnets__account_id` FOREIGN KEY (`account_id`) REFERENCES `account`(`id`), + CONSTRAINT `uc_dc_ip4_guest_subnets__uuid` UNIQUE (`uuid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`ip4_guest_subnet_network_map` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `uuid` varchar(40) DEFAULT NULL, + `parent_id` bigint(20) unsigned COMMENT 'ip4 guest subnet which subnet belongs to', + `subnet` varchar(255) NOT NULL COMMENT 'subnet of the ip4 network', + `network_id` bigint(20) unsigned DEFAULT NULL COMMENT 'network which subnet is associated to', + `vpc_id` bigint(20) unsigned DEFAULT NULL COMMENT 'VPC which subnet is associated to', + `state` varchar(255) NOT NULL COMMENT 'state of the subnet', + `allocated` datetime DEFAULT NULL, + `created` datetime DEFAULT NULL, + `removed` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `fk_ip4_guest_subnet_network_map__parent_id` FOREIGN KEY (`parent_id`) REFERENCES `dc_ip4_guest_subnets`(`id`), + CONSTRAINT `fk_ip4_guest_subnet_network_map__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`), + CONSTRAINT `fk_ip4_guest_subnet_network_map__vpc_id` FOREIGN KEY (`vpc_id`) REFERENCES `vpc`(`id`), + CONSTRAINT `uc_ip4_guest_subnet_network_map__uuid` UNIQUE (`uuid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('network_offerings', 'nsx_mode', 'network_mode', 'varchar(32) COMMENT "mode in which the network would route traffic"'); +CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('vpc_offerings', 'nsx_mode', 'network_mode', 'varchar(32) COMMENT "mode in which the network would route traffic"'); +ALTER TABLE `cloud`.`event` MODIFY COLUMN `type` varchar(50) NOT NULL; + +-- Add tables for AS Numbers and range +CREATE TABLE IF NOT EXISTS `cloud`.`as_number_range` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT, + `uuid` varchar(40) DEFAULT NULL, + `data_center_id` bigint unsigned NOT NULL COMMENT 'zone that it belongs to', + `start_as_number` bigint unsigned NOT NULL COMMENT 'start AS number of the range', + `end_as_number` bigint unsigned NOT NULL COMMENT 'end AS number of the range', + `created` datetime DEFAULT NULL COMMENT 'date created', + `removed` datetime DEFAULT NULL COMMENT 'date removed', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_as_number_range__uuid` (`uuid`), + UNIQUE KEY `uk_as_number_range__range` (`data_center_id`,`start_as_number`,`end_as_number`, `removed`), + CONSTRAINT `fk_as_number_range__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `cloud`.`as_number` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT, + `uuid` varchar(40) DEFAULT NULL, + `account_id` bigint unsigned DEFAULT NULL, + `domain_id` bigint unsigned DEFAULT NULL, + `as_number` bigint unsigned NOT NULL COMMENT 'the AS Number', + `as_number_range_id` bigint unsigned NOT NULL, + `data_center_id` bigint unsigned NOT NULL COMMENT 'zone that it belongs to', + `allocated` datetime DEFAULT NULL COMMENT 'Date this AS Number was allocated to some network', + `is_allocated` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'indicates if the AS Number is allocated to some network', + `network_id` bigint unsigned DEFAULT NULL COMMENT 'Network this AS Number is associated with', + `vpc_id` bigint unsigned DEFAULT NULL COMMENT 'VPC this AS Number is associated with', + `created` datetime DEFAULT NULL COMMENT 'date created', + `removed` datetime DEFAULT NULL COMMENT 'date removed', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_as_number__uuid` (`uuid`), + UNIQUE KEY `uk_as_number__number` (`data_center_id`,`as_number`,`as_number_range_id`), + CONSTRAINT `fk_as_number__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`), + CONSTRAINT `fk_as_number__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_as_number__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks` (`id`), + CONSTRAINT `fk_as_number__as_number_range_id` FOREIGN KEY (`as_number_range_id`) REFERENCES `as_number_range` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','routing_mode', 'varchar(10) COMMENT "routing mode for the offering"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','specify_as_number', 'tinyint(1) NOT NULL DEFAULT 0 COMMENT "specify AS number when using dynamic routing"'); + +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','routing_mode', 'varchar(10) COMMENT "routing mode for the offering"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','specify_as_number', 'tinyint(1) NOT NULL DEFAULT 0 COMMENT "specify AS number when using dynamic routing"'); + +-- Tables for Dynamic Routing +CREATE TABLE IF NOT EXISTS `cloud`.`bgp_peers` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT, + `uuid` varchar(40) DEFAULT NULL, + `data_center_id` bigint(20) unsigned NOT NULL COMMENT 'zone it belongs to', + `ip4_address` varchar(40) DEFAULT NULL COMMENT 'IPv4 address of the BGP peer', + `ip6_address` varchar(40) DEFAULT NULL COMMENT 'IPv6 address of the BGP peer', + `as_number` bigint unsigned NOT NULL COMMENT 'AS number of the BGP peer', + `password` varchar(255) DEFAULT NULL COMMENT 'Password of the BGP peer', + `domain_id` bigint unsigned DEFAULT NULL COMMENT 'domain the subnet belongs to', + `account_id` bigint unsigned DEFAULT NULL COMMENT 'owner of this subnet', + `created` datetime DEFAULT NULL COMMENT 'date created', + `removed` datetime DEFAULT NULL COMMENT 'date removed', + PRIMARY KEY (`id`), + UNIQUE KEY `uk_bgp_peers__uuid` (`uuid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`bgp_peer_details` ( + `id` bigint unsigned NOT NULL auto_increment, + `bgp_peer_id` bigint unsigned NOT NULL COMMENT 'bgp peer id', + `name` varchar(255) NOT NULL, + `value` varchar(1024) NOT NULL, + `display` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'True if the detail can be displayed to the end user', + PRIMARY KEY (`id`), + CONSTRAINT `fk_bgp_peer_details__bgp_peer_id` FOREIGN KEY `fk_bgp_peer_details__bgp_peer_id`(`bgp_peer_id`) REFERENCES `bgp_peers`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `cloud`.`bgp_peer_network_map` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `bgp_peer_id` bigint(20) unsigned COMMENT 'id of the BGP peer', + `network_id` bigint(20) unsigned DEFAULT NULL COMMENT 'network which BGP peer is associated to', + `vpc_id` bigint(20) unsigned DEFAULT NULL COMMENT 'vpc which BGP peer is associated to', + `state` varchar(40) DEFAULT NULL, + `created` datetime DEFAULT NULL COMMENT 'date created', + `removed` datetime DEFAULT NULL COMMENT 'date removed', + PRIMARY KEY (`id`), + CONSTRAINT `fk_bgp_peer_network_map__bgp_peer_id` FOREIGN KEY (`bgp_peer_id`) REFERENCES `bgp_peers`(`id`), + CONSTRAINT `fk_bgp_peer_network_map__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`), + CONSTRAINT `fk_bgp_peer_network_map__vpc_id` FOREIGN KEY (`vpc_id`) REFERENCES `vpc`(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`shared_filesystem`( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'ID', + `uuid` varchar(40) COMMENT 'UUID', + `name` varchar(255) NOT NULL COMMENT 'Name of the shared filesystem', + `description` varchar(1024) COMMENT 'Description', + `domain_id` bigint unsigned NOT NULL COMMENT 'Domain ID', + `account_id` bigint unsigned NOT NULL COMMENT 'Account ID', + `data_center_id` bigint unsigned NOT NULL COMMENT 'Data center ID', + `state` varchar(12) NOT NULL COMMENT 'State of the shared filesystem in the FSM', + `fs_provider_name` varchar(255) COMMENT 'Name of the shared filesystem provider', + `protocol` varchar(10) COMMENT 'Protocol supported by the shared filesystem', + `volume_id` bigint unsigned COMMENT 'Volume which the shared filesystem is using as storage', + `vm_id` bigint unsigned COMMENT 'vm on which the shared filesystem is hosted', + `fs_type` varchar(10) NOT NULL COMMENT 'The filesystem format to be used for the shared filesystem', + `service_offering_id` bigint unsigned COMMENT 'Service offering for the vm', + `update_count` bigint unsigned COMMENT 'Update count for state change', + `updated` datetime COMMENT 'date updated', + `created` datetime NOT NULL COMMENT 'date created', + `removed` datetime COMMENT 'date removed if not null', + PRIMARY KEY (`id`), + CONSTRAINT `uc_shared_filesystem__uuid` UNIQUE (`uuid`), + INDEX `i_shared_filesystem__account_id`(`account_id`), + INDEX `i_shared_filesystem__domain_id`(`domain_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Quota inject tariff result into subsequent ones +CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.quota_tariff', 'position', 'bigint(20) NOT NULL DEFAULT 1 COMMENT "Position in the execution sequence for tariffs of the same type"'); + +-- Idempotent IDEMPOTENT_MODIFY_COLUMN_CHAR_SET +DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`; +CREATE PROCEDURE `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET` ( + IN in_table_name VARCHAR(200) +, IN in_column_name VARCHAR(200) +, IN in_column_type VARCHAR(200) +, IN in_column_definition VARCHAR(1000) +) +BEGIN + DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' MODIFY COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_type); SET @ddl = CONCAT(@ddl, ' ', ' CHARACTER SET utf8mb4'); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END; + +DROP PROCEDURE IF EXISTS `cloud_usage`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`; +CREATE PROCEDURE `cloud_usage`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET` ( + IN in_table_name VARCHAR(200) +, IN in_column_name VARCHAR(200) +, IN in_column_type VARCHAR(200) +, IN in_column_definition VARCHAR(1000) +) +BEGIN + DECLARE CONTINUE HANDLER FOR 1060 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name); SET @ddl = CONCAT(@ddl, ' ', ' MODIFY COLUMN') ; SET @ddl = CONCAT(@ddl, ' ', in_column_name); SET @ddl = CONCAT(@ddl, ' ', in_column_type); SET @ddl = CONCAT(@ddl, ' ', ' CHARACTER SET utf8mb4'); SET @ddl = CONCAT(@ddl, ' ', in_column_definition); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END; + +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('async_job', 'job_result', 'TEXT', 'COMMENT \'job result info\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('async_job', 'job_cmd_info', 'TEXT', 'COMMENT \'command parameter info\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('event', 'description', 'VARCHAR(1024)', 'NOT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('usage_event', 'resource_name', 'VARCHAR(255)', 'DEFAULT NULL'); +CALL `cloud_usage`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('usage_event', 'resource_name', 'VARCHAR(255)', 'DEFAULT NULL'); + +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('account', 'account_name', 'VARCHAR(100)', 'DEFAULT NULL COMMENT \'an account name set by the creator of the account, defaults to username for single accounts\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('affinity_group', 'description', 'VARCHAR(4096)', 'DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('annotations', 'annotation', 'TEXT', ''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('autoscale_vmgroups', 'name', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'name of the autoscale vm group\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('backup_offering', 'name', 'VARCHAR(255)', 'NOT NULL COMMENT \'backup offering name\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('backup_offering', 'description', 'VARCHAR(255)', 'NOT NULL COMMENT \'backup offering description\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('disk_offering', 'name', 'VARCHAR(255)', 'NOT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('disk_offering', 'unique_name', 'VARCHAR(32)', 'DEFAULT NULL COMMENT \'unique name\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('disk_offering', 'display_text', 'VARCHAR(4096)', 'DEFAULT NULL COMMENT \'Optional text set by the admin for display purpose only\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('instance_group', 'name', 'VARCHAR(255)', 'NOT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('kubernetes_cluster', 'name', 'VARCHAR(255)', 'NOT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('kubernetes_cluster', 'description', 'VARCHAR(4096)', 'DEFAULT NULL COMMENT \'display text for this Kubernetes cluster\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('kubernetes_supported_version', 'name', 'VARCHAR(255)', 'NOT NULL COMMENT \'the name of this Kubernetes version\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('network_offerings', 'name', 'VARCHAR(64)', 'DEFAULT NULL COMMENT \'name of the network offering\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('network_offerings', 'unique_name', 'VARCHAR(64)', 'DEFAULT NULL COMMENT \'unique name of the network offering\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('network_offerings', 'display_text', 'VARCHAR(255)', 'NOT NULL COMMENT \'text to display to users\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('networks', 'name', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'name for this network\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('networks', 'display_text', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'display text for this network\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('project_role', 'description', 'TEXT', 'COMMENT \'description of the project role\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('projects', 'name', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'project name\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('projects', 'display_text', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'project display text\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('roles', 'description', 'TEXT', 'COMMENT \'description of the role\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('service_offering', 'name', 'VARCHAR(255)', 'NOT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('service_offering', 'unique_name', 'VARCHAR(32)', 'DEFAULT NULL COMMENT \'unique name for offerings\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('service_offering', 'display_text', 'VARCHAR(4096)', 'DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('snapshots', 'name', 'VARCHAR(255)', 'NOT NULL COMMENT \'snapshot name\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('ssh_keypairs', 'keypair_name', 'VARCHAR(256)', 'NOT NULL COMMENT \'name of the key pair\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('user_vm', 'display_name', 'VARCHAR(255)', 'DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('user_vm_details', 'value', 'VARCHAR(5120)', 'NOT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('user', 'firstname', 'VARCHAR(255)', 'DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('user', 'lastname', 'VARCHAR(255)', 'DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('user_data', 'name', 'VARCHAR(256)', 'NOT NULL COMMENT \'name of the user data\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vm_instance', 'display_name', 'VARCHAR(255)', 'DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vm_snapshots', 'display_name', 'VARCHAR(255)', 'DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vm_snapshots', 'description', 'VARCHAR(255)', 'DEFAULT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vm_template', 'name', 'VARCHAR(255)', 'NOT NULL'); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vm_template', 'display_text', 'VARCHAR(4096)', 'DEFAULT NULL COMMENT \'Description text set by the admin for display purpose only\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('volumes', 'name', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'A user specified name for the volume\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vpc', 'name', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'vpc name\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vpc', 'display_text', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'vpc display text\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vpc_offerings', 'name', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'vpc offering name\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vpc_offerings', 'unique_name', 'VARCHAR(64)', 'DEFAULT NULL COMMENT \'unique name of the vpc offering\''); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('vpc_offerings', 'display_text', 'VARCHAR(255)', 'DEFAULT NULL COMMENT \'display text\''); + +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.roles','state', 'varchar(10) NOT NULL default "enabled" COMMENT "role state"'); + +-- Multi-Arch Zones +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.cluster', 'arch', 'varchar(8) DEFAULT "x86_64" COMMENT "the CPU architecture of the hosts in the cluster"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.host', 'arch', 'varchar(8) DEFAULT "x86_64" COMMENT "the CPU architecture of the host"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_template', 'arch', 'varchar(8) DEFAULT "x86_64" COMMENT "the CPU architecture of the template/ISO"'); + +-- NAS B&R Plugin Backup Repository +DROP TABLE IF EXISTS `cloud`.`backup_repository`; +CREATE TABLE `cloud`.`backup_repository` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the backup repository', + `uuid` varchar(255) NOT NULL COMMENT 'uuid of the backup repository', + `name` varchar(255) CHARACTER SET utf8mb4 NOT NULL COMMENT 'name of the backup repository', + `zone_id` bigint unsigned NOT NULL COMMENT 'id of zone', + `provider` varchar(255) NOT NULL COMMENT 'backup provider name', + `type` varchar(255) NOT NULL COMMENT 'backup repo type', + `address` varchar(1024) NOT NULL COMMENT 'url of the backup repository', + `mount_opts` varchar(1024) NOT NULL COMMENT 'mount options for the backup repository', + `used_bytes` bigint unsigned, + `capacity_bytes` bigint unsigned, + `created` datetime, + `removed` datetime, + PRIMARY KEY(`id`), + INDEX `i_backup_repository__uuid`(`uuid`), + INDEX `i_backup_repository__zone_id_provider`(`zone_id`, `provider`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Drop foreign key on backup_schedule, drop unique key on vm_id and re-add foreign key to allow multiple backup schedules to be created +ALTER TABLE `cloud`.`backup_schedule` DROP FOREIGN KEY fk_backup_schedule__vm_id; +ALTER TABLE `cloud`.`backup_schedule` DROP INDEX vm_id; +ALTER TABLE `cloud`.`backup_schedule` ADD CONSTRAINT fk_backup_schedule__vm_id FOREIGN KEY (vm_id) REFERENCES vm_instance(id) ON DELETE CASCADE; + +-- Add volume details to the backups table to keep track of the volumes being backed up +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backups', 'backed_volumes', 'text DEFAULT NULL COMMENT "details of backed-up volumes" '); +CALL `cloud`.`IDEMPOTENT_MODIFY_COLUMN_CHAR_SET`('backups', 'backed_volumes', 'TEXT', 'DEFAULT NULL COMMENT \'details of backed-up volumes\''); + +-- Add support for VMware 8.0u2 (8.0.2.x) and 8.0u3 (8.0.3.x) +INSERT IGNORE INTO `cloud`.`hypervisor_capabilities` (uuid, hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled, max_data_volumes_limit, max_hosts_per_cluster, storage_motion_supported, vm_snapshot_enabled) values (UUID(), 'VMware', '8.0.2', 1024, 0, 59, 64, 1, 1); +INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) SELECT UUID(),'VMware', '8.0.2', guest_os_name, guest_os_id, utc_timestamp(), 0 FROM `cloud`.`guest_os_hypervisor` WHERE hypervisor_type='VMware' AND hypervisor_version='8.0'; +INSERT IGNORE INTO `cloud`.`hypervisor_capabilities` (uuid, hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled, max_data_volumes_limit, max_hosts_per_cluster, storage_motion_supported, vm_snapshot_enabled) values (UUID(), 'VMware', '8.0.3', 1024, 0, 59, 64, 1, 1); +INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid, hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) SELECT UUID(),'VMware', '8.0.3', guest_os_name, guest_os_id, utc_timestamp(), 0 FROM `cloud`.`guest_os_hypervisor` WHERE hypervisor_type='VMware' AND hypervisor_version='8.0'; + +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_instance', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for vm" '); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for volumes" '); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-420to421.sql b/engine/schema/src/main/resources/META-INF/db/schema-420to421.sql index b99af287bc5e..25c025c56511 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-420to421.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-420to421.sql @@ -20,10 +20,10 @@ --; -INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 's3.singleupload.max.size', '5', +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 's3.singleupload.max.size', '5', 'The maximum size limit for S3 single part upload API(in GB). If it is set to 0, then it means always use multi-part upload to upload object to S3. If it is set to -1, then it means always use single-part upload to upload object to S3.'); -INSERT IGNORE INTO `cloud`.`configuration` VALUES ("Storage", 'DEFAULT', 'management-server', "enable.ha.storage.migration", "true", "Enable/disable storage migration across primary storage during HA"); +INSERT IGNORE INTO `cloud`.`configuration` VALUES ("Storage", 'DEFAULT', 'management-server', "enable.ha.storage.migration", "true", "Enable/disable storage migration across primary storage during HA"); UPDATE `cloud`.`configuration` SET description="Specify whether or not to reserve CPU based on CPU overprovisioning factor" where name="vmware.reserve.cpu"; UPDATE `cloud`.`configuration` SET description="Specify whether or not to reserve memory based on memory overprovisioning factor" where name="vmware.reserve.mem"; -- Remove Windows Server 8 from guest_os_type dropdown to use Windows Server 2012 diff --git a/engine/schema/src/main/resources/META-INF/db/schema-442to450.sql b/engine/schema/src/main/resources/META-INF/db/schema-442to450.sql index 90a52bd42732..d2ba408241e0 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-442to450.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-442to450.sql @@ -671,7 +671,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS resource_tags.resource_id tag_resource_id, resource_tags.resource_uuid tag_resource_uuid, resource_tags.resource_type tag_resource_type, - resource_tags.customer tag_customer, + resource_tags.customer tag_customer, async_job.id job_id, async_job.uuid job_uuid, async_job.job_status job_status, @@ -752,7 +752,7 @@ CREATE VIEW `cloud`.`user_vm_view` AS left join `cloud`.`user_vm_details` `custom_speed` ON (((`custom_speed`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_speed`.`name` = 'CpuSpeed'))) left join - `cloud`.`user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_ram_size`.`name` = 'memory'))); + `cloud`.`user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_ram_size`.`name` = 'memory'))); INSERT IGNORE INTO `cloud`.`guest_os` (id, uuid, category_id, display_name, created) VALUES (231, UUID(), 1, 'CentOS 5 (32-bit)', utc_timestamp()); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-481to490-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-481to490-cleanup.sql index 1868a0908006..b8dd0477db96 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-481to490-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-481to490-cleanup.sql @@ -22,7 +22,7 @@ -- Added in CLOUDSTACK-9340: General DB optimization, 4 cases: ----- 1) Incorrect PRIMARY key -ALTER TABLE `cloud`.`ovs_tunnel_network` +ALTER TABLE `cloud`.`ovs_tunnel_network` DROP PRIMARY KEY, ADD PRIMARY KEY (`id`), DROP INDEX `id` , diff --git a/engine/schema/src/main/resources/META-INF/db/schema-481to490.sql b/engine/schema/src/main/resources/META-INF/db/schema-481to490.sql index 49cfc8346c54..bac3b1e6fabd 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-481to490.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-481to490.sql @@ -23,9 +23,9 @@ ALTER TABLE `event` ADD INDEX `archived` (`archived`); ALTER TABLE `event` ADD INDEX `state` (`state`); DROP VIEW IF EXISTS `cloud`.`template_view`; -CREATE +CREATE VIEW `template_view` AS - SELECT + SELECT `vm_template`.`id` AS `id`, `vm_template`.`uuid` AS `uuid`, `vm_template`.`unique_name` AS `unique_name`, @@ -124,9 +124,9 @@ VIEW `template_view` AS OR (`resource_tags`.`resource_type` = 'ISO'))))); DROP VIEW IF EXISTS `cloud`.`volume_view`; -CREATE +CREATE VIEW `volume_view` AS - SELECT + SELECT `volumes`.`id` AS `id`, `volumes`.`uuid` AS `uuid`, `volumes`.`name` AS `name`, @@ -234,9 +234,9 @@ VIEW `volume_view` AS AND (`async_job`.`job_status` = 0)))); DROP VIEW IF EXISTS `cloud`.`user_vm_view`; -CREATE +CREATE VIEW `user_vm_view` AS - SELECT + SELECT `vm_instance`.`id` AS `id`, `vm_instance`.`name` AS `name`, `user_vm`.`display_name` AS `display_name`, @@ -423,10 +423,10 @@ ALTER TABLE `cloud`.`ssh_keypairs` ADD INDEX `i_public_key` (`public_key` (64) A ALTER TABLE `cloud`.`user_vm_details` ADD INDEX `i_name_vm_id` (`vm_id` ASC, `name` ASC); ALTER TABLE `cloud`.`instance_group` ADD INDEX `i_name` (`name` ASC); ------ 4) Some views query (Change view to improve account retrieval speed) +----- 4) Some views query (Change view to improve account retrieval speed) CREATE OR REPLACE VIEW `account_vmstats_view` AS - SELECT + SELECT `vm_instance`.`account_id` AS `account_id`, `vm_instance`.`state` AS `state`, COUNT(0) AS `vmcount` diff --git a/engine/schema/src/main/resources/META-INF/db/schema-4930to41000.sql b/engine/schema/src/main/resources/META-INF/db/schema-4930to41000.sql index dc0cd6d4d75a..23670757247a 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-4930to41000.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-4930to41000.sql @@ -147,7 +147,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`storage_pool_tags` ( ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -- Insert storage tags from storage_pool_details -INSERT INTO `cloud`.`storage_pool_tags` (pool_id, tag) SELECT pool_id, +INSERT INTO `cloud`.`storage_pool_tags` (pool_id, tag) SELECT pool_id, name FROM `cloud`.`storage_pool_details` WHERE value = 'true'; -- Alter view storage_pool_view @@ -227,7 +227,7 @@ ALTER TABLE `cloud`.`vm_snapshots` ADD CONSTRAINT `fk_vm_snapshots_service_offer INSERT INTO `cloud`.`vm_snapshot_details` (vm_snapshot_id, name, value) SELECT s.id, d.name, d.value FROM `cloud`.`user_vm_details` d JOIN `cloud`.`vm_instance` v ON (d.vm_id = v.id) -JOIN `cloud`.`service_offering` o ON (v.service_offering_id = o.id) +JOIN `cloud`.`service_offering` o ON (v.service_offering_id = o.id) JOIN `cloud`.`vm_snapshots` s ON (s.service_offering_id = o.id AND s.vm_id = v.id) WHERE (o.cpu is null AND o.speed IS NULL AND o.ram_size IS NULL) AND (d.name = 'cpuNumber' OR d.name = 'cpuSpeed' OR d.name = 'memory'); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-level.sql b/engine/schema/src/main/resources/META-INF/db/schema-level.sql index 72aade4e5016..fef961502fa5 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-level.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-level.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-snapshot-217to224.sql b/engine/schema/src/main/resources/META-INF/db/schema-snapshot-217to224.sql index 7320bda59063..5e29435855df 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-snapshot-217to224.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-snapshot-217to224.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/schema-snapshot-223to224.sql b/engine/schema/src/main/resources/META-INF/db/schema-snapshot-223to224.sql index 668cbb692b99..5c27eed68f00 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-snapshot-223to224.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-snapshot-223to224.sql @@ -5,9 +5,9 @@ -- to you under the Apache License, Version 2.0 (the -- "License"); you may not use this file except in compliance -- with the License. You may obtain a copy of the License at --- +-- -- http://www.apache.org/licenses/LICENSE-2.0 --- +-- -- Unless required by applicable law or agreed to in writing, -- software distributed under the License is distributed on an -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql index 27d70b4171c1..87546a9d1188 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql @@ -15,11 +15,9 @@ -- specific language governing permissions and limitations -- under the License. --- cloud.account_view source - +-- VIEW `cloud`.`account_view`; DROP VIEW IF EXISTS `cloud`.`account_view`; - CREATE VIEW `cloud`.`account_view` AS select `account`.`id` AS `id`, @@ -31,7 +29,7 @@ select `account`.`created` AS `created`, `account`.`removed` AS `removed`, `account`.`cleanup_needed` AS `cleanup_needed`, - `account`.`network_domain` AS `network_domain`, + `account`.`network_domain` AS `network_domain` , `account`.`default` AS `default`, `domain`.`id` AS `domain_id`, `domain`.`uuid` AS `domain_uuid`, @@ -74,93 +72,93 @@ select `async_job`.`job_status` AS `job_status`, `async_job`.`account_id` AS `job_account_id` from - (`free_ip_view` -join ((((((((((((((((((((((((((((((`account` -join `domain` on - ((`account`.`domain_id` = `domain`.`id`))) -left join `data_center` on - ((`account`.`default_zone_id` = `data_center`.`id`))) -left join `account_netstats_view` on - ((`account`.`id` = `account_netstats_view`.`account_id`))) -left join `resource_limit` `vmlimit` on - (((`account`.`id` = `vmlimit`.`account_id`) - and (`vmlimit`.`type` = 'user_vm')))) -left join `resource_count` `vmcount` on - (((`account`.`id` = `vmcount`.`account_id`) - and (`vmcount`.`type` = 'user_vm')))) -left join `account_vmstats_view` `runningvm` on - (((`account`.`id` = `runningvm`.`account_id`) - and (`runningvm`.`state` = 'Running')))) -left join `account_vmstats_view` `stoppedvm` on - (((`account`.`id` = `stoppedvm`.`account_id`) - and (`stoppedvm`.`state` = 'Stopped')))) -left join `resource_limit` `iplimit` on - (((`account`.`id` = `iplimit`.`account_id`) - and (`iplimit`.`type` = 'public_ip')))) -left join `resource_count` `ipcount` on - (((`account`.`id` = `ipcount`.`account_id`) - and (`ipcount`.`type` = 'public_ip')))) -left join `resource_limit` `volumelimit` on - (((`account`.`id` = `volumelimit`.`account_id`) - and (`volumelimit`.`type` = 'volume')))) -left join `resource_count` `volumecount` on - (((`account`.`id` = `volumecount`.`account_id`) - and (`volumecount`.`type` = 'volume')))) -left join `resource_limit` `snapshotlimit` on - (((`account`.`id` = `snapshotlimit`.`account_id`) - and (`snapshotlimit`.`type` = 'snapshot')))) -left join `resource_count` `snapshotcount` on - (((`account`.`id` = `snapshotcount`.`account_id`) - and (`snapshotcount`.`type` = 'snapshot')))) -left join `resource_limit` `templatelimit` on - (((`account`.`id` = `templatelimit`.`account_id`) - and (`templatelimit`.`type` = 'template')))) -left join `resource_count` `templatecount` on - (((`account`.`id` = `templatecount`.`account_id`) - and (`templatecount`.`type` = 'template')))) -left join `resource_limit` `vpclimit` on - (((`account`.`id` = `vpclimit`.`account_id`) - and (`vpclimit`.`type` = 'vpc')))) -left join `resource_count` `vpccount` on - (((`account`.`id` = `vpccount`.`account_id`) - and (`vpccount`.`type` = 'vpc')))) -left join `resource_limit` `projectlimit` on - (((`account`.`id` = `projectlimit`.`account_id`) - and (`projectlimit`.`type` = 'project')))) -left join `resource_count` `projectcount` on - (((`account`.`id` = `projectcount`.`account_id`) - and (`projectcount`.`type` = 'project')))) -left join `resource_limit` `networklimit` on - (((`account`.`id` = `networklimit`.`account_id`) - and (`networklimit`.`type` = 'network')))) -left join `resource_count` `networkcount` on - (((`account`.`id` = `networkcount`.`account_id`) - and (`networkcount`.`type` = 'network')))) -left join `resource_limit` `cpulimit` on - (((`account`.`id` = `cpulimit`.`account_id`) - and (`cpulimit`.`type` = 'cpu')))) -left join `resource_count` `cpucount` on - (((`account`.`id` = `cpucount`.`account_id`) - and (`cpucount`.`type` = 'cpu')))) -left join `resource_limit` `memorylimit` on - (((`account`.`id` = `memorylimit`.`account_id`) - and (`memorylimit`.`type` = 'memory')))) -left join `resource_count` `memorycount` on - (((`account`.`id` = `memorycount`.`account_id`) - and (`memorycount`.`type` = 'memory')))) -left join `resource_limit` `primary_storage_limit` on - (((`account`.`id` = `primary_storage_limit`.`account_id`) - and (`primary_storage_limit`.`type` = 'primary_storage')))) -left join `resource_count` `primary_storage_count` on - (((`account`.`id` = `primary_storage_count`.`account_id`) - and (`primary_storage_count`.`type` = 'primary_storage')))) -left join `resource_limit` `secondary_storage_limit` on - (((`account`.`id` = `secondary_storage_limit`.`account_id`) - and (`secondary_storage_limit`.`type` = 'secondary_storage')))) -left join `resource_count` `secondary_storage_count` on - (((`account`.`id` = `secondary_storage_count`.`account_id`) - and (`secondary_storage_count`.`type` = 'secondary_storage')))) -left join `async_job` on - (((`async_job`.`instance_id` = `account`.`id`) - and (`async_job`.`instance_type` = 'Account') - and (`async_job`.`job_status` = 0))))); + `cloud`.`free_ip_view`, + `cloud`.`account` + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`data_center` ON account.default_zone_id = data_center.id + left join + `cloud`.`account_netstats_view` ON account.id = account_netstats_view.account_id + left join + `cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id + and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL + left join + `cloud`.`resource_count` vmcount ON account.id = vmcount.account_id + and vmcount.type = 'user_vm' and vmcount.tag IS NULL + left join + `cloud`.`account_vmstats_view` runningvm ON account.id = runningvm.account_id + and runningvm.state = 'Running' + left join + `cloud`.`account_vmstats_view` stoppedvm ON account.id = stoppedvm.account_id + and stoppedvm.state = 'Stopped' + left join + `cloud`.`resource_limit` iplimit ON account.id = iplimit.account_id + and iplimit.type = 'public_ip' + left join + `cloud`.`resource_count` ipcount ON account.id = ipcount.account_id + and ipcount.type = 'public_ip' + left join + `cloud`.`resource_limit` volumelimit ON account.id = volumelimit.account_id + and volumelimit.type = 'volume' and volumelimit.tag IS NULL + left join + `cloud`.`resource_count` volumecount ON account.id = volumecount.account_id + and volumecount.type = 'volume' and volumecount.tag IS NULL + left join + `cloud`.`resource_limit` snapshotlimit ON account.id = snapshotlimit.account_id + and snapshotlimit.type = 'snapshot' + left join + `cloud`.`resource_count` snapshotcount ON account.id = snapshotcount.account_id + and snapshotcount.type = 'snapshot' + left join + `cloud`.`resource_limit` templatelimit ON account.id = templatelimit.account_id + and templatelimit.type = 'template' + left join + `cloud`.`resource_count` templatecount ON account.id = templatecount.account_id + and templatecount.type = 'template' + left join + `cloud`.`resource_limit` vpclimit ON account.id = vpclimit.account_id + and vpclimit.type = 'vpc' + left join + `cloud`.`resource_count` vpccount ON account.id = vpccount.account_id + and vpccount.type = 'vpc' + left join + `cloud`.`resource_limit` projectlimit ON account.id = projectlimit.account_id + and projectlimit.type = 'project' + left join + `cloud`.`resource_count` projectcount ON account.id = projectcount.account_id + and projectcount.type = 'project' + left join + `cloud`.`resource_limit` networklimit ON account.id = networklimit.account_id + and networklimit.type = 'network' + left join + `cloud`.`resource_count` networkcount ON account.id = networkcount.account_id + and networkcount.type = 'network' + left join + `cloud`.`resource_limit` cpulimit ON account.id = cpulimit.account_id + and cpulimit.type = 'cpu' and cpulimit.tag IS NULL + left join + `cloud`.`resource_count` cpucount ON account.id = cpucount.account_id + and cpucount.type = 'cpu' and cpucount.tag IS NULL + left join + `cloud`.`resource_limit` memorylimit ON account.id = memorylimit.account_id + and memorylimit.type = 'memory' and memorylimit.tag IS NULL + left join + `cloud`.`resource_count` memorycount ON account.id = memorycount.account_id + and memorycount.type = 'memory' and memorycount.tag IS NULL + left join + `cloud`.`resource_limit` primary_storage_limit ON account.id = primary_storage_limit.account_id + and primary_storage_limit.type = 'primary_storage' and primary_storage_limit.tag IS NULL + left join + `cloud`.`resource_count` primary_storage_count ON account.id = primary_storage_count.account_id + and primary_storage_count.type = 'primary_storage' and primary_storage_count.tag IS NULL + left join + `cloud`.`resource_limit` secondary_storage_limit ON account.id = secondary_storage_limit.account_id + and secondary_storage_limit.type = 'secondary_storage' + left join + `cloud`.`resource_count` secondary_storage_count ON account.id = secondary_storage_count.account_id + and secondary_storage_count.type = 'secondary_storage' + left join + `cloud`.`async_job` ON async_job.instance_id = account.id + and async_job.instance_type = 'Account' + and async_job.job_status = 0; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql index 2d8a9b536f28..201ece95023a 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql @@ -63,10 +63,10 @@ from `cloud`.`domain` left join `cloud`.`resource_limit` vmlimit ON domain.id = vmlimit.domain_id - and vmlimit.type = 'user_vm' + and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL left join `cloud`.`resource_count` vmcount ON domain.id = vmcount.domain_id - and vmcount.type = 'user_vm' + and vmcount.type = 'user_vm' and vmcount.tag IS NULL left join `cloud`.`resource_limit` iplimit ON domain.id = iplimit.domain_id and iplimit.type = 'public_ip' @@ -75,10 +75,10 @@ from and ipcount.type = 'public_ip' left join `cloud`.`resource_limit` volumelimit ON domain.id = volumelimit.domain_id - and volumelimit.type = 'volume' + and volumelimit.type = 'volume' and volumelimit.tag IS NULL left join `cloud`.`resource_count` volumecount ON domain.id = volumecount.domain_id - and volumecount.type = 'volume' + and volumecount.type = 'volume' and volumecount.tag IS NULL left join `cloud`.`resource_limit` snapshotlimit ON domain.id = snapshotlimit.domain_id and snapshotlimit.type = 'snapshot' @@ -111,22 +111,22 @@ from and networkcount.type = 'network' left join `cloud`.`resource_limit` cpulimit ON domain.id = cpulimit.domain_id - and cpulimit.type = 'cpu' + and cpulimit.type = 'cpu' and cpulimit.tag IS NULL left join `cloud`.`resource_count` cpucount ON domain.id = cpucount.domain_id - and cpucount.type = 'cpu' + and cpucount.type = 'cpu' and cpucount.tag IS NULL left join `cloud`.`resource_limit` memorylimit ON domain.id = memorylimit.domain_id - and memorylimit.type = 'memory' + and memorylimit.type = 'memory' and memorylimit.tag IS NULL left join `cloud`.`resource_count` memorycount ON domain.id = memorycount.domain_id - and memorycount.type = 'memory' + and memorycount.type = 'memory' and memorycount.tag IS NULL left join `cloud`.`resource_limit` primary_storage_limit ON domain.id = primary_storage_limit.domain_id - and primary_storage_limit.type = 'primary_storage' + and primary_storage_limit.type = 'primary_storage' and primary_storage_limit.tag IS NULL left join `cloud`.`resource_count` primary_storage_count ON domain.id = primary_storage_count.domain_id - and primary_storage_count.type = 'primary_storage' + and primary_storage_count.type = 'primary_storage' and primary_storage_count.tag IS NULL left join `cloud`.`resource_limit` secondary_storage_limit ON domain.id = secondary_storage_limit.domain_id and secondary_storage_limit.type = 'secondary_storage' diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.host_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.host_view.sql index 5c6d4fd772b3..6fc8fb803862 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.host_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.host_view.sql @@ -41,6 +41,7 @@ SELECT host.cpus, host.speed, host.ram, + host.arch, cluster.id cluster_id, cluster.uuid cluster_uuid, cluster.name cluster_name, @@ -53,7 +54,9 @@ SELECT host_pod_ref.uuid pod_uuid, host_pod_ref.name pod_name, GROUP_CONCAT(DISTINCT(host_tags.tag)) AS tag, - `host_tags`.`is_tag_a_rule` AS `is_tag_a_rule`, + GROUP_CONCAT(DISTINCT(explicit_host_tags.tag)) AS explicit_tag, + GROUP_CONCAT(DISTINCT(implicit_host_tags.tag)) AS implicit_tag, + `explicit_host_tags`.`is_tag_a_rule` AS `is_tag_a_rule`, guest_os_category.id guest_os_category_id, guest_os_category.uuid guest_os_category_uuid, guest_os_category.name guest_os_category_name, @@ -89,6 +92,10 @@ FROM LEFT JOIN `cloud`.`host_tags` ON host_tags.host_id = host.id LEFT JOIN + `cloud`.`host_tags` AS explicit_host_tags ON explicit_host_tags.host_id = host.id AND explicit_host_tags.is_implicit = 0 + LEFT JOIN + `cloud`.`host_tags` AS implicit_host_tags ON implicit_host_tags.host_id = host.id AND implicit_host_tags.is_implicit = 1 + LEFT JOIN `cloud`.`op_host_capacity` mem_caps ON host.id = mem_caps.host_id AND mem_caps.capacity_type = 0 LEFT JOIN diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql index 8ba291e154cd..b6abaabcd48f 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql @@ -60,7 +60,11 @@ SELECT `network_offerings`.`supports_vm_autoscaling` AS `supports_vm_autoscaling`, `network_offerings`.`for_vpc` AS `for_vpc`, `network_offerings`.`for_tungsten` AS `for_tungsten`, + `network_offerings`.`for_nsx` AS `for_nsx`, + `network_offerings`.`network_mode` AS `network_mode`, `network_offerings`.`service_package_id` AS `service_package_id`, + `network_offerings`.`routing_mode` AS `routing_mode`, + `network_offerings`.`specify_as_number` AS `specify_as_number`, GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id, GROUP_CONCAT(DISTINCT(domain.uuid)) AS domain_uuid, GROUP_CONCAT(DISTINCT(domain.name)) AS domain_name, diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.shared_filesystem_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.shared_filesystem_view.sql new file mode 100644 index 000000000000..1f72babd1cec --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.shared_filesystem_view.sql @@ -0,0 +1,83 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +-- VIEW `cloud`.`shared_filesystem_view`; + +DROP VIEW IF EXISTS `cloud`.`shared_filesystem_view`; + +CREATE VIEW `cloud`.`shared_filesystem_view` AS +SELECT + `shared_filesystem`.`id` AS `id`, + `shared_filesystem`.`uuid` AS `uuid`, + `shared_filesystem`.`name` AS `name`, + `shared_filesystem`.`description` AS `description`, + `shared_filesystem`.`state` AS `state`, + `shared_filesystem`.`fs_provider_name` AS `provider`, + `shared_filesystem`.`fs_type` AS `fs_type`, + `shared_filesystem`.`volume_id` AS `volume_id`, + `shared_filesystem`.`account_id` AS `account_id`, + `shared_filesystem`.`data_center_id` AS `zone_id`, + `zone`.`uuid` AS `zone_uuid`, + `zone`.`name` AS `zone_name`, + `instance`.`id` AS `instance_id`, + `instance`.`uuid` AS `instance_uuid`, + `instance`.`name` AS `instance_name`, + `instance`.`state` AS `instance_state`, + `volumes`.`size` AS `size`, + `volumes`.`uuid` AS `volume_uuid`, + `volumes`.`name` AS `volume_name`, + `volumes`.`provisioning_type` AS `provisioning_type`, + `volumes`.`format` AS `volume_format`, + `volumes`.`path` AS `volume_path`, + `volumes`.`chain_info` AS `volume_chain_info`, + `storage_pool`.`uuid` AS `pool_uuid`, + `storage_pool`.`name` AS `pool_name`, + `account`.`account_name` AS `account_name`, + `project`.`uuid` AS `project_uuid`, + `project`.`name` AS `project_name`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path`, + `service_offering`.`uuid` AS `service_offering_uuid`, + `service_offering`.`name` AS `service_offering_name`, + `disk_offering`.`uuid` AS `disk_offering_uuid`, + `disk_offering`.`name` AS `disk_offering_name`, + `disk_offering`.`display_text` AS `disk_offering_display_text`, + `disk_offering`.`disk_size` AS `disk_offering_size`, + `disk_offering`.`customized` AS `disk_offering_custom` +FROM + `cloud`.`shared_filesystem` + LEFT JOIN + `cloud`.`data_center` AS `zone` ON `shared_filesystem`.`data_center_id` = `zone`.`id` + LEFT JOIN + `cloud`.`vm_instance` AS `instance` ON `shared_filesystem`.`vm_id` = `instance`.`id` + LEFT JOIN + `cloud`.`volumes` AS `volumes` ON `shared_filesystem`.`volume_id` = `volumes`.`id` + LEFT JOIN + `cloud`.`storage_pool` AS `storage_pool` ON `volumes`.`pool_id` = `storage_pool`.`id` + LEFT JOIN + `cloud`.`account` AS `account` ON `shared_filesystem`.`account_id` = `account`.`id` + LEFT JOIN + `cloud`.`projects` AS `project` ON `project`.`project_account_id` = `account`.`id` + LEFT JOIN + `cloud`.`domain` AS `domain` ON `shared_filesystem`.`domain_id` = `domain`.`id` + LEFT JOIN + `cloud`.`service_offering` AS `service_offering` ON `shared_filesystem`.`service_offering_id` = `service_offering`.`id` + LEFT JOIN + `cloud`.`disk_offering` AS `disk_offering` ON `volumes`.`disk_offering_id` = `disk_offering`.`id` +GROUP BY + `shared_filesystem`.`id`; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.template_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.template_view.sql index 40b416b16de4..339e43860d88 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.template_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.template_view.sql @@ -50,6 +50,7 @@ SELECT `vm_template`.`sort_key` AS `sort_key`, `vm_template`.`removed` AS `removed`, `vm_template`.`enable_sshkey` AS `enable_sshkey`, + `vm_template`.`arch` AS `arch`, `parent_template`.`id` AS `parent_template_id`, `parent_template`.`uuid` AS `parent_template_uuid`, `source_template`.`id` AS `source_template_id`, diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql index 62294ed5d890..97cb7b735cfc 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql @@ -25,6 +25,7 @@ SELECT `vm_instance`.`name` AS `name`, `user_vm`.`display_name` AS `display_name`, `user_vm`.`user_data` AS `user_data`, + `user_vm`.`user_vm_type` AS `user_vm_type`, `account`.`id` AS `account_id`, `account`.`uuid` AS `account_uuid`, `account`.`account_name` AS `account_name`, @@ -53,6 +54,7 @@ SELECT `vm_instance`.`instance_name` AS `instance_name`, `vm_instance`.`guest_os_id` AS `guest_os_id`, `vm_instance`.`display_vm` AS `display_vm`, + `vm_instance`.`delete_protection` AS `delete_protection`, `guest_os`.`uuid` AS `guest_os_uuid`, `vm_instance`.`pod_id` AS `pod_id`, `host_pod_ref`.`uuid` AS `pod_uuid`, diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.volume_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.volume_view.sql index 950dcddf4c71..ffeb93e8fa7a 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.volume_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.volume_view.sql @@ -40,6 +40,7 @@ SELECT `volumes`.`chain_info` AS `chain_info`, `volumes`.`external_uuid` AS `external_uuid`, `volumes`.`encrypt_format` AS `encrypt_format`, + `volumes`.`delete_protection` AS `delete_protection`, `account`.`id` AS `account_id`, `account`.`uuid` AS `account_uuid`, `account`.`account_name` AS `account_name`, diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.vpc_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.vpc_offering_view.sql index cb762a578839..c74d50590de5 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.vpc_offering_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.vpc_offering_view.sql @@ -17,7 +17,6 @@ -- cloud.vpc_offering_view source - DROP VIEW IF EXISTS `cloud`.`vpc_offering_view`; CREATE VIEW `cloud`.`vpc_offering_view` AS @@ -29,6 +28,8 @@ select `vpc_offerings`.`display_text` AS `display_text`, `vpc_offerings`.`state` AS `state`, `vpc_offerings`.`default` AS `default`, + `vpc_offerings`.`for_nsx` AS `for_nsx`, + `vpc_offerings`.`network_mode` AS `network_mode`, `vpc_offerings`.`created` AS `created`, `vpc_offerings`.`removed` AS `removed`, `vpc_offerings`.`service_offering_id` AS `service_offering_id`, @@ -36,6 +37,8 @@ select `vpc_offerings`.`supports_region_level_vpc` AS `supports_region_level_vpc`, `vpc_offerings`.`redundant_router_service` AS `redundant_router_service`, `vpc_offerings`.`sort_key` AS `sort_key`, + `vpc_offerings`.`routing_mode` AS `routing_mode`, + `vpc_offerings`.`specify_as_number` AS `specify_as_number`, group_concat(distinct `domain`.`id` separator ',') AS `domain_id`, group_concat(distinct `domain`.`uuid` separator ',') AS `domain_uuid`, group_concat(distinct `domain`.`name` separator ',') AS `domain_name`, diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.webhook_delivery_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.webhook_delivery_view.sql new file mode 100644 index 000000000000..54ba52fba4a6 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.webhook_delivery_view.sql @@ -0,0 +1,48 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +-- VIEW `cloud`.`webhook_delivery_view`; + +DROP VIEW IF EXISTS `cloud`.`webhook_delivery_view`; +CREATE VIEW `cloud`.`webhook_delivery_view` AS + SELECT + webhook_delivery.id, + webhook_delivery.uuid, + webhook_delivery.headers, + webhook_delivery.payload, + webhook_delivery.success, + webhook_delivery.response, + webhook_delivery.start_time, + webhook_delivery.end_time, + event.id event_id, + event.uuid event_uuid, + event.type event_type, + webhook.id webhook_id, + webhook.uuid webhook_uuid, + webhook.name webhook_name, + mshost.id mshost_id, + mshost.uuid mshost_uuid, + mshost.msid mshost_msid, + mshost.name mshost_name + FROM + `cloud`.`webhook_delivery` + INNER JOIN + `cloud`.`event` ON webhook_delivery.event_id = event.id + INNER JOIN + `cloud`.`webhook` ON webhook_delivery.webhook_id = webhook.id + LEFT JOIN + `cloud`.`mshost` ON mshost.msid = webhook_delivery.mshost_msid; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.webhook_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.webhook_view.sql new file mode 100644 index 000000000000..443463eec4bd --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.webhook_view.sql @@ -0,0 +1,52 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +-- VIEW `cloud`.`webhook_view`; + +DROP VIEW IF EXISTS `cloud`.`webhook_view`; +CREATE VIEW `cloud`.`webhook_view` AS + SELECT + webhook.id, + webhook.uuid, + webhook.name, + webhook.description, + webhook.state, + webhook.payload_url, + webhook.secret_key, + webhook.ssl_verification, + webhook.scope, + webhook.created, + webhook.removed, + account.id account_id, + account.uuid account_uuid, + account.account_name account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name + FROM + `cloud`.`webhook` + INNER JOIN + `cloud`.`account` ON webhook.account_id = account.id + INNER JOIN + `cloud`.`domain` ON webhook.domain_id = domain.id + LEFT JOIN + `cloud`.`projects` ON projects.project_account_id = webhook.account_id; diff --git a/engine/schema/src/test/java/com/cloud/host/HostVOTest.java b/engine/schema/src/test/java/com/cloud/host/HostVOTest.java index 76bc5270b4f7..3262c4cc2918 100755 --- a/engine/schema/src/test/java/com/cloud/host/HostVOTest.java +++ b/engine/schema/src/test/java/com/cloud/host/HostVOTest.java @@ -1,84 +1,149 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.host; - -import com.cloud.service.ServiceOfferingVO; -import com.cloud.vm.VirtualMachine; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.junit.Before; - -public class HostVOTest { - HostVO host; - ServiceOfferingVO offering; - - @Before - public void setUp() throws Exception { - host = new HostVO(); - offering = new ServiceOfferingVO("TestSO", 0, 0, 0, 0, 0, - false, "TestSO", false,VirtualMachine.Type.User,false); - } - - @Test - public void testNoSO() { - assertFalse(host.checkHostServiceOfferingTags(null)); - } - - @Test - public void testNoTag() { - assertTrue(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void testRightTag() { - host.setHostTags(Arrays.asList("tag1","tag2"), false); - offering.setHostTag("tag2,tag1"); - assertTrue(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void testWrongTag() { - host.setHostTags(Arrays.asList("tag1","tag2"), false); - offering.setHostTag("tag2,tag4"); - assertFalse(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatMatches() { - host.setHostTags(List.of("tags[0] == 'A'"), true); - offering.setHostTag("A"); - assertTrue(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatDoesNotMatch() { - host.setHostTags(List.of("tags[0] == 'A'"), true); - offering.setHostTag("B"); - assertFalse(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void checkHostServiceOfferingTagsTestRuleTagWithNullServiceTag() { - host.setHostTags(List.of("tags[0] == 'A'"), true); - offering.setHostTag(null); - assertFalse(host.checkHostServiceOfferingTags(offering)); - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.host; + +import com.cloud.offering.ServiceOffering; +import com.cloud.service.ServiceOfferingVO; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.vm.VirtualMachine; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class HostVOTest { + HostVO host; + ServiceOfferingVO offering; + + @Before + public void setUp() throws Exception { + host = new HostVO(); + offering = new ServiceOfferingVO("TestSO", 0, 0, 0, 0, 0, + false, "TestSO", false, VirtualMachine.Type.User, false); + } + + @Test + public void testNoSO() { + assertFalse(host.checkHostServiceOfferingTags(null)); + } + + @Test + public void testNoTag() { + assertTrue(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void testRightTag() { + host.setHostTags(Arrays.asList("tag1", "tag2"), false); + offering.setHostTag("tag2,tag1"); + assertTrue(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void testWrongTag() { + host.setHostTags(Arrays.asList("tag1", "tag2"), false); + offering.setHostTag("tag2,tag4"); + assertFalse(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatMatches() { + host.setHostTags(List.of("tags[0] == 'A'"), true); + offering.setHostTag("A"); + assertTrue(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatDoesNotMatch() { + host.setHostTags(List.of("tags[0] == 'A'"), true); + offering.setHostTag("B"); + assertFalse(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void checkHostServiceOfferingTagsTestRuleTagWithNullServiceTag() { + host.setHostTags(List.of("tags[0] == 'A'"), true); + offering.setHostTag(null); + assertFalse(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void testEitherNoSOOrTemplate() { + assertFalse(host.checkHostServiceOfferingAndTemplateTags(null, Mockito.mock(VirtualMachineTemplate.class), null)); + assertFalse(host.checkHostServiceOfferingAndTemplateTags(Mockito.mock(ServiceOffering.class), null, null)); + } + + @Test + public void testNoTagOfferingTemplate() { + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, Mockito.mock(VirtualMachineTemplate.class), Collections.emptySet())); + assertTrue(host.getHostServiceOfferingAndTemplateMissingTags(offering, Mockito.mock(VirtualMachineTemplate.class), Collections.emptySet()).isEmpty()); + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, Mockito.mock(VirtualMachineTemplate.class), Set.of("tag1", "tag2"))); + assertTrue(host.getHostServiceOfferingAndTemplateMissingTags(offering, Mockito.mock(VirtualMachineTemplate.class), Set.of("tag1", "tag2")).isEmpty()); + } + + @Test + public void testRightTagOfferingTemplate() { + host.setHostTags(Arrays.asList("tag1", "tag2"), false); + offering.setHostTag("tag2,tag1"); + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, Mockito.mock(VirtualMachineTemplate.class), Set.of("tag1"))); + Set actualMissingTags = host.getHostServiceOfferingAndTemplateMissingTags(offering, Mockito.mock(VirtualMachineTemplate.class), Set.of("tag1")); + assertTrue(actualMissingTags.isEmpty()); + + host.setHostTags(Arrays.asList("tag1", "tag2", "tag3"), false); + offering.setHostTag("tag2,tag1"); + VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class); + Mockito.when(template.getTemplateTag()).thenReturn("tag3"); + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, template, Set.of("tag2", "tag3"))); + actualMissingTags = host.getHostServiceOfferingAndTemplateMissingTags(offering, template, Set.of("tag2", "tag3")); + assertTrue(actualMissingTags.isEmpty()); + host.setHostTags(List.of("tag3"), false); + offering.setHostTag(null); + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, template, Set.of("tag3"))); + actualMissingTags = host.getHostServiceOfferingAndTemplateMissingTags(offering, template, Set.of("tag3")); + assertTrue(actualMissingTags.isEmpty()); + + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, template, Set.of("tag2", "tag1"))); + actualMissingTags = host.getHostServiceOfferingAndTemplateMissingTags(offering, template, Set.of("tag2", "tag1")); + assertTrue(actualMissingTags.isEmpty()); + } + + @Test + public void testWrongOfferingTag() { + host.setHostTags(Arrays.asList("tag1", "tag2"), false); + offering.setHostTag("tag2,tag4"); + VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class); + Mockito.when(template.getTemplateTag()).thenReturn("tag1"); + assertFalse(host.checkHostServiceOfferingAndTemplateTags(offering, template, Set.of("tag1", "tag2", "tag3", "tag4"))); + Set actualMissingTags = host.getHostServiceOfferingAndTemplateMissingTags(offering, template, Set.of("tag1", "tag2", "tag3", "tag4")); + assertEquals(Set.of("tag4"), actualMissingTags); + + offering.setHostTag("tag1,tag2"); + template = Mockito.mock(VirtualMachineTemplate.class); + Mockito.when(template.getTemplateTag()).thenReturn("tag3"); + actualMissingTags = host.getHostServiceOfferingAndTemplateMissingTags(offering, template, Set.of("tag1", "tag2", "tag3", "tag4")); + assertFalse(host.checkHostServiceOfferingAndTemplateTags(offering, template, Set.of("tag1", "tag2", "tag3", "tag4"))); + assertEquals(Set.of("tag3"), actualMissingTags); + } +} diff --git a/engine/schema/src/test/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImplTest.java b/engine/schema/src/test/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImplTest.java index e13ad42ec808..6de8960ae747 100644 --- a/engine/schema/src/test/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImplTest.java @@ -19,11 +19,9 @@ package com.cloud.network.as.dao; -import com.cloud.network.as.AutoScaleVmGroupVmMapVO; -import com.cloud.utils.db.GenericSearchBuilder; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.vm.VirtualMachine; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.junit.Assert; import org.junit.Before; @@ -33,9 +31,13 @@ import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; -import java.util.Arrays; -import java.util.List; +import com.cloud.network.as.AutoScaleVmGroupVmMapVO; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.vm.VirtualMachine; @RunWith(MockitoJUnitRunner.class) public class AutoScaleVmGroupVmMapDaoImplTest { @@ -198,4 +200,33 @@ public void testRemoveByGroupFailed() { Mockito.verify(searchCriteriaAutoScaleVmGroupVmMapVOMock).setParameters("vmGroupId", groupId); Mockito.verify(AutoScaleVmGroupVmMapDaoImplSpy).remove(searchCriteriaAutoScaleVmGroupVmMapVOMock); } + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, AutoScaleVmGroupVmMapDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, AutoScaleVmGroupVmMapDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(AutoScaleVmGroupVmMapDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(AutoScaleVmGroupVmMapDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final AutoScaleVmGroupVmMapVO mockedVO = Mockito.mock(AutoScaleVmGroupVmMapVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), AutoScaleVmGroupVmMapDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(AutoScaleVmGroupVmMapDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } } diff --git a/engine/schema/src/test/java/com/cloud/network/dao/IPAddressDaoImplTest.java b/engine/schema/src/test/java/com/cloud/network/dao/IPAddressDaoImplTest.java new file mode 100644 index 000000000000..d8f6a08d8d33 --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/network/dao/IPAddressDaoImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class IPAddressDaoImplTest { + + @Spy + IPAddressDaoImpl ipAddressDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, ipAddressDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, ipAddressDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(ipAddressDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(ipAddressDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final IPAddressVO mockedVO = Mockito.mock(IPAddressVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), ipAddressDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(ipAddressDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImplTest.java b/engine/schema/src/test/java/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImplTest.java new file mode 100644 index 000000000000..8e06c7618f6a --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/network/dao/InlineLoadBalancerNicMapDaoImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class InlineLoadBalancerNicMapDaoImplTest { + + @Spy + InlineLoadBalancerNicMapDaoImpl inlineLoadBalancerNicMapDaoImplSpy; + + @Test + public void testExpungeByNicListNoVms() { + Assert.assertEquals(0, inlineLoadBalancerNicMapDaoImplSpy.expungeByNicList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, inlineLoadBalancerNicMapDaoImplSpy.expungeByNicList( + null, 100L)); + } + + @Test + public void testExpungeByNicList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(inlineLoadBalancerNicMapDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(inlineLoadBalancerNicMapDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final InlineLoadBalancerNicMapVO mockedVO = Mockito.mock(InlineLoadBalancerNicMapVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), inlineLoadBalancerNicMapDaoImplSpy.expungeByNicList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("nicIds", array); + Mockito.verify(inlineLoadBalancerNicMapDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/network/dao/LoadBalancerVMMapDaoImplTest.java b/engine/schema/src/test/java/com/cloud/network/dao/LoadBalancerVMMapDaoImplTest.java new file mode 100644 index 000000000000..fa9571949031 --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/network/dao/LoadBalancerVMMapDaoImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class LoadBalancerVMMapDaoImplTest { + + @Spy + LoadBalancerVMMapDaoImpl loadBalancerVMMapDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, loadBalancerVMMapDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, loadBalancerVMMapDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(loadBalancerVMMapDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(loadBalancerVMMapDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final LoadBalancerVMMapVO mockedVO = Mockito.mock(LoadBalancerVMMapVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), loadBalancerVMMapDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(loadBalancerVMMapDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/network/dao/OpRouterMonitorServiceDaoImplTest.java b/engine/schema/src/test/java/com/cloud/network/dao/OpRouterMonitorServiceDaoImplTest.java new file mode 100644 index 000000000000..7d0b1b069baa --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/network/dao/OpRouterMonitorServiceDaoImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class OpRouterMonitorServiceDaoImplTest { + + @Spy + OpRouterMonitorServiceDaoImpl opRouterMonitorServiceDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, opRouterMonitorServiceDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, opRouterMonitorServiceDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(opRouterMonitorServiceDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(opRouterMonitorServiceDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final OpRouterMonitorServiceVO mockedVO = Mockito.mock(OpRouterMonitorServiceVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), opRouterMonitorServiceDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(opRouterMonitorServiceDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/network/rules/dao/PortForwardingRulesDaoImplTest.java b/engine/schema/src/test/java/com/cloud/network/rules/dao/PortForwardingRulesDaoImplTest.java new file mode 100644 index 000000000000..c60e9b1f1bfa --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/network/rules/dao/PortForwardingRulesDaoImplTest.java @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.network.rules.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.network.rules.PortForwardingRuleVO; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class PortForwardingRulesDaoImplTest { + + @Spy + PortForwardingRulesDaoImpl portForwardingRulesDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, portForwardingRulesDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, portForwardingRulesDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(portForwardingRulesDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(portForwardingRulesDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final PortForwardingRuleVO mockedVO = Mockito.mock(PortForwardingRuleVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), portForwardingRulesDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(portForwardingRulesDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java b/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java index 6c894de7fb21..64941d99bb62 100644 --- a/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java @@ -17,6 +17,7 @@ package com.cloud.offerings.dao; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -37,9 +38,16 @@ public class NetworkOfferingDaoImplTest { final long offeringId = 1L; + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/engine/schema/src/test/java/com/cloud/secstorage/CommandExecLogDaoImplTest.java b/engine/schema/src/test/java/com/cloud/secstorage/CommandExecLogDaoImplTest.java new file mode 100644 index 000000000000..f86df6bdd36f --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/secstorage/CommandExecLogDaoImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.secstorage; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class CommandExecLogDaoImplTest { + + @Spy + CommandExecLogDaoImpl commandExecLogDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, commandExecLogDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, commandExecLogDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(commandExecLogDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(commandExecLogDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final CommandExecLogVO mockedVO = Mockito.mock(CommandExecLogVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), commandExecLogDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(commandExecLogDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java b/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java index 9277bf915c18..85fe0e09542a 100755 --- a/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; @@ -72,7 +72,7 @@ public class StoragePoolTagsDaoImplTest extends TestCase { public void setup() { when(_configDao.getValue(batchSizeConfigurationKey)).thenReturn(batchSizeValue); doReturn(storagePoolTagList).when(_storagePoolTagsDaoImpl).searchIncludingRemoved( - Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); } @Test @@ -91,7 +91,7 @@ public void testSearchForStoragePoolIdsInternalStorageTagsNotNullSearch() { List storagePoolTags = new ArrayList(); _storagePoolTagsDaoImpl.searchForStoragePoolIdsInternal(0, storageTagsIds.length, storageTagsIds, storagePoolTags); - verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); assertEquals(2, storagePoolTags.size()); } @@ -99,30 +99,30 @@ public void testSearchForStoragePoolIdsInternalStorageTagsNotNullSearch() { public void testSearchForStoragePoolIdsInternalStorageTagsNullSearch() { List storagePoolTags = new ArrayList(); doReturn(null).when(_storagePoolTagsDaoImpl).searchIncludingRemoved( - Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); _storagePoolTagsDaoImpl.searchForStoragePoolIdsInternal(0, storageTagsIds.length, storageTagsIds, storagePoolTags); - verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); assertEquals(0, storagePoolTags.size()); } @Test public void testSearchByIdsStorageTagsIdsGreaterOrEqualThanBatchSize() { when(_configDao.getValue(batchSizeConfigurationKey)).thenReturn(batchSizeLow); - doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.anyInt(), Matchers.any(Long[].class), Matchers.anyList()); + doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); _storagePoolTagsDaoImpl.searchByIds(storageTagsIds); int batchSize = Integer.parseInt(batchSizeLow); int difference = storageTagsIds.length - 2 * batchSize; - verify(_storagePoolTagsDaoImpl, Mockito.times(2)).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.eq(batchSize), Matchers.any(Long[].class), Matchers.anyList()); - verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.eq(2 * batchSize), Matchers.eq(difference), Matchers.any(Long[].class), Matchers.anyList()); + verify(_storagePoolTagsDaoImpl, Mockito.times(2)).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.eq(batchSize), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); + verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.eq(2 * batchSize), ArgumentMatchers.eq(difference), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); } @Test public void testSearchByIdsStorageTagsIdsLowerThanBatchSize() { - doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.anyInt(), Matchers.any(Long[].class), Matchers.anyList()); + doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); _storagePoolTagsDaoImpl.searchByIds(storageTagsIds); - verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.eq(0), Matchers.eq(storageTagsIds.length), Matchers.any(Long[].class), Matchers.anyList()); + verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.eq(0), ArgumentMatchers.eq(storageTagsIds.length), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); } } diff --git a/engine/schema/src/test/java/com/cloud/storage/dao/VolumeDaoImplTest.java b/engine/schema/src/test/java/com/cloud/storage/dao/VolumeDaoImplTest.java index 7968ee4a375e..9445efeb089c 100644 --- a/engine/schema/src/test/java/com/cloud/storage/dao/VolumeDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/storage/dao/VolumeDaoImplTest.java @@ -26,16 +26,25 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.collections.CollectionUtils; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; +import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import com.cloud.storage.VolumeVO; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.TransactionLegacy; @RunWith(MockitoJUnitRunner.class) @@ -48,6 +57,7 @@ public class VolumeDaoImplTest { private static MockedStatic mockedTransactionLegacy; + @Spy private final VolumeDaoImpl volumeDao = new VolumeDaoImpl(); @BeforeClass @@ -102,4 +112,34 @@ public void testListPoolIdsByVolumeCount_without_cluster_details() throws SQLExc verify(preparedStatementMock, times(2)).setLong(anyInt(), anyLong()); verify(preparedStatementMock, times(1)).executeQuery(); } + + @Test + public void testSearchRemovedByVmsNoVms() { + Assert.assertTrue(CollectionUtils.isEmpty(volumeDao.searchRemovedByVms( + new ArrayList<>(), 100L))); + Assert.assertTrue(CollectionUtils.isEmpty(volumeDao.searchRemovedByVms( + null, 100L))); + } + + @Test + public void testSearchRemovedByVms() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doReturn(new ArrayList<>()).when(volumeDao).searchIncludingRemoved( + Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), Mockito.eq(null), + Mockito.eq(false)); + Mockito.when(volumeDao.createSearchBuilder()).thenReturn(sb); + final VolumeVO mockedVO = Mockito.mock(VolumeVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + volumeDao.searchRemovedByVms(List.of(1L, 2L), batchSize); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(volumeDao, Mockito.times(1)).searchIncludingRemoved( + Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), Mockito.eq(null), + Mockito.eq(false)); + } + } diff --git a/engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java b/engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java index bd05fbe3c4cd..4c07abda9389 100644 --- a/engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java +++ b/engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java @@ -16,7 +16,6 @@ // under the License. package com.cloud.upgrade.dao; - import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.contains; @@ -32,14 +31,13 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) public class DatabaseAccessObjectTest { @@ -60,8 +58,7 @@ public class DatabaseAccessObjectTest { @Before public void setup() { - ReflectionTestUtils.setField(dao, "s_logger", loggerMock); - + dao.logger = loggerMock; } @Test diff --git a/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java b/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java index c3ad42a91305..05d9154b6a45 100644 --- a/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java @@ -17,7 +17,7 @@ package com.cloud.usage.dao; -import static org.mockito.Matchers.contains; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/engine/schema/src/test/java/com/cloud/vm/ItWorkDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/ItWorkDaoImplTest.java new file mode 100644 index 000000000000..04bc125e05f8 --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/vm/ItWorkDaoImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class ItWorkDaoImplTest { + + @Spy + ItWorkDaoImpl itWorkDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, itWorkDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, itWorkDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(itWorkDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(itWorkDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final ItWorkVO mockedVO = Mockito.mock(ItWorkVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), itWorkDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(itWorkDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/vm/dao/ConsoleSessionDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/dao/ConsoleSessionDaoImplTest.java new file mode 100644 index 000000000000..c9919e26af6c --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/vm/dao/ConsoleSessionDaoImplTest.java @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.vm.ConsoleSessionVO; + +@RunWith(MockitoJUnitRunner.class) +public class ConsoleSessionDaoImplTest { + + @Spy + ConsoleSessionDaoImpl consoleSessionDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, consoleSessionDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, consoleSessionDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(consoleSessionDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(consoleSessionDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final ConsoleSessionVO mockedVO = Mockito.mock(ConsoleSessionVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), consoleSessionDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(consoleSessionDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/vm/dao/NicDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/dao/NicDaoImplTest.java new file mode 100644 index 000000000000..506fdb7fc92b --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/vm/dao/NicDaoImplTest.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.vm.NicVO; + +@RunWith(MockitoJUnitRunner.class) +public class NicDaoImplTest { + + @Spy + NicDaoImpl nicDaoImplSpy; + + @Test + public void testSearchRemovedByVmsNoVms() { + Assert.assertTrue(CollectionUtils.isEmpty(nicDaoImplSpy.searchRemovedByVms( + new ArrayList<>(), 100L))); + Assert.assertTrue(CollectionUtils.isEmpty(nicDaoImplSpy.searchRemovedByVms( + null, 100L))); + } + + @Test + public void testSearchRemovedByVms() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doReturn(new ArrayList<>()).when(nicDaoImplSpy).searchIncludingRemoved( + Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), Mockito.eq(null), + Mockito.eq(false)); + Mockito.when(nicDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final NicVO mockedVO = Mockito.mock(NicVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + nicDaoImplSpy.searchRemovedByVms(List.of(1L, 2L), batchSize); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(nicDaoImplSpy, Mockito.times(1)).searchIncludingRemoved( + Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), Mockito.eq(null), + Mockito.eq(false)); + } +} diff --git a/engine/schema/src/test/java/com/cloud/vm/dao/NicExtraDhcpOptionDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/dao/NicExtraDhcpOptionDaoImplTest.java new file mode 100644 index 000000000000..7a1e32e95caf --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/vm/dao/NicExtraDhcpOptionDaoImplTest.java @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.vm.NicExtraDhcpOptionVO; + +@RunWith(MockitoJUnitRunner.class) +public class NicExtraDhcpOptionDaoImplTest { + + @Spy + NicExtraDhcpOptionDaoImpl nicExtraDhcpOptionDaoImplSpy; + + @Test + public void testExpungeByNicListNoVms() { + Assert.assertEquals(0, nicExtraDhcpOptionDaoImplSpy.expungeByNicList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, nicExtraDhcpOptionDaoImplSpy.expungeByNicList( + null, 100L)); + } + + @Test + public void testExpungeByNicList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(nicExtraDhcpOptionDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(nicExtraDhcpOptionDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final NicExtraDhcpOptionVO mockedVO = Mockito.mock(NicExtraDhcpOptionVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), nicExtraDhcpOptionDaoImplSpy.expungeByNicList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("nicIds", array); + Mockito.verify(nicExtraDhcpOptionDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/vm/dao/NicSecondaryIpDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/dao/NicSecondaryIpDaoImplTest.java new file mode 100644 index 000000000000..a9f798dbc017 --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/vm/dao/NicSecondaryIpDaoImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class NicSecondaryIpDaoImplTest { + + @Spy + NicSecondaryIpDaoImpl nicSecondaryIpDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, nicSecondaryIpDaoImplSpy.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, nicSecondaryIpDaoImplSpy.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(nicSecondaryIpDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(nicSecondaryIpDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final NicSecondaryIpVO mockedVO = Mockito.mock(NicSecondaryIpVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), nicSecondaryIpDaoImplSpy.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(nicSecondaryIpDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java index 9dc773cd7d63..43679081550b 100644 --- a/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java @@ -30,16 +30,23 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import org.joda.time.DateTime; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import com.cloud.utils.Pair; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; @@ -55,15 +62,22 @@ public class VMInstanceDaoImplTest { @Mock VMInstanceVO vm; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); Long hostId = null; when(vm.getHostId()).thenReturn(hostId); when(vm.getUpdated()).thenReturn(5L); when(vm.getUpdateTime()).thenReturn(DateTime.now().toDate()); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testUpdateState() { Long destHostId = null; @@ -191,4 +205,29 @@ public void testUpdatePowerStateNoChangeMaxUpdatesInvalidStateVmRunning() { assertTrue(result); } + + @Test + public void testSearchRemovedByRemoveDate() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.when(vmInstanceDao.createSearchBuilder()).thenReturn(sb); + final VMInstanceVO mockedVO = Mockito.mock(VMInstanceVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + Mockito.doReturn(new ArrayList<>()).when(vmInstanceDao).searchIncludingRemoved( + Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), Mockito.eq(null), + Mockito.eq(false)); + Calendar cal = Calendar.getInstance(); + Date endDate = new Date(); + cal.setTime(endDate); + cal.add(Calendar.DATE, -1 * 10); + Date startDate = cal.getTime(); + vmInstanceDao.searchRemovedByRemoveDate(startDate, endDate, 50L, new ArrayList<>()); + Mockito.verify(sc).setParameters("startDate", startDate); + Mockito.verify(sc).setParameters("endDate", endDate); + Mockito.verify(sc, Mockito.never()).setParameters(Mockito.eq("skippedVmIds"), Mockito.any()); + Mockito.verify(vmInstanceDao, Mockito.times(1)).searchIncludingRemoved( + Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), Mockito.eq(null), + Mockito.eq(false)); + } } diff --git a/engine/schema/src/test/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImplTest.java new file mode 100644 index 000000000000..e71518080d24 --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImplTest.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.vm.snapshot.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.vm.snapshot.VMSnapshotVO; + +@RunWith(MockitoJUnitRunner.class) +public class VMSnapshotDaoImplTest { + + @Spy + VMSnapshotDaoImpl vmSnapshotDaoImplSpy; + + @Test + public void testSearchRemovedByVmsNoVms() { + Assert.assertTrue(CollectionUtils.isEmpty(vmSnapshotDaoImplSpy.searchRemovedByVms( + new ArrayList<>(), 100L))); + Assert.assertTrue(CollectionUtils.isEmpty(vmSnapshotDaoImplSpy.searchRemovedByVms( + null, 100L))); + } + + @Test + public void testSearchRemovedByVms() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doReturn(new ArrayList<>()).when(vmSnapshotDaoImplSpy).searchIncludingRemoved( + Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), Mockito.eq(null), + Mockito.eq(false)); + Mockito.when(vmSnapshotDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final VMSnapshotVO mockedVO = Mockito.mock(VMSnapshotVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + vmSnapshotDaoImplSpy.searchRemovedByVms(List.of(1L, 2L), batchSize); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(vmSnapshotDaoImplSpy, Mockito.times(1)).searchIncludingRemoved( + Mockito.any(SearchCriteria.class), Mockito.any(Filter.class), Mockito.eq(null), + Mockito.eq(false)); + } +} diff --git a/engine/schema/src/test/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImplTest.java b/engine/schema/src/test/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImplTest.java new file mode 100644 index 000000000000..85240ab4a058 --- /dev/null +++ b/engine/schema/src/test/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.datastore.db; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class SnapshotDataStoreDaoImplTest { + + @Spy + SnapshotDataStoreDaoImpl snapshotDataStoreDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, snapshotDataStoreDaoImplSpy.expungeBySnapshotList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, snapshotDataStoreDaoImplSpy.expungeBySnapshotList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(snapshotDataStoreDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(snapshotDataStoreDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final SnapshotDataStoreVO mockedVO = Mockito.mock(SnapshotDataStoreVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), snapshotDataStoreDaoImplSpy.expungeBySnapshotList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("snapshotIds", array); + Mockito.verify(snapshotDataStoreDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/schema/templateConfig.sh b/engine/schema/templateConfig.sh index fb12ad752a25..4205e06aa693 100644 --- a/engine/schema/templateConfig.sh +++ b/engine/schema/templateConfig.sh @@ -60,22 +60,23 @@ function createMetadataFile() { section="${template%%:*}" hvName=$(getGenericName $section) - templatename="systemvm-${section}-${VERSION}" - checksum=$(getChecksum "$fileData" "$VERSION-$hvName") downloadurl="${template#*:}" + arch=$(echo ${downloadurl#*"/systemvmtemplate-$VERSION-"} | cut -d'-' -f 1) + templatename="systemvm-${section%.*}-${VERSION}-${arch}" + checksum=$(getChecksum "$fileData" "$VERSION-${arch}-$hvName") filename=$(echo ${downloadurl##*'/'}) - echo -e "["$section"]\ntemplatename = $templatename\nchecksum = $checksum\ndownloadurl = $downloadurl\nfilename = $filename\n" >> $METADATAFILE + echo -e "["$section"]\ntemplatename = $templatename\nchecksum = $checksum\ndownloadurl = $downloadurl\nfilename = $filename\narch = $arch\n" >> $METADATAFILE done } declare -a templates getTemplateVersion $1 -templates=( "kvm:https://download.cloudstack.org/systemvm/${CS_VERSION}/systemvmtemplate-$VERSION-kvm.qcow2.bz2" - "vmware:https://download.cloudstack.org/systemvm/${CS_VERSION}/systemvmtemplate-$VERSION-vmware.ova" - "xenserver:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-xen.vhd.bz2" - "hyperv:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-hyperv.vhd.zip" - "lxc:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-kvm.qcow2.bz2" - "ovm3:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-ovm.raw.bz2" ) +templates=( "kvm:https://download.cloudstack.org/systemvm/${CS_VERSION}/systemvmtemplate-$VERSION-x86_64-kvm.qcow2.bz2" + "vmware:https://download.cloudstack.org/systemvm/${CS_VERSION}/systemvmtemplate-$VERSION-x86_64-vmware.ova" + "xenserver:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-xen.vhd.bz2" + "hyperv:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-hyperv.vhd.zip" + "lxc:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-kvm.qcow2.bz2" + "ovm3:https://download.cloudstack.org/systemvm/$CS_VERSION/systemvmtemplate-$VERSION-x86_64-ovm.raw.bz2" ) PARENTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/dist/systemvm-templates/" mkdir -p $PARENTPATH diff --git a/engine/service/pom.xml b/engine/service/pom.xml index 9b92b831eb72..34221e1001dd 100644 --- a/engine/service/pom.xml +++ b/engine/service/pom.xml @@ -22,7 +22,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT cloud-engine-service war @@ -66,6 +66,11 @@ engine + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + org.eclipse.jetty jetty-maven-plugin diff --git a/engine/service/src/main/webapp/WEB-INF/log4j.xml b/engine/service/src/main/webapp/WEB-INF/log4j.xml index 19d48b47e836..48d61a10b413 100644 --- a/engine/service/src/main/webapp/WEB-INF/log4j.xml +++ b/engine/service/src/main/webapp/WEB-INF/log4j.xml @@ -16,24 +16,41 @@ specific language governing permissions and limitations under the License. --> - - - - - - - - - - - - - - - - - - - - - + + + + + net.sf.cglib.proxy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/engine/storage/cache/pom.xml b/engine/storage/cache/pom.xml index 06e6280068ea..a1b7aff7afd0 100644 --- a/engine/storage/cache/pom.xml +++ b/engine/storage/cache/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java b/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java index 22b3f46a9463..fe3bb5cf00da 100644 --- a/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java +++ b/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java @@ -22,7 +22,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; @@ -39,7 +40,7 @@ @Component public class StorageCacheRandomAllocator implements StorageCacheAllocator { - private static final Logger s_logger = Logger.getLogger(StorageCacheRandomAllocator.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject DataStoreManager dataStoreMgr; @Inject @@ -52,13 +53,13 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator { @Override public DataStore getCacheStore(Scope scope) { if (scope.getScopeType() != ScopeType.ZONE) { - s_logger.debug("Can only support zone wide cache storage"); + logger.debug("Can only support zone wide cache storage"); return null; } List cacheStores = dataStoreMgr.getImageCacheStores(scope); if ((cacheStores == null) || (cacheStores.size() <= 0)) { - s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); + logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); return null; } @@ -68,13 +69,13 @@ public DataStore getCacheStore(Scope scope) { @Override public DataStore getCacheStore(DataObject data, Scope scope) { if (scope.getScopeType() != ScopeType.ZONE) { - s_logger.debug("Can only support zone wide cache storage"); + logger.debug("Can only support zone wide cache storage"); return null; } List cacheStores = dataStoreMgr.getImageCacheStores(scope); if (cacheStores.size() <= 0) { - s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); + logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); return null; } @@ -83,7 +84,7 @@ public DataStore getCacheStore(DataObject data, Scope scope) { for (DataStore store : cacheStores) { DataObjectInStore obj = objectInStoreMgr.findObject(data, store); if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready && statsCollector.imageStoreHasEnoughCapacity(store)) { - s_logger.debug("pick the cache store " + store.getId() + " where data is already there"); + logger.debug("pick the cache store " + store.getId() + " where data is already there"); return store; } } diff --git a/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java b/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java index a687ddfc4371..889d0ce14ccc 100644 --- a/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java +++ b/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java @@ -32,7 +32,8 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService; @@ -64,7 +65,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class StorageCacheManagerImpl implements StorageCacheManager, Manager { - private static final Logger s_logger = Logger.getLogger(StorageCacheManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject List storageCacheAllocator; @Inject @@ -195,7 +196,7 @@ protected void runInContext() { } } } catch (Exception e) { - s_logger.debug("Failed to execute CacheReplacementRunner: " + e.toString()); + logger.debug("Failed to execute CacheReplacementRunner: " + e.toString()); } finally { if (replacementLock != null) { replacementLock.unlock(); @@ -245,7 +246,7 @@ public DataObject createCacheObject(DataObject data, DataStore store) { String msg = "unsupported DataObject comes, then can't acquire correct lock object"; throw new CloudRuntimeException(msg); } - s_logger.debug("check " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")"); + logger.debug("check " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")"); DataObject existingDataObj = null; synchronized (lock) { @@ -271,13 +272,13 @@ public DataObject createCacheObject(DataObject data, DataStore store) { * Threads must release lock within waiting for cache copy and * must be waken up at completion. */ - s_logger.debug("waiting cache copy completion type: " + typeName + ", id: " + obj.getObjectId() + ", lock: " + lock.hashCode()); + logger.debug("waiting cache copy completion type: " + typeName + ", id: " + obj.getObjectId() + ", lock: " + lock.hashCode()); try { lock.wait(milliSeconds); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while waiting for cache copy completion."); + logger.debug("[ignored] interrupted while waiting for cache copy completion."); } - s_logger.debug("waken up"); + logger.debug("waken up"); now = new Date(); if (now.after(expiredDate)) { @@ -290,7 +291,7 @@ public DataObject createCacheObject(DataObject data, DataStore store) { } if (st == ObjectInDataStoreStateMachine.State.Ready) { - s_logger.debug("there is already one in the cache store"); + logger.debug("there is already one in the cache store"); DataObject dataObj = objectInStoreMgr.get(data, store, null); dataObj.incRefCount(); existingDataObj = dataObj; @@ -298,7 +299,7 @@ public DataObject createCacheObject(DataObject data, DataStore store) { } if(existingDataObj == null) { - s_logger.debug("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")"); + logger.debug("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")"); objOnCacheStore = store.create(data); } lock.notifyAll(); @@ -307,7 +308,7 @@ public DataObject createCacheObject(DataObject data, DataStore store) { return existingDataObj; } if (objOnCacheStore == null) { - s_logger.error("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ") failed"); + logger.error("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ") failed"); return null; } @@ -327,10 +328,10 @@ public DataObject createCacheObject(DataObject data, DataStore store) { return objOnCacheStore; } } catch (InterruptedException e) { - s_logger.debug("create cache storage failed: " + e.toString()); + logger.debug("create cache storage failed: " + e.toString()); throw new CloudRuntimeException(e); } catch (ExecutionException e) { - s_logger.debug("create cache storage failed: " + e.toString()); + logger.debug("create cache storage failed: " + e.toString()); throw new CloudRuntimeException(e); } finally { if (result == null) { @@ -340,7 +341,7 @@ public DataObject createCacheObject(DataObject data, DataStore store) { /* * Wake up all threads waiting for cache copy. */ - s_logger.debug("wake up all waiting threads(lock: " + lock.hashCode() + ")"); + logger.debug("wake up all waiting threads(lock: " + lock.hashCode() + ")"); lock.notifyAll(); } } diff --git a/engine/storage/cache/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-cache-core-context.xml b/engine/storage/cache/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-cache-core-context.xml index f98b06da2a8e..2038cfac9457 100644 --- a/engine/storage/cache/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-cache-core-context.xml +++ b/engine/storage/cache/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-cache-core-context.xml @@ -34,5 +34,5 @@ - + diff --git a/engine/storage/configdrive/pom.xml b/engine/storage/configdrive/pom.xml index 30d16956a724..b14acf101386 100644 --- a/engine/storage/configdrive/pom.xml +++ b/engine/storage/configdrive/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java b/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java index e02c0920004d..58cc341a87ba 100644 --- a/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java +++ b/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java @@ -22,6 +22,8 @@ import static com.cloud.network.NetworkModel.CONFIGDATA_FILE; import static com.cloud.network.NetworkModel.PASSWORD_FILE; import static com.cloud.network.NetworkModel.USERDATA_FILE; +import static com.cloud.network.NetworkService.DEFAULT_MTU; +import static org.apache.cloudstack.storage.configdrive.ConfigDriveUtils.mergeJsonArraysAndUpdateObject; import java.io.File; import java.io.IOException; @@ -33,11 +35,15 @@ import java.util.Map; import java.util.Set; +import com.cloud.network.Network; +import com.cloud.vm.NicProfile; +import com.googlecode.ipv6.IPv6Network; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.MapUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.joda.time.Duration; import com.cloud.network.NetworkModel; @@ -49,7 +55,7 @@ public class ConfigDriveBuilder { - public static final Logger LOG = Logger.getLogger(ConfigDriveBuilder.class); + protected static Logger LOGGER = LogManager.getLogger(ConfigDriveBuilder.class); /** * This is for mocking the File class. We cannot mock the File class directly because Mockito uses it internally. @@ -80,7 +86,7 @@ static void writeFile(File folder, String file, String content) { /** * Read the content of a {@link File} and convert it to a String in base 64. - * We expect the content of the file to be encoded using {@link StandardCharsets#US_ASC} + * We expect the content of the file to be encoded using {@link StandardCharsets#US_ASCII} */ public static String fileToBase64String(File isoFile) throws IOException { byte[] encoded = Base64.encodeBase64(FileUtils.readFileToByteArray(isoFile)); @@ -98,7 +104,7 @@ public static File base64StringToFile(String encodedIsoData, String folder, Stri try { Files.createDirectories(destPath.getParent()); } catch (final IOException e) { - LOG.warn("Exception hit while trying to recreate directory: " + destPath.getParent().toString()); + LOGGER.warn("Exception hit while trying to recreate directory: " + destPath.getParent().toString()); } return Files.write(destPath, decoded).toFile(); } @@ -107,9 +113,9 @@ public static File base64StringToFile(String encodedIsoData, String folder, Stri * This method will build the metadata files required by OpenStack driver. Then, an ISO is going to be generated and returned as a String in base 64. * If vmData is null, we throw a {@link CloudRuntimeException}. Moreover, {@link IOException} are captured and re-thrown as {@link CloudRuntimeException}. */ - public static String buildConfigDrive(List vmData, String isoFileName, String driveLabel, Map customUserdataParams) { - if (vmData == null) { - throw new CloudRuntimeException("No VM metadata provided"); + public static String buildConfigDrive(List nics, List vmData, String isoFileName, String driveLabel, Map customUserdataParams, Map> supportedServices) { + if (vmData == null && nics == null) { + throw new CloudRuntimeException("No VM metadata and nic profile provided"); } Path tempDir = null; @@ -120,10 +126,19 @@ public static String buildConfigDrive(List vmData, String isoFileName, File openStackFolder = new File(tempDirName + ConfigDrive.openStackConfigDriveName); - writeVendorAndNetworkEmptyJsonFile(openStackFolder); - writeVmMetadata(vmData, tempDirName, openStackFolder, customUserdataParams); - - linkUserData(tempDirName); + writeVendorEmptyJsonFile(openStackFolder); + writeNetworkData(nics, supportedServices, openStackFolder); + for (NicProfile nic: nics) { + if (supportedServices.get(nic.getId()).contains(Network.Service.UserData)) { + if (vmData == null) { + throw new CloudRuntimeException("No VM metadata provided"); + } + writeVmMetadata(vmData, tempDirName, openStackFolder, customUserdataParams); + + linkUserData(tempDirName); + break; + } + } return generateAndRetrieveIsoAsBase64Iso(isoFileName, driveLabel, tempDirName); } catch (IOException e) { @@ -139,7 +154,7 @@ private static void deleteTempDir(Path tempDir) { FileUtils.deleteDirectory(tempDir.toFile()); } } catch (IOException ioe) { - LOG.warn("Failed to delete ConfigDrive temporary directory: " + tempDir.toString(), ioe); + LOGGER.warn("Failed to delete ConfigDrive temporary directory: " + tempDir.toString(), ioe); } } @@ -151,7 +166,7 @@ private static void deleteTempDir(Path tempDir) { */ static String generateAndRetrieveIsoAsBase64Iso(String isoFileName, String driveLabel, String tempDirName) throws IOException { File tmpIsoStore = getFile(tempDirName, isoFileName); - Script command = new Script(getProgramToGenerateIso(), Duration.standardSeconds(300), LOG); + Script command = new Script(getProgramToGenerateIso(), Duration.standardSeconds(300), LOGGER); command.add("-o", tmpIsoStore.getAbsolutePath()); command.add("-ldots"); command.add("-allow-lowercase"); @@ -163,11 +178,11 @@ static String generateAndRetrieveIsoAsBase64Iso(String isoFileName, String drive command.add("-r"); command.add("-V", driveLabel); command.add(tempDirName); - LOG.debug("Executing config drive creation command: " + command.toString()); + LOGGER.debug("Executing config drive creation command: " + command.toString()); String result = command.execute(); if (StringUtils.isNotBlank(result)) { String errMsg = "Unable to create iso file: " + isoFileName + " due to ge" + result; - LOG.warn(errMsg); + LOGGER.warn(errMsg); throw new CloudRuntimeException(errMsg); } File tmpIsoFile = getFile(tmpIsoStore.getAbsolutePath()); @@ -211,18 +226,36 @@ static void writeVmMetadata(List vmData, String tempDirName, File open } /** - * Writes the following empty JSON files: - *

    - *
  • vendor_data.json - *
  • network_data.json - *
+ * First we generate a JSON object using {@link #getNetworkDataJsonObjectForNic(NicProfile, List)}, then we write it to a file called "network_data.json". + */ + static void writeNetworkData(List nics, Map> supportedServices, File openStackFolder) { + JsonObject finalNetworkData = new JsonObject(); + if (needForGeneratingNetworkData(supportedServices)) { + for (NicProfile nic : nics) { + List supportedService = supportedServices.get(nic.getId()); + JsonObject networkData = getNetworkDataJsonObjectForNic(nic, supportedService); + + mergeJsonArraysAndUpdateObject(finalNetworkData, networkData, "links", "id", "type"); + mergeJsonArraysAndUpdateObject(finalNetworkData, networkData, "networks", "id", "type"); + mergeJsonArraysAndUpdateObject(finalNetworkData, networkData, "services", "address", "type"); + } + } + + writeFile(openStackFolder, "network_data.json", finalNetworkData.toString()); + } + + static boolean needForGeneratingNetworkData(Map> supportedServices) { + return supportedServices.values().stream().anyMatch(services -> services.contains(Network.Service.Dhcp) || services.contains(Network.Service.Dns)); + } + + /** + * Writes an empty JSON file named vendor_data.json in openStackFolder * - * If the folder does not exist and we cannot create it, we throw a {@link CloudRuntimeException}. + * If the folder does not exist, and we cannot create it, we throw a {@link CloudRuntimeException}. */ - static void writeVendorAndNetworkEmptyJsonFile(File openStackFolder) { + static void writeVendorEmptyJsonFile(File openStackFolder) { if (openStackFolder.exists() || openStackFolder.mkdirs()) { writeFile(openStackFolder, "vendor_data.json", "{}"); - writeFile(openStackFolder, "network_data.json", "{}"); } else { throw new CloudRuntimeException("Failed to create folder " + openStackFolder); } @@ -242,13 +275,127 @@ static JsonObject createJsonObjectWithVmData(List vmData, String tempD String dataType = item[CONFIGDATA_DIR]; String fileName = item[CONFIGDATA_FILE]; String content = item[CONFIGDATA_CONTENT]; - LOG.debug(String.format("[createConfigDriveIsoForVM] dataType=%s, filename=%s, content=%s", dataType, fileName, (PASSWORD_FILE.equals(fileName) ? "********" : content))); + LOGGER.debug(String.format("[createConfigDriveIsoForVM] dataType=%s, filename=%s, content=%s", dataType, fileName, (PASSWORD_FILE.equals(fileName) ? "********" : content))); createFileInTempDirAnAppendOpenStackMetadataToJsonObject(tempDirName, metaData, dataType, fileName, content, customUserdataParams); } return metaData; } + /** + * Creates the {@link JsonObject} using @param nic's metadata. We expect the JSONObject to have the following entries: + *
    + *
  • links
  • + *
  • networks
  • + *
  • services
  • + *
+ */ + static JsonObject getNetworkDataJsonObjectForNic(NicProfile nic, List supportedServices) { + JsonObject networkData = new JsonObject(); + + JsonArray links = getLinksJsonArrayForNic(nic); + JsonArray networks = getNetworksJsonArrayForNic(nic); + if (links.size() > 0) { + networkData.add("links", links); + } + if (networks.size() > 0) { + networkData.add("networks", networks); + } + + JsonArray services = getServicesJsonArrayForNic(nic); + if (services.size() > 0) { + networkData.add("services", services); + } + + return networkData; + } + + static JsonArray getLinksJsonArrayForNic(NicProfile nic) { + JsonArray links = new JsonArray(); + if (StringUtils.isNotBlank(nic.getMacAddress())) { + JsonObject link = new JsonObject(); + link.addProperty("ethernet_mac_address", nic.getMacAddress()); + link.addProperty("id", String.format("eth%d", nic.getDeviceId())); + link.addProperty("mtu", nic.getMtu() != null ? nic.getMtu() : DEFAULT_MTU); + link.addProperty("type", "phy"); + links.add(link); + } + return links; + } + + static JsonArray getNetworksJsonArrayForNic(NicProfile nic) { + JsonArray networks = new JsonArray(); + if (StringUtils.isNotBlank(nic.getIPv4Address())) { + JsonObject ipv4Network = new JsonObject(); + ipv4Network.addProperty("id", String.format("eth%d", nic.getDeviceId())); + ipv4Network.addProperty("ip_address", nic.getIPv4Address()); + ipv4Network.addProperty("link", String.format("eth%d", nic.getDeviceId())); + ipv4Network.addProperty("netmask", nic.getIPv4Netmask()); + ipv4Network.addProperty("network_id", nic.getUuid()); + ipv4Network.addProperty("type", "ipv4"); + + JsonArray ipv4RouteArray = new JsonArray(); + JsonObject ipv4Route = new JsonObject(); + ipv4Route.addProperty("gateway", nic.getIPv4Gateway()); + ipv4Route.addProperty("netmask", "0.0.0.0"); + ipv4Route.addProperty("network", "0.0.0.0"); + ipv4RouteArray.add(ipv4Route); + + ipv4Network.add("routes", ipv4RouteArray); + + networks.add(ipv4Network); + } + + if (StringUtils.isNotBlank(nic.getIPv6Address())) { + JsonObject ipv6Network = new JsonObject(); + ipv6Network.addProperty("id", String.format("eth%d", nic.getDeviceId())); + ipv6Network.addProperty("ip_address", nic.getIPv6Address()); + ipv6Network.addProperty("link", String.format("eth%d", nic.getDeviceId())); + ipv6Network.addProperty("netmask", IPv6Network.fromString(nic.getIPv6Cidr()).getNetmask().toString()); + ipv6Network.addProperty("network_id", nic.getUuid()); + ipv6Network.addProperty("type", "ipv6"); + + JsonArray ipv6RouteArray = new JsonArray(); + JsonObject ipv6Route = new JsonObject(); + ipv6Route.addProperty("gateway", nic.getIPv6Gateway()); + ipv6Route.addProperty("netmask", "0"); + ipv6Route.addProperty("network", "::"); + ipv6RouteArray.add(ipv6Route); + + ipv6Network.add("routes", ipv6RouteArray); + + networks.add(ipv6Network); + } + return networks; + } + + static JsonArray getServicesJsonArrayForNic(NicProfile nic) { + JsonArray services = new JsonArray(); + if (StringUtils.isNotBlank(nic.getIPv4Dns1())) { + services.add(getDnsServiceObject(nic.getIPv4Dns1())); + } + + if (StringUtils.isNotBlank(nic.getIPv4Dns2())) { + services.add(getDnsServiceObject(nic.getIPv4Dns2())); + } + + if (StringUtils.isNotBlank(nic.getIPv6Dns1())) { + services.add(getDnsServiceObject(nic.getIPv6Dns1())); + } + + if (StringUtils.isNotBlank(nic.getIPv6Dns2())) { + services.add(getDnsServiceObject(nic.getIPv6Dns2())); + } + return services; + } + + private static JsonObject getDnsServiceObject(String dnsAddress) { + JsonObject dnsService = new JsonObject(); + dnsService.addProperty("address", dnsAddress); + dnsService.addProperty("type", "dns"); + return dnsService; + } + static void createFileInTempDirAnAppendOpenStackMetadataToJsonObject(String tempDirName, JsonObject metaData, String dataType, String fileName, String content, Map customUserdataParams) { if (StringUtils.isBlank(dataType)) { return; @@ -299,10 +446,10 @@ static void linkUserData(String tempDirName) { String userDataFilePath = tempDirName + ConfigDrive.cloudStackConfigDriveName + "userdata/user_data.txt"; File file = getFile(userDataFilePath); if (file.exists()) { - Script hardLink = new Script("ln", Duration.standardSeconds(300), LOG); + Script hardLink = new Script("ln", Duration.standardSeconds(300), LOGGER); hardLink.add(userDataFilePath); hardLink.add(tempDirName + ConfigDrive.openStackConfigDriveName + "user_data"); - LOG.debug("execute command: " + hardLink.toString()); + LOGGER.debug("execute command: " + hardLink.toString()); String executionResult = hardLink.execute(); if (StringUtils.isNotBlank(executionResult)) { diff --git a/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveUtils.java b/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveUtils.java new file mode 100644 index 000000000000..8847497f193c --- /dev/null +++ b/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveUtils.java @@ -0,0 +1,54 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.storage.configdrive; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class ConfigDriveUtils { + + static void mergeJsonArraysAndUpdateObject(JsonObject finalObject, JsonObject newObj, String memberName, String... keys) { + JsonArray existingMembers = finalObject.has(memberName) ? finalObject.get(memberName).getAsJsonArray() : new JsonArray(); + JsonArray newMembers = newObj.has(memberName) ? newObj.get(memberName).getAsJsonArray() : new JsonArray(); + + if (existingMembers.size() > 0 || newMembers.size() > 0) { + JsonArray finalMembers = new JsonArray(); + Set idSet = new HashSet<>(); + for (JsonElement element : existingMembers.getAsJsonArray()) { + JsonObject elementObject = element.getAsJsonObject(); + String key = Arrays.stream(keys).map(elementObject::get).map(JsonElement::getAsString).reduce((a, b) -> a + "-" + b).orElse(""); + idSet.add(key); + finalMembers.add(element); + } + for (JsonElement element : newMembers.getAsJsonArray()) { + JsonObject elementObject = element.getAsJsonObject(); + String key = Arrays.stream(keys).map(elementObject::get).map(JsonElement::getAsString).reduce((a, b) -> a + "-" + b).orElse(""); + if (!idSet.contains(key)) { + finalMembers.add(element); + } + } + finalObject.add(memberName, finalMembers); + } + } + +} diff --git a/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java b/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java index 6ef248fdd623..3effdb5ba212 100644 --- a/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java +++ b/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java @@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import java.io.File; @@ -27,14 +28,21 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.cloud.network.Network; +import com.cloud.vm.NicProfile; +import com.google.gson.JsonParser; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.mockito.InOrder; import org.mockito.MockedConstruction; @@ -49,6 +57,13 @@ @RunWith(MockitoJUnitRunner.class) public class ConfigDriveBuilderTest { + private static Map> supportedServices; + + @BeforeClass + public static void beforeClass() throws Exception { + supportedServices = Map.of(1L, List.of(Network.Service.UserData, Network.Service.Dhcp, Network.Service.Dns)); + } + @Test public void writeFileTest() { try (MockedStatic fileUtilsMocked = Mockito.mockStatic(FileUtils.class)) { @@ -112,16 +127,16 @@ public void base64StringToFileTest() throws Exception { } @Test(expected = CloudRuntimeException.class) - public void buildConfigDriveTestNoVmData() { - ConfigDriveBuilder.buildConfigDrive(null, "teste", "C:", null); + public void buildConfigDriveTestNoVmDataAndNic() { + ConfigDriveBuilder.buildConfigDrive(null, null, "teste", "C:", null, null); } @Test(expected = CloudRuntimeException.class) public void buildConfigDriveTestIoException() { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { - configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(nullable(File.class))).thenThrow(CloudRuntimeException.class); - Mockito.when(ConfigDriveBuilder.buildConfigDrive(new ArrayList<>(), "teste", "C:", null)).thenCallRealMethod(); - ConfigDriveBuilder.buildConfigDrive(new ArrayList<>(), "teste", "C:", null); + configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVendorEmptyJsonFile(nullable(File.class))).thenThrow(CloudRuntimeException.class); + Mockito.when(ConfigDriveBuilder.buildConfigDrive(null, new ArrayList<>(), "teste", "C:", null, supportedServices)).thenCallRealMethod(); + ConfigDriveBuilder.buildConfigDrive(null, new ArrayList<>(), "teste", "C:", null, supportedServices); } } @@ -129,23 +144,27 @@ public void buildConfigDriveTestIoException() { public void buildConfigDriveTest() { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { - configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(Mockito.any(File.class))).then(invocationOnMock -> null); + configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVendorEmptyJsonFile(Mockito.any(File.class))).then(invocationOnMock -> null); - configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVmMetadata(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.any(File.class), anyMap())).then(invocationOnMock -> null); + configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVmMetadata(Mockito.anyList(), Mockito.anyString(), Mockito.any(File.class), anyMap())).then(invocationOnMock -> null); configDriveBuilderMocked.when(() -> ConfigDriveBuilder.linkUserData((Mockito.anyString()))).then(invocationOnMock -> null); configDriveBuilderMocked.when(() -> ConfigDriveBuilder.generateAndRetrieveIsoAsBase64Iso(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenAnswer(invocation -> "mockIsoDataBase64"); + + NicProfile mockedNicProfile = Mockito.mock(NicProfile.class); + Mockito.when(mockedNicProfile.getId()).thenReturn(1L); + //force execution of real method - Mockito.when(ConfigDriveBuilder.buildConfigDrive(new ArrayList<>(), "teste", "C:", null)).thenCallRealMethod(); + Mockito.when(ConfigDriveBuilder.buildConfigDrive(List.of(mockedNicProfile), new ArrayList<>(), "teste", "C:", null, supportedServices)).thenCallRealMethod(); - String returnedIsoData = ConfigDriveBuilder.buildConfigDrive(new ArrayList<>(), "teste", "C:", null); + String returnedIsoData = ConfigDriveBuilder.buildConfigDrive(List.of(mockedNicProfile), new ArrayList<>(), "teste", "C:", null, supportedServices); Assert.assertEquals("mockIsoDataBase64", returnedIsoData); configDriveBuilderMocked.verify(() -> { - ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(Mockito.any(File.class)); - ConfigDriveBuilder.writeVmMetadata(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.any(File.class), anyMap()); + ConfigDriveBuilder.writeVendorEmptyJsonFile(Mockito.any(File.class)); + ConfigDriveBuilder.writeVmMetadata(Mockito.anyList(), Mockito.anyString(), Mockito.any(File.class), anyMap()); ConfigDriveBuilder.linkUserData(Mockito.anyString()); ConfigDriveBuilder.generateAndRetrieveIsoAsBase64Iso(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); }); @@ -153,23 +172,23 @@ public void buildConfigDriveTest() { } @Test(expected = CloudRuntimeException.class) - public void writeVendorAndNetworkEmptyJsonFileTestCannotCreateOpenStackFolder() { + public void writeVendorEmptyJsonFileTestCannotCreateOpenStackFolder() { File folderFileMock = Mockito.mock(File.class); Mockito.doReturn(false).when(folderFileMock).mkdirs(); - ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(folderFileMock); + ConfigDriveBuilder.writeVendorEmptyJsonFile(folderFileMock); } @Test(expected = CloudRuntimeException.class) - public void writeVendorAndNetworkEmptyJsonFileTest() { + public void writeVendorEmptyJsonFileTest() { File folderFileMock = Mockito.mock(File.class); Mockito.doReturn(false).when(folderFileMock).mkdirs(); - ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(folderFileMock); + ConfigDriveBuilder.writeVendorEmptyJsonFile(folderFileMock); } @Test - public void writeVendorAndNetworkEmptyJsonFileTestCreatingFolder() { + public void writeVendorEmptyJsonFileTestCreatingFolder() { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { File folderFileMock = Mockito.mock(File.class); @@ -177,9 +196,9 @@ public void writeVendorAndNetworkEmptyJsonFileTestCreatingFolder() { Mockito.doReturn(true).when(folderFileMock).mkdirs(); //force execution of real method - configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(folderFileMock)).thenCallRealMethod(); + configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVendorEmptyJsonFile(folderFileMock)).thenCallRealMethod(); - ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(folderFileMock); + ConfigDriveBuilder.writeVendorEmptyJsonFile(folderFileMock); Mockito.verify(folderFileMock).exists(); Mockito.verify(folderFileMock).mkdirs(); @@ -194,7 +213,7 @@ public void writeVendorAndNetworkEmptyJsonFileTestCreatingFolder() { @Test public void writeVmMetadataTest() { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { - Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.anyMap())).thenReturn(new JsonObject()); + Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyList(), Mockito.anyString(), Mockito.anyMap())).thenReturn(new JsonObject()); List vmData = new ArrayList<>(); vmData.add(new String[]{"dataType", "fileName", "content"}); @@ -347,7 +366,7 @@ public void createJsonObjectWithVmDataTesT() { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { - Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.nullable(Map.class))).thenCallRealMethod(); + Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyList(), Mockito.anyString(), Mockito.nullable(Map.class))).thenCallRealMethod(); List vmData = new ArrayList<>(); vmData.add(new String[]{"dataType", "fileName", "content"}); @@ -501,4 +520,143 @@ public void getProgramToGenerateIsoTestMkIsoMac() throws Exception { Mockito.verify(mkIsoProgramInMacOsFileMock, Mockito.times(1)).getCanonicalPath(); } } + + @Test + public void testWriteNetworkData() throws Exception { + // Setup + NicProfile nicp = mock(NicProfile.class); + Mockito.when(nicp.getId()).thenReturn(1L); + + Mockito.when(nicp.getMacAddress()).thenReturn("00:00:00:00:00:00"); + Mockito.when(nicp.getMtu()).thenReturn(2000); + + Mockito.when(nicp.getIPv4Address()).thenReturn("172.31.0.10"); + Mockito.when(nicp.getDeviceId()).thenReturn(1); + Mockito.when(nicp.getIPv4Netmask()).thenReturn("255.255.255.0"); + Mockito.when(nicp.getUuid()).thenReturn("NETWORK UUID"); + Mockito.when(nicp.getIPv4Gateway()).thenReturn("172.31.0.1"); + + + Mockito.when(nicp.getIPv6Address()).thenReturn("2001:db8:0:1234:0:567:8:1"); + Mockito.when(nicp.getIPv6Cidr()).thenReturn("2001:db8:0:1234:0:567:8:1/64"); + Mockito.when(nicp.getIPv6Gateway()).thenReturn("2001:db8:0:1234:0:567:8::1"); + + Mockito.when(nicp.getIPv4Dns1()).thenReturn("8.8.8.8"); + Mockito.when(nicp.getIPv4Dns2()).thenReturn("1.1.1.1"); + Mockito.when(nicp.getIPv6Dns1()).thenReturn("2001:4860:4860::8888"); + Mockito.when(nicp.getIPv6Dns2()).thenReturn("2001:4860:4860::8844"); + + + List services1 = Arrays.asList(Network.Service.Dhcp, Network.Service.Dns); + + Map> supportedServices = new HashMap<>(); + supportedServices.put(1L, services1); + + TemporaryFolder folder = new TemporaryFolder(); + folder.create(); + File openStackFolder = folder.newFolder("openStack"); + + // Expected JSON structure + String expectedJson = "{" + + " \"links\": [" + + " {" + + " \"ethernet_mac_address\": \"00:00:00:00:00:00\"," + + " \"id\": \"eth1\"," + + " \"mtu\": 2000," + + " \"type\": \"phy\"" + + " }" + + " ]," + + " \"networks\": [" + + " {" + + " \"id\": \"eth1\"," + + " \"ip_address\": \"172.31.0.10\"," + + " \"link\": \"eth1\"," + + " \"netmask\": \"255.255.255.0\"," + + " \"network_id\": \"NETWORK UUID\"," + + " \"type\": \"ipv4\"," + + " \"routes\": [" + + " {" + + " \"gateway\": \"172.31.0.1\"," + + " \"netmask\": \"0.0.0.0\"," + + " \"network\": \"0.0.0.0\"" + + " }" + + " ]" + + " }," + + " {" + + " \"id\": \"eth1\"," + + " \"ip_address\": \"2001:db8:0:1234:0:567:8:1\"," + + " \"link\": \"eth1\"," + + " \"netmask\": \"64\"," + + " \"network_id\": \"NETWORK UUID\"," + + " \"type\": \"ipv6\"," + + " \"routes\": [" + + " {" + + " \"gateway\": \"2001:db8:0:1234:0:567:8::1\"," + + " \"netmask\": \"0\"," + + " \"network\": \"::\"" + + " }" + + " ]" + + " }" + + " ]," + + " \"services\": [" + + " {" + + " \"address\": \"8.8.8.8\"," + + " \"type\": \"dns\"" + + " }," + + " {" + + " \"address\": \"1.1.1.1\"," + + " \"type\": \"dns\"" + + " }," + + " {" + + " \"address\": \"2001:4860:4860::8888\"," + + " \"type\": \"dns\"" + + " }," + + " {" + + " \"address\": \"2001:4860:4860::8844\"," + + " \"type\": \"dns\"" + + " }" + + " ]" + + "}"; + + // Action + ConfigDriveBuilder.writeNetworkData(Arrays.asList(nicp), supportedServices, openStackFolder); + + // Verify + File networkDataFile = new File(openStackFolder, "network_data.json"); + String content = FileUtils.readFileToString(networkDataFile, StandardCharsets.UTF_8); + JsonObject actualJson = new JsonParser().parse(content).getAsJsonObject(); + JsonObject expectedJsonObject = new JsonParser().parse(expectedJson).getAsJsonObject(); + + Assert.assertEquals(expectedJsonObject, actualJson); + folder.delete(); + } + + @Test + public void testWriteNetworkDataEmptyJson() throws Exception { + // Setup + NicProfile nicp = mock(NicProfile.class); + List services1 = Collections.emptyList(); + + Map> supportedServices = new HashMap<>(); + supportedServices.put(1L, services1); + + TemporaryFolder folder = new TemporaryFolder(); + folder.create(); + File openStackFolder = folder.newFolder("openStack"); + + // Expected JSON structure + String expectedJson = "{}"; + + // Action + ConfigDriveBuilder.writeNetworkData(Arrays.asList(nicp), supportedServices, openStackFolder); + + // Verify + File networkDataFile = new File(openStackFolder, "network_data.json"); + String content = FileUtils.readFileToString(networkDataFile, StandardCharsets.UTF_8); + JsonObject actualJson = new JsonParser().parse(content).getAsJsonObject(); + JsonObject expectedJsonObject = new JsonParser().parse(expectedJson).getAsJsonObject(); + + Assert.assertEquals(expectedJsonObject, actualJson); + folder.delete(); + } } diff --git a/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveUtilsTest.java b/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveUtilsTest.java new file mode 100644 index 000000000000..6e935b951da3 --- /dev/null +++ b/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveUtilsTest.java @@ -0,0 +1,108 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.storage.configdrive; + +import static org.apache.cloudstack.storage.configdrive.ConfigDriveUtils.mergeJsonArraysAndUpdateObject; + +import com.google.gson.JsonArray; +import com.google.gson.JsonParser; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import com.google.gson.JsonObject; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigDriveUtilsTest { + + @Test + public void testMergeJsonArraysAndUpdateObjectWithEmptyObjects() { + JsonObject finalObject = new JsonObject(); + JsonObject newObj = new JsonObject(); + mergeJsonArraysAndUpdateObject(finalObject, newObj, "links", "id", "type"); + Assert.assertEquals("{}", finalObject.toString()); + } + + @Test + public void testMergeJsonArraysAndUpdateObjectWithNewMembersAdded() { + JsonObject finalObject = new JsonObject(); + + JsonObject newObj = new JsonObject(); + JsonArray newMembers = new JsonArray(); + JsonObject newMember = new JsonObject(); + newMember.addProperty("id", "eth0"); + newMember.addProperty("type", "phy"); + newMembers.add(newMember); + newObj.add("links", newMembers); + + mergeJsonArraysAndUpdateObject(finalObject, newObj, "links", "id", "type"); + Assert.assertEquals(1, finalObject.getAsJsonArray("links").size()); + JsonObject expectedObj = new JsonParser().parse("{'links': [{'id': 'eth0', 'type': 'phy'}]}").getAsJsonObject(); + Assert.assertEquals(expectedObj, finalObject); + } + + @Test + public void testMergeJsonArraysAndUpdateObjectWithDuplicateMembersIgnored() { + JsonObject finalObject = new JsonObject(); + JsonArray existingMembers = new JsonArray(); + JsonObject existingMember = new JsonObject(); + existingMember.addProperty("id", "eth0"); + existingMember.addProperty("type", "phy"); + existingMembers.add(existingMember); + finalObject.add("links", existingMembers); + + JsonObject newObj = new JsonObject(); + newObj.add("links", existingMembers); // same as existingMembers for duplication + + mergeJsonArraysAndUpdateObject(finalObject, newObj, "links", "id", "type"); + Assert.assertEquals(1, finalObject.getAsJsonArray("links").size()); + JsonObject expectedObj = new JsonParser().parse("{'links': [{'id': 'eth0', 'type': 'phy'}]}").getAsJsonObject(); + Assert.assertEquals(expectedObj, finalObject); + } + + @Test + public void testMergeJsonArraysAndUpdateObjectWithDifferentMembers() { + JsonObject finalObject = new JsonObject(); + + JsonArray newMembers = new JsonArray(); + JsonObject newMember = new JsonObject(); + newMember.addProperty("id", "eth0"); + newMember.addProperty("type", "phy"); + newMembers.add(newMember); + finalObject.add("links", newMembers); + + JsonObject newObj = new JsonObject(); + newMembers = new JsonArray(); + newMember = new JsonObject(); + newMember.addProperty("id", "eth1"); + newMember.addProperty("type", "phy"); + newMembers.add(newMember); + newObj.add("links", newMembers); + + mergeJsonArraysAndUpdateObject(finalObject, newObj, "links", "id", "type"); + Assert.assertEquals(2, finalObject.getAsJsonArray("links").size()); + JsonObject expectedObj = new JsonParser().parse("{'links': [{'id': 'eth0', 'type': 'phy'}, {'id': 'eth1', 'type': 'phy'}]}").getAsJsonObject(); + Assert.assertEquals(expectedObj, finalObject); + } + + @Test(expected = NullPointerException.class) + public void testMergeJsonArraysAndUpdateObjectWithNullObjects() { + mergeJsonArraysAndUpdateObject(null, null, "services", "id", "type"); + } +} diff --git a/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/datamotion/pom.xml b/engine/storage/datamotion/pom.xml index d96350fa209e..5620ca8ef704 100644 --- a/engine/storage/datamotion/pom.xml +++ b/engine/storage/datamotion/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java index 370753ed9230..0b0065361d07 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java @@ -51,7 +51,8 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; @@ -81,7 +82,7 @@ @Component public class AncientDataMotionStrategy implements DataMotionStrategy { - private static final Logger s_logger = Logger.getLogger(AncientDataMotionStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String NO_REMOTE_ENDPOINT_SSVM = "No remote endpoint to send command, check if host or ssvm is down?"; private static final String NO_REMOTE_ENDPOINT_WITH_ENCRYPTION = "No remote endpoint to send command, unable to find a valid endpoint. Requires encryption support: %s"; @@ -126,8 +127,8 @@ protected boolean needCacheStorage(DataObject srcData, DataObject destData) { if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("needCacheStorage true, dest at " + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + srcTO.getPath() + " src role " + + if (logger.isDebugEnabled()) { + logger.debug("needCacheStorage true, dest at " + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + srcTO.getPath() + " src role " + srcStoreTO.getRole().toString()); } return true; @@ -157,7 +158,7 @@ private Scope pickCacheScopeForCopy(DataObject srcData, DataObject destData) { } else if (destScope.getScopeId() != null) { selectedScope = getZoneScope(destScope); } else { - s_logger.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); + logger.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); } return selectedScope; } @@ -177,7 +178,7 @@ protected Answer copyObject(DataObject srcData, DataObject destData, Host destHo VirtualMachineManager.ExecuteInSequence.value()); EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcForCopy, destData); if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -193,19 +194,19 @@ protected Answer copyObject(DataObject srcData, DataObject destData, Host destHo destData.getType() == DataObjectType.TEMPLATE)) { // volume transfer from primary to secondary. Volume transfer between primary pools are already handled by copyVolumeBetweenPools // Delete cache in order to certainly transfer a latest image. - if (s_logger.isDebugEnabled()) s_logger.debug("Delete " + cacheType + " cache(id: " + cacheId + + if (logger.isDebugEnabled()) logger.debug("Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")"); cacheMgr.deleteCacheObject(srcForCopy); } else { // for template, we want to leave it on cache for performance reason if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) { // cache object created by this copy, not already there - s_logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + + logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + " Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")"); cacheMgr.deleteCacheObject(srcForCopy); } else { - if (s_logger.isDebugEnabled()) s_logger.debug("Decrease reference count of " + cacheType + + if (logger.isDebugEnabled()) logger.debug("Decrease reference count of " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")"); cacheMgr.releaseCacheObject(srcForCopy); } @@ -213,7 +214,7 @@ protected Answer copyObject(DataObject srcData, DataObject destData, Host destHo } return answer; } catch (Exception e) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy object failed: ", e); + if (logger.isDebugEnabled()) logger.debug("copy object failed: ", e); if (cacheData != null) { cacheMgr.deleteCacheObject(cacheData); } @@ -300,7 +301,7 @@ protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) { Answer answer = null; if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -308,7 +309,7 @@ protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) { return answer; } catch (Exception e) { - s_logger.error(basicErrMsg, e); + logger.error(basicErrMsg, e); throw new CloudRuntimeException(basicErrMsg); } finally { if (!(storTO instanceof NfsTO)) { @@ -324,14 +325,14 @@ protected Answer cloneVolume(DataObject template, DataObject volume) { EndPoint ep = selector.select(volume, anyVolumeRequiresEncryption(volume)); Answer answer = null; if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); } return answer; } catch (Exception e) { - if (s_logger.isDebugEnabled()) s_logger.debug("Failed to send to storage pool", e); + if (logger.isDebugEnabled()) logger.debug("Failed to send to storage pool", e); throw new CloudRuntimeException("Failed to send to storage pool", e); } } @@ -364,7 +365,7 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) Answer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -388,7 +389,7 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) if (answer == null || !answer.getResult()) { if (answer != null) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy to image store failed: " + answer.getDetails()); + if (logger.isDebugEnabled()) logger.debug("copy to image store failed: " + answer.getDetails()); } objOnImageStore.processEvent(Event.OperationFailed); imageStore.delete(objOnImageStore); @@ -403,7 +404,7 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) EndPoint ep = selector.select(objOnImageStore, destData, encryptionRequired); if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -411,7 +412,7 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) if (answer == null || !answer.getResult()) { if (answer != null) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy to primary store failed: " + answer.getDetails()); + if (logger.isDebugEnabled()) logger.debug("copy to primary store failed: " + answer.getDetails()); } objOnImageStore.processEvent(Event.OperationFailed); imageStore.delete(objOnImageStore); @@ -422,7 +423,7 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) objOnImageStore.processEvent(Event.OperationFailed); imageStore.delete(objOnImageStore); } - s_logger.error("Failed to perform operation: "+ e.getLocalizedMessage()); + logger.error("Failed to perform operation: "+ e.getLocalizedMessage()); throw e; } @@ -436,7 +437,7 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) Answer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -468,19 +469,19 @@ protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) { Answer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(command, false, errMsg); } else { - if (s_logger.isDebugEnabled()) s_logger.debug("Sending MIGRATE_COPY request to node " + ep); + if (logger.isDebugEnabled()) logger.debug("Sending MIGRATE_COPY request to node " + ep); answer = ep.sendMessage(command); - if (s_logger.isDebugEnabled()) s_logger.debug("Received MIGRATE_COPY response from node with answer: " + answer); + if (logger.isDebugEnabled()) logger.debug("Received MIGRATE_COPY response from node with answer: " + answer); } if (answer == null || !answer.getResult()) { throw new CloudRuntimeException("Failed to migrate volume " + volume + " to storage pool " + destPool); } else { // Update the volume details after migration. - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE_COPY updating volume"); + if (logger.isDebugEnabled()) logger.debug("MIGRATE_COPY updating volume"); VolumeVO volumeVo = volDao.findById(volume.getId()); Long oldPoolId = volume.getPoolId(); @@ -500,7 +501,7 @@ protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) { } volumeVo.setFolder(folder); volDao.update(volume.getId(), volumeVo); - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE_COPY update volume data complete"); + if (logger.isDebugEnabled()) logger.debug("MIGRATE_COPY update volume data complete"); } @@ -513,7 +514,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As Answer answer = null; String errMsg = null; try { - if (s_logger.isDebugEnabled()) s_logger.debug("copyAsync inspecting src type " + srcData.getType().toString() + " copyAsync inspecting dest type " + destData.getType().toString()); + if (logger.isDebugEnabled()) logger.debug("copyAsync inspecting src type " + srcData.getType().toString() + " copyAsync inspecting dest type " + destData.getType().toString()); if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.VOLUME) { answer = copyVolumeFromSnapshot(srcData, destData); } else if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.TEMPLATE) { @@ -522,16 +523,16 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As answer = cloneVolume(srcData, destData); } else if (destData.getType() == DataObjectType.VOLUME && srcData.getType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Primary && destData.getDataStore().getRole() == DataStoreRole.Primary) { - if (s_logger.isDebugEnabled()) s_logger.debug("About to MIGRATE copy between datasources"); + if (logger.isDebugEnabled()) logger.debug("About to MIGRATE copy between datasources"); if (srcData.getId() == destData.getId()) { // The volume has to be migrated across storage pools. - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE copy using migrateVolumeToPool STARTING"); + if (logger.isDebugEnabled()) logger.debug("MIGRATE copy using migrateVolumeToPool STARTING"); answer = migrateVolumeToPool(srcData, destData); - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE copy using migrateVolumeToPool DONE: " + answer.getResult()); + if (logger.isDebugEnabled()) logger.debug("MIGRATE copy using migrateVolumeToPool DONE: " + answer.getResult()); } else { - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE copy using copyVolumeBetweenPools STARTING"); + if (logger.isDebugEnabled()) logger.debug("MIGRATE copy using copyVolumeBetweenPools STARTING"); answer = copyVolumeBetweenPools(srcData, destData); - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE copy using copyVolumeBetweenPools DONE: " + answer.getResult()); + if (logger.isDebugEnabled()) logger.debug("MIGRATE copy using copyVolumeBetweenPools DONE: " + answer.getResult()); } } else if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.SNAPSHOT) { answer = copySnapshot(srcData, destData); @@ -543,7 +544,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As errMsg = answer.getDetails(); } } catch (Exception e) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy failed", e); + if (logger.isDebugEnabled()) logger.debug("copy failed", e); errMsg = e.toString(); } CopyCommandResult result = new CopyCommandResult(null, answer); @@ -574,7 +575,7 @@ protected Answer createTemplateFromSnapshot(DataObject srcData, DataObject destD CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest(destData.getTO()), _createprivatetemplatefromsnapshotwait, VirtualMachineManager.ExecuteInSequence.value()); Answer answer = null; if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -614,7 +615,7 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) { cmd.setOptions(options); EndPoint ep = selector.select(srcData, destData, encryptionRequired); if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -625,7 +626,7 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) { cmd.setOptions(options); EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT, encryptionRequired); if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -638,7 +639,7 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) { } return answer; } catch (Exception e) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy snasphot failed: ", e); + if (logger.isDebugEnabled()) logger.debug("copy snasphot failed: ", e); if (cacheData != null) { cacheMgr.deleteCacheObject(cacheData); } diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java index c8edb7b8abcf..e55302b8044d 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java @@ -36,7 +36,8 @@ import org.apache.cloudstack.secret.dao.PassphraseDao; import org.apache.cloudstack.storage.command.CopyCmdAnswer; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.api.to.VirtualMachineTO; @@ -48,7 +49,7 @@ @Component public class DataMotionServiceImpl implements DataMotionService { - private static final Logger LOGGER = Logger.getLogger(DataMotionServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject StorageStrategyFactory storageStrategyFactory; diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java index f2ccce756900..bf8fa43fe6c2 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.MigrateCommand; @@ -74,7 +73,6 @@ public class KvmNonManagedStorageDataMotionStrategy extends StorageSystemDataMot @Inject private VirtualMachineManager virtualMachineManager; - private static final Logger LOGGER = Logger.getLogger(KvmNonManagedStorageDataMotionStrategy.class); /** * Uses the canHandle from the Super class {@link StorageSystemDataMotionStrategy}. If the storage pool is of file and the internalCanHandle from {@link StorageSystemDataMotionStrategy} CANT_HANDLE, returns the StrategyPriority.HYPERVISOR strategy priority. otherwise returns CANT_HANDLE. @@ -212,7 +210,7 @@ protected void copyTemplateToTargetFilesystemStorageIfNeeded(VolumeInfo srcVolum TemplateInfo directDownloadTemplateInfo = templateDataFactory.getReadyBypassedTemplateOnPrimaryStore(srcVolumeInfo.getTemplateId(), destDataStore.getId(), destHost.getId()); if (directDownloadTemplateInfo != null) { - LOGGER.debug(String.format("Template %s was of direct download type and successfully staged to primary store %s", directDownloadTemplateInfo.getId(), directDownloadTemplateInfo.getDataStore().getId())); + logger.debug(String.format("Template %s was of direct download type and successfully staged to primary store %s", directDownloadTemplateInfo.getId(), directDownloadTemplateInfo.getDataStore().getId())); return; } @@ -223,7 +221,7 @@ protected void copyTemplateToTargetFilesystemStorageIfNeeded(VolumeInfo srcVolum TemplateInfo sourceTemplateInfo = templateDataFactory.getTemplate(srcVolumeInfo.getTemplateId(), sourceTemplateDataStore); TemplateObjectTO sourceTemplate = new TemplateObjectTO(sourceTemplateInfo); - LOGGER.debug(String.format("Could not find template [id=%s, name=%s] on the storage pool [id=%s]; copying the template to the target storage pool.", + logger.debug(String.format("Could not find template [id=%s, name=%s] on the storage pool [id=%s]; copying the template to the target storage pool.", srcVolumeInfo.getTemplateId(), sourceTemplateInfo.getName(), destDataStore.getId())); TemplateInfo destTemplateInfo = templateDataFactory.getTemplate(srcVolumeInfo.getTemplateId(), destDataStore); @@ -236,7 +234,7 @@ protected void copyTemplateToTargetFilesystemStorageIfNeeded(VolumeInfo srcVolum return; } } - LOGGER.debug(String.format("Skipping 'copy template to target filesystem storage before migration' due to the template [%s] already exist on the storage pool [%s].", srcVolumeInfo.getTemplateId(), destStoragePool.getId())); + logger.debug(String.format("Skipping 'copy template to target filesystem storage before migration' due to the template [%s] already exist on the storage pool [%s].", srcVolumeInfo.getTemplateId(), destStoragePool.getId())); } /** @@ -282,7 +280,7 @@ protected void logInCaseOfTemplateCopyFailure(Answer copyCommandAnswer, Template if (copyCommandAnswer.getDetails() != null) { failureDetails = " Details: " + copyCommandAnswer.getDetails(); } - LOGGER.error(generateFailToCopyTemplateMessage(sourceTemplate, destDataStore) + failureDetails); + logger.error(generateFailToCopyTemplateMessage(sourceTemplate, destDataStore) + failureDetails); } } diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java index c83d52c3d2b4..07b538426405 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java @@ -72,7 +72,8 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -145,7 +146,7 @@ import static org.apache.cloudstack.vm.UnmanagedVMsManagerImpl.VM_IMPORT_DEFAULT_TEMPLATE_NAME; public class StorageSystemDataMotionStrategy implements DataMotionStrategy { - private static final Logger LOGGER = Logger.getLogger(StorageSystemDataMotionStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final Random RANDOM = new Random(System.nanoTime()); private static final int LOCK_TIME_IN_SECONDS = 300; private static final String OPERATION_NOT_SUPPORTED = "This operation is not supported."; @@ -268,7 +269,7 @@ private boolean canHandle(DataObject dataObject) { Boolean supportsStorageSystemSnapshots = Boolean.valueOf(value); if (supportsStorageSystemSnapshots) { - LOGGER.info("Using 'StorageSystemDataMotionStrategy' (dataObject is a volume or snapshot and the storage system supports snapshots)"); + logger.info("Using 'StorageSystemDataMotionStrategy' (dataObject is a volume or snapshot and the storage system supports snapshots)"); return true; } @@ -278,7 +279,7 @@ private boolean canHandle(DataObject dataObject) { Boolean canCloneVolume = Boolean.valueOf(value); if (canCloneVolume) { - LOGGER.info("Using 'StorageSystemDataMotionStrategy' (dataObject is a template and the storage system can create a volume from a volume)"); + logger.info("Using 'StorageSystemDataMotionStrategy' (dataObject is a template and the storage system can create a volume from a volume)"); return true; } @@ -439,7 +440,7 @@ private void handleCopyAsyncForVolumes(VolumeInfo srcVolumeInfo, VolumeInfo dest } private void handleError(String errMsg, AsyncCompletionCallback callback) { - LOGGER.warn(errMsg); + logger.warn(errMsg); invokeCallback(errMsg, callback); @@ -643,8 +644,8 @@ private boolean needCacheStorage(DataObject srcData, DataObject destData) { return false; } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("needCacheStorage true; dest at " + destTO.getPath() + ", dest role " + destStoreTO.getRole().toString() + "; src at " + + if (logger.isDebugEnabled()) { + logger.debug("needCacheStorage true; dest at " + destTO.getPath() + ", dest role " + destStoreTO.getRole().toString() + "; src at " + srcTO.getPath() + ", src role " + srcStoreTO.getRole().toString()); } @@ -662,7 +663,7 @@ private Scope pickCacheScopeForCopy(DataObject srcData, DataObject destData) { } else if (destScope.getScopeId() != null) { selectedScope = getZoneScope(destScope); } else { - LOGGER.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); + logger.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); } return selectedScope; @@ -757,7 +758,7 @@ private void handleVolumeMigrationForXenServer(VolumeInfo srcVolumeInfo, VolumeI if (ep == null) { String errMsg = "No remote endpoint to send command to; check if host or SSVM is down"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(command, false, errMsg); } else { @@ -798,7 +799,7 @@ private void handleFailedVolumeMigration(VolumeInfo srcVolumeInfo, VolumeInfo de _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); } catch (Exception ex) { - LOGGER.warn("Failed to revoke access to the volume with the following ID: " + destVolumeInfo.getId()); + logger.warn("Failed to revoke access to the volume with the following ID: " + destVolumeInfo.getId()); } try { @@ -812,7 +813,7 @@ private void handleFailedVolumeMigration(VolumeInfo srcVolumeInfo, VolumeInfo de volumeDetailsDao.removeDetails(srcVolumeInfo.getId()); } catch (Exception ex) { - LOGGER.warn(ex.getMessage()); + logger.warn(ex.getMessage()); } VolumeVO volumeVO = _volumeDao.findById(srcVolumeInfo.getId()); @@ -875,7 +876,7 @@ private void handleVolumeMigrationForKVM(VolumeInfo srcVolumeInfo, VolumeInfo de try { _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); } catch (Exception e) { - LOGGER.warn(String.format("Failed to revoke access for volume 'name=%s,uuid=%s' after a migration attempt", destVolumeInfo.getVolume(), destVolumeInfo.getUuid()), e); + logger.warn(String.format("Failed to revoke access for volume 'name=%s,uuid=%s' after a migration attempt", destVolumeInfo.getVolume(), destVolumeInfo.getUuid()), e); } } @@ -967,7 +968,7 @@ private VolumeInfo createTemporaryVolumeCopyOfSnapshotAdaptive(SnapshotInfo snap _volumeDao.remove(tempVolumeVO.getId()); } } catch (Throwable e2) { - LOGGER.warn("Failed to delete temporary volume created for copy", e2); + logger.warn("Failed to delete temporary volume created for copy", e2); } throw e; @@ -1015,7 +1016,7 @@ private void handleCopyAsyncToSecondaryStorageAdaptive(SnapshotInfo snapshotInfo copyCmdAnswer = (CopyCmdAnswer)agentManager.send(hostVO.getId(), copyCommand); } catch (Exception ex) { String msg = "Failed to create template from snapshot (Snapshot ID = " + snapshotInfo.getId() + ") : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } finally { @@ -1029,7 +1030,7 @@ private void handleCopyAsyncToSecondaryStorageAdaptive(SnapshotInfo snapshotInfo try { srcFinal.getDataStore().getDriver().deleteAsync(srcFinal.getDataStore(), srcFinal, null); } catch (Throwable e) { - LOGGER.warn("Failed to delete temporary volume created for copy", e); + logger.warn("Failed to delete temporary volume created for copy", e); } } @@ -1116,7 +1117,7 @@ else if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType()) || Hyper String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId(); - LOGGER.warn(noSupportForResignErrMsg); + logger.warn(noSupportForResignErrMsg); throw new CloudRuntimeException(noSupportForResignErrMsg); } @@ -1197,7 +1198,7 @@ else if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType()) || Hyper if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -1218,7 +1219,7 @@ else if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType()) || Hyper if (ep == null) { errMsg = "No remote endpoint to send command, check if host or SSVM is down"; - LOGGER.error(errMsg); + logger.error(errMsg); copyCmdAnswer = new CopyCmdAnswer(errMsg); } else { @@ -1231,7 +1232,7 @@ else if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType()) || Hyper } catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to create template from snapshot (Snapshot ID = " + snapshotInfo.getId() + ") : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } finally { @@ -1266,7 +1267,7 @@ else if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType()) || Hyper } } catch (Exception ex) { - LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex); + logger.warn("Error processing snapshot event: " + ex.getMessage(), ex); } } } @@ -1326,7 +1327,7 @@ private void handleCreateNonManagedVolumeFromManagedSnapshot(SnapshotInfo snapsh String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + volumeStoragePoolVO.getClusterId(); - LOGGER.warn(noSupportForResignErrMsg); + logger.warn(noSupportForResignErrMsg); throw new CloudRuntimeException(noSupportForResignErrMsg); } @@ -1363,7 +1364,7 @@ private void handleCreateNonManagedVolumeFromManagedSnapshot(SnapshotInfo snapsh if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -1383,7 +1384,7 @@ private void handleCreateNonManagedVolumeFromManagedSnapshot(SnapshotInfo snapsh _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotDataStore); } catch (Exception e) { - LOGGER.debug("Failed to revoke access from dest volume", e); + logger.debug("Failed to revoke access from dest volume", e); } if (usingBackendSnapshot) { @@ -1399,7 +1400,7 @@ private void handleCreateNonManagedVolumeFromManagedSnapshot(SnapshotInfo snapsh } } catch (Exception ex) { - LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex); + logger.warn("Error processing snapshot event: " + ex.getMessage(), ex); } if (copyCmdAnswer == null) { @@ -1458,7 +1459,7 @@ private void handleCreateManagedVolumeFromNonManagedSnapshot(SnapshotInfo snapsh VolumeApiResult result = future.get(); if (result.isFailed()) { - LOGGER.error("Failed to create a volume: " + result.getResult()); + logger.error("Failed to create a volume: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } @@ -1553,7 +1554,7 @@ private void handleCreateVolumeFromTemplateBothOnStorageSystem(TemplateInfo temp String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId(); - LOGGER.warn(noSupportForResignErrMsg); + logger.warn(noSupportForResignErrMsg); throw new CloudRuntimeException(noSupportForResignErrMsg); } @@ -1586,7 +1587,7 @@ else if (volumeInfo.getFormat() == ImageFormat.OVA) { } if (result.isFailed()) { - LOGGER.warn("Failed to create a volume: " + result.getResult()); + logger.warn("Failed to create a volume: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } @@ -1630,7 +1631,7 @@ else if (volumeInfo.getFormat() == ImageFormat.OVA) { volumeInfo.getDataStore().getDriver().deleteAsync(volumeInfo.getDataStore(), volumeInfo, null); } catch (Exception exc) { - LOGGER.warn("Failed to delete volume", exc); + logger.warn("Failed to delete volume", exc); } if (templateInfo != null) { @@ -1677,7 +1678,7 @@ private void handleCreateManagedVolumeFromManagedSnapshot(SnapshotInfo snapshotI String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId(); - LOGGER.warn(noSupportForResignErrMsg); + logger.warn(noSupportForResignErrMsg); throw new CloudRuntimeException(noSupportForResignErrMsg); } @@ -1713,7 +1714,7 @@ private void handleCreateManagedVolumeFromManagedSnapshot(SnapshotInfo snapshotI } if (result.isFailed()) { - LOGGER.warn("Failed to create a volume: " + result.getResult()); + logger.warn("Failed to create a volume: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } @@ -1856,7 +1857,7 @@ private CopyCmdAnswer copyImageToVolume(DataObject srcDataObject, VolumeInfo des catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to copy image : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } @@ -1899,7 +1900,7 @@ private void createVolumeFromSnapshot(SnapshotInfo snapshotInfo) { */ private void deleteVolumeFromSnapshot(SnapshotInfo snapshotInfo) { try { - LOGGER.debug("Cleaning up temporary volume created for copy from a snapshot"); + logger.debug("Cleaning up temporary volume created for copy from a snapshot"); SnapshotDetailsVO snapshotDetails = handleSnapshotDetails(snapshotInfo.getId(), "delete"); @@ -1911,7 +1912,7 @@ private void deleteVolumeFromSnapshot(SnapshotInfo snapshotInfo) { } } catch (Throwable e) { - LOGGER.warn("Failed to clean up temporary volume created for copy from a snapshot, transction will not be failed but an adminstrator should clean this up: " + snapshotInfo.getUuid() + " - " + snapshotInfo.getPath(), e); + logger.warn("Failed to clean up temporary volume created for copy from a snapshot, transction will not be failed but an adminstrator should clean this up: " + snapshotInfo.getUuid() + " - " + snapshotInfo.getPath(), e); } } @@ -1920,7 +1921,7 @@ private void handleQualityOfServiceForVolumeMigration(VolumeInfo volumeInfo, Pri ((PrimaryDataStoreDriver)volumeInfo.getDataStore().getDriver()).handleQualityOfServiceForVolumeMigration(volumeInfo, qualityOfServiceState); } catch (Exception ex) { - LOGGER.warn(ex); + logger.warn(ex); } } @@ -2027,10 +2028,10 @@ public void copyAsync(Map volumeDataStoreMap, VirtualMach if (srcVolumeInfo.getTemplateId() != null && Objects.nonNull(vmTemplate) && !Arrays.asList(KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME, VM_IMPORT_DEFAULT_TEMPLATE_NAME).contains(vmTemplate.getName())) { - LOGGER.debug(String.format("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s].", srcVolumeInfo.getTemplateId(), srcVolumeInfo.getId(), sourceStoragePool.getId(), destStoragePool.getId())); + logger.debug(String.format("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s].", srcVolumeInfo.getTemplateId(), srcVolumeInfo.getId(), sourceStoragePool.getId(), destStoragePool.getId())); copyTemplateToTargetFilesystemStorageIfNeeded(srcVolumeInfo, sourceStoragePool, destDataStore, destStoragePool, destHost); } else { - LOGGER.debug(String.format("Skipping copy template from source storage pool [%s] to target storage pool [%s] before migration due to volume [%s] does not have a template.", sourceStoragePool.getId(), destStoragePool.getId(), srcVolumeInfo.getId())); + logger.debug(String.format("Skipping copy template from source storage pool [%s] to target storage pool [%s] before migration due to volume [%s] does not have a template.", sourceStoragePool.getId(), destStoragePool.getId(), srcVolumeInfo.getId())); } VolumeVO destVolume = duplicateVolumeOnAnotherStorage(srcVolume, destStoragePool); @@ -2120,7 +2121,7 @@ public void copyAsync(Map volumeDataStoreMap, VirtualMach Integer newVmCpuShares = ((PrepareForMigrationAnswer) pfma).getNewVmCpuShares(); if (newVmCpuShares != null) { - LOGGER.debug(String.format("Setting CPU shares to [%d] as part of migrate VM with volumes command for VM [%s].", newVmCpuShares, vmTO)); + logger.debug(String.format("Setting CPU shares to [%d] as part of migrate VM with volumes command for VM [%s].", newVmCpuShares, vmTO)); migrateCommand.setNewVmCpuShares(newVmCpuShares); } @@ -2146,7 +2147,7 @@ public void copyAsync(Map volumeDataStoreMap, VirtualMach String volumesAndStorages = volumeDataStoreMap.entrySet().stream().map(entry -> formatEntryOfVolumesAndStoragesAsJsonToDisplayOnLog(entry)).collect(Collectors.joining(",")); errMsg = String.format("Copy volume(s) to storage(s) [%s] and VM to host [%s] failed in StorageSystemDataMotionStrategy.copyAsync. Error message: [%s].", volumesAndStorages, formatMigrationElementsAsJsonToDisplayOnLog("vm", vmTO.getId(), srcHost.getId(), destHost.getId()), ex.getMessage()); - LOGGER.error(errMsg, ex); + logger.error(errMsg, ex); throw new CloudRuntimeException(errMsg); } finally { @@ -2270,7 +2271,7 @@ private void handlePostMigration(boolean success, Map sr } } catch (Exception e) { - LOGGER.debug("Failed to disconnect one or more (original) dest volumes", e); + logger.debug("Failed to disconnect one or more (original) dest volumes", e); } } @@ -2299,14 +2300,14 @@ private void handlePostMigration(boolean success, Map sr disconnectHostFromVolume(destHost, destVolumeInfo.getPoolId(), destVolumeInfo.get_iScsiName()); } catch (Exception e) { - LOGGER.debug("Failed to disconnect (new) dest volume", e); + logger.debug("Failed to disconnect (new) dest volume", e); } try { _volumeService.revokeAccess(destVolumeInfo, destHost, destVolumeInfo.getDataStore()); } catch (Exception e) { - LOGGER.debug("Failed to revoke access from dest volume", e); + logger.debug("Failed to revoke access from dest volume", e); } destVolumeInfo.processEvent(Event.OperationFailed); @@ -2320,10 +2321,10 @@ private void handlePostMigration(boolean success, Map sr AsyncCallFuture destroyFuture = _volumeService.expungeVolumeAsync(destVolumeInfo); if (destroyFuture.get().isFailed()) { - LOGGER.debug("Failed to clean up dest volume on storage"); + logger.debug("Failed to clean up dest volume on storage"); } } catch (Exception e) { - LOGGER.debug("Failed to clean up dest volume on storage", e); + logger.debug("Failed to clean up dest volume on storage", e); } } } @@ -2436,7 +2437,7 @@ protected void postVolumeCreationActions(VolumeInfo srcVolumeInfo, VolumeInfo de */ protected void prepareDiskWithSecretConsumerDetail(VirtualMachineTO vmTO, VolumeInfo srcVolume, String destPath) { if (vmTO.getDisks() != null) { - LOGGER.debug(String.format("Preparing VM TO '%s' disks with migration data", vmTO)); + logger.debug(String.format("Preparing VM TO '%s' disks with migration data", vmTO)); Arrays.stream(vmTO.getDisks()).filter(diskTO -> diskTO.getData().getId() == srcVolume.getId()).forEach( diskTO -> { if (diskTO.getDetails() == null) { diskTO.setDetails(new HashMap<>()); @@ -2566,7 +2567,7 @@ private void handleCreateTemplateFromManagedVolume(VolumeInfo volumeInfo, Templa if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -2580,7 +2581,7 @@ private void handleCreateTemplateFromManagedVolume(VolumeInfo volumeInfo, Templa catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to create template from volume (Volume ID = " + volumeInfo.getId() + ") : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } @@ -2590,7 +2591,7 @@ private void handleCreateTemplateFromManagedVolume(VolumeInfo volumeInfo, Templa _volumeService.revokeAccess(volumeInfo, hostVO, srcDataStore); } catch (Exception ex) { - LOGGER.warn("Error revoking access to volume (Volume ID = " + volumeInfo.getId() + "): " + ex.getMessage(), ex); + logger.warn("Error revoking access to volume (Volume ID = " + volumeInfo.getId() + "): " + ex.getMessage(), ex); } } @@ -2614,7 +2615,7 @@ private void handleCreateTemplateFromManagedVolume(VolumeInfo volumeInfo, Templa } } catch (Exception ex) { - LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex); + logger.warn("Error processing snapshot event: " + ex.getMessage(), ex); } } } @@ -2824,7 +2825,7 @@ private CopyCmdAnswer performResignature(DataObject dataObj, HostVO hostVO, Map< if (!lock.lock(LOCK_TIME_IN_SECONDS)) { String errMsg = "Couldn't lock the DB (in performResignature) on the following string: " + dataStore.getUuid(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -2839,7 +2840,7 @@ private CopyCmdAnswer performResignature(DataObject dataObj, HostVO hostVO, Map< String msg = "Failed to resign the DataObject with the following ID: " + dataObj.getId(); - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage()); } @@ -2925,9 +2926,9 @@ private String migrateVolumeForKVM(VolumeInfo srcVolumeInfo, VolumeInfo destVolu _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION); } catch (Throwable e) { - LOGGER.warn("During cleanup post-migration and exception occured: " + e); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exception during post-migration cleanup.", e); + logger.warn("During cleanup post-migration and exception occured: " + e); + if (logger.isDebugEnabled()) { + logger.debug("Exception during post-migration cleanup.", e); } } } @@ -2968,7 +2969,7 @@ private String copyManagedVolumeToSecondaryStorage(VolumeInfo srcVolumeInfo, Vol catch (Exception ex) { String msg = "Failed to perform volume copy to secondary storage : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage()); } @@ -3046,7 +3047,7 @@ private CopyCmdAnswer performCopyOfVdi(VolumeInfo volumeInfo, SnapshotInfo snaps catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to perform VDI copy : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } diff --git a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategyTest.java b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategyTest.java index 56e0948e5931..67e3ea844d58 100755 --- a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategyTest.java +++ b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategyTest.java @@ -21,7 +21,6 @@ import static org.mockito.Mockito.when; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.never; @@ -55,8 +54,6 @@ public class AncientDataMotionStrategyTest { @Mock PrimaryDataStoreTO dataStoreTO; @Mock - ConfigKey vmwareKey; - @Mock StorageManager storageManager; @Mock StoragePool storagePool; @@ -66,9 +63,7 @@ public class AncientDataMotionStrategyTest { @Before public void setup() throws Exception { - replaceVmwareCreateCloneFullField(); - - when(vmwareKey.valueIn(POOL_ID)).thenReturn(FULL_CLONE_FLAG); + overrideDefaultConfigValue(StorageManager.VmwareCreateCloneFull, String.valueOf(FULL_CLONE_FLAG)); when(dataTO.getHypervisorType()).thenReturn(HypervisorType.VMware); when(dataTO.getDataStore()).thenReturn(dataStoreTO); @@ -76,14 +71,10 @@ public void setup() throws Exception { when(storageManager.getStoragePool(POOL_ID)).thenReturn(storagePool); } - private void replaceVmwareCreateCloneFullField() throws Exception { - Field field = StorageManager.class.getDeclaredField("VmwareCreateCloneFull"); - field.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, vmwareKey); + private void overrideDefaultConfigValue(final ConfigKey configKey, final String value) throws IllegalAccessException, NoSuchFieldException { + final Field f = ConfigKey.class.getDeclaredField("_defaultValue"); + f.setAccessible(true); + f.set(configKey, value); } @Test diff --git a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java index c8a77a422526..b7468195f5da 100644 --- a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java +++ b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java @@ -51,7 +51,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; diff --git a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java index e619b40fae07..45357fa64b2a 100644 --- a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java +++ b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java @@ -46,7 +46,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.api.MigrateCommand; import com.cloud.host.HostVO; diff --git a/engine/storage/image/pom.xml b/engine/storage/image/pom.xml index 6658df278bec..278b3672b2fd 100644 --- a/engine/storage/image/pom.xml +++ b/engine/storage/image/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java index 3557921a8936..730b003fcb06 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java @@ -44,7 +44,8 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.secstorage.CommandExecLogDao; @@ -53,7 +54,7 @@ public class SecondaryStorageServiceImpl implements SecondaryStorageService { - private static final Logger s_logger = Logger.getLogger(SecondaryStorageServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject DataMotionService motionSrv; @@ -126,11 +127,11 @@ public AsyncCallFuture migrateData(DataObject srcDataObject, D else { // Check if template in destination store, if yes, do not proceed if (srcDataObject instanceof TemplateInfo) { - s_logger.debug("Checking if template present at destination"); + logger.debug("Checking if template present at destination"); TemplateDataStoreVO templateStoreVO = templateStoreDao.findByStoreTemplate(destDatastore.getId(), srcDataObject.getId()); if (templateStoreVO != null) { String msg = "Template already exists in destination store"; - s_logger.debug(msg); + logger.debug(msg); res.setResult(msg); res.setSuccess(true); future.complete(res); @@ -143,9 +144,9 @@ public AsyncCallFuture migrateData(DataObject srcDataObject, D migrateJob(future, srcDataObject, destDataObject, destDatastore); } } catch (Exception e) { - s_logger.debug("Failed to copy Data", e); + logger.debug("Failed to copy Data", e); if (destDataObject != null) { - s_logger.info("Deleting data on destination store: " + destDataObject.getDataStore().getName()); + logger.info("Deleting data on destination store: " + destDataObject.getDataStore().getName()); destDataObject.getDataStore().delete(destDataObject); } if (!(srcDataObject instanceof VolumeInfo)) { @@ -178,7 +179,7 @@ protected Void migrateDataCallBack(AsyncCallbackDispatcher context = new TemplateOpContext<>(null,(TemplateObject)tmpl, null); @@ -554,7 +555,7 @@ public void handleTemplateSync(DataStore store) { caller.setContext(context); createTemplateAsync(tmpl, store, caller); } else { - s_logger.info("Skip downloading template " + tmplt.getUniqueName() + " since current data center does not have hypervisor " + + logger.info("Skip downloading template " + tmplt.getUniqueName() + " since current data center does not have hypervisor " + tmplt.getHypervisorType().toString()); } } @@ -573,17 +574,17 @@ public void handleTemplateSync(DataStore store) { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(dtCommand, false, errMsg); } else { answer = ep.sendMessage(dtCommand); } if (answer == null || !answer.getResult()) { - s_logger.info("Failed to deleted template at store: " + store.getName()); + logger.info("Failed to deleted template at store: " + store.getName()); } else { String description = "Deleted template " + tInfo.getTemplateName() + " on secondary storage " + storeId; - s_logger.info(description); + logger.info(description); } } @@ -592,7 +593,7 @@ public void handleTemplateSync(DataStore store) { syncLock.unlock(); } } else { - s_logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing template sync on data store " + storeId + " now."); + logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing template sync on data store " + storeId + " now."); } } finally { syncLock.releaseRef(); @@ -667,7 +668,7 @@ protected Void createTemplateAsyncCallBack(AsyncCallbackDispatcher listTemplate(DataStore ssStore) { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -700,8 +701,8 @@ private Map listTemplate(DataStore ssStore) { ListTemplateAnswer tanswer = (ListTemplateAnswer)answer; return tanswer.getTemplateInfo(); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("can not list template for secondary storage host " + ssStore.getId()); + if (logger.isDebugEnabled()) { + logger.debug("can not list template for secondary storage host " + ssStore.getId()); } } @@ -813,7 +814,7 @@ private boolean createChildDataDiskTemplate(DatadiskTO dataDiskTemplate, VMTempl String templateName = dataDiskTemplate.isIso() ? dataDiskTemplate.getPath().substring(dataDiskTemplate.getPath().lastIndexOf(File.separator) + 1) : template.getName() + suffix + diskCount; VMTemplateVO templateVO = new VMTemplateVO(templateId, templateName, format, false, false, false, ttype, template.getUrl(), template.requiresHvm(), template.getBits(), template.getAccountId(), null, templateName, false, guestOsId, false, template.getHypervisorType(), null, - null, false, false, false, false); + null, false, false, false, false, template.getArch()); if (dataDiskTemplate.isIso()){ templateVO.setUniqueName(templateName); } @@ -838,7 +839,7 @@ private boolean createChildDataDiskTemplate(DatadiskTO dataDiskTemplate, VMTempl _resourceLimitMgr.incrementResourceCount(template.getAccountId(), ResourceType.secondary_storage, templateVO.getSize()); } else { // Delete the Datadisk templates that were already created as they are now invalid - s_logger.debug("Since creation of Datadisk template: " + templateVO.getId() + " failed, delete other Datadisk templates that were created as part of parent" + logger.debug("Since creation of Datadisk template: " + templateVO.getId() + " failed, delete other Datadisk templates that were created as part of parent" + " template download"); TemplateInfo parentTemplateInfo = imageFactory.getTemplate(templateVO.getParentTemplateId(), imageStore); cleanupDatadiskTemplates(parentTemplateInfo); @@ -853,7 +854,7 @@ private boolean finalizeParentTemplate(DatadiskTO dataDiskTemplate, VMTemplateVO TemplateApiResult result = null; result = templateFuture.get(); if (!result.isSuccess()) { - s_logger.debug("Since creation of parent template: " + templateInfo.getId() + " failed, delete Datadisk templates that were created as part of parent" + logger.debug("Since creation of parent template: " + templateInfo.getId() + " failed, delete Datadisk templates that were created as part of parent" + " template download"); cleanupDatadiskTemplates(templateInfo); } @@ -903,18 +904,18 @@ private void cleanupDatadiskTemplates(TemplateInfo parentTemplateInfo) { DataStore imageStore = parentTemplateInfo.getDataStore(); List datadiskTemplatesToDelete = _templateDao.listByParentTemplatetId(parentTemplateInfo.getId()); for (VMTemplateVO datadiskTemplateToDelete: datadiskTemplatesToDelete) { - s_logger.info("Delete template: " + datadiskTemplateToDelete.getId() + " from image store: " + imageStore.getName()); + logger.info("Delete template: " + datadiskTemplateToDelete.getId() + " from image store: " + imageStore.getName()); AsyncCallFuture future = deleteTemplateAsync(imageFactory.getTemplate(datadiskTemplateToDelete.getId(), imageStore)); try { TemplateApiResult result = future.get(); if (!result.isSuccess()) { - s_logger.warn("Failed to delete datadisk template: " + datadiskTemplateToDelete + " from image store: " + imageStore.getName() + " due to: " + result.getResult()); + logger.warn("Failed to delete datadisk template: " + datadiskTemplateToDelete + " from image store: " + imageStore.getName() + " due to: " + result.getResult()); break; } _vmTemplateZoneDao.deletePrimaryRecordsForTemplate(datadiskTemplateToDelete.getId()); _resourceLimitMgr.decrementResourceCount(datadiskTemplateToDelete.getAccountId(), ResourceType.secondary_storage, datadiskTemplateToDelete.getSize()); } catch (Exception e) { - s_logger.debug("Delete datadisk template failed", e); + logger.debug("Delete datadisk template failed", e); throw new CloudRuntimeException("Delete template Failed", e); } } @@ -1010,7 +1011,7 @@ protected Void syncTemplateCallBack(AsyncCallbackDispatcher copyTemplate(TemplateInfo srcTemplate, // generate a URL from source template ssvm to download to destination data store String url = generateCopyUrl(srcTemplate); if (url == null) { - s_logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + + logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + ", no secondary storage vm in running state in source zone"); throw new CloudRuntimeException("No secondary VM in running state in source template zone "); } TemplateObject tmplForCopy = (TemplateObject)_templateFactory.getTemplate(srcTemplate, destStore, null); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Setting source template url to " + url); + if (logger.isDebugEnabled()) { + logger.debug("Setting source template url to " + url); } tmplForCopy.setUrl(url); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Mark template_store_ref entry as Creating"); + if (logger.isDebugEnabled()) { + logger.debug("Mark template_store_ref entry as Creating"); } AsyncCallFuture future = new AsyncCallFuture(); DataObject templateOnStore = destStore.create(tmplForCopy); @@ -1087,8 +1088,8 @@ public AsyncCallFuture copyTemplate(TemplateInfo srcTemplate, ((TemplateObject)templateOnStore).getImage().setChecksum(null); } // else we don't know what to do. - if (s_logger.isDebugEnabled()) { - s_logger.debug("Invoke datastore driver createAsync to create template on destination store"); + if (logger.isDebugEnabled()) { + logger.debug("Invoke datastore driver createAsync to create template on destination store"); } try { TemplateOpContext context = new TemplateOpContext(null, (TemplateObject)templateOnStore, future); @@ -1119,7 +1120,7 @@ private String generateCopyUrl(String ipAddress, String dir, String path) { _sslCopy = Boolean.parseBoolean(sslCfg); } if(_sslCopy && (_ssvmUrlDomain == null || _ssvmUrlDomain.isEmpty())){ - s_logger.warn("Empty secondary storage url domain, ignoring SSL"); + logger.warn("Empty secondary storage url domain, ignoring SSL"); _sslCopy = false; } if (_sslCopy) { @@ -1139,7 +1140,7 @@ private String generateCopyUrl(TemplateInfo srcTemplate) { EndPoint ep = _epSelector.select(srcTemplate); if (ep != null) { if (ep.getPublicAddr() == null) { - s_logger.warn("A running secondary storage vm has a null public ip?"); + logger.warn("A running secondary storage vm has a null public ip?"); return null; } return generateCopyUrl(ep.getPublicAddr(), ((ImageStoreEntity)srcStore).getMountPoint(), srcTemplate.getInstallPath()); @@ -1192,7 +1193,7 @@ protected Void copyTemplateCallBack(AsyncCallbackDispatcher callback, TemplateOpContext context) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Performing copy template cross zone callback after completion"); + if (logger.isDebugEnabled()) { + logger.debug("Performing copy template cross zone callback after completion"); } TemplateInfo destTemplate = context.getTemplate(); CreateCmdResult result = callback.getResult(); @@ -1217,7 +1218,7 @@ protected Void copyTemplateCrossZoneCallBack(AsyncCallbackDispatcher listImageStoreByProvider(String provider) { @Override public List listImageCacheStores(Scope scope) { if (scope.getScopeType() != ScopeType.ZONE) { - s_logger.debug("only support zone wide image cache stores"); + logger.debug("only support zone wide image cache stores"); return null; } List stores = dataStoreDao.findImageCacheByScope(new ZoneScope(scope.getScopeId())); @@ -200,7 +201,7 @@ public int compare(DataStore store1, DataStore store2) { } // No store with space found - s_logger.error(String.format("Can't find an image storage in zone with less than %d usage", + logger.error(String.format("Can't find an image storage in zone with less than %d usage", Math.round(_statsCollector.getImageStoreCapacityThreshold() * 100))); return null; } @@ -242,7 +243,7 @@ public List listImageStoresWithFreeCapacity(List imageStor // No store with space found if (stores.isEmpty()) { - s_logger.error(String.format("Can't find image storage in zone with less than %d usage", + logger.error(String.format("Can't find image storage in zone with less than %d usage", Math.round(_statsCollector.getImageStoreCapacityThreshold() * 100))); } return stores; diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java index d4e2c056763e..d59f6d4c54dd 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java @@ -26,7 +26,8 @@ import javax.inject.Inject; import com.cloud.storage.Upload; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; @@ -54,7 +55,7 @@ import com.cloud.utils.component.ComponentContext; public class ImageStoreImpl implements ImageStoreEntity { - private static final Logger s_logger = Logger.getLogger(ImageStoreImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject VMTemplateDao imageDao; @Inject @@ -153,10 +154,10 @@ public boolean delete(DataObject obj) { try { future.get(); } catch (InterruptedException e) { - s_logger.debug("failed delete obj", e); + logger.debug("failed delete obj", e); return false; } catch (ExecutionException e) { - s_logger.debug("failed delete obj", e); + logger.debug("failed delete obj", e); return false; } objectInStoreMgr.delete(obj); diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java index 899f1d83e0b4..b7d83c702231 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java @@ -23,9 +23,11 @@ import javax.inject.Inject; +import com.cloud.cpu.CPU; import com.cloud.storage.StorageManager; import com.cloud.user.UserData; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -60,7 +62,7 @@ @SuppressWarnings("serial") public class TemplateObject implements TemplateInfo { - private static final Logger s_logger = Logger.getLogger(TemplateObject.class); + protected Logger logger = LogManager.getLogger(getClass()); private VMTemplateVO imageVO; private DataStore dataStore; private String url; @@ -83,7 +85,7 @@ public TemplateObject() { protected void configure(VMTemplateVO template, DataStore dataStore) { if (template == null) { String msg = String.format("Template Object is not properly initialised %s", this.toString()); - s_logger.warn(msg); + logger.warn(msg); } imageVO = template; this.dataStore = dataStore; @@ -103,7 +105,7 @@ public void setSize(Long size) { public VMTemplateVO getImage() { if (imageVO == null) { String msg = String.format("Template Object is not properly initialised %s", this.toString()); - s_logger.error(msg); + logger.error(msg); } // somehow the nullpointer is needed : refacter needed!?! return imageVO; } @@ -254,10 +256,10 @@ public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answe } objectInStoreMgr.update(this, event); } catch (NoTransitionException e) { - s_logger.debug("failed to update state", e); + logger.debug("failed to update state", e); throw new CloudRuntimeException("Failed to update state" + e.toString()); } catch (Exception ex) { - s_logger.debug("failed to process event and answer", ex); + logger.debug("failed to process event and answer", ex); objectInStoreMgr.delete(this); throw new CloudRuntimeException("Failed to process event", ex); } finally { @@ -349,6 +351,11 @@ public UserData.UserDataOverridePolicy getUserDataOverridePolicy() { return imageVO.getUserDataOverridePolicy(); } + @Override + public CPU.CPUArch getArch() { + return imageVO.getArch(); + } + @Override public DataTO getTO() { DataTO to = null; @@ -409,7 +416,7 @@ public boolean canBeDeletedFromDataStore() { // Marking downloaded templates for deletion, but might skip any deletion handled for failed templates. // Only templates not downloaded and in error state (with no install path) cannot be deleted from the datastore, so doesn't impact last behavior for templates with other states if (downloadStatus == null || downloadStatus == Status.NOT_DOWNLOADED || (downloadStatus == Status.DOWNLOAD_ERROR && downloadPercent == 0)) { - s_logger.debug("Template: " + getId() + " cannot be deleted from the store: " + getDataStore().getId()); + logger.debug("Template: " + getId() + " cannot be deleted from the store: " + getDataStore().getId()); return false; } diff --git a/engine/storage/integration-test/pom.xml b/engine/storage/integration-test/pom.xml index d46e8e596074..a5bc225f4f63 100644 --- a/engine/storage/integration-test/pom.xml +++ b/engine/storage/integration-test/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java index c6003afee578..1d072985a667 100644 --- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java +++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java @@ -26,7 +26,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -60,7 +59,6 @@ import com.cloud.utils.fsm.StateMachine2; public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentManager { - private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class); private final Map hostResourcesMap = new HashMap(); @Inject HostDao hostDao; diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/MockRpcCallBack.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/MockRpcCallBack.java index 25f96c267509..8b3de65b4cca 100644 --- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/MockRpcCallBack.java +++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/MockRpcCallBack.java @@ -18,7 +18,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; @@ -28,7 +29,7 @@ import com.cloud.utils.db.DB; public class MockRpcCallBack implements Runnable { - private static final Logger s_logger = Logger.getLogger(MockRpcCallBack.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AgentManager agentMgr; private Command cmd; @@ -54,7 +55,7 @@ public void run() { Answer answer = agentMgr.send(hostId, cmd); callback.complete(answer); } catch (Throwable e) { - s_logger.debug("send command failed:", e); + logger.debug("send command failed:", e); } } diff --git a/engine/storage/integration-test/src/test/resources/component.xml b/engine/storage/integration-test/src/test/resources/component.xml index d384d5466659..608326d12794 100644 --- a/engine/storage/integration-test/src/test/resources/component.xml +++ b/engine/storage/integration-test/src/test/resources/component.xml @@ -17,13 +17,13 @@ under the License. --> - + - + @@ -47,15 +47,15 @@ - - + + - + @@ -74,7 +74,7 @@ - + @@ -89,7 +89,7 @@ - + @@ -138,8 +138,8 @@ - - + + @@ -179,11 +179,11 @@ - + - + diff --git a/engine/storage/integration-test/src/test/resources/s3_testng.xml b/engine/storage/integration-test/src/test/resources/s3_testng.xml index c46e5a2db049..8beb598ee008 100644 --- a/engine/storage/integration-test/src/test/resources/s3_testng.xml +++ b/engine/storage/integration-test/src/test/resources/s3_testng.xml @@ -28,17 +28,17 @@ - + - + - + diff --git a/engine/storage/integration-test/src/test/resources/storageContext.xml b/engine/storage/integration-test/src/test/resources/storageContext.xml index 7c95345f6734..f38e718ea413 100644 --- a/engine/storage/integration-test/src/test/resources/storageContext.xml +++ b/engine/storage/integration-test/src/test/resources/storageContext.xml @@ -1,27 +1,27 @@ - - + @@ -36,10 +36,10 @@ - - - - + + + + @@ -56,7 +56,7 @@ - + diff --git a/engine/storage/integration-test/src/test/resources/testng.xml b/engine/storage/integration-test/src/test/resources/testng.xml index fb4330999f35..34ef6defcd93 100644 --- a/engine/storage/integration-test/src/test/resources/testng.xml +++ b/engine/storage/integration-test/src/test/resources/testng.xml @@ -27,10 +27,10 @@ - + - + @@ -40,11 +40,11 @@ - + - + diff --git a/engine/storage/object/pom.xml b/engine/storage/object/pom.xml index 6dd0ea65ebcd..7159a646fbb8 100644 --- a/engine/storage/object/pom.xml +++ b/engine/storage/object/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/ObjectStorageServiceImpl.java b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/ObjectStorageServiceImpl.java index a0db89bad4e1..40edc66d4d0e 100644 --- a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/ObjectStorageServiceImpl.java +++ b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/ObjectStorageServiceImpl.java @@ -18,11 +18,8 @@ package org.apache.cloudstack.storage.object; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectStorageService; -import org.apache.log4j.Logger; public class ObjectStorageServiceImpl implements ObjectStorageService { - private static final Logger s_logger = Logger.getLogger(ObjectStorageServiceImpl.class); - } diff --git a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/manager/ObjectStoreProviderManagerImpl.java b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/manager/ObjectStoreProviderManagerImpl.java index 40f503692e18..222b21e0ce84 100644 --- a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/manager/ObjectStoreProviderManagerImpl.java +++ b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/manager/ObjectStoreProviderManagerImpl.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.storage.object.ObjectStoreEntity; import org.apache.cloudstack.storage.object.datastore.ObjectStoreProviderManager; import org.apache.cloudstack.storage.object.store.ObjectStoreImpl; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -41,7 +40,6 @@ @Component public class ObjectStoreProviderManagerImpl implements ObjectStoreProviderManager, Configurable { - private static final Logger s_logger = Logger.getLogger(ObjectStoreProviderManagerImpl.class); @Inject ObjectStoreDao objectStoreDao; diff --git a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java index 825b349bdfce..f1c27526f529 100644 --- a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java +++ b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java @@ -18,6 +18,7 @@ */ package org.apache.cloudstack.storage.object.store; +import com.cloud.agent.api.to.BucketTO; import com.cloud.agent.api.to.DataStoreTO; import org.apache.cloudstack.storage.object.Bucket; import com.cloud.storage.DataStoreRole; @@ -29,14 +30,12 @@ import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; import org.apache.cloudstack.storage.object.ObjectStoreDriver; import org.apache.cloudstack.storage.object.ObjectStoreEntity; -import org.apache.log4j.Logger; import java.util.Date; import java.util.List; import java.util.Map; public class ObjectStoreImpl implements ObjectStoreEntity { - private static final Logger s_logger = Logger.getLogger(ObjectStoreImpl.class); protected ObjectStoreDriver driver; protected ObjectStoreVO objectStoreVO; @@ -109,38 +108,38 @@ public Bucket createBucket(Bucket bucket, boolean objectLock) { } @Override - public boolean deleteBucket(String bucketName) { - return driver.deleteBucket(bucketName, objectStoreVO.getId()); + public boolean deleteBucket(BucketTO bucket) { + return driver.deleteBucket(bucket, objectStoreVO.getId()); } @Override - public boolean setBucketEncryption(String bucketName) { - return driver.setBucketEncryption(bucketName, objectStoreVO.getId()); + public boolean setBucketEncryption(BucketTO bucket) { + return driver.setBucketEncryption(bucket, objectStoreVO.getId()); } @Override - public boolean deleteBucketEncryption(String bucketName) { - return driver.deleteBucketEncryption(bucketName, objectStoreVO.getId()); + public boolean deleteBucketEncryption(BucketTO bucket) { + return driver.deleteBucketEncryption(bucket, objectStoreVO.getId()); } @Override - public boolean setBucketVersioning(String bucketName) { - return driver.setBucketVersioning(bucketName, objectStoreVO.getId()); + public boolean setBucketVersioning(BucketTO bucket) { + return driver.setBucketVersioning(bucket, objectStoreVO.getId()); } @Override - public boolean deleteBucketVersioning(String bucketName) { - return driver.deleteBucketVersioning(bucketName, objectStoreVO.getId()); + public boolean deleteBucketVersioning(BucketTO bucket) { + return driver.deleteBucketVersioning(bucket, objectStoreVO.getId()); } @Override - public void setBucketPolicy(String bucketName, String policy) { - driver.setBucketPolicy(bucketName, policy, objectStoreVO.getId()); + public void setBucketPolicy(BucketTO bucket, String policy) { + driver.setBucketPolicy(bucket, policy, objectStoreVO.getId()); } @Override - public void setQuota(String bucketName, int quota) { - driver.setBucketQuota(bucketName, objectStoreVO.getId(), quota); + public void setQuota(BucketTO bucket, int quota) { + driver.setBucketQuota(bucket, objectStoreVO.getId(), quota); } @Override diff --git a/engine/storage/object/src/test/resource/testContext.xml b/engine/storage/object/src/test/resource/testContext.xml index 7352b1148f78..c168582bab80 100644 --- a/engine/storage/object/src/test/resource/testContext.xml +++ b/engine/storage/object/src/test/resource/testContext.xml @@ -22,7 +22,7 @@ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd @@ -38,7 +38,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -58,7 +58,7 @@ - + @@ -68,12 +68,12 @@ - + - + diff --git a/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/pom.xml b/engine/storage/pom.xml index ca6e219d1e29..e16e88e235d1 100644 --- a/engine/storage/pom.xml +++ b/engine/storage/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/engine/storage/snapshot/pom.xml b/engine/storage/snapshot/pom.xml index 138db9cf99a5..f29b43d8de0b 100644 --- a/engine/storage/snapshot/pom.xml +++ b/engine/storage/snapshot/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -56,6 +56,11 @@ ${project.version} compile
+ + mysql + mysql-connector-java + test +
diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategy.java index 19b3fc87f4e3..04cca2e8f923 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategy.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import com.cloud.storage.DataStoreRole; import com.cloud.storage.Snapshot; @@ -44,7 +43,6 @@ public class CephSnapshotStrategy extends StorageSystemSnapshotStrategy { @Inject private VolumeDao volumeDao; - private static final Logger s_logger = Logger.getLogger(CephSnapshotStrategy.class); @Override public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperation op) { @@ -71,7 +69,7 @@ public boolean revertSnapshot(SnapshotInfo snapshotInfo) { VolumeInfo volumeInfo = snapshotInfo.getBaseVolume(); ImageFormat imageFormat = volumeInfo.getFormat(); if (!ImageFormat.RAW.equals(imageFormat)) { - s_logger.error(String.format("Does not support revert snapshot of the image format [%s] on Ceph/RBD. Can only rollback snapshots of format RAW", imageFormat)); + logger.error(String.format("Does not support revert snapshot of the image format [%s] on Ceph/RBD. Can only rollback snapshots of format RAW", imageFormat)); return false; } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java index 333272113bd2..afc8be1e5f97 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java @@ -44,7 +44,6 @@ import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.to.DataTO; import com.cloud.event.EventTypes; @@ -79,7 +78,6 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { - private static final Logger s_logger = Logger.getLogger(DefaultSnapshotStrategy.class); @Inject SnapshotService snapshotSvr; @@ -138,12 +136,12 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) { try { snapObj.processEvent(Snapshot.Event.OperationNotPerformed); } catch (NoTransitionException e) { - s_logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString()); + logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString()); throw new CloudRuntimeException(e.toString()); } return snapshotDataFactory.getSnapshot(snapObj.getId(), store); } else { - s_logger.debug("parent snapshot hasn't been backed up yet"); + logger.debug("parent snapshot hasn't been backed up yet"); } } @@ -197,7 +195,7 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) { protected boolean deleteSnapshotChain(SnapshotInfo snapshot, String storageToString) { DataTO snapshotTo = snapshot.getTO(); - s_logger.debug(String.format("Deleting %s chain of snapshots.", snapshotTo)); + logger.debug(String.format("Deleting %s chain of snapshots.", snapshotTo)); boolean result = false; boolean resultIsSet = false; @@ -206,11 +204,11 @@ protected boolean deleteSnapshotChain(SnapshotInfo snapshot, String storageToStr SnapshotInfo child = snapshot.getChild(); if (child != null) { - s_logger.debug(String.format("Snapshot [%s] has child [%s], not deleting it on the storage [%s]", snapshotTo, child.getTO(), storageToString)); + logger.debug(String.format("Snapshot [%s] has child [%s], not deleting it on the storage [%s]", snapshotTo, child.getTO(), storageToString)); break; } - s_logger.debug(String.format("Snapshot [%s] does not have children; therefore, we will delete it and its parents.", snapshotTo)); + logger.debug(String.format("Snapshot [%s] does not have children; therefore, we will delete it and its parents.", snapshotTo)); SnapshotInfo parent = snapshot.getParent(); boolean deleted = false; @@ -218,7 +216,7 @@ protected boolean deleteSnapshotChain(SnapshotInfo snapshot, String storageToStr if (parent.getPath() != null && parent.getPath().equalsIgnoreCase(snapshot.getPath())) { //NOTE: if both snapshots share the same path, it's for xenserver's empty delta snapshot. We can't delete the snapshot on the backend, as parent snapshot still reference to it //Instead, mark it as destroyed in the db. - s_logger.debug(String.format("Snapshot [%s] is an empty delta snapshot; therefore, we will only mark it as destroyed in the database.", snapshotTo)); + logger.debug(String.format("Snapshot [%s] is an empty delta snapshot; therefore, we will only mark it as destroyed in the database.", snapshotTo)); deleted = true; if (!resultIsSet) { result = true; @@ -233,7 +231,7 @@ protected boolean deleteSnapshotChain(SnapshotInfo snapshot, String storageToStr if (r) { List cacheSnaps = snapshotDataFactory.listSnapshotOnCache(snapshot.getId()); for (SnapshotInfo cacheSnap : cacheSnaps) { - s_logger.debug(String.format("Deleting snapshot %s from image cache [%s].", snapshotTo, cacheSnap.getDataStore().getName())); + logger.debug(String.format("Deleting snapshot %s from image cache [%s].", snapshotTo, cacheSnap.getDataStore().getName())); cacheSnap.delete(); } } @@ -243,14 +241,14 @@ protected boolean deleteSnapshotChain(SnapshotInfo snapshot, String storageToStr resultIsSet = true; } } catch (Exception e) { - s_logger.error(String.format("Failed to delete snapshot [%s] on storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e); + logger.error(String.format("Failed to delete snapshot [%s] on storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e); } } snapshot = parent; } while (snapshot != null && snapshotStatesAbleToDeleteSnapshot.contains(snapshot.getState())); } catch (Exception e) { - s_logger.error(String.format("Failed to delete snapshot [%s] on storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e); + logger.error(String.format("Failed to delete snapshot [%s] on storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e); } return result; } @@ -363,9 +361,9 @@ protected Boolean deleteSnapshotInfo(SnapshotInfo snapshotInfo, SnapshotVO snaps if (!DataStoreRole.Primary.equals(dataStore.getRole())) { verifyIfTheSnapshotIsBeingUsedByAnyVolume(snapshotObject); if (deleteSnapshotChain(snapshotInfo, storageToString)) { - s_logger.debug(String.format("%s was deleted on %s. We will mark the snapshot as destroyed.", snapshotVo, storageToString)); + logger.debug(String.format("%s was deleted on %s. We will mark the snapshot as destroyed.", snapshotVo, storageToString)); } else { - s_logger.debug(String.format("%s was not deleted on %s; however, we will mark the snapshot as destroyed for future garbage collecting.", snapshotVo, + logger.debug(String.format("%s was not deleted on %s; however, we will mark the snapshot as destroyed for future garbage collecting.", snapshotVo, storageToString)); } snapshotStoreDao.updateDisplayForSnapshotStoreRole(snapshotVo.getId(), dataStore.getId(), dataStore.getRole(), false); @@ -377,12 +375,12 @@ protected Boolean deleteSnapshotInfo(SnapshotInfo snapshotInfo, SnapshotVO snaps snapshotStoreDao.updateDisplayForSnapshotStoreRole(snapshotVo.getId(), dataStore.getId(), dataStore.getRole(), false); return true; } - s_logger.debug(String.format("Failed to delete %s on %s.", snapshotVo, storageToString)); + logger.debug(String.format("Failed to delete %s on %s.", snapshotVo, storageToString)); if (isLastSnapshotRef) { snapshotObject.processEvent(Snapshot.Event.OperationFailed); } } catch (NoTransitionException ex) { - s_logger.warn(String.format("Failed to delete %s on %s due to %s.", snapshotVo, storageToString, ex.getMessage()), ex); + logger.warn(String.format("Failed to delete %s on %s due to %s.", snapshotVo, storageToString, ex.getMessage()), ex); } return false; } @@ -396,11 +394,11 @@ protected boolean deleteSnapshotInPrimaryStorage(SnapshotInfo snapshotInfo, Snap msg = String.format("%s We will mark the snapshot as destroyed.", msg); snapshotObject.processEvent(Snapshot.Event.OperationSucceeded); } - s_logger.debug(msg); + logger.debug(msg); return true; } } catch (CloudRuntimeException ex) { - s_logger.warn(String.format("Unable do delete snapshot %s on %s due to [%s]. The reference will be marked as 'Destroying' for future garbage collecting.", + logger.warn(String.format("Unable do delete snapshot %s on %s due to [%s]. The reference will be marked as 'Destroying' for future garbage collecting.", snapshotVo, storageToString, ex.getMessage()), ex); } return false; @@ -465,7 +463,7 @@ public boolean revertSnapshot(SnapshotInfo snapshot) { result = snapshotSvr.revertSnapshot(snapshot); if (!result) { - s_logger.debug("Failed to revert snapshot: " + snapshot.getId()); + logger.debug("Failed to revert snapshot: " + snapshot.getId()); throw new CloudRuntimeException("Failed to revert snapshot: " + snapshot.getId()); } @@ -510,7 +508,7 @@ public SnapshotInfo takeSnapshot(SnapshotInfo snapshot) { try { result = snapshotSvr.takeSnapshot(snapshot); if (result.isFailed()) { - s_logger.debug("Failed to take snapshot: " + result.getResult()); + logger.debug("Failed to take snapshot: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } } finally { @@ -565,7 +563,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { } } } catch (Exception e) { - s_logger.debug("Failed to clean up snapshots on primary storage", e); + logger.debug("Failed to clean up snapshots on primary storage", e); } } }); @@ -584,7 +582,7 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat return StrategyPriority.CANT_HANDLE; } if (zoneId != null && SnapshotOperation.DELETE.equals(op)) { - s_logger.debug(String.format("canHandle for zone ID: %d, operation: %s - %s", zoneId, op, StrategyPriority.DEFAULT)); + logger.debug(String.format("canHandle for zone ID: %d, operation: %s - %s", zoneId, op, StrategyPriority.DEFAULT)); } return StrategyPriority.DEFAULT; } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/ScaleIOSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/ScaleIOSnapshotStrategy.java index 3dee4f4aa94f..0d48cb944aee 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/ScaleIOSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/ScaleIOSnapshotStrategy.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import com.cloud.storage.DataStoreRole; import com.cloud.storage.Snapshot; @@ -42,7 +41,6 @@ public class ScaleIOSnapshotStrategy extends StorageSystemSnapshotStrategy { @Inject private VolumeDao volumeDao; - private static final Logger LOG = Logger.getLogger(ScaleIOSnapshotStrategy.class); @Override public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperation op) { @@ -73,7 +71,7 @@ public boolean revertSnapshot(SnapshotInfo snapshotInfo) { VolumeInfo volumeInfo = snapshotInfo.getBaseVolume(); Storage.ImageFormat imageFormat = volumeInfo.getFormat(); if (!Storage.ImageFormat.RAW.equals(imageFormat)) { - LOG.error(String.format("Does not support revert snapshot of the image format [%s] on PowerFlex. Can only rollback snapshots of format RAW", imageFormat)); + logger.error(String.format("Does not support revert snapshot of the image format [%s] on PowerFlex. Can only rollback snapshots of format RAW", imageFormat)); return false; } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java index 6cf68f64fd92..961a647d7a8c 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java @@ -41,7 +41,8 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.to.SnapshotObjectTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataObjectType; @@ -60,7 +61,7 @@ import com.cloud.utils.fsm.NoTransitionException; public class SnapshotObject implements SnapshotInfo { - private static final Logger s_logger = Logger.getLogger(SnapshotObject.class); + protected Logger logger = LogManager.getLogger(getClass()); private SnapshotVO snapshot; private DataStore store; private Object payload; @@ -182,7 +183,7 @@ public void markBackedUp() throws CloudRuntimeException{ try { processEvent(Event.OperationNotPerformed); } catch (NoTransitionException ex) { - s_logger.error("no transition error: ", ex); + logger.error("no transition error: ", ex); throw new CloudRuntimeException("Error marking snapshot backed up: " + this.snapshot.getId() + " " + ex.getMessage()); } @@ -235,7 +236,7 @@ public void processEvent(ObjectInDataStoreStateMachine.Event event) { try { objectInStoreMgr.update(this, event); } catch (Exception e) { - s_logger.debug("Failed to update state:" + e.toString()); + logger.debug("Failed to update state:" + e.toString()); throw new CloudRuntimeException("Failed to update state: " + e.toString()); } finally { DataObjectInStore obj = objectInStoreMgr.findObject(this, this.getDataStore()); @@ -369,12 +370,12 @@ public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answe if (snapshotTO.getVolume() != null && snapshotTO.getVolume().getPath() != null) { VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid()); if (vol != null) { - s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + + logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + snapshotTO.getVolume().getPath()); vol.setPath(snapshotTO.getVolume().getPath()); volumeDao.update(vol.getId(), vol); } else { - s_logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid()); + logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid()); } } } else { diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java index 9c7ee9834749..dafc40e0674d 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java @@ -57,7 +57,8 @@ import org.apache.cloudstack.storage.heuristics.HeuristicRuleHelper; import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; import org.apache.cloudstack.storage.to.SnapshotObjectTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.configuration.Config; @@ -79,7 +80,7 @@ import com.cloud.utils.fsm.NoTransitionException; public class SnapshotServiceImpl implements SnapshotService { - private static final Logger s_logger = Logger.getLogger(SnapshotServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected SnapshotDao _snapshotDao; @Inject @@ -176,7 +177,7 @@ private String generateCopyUrlBase(String hostname, String dir) { _sslCopy = Boolean.parseBoolean(sslCfg); } if(_sslCopy && (_ssvmUrlDomain == null || _ssvmUrlDomain.isEmpty())){ - s_logger.warn("Empty secondary storage url domain, ignoring SSL"); + logger.warn("Empty secondary storage url domain, ignoring SSL"); _sslCopy = false; } if (_sslCopy) { @@ -197,12 +198,12 @@ protected Void createSnapshotAsyncCallback(AsyncCallbackDispatcher future = context.future; SnapshotResult snapResult = new SnapshotResult(snapshot, result.getAnswer()); if (result.isFailed()) { - s_logger.debug("create snapshot " + context.snapshot.getName() + " failed: " + result.getResult()); + logger.debug("create snapshot " + context.snapshot.getName() + " failed: " + result.getResult()); try { snapshot.processEvent(Snapshot.Event.OperationFailed); snapshot.processEvent(Event.OperationFailed); } catch (Exception e) { - s_logger.debug("Failed to update snapshot state due to " + e.getMessage()); + logger.debug("Failed to update snapshot state due to " + e.getMessage()); } snapResult.setResult(result.getResult()); @@ -214,12 +215,12 @@ protected Void createSnapshotAsyncCallback(AsyncCallbackDispatcher snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId); for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) { - s_logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + + logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + " on snapshot_store_ref table with id: " + snapshotDataStoreVO.getId()); _snapshotStoreDao.remove(snapshotDataStoreVO.getId()); } - s_logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table"); + logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table"); _snapshotDao.remove(snapshotId); } } @@ -631,8 +632,8 @@ private void syncSnapshotToRegionStore(long snapshotId, DataStore store){ throw new CloudRuntimeException("Cannot find an entry in snapshot_store_ref for snapshot " + snapshotId + " on region store: " + store.getName()); } if (snapOnStore.getPath() == null || snapOnStore.getPath().length() == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("sync snapshot " + snapshotId + " from cache to object store..."); + if (logger.isDebugEnabled()) { + logger.debug("sync snapshot " + snapshotId + " from cache to object store..."); } // snapshot is not on region store yet, sync to region store SnapshotInfo srcSnapshot = _snapshotFactory.getReadySnapshotOnCache(snapshotId); @@ -688,7 +689,7 @@ protected Void syncSnapshotCallBack(AsyncCallbackDispatcher copySnapshot(SnapshotInfo snapshot, Strin SnapshotObject snapshotForCopy = (SnapshotObject)_snapshotFactory.getSnapshot(snapshot, store); snapshotForCopy.setUrl(copyUrl); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Mark snapshot_store_ref entry as Creating"); + if (logger.isDebugEnabled()) { + logger.debug("Mark snapshot_store_ref entry as Creating"); } AsyncCallFuture future = new AsyncCallFuture(); DataObject snapshotOnStore = store.create(snapshotForCopy); ((SnapshotObject)snapshotOnStore).setUrl(copyUrl); snapshotOnStore.processEvent(Event.CreateOnlyRequested); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Invoke datastore driver createAsync to create snapshot on destination store"); + if (logger.isDebugEnabled()) { + logger.debug("Invoke datastore driver createAsync to create snapshot on destination store"); } try { CopySnapshotContext context = new CopySnapshotContext<>(null, (SnapshotObject)snapshotOnStore, snapshotForCopy, future); @@ -768,7 +769,7 @@ public AsyncCallFuture queryCopySnapshot(SnapshotInfo snapshot) AsyncCallFuture future = new AsyncCallFuture<>(); EndPoint ep = epSelector.select(snapshot); if (ep == null) { - s_logger.error(String.format("Failed to find endpoint for generating copy URL for snapshot %d with store %d", snapshot.getId(), snapshot.getDataStore().getId())); + logger.error(String.format("Failed to find endpoint for generating copy URL for snapshot %d with store %d", snapshot.getId(), snapshot.getDataStore().getId())); throw new ResourceUnavailableException("No secondary VM in running state in source snapshot zone", DataCenter.class, snapshot.getDataCenterId()); } DataStore store = snapshot.getDataStore(); diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotStrategyBase.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotStrategyBase.java index ba16e75f737a..2bfcbc107f75 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotStrategyBase.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotStrategyBase.java @@ -21,8 +21,11 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public abstract class SnapshotStrategyBase implements SnapshotStrategy { + protected Logger logger = LogManager.getLogger(getClass()); @Inject SnapshotService snapshotSvr; diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java index dabb8d17702d..9838e41f8f6c 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java @@ -45,7 +45,6 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -91,7 +90,6 @@ @Component public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { - private static final Logger s_logger = Logger.getLogger(StorageSystemSnapshotStrategy.class); @Inject private AgentManager agentMgr; @Inject private ClusterDao clusterDao; @@ -132,7 +130,7 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshotInfo) { if (!canStorageSystemCreateVolumeFromSnapshot) { String msg = "Cannot archive snapshot: 'canStorageSystemCreateVolumeFromSnapshot' was false."; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -142,7 +140,7 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshotInfo) { if (!computeClusterSupportsResign) { String msg = "Cannot archive snapshot: 'computeClusterSupportsResign' was false."; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -185,7 +183,7 @@ private boolean cleanupSnapshotOnPrimaryStore(long snapshotId) { SnapshotObject snapshotObj = (SnapshotObject)snapshotDataFactory.getSnapshotOnPrimaryStore(snapshotId); if (snapshotObj == null) { - s_logger.debug("Can't find snapshot; deleting it in DB"); + logger.debug("Can't find snapshot; deleting it in DB"); snapshotDao.remove(snapshotId); @@ -205,14 +203,14 @@ private boolean cleanupSnapshotOnPrimaryStore(long snapshotId) { try { snapshotObj.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.debug("Failed to change snapshot state: " + e1.toString()); + logger.debug("Failed to change snapshot state: " + e1.toString()); } throw new InvalidParameterValueException("Unable to perform delete operation, Snapshot with id: " + snapshotId + " is in use "); } } catch (NoTransitionException e) { - s_logger.debug("Failed to set the state to destroying: ", e); + logger.debug("Failed to set the state to destroying: ", e); return false; } @@ -226,13 +224,13 @@ private boolean cleanupSnapshotOnPrimaryStore(long snapshotId) { snapshotObj.getName(), null, null, 0L, snapshotObj.getClass().getName(), snapshotObj.getUuid()); } catch (Exception e) { - s_logger.debug("Failed to delete snapshot: ", e); + logger.debug("Failed to delete snapshot: ", e); try { snapshotObj.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.debug("Failed to change snapshot state: " + e.toString()); + logger.debug("Failed to change snapshot state: " + e.toString()); } return false; @@ -302,7 +300,7 @@ public boolean revertSnapshot(SnapshotInfo snapshotInfo) { if (!volumeInfo.getPoolId().equals(snapshotStoragePoolId)) { String errMsg = "Storage pool mismatch"; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -313,7 +311,7 @@ public boolean revertSnapshot(SnapshotInfo snapshotInfo) { if (!storageSystemSupportsCapability) { String errMsg = "Storage pool revert capability not supported"; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -335,7 +333,7 @@ protected void executeRevertSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volum if (snapshotVO == null) { String errMsg = "Failed to acquire lock on the following snapshot: " + snapshotInfo.getId(); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -362,7 +360,7 @@ protected void executeRevertSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volum String errMsg = String.format("Failed to revert volume [name:%s, format:%s] to snapshot [id:%s] state", volumeInfo.getName(), volumeInfo.getFormat(), snapshotInfo.getSnapshotId()); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -500,7 +498,7 @@ else if (volumeInfo.getFormat() == ImageFormat.OVA || volumeInfo.getFormat() == result = snapshotSvr.takeSnapshot(snapshotInfo); if (result.isFailed()) { - s_logger.debug("Failed to take a snapshot: " + result.getResult()); + logger.debug("Failed to take a snapshot: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } @@ -539,7 +537,7 @@ public void postSnapshotCreation(SnapshotInfo snapshot) { try { snapshotSvr.deleteSnapshot(snapshot); } catch (Exception e) { - s_logger.warn("Failed to clean up snapshot '" + snapshot.getId() + "' on primary storage: " + e.getMessage()); + logger.warn("Failed to clean up snapshot '" + snapshot.getId() + "' on primary storage: " + e.getMessage()); } } @@ -571,7 +569,7 @@ private VMSnapshot takeHypervisorSnapshot(VolumeInfo volumeInfo) { Thread.sleep(60000); } catch (Exception ex) { - s_logger.warn(ex.getMessage(), ex); + logger.warn(ex.getMessage(), ex); } return vmSnapshot; @@ -686,7 +684,7 @@ private void performSnapshotAndCopyOnHostSide(VolumeInfo volumeInfo, SnapshotInf if (hostVO == null) { final String errMsg = "Unable to locate an applicable host"; - s_logger.error("performSnapshotAndCopyOnHostSide: " + errMsg); + logger.error("performSnapshotAndCopyOnHostSide: " + errMsg); throw new CloudRuntimeException(errMsg); } @@ -724,7 +722,7 @@ private void performSnapshotAndCopyOnHostSide(VolumeInfo volumeInfo, SnapshotInf } } catch (Exception ex) { - s_logger.debug(ex.getMessage(), ex); + logger.debug(ex.getMessage(), ex); } } @@ -894,13 +892,13 @@ private void markAsBackedUp(SnapshotObject snapshotObj) { snapshotObj.processEvent(Snapshot.Event.OperationSucceeded); } catch (NoTransitionException ex) { - s_logger.debug("Failed to change state: " + ex.toString()); + logger.debug("Failed to change state: " + ex.toString()); try { snapshotObj.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException ex2) { - s_logger.debug("Failed to change state: " + ex2.toString()); + logger.debug("Failed to change state: " + ex2.toString()); } } } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java index e2815c005c44..1d3788a03014 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -77,7 +76,6 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDao; public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshotStrategy { - private static final Logger s_logger = Logger.getLogger(DefaultVMSnapshotStrategy.class); @Inject VMSnapshotHelper vmSnapshotHelper; @Inject @@ -164,7 +162,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { answer = (CreateVMSnapshotAnswer)agentMgr.send(hostId, ccmd); if (answer != null && answer.getResult()) { processAnswer(vmSnapshotVO, userVm, answer, hostId); - s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); + logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); result = true; long new_chain_size=0; for (VolumeObjectTO volumeTo : answer.getVolumeTOs()) { @@ -177,21 +175,21 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { String errMsg = "Creating VM snapshot: " + vmSnapshot.getName() + " failed"; if (answer != null && answer.getDetails() != null) errMsg = errMsg + " due to " + answer.getDetails(); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (OperationTimedoutException e) { - s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); + logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); } catch (AgentUnavailableException e) { - s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e); + logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e); throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -204,7 +202,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } @@ -235,7 +233,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { return true; } else { String errMsg = (answer == null) ? null : answer.getDetails(); - s_logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg); + logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg); processAnswer(vmSnapshotVO, userVm, answer, hostId); throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg); } @@ -271,7 +269,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws NoTran }); } catch (Exception e) { String errMsg = "Error while process answer: " + as.getClass() + " due to " + e.getMessage(); - s_logger.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -377,7 +375,7 @@ protected void publishUsageEvent(String type, VMSnapshot vmSnapshot, UserVm user UsageEventUtils.publishUsageEvent(type, vmSnapshot.getAccountId(), userVm.getDataCenterId(), userVm.getId(), vmSnapshot.getName(), 0L, 0L, vmSnapSize, virtualSize, VMSnapshot.class.getName(), vmSnapshot.getUuid(), details); } catch (Exception e) { - s_logger.error("Failed to publis usage event " + type, e); + logger.error("Failed to publis usage event " + type, e); } } @@ -420,21 +418,21 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) { String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed"; if (answer != null && answer.getDetails() != null) errMsg = errMsg + " due to " + answer.getDetails(); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (OperationTimedoutException e) { - s_logger.debug("Failed to revert vm snapshot", e); + logger.debug("Failed to revert vm snapshot", e); throw new CloudRuntimeException(e.getMessage()); } catch (AgentUnavailableException e) { - s_logger.debug("Failed to revert vm snapshot", e); + logger.debug("Failed to revert vm snapshot", e); throw new CloudRuntimeException(e.getMessage()); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -451,7 +449,7 @@ public boolean deleteVMSnapshotFromDB(VMSnapshot vmSnapshot, boolean unmanage) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } UserVm userVm = userVmDao.findById(vmSnapshot.getVmId()); diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java index 50afa647dc37..d27beecfddac 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.VMSnapshotTO; import com.cloud.alert.AlertManager; @@ -70,7 +69,6 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDetailsDao; public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshotStrategy { - private static final Logger LOGGER = Logger.getLogger(ScaleIOVMSnapshotStrategy.class); @Inject VMSnapshotHelper vmSnapshotHelper; @Inject @@ -213,7 +211,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { finalizeCreate(vmSnapshotVO, volumeTOs); result = true; - LOGGER.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); + logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); long new_chain_size=0; for (VolumeObjectTO volumeTo : volumeTOs) { @@ -224,7 +222,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { return vmSnapshot; } catch (Exception e) { String errMsg = "Unable to take vm snapshot due to: " + e.getMessage(); - LOGGER.warn(errMsg, e); + logger.warn(errMsg, e); throw new CloudRuntimeException(errMsg); } } finally { @@ -236,7 +234,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { String message = "Snapshot operation failed for VM: " + userVm.getDisplayName() + ", Please check and delete if any stale volumes created with VM snapshot id: " + vmSnapshot.getVmId(); alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_VM_SNAPSHOT, userVm.getDataCenterId(), userVm.getPodIdToDeployIn(), subject, message); } catch (NoTransitionException e1) { - LOGGER.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -274,7 +272,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws NoTran }); } catch (Exception e) { String errMsg = "Error while finalize create vm snapshot: " + vmSnapshot.getName() + " due to " + e.getMessage(); - LOGGER.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -317,14 +315,14 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) { result = true; } catch (Exception e) { String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed due to " + e.getMessage(); - LOGGER.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - LOGGER.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -361,7 +359,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws NoTran }); } catch (Exception e) { String errMsg = "Error while finalize revert vm snapshot: " + vmSnapshot.getName() + " due to " + e.getMessage(); - LOGGER.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -374,7 +372,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - LOGGER.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } @@ -397,7 +395,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { if (volumesDeleted <= 0) { throw new CloudRuntimeException("Failed to delete VM snapshot: " + vmSnapshot.getName()); } else if (volumesDeleted != volumeTOs.size()) { - LOGGER.warn("Unable to delete all volumes of the VM snapshot: " + vmSnapshot.getName()); + logger.warn("Unable to delete all volumes of the VM snapshot: " + vmSnapshot.getName()); } finalizeDelete(vmSnapshotVO, volumeTOs); @@ -410,7 +408,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { return true; } catch (Exception e) { String errMsg = "Unable to delete vm snapshot: " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " due to " + e.getMessage(); - LOGGER.warn(errMsg, e); + logger.warn(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -453,7 +451,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws NoTran }); } catch (Exception e) { String errMsg = "Error while finalize delete vm snapshot: " + vmSnapshot.getName() + " due to " + e.getMessage(); - LOGGER.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -463,7 +461,7 @@ public boolean deleteVMSnapshotFromDB(VMSnapshot vmSnapshot, boolean unmanage) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - LOGGER.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } UserVm userVm = userVmDao.findById(vmSnapshot.getVmId()); @@ -507,7 +505,7 @@ private void publishUsageEvent(String type, VMSnapshot vmSnapshot, UserVm userVm UsageEventUtils.publishUsageEvent(type, vmSnapshot.getAccountId(), userVm.getDataCenterId(), userVm.getId(), vmSnapshot.getName(), 0L, 0L, vmSnapSize, virtualSize, VMSnapshot.class.getName(), vmSnapshot.getUuid(), details); } catch (Exception e) { - LOGGER.error("Failed to publish usage event " + type, e); + logger.error("Failed to publish usage event " + type, e); } } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/StorageVMSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/StorageVMSnapshotStrategy.java index f5d70817333c..ec73246851cd 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/StorageVMSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/StorageVMSnapshotStrategy.java @@ -39,7 +39,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.CreateVMSnapshotAnswer; import com.cloud.agent.api.CreateVMSnapshotCommand; @@ -75,7 +74,6 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDetailsDao; public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { - private static final Logger s_logger = Logger.getLogger(StorageVMSnapshotStrategy.class); @Inject VolumeApiService volumeService; @Inject @@ -148,7 +146,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { vmSnapshotVO.setParent(current.getId()); } CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(userVm.getInstanceName(), userVm.getUuid(), target, volumeTOs, guestOS.getDisplayName()); - s_logger.info("Creating VM snapshot for KVM hypervisor without memory"); + logger.info("Creating VM snapshot for KVM hypervisor without memory"); List vinfos = new ArrayList<>(); for (VolumeObjectTO volumeObjectTO : volumeTOs) { @@ -166,7 +164,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { thawCmd = new FreezeThawVMCommand(userVm.getInstanceName()); thawCmd.setOption(FreezeThawVMCommand.THAW); if (freezeAnswer != null && freezeAnswer.getResult()) { - s_logger.info("The virtual machine is frozen"); + logger.info("The virtual machine is frozen"); for (VolumeInfo vol : vinfos) { long startSnapshtot = System.nanoTime(); SnapshotInfo snapInfo = createDiskSnapshot(vmSnapshot, forRollback, vol); @@ -175,14 +173,14 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { thawAnswer = (FreezeThawVMAnswer) agentMgr.send(hostId, thawCmd); throw new CloudRuntimeException("Could not take snapshot for volume with id=" + vol.getId()); } - s_logger.info(String.format("Snapshot with id=%s, took %s milliseconds", snapInfo.getId(), + logger.info(String.format("Snapshot with id=%s, took %s milliseconds", snapInfo.getId(), TimeUnit.MILLISECONDS.convert(elapsedTime(startSnapshtot), TimeUnit.NANOSECONDS))); } answer = new CreateVMSnapshotAnswer(ccmd, true, ""); answer.setVolumeTOs(volumeTOs); thawAnswer = (FreezeThawVMAnswer) agentMgr.send(hostId, thawCmd); if (thawAnswer != null && thawAnswer.getResult()) { - s_logger.info(String.format( + logger.info(String.format( "Virtual machne is thawed. The freeze of virtual machine took %s milliseconds.", TimeUnit.MILLISECONDS.convert(elapsedTime(startFreeze), TimeUnit.NANOSECONDS))); } @@ -191,7 +189,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { } if (answer != null && answer.getResult()) { processAnswer(vmSnapshotVO, userVm, answer, null); - s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); + logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); long new_chain_size = 0; for (VolumeObjectTO volumeTo : answer.getVolumeTOs()) { publishUsageEvent(EventTypes.EVENT_VM_SNAPSHOT_CREATE, vmSnapshot, userVm, volumeTo); @@ -202,27 +200,27 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { return vmSnapshot; } else { String errMsg = "Creating VM snapshot: " + vmSnapshot.getName() + " failed"; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (OperationTimedoutException e) { - s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); + logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); throw new CloudRuntimeException( "Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); } catch (AgentUnavailableException e) { - s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e); + logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e); throw new CloudRuntimeException( "Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); } catch (CloudRuntimeException e) { throw new CloudRuntimeException(e.getMessage()); } finally { if (thawAnswer == null && freezeAnswer != null) { - s_logger.info(String.format("Freeze of virtual machine took %s milliseconds.", TimeUnit.MILLISECONDS + logger.info(String.format("Freeze of virtual machine took %s milliseconds.", TimeUnit.MILLISECONDS .convert(elapsedTime(startFreeze), TimeUnit.NANOSECONDS))); try { thawAnswer = (FreezeThawVMAnswer) agentMgr.send(hostId, thawCmd); } catch (AgentUnavailableException | OperationTimedoutException e) { - s_logger.debug("Could not unfreeze the VM due to " + e); + logger.debug("Could not unfreeze the VM due to " + e); } } if (!result) { @@ -238,7 +236,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { } vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -251,7 +249,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException( "Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } @@ -289,7 +287,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { } } String errMsg = String.format("Delete of VM snapshot [%s] of VM [%s] failed due to [%s]", vmSnapshot.getName(), userVm.getUserId(), err); - s_logger.error(errMsg, err); + logger.error(errMsg, err); throw new CloudRuntimeException(errMsg, err); } } @@ -325,14 +323,14 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) { processAnswer(vmSnapshotVO, userVm, answer, null); result = true; } catch (CloudRuntimeException e) { - s_logger.error(e); + logger.error(e); throw new CloudRuntimeException(e); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -382,7 +380,7 @@ protected void rollbackDiskSnapshot(SnapshotInfo snapshotInfo) { Long snapshotID = snapshotInfo.getId(); SnapshotVO snapshot = snapshotDao.findById(snapshotID); deleteSnapshotByStrategy(snapshot); - s_logger.debug("Rollback is executed: deleting snapshot with id:" + snapshotID); + logger.debug("Rollback is executed: deleting snapshot with id:" + snapshotID); } protected void deleteSnapshotByStrategy(SnapshotVO snapshot) { diff --git a/engine/storage/snapshot/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-snapshot-core-context.xml b/engine/storage/snapshot/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-snapshot-core-context.xml index 1d1c831a7b0a..cd64cedb7b2f 100644 --- a/engine/storage/snapshot/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-snapshot-core-context.xml +++ b/engine/storage/snapshot/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-snapshot-core-context.xml @@ -35,5 +35,5 @@ - + diff --git a/engine/storage/snapshot/src/main/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml b/engine/storage/snapshot/src/main/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml index 56c6fff63e0f..fc561159c8ea 100644 --- a/engine/storage/snapshot/src/main/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml +++ b/engine/storage/snapshot/src/main/resources/META-INF/cloudstack/storage/spring-engine-storage-snapshot-storage-context.xml @@ -32,7 +32,7 @@ - + diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java index b33f57c685c5..0a8bba821f87 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java @@ -33,7 +33,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.storage.Snapshot; import com.cloud.storage.Storage.ImageFormat; diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java index d438fef56381..6aab8d323846 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java @@ -47,7 +47,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -192,22 +192,22 @@ public void testRevertVMsnapshot() throws AgentUnavailableException, OperationTi UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); @@ -270,22 +270,22 @@ public void testDeleteVMsnapshot() throws AgentUnavailableException, OperationTi UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class); diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java index 5fd6dee90832..7bcfd4dda581 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java @@ -33,7 +33,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -115,18 +115,18 @@ public void testCreateVMSnapshot() throws AgentUnavailableException, OperationTi UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); Exception e = null; @@ -139,8 +139,8 @@ public void testCreateVMSnapshot() throws AgentUnavailableException, OperationTi assertNotNull(e); CreateVMSnapshotAnswer answer = Mockito.mock(CreateVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(true); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); VMSnapshot snapshot = null; snapshot = vmSnapshotStrategy.takeVMSnapshot(vmSnapshot); assertNotNull(snapshot); @@ -159,23 +159,23 @@ public void testRevertSnapshot() throws AgentUnavailableException, OperationTime UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); Exception e = null; @@ -189,7 +189,7 @@ public void testRevertSnapshot() throws AgentUnavailableException, OperationTime RevertToVMSnapshotAnswer answer = Mockito.mock(RevertToVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(Boolean.TRUE); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); boolean result = vmSnapshotStrategy.revertVMSnapshot(vmSnapshot); assertTrue(result); } @@ -207,23 +207,23 @@ public void testDeleteVMSnapshot() throws AgentUnavailableException, OperationTi UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); @@ -238,7 +238,7 @@ public void testDeleteVMSnapshot() throws AgentUnavailableException, OperationTi DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(true); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); boolean result = vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot); assertTrue(result); diff --git a/engine/storage/snapshot/src/test/resources/SnapshotManagerTestContext.xml b/engine/storage/snapshot/src/test/resources/SnapshotManagerTestContext.xml index a06ba6a3b9a1..b0aa3956f028 100644 --- a/engine/storage/snapshot/src/test/resources/SnapshotManagerTestContext.xml +++ b/engine/storage/snapshot/src/test/resources/SnapshotManagerTestContext.xml @@ -1,19 +1,19 @@ - callba // update endpoint with new host if changed setId(newHostId); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending command " + cmd.toString() + " to host: " + newHostId); + if (logger.isDebugEnabled()) { + logger.debug("Sending command " + cmd.toString() + " to host: " + newHostId); } agentMgr.send(newHostId, new Commands(cmd), new CmdRunner(callback)); } catch (AgentUnavailableException e) { diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java index 2a65fad8e8b5..63524ccb6db5 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java @@ -38,7 +38,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; @@ -66,7 +65,6 @@ import com.cloud.vm.VirtualMachineProfile; public abstract class AbstractStoragePoolAllocator extends AdapterBase implements StoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(AbstractStoragePoolAllocator.class); protected BigDecimal storageOverprovisioningFactor = new BigDecimal(1); protected String allocationAlgorithm = "random"; @@ -140,7 +138,7 @@ protected List reorderPoolsByCapacity(DeploymentPlan plan, List poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType); - s_logger.debug(String.format("List of pools in descending order of available capacity [%s].", poolIdsByCapacity)); + logger.debug(String.format("List of pools in descending order of available capacity [%s].", poolIdsByCapacity)); //now filter the given list of Pools by this ordered list @@ -169,7 +167,7 @@ protected List reorderPoolsByNumberOfVolumes(DeploymentPlan plan, L Long clusterId = plan.getClusterId(); List poolIdsByVolCount = volumeDao.listPoolIdsByVolumeCount(dcId, podId, clusterId, account.getAccountId()); - s_logger.debug(String.format("List of pools in ascending order of number of volumes for account [%s] is [%s].", account, poolIdsByVolCount)); + logger.debug(String.format("List of pools in ascending order of number of volumes for account [%s] is [%s].", account, poolIdsByVolCount)); // now filter the given list of Pools by this ordered list Map poolMap = new HashMap<>(); @@ -190,15 +188,15 @@ protected List reorderPoolsByNumberOfVolumes(DeploymentPlan plan, L @Override public List reorderPools(List pools, VirtualMachineProfile vmProfile, DeploymentPlan plan, DiskProfile dskCh) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("reordering pools"); + if (logger.isTraceEnabled()) { + logger.trace("reordering pools"); } if (pools == null) { - s_logger.trace("There are no pools to reorder; returning null."); + logger.trace("There are no pools to reorder; returning null."); return null; } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("reordering %d pools", pools.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("reordering %d pools", pools.size())); } Account account = null; if (vmProfile.getVirtualMachine() != null) { @@ -208,8 +206,8 @@ public List reorderPools(List pools, VirtualMachinePro pools = reorderStoragePoolsBasedOnAlgorithm(pools, plan, account); if (vmProfile.getVirtualMachine() == null) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("The VM is null, skipping pools reordering by disk provisioning type."); + if (logger.isTraceEnabled()) { + logger.trace("The VM is null, skipping pools reordering by disk provisioning type."); } return pools; } @@ -226,8 +224,8 @@ List reorderStoragePoolsBasedOnAlgorithm(List pools, D if (allocationAlgorithm.equals("random") || allocationAlgorithm.equals("userconcentratedpod_random") || (account == null)) { reorderRandomPools(pools); } else if (StringUtils.equalsAny(allocationAlgorithm, "userdispersing", "firstfitleastconsumed")) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Using reordering algorithm [%s]", allocationAlgorithm)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Using reordering algorithm [%s]", allocationAlgorithm)); } if (allocationAlgorithm.equals("userdispersing")) { @@ -240,13 +238,13 @@ List reorderStoragePoolsBasedOnAlgorithm(List pools, D } void reorderRandomPools(List pools) { - StorageUtil.traceLogStoragePools(pools, s_logger, "pools to choose from: "); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Shuffle this so that we don't check the pools in the same order. Algorithm == '%s' (or no account?)", allocationAlgorithm)); + StorageUtil.traceLogStoragePools(pools, logger, "pools to choose from: "); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Shuffle this so that we don't check the pools in the same order. Algorithm == '%s' (or no account?)", allocationAlgorithm)); } - StorageUtil.traceLogStoragePools(pools, s_logger, "pools to shuffle: "); + StorageUtil.traceLogStoragePools(pools, logger, "pools to shuffle: "); Collections.shuffle(pools, secureRandom); - StorageUtil.traceLogStoragePools(pools, s_logger, "shuffled list of pools to choose from: "); + StorageUtil.traceLogStoragePools(pools, logger, "shuffled list of pools to choose from: "); } private List reorderPoolsByDiskProvisioningType(List pools, DiskProfile diskProfile) { @@ -271,15 +269,15 @@ private List reorderPoolsByDiskProvisioningType(List p } protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, DeploymentPlan plan) { - s_logger.debug(String.format("Checking if storage pool [%s] is suitable to disk [%s].", pool, dskCh)); + logger.debug(String.format("Checking if storage pool [%s] is suitable to disk [%s].", pool, dskCh)); if (avoid.shouldAvoid(pool)) { - s_logger.debug(String.format("StoragePool [%s] is in avoid set, skipping this pool to allocation of disk [%s].", pool, dskCh)); + logger.debug(String.format("StoragePool [%s] is in avoid set, skipping this pool to allocation of disk [%s].", pool, dskCh)); return false; } if (dskCh.requiresEncryption() && !pool.getPoolType().supportsEncryption()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Storage pool type '%s' doesn't support encryption required for volume, skipping this pool", pool.getPoolType())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Storage pool type '%s' doesn't support encryption required for volume, skipping this pool", pool.getPoolType())); } return false; } @@ -288,20 +286,20 @@ protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, if (clusterId != null) { ClusterVO cluster = clusterDao.findById(clusterId); if (!(cluster.getHypervisorType() == dskCh.getHypervisorType())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("StoragePool's Cluster does not have required hypervisorType, skipping this pool"); + if (logger.isDebugEnabled()) { + logger.debug("StoragePool's Cluster does not have required hypervisorType, skipping this pool"); } return false; } } else if (pool.getHypervisor() != null && !pool.getHypervisor().equals(HypervisorType.Any) && !(pool.getHypervisor() == dskCh.getHypervisorType())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("StoragePool does not have required hypervisorType, skipping this pool"); + if (logger.isDebugEnabled()) { + logger.debug("StoragePool does not have required hypervisorType, skipping this pool"); } return false; } if (!checkDiskProvisioningSupport(dskCh, pool)) { - s_logger.debug(String.format("Storage pool [%s] does not have support to disk provisioning of disk [%s].", pool, ReflectionToStringBuilderUtils.reflectOnlySelectedFields(dskCh, + logger.debug(String.format("Storage pool [%s] does not have support to disk provisioning of disk [%s].", pool, ReflectionToStringBuilderUtils.reflectOnlySelectedFields(dskCh, "type", "name", "diskOfferingId", "templateId", "volumeId", "provisioningType", "hyperType"))); return false; } @@ -310,14 +308,18 @@ protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, return false; } - Volume volume = volumeDao.findById(dskCh.getVolumeId()); - if(!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) { - s_logger.debug(String.format("Pool [%s] is not compatible with volume [%s], skipping it.", pool, volume)); - return false; + Volume volume = null; + boolean isTempVolume = dskCh.getVolumeId() == Volume.DISK_OFFERING_SUITABILITY_CHECK_VOLUME_ID; + if (!isTempVolume) { + volume = volumeDao.findById(dskCh.getVolumeId()); + if (!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) { + logger.debug(String.format("Pool [%s] is not compatible with volume [%s], skipping it.", pool, volume)); + return false; + } } if (pool.isManaged() && !storageUtil.managedStoragePoolCanScale(pool, plan.getClusterId(), plan.getHostId())) { - s_logger.debug(String.format("Cannot allocate pool [%s] to volume [%s] because the max number of managed clustered filesystems has been exceeded.", pool, volume)); + logger.debug(String.format("Cannot allocate pool [%s] to volume [%s] because the max number of managed clustered filesystems has been exceeded.", pool, volume)); return false; } @@ -326,29 +328,35 @@ protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, requestVolumeDiskProfilePairs.add(new Pair<>(volume, dskCh)); if (dskCh.getHypervisorType() == HypervisorType.VMware) { if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster && storageMgr.isStoragePoolDatastoreClusterParent(pool)) { - s_logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is a parent datastore cluster.", pool, volume)); + logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is a parent datastore cluster.", pool, volume)); return false; } if (pool.getParent() != 0L) { StoragePoolVO datastoreCluster = storagePoolDao.findById(pool.getParent()); if (datastoreCluster == null || (datastoreCluster != null && datastoreCluster.getStatus() != StoragePoolStatus.Up)) { - s_logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not in [%s] state.", datastoreCluster, volume, StoragePoolStatus.Up)); + logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not in [%s] state.", datastoreCluster, volume, StoragePoolStatus.Up)); return false; } } try { - boolean isStoragePoolStoragepolicyComplaince = storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool); - if (!isStoragePoolStoragepolicyComplaince) { - s_logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not compliant with the storage policy required by the volume.", pool, volume)); + boolean isStoragePoolStoragePolicyCompliance = isTempVolume ? + storageMgr.isStoragePoolCompliantWithStoragePolicy(dskCh.getDiskOfferingId(), pool) : + storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool); + if (!isStoragePoolStoragePolicyCompliance) { + logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not compliant with the storage policy required by the volume.", pool, volume)); return false; } } catch (StorageUnavailableException e) { - s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", pool.getUuid(), e.getMessage())); + logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", pool.getUuid(), e.getMessage())); return false; } } - return storageMgr.storagePoolHasEnoughIops(requestVolumeDiskProfilePairs, pool) && storageMgr.storagePoolHasEnoughSpace(requestVolumeDiskProfilePairs, pool, plan.getClusterId()); + return isTempVolume ? + (storageMgr.storagePoolHasEnoughIops(dskCh.getMinIops(), pool) && + storageMgr.storagePoolHasEnoughSpace(dskCh.getSize(), pool)): + (storageMgr.storagePoolHasEnoughIops(requestVolumeDiskProfilePairs, pool) && + storageMgr.storagePoolHasEnoughSpace(requestVolumeDiskProfilePairs, pool, plan.getClusterId())); } private boolean checkDiskProvisioningSupport(DiskProfile dskCh, StoragePool pool) { @@ -372,13 +380,13 @@ private boolean checkHypervisorCompatibility(HypervisorType hyperType, Volume.Ty //LXC ROOT disks supports NFS and local storage pools only if(!(Storage.StoragePoolType.NetworkFilesystem.equals(poolType) || Storage.StoragePoolType.Filesystem.equals(poolType)) ){ - s_logger.debug("StoragePool does not support LXC ROOT disk, skipping this pool"); + logger.debug("StoragePool does not support LXC ROOT disk, skipping this pool"); return false; } } else if (Volume.Type.DATADISK.equals(volType)){ //LXC DATA disks supports RBD storage pool only if(!Storage.StoragePoolType.RBD.equals(poolType)){ - s_logger.debug("StoragePool does not support LXC DATA disk, skipping this pool"); + logger.debug("StoragePool does not support LXC DATA disk, skipping this pool"); return false; } } @@ -389,18 +397,18 @@ private boolean checkHypervisorCompatibility(HypervisorType hyperType, Volume.Ty protected void logDisabledStoragePools(long dcId, Long podId, Long clusterId, ScopeType scope) { List disabledPools = storagePoolDao.findDisabledPoolsByScope(dcId, podId, clusterId, scope); if (disabledPools != null && !disabledPools.isEmpty()) { - s_logger.trace(String.format("Ignoring pools [%s] as they are in disabled state.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(disabledPools))); + logger.trace(String.format("Ignoring pools [%s] as they are in disabled state.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(disabledPools))); } } protected void logStartOfSearch(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, int returnUpTo, boolean bypassStorageTypeCheck){ - s_logger.trace(String.format("%s is looking for storage pools that match the VM's disk profile [%s], virtual machine profile [%s] and " + logger.trace(String.format("%s is looking for storage pools that match the VM's disk profile [%s], virtual machine profile [%s] and " + "deployment plan [%s]. Returning up to [%d] and bypassStorageTypeCheck [%s].", this.getClass().getSimpleName(), dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck)); } protected void logEndOfSearch(List storagePoolList) { - s_logger.debug(String.format("%s is returning [%s] suitable storage pools [%s].", this.getClass().getSimpleName(), storagePoolList.size(), + logger.debug(String.format("%s is returning [%s] suitable storage pools [%s].", this.getClass().getSimpleName(), storagePoolList.size(), Arrays.toString(storagePoolList.toArray()))); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java index da35baf9366d..a52372fb3cad 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java @@ -26,7 +26,6 @@ import com.cloud.storage.VolumeApiServiceImpl; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.deploy.DeploymentPlan; @@ -40,7 +39,6 @@ @Component public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(ClusterScopeStoragePoolAllocator.class); @Inject DiskOfferingDao _diskOfferingDao; @@ -64,35 +62,35 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr // clusterId == null here because it will break ClusterWide primary // storage volume operation where // only podId is passed into this call. - s_logger.debug("ClusterScopeStoragePoolAllocator is returning null since the pod ID is null. This may be a zone wide storage."); + logger.debug("ClusterScopeStoragePoolAllocator is returning null since the pod ID is null. This may be a zone wide storage."); return null; } if (dskCh.getTags() != null && dskCh.getTags().length != 0) { - s_logger.debug(String.format("Looking for pools in dc [%s], pod [%s], cluster [%s], and having tags [%s]. Disabled pools will be ignored.", dcId, podId, clusterId, + logger.debug(String.format("Looking for pools in dc [%s], pod [%s], cluster [%s], and having tags [%s]. Disabled pools will be ignored.", dcId, podId, clusterId, Arrays.toString(dskCh.getTags()))); } else { - s_logger.debug(String.format("Looking for pools in dc [%s], pod [%s] and cluster [%s]. Disabled pools will be ignored.", dcId, podId, clusterId)); + logger.debug(String.format("Looking for pools in dc [%s], pod [%s] and cluster [%s]. Disabled pools will be ignored.", dcId, podId, clusterId)); } - if (s_logger.isTraceEnabled()) { + if (logger.isTraceEnabled()) { // Log the pools details that are ignored because they are in disabled state logDisabledStoragePools(dcId, podId, clusterId, ScopeType.CLUSTER); } List pools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags(), true, VolumeApiServiceImpl.storageTagRuleExecutionTimeout.value()); pools.addAll(storagePoolJoinDao.findStoragePoolByScopeAndRuleTags(dcId, podId, clusterId, ScopeType.CLUSTER, List.of(dskCh.getTags()))); - s_logger.debug(String.format("Found pools [%s] that match with tags [%s].", pools, Arrays.toString(dskCh.getTags()))); + logger.debug(String.format("Found pools [%s] that match with tags [%s].", pools, Arrays.toString(dskCh.getTags()))); // add remaining pools in cluster, that did not match tags, to avoid set List allPools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, null, false, 0); allPools.removeAll(pools); for (StoragePoolVO pool : allPools) { - s_logger.trace(String.format("Adding pool [%s] to the 'avoid' set since it did not match any tags.", pool)); + logger.trace(String.format("Adding pool [%s] to the 'avoid' set since it did not match any tags.", pool)); avoid.addPool(pool.getId()); } if (pools.size() == 0) { - s_logger.debug(String.format("No storage pools available for [%s] volume allocation.", ServiceOffering.StorageType.shared)); + logger.debug(String.format("No storage pools available for [%s] volume allocation.", ServiceOffering.StorageType.shared)); return suitablePools; } @@ -102,10 +100,10 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr } StoragePool storagePool = (StoragePool)dataStoreMgr.getPrimaryDataStore(pool.getId()); if (filter(avoid, storagePool, dskCh, plan)) { - s_logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); + logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); suitablePools.add(storagePool); } else { - s_logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); + logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); avoid.addPool(pool.getId()); } } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java index 9b9f56d4aa50..39c29bd2c6e6 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; @@ -36,7 +35,6 @@ import com.cloud.vm.VirtualMachineProfile; public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(GarbageCollectingStoragePoolAllocator.class); StoragePoolAllocator _firstFitStoragePoolAllocator; StoragePoolAllocator _localStoragePoolAllocator; @@ -50,7 +48,7 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl public List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) { logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck); if (!_storagePoolCleanupEnabled) { - s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped."); + logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped."); return null; } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java index 7ec2f26d9568..b8dcfb0ba7bf 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.capacity.dao.CapacityDao; @@ -44,7 +43,6 @@ @Component public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(LocalStoragePoolAllocator.class); @Inject StoragePoolHostDao _poolHostDao; @@ -64,11 +62,11 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck); if (!bypassStorageTypeCheck && !dskCh.useLocalStorage()) { - s_logger.debug("LocalStoragePoolAllocator is returning null since the disk profile does not use local storage and bypassStorageTypeCheck is false."); + logger.debug("LocalStoragePoolAllocator is returning null since the disk profile does not use local storage and bypassStorageTypeCheck is false."); return null; } - if (s_logger.isTraceEnabled()) { + if (logger.isTraceEnabled()) { // Log the pools details that are ignored because they are in disabled state logDisabledStoragePools(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), ScopeType.HOST); } @@ -82,10 +80,10 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr if (pool != null && pool.isLocal()) { StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()); if (filter(avoid, storagePool, dskCh, plan)) { - s_logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); + logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); suitablePools.add(storagePool); } else { - s_logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); + logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); avoid.addPool(pool.getId()); } } @@ -97,7 +95,7 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr } else { if (plan.getPodId() == null) { // zone wide primary storage deployment - s_logger.debug("LocalStoragePoolAllocator is returning null since both the host ID and pod ID are null. That means this should be a zone wide primary storage deployment."); + logger.debug("LocalStoragePoolAllocator is returning null since both the host ID and pod ID are null. That means this should be a zone wide primary storage deployment."); return null; } List availablePools = @@ -109,10 +107,10 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr } StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()); if (filter(avoid, storagePool, dskCh, plan)) { - s_logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); + logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); suitablePools.add(storagePool); } else { - s_logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); + logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); avoid.addPool(pool.getId()); } } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java index b02d437207e6..0c59cf24fc5b 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; @@ -43,7 +42,6 @@ @Component public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger LOGGER = Logger.getLogger(ZoneWideStoragePoolAllocator.class); @Inject private DataStoreManager dataStoreMgr; @Inject @@ -57,7 +55,7 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr return null; } - if (LOGGER.isTraceEnabled()) { + if (logger.isTraceEnabled()) { // Log the pools details that are ignored because they are in disabled state logDisabledStoragePools(plan.getDataCenterId(), null, null, ScopeType.ZONE); } @@ -66,7 +64,7 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr List storagePools = storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags(), true); storagePools.addAll(storagePoolJoinDao.findStoragePoolByScopeAndRuleTags(plan.getDataCenterId(), null, null, ScopeType.ZONE, List.of(dskCh.getTags()))); if (storagePools.isEmpty()) { - LOGGER.debug(String.format("Could not find any zone wide storage pool that matched with any of the following tags [%s].", Arrays.toString(dskCh.getTags()))); + logger.debug(String.format("Could not find any zone wide storage pool that matched with any of the following tags [%s].", Arrays.toString(dskCh.getTags()))); storagePools = new ArrayList<>(); } @@ -94,11 +92,11 @@ protected List select(DiskProfile dskCh, VirtualMachineProfile vmPr } StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(storage.getId()); if (filter(avoid, storagePool, dskCh, plan)) { - LOGGER.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", storagePool, dskCh)); + logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", storagePool, dskCh)); suitablePools.add(storagePool); } else { if (canAddStoragePoolToAvoidSet(storage)) { - LOGGER.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", storagePool, dskCh)); + logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", storagePool, dskCh)); avoid.addPool(storagePool.getId()); } } @@ -125,8 +123,8 @@ protected List reorderPoolsByCapacity(DeploymentPlan plan, } List poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, null, capacityType); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("List of zone-wide storage pools in descending order of free capacity: "+ poolIdsByCapacity); + if (logger.isDebugEnabled()) { + logger.debug("List of zone-wide storage pools in descending order of free capacity: "+ poolIdsByCapacity); } //now filter the given list of Pools by this ordered list @@ -154,8 +152,8 @@ protected List reorderPoolsByNumberOfVolumes(DeploymentPlan plan, L long dcId = plan.getDataCenterId(); List poolIdsByVolCount = volumeDao.listZoneWidePoolIdsByVolumeCount(dcId, account.getAccountId()); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("List of pools in ascending order of number of volumes for account id: " + account.getAccountId() + " is: " + poolIdsByVolCount); + if (logger.isDebugEnabled()) { + logger.debug("List of pools in ascending order of number of volumes for account id: " + account.getAccountId() + " is: " + poolIdsByVolCount); } // now filter the given list of Pools by this ordered list diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java index 460f869bebf3..7c1cbb55b3b1 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java @@ -20,7 +20,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; @@ -42,7 +43,7 @@ @Component public class DataObjectManagerImpl implements DataObjectManager { - private static final Logger s_logger = Logger.getLogger(DataObjectManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject ObjectInDataStoreManager objectInDataStoreMgr; @Inject @@ -57,13 +58,13 @@ protected DataObject waitingForCreated(DataObject dataObj, DataStore dataStore) try { Thread.sleep(waitingTime); } catch (InterruptedException e) { - s_logger.debug("sleep interrupted", e); + logger.debug("sleep interrupted", e); throw new CloudRuntimeException("sleep interrupted", e); } obj = objectInDataStoreMgr.findObject(dataObj, dataStore); if (obj == null) { - s_logger.debug("can't find object in db, maybe it's cleaned up already, exit waiting"); + logger.debug("can't find object in db, maybe it's cleaned up already, exit waiting"); break; } if (obj.getState() == ObjectInDataStoreStateMachine.State.Ready) { @@ -73,7 +74,7 @@ protected DataObject waitingForCreated(DataObject dataObj, DataStore dataStore) } while (retries > 0); if (obj == null || retries <= 0) { - s_logger.debug("waiting too long for template downloading, marked it as failed"); + logger.debug("waiting too long for template downloading, marked it as failed"); throw new CloudRuntimeException("waiting too long for template downloading, marked it as failed"); } return objectInDataStoreMgr.get(dataObj, dataStore, null); @@ -138,7 +139,7 @@ public void createAsync(DataObject data, DataStore store, AsyncCompletionCallbac try { objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("state transaction failed", e1); + logger.debug("state transaction failed", e1); } CreateCmdResult result = new CreateCmdResult(null, null); result.setSuccess(false); @@ -149,7 +150,7 @@ public void createAsync(DataObject data, DataStore store, AsyncCompletionCallbac try { objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("state transaction failed", e1); + logger.debug("state transaction failed", e1); } CreateCmdResult result = new CreateCmdResult(null, null); result.setSuccess(false); @@ -182,7 +183,7 @@ protected Void createAsynCallback(AsyncCallbackDispatcher try { objectInDataStoreMgr.update(data, Event.DestroyRequested); } catch (NoTransitionException e) { - s_logger.debug("destroy failed", e); + logger.debug("destroy failed", e); CreateCmdResult res = new CreateCmdResult(null, null); callback.complete(res); } catch (ConcurrentOperationException e) { - s_logger.debug("destroy failed", e); + logger.debug("destroy failed", e); CreateCmdResult res = new CreateCmdResult(null, null); callback.complete(res); } @@ -333,18 +334,18 @@ protected Void deleteAsynCallback(AsyncCallbackDispatcher { - private static final Logger s_logger = Logger.getLogger(DataStoreProviderManagerImpl.class); List providers; protected Map providerMap = new ConcurrentHashMap(); @@ -127,18 +125,18 @@ protected boolean registerProvider(DataStoreProvider provider) { String providerName = provider.getName(); if (providerMap.get(providerName) != null) { - s_logger.debug("Did not register data store provider, provider name: " + providerName + " is not unique"); + logger.debug("Did not register data store provider, provider name: " + providerName + " is not unique"); return false; } - s_logger.debug("registering data store provider:" + provider.getName()); + logger.debug("registering data store provider:" + provider.getName()); providerMap.put(providerName, provider); try { boolean registrationResult = provider.configure(copyParams); if (!registrationResult) { providerMap.remove(providerName); - s_logger.debug("Failed to register data store provider: " + providerName); + logger.debug("Failed to register data store provider: " + providerName); return false; } @@ -152,7 +150,7 @@ protected boolean registerProvider(DataStoreProvider provider) { objectStoreProviderMgr.registerDriver(provider.getName(), (ObjectStoreDriver)provider.getDataStoreDriver()); } } catch (Exception e) { - s_logger.debug("configure provider failed", e); + logger.debug("configure provider failed", e); providerMap.remove(providerName); return false; } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/db/ObjectInDataStoreDaoImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/db/ObjectInDataStoreDaoImpl.java index a492e76b9913..4b13c100a44d 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/db/ObjectInDataStoreDaoImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/db/ObjectInDataStoreDaoImpl.java @@ -21,7 +21,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; @@ -36,7 +35,6 @@ @Component public class ObjectInDataStoreDaoImpl extends GenericDaoBase implements ObjectInDataStoreDao { - private static final Logger s_logger = Logger.getLogger(ObjectInDataStoreDaoImpl.class); private SearchBuilder updateStateSearch; @Override @@ -69,7 +67,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat builder.set(vo, "updated", new Date()); int rows = update(vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { ObjectInDataStoreVO dbVol = findByIdIncludingRemoved(vo.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -102,7 +100,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update objectIndatastore: id=" + vo.getId() + ", as there is no such object exists in the database anymore"); + logger.debug("Unable to update objectIndatastore: id=" + vo.getId() + ", as there is no such object exists in the database anymore"); } } return rows > 0; diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java index ba1278f2fa04..a621e8a076d1 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java @@ -46,7 +46,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.storage.LocalHostEndpoint; import org.apache.cloudstack.storage.RemoteHostEndPoint; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.capacity.CapacityManager; @@ -69,7 +70,7 @@ @Component public class DefaultEndPointSelector implements EndPointSelector { - private static final Logger s_logger = Logger.getLogger(DefaultEndPointSelector.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private HostDao hostDao; @Inject @@ -174,10 +175,10 @@ protected EndPoint findEndPointInScope(Scope scope, String sqlBase, Long poolId, host = hostDao.findById(id); } } catch (SQLException e) { - s_logger.warn("can't find endpoint", e); + logger.warn("can't find endpoint", e); } } catch (SQLException e) { - s_logger.warn("can't find endpoint", e); + logger.warn("can't find endpoint", e); } if (host == null) { return null; @@ -298,7 +299,7 @@ public EndPoint select(DataObject srcData, DataObject destData, StorageAction ac @Override public EndPoint select(DataObject srcData, DataObject destData, StorageAction action, boolean encryptionRequired) { - s_logger.error("IR24 select BACKUPSNAPSHOT from primary to secondary " + srcData.getId() + " dest=" + destData.getId()); + logger.error("IR24 select BACKUPSNAPSHOT from primary to secondary " + srcData.getId() + " dest=" + destData.getId()); if (action == StorageAction.BACKUPSNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) { SnapshotInfo srcSnapshot = (SnapshotInfo)srcData; VolumeInfo volumeInfo = srcSnapshot.getBaseVolume(); @@ -425,11 +426,11 @@ public EndPoint select(DataStore store, String downloadUrl){ } } catch (URISyntaxException e) { - s_logger.debug("Received URISyntaxException for url" +downloadUrl); + logger.debug("Received URISyntaxException for url" +downloadUrl); } // If ssvm doesn't exist then find any ssvm in the zone. - s_logger.debug("Couldn't find ssvm for url" +downloadUrl); + logger.debug("Couldn't find ssvm for url" +downloadUrl); return findEndpointForImageStorage(store); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java index 9b7007dc4d66..10af5d55d619 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java @@ -23,7 +23,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; @@ -56,7 +57,7 @@ import com.cloud.vm.snapshot.VMSnapshot; public class HypervisorHelperImpl implements HypervisorHelper { - private static final Logger s_logger = Logger.getLogger(HypervisorHelperImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject EndPointSelector selector; @Inject @@ -79,7 +80,7 @@ public DataTO introduceObject(DataTO object, Scope scope, Long storeId) { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -99,7 +100,7 @@ public boolean forgetObject(DataTO object, Scope scope, Long storeId) { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -107,7 +108,7 @@ public boolean forgetObject(DataTO object, Scope scope, Long storeId) { if (answer == null || !answer.getResult()) { String errMsg = answer == null ? null : answer.getDetails(); if (errMsg != null) { - s_logger.debug("Failed to forget object: " + errMsg); + logger.debug("Failed to forget object: " + errMsg); } return false; } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java index 369630a1a73e..db3f798a68a7 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java @@ -20,9 +20,6 @@ import java.net.URI; import java.net.URISyntaxException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -55,7 +52,8 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.endpoint.DefaultEndPointSelector; import org.apache.cloudstack.storage.image.deployasis.DeployAsIsHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -86,14 +84,13 @@ import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.download.DownloadMonitor; import com.cloud.utils.NumbersUtil; -import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Proxy; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.SecondaryStorageVmDao; public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { - private static final Logger LOGGER = Logger.getLogger(BaseImageStoreDriverImpl.class); + protected Logger logger = LogManager.getLogger(BaseImageStoreDriverImpl.class); @Inject protected VMTemplateDao _templateDao; @@ -179,20 +176,20 @@ public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCal caller.setContext(context); if (data.getType() == DataObjectType.TEMPLATE) { caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null)); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Downloading template to data store " + dataStore.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Downloading template to data store " + dataStore.getId()); } _downloadMonitor.downloadTemplateToStorage(data, caller); } else if (data.getType() == DataObjectType.VOLUME) { caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null)); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Downloading volume to data store " + dataStore.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Downloading volume to data store " + dataStore.getId()); } _downloadMonitor.downloadVolumeToStorage(data, caller); } else if (data.getType() == DataObjectType.SNAPSHOT) { caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Downloading volume to data store " + dataStore.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Downloading volume to data store " + dataStore.getId()); } _downloadMonitor.downloadSnapshotToStorage(data, caller); } @@ -200,8 +197,8 @@ public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCal protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher callback, CreateContext context) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Performing image store createTemplate async callback"); + if (logger.isDebugEnabled()) { + logger.debug("Performing image store createTemplate async callback"); } DownloadAnswer answer = callback.getResult(); DataObject obj = context.data; @@ -215,16 +212,16 @@ protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher eps = _epSelector.findAllEndpointsForScope(srcdata.getDataStore()); if (eps == null || eps.isEmpty()) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { // select endpoint with least number of commands running on them @@ -424,8 +421,9 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As private Answer sendToLeastBusyEndpoint(List eps, CopyCommand cmd) { Answer answer = null; EndPoint endPoint = null; - List epIds = ssvmWithLeastMigrateJobs(); + logger.debug("Picking SSVM from the pool with least commands running on it."); + List epIds = hostDao.listSsvmHostsWithPendingMigrateJobsOrderedByJobCount(); if (epIds.isEmpty()) { Collections.shuffle(eps); endPoint = eps.get(0); @@ -447,10 +445,10 @@ private Answer sendToLeastBusyEndpoint(List eps, CopyCommand cmd) { return answer; } catch (AgentUnavailableException e) { errMsg = e.toString(); - LOGGER.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString()); + logger.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString()); } catch (OperationTimedoutException e) { errMsg = e.toString(); - LOGGER.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString()); + logger.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString()); } throw new CloudRuntimeException("Failed to send command, due to Agent:" + endPoint.getId() + ", " + errMsg); } @@ -480,8 +478,8 @@ public void deleteEntityExtractUrl(DataStore store, String installPath, String u @Override public List getDataDiskTemplates(DataObject obj, String configurationId) { List dataDiskDetails = new ArrayList(); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Get the data disks present in the OVA template"); + if (logger.isDebugEnabled()) { + logger.debug("Get the data disks present in the OVA template"); } DataStore store = obj.getDataStore(); GetDatadisksCommand cmd = new GetDatadisksCommand(obj.getTO(), configurationId); @@ -489,7 +487,7 @@ public List getDataDiskTemplates(DataObject obj, String configuratio Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -508,14 +506,14 @@ public List getDataDiskTemplates(DataObject obj, String configuratio public Void createDataDiskTemplateAsync(TemplateInfo dataDiskTemplate, String path, String diskId, boolean bootable, long fileSize, AsyncCompletionCallback callback) { Answer answer = null; String errMsg = null; - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Create Datadisk template: " + dataDiskTemplate.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Create Datadisk template: " + dataDiskTemplate.getId()); } CreateDatadiskTemplateCommand cmd = new CreateDatadiskTemplateCommand(dataDiskTemplate.getTO(), path, diskId, fileSize, bootable); EndPoint ep = _defaultEpSelector.select(dataDiskTemplate.getDataStore()); if (ep == null) { errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -532,23 +530,4 @@ public Void createDataDiskTemplateAsync(TemplateInfo dataDiskTemplate, String pa private Integer getCopyCmdsCountToSpecificSSVM(Long ssvmId) { return _cmdExecLogDao.getCopyCmdCountForSSVM(ssvmId); } - - private List ssvmWithLeastMigrateJobs() { - LOGGER.debug("Picking ssvm from the pool with least commands running on it"); - String query = "select host_id, count(*) from cmd_exec_log group by host_id order by 2;"; - TransactionLegacy txn = TransactionLegacy.currentTxn(); - - List result = new ArrayList(); - PreparedStatement pstmt = null; - try { - pstmt = txn.prepareAutoCloseStatement(query); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) { - result.add((long) rs.getInt(1)); - } - } catch (SQLException e) { - LOGGER.debug("SQLException caught", e); - } - return result; - } } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java index cb14506ad171..aceab4506781 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java @@ -28,7 +28,6 @@ import javax.naming.ConfigurationException; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -58,7 +57,6 @@ @Component public class TemplateDataStoreDaoImpl extends GenericDaoBase implements TemplateDataStoreDao { - private static final Logger s_logger = Logger.getLogger(TemplateDataStoreDaoImpl.class); private SearchBuilder updateStateSearch; private SearchBuilder storeSearch; private SearchBuilder cacheSearch; @@ -199,7 +197,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat } int rows = update(dataObj, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { TemplateDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString()); @@ -232,7 +230,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId() + ", as there is no such object exists in the database anymore"); + logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId() + ", as there is no such object exists in the database anymore"); } } return rows > 0; @@ -494,7 +492,7 @@ public void duplicateCacheRecordsOnRegionStore(long storeId) { List tmpls = listBy(sc); // create an entry for each template record, but with empty install path since the content is not yet on region-wide store yet if (tmpls != null) { - s_logger.info("Duplicate " + tmpls.size() + " template cache store records to region store"); + logger.info("Duplicate " + tmpls.size() + " template cache store records to region store"); for (TemplateDataStoreVO tmpl : tmpls) { long templateId = tmpl.getTemplateId(); VMTemplateVO template = _tmpltDao.findById(templateId); @@ -502,15 +500,15 @@ public void duplicateCacheRecordsOnRegionStore(long storeId) { throw new CloudRuntimeException("No template is found for template id: " + templateId); } if (template.getTemplateType() == TemplateType.SYSTEM) { - s_logger.info("No need to duplicate system template since it will be automatically downloaded while adding region store"); + logger.info("No need to duplicate system template since it will be automatically downloaded while adding region store"); continue; } TemplateDataStoreVO tmpStore = findByStoreTemplate(storeId, tmpl.getTemplateId()); if (tmpStore != null) { - s_logger.info("There is already entry for template " + tmpl.getTemplateId() + " on region store " + storeId); + logger.info("There is already entry for template " + tmpl.getTemplateId() + " on region store " + storeId); continue; } - s_logger.info("Persisting an entry for template " + tmpl.getTemplateId() + " on region store " + storeId); + logger.info("Persisting an entry for template " + tmpl.getTemplateId() + " on region store " + storeId); TemplateDataStoreVO ts = new TemplateDataStoreVO(); ts.setTemplateId(tmpl.getTemplateId()); ts.setDataStoreId(storeId); @@ -545,7 +543,7 @@ public void updateStoreRoleToCachce(long storeId) { sc.setParameters("destroyed", false); List tmpls = listBy(sc); if (tmpls != null) { - s_logger.info("Update to cache store role for " + tmpls.size() + " entries in template_store_ref"); + logger.info("Update to cache store role for " + tmpls.size() + " entries in template_store_ref"); for (TemplateDataStoreVO tmpl : tmpls) { tmpl.setDataStoreRole(DataStoreRole.ImageCache); update(tmpl.getId(), tmpl); @@ -605,7 +603,7 @@ public void expireDnldUrlsForZone(Long dcId){ txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Failed expiring download urls for dcId: " + dcId, e); + logger.warn("Failed expiring download urls for dcId: " + dcId, e); } } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java index dcdc9ea56c24..9eae1fc0711c 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java @@ -29,7 +29,6 @@ import com.cloud.utils.db.Filter; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -52,7 +51,6 @@ @Component public class VolumeDataStoreDaoImpl extends GenericDaoBase implements VolumeDataStoreDao { - private static final Logger s_logger = Logger.getLogger(VolumeDataStoreDaoImpl.class); private SearchBuilder updateStateSearch; private SearchBuilder volumeSearch; private SearchBuilder storeSearch; @@ -150,7 +148,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat } int rows = update(dataObj, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { VolumeDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString()); @@ -183,7 +181,7 @@ public boolean updateState(State currentState, Event event, State nextState, Dat .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId() + ", as there is no such object exists in the database anymore"); + logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId() + ", as there is no such object exists in the database anymore"); } } return rows > 0; @@ -296,14 +294,14 @@ public void duplicateCacheRecordsOnRegionStore(long storeId) { } // create an entry for each record, but with empty install path since the content is not yet on region-wide store yet if (vols != null) { - s_logger.info("Duplicate " + vols.size() + " volume cache store records to region store"); + logger.info("Duplicate " + vols.size() + " volume cache store records to region store"); for (VolumeDataStoreVO vol : vols) { VolumeDataStoreVO volStore = findByStoreVolume(storeId, vol.getVolumeId()); if (volStore != null) { - s_logger.info("There is already entry for volume " + vol.getVolumeId() + " on region store " + storeId); + logger.info("There is already entry for volume " + vol.getVolumeId() + " on region store " + storeId); continue; } - s_logger.info("Persisting an entry for volume " + vol.getVolumeId() + " on region store " + storeId); + logger.info("Persisting an entry for volume " + vol.getVolumeId() + " on region store " + storeId); VolumeDataStoreVO vs = new VolumeDataStoreVO(); vs.setVolumeId(vol.getVolumeId()); vs.setDataStoreId(storeId); @@ -380,7 +378,7 @@ public void expireDnldUrlsForZone(Long dcId){ txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Failed expiring download urls for dcId: " + dcId, e); + logger.warn("Failed expiring download urls for dcId: " + dcId, e); } } @@ -409,4 +407,16 @@ public boolean updateVolumeId(long srcVolId, long destVolId) { } return true; } + + @Override + public int expungeByVolumeList(List volumeIds, Long batchSize) { + if (CollectionUtils.isEmpty(volumeIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("volumeIds", sb.entity().getVolumeId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("volumeIds", volumeIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java index 2d0a0f2b32a5..b39ef1dd1163 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java @@ -56,7 +56,8 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import javax.inject.Inject; @@ -71,7 +72,7 @@ @Component public class DeployAsIsHelperImpl implements DeployAsIsHelper { - private static final Logger LOGGER = Logger.getLogger(DeployAsIsHelperImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private static Gson gson; @Inject @@ -128,7 +129,7 @@ private void persistTemplateOVFInformation(long templateId, OVFInformationTO ovf if (guestOsInfo != null) { String osType = guestOsInfo.first(); String osDescription = guestOsInfo.second(); - LOGGER.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription); + logger.info("Guest OS information retrieved from the template: " + osType + " - " + osDescription); handleGuestOsFromOVFDescriptor(templateId, osType, osDescription, minimumHardwareVersion); } } @@ -139,14 +140,14 @@ public boolean persistTemplateOVFInformationAndUpdateGuestOS(long templateId, OV persistTemplateOVFInformation(templateId, ovfInformationTO); } } catch (Exception e) { - LOGGER.error("Error persisting deploy-as-is details for template " + templateId, e); + logger.error("Error persisting deploy-as-is details for template " + templateId, e); tmpltStoreVO.setErrorString(e.getMessage()); tmpltStoreVO.setState(Failed); tmpltStoreVO.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); templateDataStoreDao.update(tmpltStoreVO.getId(), tmpltStoreVO); return false; } - LOGGER.info("Successfully persisted deploy-as-is details for template " + templateId); + logger.info("Successfully persisted deploy-as-is details for template " + templateId); return true; } @@ -162,16 +163,16 @@ private Long retrieveTemplateGuestOsIdFromGuestOsInfo(long templateId, String gu } String minimumHypervisorVersion = getMinimumSupportedHypervisorVersionForHardwareVersion(minimumHardwareVersion); - LOGGER.info("Minimum hardware version " + minimumHardwareVersion + " matched to hypervisor version " + minimumHypervisorVersion + ". " + + logger.info("Minimum hardware version " + minimumHardwareVersion + " matched to hypervisor version " + minimumHypervisorVersion + ". " + "Checking guest OS supporting this version"); List guestOsMappings = guestOSHypervisorDao.listByOsNameAndHypervisorMinimumVersion(guestOsType, hypervisor.toString(), minimumHypervisorVersion); if (CollectionUtils.isNotEmpty(guestOsMappings)) { - if (LOGGER.isDebugEnabled()) { + if (logger.isDebugEnabled()) { String msg = String.format("number of hypervisor mappings for guest os \"%s\" is: %d", guestOsType, guestOsMappings.size()); - LOGGER.debug(msg); + logger.debug(msg); } Long guestOsId = null; if (guestOsMappings.size() == 1) { @@ -207,7 +208,7 @@ private void handleGuestOsFromOVFDescriptor(long templateId, String guestOsType, String minimumHardwareVersion) { Long guestOsId = retrieveTemplateGuestOsIdFromGuestOsInfo(templateId, guestOsType, guestOsDescription, minimumHardwareVersion); if (guestOsId != null) { - LOGGER.info("Updating deploy-as-is template guest OS to " + guestOsType); + logger.info("Updating deploy-as-is template guest OS to " + guestOsType); VMTemplateVO template = templateDao.findById(templateId); updateTemplateGuestOsId(template, guestOsId); } @@ -223,7 +224,7 @@ private void updateDeployAsIsTemplateToNewGuestOs(VMTemplateVO template, String Hypervisor.HypervisorType hypervisor, Collection hypervisorVersions) { GuestOSVO newGuestOs = createGuestOsEntry(guestOsDescription); for (String hypervisorVersion : hypervisorVersions) { - LOGGER.info(String.format("Adding a new guest OS mapping for hypervisor: %s version: %s and " + + logger.info(String.format("Adding a new guest OS mapping for hypervisor: %s version: %s and " + "guest OS: %s", hypervisor.toString(), hypervisorVersion, guestOsType)); createGuestOsHypervisorMapping(newGuestOs.getId(), guestOsType, hypervisor.toString(), hypervisorVersion); } @@ -278,7 +279,7 @@ protected String mapHardwareVersionToHypervisorVersion(String hardwareVersion) { hypervisorVersion = "6.7"; } } catch (NumberFormatException e) { - LOGGER.error("Cannot parse hardware version " + hwVersion + " to integer. Using default hypervisor version", e); + logger.error("Cannot parse hardware version " + hwVersion + " to integer. Using default hypervisor version", e); } return hypervisorVersion; } @@ -332,7 +333,7 @@ public Map getAllocatedVirtualMachineNicsAdapterMapping(Virtual if (ArrayUtils.isNotEmpty(nics)) { if (nics.length != networks.size()) { String msg = "Different number of networks provided vs networks defined in deploy-as-is template"; - LOGGER.error(msg); + logger.error(msg); return map; } for (int i = 0; i < nics.length; i++) { @@ -347,16 +348,16 @@ public void persistTemplateDeployAsIsInformationTOList(long templateId, List informationTOList) { for (TemplateDeployAsIsInformationTO informationTO : informationTOList) { String propKey = getKeyFromInformationTO(informationTO); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Saving property %s for template %d as detail", propKey, templateId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Saving property %s for template %d as detail", propKey, templateId)); } String propValue = null; try { propValue = getValueFromInformationTO(informationTO); } catch (RuntimeException re) { - LOGGER.error("gson marshalling of property object fails: " + propKey,re); + logger.error("gson marshalling of property object fails: " + propKey,re); } catch (IOException e) { - LOGGER.error("Could not decompress the license for template " + templateId, e); + logger.error("Could not decompress the license for template " + templateId, e); } saveTemplateDeployAsIsPropertyAttribute(templateId, propKey, propValue); } @@ -391,18 +392,18 @@ private String getKeyFromInformationTO(TemplateDeployAsIsInformationTO informati } private void saveTemplateDeployAsIsPropertyAttribute(long templateId, String key, String value) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Saving property %s for template %d as detail", key, templateId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Saving property %s for template %d as detail", key, templateId)); } if (templateDeployAsIsDetailsDao.findDetail(templateId,key) != null) { - LOGGER.debug(String.format("Detail '%s' existed for template %d, deleting.", key, templateId)); + logger.debug(String.format("Detail '%s' existed for template %d, deleting.", key, templateId)); templateDeployAsIsDetailsDao.removeDetail(templateId,key); } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Template detail for template %d to save is '%s': '%s'", templateId, key, value)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Template detail for template %d to save is '%s': '%s'", templateId, key, value)); } TemplateDeployAsIsDetailVO detailVO = new TemplateDeployAsIsDetailVO(templateId, key, value); - LOGGER.debug("Persisting template details " + detailVO.getName() + " from OVF properties for template " + templateId); + logger.debug("Persisting template details " + detailVO.getName() + " from OVF properties for template " + templateId); templateDeployAsIsDetailsDao.persist(detailVO); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/object/BaseObjectStoreDriverImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/object/BaseObjectStoreDriverImpl.java index e6027a1959f8..8d45c959b59b 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/object/BaseObjectStoreDriverImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/object/BaseObjectStoreDriverImpl.java @@ -27,12 +27,13 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncRpcContext; import org.apache.cloudstack.storage.command.CommandResult; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Map; public abstract class BaseObjectStoreDriverImpl implements ObjectStoreDriver { - private static final Logger LOGGER = Logger.getLogger(BaseObjectStoreDriverImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Override public Map getCapabilities() { diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/object/ObjectStoreDriver.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/object/ObjectStoreDriver.java index 4953b9b0cdf5..13aaf7c002ef 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/object/ObjectStoreDriver.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/object/ObjectStoreDriver.java @@ -20,6 +20,7 @@ import com.amazonaws.services.s3.model.AccessControlList; import com.amazonaws.services.s3.model.BucketPolicy; +import com.cloud.agent.api.to.BucketTO; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; import java.util.List; @@ -30,30 +31,30 @@ public interface ObjectStoreDriver extends DataStoreDriver { List listBuckets(long storeId); - boolean deleteBucket(String bucketName, long storeId); + boolean deleteBucket(BucketTO bucket, long storeId); - AccessControlList getBucketAcl(String bucketName, long storeId); + AccessControlList getBucketAcl(BucketTO bucket, long storeId); - void setBucketAcl(String bucketName, AccessControlList acl, long storeId); + void setBucketAcl(BucketTO bucket, AccessControlList acl, long storeId); - void setBucketPolicy(String bucketName, String policyType, long storeId); + void setBucketPolicy(BucketTO bucket, String policyType, long storeId); - BucketPolicy getBucketPolicy(String bucketName, long storeId); + BucketPolicy getBucketPolicy(BucketTO bucket, long storeId); - void deleteBucketPolicy(String bucketName, long storeId); + void deleteBucketPolicy(BucketTO bucket, long storeId); boolean createUser(long accountId, long storeId); - boolean setBucketEncryption(String bucketName, long storeId); + boolean setBucketEncryption(BucketTO bucket, long storeId); - boolean deleteBucketEncryption(String bucketName, long storeId); + boolean deleteBucketEncryption(BucketTO bucket, long storeId); - boolean setBucketVersioning(String bucketName, long storeId); + boolean setBucketVersioning(BucketTO bucket, long storeId); - boolean deleteBucketVersioning(String bucketName, long storeId); + boolean deleteBucketVersioning(BucketTO bucket, long storeId); - void setBucketQuota(String bucketName, long storeId, long size); + void setBucketQuota(BucketTO bucket, long storeId, long size); Map getAllBucketsUsage(long storeId); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java index 216d6042f364..e4c269326198 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java @@ -28,6 +28,10 @@ import org.apache.cloudstack.annotation.AnnotationService; import org.apache.cloudstack.annotation.dao.AnnotationDao; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; @@ -35,8 +39,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreParameters; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.agent.api.StoragePoolInfo; import com.cloud.capacity.Capacity; @@ -60,7 +62,7 @@ @Component public class PrimaryDataStoreHelper { - private static final Logger s_logger = Logger.getLogger(PrimaryDataStoreHelper.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private PrimaryDataStoreDao dataStoreDao; @Inject @@ -111,7 +113,7 @@ public DataStore createPrimaryDataStore(PrimaryDataStoreParameters params) { if (user == null || password == null) { String errMsg = "Missing cifs user and password details. Add them as details parameter."; - s_logger.warn(errMsg); + logger.warn(errMsg); throw new InvalidParameterValueException(errMsg); } else { try { @@ -264,7 +266,7 @@ public boolean deletePrimaryDataStore(DataStore store) { this._capacityDao.removeBy(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, null, null, null, poolVO.getId()); txn.commit(); - s_logger.debug("Storage pool id=" + poolVO.getId() + " is removed successfully"); + logger.debug("Storage pool id=" + poolVO.getId() + " is removed successfully"); return true; } @@ -284,7 +286,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { _capacityDao.update(capacity.getId(), capacity); } }); - s_logger.debug("Scope of storage pool id=" + pool.getId() + " is changed to zone"); + logger.debug("Scope of storage pool id=" + pool.getId() + " is changed to zone"); } public void switchToCluster(DataStore store, ClusterScope clusterScope) { @@ -310,6 +312,6 @@ public void doInTransactionWithoutResult(TransactionStatus status) { _capacityDao.update(capacity.getId(), capacity); } }); - s_logger.debug("Scope of storage pool id=" + pool.getId() + " is changed to cluster id=" + clusterScope.getScopeId()); + logger.debug("Scope of storage pool id=" + pool.getId() + " is changed to cluster id=" + clusterScope.getScopeId()); } } diff --git a/engine/storage/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml b/engine/storage/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml index 5cecb224125c..ad13a3971728 100644 --- a/engine/storage/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml +++ b/engine/storage/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-core-context.xml @@ -35,7 +35,7 @@ - + - + - + diff --git a/engine/storage/src/main/resources/META-INF/cloudstack/storage-allocator/spring-engine-storage-storage-allocator-context.xml b/engine/storage/src/main/resources/META-INF/cloudstack/storage-allocator/spring-engine-storage-storage-allocator-context.xml index 783c98aacbe2..e68d2c673092 100644 --- a/engine/storage/src/main/resources/META-INF/cloudstack/storage-allocator/spring-engine-storage-storage-allocator-context.xml +++ b/engine/storage/src/main/resources/META-INF/cloudstack/storage-allocator/spring-engine-storage-storage-allocator-context.xml @@ -31,7 +31,7 @@ class="org.apache.cloudstack.storage.allocator.LocalStoragePoolAllocator"> - + - + diff --git a/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java b/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java index 493ea089ef49..ae25017db31a 100644 --- a/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java +++ b/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/engine/storage/src/test/java/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImplTest.java b/engine/storage/src/test/java/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImplTest.java new file mode 100644 index 000000000000..0cd886999564 --- /dev/null +++ b/engine/storage/src/test/java/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImplTest.java @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.image.db; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class VolumeDataStoreDaoImplTest { + + @Spy + VolumeDataStoreDaoImpl volumeDataStoreDaoImplSpy; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, volumeDataStoreDaoImplSpy.expungeByVolumeList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, volumeDataStoreDaoImplSpy.expungeByVolumeList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(volumeDataStoreDaoImplSpy).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(volumeDataStoreDaoImplSpy.createSearchBuilder()).thenReturn(sb); + final VolumeDataStoreVO mockedVO = Mockito.mock(VolumeDataStoreVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), volumeDataStoreDaoImplSpy.expungeByVolumeList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("volumeIds", array); + Mockito.verify(volumeDataStoreDaoImplSpy, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/engine/storage/volume/pom.xml b/engine/storage/volume/pom.xml index 34394f551053..a00c33141263 100644 --- a/engine/storage/volume/pom.xml +++ b/engine/storage/volume/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java index e392c2615f17..7f373fa9988c 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java @@ -47,7 +47,8 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.volume.VolumeObject; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.to.DataObjectType; import com.cloud.agent.api.to.DataStoreTO; @@ -69,7 +70,7 @@ @SuppressWarnings("serial") public class PrimaryDataStoreImpl implements PrimaryDataStore { - private static final Logger s_logger = Logger.getLogger(PrimaryDataStoreImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); protected PrimaryDataStoreDriver driver; protected StoragePoolVO pdsv; @@ -186,7 +187,7 @@ public Scope getScope() { if (poolHosts.size() > 0) { return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId()); } - s_logger.debug("can't find a local storage in pool host table: " + vo.getId()); + logger.debug("can't find a local storage in pool host table: " + vo.getId()); } return null; } @@ -296,29 +297,29 @@ public DataObject create(DataObject obj, boolean createEntryInTempSpoolRef, Stri VMTemplateStoragePoolVO templateStoragePoolRef; GlobalLock lock = GlobalLock.getInternLock(templateIdPoolIdString); if (!lock.lock(5)) { - s_logger.debug("Couldn't lock the db on the string " + templateIdPoolIdString); + logger.debug("Couldn't lock the db on the string " + templateIdPoolIdString); return null; } try { templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId(), configuration); if (templateStoragePoolRef == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Not found (" + templateIdPoolIdString + ") in template_spool_ref, persisting it"); + if (logger.isDebugEnabled()) { + logger.debug("Not found (" + templateIdPoolIdString + ") in template_spool_ref, persisting it"); } templateStoragePoolRef = new VMTemplateStoragePoolVO(getId(), obj.getId(), configuration); templateStoragePoolRef = templatePoolDao.persist(templateStoragePoolRef); } } catch (Throwable t) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to insert (" + templateIdPoolIdString + ") to template_spool_ref", t); + if (logger.isDebugEnabled()) { + logger.debug("Failed to insert (" + templateIdPoolIdString + ") to template_spool_ref", t); } templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId(), configuration); if (templateStoragePoolRef == null) { throw new CloudRuntimeException("Failed to create template storage pool entry"); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Another thread already inserts " + templateStoragePoolRef.getId() + " to template_spool_ref", t); + if (logger.isDebugEnabled()) { + logger.debug("Another thread already inserts " + templateStoragePoolRef.getId() + " to template_spool_ref", t); } } } finally { @@ -326,7 +327,7 @@ public DataObject create(DataObject obj, boolean createEntryInTempSpoolRef, Stri lock.releaseRef(); } } catch (Exception e) { - s_logger.debug("Caught exception ", e); + logger.debug("Caught exception ", e); } } else if (obj.getType() == DataObjectType.SNAPSHOT) { return objectInStoreMgr.create(obj, this); diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/BasePrimaryDataStoreLifeCycleImpl.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/BasePrimaryDataStoreLifeCycleImpl.java index adc74a77d43b..1ee4d40a5678 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/BasePrimaryDataStoreLifeCycleImpl.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/BasePrimaryDataStoreLifeCycleImpl.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -39,9 +38,12 @@ import com.cloud.storage.StoragePoolHostVO; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.utils.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class BasePrimaryDataStoreLifeCycleImpl { - private static final Logger s_logger = Logger.getLogger(BasePrimaryDataStoreLifeCycleImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); + @Inject AgentManager agentMgr; @Inject @@ -70,13 +72,13 @@ private List getPoolHostsList(ClusterScope clusterScope, HypervisorType public void changeStoragePoolScopeToZone(DataStore store, ClusterScope clusterScope, HypervisorType hypervisorType) { List hosts = getPoolHostsList(clusterScope, hypervisorType); - s_logger.debug("Changing scope of the storage pool to Zone"); + logger.debug("Changing scope of the storage pool to Zone"); if (hosts != null) { for (HostVO host : hosts) { try { storageMgr.connectHostToSharedPool(host.getId(), store.getId()); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + store, e); + logger.warn("Unable to establish a connection between " + host + " and " + store, e); } } } @@ -85,7 +87,7 @@ public void changeStoragePoolScopeToZone(DataStore store, ClusterScope clusterSc public void changeStoragePoolScopeToCluster(DataStore store, ClusterScope clusterScope, HypervisorType hypervisorType) { Pair, Integer> hostPoolRecords = storagePoolHostDao.listByPoolIdNotInCluster(clusterScope.getScopeId(), store.getId()); - s_logger.debug("Changing scope of the storage pool to Cluster"); + logger.debug("Changing scope of the storage pool to Cluster"); if (hostPoolRecords.second() > 0) { StoragePool pool = (StoragePool) store; for (StoragePoolHostVO host : hostPoolRecords.first()) { @@ -94,7 +96,7 @@ public void changeStoragePoolScopeToCluster(DataStore store, ClusterScope cluste if (answer != null) { if (!answer.getResult()) { - s_logger.debug("Failed to delete storage pool: " + answer.getResult()); + logger.debug("Failed to delete storage pool: " + answer.getResult()); } else if (HypervisorType.KVM != hypervisorType) { break; } diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java index ea1e524f5d60..c6d9fab5f17a 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java @@ -52,7 +52,8 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import javax.inject.Inject; @@ -60,7 +61,7 @@ import java.util.Map; public class DefaultHostListener implements HypervisorHostListener { - private static final Logger s_logger = Logger.getLogger(DefaultHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); /** * Wait time for modify storage pool command to complete. We should wait for 5 minutes for the command to complete. @@ -102,7 +103,7 @@ public boolean hostAdded(long hostId) { private boolean createPersistentNetworkResourcesOnHost(long hostId) { HostVO host = hostDao.findById(hostId); if (host == null) { - s_logger.warn(String.format("Host with id %ld can't be found", hostId)); + logger.warn(String.format("Host with id %ld can't be found", hostId)); return false; } setupPersistentNetwork(host); @@ -133,7 +134,7 @@ public boolean hostConnect(long hostId, long poolId) throws StorageConflictExcep ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool, nfsMountOpts.first()); cmd.setWait(modifyStoragePoolCommandWait); - s_logger.debug(String.format("Sending modify storage pool command to agent: %d for storage pool: %d with timeout %d seconds", + logger.debug(String.format("Sending modify storage pool command to agent: %d for storage pool: %d with timeout %d seconds", hostId, poolId, cmd.getWait())); final Answer answer = agentMgr.easySend(hostId, cmd); @@ -156,7 +157,7 @@ public boolean hostConnect(long hostId, long poolId) throws StorageConflictExcep List localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName); for (StoragePoolVO localStoragePool : localStoragePools) { if (datastoreName.equals(localStoragePool.getPath())) { - s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName()); + logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName()); throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName()); } @@ -172,7 +173,7 @@ public boolean hostConnect(long hostId, long poolId) throws StorageConflictExcep storageService.updateStorageCapabilities(poolId, false); - s_logger.info("Connection established between storage pool " + pool + " and host " + hostId); + logger.info("Connection established between storage pool " + pool + " and host " + hostId); return createPersistentNetworkResourcesOnHost(hostId); } @@ -210,7 +211,7 @@ public boolean hostAboutToBeRemoved(long hostId) { // send host the cleanup persistent network resources HostVO host = hostDao.findById(hostId); if (host == null) { - s_logger.warn("Host with id " + hostId + " can't be found"); + logger.warn("Host with id " + hostId + " can't be found"); return false; } @@ -221,12 +222,12 @@ public boolean hostAboutToBeRemoved(long hostId) { new CleanupPersistentNetworkResourceCommand(createNicTOFromNetworkAndOffering(persistentNetworkVO, networkOfferingVO, host)); Answer answer = agentMgr.easySend(hostId, cleanupCmd); if (answer == null) { - s_logger.error("Unable to get answer to the cleanup persistent network command " + persistentNetworkVO.getId()); + logger.error("Unable to get answer to the cleanup persistent network command " + persistentNetworkVO.getId()); continue; } if (!answer.getResult()) { String msg = String.format("Unable to cleanup persistent network resources from network %d on the host %d", persistentNetworkVO.getId(), hostId); - s_logger.error(msg); + logger.error(msg); } } return true; @@ -241,7 +242,7 @@ public boolean hostRemoved(long hostId, long clusterId) { public boolean hostEnabled(long hostId) { HostVO host = hostDao.findById(hostId); if (host == null) { - s_logger.warn(String.format("Host with id %d can't be found", hostId)); + logger.warn(String.format("Host with id %d can't be found", hostId)); return false; } setupPersistentNetwork(host); @@ -261,7 +262,7 @@ private void setupPersistentNetwork(HostVO host) { } if (!answer.getResult()) { String msg = String.format("Unable to create persistent network resources for network %d on the host %d in zone %d", networkVO.getId(), host.getId(), networkVO.getDataCenterId()); - s_logger.error(msg); + logger.error(msg); } } } diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java index 2e49698d0da3..825a8cbd941c 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java @@ -51,7 +51,8 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.DownloadAnswer; @@ -85,7 +86,7 @@ import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; public class VolumeObject implements VolumeInfo { - private static final Logger s_logger = Logger.getLogger(VolumeObject.class); + protected Logger logger = LogManager.getLogger(getClass()); protected VolumeVO volumeVO; private StateMachine2 _volStateMachine; protected DataStore dataStore; @@ -234,7 +235,7 @@ public boolean stateTransit(Volume.Event event) { } } catch (NoTransitionException e) { String errorMessage = String.format("Failed to transit volume %s to [%s] due to [%s].", volumeVO.getVolumeDescription(), event, e.getMessage()); - s_logger.warn(errorMessage, e); + logger.warn(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } return result; @@ -445,7 +446,7 @@ protected void updateObjectInDataStoreManager(ObjectInDataStoreStateMachine.Even } catch (ConcurrentOperationException | NoTransitionException e) { String message = String.format("Failed to update %sto state [%s] due to [%s].", volumeVO == null ? "" : String.format("volume %s ", volumeVO.getVolumeDescription()), getMapOfEvents().get(event), e.getMessage()); - s_logger.warn(message, e); + logger.warn(message, e); throw new CloudRuntimeException(message, e); } finally { expungeEntryOnOperationFailed(event, callExpungeEntry); @@ -691,7 +692,7 @@ protected void updateVolumeInfo(VolumeObjectTO newVolume, VolumeVO volumeVo, boo volumeDao.update(volumeVo.getId(), volumeVo); String newValues = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volumeVo, "path", "size", "format", "encryptFormat", "poolId"); - s_logger.debug(String.format("Updated %s from %s to %s ", volumeVo.getVolumeDescription(), previousValues, newValues)); + logger.debug(String.format("Updated %s from %s to %s ", volumeVo.getVolumeDescription(), previousValues, newValues)); } protected void updateResourceCount(VolumeObjectTO newVolume, VolumeVO oldVolume) { @@ -725,7 +726,7 @@ protected void handleProcessEventCopyCmdAnswerNotPrimaryStore(VolumeObjectTO new volumeStoreDao.update(volStore.getId(), volStore); String newValues = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volStore, "installPath", "size"); - s_logger.debug(String.format("Updated volume_store_ref %s from %s to %s.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volStore, "id", "volumeId"), + logger.debug(String.format("Updated volume_store_ref %s from %s to %s.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volStore, "id", "volumeId"), previousValues, newValues)); } @@ -757,7 +758,7 @@ protected void handleProcessEventAnswer(DownloadAnswer downloadAnswer) { volumeStoreDao.update(volumeDataStoreVo.getId(), volumeDataStoreVo); String newValues = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volumeDataStoreVo, "installPath", "checksum"); - s_logger.debug(String.format("Updated volume_store_ref %s from %s to %s.", ReflectionToStringBuilderUtils. + logger.debug(String.format("Updated volume_store_ref %s from %s to %s.", ReflectionToStringBuilderUtils. reflectOnlySelectedFields(volumeDataStoreVo, "id", "volumeId"), previousValues, newValues)); } @Override @@ -899,15 +900,15 @@ public void doInTransactionWithoutResult(TransactionStatus status) { volumeVO.setPassphraseId(null); volumeDao.persist(volumeVO); - s_logger.debug(String.format("Checking to see if we can delete passphrase id %s", passphraseId)); + logger.debug(String.format("Checking to see if we can delete passphrase id %s", passphraseId)); List volumes = volumeDao.listVolumesByPassphraseId(passphraseId); if (volumes != null && !volumes.isEmpty()) { - s_logger.debug("Other volumes use this passphrase, skipping deletion"); + logger.debug("Other volumes use this passphrase, skipping deletion"); return; } - s_logger.debug(String.format("Deleting passphrase %s", passphraseId)); + logger.debug(String.format("Deleting passphrase %s", passphraseId)); passphraseDao.remove(passphraseId); } } @@ -934,6 +935,11 @@ public void setEncryptFormat(String encryptFormat) { volumeVO.setEncryptFormat(encryptFormat); } + @Override + public boolean isDeleteProtection() { + return volumeVO.isDeleteProtection(); + } + @Override public boolean isFollowRedirects() { return followRedirects; diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 63726b400936..9a3319f79a33 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -32,10 +32,6 @@ import javax.inject.Inject; -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.storage.DiskOfferingVO; -import com.cloud.storage.VolumeApiServiceImpl; -import com.cloud.storage.dao.DiskOfferingDao; import org.apache.cloudstack.annotation.AnnotationService; import org.apache.cloudstack.annotation.dao.AnnotationDao; import org.apache.cloudstack.api.command.user.volume.CheckAndRepairVolumeCmd; @@ -87,7 +83,8 @@ import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -107,6 +104,7 @@ import com.cloud.dc.dao.ClusterDao; import com.cloud.event.EventTypes; import com.cloud.event.UsageEventUtils; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.StorageAccessException; import com.cloud.host.Host; @@ -120,6 +118,7 @@ import com.cloud.resource.ResourceState; import com.cloud.server.ManagementService; import com.cloud.storage.CheckAndRepairVolumePayload; +import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.DataStoreRole; import com.cloud.storage.RegisterVolumePayload; import com.cloud.storage.ScopeType; @@ -132,9 +131,11 @@ import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume; +import com.cloud.storage.VolumeApiServiceImpl; import com.cloud.storage.Volume.State; import com.cloud.storage.VolumeDetailVO; import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplatePoolDao; import com.cloud.storage.dao.VolumeDao; @@ -156,7 +157,7 @@ @Component public class VolumeServiceImpl implements VolumeService { - private static final Logger s_logger = Logger.getLogger(VolumeServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected AgentManager agentMgr; @Inject @@ -291,12 +292,12 @@ public boolean requiresAccessForMigration(DataObject dataObject, DataStore dataS @Override public AsyncCallFuture createVolumeAsync(VolumeInfo volume, DataStore dataStore) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); DataObject volumeOnStore = dataStore.create(volume); volumeOnStore.processEvent(Event.CreateOnlyRequested); try { - CreateVolumeContext context = new CreateVolumeContext(null, volumeOnStore, future); + CreateVolumeContext context = new CreateVolumeContext<>(null, volumeOnStore, future); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().createVolumeCallback(null, null)).setContext(context); @@ -372,12 +373,12 @@ private boolean canVolumeBeRemoved(long volumeId) { @DB @Override public AsyncCallFuture expungeVolumeAsync(VolumeInfo volume) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); VolumeApiResult result = new VolumeApiResult(volume); if (volume.getDataStore() == null) { - s_logger.info("Expunge volume with no data store specified"); + logger.info("Expunge volume with no data store specified"); if (canVolumeBeRemoved(volume.getId())) { - s_logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table"); + logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table"); volDao.remove(volume.getId()); } future.complete(result); @@ -389,7 +390,7 @@ public AsyncCallFuture expungeVolumeAsync(VolumeInfo volume) { if (volumeStore != null) { if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) { String msg = "Volume: " + volume.getName() + " is currently being uploaded; can't delete it."; - s_logger.debug(msg); + logger.debug(msg); result.setSuccess(false); result.setResult(msg); future.complete(result); @@ -399,7 +400,7 @@ public AsyncCallFuture expungeVolumeAsync(VolumeInfo volume) { VolumeVO vol = volDao.findById(volume.getId()); if (vol == null) { - s_logger.debug("Volume " + volume.getId() + " is not found"); + logger.debug("Volume " + volume.getId() + " is not found"); future.complete(result); return future; } @@ -408,8 +409,8 @@ public AsyncCallFuture expungeVolumeAsync(VolumeInfo volume) { // not created on primary store if (volumeStore == null) { // also not created on secondary store - if (s_logger.isDebugEnabled()) { - s_logger.debug("Marking volume that was never created as destroyed: " + vol); + if (logger.isDebugEnabled()) { + logger.debug("Marking volume that was never created as destroyed: " + vol); } VMTemplateVO template = templateDao.findById(vol.getTemplateId()); if (template != null && !template.isDeployAsIs()) { @@ -428,7 +429,7 @@ public AsyncCallFuture expungeVolumeAsync(VolumeInfo volume) { volume.processEvent(Event.ExpungeRequested); } - DeleteVolumeContext context = new DeleteVolumeContext(null, vo, future); + DeleteVolumeContext context = new DeleteVolumeContext<>(null, vo, future); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().deleteVolumeCallback(null, null)).setContext(context); @@ -483,7 +484,7 @@ public Void deleteVolumeCallback(AsyncCallbackDispatcher context = new CreateBaseImageContext(null, volume, dataStore, template, future, templateOnPrimaryStoreObj, templatePoolRefId); + CreateBaseImageContext context = new CreateBaseImageContext<>(null, volume, dataStore, template, future, templateOnPrimaryStoreObj, templatePoolRefId); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().copyBaseImageCallback(null, null)).setContext(context); int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds"); + if (logger.isDebugEnabled()) { + logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds"); } templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds); if (templatePoolRef == null) { - if (s_logger.isDebugEnabled()) { - s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId); + if (logger.isDebugEnabled()) { + logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId); } templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId(), deployAsIsConfiguration); if (templatePoolRef != null && templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) { - s_logger.info( + logger.info( "Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId + ", But Template " + template.getUniqueName() + " is already copied to primary storage, skip copying"); createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future); return; @@ -663,27 +664,27 @@ protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStor throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId); } - if (s_logger.isDebugEnabled()) { - s_logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId); + if (logger.isDebugEnabled()) { + logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId); } try { if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) { - s_logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying"); + logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying"); createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future); return; } templateOnPrimaryStoreObj.processEvent(Event.CreateOnlyRequested); motionSrv.copyAsync(template, templateOnPrimaryStoreObj, caller); } catch (Throwable e) { - s_logger.debug("failed to create template on storage", e); + logger.debug("failed to create template on storage", e); templateOnPrimaryStoreObj.processEvent(Event.OperationFailed); dataStore.create(template, deployAsIsConfiguration); // make sure that template_spool_ref entry is still present so that the second thread can acquire the lock VolumeApiResult result = new VolumeApiResult(volume); result.setResult(e.toString()); future.complete(result); } finally { - if (s_logger.isDebugEnabled()) { - s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId); + if (logger.isDebugEnabled()) { + logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId); } _tmpltPoolDao.releaseFromLockTable(templatePoolRefId); } @@ -809,7 +810,7 @@ protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject temp DataObject volumeOnPrimaryStorage = pd.create(volume, volume.getDeployAsIsConfiguration()); volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested); - CreateVolumeFromBaseImageContext context = new CreateVolumeFromBaseImageContext(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null, volume.getDeployAsIsConfiguration()); + CreateVolumeFromBaseImageContext context = new CreateVolumeFromBaseImageContext<>(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null, volume.getDeployAsIsConfiguration()); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null)); caller.setContext(context); @@ -838,14 +839,14 @@ protected Void createVolumeFromBaseImageCallBack(AsyncCallbackDispatcher details = new HashMap(); + Map details = new HashMap<>(); details.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString()); details.put(PrimaryDataStore.STORAGE_HOST, destPrimaryDataStore.getHostAddress()); details.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(destPrimaryDataStore.getPort())); @@ -1204,13 +1205,13 @@ private void createManagedVolumeCopyManagedTemplateAsync(VolumeInfo volumeInfo, } catch (StorageAccessException e) { throw e; } catch (Throwable e) { - s_logger.debug("Failed to copy managed template on primary storage", e); + logger.debug("Failed to copy managed template on primary storage", e); String errMsg = "Failed due to " + e.toString(); try { destroyAndReallocateManagedVolume(volumeInfo); } catch (CloudRuntimeException ex) { - s_logger.warn("Failed to destroy managed volume: " + volumeInfo.getId()); + logger.warn("Failed to destroy managed volume: " + volumeInfo.getId()); errMsg += " : " + ex.getMessage(); } @@ -1247,20 +1248,20 @@ private void destroyAndReallocateManagedVolume(VolumeInfo volumeInfo) { VolumeVO newVolume = (VolumeVO) newVol; newVolume.set_iScsiName(null); volDao.update(newVolume.getId(), newVolume); - s_logger.debug("Allocated new volume: " + newVolume.getId() + " for the VM: " + volume.getInstanceId()); + logger.debug("Allocated new volume: " + newVolume.getId() + " for the VM: " + volume.getInstanceId()); try { AsyncCallFuture expungeVolumeFuture = expungeVolumeAsync(volumeInfo); VolumeApiResult expungeVolumeResult = expungeVolumeFuture.get(); if (expungeVolumeResult.isFailed()) { - s_logger.warn("Failed to expunge volume: " + volumeInfo.getId() + " that was created"); + logger.warn("Failed to expunge volume: " + volumeInfo.getId() + " that was created"); throw new CloudRuntimeException("Failed to expunge volume: " + volumeInfo.getId() + " that was created"); } } catch (Exception ex) { if (canVolumeBeRemoved(volumeInfo.getId())) { volDao.remove(volumeInfo.getId()); } - s_logger.warn("Unable to expunge volume: " + volumeInfo.getId() + " due to: " + ex.getMessage()); + logger.warn("Unable to expunge volume: " + volumeInfo.getId() + " due to: " + ex.getMessage()); throw new CloudRuntimeException("Unable to expunge volume: " + volumeInfo.getId() + " due to: " + ex.getMessage()); } } @@ -1281,12 +1282,12 @@ private void createManagedVolumeCopyTemplateAsync(VolumeInfo volumeInfo, Primary // Refresh the volume info from the DB. volumeInfo = volFactory.getVolume(volumeInfo.getId(), primaryDataStore); - ManagedCreateBaseImageContext context = new ManagedCreateBaseImageContext(null, volumeInfo, primaryDataStore, srcTemplateInfo, future); + ManagedCreateBaseImageContext context = new ManagedCreateBaseImageContext<>(null, volumeInfo, primaryDataStore, srcTemplateInfo, future); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().managedCopyBaseImageCallback(null, null)).setContext(context); - Map details = new HashMap(); + Map details = new HashMap<>(); details.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString()); details.put(PrimaryDataStore.STORAGE_HOST, primaryDataStore.getHostAddress()); @@ -1367,7 +1368,7 @@ public TemplateInfo createManagedStorageTemplate(long srcTemplateId, long destDa int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); if (!lock.lock(storagePoolMaxWaitSeconds)) { - s_logger.debug("Unable to create managed storage template, couldn't lock on " + templateIdManagedPoolIdLockString); + logger.debug("Unable to create managed storage template, couldn't lock on " + templateIdManagedPoolIdLockString); throw new CloudRuntimeException("Unable to create managed storage template, couldn't lock on " + templateIdManagedPoolIdLockString); } @@ -1415,7 +1416,7 @@ public TemplateInfo createManagedStorageTemplate(long srcTemplateId, long destDa //Download and copy template to the managed volume TemplateInfo templateOnPrimaryNow = tmplFactory.getReadyBypassedTemplateOnManagedStorage(srcTemplateId, templateOnPrimary, destDataStoreId, destHostId); if (templateOnPrimaryNow == null) { - s_logger.debug("Failed to prepare ready bypassed template: " + srcTemplateId + " on primary storage: " + templateOnPrimary.getId()); + logger.debug("Failed to prepare ready bypassed template: " + srcTemplateId + " on primary storage: " + templateOnPrimary.getId()); throw new CloudRuntimeException("Failed to prepare ready bypassed template: " + srcTemplateId + " on primary storage: " + templateOnPrimary.getId()); } templateOnPrimary.processEvent(Event.OperationSuccessed); @@ -1428,7 +1429,7 @@ public TemplateInfo createManagedStorageTemplate(long srcTemplateId, long destDa } catch (StorageAccessException e) { throw e; } catch (Throwable e) { - s_logger.debug("Failed to create template on managed primary storage", e); + logger.debug("Failed to create template on managed primary storage", e); if (templateOnPrimary != null) { templateOnPrimary.processEvent(Event.OperationFailed); } @@ -1458,7 +1459,7 @@ public AsyncCallFuture createManagedStorageVolumeFromTemplateAs AsyncCallFuture future = new AsyncCallFuture<>(); if (storageCanCloneVolume && computeSupportsVolumeClone) { - s_logger.debug("Storage " + destDataStoreId + " can support cloning using a cached template and compute side is OK with volume cloning."); + logger.debug("Storage " + destDataStoreId + " can support cloning using a cached template and compute side is OK with volume cloning."); GlobalLock lock = null; TemplateInfo templateOnPrimary = null; @@ -1472,7 +1473,7 @@ public AsyncCallFuture createManagedStorageVolumeFromTemplateAs int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); if (!lock.lock(storagePoolMaxWaitSeconds)) { - s_logger.debug("Unable to create managed storage template/volume, couldn't lock on " + tmplIdManagedPoolIdLockString); + logger.debug("Unable to create managed storage template/volume, couldn't lock on " + tmplIdManagedPoolIdLockString); throw new CloudRuntimeException("Unable to create managed storage template/volume, couldn't lock on " + tmplIdManagedPoolIdLockString); } @@ -1504,7 +1505,7 @@ public AsyncCallFuture createManagedStorageVolumeFromTemplateAs result.setResult(e.getLocalizedMessage()); result.setSuccess(false); future.complete(result); - s_logger.warn("Failed to create template on primary storage", e); + logger.warn("Failed to create template on primary storage", e); return future; } finally { if (lock != null) { @@ -1515,7 +1516,7 @@ public AsyncCallFuture createManagedStorageVolumeFromTemplateAs if (destPrimaryDataStore.getPoolType() != StoragePoolType.PowerFlex) { // We have a template on primary storage. Clone it to new volume. - s_logger.debug("Creating a clone from template on primary storage " + destDataStoreId); + logger.debug("Creating a clone from template on primary storage " + destDataStoreId); createManagedVolumeCloneTemplateAsync(volumeInfo, templateOnPrimary, destPrimaryDataStore, future); } else { @@ -1524,7 +1525,7 @@ public AsyncCallFuture createManagedStorageVolumeFromTemplateAs destHost, future, destDataStoreId, srcTemplateInfo.getId()); } } else { - s_logger.debug("Primary storage does not support cloning or no support for UUID resigning on the host side; copying the template normally"); + logger.debug("Primary storage does not support cloning or no support for UUID resigning on the host side; copying the template normally"); createManagedVolumeCopyTemplateAsync(volumeInfo, destPrimaryDataStore, srcTemplateInfo, destHost, future); } @@ -1544,11 +1545,11 @@ private void createManagedVolumeCopyManagedTemplateAsyncWithLock(VolumeInfo volu int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); if (!lock.lock(storagePoolMaxWaitSeconds)) { - s_logger.debug("Unable to create volume from template, couldn't lock on " + tmplIdManagedPoolIdDestinationHostLockString); + logger.debug("Unable to create volume from template, couldn't lock on " + tmplIdManagedPoolIdDestinationHostLockString); throw new CloudRuntimeException("Unable to create volume from template, couldn't lock on " + tmplIdManagedPoolIdDestinationHostLockString); } - s_logger.debug("Copying the template to the volume on primary storage"); + logger.debug("Copying the template to the volume on primary storage"); createManagedVolumeCopyManagedTemplateAsync(volumeInfo, destPrimaryDataStore, templateOnPrimary, destHost, future); } finally { if (lock != null) { @@ -1636,26 +1637,25 @@ public void destroyVolume(long volumeId) { if (vol.getAttachedVM() == null || vol.getAttachedVM().getType() == VirtualMachine.Type.User) { // Decrement the resource count for volumes and primary storage belonging user VM's only - _resourceLimitMgr.decrementResourceCount(vol.getAccountId(), ResourceType.volume, vol.isDisplay()); - _resourceLimitMgr.decrementResourceCount(vol.getAccountId(), ResourceType.primary_storage, vol.isDisplay(), new Long(vol.getSize())); + _resourceLimitMgr.decrementVolumeResourceCount(vol.getAccountId(), vol.isDisplay(), vol.getSize(), diskOfferingDao.findById(vol.getDiskOfferingId())); } } @Override public AsyncCallFuture createVolumeFromSnapshot(VolumeInfo volume, DataStore store, SnapshotInfo snapshot) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); try { DataObject volumeOnStore = store.create(volume); volumeOnStore.processEvent(Event.CreateOnlyRequested); _volumeDetailsDao.addDetail(volume.getId(), SNAPSHOT_ID, Long.toString(snapshot.getId()), false); - CreateVolumeFromBaseImageContext context = new CreateVolumeFromBaseImageContext(null, volume, store, volumeOnStore, future, snapshot, null); + CreateVolumeFromBaseImageContext context = new CreateVolumeFromBaseImageContext<>(null, volume, store, volumeOnStore, future, snapshot, null); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().createVolumeFromSnapshotCallback(null, null)).setContext(context); motionSrv.copyAsync(snapshot, volumeOnStore, caller); } catch (Exception e) { - s_logger.debug("create volume from snapshot failed", e); + logger.debug("create volume from snapshot failed", e); VolumeApiResult result = new VolumeApiResult(volume); result.setResult(e.toString()); future.complete(result); @@ -1686,7 +1686,7 @@ protected Void createVolumeFromSnapshotCallback(AsyncCallbackDispatcher callback, AsyncCallFuture copyVolumeFromImageToPrimary(VolumeInfo srcVolume, DataStore destStore) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); VolumeApiResult res = new VolumeApiResult(srcVolume); VolumeInfo destVolume = null; try { @@ -1745,14 +1745,14 @@ protected AsyncCallFuture copyVolumeFromImageToPrimary(VolumeIn destVolume.processEvent(Event.CopyingRequested); srcVolume.processEvent(Event.CopyingRequested); - CopyVolumeContext context = new CopyVolumeContext(null, future, srcVolume, destVolume, destStore); + CopyVolumeContext context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().copyVolumeFromImageToPrimaryCallback(null, null)).setContext(context); motionSrv.copyAsync(srcVolume, destVolume, caller); return future; } catch (Exception e) { - s_logger.error("failed to copy volume from image store", e); + logger.error("failed to copy volume from image store", e); if (destVolume != null) { destVolume.processEvent(Event.OperationFailed); } @@ -1791,7 +1791,7 @@ protected Void copyVolumeFromImageToPrimaryCallback(AsyncCallbackDispatcher copyVolumeFromPrimaryToImage(VolumeInfo srcVolume, DataStore destStore) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); VolumeApiResult res = new VolumeApiResult(srcVolume); VolumeInfo destVolume = null; try { @@ -1799,14 +1799,14 @@ protected AsyncCallFuture copyVolumeFromPrimaryToImage(VolumeIn srcVolume.processEvent(Event.MigrationRequested); // this is just used for locking that src volume record in DB to avoid using lock destVolume.processEventOnly(Event.CreateOnlyRequested); - CopyVolumeContext context = new CopyVolumeContext(null, future, srcVolume, destVolume, destStore); + CopyVolumeContext context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().copyVolumeFromPrimaryToImageCallback(null, null)).setContext(context); motionSrv.copyAsync(srcVolume, destVolume, caller); return future; } catch (Exception e) { - s_logger.error("failed to copy volume to image store", e); + logger.error("failed to copy volume to image store", e); if (destVolume != null) { destVolume.getDataStore().delete(destVolume); } @@ -1844,7 +1844,7 @@ protected Void copyVolumeFromPrimaryToImageCallback(AsyncCallbackDispatcher copyVolume(VolumeInfo srcVolume, DataStore destStore) { DataStore srcStore = srcVolume.getDataStore(); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { String srcRole = (srcStore != null && srcStore.getRole() != null ? srcVolume.getDataStore().getRole().toString() : ""); String msg = String.format("copying %s(id=%d, role=%s) to %s (id=%d, role=%s)" @@ -1854,7 +1854,7 @@ public AsyncCallFuture copyVolume(VolumeInfo srcVolume, DataSto , destStore.getName() , destStore.getId() , destStore.getRole()); - s_logger.debug(msg); + logger.debug(msg); } if (srcVolume.getState() == Volume.State.Uploaded) { @@ -1872,11 +1872,11 @@ public AsyncCallFuture copyVolume(VolumeInfo srcVolume, DataSto // OfflineVmwareMigration: aren't we missing secondary to secondary in this logic? - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); VolumeApiResult res = new VolumeApiResult(srcVolume); try { if (!snapshotMgr.canOperateOnVolume(srcVolume)) { - s_logger.debug("There are snapshots creating on this volume, can not move this volume"); + logger.debug("There are snapshots creating on this volume, can not move this volume"); res.setResult("There are snapshots creating on this volume, can not move this volume"); future.complete(res); @@ -1888,14 +1888,14 @@ public AsyncCallFuture copyVolume(VolumeInfo srcVolume, DataSto destVolume.processEvent(Event.MigrationCopyRequested); srcVolume.processEvent(Event.MigrationRequested); - CopyVolumeContext context = new CopyVolumeContext(null, future, srcVolume, destVolume, destStore); + CopyVolumeContext context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().copyVolumeCallBack(null, null)).setContext(context); motionSrv.copyAsync(srcVolume, destVolume, caller); } catch (Exception e) { - s_logger.error("Failed to copy volume:" + e); - if(s_logger.isDebugEnabled()) { - s_logger.debug("Failed to copy volume.", e); + logger.error("Failed to copy volume:" + e); + if(logger.isDebugEnabled()) { + logger.debug("Failed to copy volume.", e); } res.setResult(e.toString()); future.complete(res); @@ -1916,7 +1916,7 @@ protected Void copyVolumeCallBack(AsyncCallbackDispatcher callback, AsyncCallFu } private AsyncCallFuture copyManagedVolume(VolumeInfo srcVolume, DataStore destStore) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); VolumeApiResult res = new VolumeApiResult(srcVolume); try { if (!snapshotMgr.canOperateOnVolume(srcVolume)) { - s_logger.debug("There are snapshots creating for this volume, can not move this volume"); + logger.debug("There are snapshots creating for this volume, can not move this volume"); res.setResult("There are snapshots creating for this volume, can not move this volume"); future.complete(res); return future; } if (snapshotMgr.backedUpSnapshotsExistsForVolume(srcVolume)) { - s_logger.debug("There are backed up snapshots for this volume, can not move."); + logger.debug("There are backed up snapshots for this volume, can not move."); res.setResult("[UNSUPPORTED] There are backed up snapshots for this volume, can not move. Please try again after removing them."); future.complete(res); return future; } - List poolIds = new ArrayList(); + List poolIds = new ArrayList<>(); poolIds.add(srcVolume.getPoolId()); poolIds.add(destStore.getId()); Host hostWithPoolsAccess = _storageMgr.findUpAndEnabledHostWithAccessToStoragePools(poolIds); if (hostWithPoolsAccess == null) { - s_logger.debug("No host(s) available with pool access, can not move this volume"); + logger.debug("No host(s) available with pool access, can not move this volume"); res.setResult("No host(s) available with pool access, can not move this volume"); future.complete(res); return future; @@ -2058,7 +2058,7 @@ private AsyncCallFuture copyManagedVolume(VolumeInfo srcVolume, AsyncCallFuture createVolumeFuture = createVolumeAsync(destVolume, destStore); VolumeApiResult createVolumeResult = createVolumeFuture.get(); if (createVolumeResult.isFailed()) { - s_logger.debug("Failed to create dest volume " + destVolume.getId() + ", volume can be removed"); + logger.debug("Failed to create dest volume " + destVolume.getId() + ", volume can be removed"); destroyVolume(destVolume.getId()); destVolume.processEvent(Event.ExpungeRequested); destVolume.processEvent(Event.OperationSuccessed); @@ -2071,7 +2071,7 @@ private AsyncCallFuture copyManagedVolume(VolumeInfo srcVolume, PrimaryDataStore srcPrimaryDataStore = (PrimaryDataStore) srcVolume.getDataStore(); if (srcPrimaryDataStore.isManaged()) { - Map srcPrimaryDataStoreDetails = new HashMap(); + Map srcPrimaryDataStoreDetails = new HashMap<>(); srcPrimaryDataStoreDetails.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString()); srcPrimaryDataStoreDetails.put(PrimaryDataStore.STORAGE_HOST, srcPrimaryDataStore.getHostAddress()); srcPrimaryDataStoreDetails.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(srcPrimaryDataStore.getPort())); @@ -2084,7 +2084,7 @@ private AsyncCallFuture copyManagedVolume(VolumeInfo srcVolume, } PrimaryDataStore destPrimaryDataStore = (PrimaryDataStore) destStore; - Map destPrimaryDataStoreDetails = new HashMap(); + Map destPrimaryDataStoreDetails = new HashMap<>(); destPrimaryDataStoreDetails.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString()); destPrimaryDataStoreDetails.put(PrimaryDataStore.STORAGE_HOST, destPrimaryDataStore.getHostAddress()); destPrimaryDataStoreDetails.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(destPrimaryDataStore.getPort())); @@ -2099,15 +2099,15 @@ private AsyncCallFuture copyManagedVolume(VolumeInfo srcVolume, destVolume.processEvent(Event.CreateRequested); srcVolume.processEvent(Event.MigrationRequested); - CopyManagedVolumeContext context = new CopyManagedVolumeContext(null, future, srcVolume, destVolume, hostWithPoolsAccess); + CopyManagedVolumeContext context = new CopyManagedVolumeContext<>(null, future, srcVolume, destVolume, hostWithPoolsAccess); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().copyManagedVolumeCallBack(null, null)).setContext(context); motionSrv.copyAsync(srcVolume, destVolume, hostWithPoolsAccess, caller); } catch (Exception e) { - s_logger.error("Copy to managed volume failed due to: " + e); - if(s_logger.isDebugEnabled()) { - s_logger.debug("Copy to managed volume failed.", e); + logger.error("Copy to managed volume failed due to: " + e); + if(logger.isDebugEnabled()) { + logger.debug("Copy to managed volume failed.", e); } res.setResult(e.toString()); future.complete(res); @@ -2147,7 +2147,7 @@ protected Void copyManagedVolumeCallBack(AsyncCallbackDispatcher callback, AsyncCallFuture @Override public AsyncCallFuture migrateVolume(VolumeInfo srcVolume, DataStore destStore) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); VolumeApiResult res = new VolumeApiResult(srcVolume); try { if (!snapshotMgr.canOperateOnVolume(srcVolume)) { - s_logger.debug("Snapshots are being created on this volume. This volume cannot be migrated now."); + logger.debug("Snapshots are being created on this volume. This volume cannot be migrated now."); res.setResult("Snapshots are being created on this volume. This volume cannot be migrated now."); future.complete(res); return future; @@ -2249,12 +2249,12 @@ public AsyncCallFuture migrateVolume(VolumeInfo srcVolume, Data VolumeInfo destVolume = volFactory.getVolume(srcVolume.getId(), destStore); srcVolume.processEvent(Event.MigrationRequested); - MigrateVolumeContext context = new MigrateVolumeContext(null, future, srcVolume, destVolume, destStore); + MigrateVolumeContext context = new MigrateVolumeContext<>(null, future, srcVolume, destVolume, destStore); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().migrateVolumeCallBack(null, null)).setContext(context); motionSrv.copyAsync(srcVolume, destVolume, caller); } catch (Exception e) { - s_logger.debug("Failed to migrate volume", e); + logger.debug("Failed to migrate volume", e); res.setResult(e.toString()); future.complete(res); } @@ -2281,7 +2281,7 @@ protected Void migrateVolumeCallBack(AsyncCallbackDispatcher callback, AsyncCal @Override public AsyncCallFuture migrateVolumes(Map volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); CommandResult res = new CommandResult(); try { // Check to make sure there are no snapshot operations on a volume // and // put it in the migrating state. - List volumesMigrating = new ArrayList(); + List volumesMigrating = new ArrayList<>(); for (Map.Entry entry : volumeMap.entrySet()) { VolumeInfo volume = entry.getKey(); if (!snapshotMgr.canOperateOnVolume(volume)) { - s_logger.debug("Snapshots are being created on a volume. Volumes cannot be migrated now."); + logger.debug("Snapshots are being created on a volume. Volumes cannot be migrated now."); res.setResult("Snapshots are being created on a volume. Volumes cannot be migrated now."); future.complete(res); @@ -2328,13 +2328,13 @@ public AsyncCallFuture migrateVolumes(Map } } - MigrateVmWithVolumesContext context = new MigrateVmWithVolumesContext(null, future, volumeMap); + MigrateVmWithVolumesContext context = new MigrateVmWithVolumesContext<>(null, future, volumeMap); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().migrateVmWithVolumesCallBack(null, null)).setContext(context); motionSrv.copyAsync(volumeMap, vmTo, srcHost, destHost, caller); } catch (Exception e) { - s_logger.debug("Failed to copy volume", e); + logger.debug("Failed to copy volume", e); res.setResult(e.toString()); future.complete(res); } @@ -2364,7 +2364,7 @@ protected Void migrateVmWithVolumesCallBack(AsyncCallbackDispatcher registerVolume(VolumeInfo volume, DataStore store) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); DataObject volumeOnStore = store.create(volume); volumeOnStore.processEvent(Event.CreateOnlyRequested); try { - CreateVolumeContext context = new CreateVolumeContext(null, volumeOnStore, future); + CreateVolumeContext context = new CreateVolumeContext<>(null, volumeOnStore, future); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().registerVolumeCallback(null, null)); caller.setContext(context); @@ -2407,7 +2407,7 @@ public Pair registerVolumeForPostUpload(VolumeInfo volume, EndPoint ep = _epSelector.select(store); if (ep == null) { String errorMessage = "There is no secondary storage VM for image store " + store.getName(); - s_logger.warn(errorMessage); + logger.warn(errorMessage); throw new CloudRuntimeException(errorMessage); } DataObject volumeOnStore = store.create(volume); @@ -2438,7 +2438,7 @@ protected Void registerVolumeCallback(AsyncCallbackDispatcher resize(VolumeInfo volume) { - AsyncCallFuture future = new AsyncCallFuture(); + AsyncCallFuture future = new AsyncCallFuture<>(); VolumeApiResult result = new VolumeApiResult(volume); try { volume.processEvent(Event.ResizeRequested); } catch (Exception e) { - s_logger.debug("Failed to change state to resize", e); + logger.debug("Failed to change state to resize", e); result.setResult(e.toString()); future.complete(result); return future; } - CreateVolumeContext context = new CreateVolumeContext(null, volume, future); + CreateVolumeContext context = new CreateVolumeContext<>(null, volume, future); AsyncCallbackDispatcher caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().resizeVolumeCallback(caller, context)).setContext(context); try { volume.getDataStore().getDriver().resize(volume, caller); } catch (Exception e) { - s_logger.debug("Failed to change state to resize", e); + logger.debug("Failed to change state to resize", e); result.setResult(e.toString()); @@ -2540,7 +2540,7 @@ protected Void resizeVolumeCallback(AsyncCallbackDispatcher dbVolumes = _volumeStoreDao.listByStoreId(storeId); - List toBeDownloaded = new ArrayList(dbVolumes); + List toBeDownloaded = new ArrayList<>(dbVolumes); for (VolumeDataStoreVO volumeStore : dbVolumes) { VolumeVO volume = volDao.findById(volumeStore.getVolumeId()); if (volume == null) { - s_logger.warn("Volume_store_ref table shows that volume " + volumeStore.getVolumeId() + " is on image store " + storeId + logger.warn("Volume_store_ref table shows that volume " + volumeStore.getVolumeId() + " is on image store " + storeId + ", but the volume is not found in volumes table, potentially some bugs in deleteVolume, so we just treat this volume to be deleted and mark it as destroyed"); volumeStore.setDestroyed(true); _volumeStoreDao.update(volumeStore.getId(), volumeStore); @@ -2599,7 +2599,7 @@ public void handleVolumeSync(DataStore store) { if (volumeInfos.containsKey(volume.getId())) { TemplateProp volInfo = volumeInfos.remove(volume.getId()); toBeDownloaded.remove(volumeStore); - s_logger.info("Volume Sync found " + volume.getUuid() + " already in the volume image store table"); + logger.info("Volume Sync found " + volume.getUuid() + " already in the volume image store table"); if (volumeStore.getDownloadState() != Status.DOWNLOADED) { volumeStore.setErrorString(""); } @@ -2607,9 +2607,9 @@ public void handleVolumeSync(DataStore store) { volumeStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Volume " + volume.getUuid() + " is corrupted on image store"; volumeStore.setErrorString(msg); - s_logger.info(msg); + logger.info(msg); if (volume.getState() == State.NotUploaded || volume.getState() == State.UploadInProgress) { - s_logger.info("Volume Sync found " + volume.getUuid() + " uploaded using SSVM on image store " + storeId + " as corrupted, marking it as failed"); + logger.info("Volume Sync found " + volume.getUuid() + " uploaded using SSVM on image store " + storeId + " as corrupted, marking it as failed"); _volumeStoreDao.update(volumeStore.getId(), volumeStore); // mark volume as failed, so that storage GC will clean it up VolumeObject volObj = (VolumeObject)volFactory.getVolume(volume.getId()); @@ -2617,9 +2617,9 @@ public void handleVolumeSync(DataStore store) { } else if (volumeStore.getDownloadUrl() == null) { msg = "Volume (" + volume.getUuid() + ") with install path " + volInfo.getInstallPath() + " is corrupted, please check in image store: " + volumeStore.getDataStoreId(); - s_logger.warn(msg); + logger.warn(msg); } else { - s_logger.info("Removing volume_store_ref entry for corrupted volume " + volume.getName()); + logger.info("Removing volume_store_ref entry for corrupted volume " + volume.getName()); _volumeStoreDao.remove(volumeStore.getId()); toBeDownloaded.add(volumeStore); } @@ -2649,7 +2649,7 @@ public void handleVolumeSync(DataStore store) { _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(volume.getAccountId()), com.cloud.configuration.Resource.ResourceType.secondary_storage, volInfo.getSize() - volInfo.getPhysicalSize()); } catch (ResourceAllocationException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED, volume.getDataCenterId(), volume.getPodId(), e.getMessage(), e.getMessage()); } finally { _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), @@ -2659,7 +2659,7 @@ public void handleVolumeSync(DataStore store) { } continue; } else if (volume.getState() == State.NotUploaded || volume.getState() == State.UploadInProgress) { // failed uploads through SSVM - s_logger.info("Volume Sync did not find " + volume.getUuid() + " uploaded using SSVM on image store " + storeId + ", marking it as failed"); + logger.info("Volume Sync did not find " + volume.getUuid() + " uploaded using SSVM on image store " + storeId + ", marking it as failed"); toBeDownloaded.remove(volumeStore); volumeStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Volume " + volume.getUuid() + " is corrupted on image store"; @@ -2672,7 +2672,7 @@ public void handleVolumeSync(DataStore store) { } // Volume is not on secondary but we should download. if (volumeStore.getDownloadState() != Status.DOWNLOADED) { - s_logger.info("Volume Sync did not find " + volume.getName() + " ready on image store " + storeId + ", will request download to start/resume shortly"); + logger.info("Volume Sync did not find " + volume.getName() + " ready on image store " + storeId + ", will request download to start/resume shortly"); } } @@ -2680,7 +2680,7 @@ public void handleVolumeSync(DataStore store) { if (toBeDownloaded.size() > 0) { for (VolumeDataStoreVO volumeHost : toBeDownloaded) { if (volumeHost.getDownloadUrl() == null) { // If url is null, skip downloading - s_logger.info("Skip downloading volume " + volumeHost.getVolumeId() + " since no download url is specified."); + logger.info("Skip downloading volume " + volumeHost.getVolumeId() + " since no download url is specified."); continue; } @@ -2688,12 +2688,12 @@ public void handleVolumeSync(DataStore store) { // means that this is a duplicate entry from migration of previous NFS to staging. if (store.getScope().getScopeType() == ScopeType.REGION) { if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && volumeHost.getInstallPath() == null) { - s_logger.info("Skip sync volume for migration of previous NFS to object store"); + logger.info("Skip sync volume for migration of previous NFS to object store"); continue; } } - s_logger.debug("Volume " + volumeHost.getVolumeId() + " needs to be downloaded to " + store.getName()); + logger.debug("Volume " + volumeHost.getVolumeId() + " needs to be downloaded to " + store.getName()); // reset volume status back to Allocated VolumeObject vol = (VolumeObject)volFactory.getVolume(volumeHost.getVolumeId()); vol.processEvent(Event.OperationFailed); // reset back volume status @@ -2722,24 +2722,24 @@ public void handleVolumeSync(DataStore store) { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(dtCommand, false, errMsg); } else { answer = ep.sendMessage(dtCommand); } if (answer == null || !answer.getResult()) { - s_logger.info("Failed to deleted volume at store: " + store.getName()); + logger.info("Failed to deleted volume at store: " + store.getName()); } else { String description = "Deleted volume " + tInfo.getTemplateName() + " on secondary storage " + storeId; - s_logger.info(description); + logger.info(description); } } } finally { syncLock.unlock(); } } else { - s_logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing volume sync on data store " + storeId + " now."); + logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing volume sync on data store " + storeId + " now."); } } finally { syncLock.releaseRef(); @@ -2752,7 +2752,7 @@ private Map listVolume(DataStore store) { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -2761,8 +2761,8 @@ private Map listVolume(DataStore store) { ListVolumeAnswer tanswer = (ListVolumeAnswer)answer; return tanswer.getTemplateInfo(); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Can not list volumes for image store " + store.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Can not list volumes for image store " + store.getId()); } } @@ -2775,11 +2775,11 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) { try { snapshot = snapshotMgr.takeSnapshot(volume); } catch (CloudRuntimeException cre) { - s_logger.error("Take snapshot: " + volume.getId() + " failed", cre); + logger.error("Take snapshot: " + volume.getId() + " failed", cre); throw cre; } catch (Exception e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("unknown exception while taking snapshot for volume " + volume.getId() + " was caught", e); + if (logger.isDebugEnabled()) { + logger.debug("unknown exception while taking snapshot for volume " + volume.getId() + " was caught", e); } throw new CloudRuntimeException("Failed to take snapshot", e); } @@ -2792,7 +2792,7 @@ public void checkAndRepairVolumeBasedOnConfig(DataObject dataObject, Host host) if (HypervisorType.KVM.equals(host.getHypervisorType()) && DataObjectType.VOLUME.equals(dataObject.getType())) { VolumeInfo volumeInfo = volFactory.getVolume(dataObject.getId()); if (VolumeApiServiceImpl.AllowCheckAndRepairVolume.valueIn(volumeInfo.getPoolId())) { - s_logger.info(String.format("Trying to check and repair the volume %d", dataObject.getId())); + logger.info(String.format("Trying to check and repair the volume %d", dataObject.getId())); String repair = CheckAndRepairVolumeCmd.RepairValues.LEAKS.name().toLowerCase(); CheckAndRepairVolumePayload payload = new CheckAndRepairVolumePayload(repair); volumeInfo.addPayload(payload); @@ -2836,15 +2836,15 @@ private Pair checkAndRepairVolumeThroughHost(VolumeInfo volume, grantAccess(volume, host, volume.getDataStore()); CheckAndRepairVolumeAnswer answer = (CheckAndRepairVolumeAnswer) _storageMgr.sendToPool(pool, new long[]{host.getId()}, command); if (answer != null && answer.getResult()) { - s_logger.debug(String.format("Check volume response result: %s", answer.getDetails())); + logger.debug(String.format("Check volume response result: %s", answer.getDetails())); return new Pair<>(answer.getVolumeCheckExecutionResult(), answer.getVolumeRepairExecutionResult()); } else { String errMsg = (answer == null) ? null : answer.getDetails(); - s_logger.debug(String.format("Failed to check and repair the volume with error %s", errMsg)); + logger.debug(String.format("Failed to check and repair the volume with error %s", errMsg)); } } catch (Exception e) { - s_logger.debug("sending check and repair volume command failed", e); + logger.debug("sending check and repair volume command failed", e); } finally { revokeAccess(volume, host, volume.getDataStore()); command.clearPassphrase(); @@ -2900,10 +2900,10 @@ public void moveVolumeOnSecondaryStorageToAnotherAccount(Volume volume, Account VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId()); if (volumeStore == null) { - s_logger.debug(String.format("Volume [%s] is not present in the secondary storage. Therefore we do not need to move it in the secondary storage.", volume)); + logger.debug(String.format("Volume [%s] is not present in the secondary storage. Therefore we do not need to move it in the secondary storage.", volume)); return; } - s_logger.debug(String.format("Volume [%s] is present in secondary storage. It will be necessary to move it from the source account's [%s] folder to the destination " + logger.debug(String.format("Volume [%s] is present in secondary storage. It will be necessary to move it from the source account's [%s] folder to the destination " + "account's [%s] folder.", volume.getUuid(), sourceAccount, destAccount)); @@ -2922,17 +2922,17 @@ public void moveVolumeOnSecondaryStorageToAnotherAccount(Volume volume, Account String msg = String.format("Unable to move volume [%s] from [%s] (source account's [%s] folder) to [%s] (destination account's [%s] folder) in the secondary storage, due " + "to [%s].", volume.getUuid(), srcPath.getParent(), sourceAccount, destPath, destAccount, answer.getDetails()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } - s_logger.debug(String.format("Volume [%s] was moved from [%s] (source account's [%s] folder) to [%s] (destination account's [%s] folder) in the secondary storage.", + logger.debug(String.format("Volume [%s] was moved from [%s] (source account's [%s] folder) to [%s] (destination account's [%s] folder) in the secondary storage.", volume.getUuid(), srcPath.getParent(), sourceAccount, destPath, destAccount)); volumeStore.setInstallPath(String.format("%s/%s", destPath, srcPath.getFileName().toString())); if (!_volumeStoreDao.update(volumeStore.getId(), volumeStore)) { String msg = String.format("Unable to update volume [%s] install path in the DB.", volumeStore.getVolumeId()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } diff --git a/engine/storage/volume/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-volume-core-context.xml b/engine/storage/volume/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-volume-core-context.xml index a0cb6a78e918..57cb7f191fff 100644 --- a/engine/storage/volume/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-volume-core-context.xml +++ b/engine/storage/volume/src/main/resources/META-INF/cloudstack/core/spring-engine-storage-volume-core-context.xml @@ -45,5 +45,5 @@ - + diff --git a/engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceTest.java b/engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceTest.java index 97ccc37be135..c4241dfbc3a1 100644 --- a/engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceTest.java +++ b/engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceTest.java @@ -28,19 +28,20 @@ import com.cloud.host.dao.HostDao; import com.cloud.storage.CheckAndRepairVolumePayload; import com.cloud.storage.DiskOfferingVO; +import com.cloud.storage.Storage; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePool; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.snapshot.SnapshotManager; +import com.cloud.utils.Pair; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; -import com.cloud.utils.Pair; -import junit.framework.TestCase; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; @@ -55,6 +56,8 @@ import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import junit.framework.TestCase; + @RunWith(MockitoJUnitRunner.class) public class VolumeServiceTest extends TestCase{ @@ -214,7 +217,9 @@ public void validateDestroySourceVolumeAfterMigrationReturnTrue() throws Executi public void validateDestroySourceVolumeAfterMigrationExpungeSourceVolumeAfterMigrationThrowExceptionReturnFalse() throws ExecutionException, InterruptedException{ VolumeObject volumeObject = new VolumeObject(); - volumeObject.configure(null, new VolumeVO() {}); + VolumeVO vo = new VolumeVO() {}; + vo.setPoolType(Storage.StoragePoolType.Filesystem); + volumeObject.configure(null, vo); List exceptions = new ArrayList<>(Arrays.asList(new InterruptedException(), new ExecutionException() {})); diff --git a/engine/storage/volume/src/test/resource/testContext.xml b/engine/storage/volume/src/test/resource/testContext.xml index 7352b1148f78..c168582bab80 100644 --- a/engine/storage/volume/src/test/resource/testContext.xml +++ b/engine/storage/volume/src/test/resource/testContext.xml @@ -22,7 +22,7 @@ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd @@ -38,7 +38,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -58,7 +58,7 @@ - + @@ -68,12 +68,12 @@ - + - + diff --git a/engine/userdata/cloud-init/pom.xml b/engine/userdata/cloud-init/pom.xml index 8a86ef6ae3a5..d4396ba382a7 100644 --- a/engine/userdata/cloud-init/pom.xml +++ b/engine/userdata/cloud-init/pom.xml @@ -23,7 +23,7 @@ cloud-engine org.apache.cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/userdata/cloud-init/src/main/java/org/apache/cloudstack/userdata/CloudInitUserDataProvider.java b/engine/userdata/cloud-init/src/main/java/org/apache/cloudstack/userdata/CloudInitUserDataProvider.java index feca8712a7d3..02e6adcc784b 100644 --- a/engine/userdata/cloud-init/src/main/java/org/apache/cloudstack/userdata/CloudInitUserDataProvider.java +++ b/engine/userdata/cloud-init/src/main/java/org/apache/cloudstack/userdata/CloudInitUserDataProvider.java @@ -38,7 +38,6 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.exception.CloudRuntimeException; @@ -62,8 +61,6 @@ protected enum FormatType { Map.entry(FormatType.INCLUDE_FILE, INCLUDE_FILE_CONTENT_TYPE) ); - private static final Logger LOGGER = Logger.getLogger(CloudInitUserDataProvider.class); - private static final Session session = Session.getDefaultInstance(new Properties()); @Override @@ -88,7 +85,7 @@ protected String extractUserDataHeader(String userdata) { .filter(x -> (x.startsWith("#") && !x.startsWith("##")) || (x.startsWith("Content-Type:"))) .collect(Collectors.toList()); if (CollectionUtils.isEmpty(lines)) { - LOGGER.debug("Failed to detect the user data format type as it does not contain a header"); + logger.debug("Failed to detect the user data format type as it does not contain a header"); return null; } return lines.get(0); @@ -99,7 +96,7 @@ protected FormatType mapUserDataHeaderToFormatType(String header, FormatType def if (defaultFormatType == null) { throw new CloudRuntimeException("Failed to detect the user data format type as it does not contain a header"); } - LOGGER.debug(String.format("Empty header for userdata, using the default format type: %s", defaultFormatType.name())); + logger.debug(String.format("Empty header for userdata, using the default format type: %s", defaultFormatType.name())); return defaultFormatType; } else if (header.equalsIgnoreCase("#cloud-config")) { return FormatType.CLOUD_CONFIG; @@ -114,7 +111,7 @@ protected FormatType mapUserDataHeaderToFormatType(String header, FormatType def } else { String msg = String.format("Cannot recognise the user data format type from the header line: %s." + "Supported types are: cloud-config, bash script, cloud-boothook, include file or MIME", header); - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } @@ -128,7 +125,7 @@ protected FormatType mapUserDataHeaderToFormatType(String header, FormatType def protected FormatType getUserDataFormatType(String userdata, FormatType defaultFormatType) { if (StringUtils.isBlank(userdata)) { String msg = "User data expected but provided empty user data"; - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -273,7 +270,7 @@ public String appendUserData(String encodedUserData1, String encodedUserData2) { } catch (MessagingException | IOException | CloudRuntimeException e) { String msg = String.format("Error attempting to merge user data as a multipart user data. " + "Reason: %s", e.getMessage()); - LOGGER.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg, e); } } diff --git a/engine/userdata/pom.xml b/engine/userdata/pom.xml index 7a3c38f0e0b9..038aa18f2909 100644 --- a/engine/userdata/pom.xml +++ b/engine/userdata/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/engine/userdata/src/main/java/org/apache/cloudstack/userdata/UserDataManagerImpl.java b/engine/userdata/src/main/java/org/apache/cloudstack/userdata/UserDataManagerImpl.java index 81a77fa5c0b7..664d308e28d1 100644 --- a/engine/userdata/src/main/java/org/apache/cloudstack/userdata/UserDataManagerImpl.java +++ b/engine/userdata/src/main/java/org/apache/cloudstack/userdata/UserDataManagerImpl.java @@ -26,14 +26,12 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.exception.CloudRuntimeException; public class UserDataManagerImpl extends ManagerBase implements UserDataManager { - private static final Logger s_logger = Logger.getLogger(UserDataManagerImpl.class); private static final int MAX_USER_DATA_LENGTH_BYTES = 2048; private static final int MAX_HTTP_GET_LENGTH = 2 * MAX_USER_DATA_LENGTH_BYTES; // 4KB private static final int NUM_OF_2K_BLOCKS = 512; @@ -89,9 +87,9 @@ public String concatenateUserData(String userdata1, String userdata2, String use @Override public String validateUserData(String userData, BaseCmd.HTTPMethod httpmethod) { - s_logger.trace(String.format("Validating base64 encoded user data: [%s].", userData)); + logger.trace(String.format("Validating base64 encoded user data: [%s].", userData)); if (StringUtils.isBlank(userData)) { - s_logger.debug("Null/empty base64 encoded user data set"); + logger.debug("Null/empty base64 encoded user data set"); return null; } @@ -126,17 +124,17 @@ private byte[] validateAndDecodeByHTTPMethod(String userData, int maxHTTPLength, throw new InvalidParameterValueException("User data is too short."); } - s_logger.trace(String.format("Decoded user data: [%s].", decodedUserData)); + logger.trace(String.format("Decoded user data: [%s].", decodedUserData)); int userDataLength = userData.length(); int decodedUserDataLength = decodedUserData.length; - s_logger.info(String.format("Configured base64 encoded user data size: %d bytes, actual user data size: %d bytes", userDataLength, decodedUserDataLength)); + logger.info(String.format("Configured base64 encoded user data size: %d bytes, actual user data size: %d bytes", userDataLength, decodedUserDataLength)); if (userDataLength > maxHTTPLength) { - s_logger.warn(String.format("Base64 encoded user data (size: %d bytes) too long for http %s request (accepted size: %d bytes)", userDataLength, httpMethod.toString(), maxHTTPLength)); + logger.warn(String.format("Base64 encoded user data (size: %d bytes) too long for http %s request (accepted size: %d bytes)", userDataLength, httpMethod.toString(), maxHTTPLength)); throw new InvalidParameterValueException(String.format("User data is too long for http %s request", httpMethod.toString())); } if (userDataLength > VM_USERDATA_MAX_LENGTH.value()) { - s_logger.warn(String.format("Base64 encoded user data (size: %d bytes) has exceeded configurable max length of %d bytes", userDataLength, VM_USERDATA_MAX_LENGTH.value())); + logger.warn(String.format("Base64 encoded user data (size: %d bytes) has exceeded configurable max length of %d bytes", userDataLength, VM_USERDATA_MAX_LENGTH.value())); throw new InvalidParameterValueException("User data has exceeded configurable max length: " + VM_USERDATA_MAX_LENGTH.value()); } diff --git a/engine/userdata/src/main/resources/META-INF/cloudstack/core/spring-engine-userdata-core-context.xml b/engine/userdata/src/main/resources/META-INF/cloudstack/core/spring-engine-userdata-core-context.xml index 0d4c6474be1e..b3a587ee594b 100644 --- a/engine/userdata/src/main/resources/META-INF/cloudstack/core/spring-engine-userdata-core-context.xml +++ b/engine/userdata/src/main/resources/META-INF/cloudstack/core/spring-engine-userdata-core-context.xml @@ -30,5 +30,5 @@ - + diff --git a/framework/agent-lb/pom.xml b/framework/agent-lb/pom.xml index 306a17fef75f..50e0bd47b90e 100644 --- a/framework/agent-lb/pom.xml +++ b/framework/agent-lb/pom.xml @@ -24,7 +24,7 @@ cloudstack-framework org.apache.cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/ca/pom.xml b/framework/ca/pom.xml index a12e2895db60..d82389cd0081 100644 --- a/framework/ca/pom.xml +++ b/framework/ca/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/cluster/pom.xml b/framework/cluster/pom.xml index 00be11753844..ef511584ae65 100644 --- a/framework/cluster/pom.xml +++ b/framework/cluster/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterFenceManagerImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterFenceManagerImpl.java index 4f5e0344e73b..203ebe6e3d45 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterFenceManagerImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterFenceManagerImpl.java @@ -23,14 +23,12 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.management.ManagementServerHost; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.component.ManagerBase; @Component public class ClusterFenceManagerImpl extends ManagerBase implements ClusterFenceManager, ClusterManagerListener { - private static final Logger s_logger = Logger.getLogger(ClusterFenceManagerImpl.class); @Inject ClusterManager _clusterMgr; @@ -51,7 +49,7 @@ public void onManagementNodeLeft(List nodeList, @Override public void onManagementNodeIsolated() { - s_logger.error("Received node isolation notification, will perform self-fencing and shut myself down"); + logger.error("Received node isolation notification, will perform self-fencing and shut myself down"); System.exit(SELF_FENCING_EXIT_CODE); } } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java index d601c094ca76..32fdf782696f 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java @@ -46,7 +46,6 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.management.ManagementServerHost; import org.apache.cloudstack.utils.identity.ManagementServerNode; -import org.apache.log4j.Logger; import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.cluster.dao.ManagementServerHostPeerDao; @@ -70,7 +69,6 @@ import com.cloud.utils.net.NetUtils; public class ClusterManagerImpl extends ManagerBase implements ClusterManager, Configurable { - private static final Logger s_logger = Logger.getLogger(ClusterManagerImpl.class); private static final int EXECUTOR_SHUTDOWN_TIMEOUT = 1000; // 1 second private static final int DEFAULT_OUTGOING_WORKERS = 5; @@ -176,7 +174,7 @@ private void cancelClusterRequestToPeer(final String strPeer) { } for (final ClusterServiceRequestPdu pdu : candidates) { - s_logger.warn("Cancel cluster request PDU to peer: " + strPeer + ", pdu: " + pdu.getJsonPackage()); + logger.warn("Cancel cluster request PDU to peer: " + strPeer + ", pdu: " + pdu.getJsonPackage()); synchronized (pdu) { pdu.notifyAll(); } @@ -260,13 +258,13 @@ private void onSendingClusterPdu() { try { peerService = getPeerService(pdu.getDestPeer()); } catch (final RemoteException e) { - s_logger.error("Unable to get cluster service on peer : " + pdu.getDestPeer()); + logger.error("Unable to get cluster service on peer : " + pdu.getDestPeer()); } if (peerService != null) { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + ". agent: " + pdu.getAgentId() + ", pdu seq: " + + if (logger.isDebugEnabled()) { + logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + ". agent: " + pdu.getAgentId() + ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage()); } @@ -276,8 +274,8 @@ private void onSendingClusterPdu() { final String strResult = peerService.execute(pdu); profiler.stop(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + " completed. time: " + + if (logger.isDebugEnabled()) { + logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + " completed. time: " + profiler.getDurationInMillis() + "ms. agent: " + pdu.getAgentId() + ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage()); } @@ -288,15 +286,15 @@ private void onSendingClusterPdu() { } catch (final RemoteException e) { invalidatePeerService(pdu.getDestPeer()); - if (s_logger.isInfoEnabled()) { - s_logger.info("Exception on remote execution, peer: " + pdu.getDestPeer() + ", iteration: " + i + ", exception message :" + + if (logger.isInfoEnabled()) { + logger.info("Exception on remote execution, peer: " + pdu.getDestPeer() + ", iteration: " + i + ", exception message :" + e.getMessage()); } } } } } catch (final Throwable e) { - s_logger.error("Unexcpeted exception: ", e); + logger.error("Unexpected exception: ", e); } } } @@ -320,11 +318,11 @@ protected void runInContext() { requestPdu.notifyAll(); } } else { - s_logger.warn("Original request has already been cancelled. pdu: " + pdu.getJsonPackage()); + logger.warn("Original request has already been cancelled. pdu: " + pdu.getJsonPackage()); } } else if (pdu.getPduType() == ClusterServicePdu.PDU_TYPE_STATUS_UPDATE) { if (statusAdministrator == null) { - s_logger.warn("No status administration to report a status update too."); + logger.warn("No status administration to report a status update too."); } else { statusAdministrator.newStatus(pdu); } @@ -348,7 +346,7 @@ protected void runInContext() { } }); } catch (final Throwable e) { - s_logger.error("Unexcpeted exception: ", e); + logger.error("Unexpected exception: ", e); } } } @@ -381,12 +379,12 @@ public void broadcast(final long agentId, final String cmds) { continue; // Skip myself. } try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Forwarding " + cmds + " to " + peer.getMsid()); + if (logger.isDebugEnabled()) { + logger.debug("Forwarding " + cmds + " to " + peer.getMsid()); } executeAsync(peerName, agentId, cmds, true); } catch (final Exception e) { - s_logger.warn("Caught exception while talkign to " + peer.getMsid()); + logger.warn("Caught exception while talking to " + peer.getMsid()); } } } @@ -409,14 +407,14 @@ public void publishStatus(final String status) { for (final ManagementServerHostVO peer : peers) { final String peerName = Long.toString(peer.getMsid()); try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Forwarding " + status + " to " + peer.getMsid()); + if (logger.isDebugEnabled()) { + logger.debug("Forwarding " + status + " to " + peer.getMsid()); } sendStatus(peerName, status); } catch (final Exception e) { String msg = String.format("Caught exception while talking to %d", peer.getMsid()); - s_logger.warn(msg); - s_logger.debug(msg, e); + logger.warn(msg); + logger.debug(msg, e); } } } @@ -434,8 +432,8 @@ public void sendStatus(final String strPeer, final String status) { @Override public String execute(final String strPeer, final long agentId, final String cmds, final boolean stopOnError) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " " + cmds); + if (logger.isDebugEnabled()) { + logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " " + cmds); } final ClusterServiceRequestPdu pdu = new ClusterServiceRequestPdu(); @@ -454,8 +452,8 @@ public String execute(final String strPeer, final long agentId, final String cmd } } - if (s_logger.isDebugEnabled()) { - s_logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " completed. result: " + pdu.getResponseResult()); + if (logger.isDebugEnabled()) { + logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " completed. result: " + pdu.getResponseResult()); } if (pdu.getResponseResult() != null && pdu.getResponseResult().length() > 0) { @@ -485,7 +483,7 @@ public void registerListener(final ClusterManagerListener listener) { // Note : we don't check duplicates synchronized (_listeners) { - s_logger.info("register cluster listener " + listener.getClass()); + logger.info("register cluster listener " + listener.getClass()); _listeners.add(listener); } @@ -494,18 +492,18 @@ public void registerListener(final ClusterManagerListener listener) { @Override public void unregisterListener(final ClusterManagerListener listener) { synchronized (_listeners) { - s_logger.info("unregister cluster listener " + listener.getClass()); + logger.info("unregister cluster listener " + listener.getClass()); _listeners.remove(listener); } } public void notifyNodeJoined(final List nodeList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notify management server node join to listeners."); + if (logger.isDebugEnabled()) { + logger.debug("Notify management server node join to listeners."); for (final ManagementServerHostVO mshost : nodeList) { - s_logger.debug("Joining node, IP: " + mshost.getServiceIP() + ", msid: " + mshost.getMsid()); + logger.debug("Joining node, IP: " + mshost.getServiceIP() + ", msid: " + mshost.getMsid()); } } @@ -519,13 +517,13 @@ public void notifyNodeJoined(final List nodeList) { } public void notifyNodeLeft(final List nodeList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notify management server node left to listeners."); + if (logger.isDebugEnabled()) { + logger.debug("Notify management server node left to listeners."); } for (final ManagementServerHostVO mshost : nodeList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Leaving node, IP: " + mshost.getServiceIP() + ", msid: " + mshost.getMsid()); + if (logger.isDebugEnabled()) { + logger.debug("Leaving node, IP: " + mshost.getServiceIP() + ", msid: " + mshost.getMsid()); } cancelClusterRequestToPeer(String.valueOf(mshost.getMsid())); } @@ -540,8 +538,8 @@ public void notifyNodeLeft(final List nodeList) { } public void notifyNodeIsolated() { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notify management server node isolation to listeners"); + if (logger.isDebugEnabled()) { + logger.debug("Notify management server node isolation to listeners"); } synchronized (_listeners) { @@ -596,16 +594,16 @@ protected void runInContext() { profilerHeartbeatUpdate.start(); txn.transitToAutoManagedConnection(TransactionLegacy.CLOUD_DB); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Cluster manager heartbeat update, id:" + _mshostId); + if (logger.isTraceEnabled()) { + logger.trace("Cluster manager heartbeat update, id:" + _mshostId); } _mshostDao.update(_mshostId, _runId, DateUtil.currentGMTTime()); profilerHeartbeatUpdate.stop(); profilerPeerScan.start(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Cluster manager peer-scan, id:" + _mshostId); + if (logger.isTraceEnabled()) { + logger.trace("Cluster manager peer-scan, id:" + _mshostId); } if (!_peerScanInited) { @@ -620,18 +618,18 @@ protected void runInContext() { profiler.stop(); if (profiler.getDurationInMillis() >= HeartbeatInterval.value()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Management server heartbeat takes too long to finish. profiler: " + profiler.toString() + ", profilerHeartbeatUpdate: " + + if (logger.isDebugEnabled()) { + logger.debug("Management server heartbeat takes too long to finish. profiler: " + profiler.toString() + ", profilerHeartbeatUpdate: " + profilerHeartbeatUpdate.toString() + ", profilerPeerScan: " + profilerPeerScan.toString()); } } } } catch (final CloudRuntimeException e) { - s_logger.error("Runtime DB exception ", e.getCause()); + logger.error("Runtime DB exception ", e.getCause()); if (e.getCause() instanceof ClusterInvalidSessionException) { - s_logger.error("Invalid cluster session found, fence it"); + logger.error("Invalid cluster session found, fence it"); queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated)); } @@ -641,7 +639,7 @@ protected void runInContext() { } catch (final ActiveFencingException e) { queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated)); } catch (final Throwable e) { - s_logger.error("Unexpected exception in cluster heartbeat", e); + logger.error("Unexpected exception in cluster heartbeat", e); if (isRootCauseConnectionRelated(e.getCause())) { invalidHeartbeatConnection(); } @@ -670,7 +668,7 @@ private void invalidHeartbeatConnection() { if (conn != null) { _heartbeatConnection.reset(conn); } else { - s_logger.error("DB communication problem detected, fence it"); + logger.error("DB communication problem detected, fence it"); queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated)); } // The stand-alone connection does not have to be closed here because there will be another reference to it. @@ -703,11 +701,11 @@ protected void runInContext() { profiler.stop(); if (profiler.getDurationInMillis() > 1000) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notifying management server join event took " + profiler.getDurationInMillis() + " ms"); + if (logger.isDebugEnabled()) { + logger.debug("Notifying management server join event took " + profiler.getDurationInMillis() + " ms"); } } else { - s_logger.warn("Notifying management server join event took " + profiler.getDurationInMillis() + " ms"); + logger.warn("Notifying management server join event took " + profiler.getDurationInMillis() + " ms"); } } break; @@ -721,11 +719,11 @@ protected void runInContext() { profiler.stop(); if (profiler.getDurationInMillis() > 1000) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms"); + if (logger.isDebugEnabled()) { + logger.debug("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms"); } } else { - s_logger.warn("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms"); + logger.warn("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms"); } } break; @@ -740,7 +738,7 @@ protected void runInContext() { } } catch (final Throwable e) { - s_logger.warn("Unexpected exception during cluster notification. ", e); + logger.warn("Unexpected exception during cluster notification. ", e); } } @@ -807,18 +805,18 @@ private void initPeerScan() { if (orphanList.size() > 0) { for (final Long orphanMsid : orphanList) { // construct fake ManagementServerHostVO based on orphan MSID - s_logger.info("Add orphan management server msid found in host table to initial clustering notification, orphan msid: " + orphanMsid); + logger.info("Add orphan management server msid found in host table to initial clustering notification, orphan msid: " + orphanMsid); inactiveList.add(new ManagementServerHostVO(orphanMsid, 0, "orphan", 0, new Date())); } } else { - s_logger.info("We are good, no orphan management server msid in host table is found"); + logger.info("We are good, no orphan management server msid in host table is found"); } if (inactiveList.size() > 0) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Found " + inactiveList.size() + " inactive management server node based on timestamp"); + if (logger.isInfoEnabled()) { + logger.info("Found " + inactiveList.size() + " inactive management server node based on timestamp"); for (final ManagementServerHostVO host : inactiveList) { - s_logger.info("management server node msid: " + host.getMsid() + ", name: " + host.getName() + ", service ip: " + host.getServiceIP() + + logger.info("management server node msid: " + host.getMsid() + ", name: " + host.getName() + ", service ip: " + host.getServiceIP() + ", version: " + host.getVersion()); } } @@ -826,7 +824,7 @@ private void initPeerScan() { final List downHostList = new ArrayList(); for (final ManagementServerHostVO host : inactiveList) { if (!pingManagementNode(host)) { - s_logger.warn("Management node " + host.getId() + " is detected inactive by timestamp and also not pingable"); + logger.warn("Management node " + host.getId() + " is detected inactive by timestamp and also not pingable"); downHostList.add(host); } } @@ -835,7 +833,7 @@ private void initPeerScan() { queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeRemoved, downHostList)); } } else { - s_logger.info("No inactive management server node found"); + logger.info("No inactive management server node found"); } } @@ -860,7 +858,7 @@ private void peerScan() throws ActiveFencingException { if (_mshostPeerDao.countStateSeenInPeers(_mshostId, _runId, ManagementServerHost.State.Down) > 0) { final String msg = "We have detected that at least one management server peer reports that this management server is down, perform active fencing to avoid split-brain situation"; - s_logger.error(msg); + logger.error(msg); throw new ActiveFencingException(msg); } @@ -870,24 +868,24 @@ private void peerScan() throws ActiveFencingException { final ManagementServerHostVO current = getInListById(entry.getKey(), currentList); if (current == null) { if (entry.getKey().longValue() != _mshostId.longValue()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Detected management node left, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); + if (logger.isDebugEnabled()) { + logger.debug("Detected management node left, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); } removedNodeList.add(entry.getValue()); } } else { if (current.getRunid() == 0) { if (entry.getKey().longValue() != _mshostId.longValue()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Detected management node left because of invalidated session, id:" + entry.getKey() + ", nodeIP:" + + if (logger.isDebugEnabled()) { + logger.debug("Detected management node left because of invalidated session, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); } invalidatedNodeList.add(entry.getValue()); } } else { if (entry.getValue().getRunid() != current.getRunid()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Detected management node left and rejoined quickly, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); + if (logger.isDebugEnabled()) { + logger.debug("Detected management node left and rejoined quickly, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); } entry.getValue().setRunid(current.getRunid()); @@ -907,7 +905,7 @@ private void peerScan() throws ActiveFencingException { try { JmxUtil.unregisterMBean("ClusterManager", "Node " + mshost.getId()); } catch (final Exception e) { - s_logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString()); + logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString()); } } @@ -922,15 +920,15 @@ private void peerScan() throws ActiveFencingException { while (it.hasNext()) { final ManagementServerHostVO mshost = it.next(); if (!pingManagementNode(mshost)) { - s_logger.warn("Management node " + mshost.getId() + " is detected inactive by timestamp and also not pingable"); + logger.warn("Management node " + mshost.getId() + " is detected inactive by timestamp and also not pingable"); _activePeers.remove(mshost.getId()); try { JmxUtil.unregisterMBean("ClusterManager", "Node " + mshost.getId()); } catch (final Exception e) { - s_logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString()); + logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString()); } } else { - s_logger.info("Management node " + mshost.getId() + " is detected inactive by timestamp but is pingable"); + logger.info("Management node " + mshost.getId() + " is detected inactive by timestamp but is pingable"); it.remove(); } } @@ -945,15 +943,15 @@ private void peerScan() throws ActiveFencingException { if (!_activePeers.containsKey(mshost.getId())) { _activePeers.put(mshost.getId(), mshost); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Detected management node joined, id:" + mshost.getId() + ", nodeIP:" + mshost.getServiceIP()); + if (logger.isDebugEnabled()) { + logger.debug("Detected management node joined, id:" + mshost.getId() + ", nodeIP:" + mshost.getServiceIP()); } newNodeList.add(mshost); try { JmxUtil.registerMBean("ClusterManager", "Node " + mshost.getId(), new ClusterManagerMBeanImpl(this, mshost)); } catch (final Exception e) { - s_logger.warn("Unable to register cluster node into JMX monitoring due to exception " + ExceptionUtil.toString(e)); + logger.warn("Unable to register cluster node into JMX monitoring due to exception " + ExceptionUtil.toString(e)); } } } @@ -965,8 +963,8 @@ private void peerScan() throws ActiveFencingException { profiler.stop(); if (profiler.getDurationInMillis() >= HeartbeatInterval.value()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Peer scan takes too long to finish. profiler: " + profiler.toString() + ", profilerQueryActiveList: " + + if (logger.isDebugEnabled()) { + logger.debug("Peer scan takes too long to finish. profiler: " + profiler.toString() + ", profilerQueryActiveList: " + profilerQueryActiveList.toString() + ", profilerSyncClusterInfo: " + profilerSyncClusterInfo.toString() + ", profilerInvalidatedNodeList: " + profilerInvalidatedNodeList.toString() + ", profilerRemovedList: " + profilerRemovedList.toString()); } @@ -985,8 +983,8 @@ private static ManagementServerHostVO getInListById(final Long id, final List() { @@ -1011,14 +1009,14 @@ public ManagementServerHostVO doInTransaction(final TransactionStatus status) { mshost.setState(ManagementServerHost.State.Up); mshost.setUuid(UUID.randomUUID().toString()); _mshostDao.persist(mshost); - if (s_logger.isInfoEnabled()) { - s_logger.info("New instance of management server msid " + _msId + ", runId " + _runId + " is being started"); + if (logger.isInfoEnabled()) { + logger.info("New instance of management server msid " + _msId + ", runId " + _runId + " is being started"); } } else { _mshostDao.update(mshost.getId(), _runId, NetUtils.getCanonicalHostName(), version, _clusterNodeIP, _currentServiceAdapter.getServicePort(), DateUtil.currentGMTTime()); - if (s_logger.isInfoEnabled()) { - s_logger.info("Management server " + _msId + ", runId " + _runId + " is being started"); + if (logger.isInfoEnabled()) { + logger.info("Management server " + _msId + ", runId " + _runId + " is being started"); } } @@ -1027,8 +1025,8 @@ public ManagementServerHostVO doInTransaction(final TransactionStatus status) { }); _mshostId = mshost.getId(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Management server (host id : " + _mshostId + ") is being started at " + _clusterNodeIP + ":" + _currentServiceAdapter.getServicePort()); + if (logger.isInfoEnabled()) { + logger.info("Management server (host id : " + _mshostId + ") is being started at " + _clusterNodeIP + ":" + _currentServiceAdapter.getServicePort()); } _mshostPeerDao.clearPeerInfo(_mshostId); @@ -1037,8 +1035,8 @@ public ManagementServerHostVO doInTransaction(final TransactionStatus status) { _heartbeatScheduler.scheduleAtFixedRate(getHeartbeatTask(), HeartbeatInterval.value(), HeartbeatInterval.value(), TimeUnit.MILLISECONDS); _notificationExecutor.submit(getNotificationTask()); - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster manager was started successfully"); + if (logger.isInfoEnabled()) { + logger.info("Cluster manager was started successfully"); } return true; @@ -1047,8 +1045,8 @@ public ManagementServerHostVO doInTransaction(final TransactionStatus status) { @Override @DB public boolean stop() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Stopping Cluster manager, msid : " + _msId); + if (logger.isInfoEnabled()) { + logger.info("Stopping Cluster manager, msid : " + _msId); } if (_mshostId != null) { @@ -1069,8 +1067,8 @@ public boolean stop() { } catch (final InterruptedException e) { } - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster manager is stopped"); + if (logger.isInfoEnabled()) { + logger.info("Cluster manager is stopped"); } return true; @@ -1078,8 +1076,8 @@ public boolean stop() { @Override public boolean configure(final String name, final Map params) throws ConfigurationException { - if (s_logger.isInfoEnabled()) { - s_logger.info("Start configuring cluster manager : " + name); + if (logger.isInfoEnabled()) { + logger.info("Start configuring cluster manager : " + name); } final Properties dbProps = DbProperties.getDbProperties(); @@ -1089,8 +1087,8 @@ public boolean configure(final String name, final Map params) th } _clusterNodeIP = _clusterNodeIP.trim(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster node IP : " + _clusterNodeIP); + if (logger.isInfoEnabled()) { + logger.info("Cluster node IP : " + _clusterNodeIP); } if (!NetUtils.isLocalAddress(_clusterNodeIP)) { @@ -1115,8 +1113,8 @@ public boolean configure(final String name, final Map params) th checkConflicts(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster manager is configured."); + if (logger.isInfoEnabled()) { + logger.info("Cluster manager is configured."); } return true; } @@ -1174,7 +1172,7 @@ private boolean pingManagementNode(final ManagementServerHostVO mshost) { final String targetIp = mshost.getServiceIP(); if ("127.0.0.1".equals(targetIp) || "0.0.0.0".equals(targetIp)) { - s_logger.info("ping management node cluster service can not be performed on self"); + logger.info("ping management node cluster service can not be performed on self"); return false; } @@ -1182,7 +1180,7 @@ private boolean pingManagementNode(final ManagementServerHostVO mshost) { while (--retry > 0) { SocketChannel sch = null; try { - s_logger.info("Trying to connect to " + targetIp); + logger.info("Trying to connect to " + targetIp); sch = SocketChannel.open(); sch.configureBlocking(true); sch.socket().setSoTimeout(5000); @@ -1192,9 +1190,9 @@ private boolean pingManagementNode(final ManagementServerHostVO mshost) { return true; } catch (final IOException e) { if (e instanceof ConnectException) { - s_logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException", e); + logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException"); + if (logger.isDebugEnabled()) { + logger.debug("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException", e); } return false; } @@ -1213,7 +1211,7 @@ private boolean pingManagementNode(final ManagementServerHostVO mshost) { } } - s_logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " after retries"); + logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " after retries"); return false; } @@ -1230,25 +1228,25 @@ private void checkConflicts() throws ConfigurationException { if ("127.0.0.1".equals(_clusterNodeIP)) { if (pingManagementNode(peer.getMsid())) { final String msg = "Detected another management node with localhost IP is already running, please check your cluster configuration"; - s_logger.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } else { final String msg = "Detected another management node with localhost IP is considered as running in DB, however it is not pingable, we will continue cluster initialization with this management server node"; - s_logger.info(msg); + logger.info(msg); } } else { if (pingManagementNode(peer.getMsid())) { final String msg = "Detected that another management node with the same IP " + peer.getServiceIP() + " is already running, please check your cluster configuration"; - s_logger.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } else { final String msg = "Detected that another management node with the same IP " + peer.getServiceIP() + " is considered as running in DB, however it is not pingable, we will continue cluster initialization with this management server node"; - s_logger.info(msg); + logger.info(msg); } } } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletAdapter.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletAdapter.java index 15ee055f9e14..3e498b1fbec3 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletAdapter.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletAdapter.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.ca.CAManager; import org.apache.cloudstack.framework.config.ConfigDepot; -import org.apache.log4j.Logger; import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.utils.NumbersUtil; @@ -35,7 +34,6 @@ public class ClusterServiceServletAdapter extends AdapterBase implements ClusterServiceAdapter { - private static final Logger s_logger = Logger.getLogger(ClusterServiceServletAdapter.class); private static final int DEFAULT_SERVICE_PORT = 9090; private static final int DEFAULT_REQUEST_TIMEOUT = 300; // 300 seconds @@ -62,7 +60,7 @@ public ClusterService getPeerService(String strPeer) throws RemoteException { try { init(); } catch (ConfigurationException e) { - s_logger.error("Unable to init ClusterServiceServletAdapter"); + logger.error("Unable to init ClusterServiceServletAdapter"); throw new RemoteException("Unable to init ClusterServiceServletAdapter"); } @@ -76,7 +74,7 @@ protected String getServiceEndpointName(String strPeer) { try { init(); } catch (ConfigurationException e) { - s_logger.error("Unable to init ClusterServiceServletAdapter"); + logger.error("Unable to init ClusterServiceServletAdapter"); return null; } @@ -128,7 +126,7 @@ private void init() throws ConfigurationException { Properties dbProps = DbProperties.getDbProperties(); _clusterServicePort = NumbersUtil.parseInt(dbProps.getProperty("cluster.servlet.port"), DEFAULT_SERVICE_PORT); - if (s_logger.isInfoEnabled()) - s_logger.info("Cluster servlet port : " + _clusterServicePort); + if (logger.isInfoEnabled()) + logger.info("Cluster servlet port : " + _clusterServicePort); } } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletContainer.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletContainer.java index 1aa9caae50a9..e8c3de980168 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletContainer.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletContainer.java @@ -53,14 +53,14 @@ import org.apache.http.protocol.ResponseContent; import org.apache.http.protocol.ResponseDate; import org.apache.http.protocol.ResponseServer; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.cloud.utils.StringUtils; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.nio.Link; public class ClusterServiceServletContainer { - private static final Logger s_logger = Logger.getLogger(ClusterServiceServletContainer.class); private ListenerThread listenerThread; @@ -81,6 +81,7 @@ public void stop() { } } + protected static SSLServerSocket getSecuredServerSocket(SSLContext sslContext, String ip, int port) throws IOException { SSLServerSocketFactory sslFactory = sslContext.getServerSocketFactory(); @@ -96,6 +97,8 @@ protected static SSLServerSocket getSecuredServerSocket(SSLContext sslContext, S } static class ListenerThread extends Thread { + + private static Logger LOGGER = LogManager.getLogger(ListenerThread.class); private HttpService httpService = null; private volatile SSLServerSocket serverSocket = null; private HttpParams params = null; @@ -111,7 +114,7 @@ public ListenerThread(HttpRequestHandler requestHandler, String ip, int port, SSLContext sslContext = Link.initManagementSSLContext(caService); serverSocket = getSecuredServerSocket(sslContext, ip, port); } catch (IOException | GeneralSecurityException e) { - s_logger.error("Error initializing cluster service servlet container for secure connection", + LOGGER.error("Error initializing cluster service servlet container for secure connection", e); return; } @@ -145,7 +148,7 @@ public void stopRunning() { try { serverSocket.close(); } catch (IOException e) { - s_logger.info("[ignored] error on closing server socket", e); + LOGGER.info("[ignored] error on closing server socket", e); } serverSocket = null; } @@ -167,8 +170,8 @@ protected boolean isValidPeerConnection(Socket socket) throws SSLPeerUnverifiedE @Override public void run() { - if (s_logger.isInfoEnabled()) - s_logger.info(String.format("Cluster service servlet container listening on host: %s and port %d", + if (LOGGER.isInfoEnabled()) + LOGGER.info(String.format("Cluster service servlet container listening on host: %s and port %d", serverSocket.getInetAddress().getHostAddress(), serverSocket.getLocalPort())); while (serverSocket != null) { @@ -178,7 +181,7 @@ public void run() { final DefaultHttpServerConnection conn = new DefaultHttpServerConnection(); conn.bind(socket, params); if (!isValidPeerConnection(socket)) { - s_logger.warn(String.format("Failure during validating cluster request from %s", + LOGGER.warn(String.format("Failure during validating cluster request from %s", socket.getInetAddress().getHostAddress())); conn.shutdown(); continue; @@ -189,47 +192,47 @@ protected void runInContext() { HttpContext context = new BasicHttpContext(null); try { while (!Thread.interrupted() && conn.isOpen()) { - if (s_logger.isTraceEnabled()) - s_logger.trace("dispatching cluster request from " + conn.getRemoteAddress().toString()); + if (LOGGER.isTraceEnabled()) + LOGGER.trace("dispatching cluster request from " + conn.getRemoteAddress().toString()); httpService.handleRequest(conn, context); - if (s_logger.isTraceEnabled()) - s_logger.trace("Cluster request from " + conn.getRemoteAddress().toString() + " is processed"); + if (LOGGER.isTraceEnabled()) + LOGGER.trace("Cluster request from " + conn.getRemoteAddress().toString() + " is processed"); } } catch (ConnectionClosedException ex) { // client close and read time out exceptions are expected // when KEEP-AVLIE is enabled - s_logger.trace("Client closed connection", ex); + LOGGER.trace("Client closed connection", ex); } catch (IOException ex) { - s_logger.trace("I/O error", ex); + LOGGER.trace("I/O error", ex); } catch (HttpException ex) { - s_logger.error("Unrecoverable HTTP protocol violation", ex); + LOGGER.error("Unrecoverable HTTP protocol violation", ex); } finally { try { conn.shutdown(); } catch (IOException ignore) { - s_logger.error("unexpected exception", ignore); + LOGGER.error("unexpected exception", ignore); } } } }); } catch (Throwable e) { - s_logger.error("Unexpected exception ", e); + LOGGER.error("Unexpected exception ", e); // back off to avoid spinning if the exception condition keeps coming back try { Thread.sleep(1000); } catch (InterruptedException e1) { - s_logger.debug("[ignored] interrupted while waiting to retry running the servlet container."); + LOGGER.debug("[ignored] interrupted while waiting to retry running the servlet container."); } } } executor.shutdown(); - if (s_logger.isInfoEnabled()) - s_logger.info("Cluster service servlet container shutdown"); + if (LOGGER.isInfoEnabled()) + LOGGER.info("Cluster service servlet container shutdown"); } } } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java index f697ade8a39b..4e94f434f8f8 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java @@ -29,10 +29,11 @@ import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class ClusterServiceServletHttpHandler implements HttpRequestHandler { - private static final Logger s_logger = Logger.getLogger(ClusterServiceServletHttpHandler.class); + protected Logger logger = LogManager.getLogger(getClass()); private final ClusterManager manager; @@ -44,27 +45,27 @@ public ClusterServiceServletHttpHandler(ClusterManager manager) { public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Start Handling cluster HTTP request"); + if (logger.isTraceEnabled()) { + logger.trace("Start Handling cluster HTTP request"); } parseRequest(request); handleRequest(request, response); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Handle cluster HTTP request done"); + if (logger.isTraceEnabled()) { + logger.trace("Handle cluster HTTP request done"); } } catch (final Throwable e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Exception " + e.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Exception " + e.toString()); } try { writeResponse(response, HttpStatus.SC_INTERNAL_SERVER_ERROR, null); } catch (final Throwable e2) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Exception " + e2.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Exception " + e2.toString()); } } } @@ -88,8 +89,8 @@ private void parseRequest(HttpRequest request) throws IOException { final String name = URLDecoder.decode(paramValue[0]); final String value = URLDecoder.decode(paramValue[1]); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Parsed request parameter " + name + "=" + value); + if (logger.isTraceEnabled()) { + logger.trace("Parsed request parameter " + name + "=" + value); } request.getParams().setParameter(name, value); } @@ -134,22 +135,22 @@ protected void handleRequest(HttpRequest req, HttpResponse response) { case RemoteMethodConstants.METHOD_UNKNOWN: default: assert false; - s_logger.error("unrecognized method " + nMethod); + logger.error("unrecognized method " + nMethod); break; } } catch (final Throwable e) { - s_logger.error("Unexpected exception when processing cluster service request : ", e); + logger.error("Unexpected exception when processing cluster service request : ", e); } if (responseContent != null) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Write response with HTTP OK " + responseContent); + if (logger.isTraceEnabled()) { + logger.trace("Write response with HTTP OK " + responseContent); } writeResponse(response, HttpStatus.SC_OK, responseContent); } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Write response with HTTP Bad request"); + if (logger.isTraceEnabled()) { + logger.trace("Write response with HTTP Bad request"); } writeResponse(response, HttpStatus.SC_BAD_REQUEST, null); @@ -184,8 +185,8 @@ private String handleDeliverPduMethodCall(HttpRequest req) { private String handlePingMethodCall(HttpRequest req) { final String callingPeer = (String)req.getParams().getParameter("callingPeer"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Handle ping request from " + callingPeer); + if (logger.isDebugEnabled()) { + logger.debug("Handle ping request from " + callingPeer); } return "true"; diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java index c5b614521698..d582538c31e0 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java @@ -36,7 +36,8 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.cloud.utils.HttpUtils; import com.cloud.utils.Profiler; @@ -45,7 +46,7 @@ public class ClusterServiceServletImpl implements ClusterService { private static final long serialVersionUID = 4574025200012566153L; - private static final Logger s_logger = Logger.getLogger(ClusterServiceServletImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private String serviceUrl; @@ -56,8 +57,8 @@ public class ClusterServiceServletImpl implements ClusterService { protected static CloseableHttpClient s_client = null; private void logPostParametersForFailedEncoding(List parameters) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("%s encoding failed for POST parameters: %s", HttpUtils.UTF_8, + if (logger.isTraceEnabled()) { + logger.trace(String.format("%s encoding failed for POST parameters: %s", HttpUtils.UTF_8, gson.toJson(parameters))); } } @@ -66,7 +67,7 @@ public ClusterServiceServletImpl() { } public ClusterServiceServletImpl(final String serviceUrl, final CAService caService) { - s_logger.info(String.format("Setup cluster service servlet. service url: %s, request timeout: %d seconds", serviceUrl, + logger.info(String.format("Setup cluster service servlet. service url: %s, request timeout: %d seconds", serviceUrl, ClusterServiceAdapter.ClusterMessageTimeOut.value())); this.serviceUrl = serviceUrl; this.caService = caService; @@ -88,8 +89,8 @@ protected List getClusterServicePduPostParameters(final ClusterSe @Override public String execute(final ClusterServicePdu pdu) throws RemoteException { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Executing ClusterServicePdu with service URL: %s", serviceUrl)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Executing ClusterServicePdu with service URL: %s", serviceUrl)); } final CloseableHttpClient client = getHttpClient(); final HttpPost method = new HttpPost(serviceUrl); @@ -97,7 +98,7 @@ public String execute(final ClusterServicePdu pdu) throws RemoteException { try { method.setEntity(new UrlEncodedFormEntity(postParameters, HttpUtils.UTF_8)); } catch (UnsupportedEncodingException e) { - s_logger.error("Failed to encode request POST parameters", e); + logger.error("Failed to encode request POST parameters", e); logPostParametersForFailedEncoding(postParameters); throw new RemoteException("Failed to encode request POST parameters", e); } @@ -114,8 +115,8 @@ protected List getPingPostParameters(final String callingPeer) { @Override public boolean ping(final String callingPeer) throws RemoteException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping at " + serviceUrl); + if (logger.isDebugEnabled()) { + logger.debug("Ping at " + serviceUrl); } final CloseableHttpClient client = getHttpClient(); @@ -125,7 +126,7 @@ public boolean ping(final String callingPeer) throws RemoteException { try { method.setEntity(new UrlEncodedFormEntity(postParameters, HttpUtils.UTF_8)); } catch (UnsupportedEncodingException e) { - s_logger.error("Failed to encode ping request POST parameters", e); + logger.error("Failed to encode ping request POST parameters", e); logPostParametersForFailedEncoding(postParameters); throw new RemoteException("Failed to encode ping request POST parameters", e); } @@ -144,16 +145,16 @@ private String executePostMethod(final CloseableHttpClient client, final HttpPos if (response == HttpStatus.SC_OK) { result = EntityUtils.toString(httpResponse.getEntity()); profiler.stop(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("POST " + serviceUrl + " response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms"); + if (logger.isDebugEnabled()) { + logger.debug("POST " + serviceUrl + " response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms"); } } else { profiler.stop(); - s_logger.error("Invalid response code : " + response + ", from : " + serviceUrl + ", method : " + method.getParams().getParameter("method") + " responding time: " + + logger.error("Invalid response code : " + response + ", from : " + serviceUrl + ", method : " + method.getParams().getParameter("method") + " responding time: " + profiler.getDurationInMillis()); } } catch (IOException e) { - s_logger.error("Exception from : " + serviceUrl + ", method : " + method.getParams().getParameter("method") + ", exception :", e); + logger.error("Exception from : " + serviceUrl + ", method : " + method.getParams().getParameter("method") + ", exception :", e); } finally { method.releaseConnection(); } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java index 715dfe26bae6..7b69889c853e 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java @@ -26,7 +26,6 @@ import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.cluster.ClusterInvalidSessionException; import org.apache.cloudstack.management.ManagementServerHost; @@ -42,7 +41,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class ManagementServerHostDaoImpl extends GenericDaoBase implements ManagementServerHostDao { - private static final Logger s_logger = Logger.getLogger(ManagementServerHostDaoImpl.class); private final SearchBuilder MsIdSearch; private final SearchBuilder ActiveSearch; @@ -99,7 +97,7 @@ public void update(long id, long runid, String name, String version, String serv pstmt.executeUpdate(); txn.commit(); } catch (Exception e) { - s_logger.warn("Unexpected exception, ", e); + logger.warn("Unexpected exception, ", e); throw new RuntimeException(e.getMessage(), e); } } @@ -119,7 +117,7 @@ public boolean remove(Long id) { txn.commit(); return true; } catch (Exception e) { - s_logger.warn("Unexpected exception, ", e); + logger.warn("Unexpected exception, ", e); throw new RuntimeException(e.getMessage(), e); } } @@ -141,11 +139,11 @@ public void update(long id, long runid, Date lastUpdate) { txn.commit(); if (count < 1) { - s_logger.info("Invalid cluster session detected, runId " + runid + " is no longer valid"); + logger.info("Invalid cluster session detected, runId " + runid + " is no longer valid"); throw new CloudRuntimeException("Invalid cluster session detected, runId " + runid + " is no longer valid", new ClusterInvalidSessionException("runId " + runid + " is no longer valid")); } } catch (Exception e) { - s_logger.warn("Unexpected exception, ", e); + logger.warn("Unexpected exception, ", e); throw new RuntimeException(e.getMessage(), e); } } @@ -181,7 +179,7 @@ public int increaseAlertCount(long id) { changedRows = pstmt.executeUpdate(); txn.commit(); } catch (Exception e) { - s_logger.warn("Unexpected exception, ", e); + logger.warn("Unexpected exception, ", e); throw new RuntimeException(e.getMessage(), e); } @@ -223,7 +221,7 @@ public void update(long id, long runId, State state, Date lastUpdate) { int count = pstmt.executeUpdate(); if (count < 1) { - s_logger.info("Invalid cluster session detected, runId " + runId + " is no longer valid"); + logger.info("Invalid cluster session detected, runId " + runId + " is no longer valid"); throw new CloudRuntimeException("Invalid cluster session detected, runId " + runId + " is no longer valid", new ClusterInvalidSessionException("runId " + runId + " is no longer valid")); } } catch (SQLException e) { diff --git a/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostPeerDaoImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostPeerDaoImpl.java index a7a56c738c16..827be4fe2998 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostPeerDaoImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostPeerDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.management.ManagementServerHost; import com.cloud.cluster.ManagementServerHostPeerVO; @@ -30,7 +29,6 @@ import com.cloud.utils.db.TransactionLegacy; public class ManagementServerHostPeerDaoImpl extends GenericDaoBase implements ManagementServerHostPeerDao { - private static final Logger s_logger = Logger.getLogger(ManagementServerHostPeerDaoImpl.class); private final SearchBuilder ClearPeerSearch; private final SearchBuilder FindForUpdateSearch; @@ -85,7 +83,7 @@ public void updatePeerInfo(long ownerMshost, long peerMshost, long peerRunid, Ma } txn.commit(); } catch (Exception e) { - s_logger.warn("Unexpected exception, ", e); + logger.warn("Unexpected exception, ", e); txn.rollback(); } } diff --git a/framework/cluster/src/main/resources/META-INF/cloudstack/core/spring-framework-cluster-core-context.xml b/framework/cluster/src/main/resources/META-INF/cloudstack/core/spring-framework-cluster-core-context.xml index 539c9e9164f9..ddb40d07626b 100644 --- a/framework/cluster/src/main/resources/META-INF/cloudstack/core/spring-framework-cluster-core-context.xml +++ b/framework/cluster/src/main/resources/META-INF/cloudstack/core/spring-framework-cluster-core-context.xml @@ -28,9 +28,9 @@ > - + - + - + diff --git a/framework/cluster/src/test/java/com/cloud/cluster/ClusterServiceServletAdapterTest.java b/framework/cluster/src/test/java/com/cloud/cluster/ClusterServiceServletAdapterTest.java index 3827236d6159..6f4b7d6aa9ee 100644 --- a/framework/cluster/src/test/java/com/cloud/cluster/ClusterServiceServletAdapterTest.java +++ b/framework/cluster/src/test/java/com/cloud/cluster/ClusterServiceServletAdapterTest.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.utils.component.ComponentLifecycle; diff --git a/framework/config/pom.xml b/framework/config/pom.xml index cab81e678988..fc3b14642f1a 100644 --- a/framework/config/pom.xml +++ b/framework/config/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigDepot.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigDepot.java index b38b30e88b8e..5ee5f9dec48a 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigDepot.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigDepot.java @@ -32,4 +32,6 @@ public interface ConfigDepot { void createOrUpdateConfigObject(String componentName, ConfigKey key, String value); boolean isNewConfig(ConfigKey configKey); + String getConfigStringValue(String key, ConfigKey.Scope scope, Long scopeId); + void invalidateConfigCache(String key, ConfigKey.Scope scope, Long scopeId); } diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java index df93f78fa833..36a8050754c0 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java @@ -19,7 +19,6 @@ import java.sql.Date; import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl; -import org.apache.cloudstack.framework.config.impl.ConfigurationVO; import com.cloud.utils.Pair; import com.cloud.utils.Ternary; @@ -41,7 +40,7 @@ public enum Scope { } public enum Kind { - CSV, Order, Select + CSV, Order, Select, WhitespaceSeparatedListWithOptions } private final String _category; @@ -136,6 +135,10 @@ public ConfigKey(String category, Class type, String name, String defaultValu this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null); } + public ConfigKey(String category, Class type, String name, String defaultValue, String description, boolean isDynamic, Kind kind, String options) { + this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null, null, null, null, null, kind, options); + } + public ConfigKey(String category, Class type, String name, String defaultValue, String description, boolean isDynamic, String parent) { this(type, name, category, defaultValue, description, isDynamic, Scope.Global, null, null, parent, null, null, null, null); } @@ -211,42 +214,38 @@ public boolean isSameKeyAs(Object obj) { public T value() { if (_value == null || isDynamic()) { - ConfigurationVO vo = s_depot != null ? s_depot.global().findById(key()) : null; - final String value = (vo != null && vo.getValue() != null) ? vo.getValue() : defaultValue(); - _value = ((value == null) ? (T)defaultValue() : valueOf(value)); + String value = s_depot != null ? s_depot.getConfigStringValue(_name, Scope.Global, null) : null; + _value = valueOf((value == null) ? defaultValue() : value); } return _value; } - public T valueIn(Long id) { + protected T valueInScope(Scope scope, Long id) { if (id == null) { return value(); } - String value = s_depot != null ? s_depot.findScopedConfigStorage(this).getConfigValue(id, this) : null; + String value = s_depot != null ? s_depot.getConfigStringValue(_name, scope, id) : null; if (value == null) { return value(); - } else { - return valueOf(value); } + return valueOf(value); } - public T valueInDomain(Long domainId) { - if (domainId == null) { - return value(); - } + public T valueIn(Long id) { + return valueInScope(_scope, id); + } - String value = s_depot != null ? s_depot.getDomainScope(this).getConfigValue(domainId, this) : null; - if (value == null) { - return value(); - } else { - return valueOf(value); - } + public T valueInDomain(Long domainId) { + return valueInScope(Scope.Domain, domainId); } @SuppressWarnings("unchecked") protected T valueOf(String value) { + if (value == null) { + return null; + } Number multiplier = 1; if (multiplier() != null) { multiplier = (Number)multiplier(); diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapper.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapper.java new file mode 100644 index 000000000000..b8d7e7829711 --- /dev/null +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapper.java @@ -0,0 +1,114 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.framework.config; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import static java.util.concurrent.TimeUnit.NANOSECONDS; + +/** + * Uses a ScheduledExecutorService and config key to execute a runnable, + * dynamically rescheduling based on the long value of the config key. + * Timing is similar to ScheduledExecutorService.scheduleAtFixedRate(), + * but we look up the next runtime dynamically via the config key. + *

+ * If config key is zero, this disables the execution. We skip execution + * and check once a minute in order to re-start execution if re-enabled. + */ +public class ConfigKeyScheduledExecutionWrapper implements Runnable { + protected Logger logger = LogManager.getLogger(getClass()); + private final ScheduledExecutorService executorService; + private final Runnable command; + private final ConfigKey configKey; + private final TimeUnit unit; + private long enableIntervalSeconds = 60; + + private void validateArgs(ScheduledExecutorService executorService, Runnable command, ConfigKey configKey) { + if (executorService == null) { + throw new IllegalArgumentException("ExecutorService cannot be null"); + } + if (command == null) { + throw new IllegalArgumentException("Command cannot be null"); + } + if (configKey == null) { + throw new IllegalArgumentException("ConfigKey cannot be null"); + } + if (!(configKey.value() instanceof Long || configKey.value() instanceof Integer)) { + throw new IllegalArgumentException("ConfigKey value must be a Long or Integer"); + } + } + + public ConfigKeyScheduledExecutionWrapper(ScheduledExecutorService executorService, Runnable command, + ConfigKey configKey, TimeUnit unit) { + validateArgs(executorService, command, configKey); + this.executorService = executorService; + this.command = command; + this.configKey = configKey; + this.unit = unit; + } + + protected ConfigKeyScheduledExecutionWrapper(ScheduledExecutorService executorService, Runnable command, + ConfigKey configKey, int enableIntervalSeconds, TimeUnit unit) { + validateArgs(executorService, command, configKey); + this.executorService = executorService; + this.command = command; + this.configKey = configKey; + this.unit = unit; + this.enableIntervalSeconds = enableIntervalSeconds; + } + + public ScheduledFuture start() { + long duration = getConfigValue(); + duration = duration < 0 ? 0 : duration; + return this.executorService.schedule(this, duration, this.unit); + } + + long getConfigValue() { + if (this.configKey.value() instanceof Long) { + return (Long) this.configKey.value(); + } else if (this.configKey.value() instanceof Integer) { + return (Integer) this.configKey.value(); + } else { + throw new IllegalArgumentException("ConfigKey value must be a Long or Integer"); + } + } + + @Override + public void run() { + if (getConfigValue() <= 0) { + executorService.schedule(this, enableIntervalSeconds, TimeUnit.SECONDS); + return; + } + + long startTime = System.nanoTime(); + try { + command.run(); + } catch (Throwable t) { + logger.warn(String.format("Last run of %s encountered an error", this.command.getClass()), t); + } finally { + long elapsed = System.nanoTime() - startTime; + long delay = this.unit.toNanos(getConfigValue()) - elapsed; + delay = delay > 0 ? delay : 0; + executorService.schedule(this, delay, NANOSECONDS); + } + } +} diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ScopedConfigStorage.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ScopedConfigStorage.java index f990278b45cd..8126b9510a27 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ScopedConfigStorage.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ScopedConfigStorage.java @@ -26,5 +26,9 @@ public interface ScopedConfigStorage { Scope getScope(); - String getConfigValue(long id, ConfigKey key); + String getConfigValue(long id, String key); + + default String getConfigValue(long id, ConfigKey key) { + return getConfigValue(id, key.key()); + } } diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java index 4e7b127a4178..7c4a6f9a609e 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java @@ -25,7 +25,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.framework.config.impl.ConfigurationVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.component.ComponentLifecycle; @@ -39,7 +38,6 @@ @Component public class ConfigurationDaoImpl extends GenericDaoBase implements ConfigurationDao { - private static final Logger s_logger = Logger.getLogger(ConfigurationDaoImpl.class); private Map _configs = null; private boolean _premium; @@ -145,7 +143,7 @@ public boolean update(String name, String value) { stmt.executeUpdate(); return true; } catch (Exception e) { - s_logger.warn("Unable to update Configuration Value", e); + logger.warn("Unable to update Configuration Value", e); } return false; } @@ -162,7 +160,7 @@ public boolean update(String name, String category, String value) { return true; } } catch (Exception e) { - s_logger.warn("Unable to update Configuration Value", e); + logger.warn("Unable to update Configuration Value", e); } return false; } @@ -196,7 +194,7 @@ public String getValueAndInitIfNotExist(String name, String category, String ini } return returnValue; } catch (Exception e) { - s_logger.warn("Unable to update Configuration Value", e); + logger.warn("Unable to update Configuration Value", e); throw new CloudRuntimeException("Unable to initialize configuration variable: " + name); } diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java index 46a1de950ddf..b47370d92059 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.TimeUnit; import javax.annotation.PostConstruct; import javax.inject.Inject; @@ -37,11 +38,14 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDao; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.cloud.utils.Pair; import com.cloud.utils.Ternary; import com.cloud.utils.exception.CloudRuntimeException; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; /** * ConfigDepotImpl implements the ConfigDepot and ConfigDepotAdmin interface. @@ -71,7 +75,8 @@ * validation class to validate the value the admin input for the key. */ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { - private final static Logger s_logger = Logger.getLogger(ConfigDepotImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); + protected final static long CONFIG_CACHE_EXPIRE_SECONDS = 30; @Inject ConfigurationDao _configDao; @Inject @@ -82,12 +87,17 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { List _scopedStorages; Set _configured = Collections.synchronizedSet(new HashSet()); Set newConfigs = Collections.synchronizedSet(new HashSet<>()); + Cache configCache; private HashMap>> _allKeys = new HashMap>>(1007); HashMap>> _scopeLevelConfigsMap = new HashMap>>(); public ConfigDepotImpl() { + configCache = Caffeine.newBuilder() + .maximumSize(512) + .expireAfterWrite(CONFIG_CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS) + .build(); ConfigKey.init(this); createEmptyScopeLevelMappings(); } @@ -126,7 +136,7 @@ protected void populateConfiguration(Date date, Configurable configurable) { if (_configured.contains(configurable)) return; - s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName()); + logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName()); for (ConfigKey key : configurable.getConfigKeys()) { Pair> previous = _allKeys.get(key.key()); @@ -267,6 +277,48 @@ public ConfigurationDao global() { return _configDao; } + protected String getConfigStringValueInternal(String cacheKey) { + String[] parts = cacheKey.split("-"); + String key = parts[0]; + ConfigKey.Scope scope = ConfigKey.Scope.Global; + Long scopeId = null; + try { + scope = ConfigKey.Scope.valueOf(parts[1]); + scopeId = Long.valueOf(parts[2]); + } catch (IllegalArgumentException ignored) {} + if (!ConfigKey.Scope.Global.equals(scope) && scopeId != null) { + ScopedConfigStorage scopedConfigStorage = null; + for (ScopedConfigStorage storage : _scopedStorages) { + if (storage.getScope() == scope) { + scopedConfigStorage = storage; + } + } + if (scopedConfigStorage == null) { + throw new CloudRuntimeException("Unable to find config storage for this scope: " + scope + " for " + key); + } + return scopedConfigStorage.getConfigValue(scopeId, key); + } + ConfigurationVO configurationVO = _configDao.findById(key); + if (configurationVO != null) { + return configurationVO.getValue(); + } + return null; + } + + private String getConfigCacheKey(String key, ConfigKey.Scope scope, Long scopeId) { + return String.format("%s-%s-%d", key, scope, (scopeId == null ? 0 : scopeId)); + } + + @Override + public String getConfigStringValue(String key, ConfigKey.Scope scope, Long scopeId) { + return configCache.get(getConfigCacheKey(key, scope, scopeId), this::getConfigStringValueInternal); + } + + @Override + public void invalidateConfigCache(String key, ConfigKey.Scope scope, Long scopeId) { + configCache.invalidate(getConfigCacheKey(key, scope, scopeId)); + } + public ScopedConfigStorage findScopedConfigStorage(ConfigKey config) { for (ScopedConfigStorage storage : _scopedStorages) { if (storage.getScope() == config.scope()) { diff --git a/framework/config/src/main/resources/META-INF/cloudstack/system/spring-framework-config-system-context-inheritable.xml b/framework/config/src/main/resources/META-INF/cloudstack/system/spring-framework-config-system-context-inheritable.xml index e176ec5a88b1..0148fa7acc6d 100644 --- a/framework/config/src/main/resources/META-INF/cloudstack/system/spring-framework-config-system-context-inheritable.xml +++ b/framework/config/src/main/resources/META-INF/cloudstack/system/spring-framework-config-system-context-inheritable.xml @@ -25,13 +25,13 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" - > + > - + diff --git a/framework/config/src/test/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapperTest.java b/framework/config/src/test/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapperTest.java new file mode 100644 index 000000000000..fbb4dc24fcae --- /dev/null +++ b/framework/config/src/test/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapperTest.java @@ -0,0 +1,177 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.framework.config; + +import com.cloud.utils.concurrency.NamedThreadFactory; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.isOneOf; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigKeyScheduledExecutionWrapperTest { + private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1, new NamedThreadFactory("TestExecutor")); + + @Mock + ConfigKey configKey; + + @Test(expected = IllegalArgumentException.class) + public void nullExecutorTest() { + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(null, runnable, configKey, TimeUnit.SECONDS); + } + + @Test(expected = IllegalArgumentException.class) + public void nullCommandTest() { + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, null, configKey, TimeUnit.SECONDS); + } + + @Test(expected = IllegalArgumentException.class) + public void nullConfigKeyTest() { + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, null, TimeUnit.SECONDS); + } + + @Test(expected = IllegalArgumentException.class) + public void invalidConfigKeyTest() { + TestRunnable runnable = new TestRunnable(); + ConfigKey configKey = new ConfigKey<>(String.class, "test", "test", "test", "test", true, + ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.SECONDS); + } + + @Test + public void scheduleOncePerSecondTest() { + when(configKey.value()).thenReturn(1); + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.SECONDS); + runner.start(); + + waitSeconds(3); + assertThat("Runnable ran once per second", runnable.getRunCount(), isOneOf(2, 3)); + } + + private void waitSeconds(int seconds) { + try { + Thread.sleep(seconds * 1000L + 100); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Test + public void scheduleTwicePerSecondTest() { + when(configKey.value()).thenReturn(500); + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.MILLISECONDS); + runner.start(); + + waitSeconds(2); + assertThat("Runnable ran twice per second", runnable.getRunCount(), isOneOf(3, 4)); + } + + @Test + public void scheduleDynamicTest() { + // start with twice per second, then switch to four times per second + when(configKey.value()).thenReturn(500); + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.MILLISECONDS); + runner.start(); + + waitSeconds(2); + assertThat("Runnable ran twice per second", runnable.getRunCount(), isOneOf(3, 4)); + + runnable.resetRunCount(); + when(configKey.value()).thenReturn(250); + waitSeconds(2); + assertThat("Runnable ran four times per second", runnable.getRunCount(), isOneOf(7, 8)); + } + + @Test + public void noOverlappingRunsTest() { + when(configKey.value()).thenReturn(200); + TestRunnable runnable = new TestRunnable(1); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.MILLISECONDS); + runner.start(); + + waitSeconds(3); + assertThat("Slow runnable on tight schedule runs without overlap", runnable.getRunCount(), isOneOf(2, 3)); + } + + @Test + public void temporaryDisableRunsTest() { + // start with twice per second, then disable, then start again + when(configKey.value()).thenReturn(500); + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, 1, TimeUnit.MILLISECONDS); + runner.start(); + + waitSeconds(2); + assertThat("Runnable ran twice per second", runnable.getRunCount(), isOneOf(3, 4)); + + runnable.resetRunCount(); + when(configKey.value()).thenReturn(0); + waitSeconds(2); + assertThat("Runnable ran zero times per second", runnable.getRunCount(), is(0)); + + runnable.resetRunCount(); + when(configKey.value()).thenReturn(500); + waitSeconds(2); + assertThat("Runnable ran twice per second", runnable.getRunCount(), isOneOf(3, 4)); + } + + static class TestRunnable implements Runnable { + private Integer runCount = 0; + private int waitSeconds = 0; + + TestRunnable(int waitSeconds) { + this.waitSeconds = waitSeconds; + } + + TestRunnable() { + } + + @Override + public void run() { + runCount++; + if (waitSeconds > 0) { + try { + Thread.sleep(waitSeconds * 1000L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + public int getRunCount() { + return this.runCount; + } + + public void resetRunCount() { + this.runCount = 0; + } + } +} diff --git a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java index 54e30ebed951..476e378cf57f 100644 --- a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java +++ b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.framework.config.impl; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -28,6 +28,7 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationGroupDao; import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDao; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -74,13 +75,15 @@ public class ConfigDepotAdminTest extends TestCase { @Mock ScopedConfigStorage _scopedStorage; + private AutoCloseable closeable; + /** * @throws java.lang.Exception */ @Override @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); _depotAdmin = new ConfigDepotImpl(); _depotAdmin._configDao = _configDao; _depotAdmin._configGroupDao = _configGroupDao; @@ -91,6 +94,12 @@ public void setUp() throws Exception { _depotAdmin._scopedStorages.add(_scopedStorage); } + @Override + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testAutoPopulation() { ConfigurationVO dynamicIntCV = new ConfigurationVO("UnitTestComponent", DynamicIntCK); diff --git a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java index 8dd6f71af3c8..8a7da7953450 100644 --- a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java +++ b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java @@ -23,12 +23,23 @@ import java.util.Set; import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; +@RunWith(MockitoJUnitRunner.class) public class ConfigDepotImplTest { + @Mock + ConfigurationDao _configDao; + + @InjectMocks private ConfigDepotImpl configDepotImpl = new ConfigDepotImpl(); @Test @@ -57,4 +68,43 @@ public void testIsNewConfig() { Assert.assertFalse(configDepotImpl.isNewConfig(invalidNewConfig)); } + private void runTestGetConfigStringValue(String key, String value) { + ConfigurationVO configurationVO = Mockito.mock(ConfigurationVO.class); + Mockito.when(configurationVO.getValue()).thenReturn(value); + Mockito.when(_configDao.findById(key)).thenReturn(configurationVO); + String result = configDepotImpl.getConfigStringValue(key, ConfigKey.Scope.Global, null); + Assert.assertEquals(value, result); + } + + @Test + public void testGetConfigStringValue() { + runTestGetConfigStringValue("test", "value"); + } + + private void runTestGetConfigStringValueExpiry(long wait, int configDBRetrieval) { + String key = "test1"; + String value = "expiry"; + runTestGetConfigStringValue(key, value); + try { + Thread.sleep(wait); + } catch (InterruptedException ie) { + Assert.fail(ie.getMessage()); + } + String result = configDepotImpl.getConfigStringValue(key, ConfigKey.Scope.Global, null); + Assert.assertEquals(value, result); + Mockito.verify(_configDao, Mockito.times(configDBRetrieval)).findById(key); + + } + + @Test + public void testGetConfigStringValueWithinExpiry() { + runTestGetConfigStringValueExpiry((ConfigDepotImpl.CONFIG_CACHE_EXPIRE_SECONDS * 1000 ) / 4, + 1); + } + + @Test + public void testGetConfigStringValueAfterExpiry() { + runTestGetConfigStringValueExpiry(((ConfigDepotImpl.CONFIG_CACHE_EXPIRE_SECONDS) + 5) * 1000, + 2); + } } diff --git a/framework/db/pom.xml b/framework/db/pom.xml index 3b0fc2a8c5e2..586d72f34f38 100644 --- a/framework/db/pom.xml +++ b/framework/db/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml @@ -40,6 +40,10 @@ org.apache.commons commons-dbcp2 + + com.zaxxer + HikariCP + commons-io commons-io @@ -48,6 +52,10 @@ org.apache.commons commons-pool2 + + mysql + mysql-connector-java + org.apache.cloudstack cloud-utils diff --git a/framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java b/framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java index 2ae0de90f268..c7c869ba9206 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java +++ b/framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java @@ -30,7 +30,8 @@ import javax.management.StandardMBean; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.managed.context.ManagedContextRunnable; @@ -45,9 +46,9 @@ */ public class ConnectionConcierge { - static final Logger s_logger = Logger.getLogger(ConnectionConcierge.class); + protected Logger logger = LogManager.getLogger(getClass()); - static final ConnectionConciergeManager s_mgr = new ConnectionConciergeManager(); + private final ConnectionConciergeManager sMgr = new ConnectionConciergeManager(); Connection _conn; String _name; @@ -57,7 +58,7 @@ public class ConnectionConcierge { int _holdability; public ConnectionConcierge(String name, Connection conn, boolean keepAlive) { - _name = name + s_mgr.getNextId(); + _name = name + sMgr.getNextId(); _keepAlive = keepAlive; try { _autoCommit = conn.getAutoCommit(); @@ -73,7 +74,7 @@ public void reset(Connection conn) { try { release(); } catch (Throwable th) { - s_logger.error("Unable to release a connection", th); + logger.error("Unable to release a connection", th); } _conn = conn; try { @@ -81,10 +82,10 @@ public void reset(Connection conn) { _conn.setHoldability(_holdability); _conn.setTransactionIsolation(_isolationLevel); } catch (SQLException e) { - s_logger.error("Unable to release a connection", e); + logger.error("Unable to release a connection", e); } - s_mgr.register(_name, this); - s_logger.debug("Registering a database connection for " + _name); + sMgr.register(_name, this); + logger.debug("Registering a database connection for " + _name); } public final Connection conn() { @@ -92,7 +93,7 @@ public final Connection conn() { } public void release() { - s_mgr.unregister(_name); + sMgr.unregister(_name); try { if (_conn != null) { _conn.close(); @@ -114,7 +115,7 @@ public boolean keepAlive() { return _keepAlive; } - protected static class ConnectionConciergeManager extends StandardMBean implements ConnectionConciergeMBean { + protected class ConnectionConciergeManager extends StandardMBean implements ConnectionConciergeMBean { ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ConnectionKeeper")); final ConcurrentHashMap _conns = new ConcurrentHashMap(); final AtomicInteger _idGenerator = new AtomicInteger(); @@ -125,7 +126,7 @@ protected static class ConnectionConciergeManager extends StandardMBean implemen try { JmxUtil.registerMBean("DB Connections", "DB Connections", this); } catch (Exception e) { - s_logger.error("Unable to register mbean", e); + logger.error("Unable to register mbean", e); } } @@ -144,10 +145,10 @@ public void unregister(String name) { protected String testValidity(String name, Connection conn) { if (conn != null) { synchronized (conn) { - try (PreparedStatement pstmt = conn.prepareStatement("SELECT 1");) { + try (PreparedStatement pstmt = conn.prepareStatement("/* ping */ SELECT 1");) { pstmt.executeQuery(); } catch (Throwable th) { - s_logger.error("Unable to keep the db connection for " + name, th); + logger.error("Unable to keep the db connection for " + name, th); return th.toString(); } } @@ -187,7 +188,7 @@ public String resetKeepAliveTask(int seconds) { try { _executor.shutdown(); } catch (Exception e) { - s_logger.error("Unable to shutdown executor", e); + logger.error("Unable to shutdown executor", e); } } @@ -196,13 +197,13 @@ public String resetKeepAliveTask(int seconds) { _executor.scheduleAtFixedRate(new ManagedContextRunnable() { @Override protected void runInContext() { - s_logger.trace("connection concierge keep alive task"); + logger.trace("connection concierge keep alive task"); for (Map.Entry entry : _conns.entrySet()) { String name = entry.getKey(); ConnectionConcierge concierge = entry.getValue(); if (concierge.keepAlive()) { if (testValidity(name, concierge.conn()) != null) { - s_logger.info("Resetting DB connection " + name); + logger.info("Resetting DB connection " + name); resetConnection(name); } } diff --git a/framework/db/src/main/java/com/cloud/utils/db/DbUtil.java b/framework/db/src/main/java/com/cloud/utils/db/DbUtil.java index 68424bc5dd9e..88397f54d4f4 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/DbUtil.java +++ b/framework/db/src/main/java/com/cloud/utils/db/DbUtil.java @@ -41,12 +41,13 @@ import javax.persistence.Table; import javax.persistence.Transient; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import static com.cloud.utils.AutoCloseableUtil.closeAutoCloseable; public class DbUtil { - protected final static Logger LOGGER = Logger.getLogger(DbUtil.class); + protected static Logger LOGGER = LogManager.getLogger(DbUtil.class); private static Map s_connectionForGlobalLocks = new HashMap(); diff --git a/framework/db/src/main/java/com/cloud/utils/db/DriverLoader.java b/framework/db/src/main/java/com/cloud/utils/db/DriverLoader.java index 55fc1dbb6ed7..ac783fa046ff 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/DriverLoader.java +++ b/framework/db/src/main/java/com/cloud/utils/db/DriverLoader.java @@ -23,13 +23,14 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.exception.CloudRuntimeException; public class DriverLoader { - private static final Logger LOGGER = Logger.getLogger(DriverLoader.class.getName()); + protected static Logger LOGGER = LogManager.getLogger(DriverLoader.class); private static final List LOADED_DRIVERS; private static final Map DRIVERS; diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericDao.java b/framework/db/src/main/java/com/cloud/utils/db/GenericDao.java index b9199468bd19..84750c2068c8 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/GenericDao.java +++ b/framework/db/src/main/java/com/cloud/utils/db/GenericDao.java @@ -229,6 +229,24 @@ public interface GenericDao { */ int expunge(final SearchCriteria sc); + /** + * remove the entity bean specified by the search criteria and filter + * @param sc + * @param filter + * @return number of rows deleted + */ + int expunge(final SearchCriteria sc, final Filter filter); + + /** + * remove the entity bean specified by the search criteria and batchSize + * @param sc + * @param batchSize + * @return number of rows deleted + */ + int batchExpunge(final SearchCriteria sc, final Long batchSize); + + int expungeList(List ids); + /** * Delete the entity beans specified by the search criteria with a given limit * @param sc Search criteria diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java index 3b950e1983dd..52a6b204ee81 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java +++ b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java @@ -20,6 +20,8 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.Array; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.math.BigInteger; @@ -42,13 +44,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import javax.naming.ConfigurationException; +import javax.persistence.AttributeConverter; import javax.persistence.AttributeOverride; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.EmbeddedId; import javax.persistence.EntityExistsException; import javax.persistence.EnumType; @@ -56,10 +61,12 @@ import javax.persistence.Table; import javax.persistence.TableGenerator; -import com.amazonaws.util.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import com.amazonaws.util.CollectionUtils; import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -72,8 +79,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.exception.ExceptionUtils; import net.sf.cglib.proxy.Callback; import net.sf.cglib.proxy.CallbackFilter; @@ -120,11 +125,11 @@ **/ @DB public abstract class GenericDaoBase extends ComponentLifecycleBase implements GenericDao, ComponentMethodInterceptable { - private final static Logger s_logger = Logger.getLogger(GenericDaoBase.class); protected final static TimeZone s_gmtTimeZone = TimeZone.getTimeZone("GMT"); protected final static Map, GenericDao> s_daoMaps = new ConcurrentHashMap, GenericDao>(71); + private final ConversionSupport _conversionSupport; protected Class _entityBeanType; protected String _table; @@ -266,29 +271,30 @@ protected GenericDaoBase() { _searchEnhancer.setSuperclass(_entityBeanType); _searchEnhancer.setCallback(new UpdateBuilder(this)); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Select SQL: " + _partialSelectSql.first().toString()); - s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql")); - s_logger.trace("Select by Id SQL: " + _selectByIdSql); - s_logger.trace("Table References: " + _tables); - s_logger.trace("Insert SQLs:"); + if (logger.isTraceEnabled()) { + logger.trace("Select SQL: " + _partialSelectSql.first().toString()); + logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql")); + logger.trace("Select by Id SQL: " + _selectByIdSql); + logger.trace("Table References: " + _tables); + logger.trace("Insert SQLs:"); for (final Pair insertSql : _insertSqls) { - s_logger.trace(insertSql.first()); + logger.trace(insertSql.first()); } - s_logger.trace("Delete SQLs"); + logger.trace("Delete SQLs"); for (final Pair deletSql : _deleteSqls) { - s_logger.trace(deletSql.first()); + logger.trace(deletSql.first()); } - s_logger.trace("Collection SQLs"); + logger.trace("Collection SQLs"); for (Attribute attr : _ecAttributes) { EcInfo info = (EcInfo)attr.attache; - s_logger.trace(info.insertSql); - s_logger.trace(info.selectSql); + logger.trace(info.insertSql); + logger.trace(info.selectSql); } } + _conversionSupport = new ConversionSupport(); setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM); } @@ -422,7 +428,7 @@ public List searchIncludingRemoved(SearchCriteria sc, final Filter filter, } } - if (s_logger.isDebugEnabled() && lock != null) { + if (logger.isDebugEnabled() && lock != null) { txn.registerLock(pstmt.toString()); } final ResultSet rs = pstmt.executeQuery(); @@ -431,9 +437,11 @@ public List searchIncludingRemoved(SearchCriteria sc, final Filter filter, } return result; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to find on DB, due to: " + e.getLocalizedMessage()); } catch (final Exception e) { - throw new CloudRuntimeException("Caught: " + pstmt, e); + logger.error("Caught: " + pstmt, e); + throw new CloudRuntimeException("Caught error: " + e.getLocalizedMessage()); } } @@ -516,9 +524,11 @@ public List customSearchIncludingRemoved(SearchCriteria sc, final Filt return results; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to find on DB, due to: " + e.getLocalizedMessage()); } catch (final Exception e) { - throw new CloudRuntimeException("Caught: " + pstmt, e); + logger.error("Caught: " + pstmt, e); + throw new CloudRuntimeException("Caught error: " + e.getLocalizedMessage()); } } @@ -667,6 +677,9 @@ protected void setField(Object entity, Field field, ResultSet rs, int index) thr } } else if (type == byte[].class) { field.set(entity, rs.getBytes(index)); + } else if (field.getDeclaredAnnotation(Convert.class) != null) { + Object val = _conversionSupport.convertToEntityAttribute(field, rs.getObject(index)); + field.set(entity, val); } else { field.set(entity, rs.getObject(index)); } @@ -794,8 +807,8 @@ protected int addJoinAttributes(int count, PreparedStatement pstmt, Collection sc, Integer rows) { ub.clear(); return result; } catch (final SQLException e) { + logger.error("DB Exception on: " + pstmt, e); handleEntityExistsException(e); - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to update on DB, due to: " + e.getLocalizedMessage()); } } @@ -892,7 +906,7 @@ protected String buildSelectByIdSql(final StringBuilder sql) { if (_idField.getAnnotation(EmbeddedId.class) == null) { sql.append(_table).append(".").append(DbUtil.getColumnName(_idField, null)).append(" = ? "); } else { - s_logger.debug(String.format("field type vs declarator : %s vs %s", _idField.getType(), _idField.getDeclaringClass())); + logger.debug(String.format("field type vs declarator : %s vs %s", _idField.getType(), _idField.getDeclaringClass())); final Class clazz = _idField.getType(); final AttributeOverride[] overrides = DbUtil.getAttributeOverrides(_idField); for (final Field field : clazz.getDeclaredFields()) { @@ -1056,7 +1070,8 @@ protected T findById(ID id, boolean removed, Boolean lock) { ResultSet rs = pstmt.executeQuery(); return rs.next() ? toEntityBean(rs, true) : null; } catch (SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to find by id on DB, due to: " + e.getLocalizedMessage()); } } @@ -1171,9 +1186,11 @@ protected List executeList(final String sql, final Object... params) { } return result; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to execute on DB, due to: " + e.getLocalizedMessage()); } catch (final Exception e) { - throw new CloudRuntimeException("Caught: " + pstmt, e); + logger.error("Caught: " + pstmt, e); + throw new CloudRuntimeException("Caught error: " + e.getLocalizedMessage()); } } @@ -1222,18 +1239,20 @@ public boolean expunge(final ID id) { } return true; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to expunge on DB, due to: " + e.getLocalizedMessage()); } } + // FIXME: Does not work for joins. @Override - public int expunge(final SearchCriteria sc) { - return expunge(sc, -1); + public int expunge(final SearchCriteria sc, long limit) { + Filter filter = new Filter(limit); + return expunge(sc, filter); } - // FIXME: Does not work for joins. @Override - public int expunge(final SearchCriteria sc, long limit) { + public int expunge(final SearchCriteria sc, final Filter filter) { if (sc == null) { throw new CloudRuntimeException("Call to throw new expunge with null search Criteria"); } @@ -1245,11 +1264,7 @@ public int expunge(final SearchCriteria sc, long limit) { if (sc != null && sc.getWhereClause().length() > 0) { str.append(sc.getWhereClause()); } - - if (limit > 0) { - str.append(" LIMIT "); - str.append(limit); - } + addFilter(str, filter); final String sql = str.toString(); @@ -1263,10 +1278,53 @@ public int expunge(final SearchCriteria sc, long limit) { } return pstmt.executeUpdate(); } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to expunge on DB, due to: " + e.getLocalizedMessage()); } catch (final Exception e) { - throw new CloudRuntimeException("Caught: " + pstmt, e); + logger.error("Caught: " + pstmt, e); + throw new CloudRuntimeException("Caught error: " + e.getLocalizedMessage()); + } + } + @Override + public int expunge(final SearchCriteria sc) { + return expunge(sc, null); + } + + @Override + public int batchExpunge(final SearchCriteria sc, final Long batchSize) { + Filter filter = null; + final long batchSizeFinal = ObjectUtils.defaultIfNull(batchSize, 0L); + if (batchSizeFinal > 0) { + filter = new Filter(batchSizeFinal); + } + int expunged = 0; + int currentExpunged = 0; + do { + currentExpunged = expunge(sc, filter); + expunged += currentExpunged; + } while (batchSizeFinal > 0 && currentExpunged >= batchSizeFinal); + return expunged; + } + + @Override + public int expungeList(final List ids) { + if (org.apache.commons.collections.CollectionUtils.isEmpty(ids)) { + return 0; } + SearchBuilder sb = createSearchBuilder(); + Object obj = null; + try { + Method m = sb.entity().getClass().getMethod("getId"); + obj = m.invoke(sb.entity()); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {} + if (obj == null) { + logger.warn(String.format("Unable to get ID object for entity: %s", _entityBeanType.getSimpleName())); + return 0; + } + sb.and("id", obj, SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("id", ids.toArray()); + return expunge(sc); } @DB() @@ -1426,9 +1484,9 @@ protected int checkCountOfRecordsAgainstTheResultSetSize(int count, int resultSe } String stackTrace = ExceptionUtils.getStackTrace(new CloudRuntimeException(String.format("The query to count all the records of [%s] resulted in a value smaller than" - + " the result set's size [count of records: %s, result set's size: %s]. Using the result set's size instead.", _entityBeanType, + + " the result set's size [count of records: %s, result set's size: %s]. Using the result set's size instead.", _entityBeanType, count, resultSetSize))); - s_logger.warn(stackTrace); + logger.warn(stackTrace); return resultSetSize; } @@ -1503,7 +1561,7 @@ public T persist(final T entity) { return entity; } - assert false : "Can't call persit if you don't have primary key"; + assert false : "Can't call persist if you don't have primary key"; } ID id = null; @@ -1559,8 +1617,9 @@ public T persist(final T entity) { } txn.commit(); } catch (final SQLException e) { + logger.error("DB Exception on: " + pstmt, e); handleEntityExistsException(e); - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to persist on DB, due to: " + e.getLocalizedMessage()); } catch (IllegalArgumentException e) { throw new CloudRuntimeException("Problem with getting the ec attribute ", e); } catch (IllegalAccessException e) { @@ -1635,10 +1694,18 @@ protected void prepareAttribute(final int j, final PreparedStatement pstmt, fina return; } } + if (attr.getValue() != null && attr.getValue() instanceof String) { pstmt.setString(j, (String)attr.getValue()); } else if (attr.getValue() != null && attr.getValue() instanceof Long) { pstmt.setLong(j, (Long)attr.getValue()); + } else if(attr.field.getDeclaredAnnotation(Convert.class) != null) { + if (value instanceof String) { + pstmt.setString(j, (String)value); + } else { + Object val = _conversionSupport.convertToDatabaseColumn(attr.field, value); + pstmt.setObject(j, val); + } } else if (attr.field.getType() == String.class) { final String str; try { @@ -1651,7 +1718,7 @@ protected void prepareAttribute(final int j, final PreparedStatement pstmt, fina // This happens when we pass in an integer, long or any other object which can't be cast to String. // Converting to string in case of integer or long can result in different results. Required specifically for details tables. // So, we set the value for the object directly. - s_logger.debug("ClassCastException when casting value to String. Setting the value of the object directly."); + logger.debug("ClassCastException when casting value to String. Setting the value of the object directly."); pstmt.setObject(j, value); return; } @@ -1773,7 +1840,7 @@ protected T toEntityBean(final ResultSet result, final boolean cache) throws SQL try { _cache.put(new Element(_idField.get(entity), entity)); } catch (final Exception e) { - s_logger.debug("Can't put it in the cache", e); + logger.debug("Can't put it in the cache", e); } } @@ -1795,7 +1862,7 @@ protected T toVO(ResultSet result, boolean cache) throws SQLException { try { _cache.put(new Element(_idField.get(entity), entity)); } catch (final Exception e) { - s_logger.debug("Can't put it in the cache", e); + logger.debug("Can't put it in the cache", e); } } @@ -1901,7 +1968,8 @@ public void expunge() { pstmt.executeUpdate(); txn.commit(); } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to expunge on DB, due to: " + e.getLocalizedMessage()); } } @@ -1929,7 +1997,8 @@ public boolean unremove(ID id) { } return result > 0; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to unremove on DB, due to: " + e.getLocalizedMessage()); } } @@ -1972,7 +2041,8 @@ public boolean remove(final ID id) { } return result > 0; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to remove on DB, due to: " + e.getLocalizedMessage()); } } @@ -2002,7 +2072,7 @@ protected void createCache(final Map params) { final int idle = NumbersUtil.parseInt((String)params.get("cache.time.to.idle"), 300); _cache = new Cache(getName(), maxElements, false, live == -1, live == -1 ? Integer.MAX_VALUE : live, idle); cm.addCache(_cache); - s_logger.info("Cache created: " + _cache.toString()); + logger.info("Cache created: " + _cache.toString()); } else { _cache = null; } @@ -2120,9 +2190,11 @@ public Integer getDistinctCountIncludingRemoved(SearchCriteria sc) { } return 0; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to get count on DB, due to: " + e.getLocalizedMessage()); } catch (final Exception e) { - throw new CloudRuntimeException("Caught: " + pstmt, e); + logger.error("Caught: " + pstmt, e); + throw new CloudRuntimeException("Caught error: " + e.getLocalizedMessage()); } } @@ -2179,9 +2251,11 @@ public Integer getDistinctCountIncludingRemoved(SearchCriteria sc, String[] d } return 0; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception in executing: " + sql, e); + logger.error("DB Exception in executing: " + sql, e); + throw new CloudRuntimeException("Unable to get count on DB, due to: " + e.getLocalizedMessage()); } catch (final Exception e) { - throw new CloudRuntimeException("Caught exception in : " + sql, e); + logger.error("Caught exception in : " + sql, e); + throw new CloudRuntimeException("Caught error: " + e.getLocalizedMessage()); } } @@ -2254,9 +2328,11 @@ public Integer getCountIncludingRemoved(SearchCriteria sc) { } return 0; } catch (final SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + pstmt, e); + logger.error("DB Exception on: " + pstmt, e); + throw new CloudRuntimeException("Unable to get count on DB, due to: " + e.getLocalizedMessage()); } catch (final Exception e) { - throw new CloudRuntimeException("Caught: " + pstmt, e); + logger.error("Caught: " + pstmt, e); + throw new CloudRuntimeException("Caught error: " + e.getLocalizedMessage()); } } @@ -2309,4 +2385,50 @@ protected StringBuilder createDistinctSelect(SearchCriteria sc, final boolean return sql; } + + /** + * Support conversion between DB and Entity values. + * Detects whether field is annotated with {@link Convert} annotation and use converter instance from the annotation. + */ + static class ConversionSupport { + /** + * Contains cache of {@link AttributeConverter} instances. + */ + private static final Map, AttributeConverter> s_converterCacheMap = new ConcurrentHashMap<>(); + + /** + * Checks whether field annotated with {@link Convert} annotation and tries to convert source value with converter. + * + * @param field Entity field + * @param value DB value + * @return converted value if field is annotated with {@link Convert} or original value otherwise + */ + private T convertToEntityAttribute(Field field, Object value) { + return (T) getConverter(field).map(converter -> converter.convertToEntityAttribute(value)).orElse(value); + } + + /** + * Checks whether field annotated with {@link Convert} annotation and tries to convert source value with converter. + * + * @param field Entity field + * @param value Entity value + * @return converted value if field is annotated with {@link Convert} or original value otherwise + */ + private T convertToDatabaseColumn(Field field, Object value) { + return (T) getConverter(field).map(converter -> converter.convertToDatabaseColumn(value)).orElse(value); + } + + private Optional> getConverter(Field field) { + return Optional.of(field).map(f -> f.getAnnotation(Convert.class)).map(Convert::converter).filter(AttributeConverter.class::isAssignableFrom).map(converterType -> { + return (AttributeConverter) s_converterCacheMap.computeIfAbsent(converterType, ct -> { + try { + return (AttributeConverter) ct.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { + throw new CloudRuntimeException("Unable to create converter for the class " + converterType, e); + } + }); + }); + } + } + } diff --git a/framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java b/framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java index 662ba921ce90..523f90b28669 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java +++ b/framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java @@ -22,7 +22,8 @@ import java.util.Map; import java.util.concurrent.Callable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.Profiler; @@ -43,7 +44,7 @@ // lock.releaseRef(); // public class GlobalLock { - protected final static Logger s_logger = Logger.getLogger(GlobalLock.class); + protected Logger logger = LogManager.getLogger(getClass()); private String name; private int lockCount = 0; @@ -74,7 +75,7 @@ public int releaseRef() { refCount = referenceCount; if (referenceCount < 0) - s_logger.warn("Unmatched Global lock " + name + " reference usage detected, check your code!"); + logger.warn("Unmatched Global lock " + name + " reference usage detected, check your code!"); if (referenceCount == 0) needToRemove = true; @@ -101,14 +102,14 @@ public static GlobalLock getInternLock(String name) { } } - private static void releaseInternLock(String name) { + private void releaseInternLock(String name) { synchronized (s_lockMap) { GlobalLock lock = s_lockMap.get(name); if (lock != null) { if (lock.referenceCount == 0) s_lockMap.remove(name); } else { - s_logger.warn("Releasing " + name + ", but it is already released."); + logger.warn("Releasing " + name + ", but it is already released."); } } } @@ -121,12 +122,12 @@ public boolean lock(int timeoutSeconds) { while (true) { synchronized (this) { if (ownerThread != null && ownerThread == Thread.currentThread()) { - s_logger.warn("Global lock re-entrance detected"); + logger.warn("Global lock re-entrance detected"); lockCount++; - if (s_logger.isTraceEnabled()) - s_logger.trace("lock " + name + " is acquired, lock count :" + lockCount); + if (logger.isTraceEnabled()) + logger.trace("lock " + name + " is acquired, lock count :" + lockCount); return true; } @@ -156,8 +157,8 @@ public boolean lock(int timeoutSeconds) { lockCount++; holdingStartTick = System.currentTimeMillis(); - if (s_logger.isTraceEnabled()) - s_logger.trace("lock " + name + " is acquired, lock count :" + lockCount); + if (logger.isTraceEnabled()) + logger.trace("lock " + name + " is acquired, lock count :" + lockCount); return true; } } else { @@ -183,8 +184,8 @@ public boolean unlock() { ownerThread = null; DbUtil.releaseGlobalLock(name); - if (s_logger.isTraceEnabled()) - s_logger.trace("lock " + name + " is returned to free state, total holding time :" + (System.currentTimeMillis() - holdingStartTick)); + if (logger.isTraceEnabled()) + logger.trace("lock " + name + " is returned to free state, total holding time :" + (System.currentTimeMillis() - holdingStartTick)); holdingStartTick = 0; // release holding position in intern map when we released the DB connection @@ -192,8 +193,8 @@ public boolean unlock() { notifyAll(); } - if (s_logger.isTraceEnabled()) - s_logger.trace("lock " + name + " is released, lock count :" + lockCount); + if (logger.isTraceEnabled()) + logger.trace("lock " + name + " is released, lock count :" + lockCount); return true; } return false; @@ -204,15 +205,15 @@ public String getName() { return name; } - public static T executeWithLock(final String operationId, final int lockAcquisitionTimeout, final Callable operation) throws Exception { + public T executeWithLock(final String operationId, final int lockAcquisitionTimeout, final Callable operation) throws Exception { final GlobalLock lock = GlobalLock.getInternLock(operationId); try { if (!lock.lock(lockAcquisitionTimeout)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(format("Failed to acquire lock for operation id %1$s", operationId)); + if (logger.isDebugEnabled()) { + logger.debug(format("Failed to acquire lock for operation id %1$s", operationId)); } return null; } @@ -229,7 +230,7 @@ public static T executeWithLock(final String operationId, final int lockAcqu } - public static T executeWithNoWaitLock(final String operationId, final Callable operation) throws Exception { + public T executeWithNoWaitLock(final String operationId, final Callable operation) throws Exception { return executeWithLock(operationId, 0, operation); diff --git a/framework/db/src/main/java/com/cloud/utils/db/Merovingian2.java b/framework/db/src/main/java/com/cloud/utils/db/Merovingian2.java index 485a68ab3134..a9a1ce4272eb 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/Merovingian2.java +++ b/framework/db/src/main/java/com/cloud/utils/db/Merovingian2.java @@ -29,7 +29,8 @@ import javax.management.StandardMBean; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.DateUtil; import com.cloud.utils.exception.CloudRuntimeException; @@ -37,7 +38,7 @@ import com.cloud.utils.time.InaccurateClock; public class Merovingian2 extends StandardMBean implements MerovingianMBean { - private static final Logger s_logger = Logger.getLogger(Merovingian2.class); + protected static Logger LOGGER = LogManager.getLogger(Merovingian2.class); private static final String ACQUIRE_SQL = "INSERT INTO op_lock (op_lock.key, op_lock.mac, op_lock.ip, op_lock.thread, op_lock.acquired_on, waiters) VALUES (?, ?, ?, ?, ?, 1)"; @@ -70,14 +71,14 @@ private Merovingian2(long msId) { conn.setAutoCommit(true); _concierge = new ConnectionConcierge("LockController", conn, true); } catch (SQLException e) { - s_logger.error("Unable to get a new db connection", e); + LOGGER.error("Unable to get a new db connection", e); throw new CloudRuntimeException("Unable to initialize a connection to the database for locking purposes", e); } finally { if (_concierge == null && conn != null) { try { conn.close(); } catch (SQLException e) { - s_logger.debug("closing connection failed after everything else.", e); + LOGGER.debug("closing connection failed after everything else.", e); } } } @@ -90,7 +91,7 @@ public static synchronized Merovingian2 createLockController(long msId) { try { JmxUtil.registerMBean("Locks", "Locks", s_instance); } catch (Exception e) { - s_logger.error("Unable to register for JMX", e); + LOGGER.error("Unable to register for JMX", e); } return s_instance; } @@ -123,8 +124,8 @@ public boolean acquire(String key, int timeInSeconds) { String threadName = th.getName(); int threadId = System.identityHashCode(th); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Acquiring lck-" + key + " with wait time of " + timeInSeconds); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Acquiring lck-" + key + " with wait time of " + timeInSeconds); } long startTime = InaccurateClock.getTime(); @@ -139,17 +140,17 @@ public boolean acquire(String key, int timeInSeconds) { } } try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Sleeping more time while waiting for lck-" + key); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Sleeping more time while waiting for lck-" + key); } Thread.sleep(5000); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while aquiring " + key); + LOGGER.debug("[ignored] interrupted while aquiring " + key); } } String msg = "Timed out on acquiring lock " + key + " . Waited for " + ((InaccurateClock.getTime() - startTime)/1000) + "seconds"; Exception e = new CloudRuntimeException(msg); - s_logger.warn(msg, e); + LOGGER.warn(msg, e); return false; } @@ -161,8 +162,8 @@ protected boolean increment(String key, String threadName, int threadId) { pstmt.setInt(4, threadId); int rows = pstmt.executeUpdate(); assert (rows <= 1) : "hmm...non unique key? " + pstmt; - if (s_logger.isTraceEnabled()) { - s_logger.trace("lck-" + key + (rows == 1 ? " acquired again" : " failed to acquire again")); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("lck-" + key + (rows == 1 ? " acquired again" : " failed to acquire again")); } if (rows == 1) { incrCount(); @@ -170,7 +171,7 @@ protected boolean increment(String key, String threadName, int threadId) { } return false; } catch (Exception e) { - s_logger.error("increment:Exception:"+e.getMessage()); + LOGGER.error("increment:Exception:"+e.getMessage()); throw new CloudRuntimeException("increment:Exception:"+e.getMessage(), e); } } @@ -186,8 +187,8 @@ protected boolean doAcquire(String key, String threadName, int threadId) { try { int rows = pstmt.executeUpdate(); if (rows == 1) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Acquired for lck-" + key); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Acquired for lck-" + key); } incrCount(); return true; @@ -198,11 +199,11 @@ protected boolean doAcquire(String key, String threadName, int threadId) { } } } catch (SQLException e) { - s_logger.error("doAcquire:Exception:"+e.getMessage()); + LOGGER.error("doAcquire:Exception:"+e.getMessage()); throw new CloudRuntimeException("Unable to lock " + key + ". Waited " + (InaccurateClock.getTime() - startTime), e); } - s_logger.trace("Unable to acquire lck-" + key); + LOGGER.trace("Unable to acquire lck-" + key); return false; } @@ -216,11 +217,11 @@ protected Map isLocked(String key) { } return toLock(rs); }catch (SQLException e) { - s_logger.error("isLocked:Exception:"+e.getMessage()); + LOGGER.error("isLocked:Exception:"+e.getMessage()); throw new CloudRuntimeException("isLocked:Exception:"+e.getMessage(), e); } } catch (SQLException e) { - s_logger.error("isLocked:Exception:"+e.getMessage()); + LOGGER.error("isLocked:Exception:"+e.getMessage()); throw new CloudRuntimeException("isLocked:Exception:"+e.getMessage(), e); } } @@ -231,20 +232,20 @@ public void cleanupThisServer() { @Override public void cleanupForServer(long msId) { - s_logger.info("Cleaning up locks for " + msId); + LOGGER.info("Cleaning up locks for " + msId); try { synchronized (_concierge.conn()) { try(PreparedStatement pstmt = _concierge.conn().prepareStatement(CLEANUP_MGMT_LOCKS_SQL);) { pstmt.setLong(1, msId); int rows = pstmt.executeUpdate(); - s_logger.info("Released " + rows + " locks for " + msId); + LOGGER.info("Released " + rows + " locks for " + msId); }catch (Exception e) { - s_logger.error("cleanupForServer:Exception:"+e.getMessage()); + LOGGER.error("cleanupForServer:Exception:"+e.getMessage()); throw new CloudRuntimeException("cleanupForServer:Exception:"+e.getMessage(), e); } } } catch (Exception e) { - s_logger.error("cleanupForServer:Exception:"+e.getMessage()); + LOGGER.error("cleanupForServer:Exception:"+e.getMessage()); throw new CloudRuntimeException("cleanupForServer:Exception:"+e.getMessage(), e); } } @@ -262,30 +263,30 @@ public boolean release(String key) { int rows = pstmt.executeUpdate(); assert (rows <= 1) : "hmmm....keys not unique? " + pstmt; - if (s_logger.isTraceEnabled()) { - s_logger.trace("lck-" + key + " released"); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("lck-" + key + " released"); } if (rows == 1) { try (PreparedStatement rel_sql_pstmt = _concierge.conn().prepareStatement(RELEASE_SQL);) { rel_sql_pstmt.setString(1, key); rel_sql_pstmt.setLong(2, _msId); int result = rel_sql_pstmt.executeUpdate(); - if (result == 1 && s_logger.isTraceEnabled()) { - s_logger.trace("lck-" + key + " removed"); + if (result == 1 && LOGGER.isTraceEnabled()) { + LOGGER.trace("lck-" + key + " removed"); } decrCount(); }catch (Exception e) { - s_logger.error("release:Exception:"+ e.getMessage()); + LOGGER.error("release:Exception:"+ e.getMessage()); throw new CloudRuntimeException("release:Exception:"+ e.getMessage(), e); } } else if (rows < 1) { String msg = ("Was unable to find lock for the key " + key + " and thread id " + threadId); Exception e = new CloudRuntimeException(msg); - s_logger.warn(msg, e); + LOGGER.warn(msg, e); } return rows == 1; } catch (Exception e) { - s_logger.error("release:Exception:"+ e.getMessage()); + LOGGER.error("release:Exception:"+ e.getMessage()); throw new CloudRuntimeException("release:Exception:"+ e.getMessage(), e); } } @@ -320,11 +321,11 @@ protected List> getLocks(String sql, Long msId) { { return toLocks(rs); }catch (Exception e) { - s_logger.error("getLocks:Exception:"+e.getMessage()); + LOGGER.error("getLocks:Exception:"+e.getMessage()); throw new CloudRuntimeException("getLocks:Exception:"+e.getMessage(), e); } } catch (Exception e) { - s_logger.error("getLocks:Exception:"+e.getMessage()); + LOGGER.error("getLocks:Exception:"+e.getMessage()); throw new CloudRuntimeException("getLocks:Exception:"+e.getMessage(), e); } } @@ -360,11 +361,11 @@ public List> getLocksAcquiredBy(long msId, String threadName return toLocks(rs); } catch (Exception e) { - s_logger.error("getLocksAcquiredBy:Exception:"+e.getMessage()); + LOGGER.error("getLocksAcquiredBy:Exception:"+e.getMessage()); throw new CloudRuntimeException("Can't get locks " + pstmt, e); } } catch (Exception e) { - s_logger.error("getLocksAcquiredBy:Exception:"+e.getMessage()); + LOGGER.error("getLocksAcquiredBy:Exception:"+e.getMessage()); throw new CloudRuntimeException("getLocksAcquiredBy:Exception:"+e.getMessage(), e); } } @@ -390,21 +391,21 @@ public void cleanupThread() { assert (false) : "Abandon hope, all ye who enter here....There were still " + rows + ":" + c + " locks not released when the transaction ended, check for lock not released or @DB is not added to the code that using the locks!"; } catch (Exception e) { - s_logger.error("cleanupThread:Exception:" + e.getMessage()); + LOGGER.error("cleanupThread:Exception:" + e.getMessage()); throw new CloudRuntimeException("cleanupThread:Exception:" + e.getMessage(), e); } } @Override public boolean releaseLockAsLastResortAndIReallyKnowWhatIAmDoing(String key) { - s_logger.info("Releasing a lock from JMX lck-" + key); + LOGGER.info("Releasing a lock from JMX lck-" + key); try (PreparedStatement pstmt = _concierge.conn().prepareStatement(RELEASE_LOCK_SQL);) { pstmt.setString(1, key); int rows = pstmt.executeUpdate(); return rows > 0; } catch (Exception e) { - s_logger.error("releaseLockAsLastResortAndIReallyKnowWhatIAmDoing : Exception: " + e.getMessage()); + LOGGER.error("releaseLockAsLastResortAndIReallyKnowWhatIAmDoing : Exception: " + e.getMessage()); return false; } } diff --git a/framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java b/framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java index 51124f693c5b..56fa8593161b 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java +++ b/framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java @@ -29,13 +29,14 @@ import java.sql.SQLException; import java.sql.Statement; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; /** * Tool to run database scripts */ public class ScriptRunner { - private static Logger s_logger = Logger.getLogger(ScriptRunner.class); + private static Logger LOGGER = LogManager.getLogger(ScriptRunner.class); private static final String DEFAULT_DELIMITER = ";"; @@ -208,17 +209,17 @@ private void print(Object o) { private void println(Object o) { _logBuffer.append(o); if (verbosity) - s_logger.debug(_logBuffer.toString()); + LOGGER.debug(_logBuffer.toString()); _logBuffer = new StringBuffer(); } private void printlnError(Object o) { - s_logger.error("" + o); + LOGGER.error("" + o); } private void flush() { if (_logBuffer.length() > 0) { - s_logger.debug(_logBuffer.toString()); + LOGGER.debug(_logBuffer.toString()); _logBuffer = new StringBuffer(); } } diff --git a/framework/db/src/main/java/com/cloud/utils/db/SequenceFetcher.java b/framework/db/src/main/java/com/cloud/utils/db/SequenceFetcher.java index 0ea8401a03cc..f902fda3bf14 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/SequenceFetcher.java +++ b/framework/db/src/main/java/com/cloud/utils/db/SequenceFetcher.java @@ -29,7 +29,8 @@ import javax.persistence.TableGenerator; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.concurrency.NamedThreadFactory; @@ -42,7 +43,7 @@ * */ public class SequenceFetcher { - private final static Logger s_logger = Logger.getLogger(SequenceFetcher.class); + protected Logger logger = LogManager.getLogger(getClass()); ExecutorService _executors; private final static Random random = new Random(); @@ -63,7 +64,7 @@ public T getNextSequence(Class clazz, TableGenerator tg, Object key, bool try { return future.get(); } catch (Exception e) { - s_logger.warn("Unable to get sequeunce for " + tg.table() + ":" + tg.pkColumnValue(), e); + logger.warn("Unable to get sequeunce for " + tg.table() + ":" + tg.pkColumnValue(), e); return null; } } @@ -138,11 +139,11 @@ public T call() throws Exception { } } } catch (SQLException e) { - s_logger.warn("Caught this exception when running: " + (selectStmt != null ? selectStmt.toString() : ""), e); + logger.warn("Caught this exception when running: " + (selectStmt != null ? selectStmt.toString() : ""), e); } if (obj == null) { - s_logger.warn("Unable to get a sequence: " + updateStmt.toString()); + logger.warn("Unable to get a sequence: " + updateStmt.toString()); return null; } @@ -153,7 +154,7 @@ public T call() throws Exception { txn.commit(); return (T)obj; } catch (SQLException e) { - s_logger.warn("Caught this exception when running: " + (updateStmt != null ? updateStmt.toString() : ""), e); + logger.warn("Caught this exception when running: " + (updateStmt != null ? updateStmt.toString() : ""), e); } } } diff --git a/framework/db/src/main/java/com/cloud/utils/db/Transaction.java b/framework/db/src/main/java/com/cloud/utils/db/Transaction.java index c6a491a216d0..24cd76e2e100 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/Transaction.java +++ b/framework/db/src/main/java/com/cloud/utils/db/Transaction.java @@ -18,14 +18,12 @@ import java.util.concurrent.atomic.AtomicLong; -import org.apache.log4j.Logger; public class Transaction { private final static AtomicLong counter = new AtomicLong(0); private final static TransactionStatus STATUS = new TransactionStatus() { }; - private static final Logger s_logger = Logger.getLogger(Transaction.class); @SuppressWarnings("deprecation") public static T execute(TransactionCallbackWithException callback) throws E { diff --git a/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java b/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java index d3fa6afb4f25..88af397c06a9 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java +++ b/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java @@ -38,16 +38,20 @@ import org.apache.commons.dbcp2.PoolableConnection; import org.apache.commons.dbcp2.PoolableConnectionFactory; import org.apache.commons.dbcp2.PoolingDataSource; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.pool2.ObjectPool; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.cloud.utils.Pair; import com.cloud.utils.PropertiesUtil; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.mgmt.JmxUtil; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; /** * Transaction abstracts away the Connection object in JDBC. It allows the @@ -64,10 +68,10 @@ * it is stored with TLS and is one per thread. Use appropriately. */ public class TransactionLegacy implements Closeable { - private static final Logger s_logger = Logger.getLogger(Transaction.class.getName() + "." + "Transaction"); - private static final Logger s_stmtLogger = Logger.getLogger(Transaction.class.getName() + "." + "Statement"); - private static final Logger s_lockLogger = Logger.getLogger(Transaction.class.getName() + "." + "Lock"); - private static final Logger s_connLogger = Logger.getLogger(Transaction.class.getName() + "." + "Connection"); + protected static Logger LOGGER = LogManager.getLogger(Transaction.class.getName() + "." + "Transaction"); + protected Logger stmtLogger = LogManager.getLogger(Transaction.class.getName() + "." + "Statement"); + protected Logger lockLogger = LogManager.getLogger(Transaction.class.getName() + "." + "Lock"); + protected static Logger CONN_LOGGER = LogManager.getLogger(Transaction.class.getName() + "." + "Connection"); private static final ThreadLocal tls = new ThreadLocal(); private static final String START_TXN = "start_txn"; @@ -90,10 +94,12 @@ public class TransactionLegacy implements Closeable { try { JmxUtil.registerMBean("Transaction", "Transaction", s_mbean); } catch (Exception e) { - s_logger.error("Unable to register mbean for transaction", e); + LOGGER.error("Unable to register mbean for transaction", e); } } + private static final String CONNECTION_POOL_LIB_DBCP = "dbcp"; + private final LinkedList _stack; private long _id; @@ -153,8 +159,8 @@ public static TransactionLegacy open(final String name) { public static TransactionLegacy open(final String name, final short databaseId, final boolean forceDbChange) { TransactionLegacy txn = tls.get(); if (txn == null) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Creating the transaction: " + name); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Creating the transaction: " + name); } txn = new TransactionLegacy(name, false, databaseId); tls.set(txn); @@ -199,7 +205,7 @@ protected StackElement peekInStack(Object obj) { } public void registerLock(String sql) { - if (_txn && s_lockLogger.isDebugEnabled()) { + if (_txn && lockLogger.isDebugEnabled()) { Pair time = new Pair(sql, System.currentTimeMillis()); _lockTimes.add(time); } @@ -211,8 +217,8 @@ public boolean dbTxnStarted() { public static Connection getStandaloneConnectionWithException() throws SQLException { Connection conn = s_ds.getConnection(); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn)); + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn)); } return conn; } @@ -221,7 +227,7 @@ public static Connection getStandaloneConnection() { try { return getStandaloneConnectionWithException(); } catch (SQLException e) { - s_logger.error("Unexpected exception: ", e); + LOGGER.error("Unexpected exception: ", e); return null; } } @@ -229,12 +235,12 @@ public static Connection getStandaloneConnection() { public static Connection getStandaloneUsageConnection() { try { Connection conn = s_usageDS.getConnection(); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Retrieving a standalone connection for usage: dbconn" + System.identityHashCode(conn)); + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Retrieving a standalone connection for usage: dbconn" + System.identityHashCode(conn)); } return conn; } catch (SQLException e) { - s_logger.warn("Unexpected exception: ", e); + LOGGER.warn("Unexpected exception: ", e); return null; } } @@ -242,12 +248,12 @@ public static Connection getStandaloneUsageConnection() { public static Connection getStandaloneSimulatorConnection() { try { Connection conn = s_simulatorDS.getConnection(); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Retrieving a standalone connection for simulator: dbconn" + System.identityHashCode(conn)); + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Retrieving a standalone connection for simulator: dbconn" + System.identityHashCode(conn)); } return conn; } catch (SQLException e) { - s_logger.warn("Unexpected exception: ", e); + LOGGER.warn("Unexpected exception: ", e); return null; } } @@ -302,12 +308,12 @@ protected static boolean checkAnnotation(int stack, TransactionLegacy txn) { } // relax stack structure for several places that @DB required injection is not in place - s_logger.warn("Non-standard stack context that Transaction context is manaully placed into the calling chain. Stack chain: " + sb); + LOGGER.warn("Non-standard stack context that Transaction context is manaully placed into the calling chain. Stack chain: " + sb); return true; } protected static String buildName() { - if (s_logger.isDebugEnabled()) { + if (LOGGER.isDebugEnabled()) { final StackTraceElement[] stacks = Thread.currentThread().getStackTrace(); final StringBuilder str = new StringBuilder(); int i = 3, j = 3; @@ -399,14 +405,14 @@ public boolean release(final String name) { */ @Deprecated public void start() { - if (s_logger.isTraceEnabled()) { - s_logger.trace("txn: start requested by: " + buildName()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("txn: start requested by: " + buildName()); } _stack.push(new StackElement(START_TXN, null)); if (_txn) { - s_logger.trace("txn: has already been started."); + LOGGER.trace("txn: has already been started."); return; } @@ -415,10 +421,10 @@ public void start() { _txnTime = System.currentTimeMillis(); if (_conn != null) { try { - s_logger.trace("txn: set auto commit to false"); + LOGGER.trace("txn: set auto commit to false"); _conn.setAutoCommit(false); } catch (final SQLException e) { - s_logger.warn("Unable to set auto commit: ", e); + LOGGER.warn("Unable to set auto commit: ", e); throw new CloudRuntimeException("Unable to set auto commit: ", e); } } @@ -427,8 +433,8 @@ public void start() { protected void closePreviousStatement() { if (_stmt != null) { try { - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Closing: " + _stmt.toString()); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Closing: " + _stmt.toString()); } try { ResultSet rs = _stmt.getResultSet(); @@ -436,11 +442,11 @@ protected void closePreviousStatement() { rs.close(); } } catch (SQLException e) { - s_stmtLogger.trace("Unable to close resultset"); + stmtLogger.trace("Unable to close resultset"); } _stmt.close(); } catch (final SQLException e) { - s_stmtLogger.trace("Unable to close statement: " + _stmt.toString()); + stmtLogger.trace("Unable to close statement: " + _stmt.toString()); } finally { _stmt = null; } @@ -467,8 +473,8 @@ public PreparedStatement prepareAutoCloseStatement(final String sql) throws SQLE public PreparedStatement prepareStatement(final String sql) throws SQLException { final Connection conn = getConnection(); final PreparedStatement pstmt = conn.prepareStatement(sql); - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Preparing: " + sql); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Preparing: " + sql); } return pstmt; } @@ -487,8 +493,8 @@ public PreparedStatement prepareStatement(final String sql) throws SQLException public PreparedStatement prepareAutoCloseStatement(final String sql, final int autoGeneratedKeys) throws SQLException { final Connection conn = getConnection(); final PreparedStatement pstmt = conn.prepareStatement(sql, autoGeneratedKeys); - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Preparing: " + sql); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Preparing: " + sql); } closePreviousStatement(); _stmt = pstmt; @@ -509,8 +515,8 @@ public PreparedStatement prepareAutoCloseStatement(final String sql, final int a public PreparedStatement prepareAutoCloseStatement(final String sql, final String[] columnNames) throws SQLException { final Connection conn = getConnection(); final PreparedStatement pstmt = conn.prepareStatement(sql, columnNames); - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Preparing: " + sql); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Preparing: " + sql); } closePreviousStatement(); _stmt = pstmt; @@ -530,8 +536,8 @@ public PreparedStatement prepareAutoCloseStatement(final String sql, final Strin public PreparedStatement prepareAutoCloseStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { final Connection conn = getConnection(); final PreparedStatement pstmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Preparing: " + sql); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Preparing: " + sql); } closePreviousStatement(); _stmt = pstmt; @@ -556,7 +562,7 @@ public Connection getConnection() throws SQLException { if (s_ds != null) { _conn = s_ds.getConnection(); } else { - s_logger.warn("A static-initialized variable becomes null, process is dying?"); + LOGGER.warn("A static-initialized variable becomes null, process is dying?"); throw new CloudRuntimeException("Database is not initialized, process is dying?"); } break; @@ -564,7 +570,7 @@ public Connection getConnection() throws SQLException { if (s_usageDS != null) { _conn = s_usageDS.getConnection(); } else { - s_logger.warn("A static-initialized variable becomes null, process is dying?"); + LOGGER.warn("A static-initialized variable becomes null, process is dying?"); throw new CloudRuntimeException("Database is not initialized, process is dying?"); } break; @@ -572,7 +578,7 @@ public Connection getConnection() throws SQLException { if (s_simulatorDS != null) { _conn = s_simulatorDS.getConnection(); } else { - s_logger.warn("A static-initialized variable becomes null, process is dying?"); + LOGGER.warn("A static-initialized variable becomes null, process is dying?"); throw new CloudRuntimeException("Database is not initialized, process is dying?"); } break; @@ -588,12 +594,12 @@ public Connection getConnection() throws SQLException { // see http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html // _stack.push(new StackElement(CREATE_CONN, null)); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + " for " + _dbId + ": dbconn" + System.identityHashCode(_conn) + + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + " for " + _dbId + ": dbconn" + System.identityHashCode(_conn) + ". Stack: " + buildName()); } } else { - s_logger.trace("conn: Using existing DB connection"); + LOGGER.trace("conn: Using existing DB connection"); } return _conn; @@ -603,8 +609,8 @@ protected boolean takeOver(final String name, final boolean create) { if (_stack.size() != 0) { if (!create) { // If it is not a create transaction, then let's just use the current one. - if (s_logger.isTraceEnabled()) { - s_logger.trace("Using current transaction: " + toString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Using current transaction: " + toString()); } mark(name); return false; @@ -614,19 +620,19 @@ protected boolean takeOver(final String name, final boolean create) { if (se.type == CREATE_TXN) { // This create is called inside of another create. Which is ok? // We will let that create be responsible for cleaning up. - if (s_logger.isTraceEnabled()) { - s_logger.trace("Create using current transaction: " + toString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Create using current transaction: " + toString()); } mark(name); return false; } - s_logger.warn("Encountered a transaction that has leaked. Cleaning up. " + toString()); + LOGGER.warn("Encountered a transaction that has leaked. Cleaning up. " + toString()); cleanup(); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Took over the transaction: " + name); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Took over the transaction: " + name); } _stack.push(new StackElement(create ? CREATE_TXN : CURRENT_TXN, name)); _name = name; @@ -657,7 +663,7 @@ public void close() { removeUpTo(CURRENT_TXN, null); if (_stack.size() == 0) { - s_logger.trace("Transaction is done"); + LOGGER.trace("Transaction is done"); cleanup(); } } @@ -671,8 +677,8 @@ public void close() { */ public boolean close(final String name) { if (_name == null) { // Already cleaned up. - if (s_logger.isTraceEnabled()) { - s_logger.trace("Already cleaned up." + buildName()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Already cleaned up." + buildName()); } return true; } @@ -682,13 +688,13 @@ public boolean close(final String name) { return false; } - if (s_logger.isDebugEnabled() && _stack.size() > 2) { - s_logger.debug("Transaction is not closed properly: " + toString() + ". Called by " + buildName()); + if (LOGGER.isDebugEnabled() && _stack.size() > 2) { + LOGGER.debug("Transaction is not closed properly: " + toString() + ". Called by " + buildName()); } cleanup(); - s_logger.trace("All done"); + LOGGER.trace("All done"); return true; } @@ -697,9 +703,9 @@ protected boolean hasTxnInStack() { } protected void clearLockTimes() { - if (s_lockLogger.isDebugEnabled()) { + if (lockLogger.isDebugEnabled()) { for (Pair time : _lockTimes) { - s_lockLogger.trace("SQL " + time.first() + " took " + (System.currentTimeMillis() - time.second())); + lockLogger.trace("SQL " + time.first() + " took " + (System.currentTimeMillis() - time.second())); } _lockTimes.clear(); } @@ -707,7 +713,7 @@ protected void clearLockTimes() { public boolean commit() { if (!_txn) { - s_logger.warn("txn: Commit called when it is not a transaction: " + buildName()); + LOGGER.warn("txn: Commit called when it is not a transaction: " + buildName()); return false; } @@ -721,8 +727,8 @@ public boolean commit() { } if (hasTxnInStack()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("txn: Not committing because transaction started elsewhere: " + buildName() + " / " + toString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("txn: Not committing because transaction started elsewhere: " + buildName() + " / " + toString()); } return false; } @@ -731,7 +737,7 @@ public boolean commit() { try { if (_conn != null) { _conn.commit(); - s_logger.trace("txn: DB Changes committed. Time = " + (System.currentTimeMillis() - _txnTime)); + LOGGER.trace("txn: DB Changes committed. Time = " + (System.currentTimeMillis() - _txnTime)); clearLockTimes(); closeConnection(); } @@ -750,22 +756,22 @@ protected void closeConnection() { } if (_txn) { - s_connLogger.trace("txn: Not closing DB connection because we're still in a transaction."); + CONN_LOGGER.trace("txn: Not closing DB connection because we're still in a transaction."); return; } try { // we should only close db connection when it is not user managed if (_dbId != CONNECTED_DB) { - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Closing DB connection: dbconn" + System.identityHashCode(_conn)); + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Closing DB connection: dbconn" + System.identityHashCode(_conn)); } _conn.close(); _conn = null; s_mbean.removeTransaction(this); } } catch (final SQLException e) { - s_logger.warn("Unable to close connection", e); + LOGGER.warn("Unable to close connection", e); } } @@ -783,8 +789,8 @@ protected void removeUpTo(String type, Object ref) { } if (item.type == CURRENT_TXN) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Releasing the current txn: " + (item.ref != null ? item.ref : "")); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Releasing the current txn: " + (item.ref != null ? item.ref : "")); } } else if (item.type == CREATE_CONN) { closeConnection(); @@ -796,13 +802,13 @@ protected void removeUpTo(String type, Object ref) { _conn.rollback((Savepoint)ref); rollback = false; } catch (final SQLException e) { - s_logger.warn("Unable to rollback Txn.", e); + LOGGER.warn("Unable to rollback Txn.", e); } } } else if (item.type == STATEMENT) { try { - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Closing: " + ref.toString()); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Closing: " + ref.toString()); } Statement stmt = (Statement)ref; try { @@ -811,21 +817,21 @@ protected void removeUpTo(String type, Object ref) { rs.close(); } } catch (SQLException e) { - s_stmtLogger.trace("Unable to close resultset"); + stmtLogger.trace("Unable to close resultset"); } stmt.close(); } catch (final SQLException e) { - s_stmtLogger.trace("Unable to close statement: " + item); + stmtLogger.trace("Unable to close statement: " + item); } } else if (item.type == ATTACHMENT) { TransactionAttachment att = (TransactionAttachment)item.ref; - if (s_logger.isTraceEnabled()) { - s_logger.trace("Cleaning up " + att.getName()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Cleaning up " + att.getName()); } att.cleanup(); } } catch (Exception e) { - s_logger.error("Unable to clean up " + item, e); + LOGGER.error("Unable to clean up " + item, e); } } @@ -837,8 +843,8 @@ protected void removeUpTo(String type, Object ref) { protected void rollbackTransaction() { closePreviousStatement(); if (!_txn) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Rollback called for " + _name + " when there's no transaction: " + buildName()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Rollback called for " + _name + " when there's no transaction: " + buildName()); } return; } @@ -846,15 +852,15 @@ protected void rollbackTransaction() { _txn = false; try { if (_conn != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Rolling back the transaction: Time = " + (System.currentTimeMillis() - _txnTime) + " Name = " + _name + "; called by " + buildName()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Rolling back the transaction: Time = " + (System.currentTimeMillis() - _txnTime) + " Name = " + _name + "; called by " + buildName()); } _conn.rollback(); } clearLockTimes(); closeConnection(); } catch (final SQLException e) { - s_logger.warn("Unable to rollback", e); + LOGGER.warn("Unable to rollback", e); } } @@ -864,7 +870,7 @@ protected void rollbackSavepoint(Savepoint sp) { _conn.rollback(sp); } } catch (SQLException e) { - s_logger.warn("Unable to rollback to savepoint " + sp); + LOGGER.warn("Unable to rollback to savepoint " + sp); } if (!hasTxnInStack()) { @@ -980,7 +986,7 @@ private TransactionLegacy() { protected void finalize() throws Throwable { if (!(_conn == null && (_stack == null || _stack.size() == 0))) { assert (false) : "Oh Alex oh alex...something is wrong with how we're doing this"; - s_logger.error("Something went wrong that a transaction is orphaned before db connection is closed"); + LOGGER.error("Something went wrong that a transaction is orphaned before db connection is closed"); cleanup(); } } @@ -1019,6 +1025,21 @@ public static void initDataSource(String propsFileName) throws IOException { } } + private static T parseNumber(String value, Class type) { + if (value == null) { + return null; + } + try { + if (type.equals(Long.class)) { + return type.cast(Long.parseLong(value)); + } else { + return type.cast(Integer.parseInt(value)); + } + } catch (NumberFormatException ignored) { + return null; + } + } + @SuppressWarnings({"rawtypes", "unchecked"}) public static void initDataSource(Properties dbProps) { try { @@ -1026,12 +1047,15 @@ public static void initDataSource(Properties dbProps) { return; s_dbHAEnabled = Boolean.valueOf(dbProps.getProperty("db.ha.enabled")); - s_logger.info("Is Data Base High Availiability enabled? Ans : " + s_dbHAEnabled); + LOGGER.info("Is Data Base High Availiability enabled? Ans : " + s_dbHAEnabled); String loadBalanceStrategy = dbProps.getProperty("db.ha.loadBalanceStrategy"); // FIXME: If params are missing...default them???? - final int cloudMaxActive = Integer.parseInt(dbProps.getProperty("db.cloud.maxActive")); - final int cloudMaxIdle = Integer.parseInt(dbProps.getProperty("db.cloud.maxIdle")); - final long cloudMaxWait = Long.parseLong(dbProps.getProperty("db.cloud.maxWait")); + final Integer cloudMaxActive = parseNumber(dbProps.getProperty("db.cloud.maxActive"), Integer.class); + final Integer cloudMaxIdle = parseNumber(dbProps.getProperty("db.cloud.maxIdle"), Integer.class); + final Long cloudMaxWait = parseNumber(dbProps.getProperty("db.cloud.maxWait"), Long.class); + final Integer cloudMinIdleConnections = parseNumber(dbProps.getProperty("db.cloud.minIdleConnections"), Integer.class); + final Long cloudConnectionTimeout = parseNumber(dbProps.getProperty("db.cloud.connectionTimeout"), Long.class); + final Long cloudKeepAliveTimeout = parseNumber(dbProps.getProperty("db.cloud.keepAliveTime"), Long.class); final String cloudUsername = dbProps.getProperty("db.cloud.username"); final String cloudPassword = dbProps.getProperty("db.cloud.password"); final String cloudValidationQuery = dbProps.getProperty("db.cloud.validationQuery"); @@ -1049,7 +1073,7 @@ public static void initDataSource(Properties dbProps) { } else if (cloudIsolationLevel.equalsIgnoreCase("readuncommitted")) { isolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED; } else { - s_logger.warn("Unknown isolation level " + cloudIsolationLevel + ". Using read uncommitted"); + LOGGER.warn("Unknown isolation level " + cloudIsolationLevel + ". Using read uncommitted"); } final boolean cloudTestOnBorrow = Boolean.parseBoolean(dbProps.getProperty("db.cloud.testOnBorrow")); @@ -1070,14 +1094,19 @@ public static void initDataSource(Properties dbProps) { DriverLoader.loadDriver(cloudUriAndDriver.second()); // Default Data Source for CloudStack - s_ds = createDataSource(cloudUriAndDriver.first(), cloudUsername, cloudPassword, cloudMaxActive, cloudMaxIdle, cloudMaxWait, - cloudTimeBtwEvictionRunsMillis, cloudMinEvcitableIdleTimeMillis, cloudTestWhileIdle, cloudTestOnBorrow, - cloudValidationQuery, isolationLevel); + s_ds = createDataSource(dbProps.getProperty("db.cloud.connectionPoolLib"), cloudUriAndDriver.first(), + cloudUsername, cloudPassword, cloudMaxActive, cloudMaxIdle, cloudMaxWait, + cloudTimeBtwEvictionRunsMillis, cloudMinEvcitableIdleTimeMillis, cloudTestWhileIdle, + cloudTestOnBorrow, cloudValidationQuery, cloudMinIdleConnections, cloudConnectionTimeout, + cloudKeepAliveTimeout, isolationLevel, "cloud"); // Configure the usage db - final int usageMaxActive = Integer.parseInt(dbProps.getProperty("db.usage.maxActive")); - final int usageMaxIdle = Integer.parseInt(dbProps.getProperty("db.usage.maxIdle")); - final long usageMaxWait = Long.parseLong(dbProps.getProperty("db.usage.maxWait")); + final Integer usageMaxActive = parseNumber(dbProps.getProperty("db.usage.maxActive"), Integer.class); + final Integer usageMaxIdle = parseNumber(dbProps.getProperty("db.usage.maxIdle"), Integer.class); + final Long usageMaxWait = parseNumber(dbProps.getProperty("db.usage.maxWait"), Long.class); + final Integer usageMinIdleConnections = parseNumber(dbProps.getProperty("db.usage.minIdleConnections"), Integer.class); + final Long usageConnectionTimeout = parseNumber(dbProps.getProperty("db.usage.connectionTimeout"), Long.class); + final Long usageKeepAliveTimeout = parseNumber(dbProps.getProperty("db.usage.keepAliveTime"), Long.class); final String usageUsername = dbProps.getProperty("db.usage.username"); final String usagePassword = dbProps.getProperty("db.usage.password"); @@ -1086,15 +1115,19 @@ public static void initDataSource(Properties dbProps) { DriverLoader.loadDriver(usageUriAndDriver.second()); // Data Source for usage server - s_usageDS = createDataSource(usageUriAndDriver.first(), usageUsername, usagePassword, - usageMaxActive, usageMaxIdle, usageMaxWait, null, null, null, null, - null, isolationLevel); + s_usageDS = createDataSource(dbProps.getProperty("db.usage.connectionPoolLib"), usageUriAndDriver.first(), + usageUsername, usagePassword, usageMaxActive, usageMaxIdle, usageMaxWait, null, + null, null, null, null, + usageMinIdleConnections, usageConnectionTimeout, usageKeepAliveTimeout, isolationLevel, "usage"); try { // Configure the simulator db - final int simulatorMaxActive = Integer.parseInt(dbProps.getProperty("db.simulator.maxActive")); - final int simulatorMaxIdle = Integer.parseInt(dbProps.getProperty("db.simulator.maxIdle")); - final long simulatorMaxWait = Long.parseLong(dbProps.getProperty("db.simulator.maxWait")); + final Integer simulatorMaxActive = parseNumber(dbProps.getProperty("db.simulator.maxActive"), Integer.class); + final Integer simulatorMaxIdle = parseNumber(dbProps.getProperty("db.simulator.maxIdle"), Integer.class); + final Long simulatorMaxWait = parseNumber(dbProps.getProperty("db.simulator.maxWait"), Long.class); + final Integer simulatorMinIdleConnections = parseNumber(dbProps.getProperty("db.simulator.minIdleConnections"), Integer.class); + final Long simulatorConnectionTimeout = parseNumber(dbProps.getProperty("db.simulator.connectionTimeout"), Long.class); + final Long simulatorKeepAliveTimeout = parseNumber(dbProps.getProperty("db.simulator.keepAliveTime"), Long.class); final String simulatorUsername = dbProps.getProperty("db.simulator.username"); final String simulatorPassword = dbProps.getProperty("db.simulator.password"); @@ -1112,7 +1145,7 @@ public static void initDataSource(Properties dbProps) { simulatorConnectionUri = simulatorDriver + "://" + simulatorHost + ":" + simulatorPort + "/" + simulatorDbName + "?autoReconnect=" + simulatorAutoReconnect; } else { - s_logger.warn("db.simulator.uri was set, ignoring the following properties on db.properties: [db.simulator.driver, db.simulator.host, db.simulator.port, " + LOGGER.warn("db.simulator.uri was set, ignoring the following properties on db.properties: [db.simulator.driver, db.simulator.host, db.simulator.port, " + "db.simulator.name, db.simulator.autoReconnect]."); String[] splitUri = simulatorUri.split(":"); simulatorDriver = String.format("%s:%s", splitUri[0], splitUri[1]); @@ -1121,16 +1154,19 @@ public static void initDataSource(Properties dbProps) { DriverLoader.loadDriver(simulatorDriver); - s_simulatorDS = createDataSource(simulatorConnectionUri, simulatorUsername, simulatorPassword, - simulatorMaxActive, simulatorMaxIdle, simulatorMaxWait, null, null, null, null, cloudValidationQuery, isolationLevel); + s_simulatorDS = createDataSource(dbProps.getProperty("db.simulator.connectionPoolLib"), + simulatorConnectionUri, simulatorUsername, simulatorPassword, simulatorMaxActive, + simulatorMaxIdle, simulatorMaxWait, null, null, null, null, + cloudValidationQuery, simulatorMinIdleConnections, simulatorConnectionTimeout, + simulatorKeepAliveTimeout, isolationLevel, "simulator"); } catch (Exception e) { - s_logger.debug("Simulator DB properties are not available. Not initializing simulator DS"); + LOGGER.debug("Simulator DB properties are not available. Not initializing simulator DS"); } } catch (final Exception e) { - s_ds = getDefaultDataSource("cloud"); - s_usageDS = getDefaultDataSource("cloud_usage"); - s_simulatorDS = getDefaultDataSource("cloud_simulator"); - s_logger.warn( + s_ds = getDefaultDataSource(dbProps.getProperty("db.cloud.connectionPoolLib"), "cloud"); + s_usageDS = getDefaultDataSource(dbProps.getProperty("db.usage.connectionPoolLib"), "cloud_usage"); + s_simulatorDS = getDefaultDataSource(dbProps.getProperty("db.simulator.connectionPoolLib"), "simulator"); + LOGGER.warn( "Unable to load db configuration, using defaults with 5 connections. Falling back on assumed datasource on localhost:3306 using username:password=cloud:cloud. Please check your configuration", e); } @@ -1145,7 +1181,7 @@ protected static Pair getConnectionUriAndDriver(Properties dbPro driver = dbProps.getProperty(String.format("db.%s.driver", schema)); connectionUri = getPropertiesAndBuildConnectionUri(dbProps, loadBalanceStrategy, driver, useSSL, schema); } else { - s_logger.warn(String.format("db.%s.uri was set, ignoring the following properties for schema %s of db.properties: [host, port, name, driver, autoReconnect, url.params," + LOGGER.warn(String.format("db.%s.uri was set, ignoring the following properties for schema %s of db.properties: [host, port, name, driver, autoReconnect, url.params," + " replicas, ha.loadBalanceStrategy, ha.enable, failOverReadOnly, reconnectAtTxEnd, autoReconnectForPools, secondsBeforeRetrySource, queriesBeforeRetrySource, " + "initialTimeout].", schema, schema)); @@ -1154,7 +1190,7 @@ protected static Pair getConnectionUriAndDriver(Properties dbPro connectionUri = propertyUri; } - s_logger.info(String.format("Using the following URI to connect to %s database [%s].", schema, connectionUri)); + LOGGER.info(String.format("Using the following URI to connect to %s database [%s].", schema, connectionUri)); return new Pair<>(connectionUri, driver); } @@ -1170,7 +1206,7 @@ protected static String getPropertiesAndBuildConnectionUri(Properties dbProps, S if (s_dbHAEnabled) { dbHaParams = getDBHAParams(schema, dbProps); replicas = dbProps.getProperty(String.format("db.%s.replicas", schema)); - s_logger.info(String.format("The replicas configured for %s data base are %s.", schema, replicas)); + LOGGER.info(String.format("The replicas configured for %s data base are %s.", schema, replicas)); } return buildConnectionUri(loadBalanceStrategy, driver, useSSL, host, replicas, port, dbName, autoReconnect, urlParams, dbHaParams); @@ -1221,11 +1257,71 @@ protected static String buildConnectionUri(String loadBalanceStrategy, String dr /** * Creates a data source */ - private static DataSource createDataSource(String uri, String username, String password, + private static DataSource createDataSource(String connectionPoolLib, String uri, String username, String password, + Integer maxActive, Integer maxIdle, Long maxWait, Long timeBtwnEvictionRuns, Long minEvictableIdleTime, + Boolean testWhileIdle, Boolean testOnBorrow, String validationQuery, Integer minIdleConnections, + Long connectionTimeout, Long keepAliveTime, Integer isolationLevel, String dsName) { + LOGGER.debug("Creating datasource for database: {} with connection pool lib: {}", dsName, + connectionPoolLib); + if (CONNECTION_POOL_LIB_DBCP.equals(connectionPoolLib)) { + return createDbcpDataSource(uri, username, password, maxActive, maxIdle, maxWait, timeBtwnEvictionRuns, + minEvictableIdleTime, testWhileIdle, testOnBorrow, validationQuery, isolationLevel); + } + return createHikaricpDataSource(uri, username, password, maxActive, maxIdle, maxWait, minIdleConnections, + connectionTimeout, keepAliveTime, isolationLevel, dsName); + } + + private static DataSource createHikaricpDataSource(String uri, String username, String password, Integer maxActive, Integer maxIdle, Long maxWait, - Long timeBtwnEvictionRuns, Long minEvictableIdleTime, - Boolean testWhileIdle, Boolean testOnBorrow, - String validationQuery, Integer isolationLevel) { + Integer minIdleConnections, Long connectionTimeout, Long keepAliveTime, + Integer isolationLevel, String dsName) { + HikariConfig config = new HikariConfig(); + config.setJdbcUrl(uri); + config.setUsername(username); + config.setPassword(password); + + config.setPoolName(dsName); + + // Connection pool properties + config.setMaximumPoolSize(ObjectUtils.defaultIfNull(maxActive, 250)); + config.setIdleTimeout(ObjectUtils.defaultIfNull(maxIdle, 30) * 1000); + config.setMaxLifetime(ObjectUtils.defaultIfNull(maxWait, 600000L)); + config.setMinimumIdle(ObjectUtils.defaultIfNull(minIdleConnections, 5)); + config.setConnectionTimeout(ObjectUtils.defaultIfNull(connectionTimeout, 30000L)); + config.setKeepaliveTime(ObjectUtils.defaultIfNull(keepAliveTime, 600000L)); + + String isolationLevelString = "TRANSACTION_READ_COMMITTED"; + if (isolationLevel == Connection.TRANSACTION_SERIALIZABLE) { + isolationLevelString = "TRANSACTION_SERIALIZABLE"; + } else if (isolationLevel == Connection.TRANSACTION_READ_UNCOMMITTED) { + isolationLevelString = "TRANSACTION_READ_UNCOMMITTED"; + } else if (isolationLevel == Connection.TRANSACTION_REPEATABLE_READ) { + isolationLevelString = "TRANSACTION_REPEATABLE_READ"; + } + config.setTransactionIsolation(isolationLevelString); + + // Standard datasource config for MySQL + config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", "250"); + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); + // Additional config for MySQL + config.addDataSourceProperty("useServerPrepStmts", "true"); + config.addDataSourceProperty("useLocalSessionState", "true"); + config.addDataSourceProperty("rewriteBatchedStatements", "true"); + config.addDataSourceProperty("cacheResultSetMetadata", "true"); + config.addDataSourceProperty("cacheServerConfiguration", "true"); + config.addDataSourceProperty("elideSetAutoCommits", "true"); + config.addDataSourceProperty("maintainTimeStats", "false"); + + HikariDataSource dataSource = new HikariDataSource(config); + return dataSource; + } + + private static DataSource createDbcpDataSource(String uri, String username, String password, + Integer maxActive, Integer maxIdle, Long maxWait, + Long timeBtwnEvictionRuns, Long minEvictableIdleTime, + Boolean testWhileIdle, Boolean testOnBorrow, + String validationQuery, Integer isolationLevel) { ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(uri, username, password); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); GenericObjectPoolConfig config = createPoolConfig(maxActive, maxIdle, maxWait, timeBtwnEvictionRuns, minEvictableIdleTime, testWhileIdle, testOnBorrow); @@ -1266,6 +1362,44 @@ private static GenericObjectPoolConfig createPoolConfig(Integer maxActive, Integ return config; } + private static DataSource getDefaultDataSource(final String connectionPoolLib, final String database) { + LOGGER.debug("Creating default datasource for database: {} with connection pool lib: {}", + database, connectionPoolLib); + if (CONNECTION_POOL_LIB_DBCP.equalsIgnoreCase(connectionPoolLib)) { + return getDefaultDbcpDataSource(database); + } + return getDefaultHikaricpDataSource(database); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private static DataSource getDefaultHikaricpDataSource(final String database) { + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:mysql://localhost:3306/" + database + "?" + CONNECTION_PARAMS); + config.setUsername("cloud"); + config.setPassword("cloud"); + config.setPoolName(database); + config.setDriverClassName("com.mysql.cj.jdbc.Driver"); + config.setMaximumPoolSize(250); + config.setConnectionTimeout(1000); + config.setIdleTimeout(1000); + config.setKeepaliveTime(1000); + config.setMaxLifetime(1000); + config.setTransactionIsolation("TRANSACTION_READ_COMMITTED"); + config.setInitializationFailTimeout(-1L); + config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", "250"); + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); + return new HikariDataSource(config); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private static DataSource getDefaultDbcpDataSource(final String database) { + final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database + "?" + CONNECTION_PARAMS, "cloud", "cloud"); + final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); + final GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory); + return new PoolingDataSource(connectionPool); + } + private static String getDBHAParams(String dbName, Properties dbProps) { StringBuilder sb = new StringBuilder(); sb.append("failOverReadOnly=" + dbProps.getProperty("db." + dbName + ".failOverReadOnly")); @@ -1277,14 +1411,6 @@ private static String getDBHAParams(String dbName, Properties dbProps) { return sb.toString(); } - @SuppressWarnings({"unchecked", "rawtypes"}) - private static DataSource getDefaultDataSource(final String database) { - final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database + "?" + CONNECTION_PARAMS, "cloud", "cloud"); - final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); - final GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory); - return new PoolingDataSource(connectionPool); - } - /** * Used for unit testing primarily * diff --git a/framework/db/src/main/resources/META-INF/cloudstack/system/spring-framework-db-system-context.xml b/framework/db/src/main/resources/META-INF/cloudstack/system/spring-framework-db-system-context.xml index f532a5cdc6ca..84f81f3b1918 100644 --- a/framework/db/src/main/resources/META-INF/cloudstack/system/spring-framework-db-system-context.xml +++ b/framework/db/src/main/resources/META-INF/cloudstack/system/spring-framework-db-system-context.xml @@ -28,5 +28,5 @@ > - + diff --git a/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java b/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java index a2153fee506c..7ae7368e173e 100644 --- a/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java +++ b/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java @@ -36,10 +36,10 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.db.DbUtil; import com.cloud.utils.db.TransactionLegacy; @@ -150,13 +150,13 @@ public void cleanup() throws SecurityException, NoSuchFieldException, IllegalArg @Test public void getGlobalLock() throws SQLException { Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(1); Assert.assertTrue(DbUtil.getGlobalLock("TEST", 600)); - Mockito.verify(connection).prepareStatement(Matchers.anyString()); + Mockito.verify(connection).prepareStatement(ArgumentMatchers.anyString()); Mockito.verify(preparedStatement).close(); Mockito.verify(resultSet).close(); } @@ -164,13 +164,13 @@ public void getGlobalLock() throws SQLException { @Test public void getGlobalLockTimeout() throws SQLException { Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(0); Assert.assertFalse(DbUtil.getGlobalLock("TEST", 600)); - Mockito.verify(connection).prepareStatement(Matchers.anyString()); + Mockito.verify(connection).prepareStatement(ArgumentMatchers.anyString()); Mockito.verify(preparedStatement).close(); Mockito.verify(resultSet).close(); Mockito.verify(connection).close(); @@ -237,7 +237,7 @@ void releaseGlobalLockNotexisting() throws SQLException { @Test public void releaseGlobalLock() throws SQLException { - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(1); diff --git a/framework/db/src/test/java/com/cloud/utils/db/DbAnnotatedBase.java b/framework/db/src/test/java/com/cloud/utils/db/DbAnnotatedBase.java index 146f79adf0b0..8a010203b510 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/DbAnnotatedBase.java +++ b/framework/db/src/test/java/com/cloud/utils/db/DbAnnotatedBase.java @@ -21,13 +21,14 @@ import junit.framework.Assert; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; @Component @DB public class DbAnnotatedBase { - private static final Logger s_logger = Logger.getLogger(DbAnnotatedBase.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject DummyComponent _dummy; @@ -38,7 +39,7 @@ public void initTest() { } public void MethodWithClassDbAnnotated() { - s_logger.info("called"); + logger.info("called"); _dummy.sayHello(); } } diff --git a/framework/db/src/test/java/com/cloud/utils/db/ElementCollectionTest.java b/framework/db/src/test/java/com/cloud/utils/db/ElementCollectionTest.java index 44f183dc8cdd..aed076a6d6b8 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/ElementCollectionTest.java +++ b/framework/db/src/test/java/com/cloud/utils/db/ElementCollectionTest.java @@ -29,10 +29,8 @@ import junit.framework.TestCase; -import org.apache.log4j.Logger; public class ElementCollectionTest extends TestCase { - static final Logger s_logger = Logger.getLogger(ElementCollectionTest.class); ArrayList ar = null; List lst = null; Collection coll = null; diff --git a/framework/db/src/test/java/com/cloud/utils/db/GlobalLockTest.java b/framework/db/src/test/java/com/cloud/utils/db/GlobalLockTest.java index 19927edb81c5..afd756eb2700 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/GlobalLockTest.java +++ b/framework/db/src/test/java/com/cloud/utils/db/GlobalLockTest.java @@ -16,7 +16,8 @@ // under the License. package com.cloud.utils.db; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; @@ -27,10 +28,10 @@ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:/testContext.xml") public class GlobalLockTest { - public static final Logger s_logger = Logger.getLogger(GlobalLockTest.class); + protected Logger logger = LogManager.getLogger(getClass()); private final static GlobalLock WorkLock = GlobalLock.getInternLock("SecurityGroupWork"); - public static class Worker implements Runnable { + public class Worker implements Runnable { int id = 0; int timeoutSeconds = 10; int jobDuration = 2; @@ -54,7 +55,7 @@ public void run() { Thread.sleep(jobDuration * 1000); } } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while testing global lock."); + logger.debug("[ignored] interrupted while testing global lock."); } finally { if (locked) { boolean unlocked = WorkLock.unlock(); diff --git a/framework/db/src/test/java/com/cloud/utils/db/Merovingian2Test.java b/framework/db/src/test/java/com/cloud/utils/db/Merovingian2Test.java index eb8b96dc7472..37c0ba776d0d 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/Merovingian2Test.java +++ b/framework/db/src/test/java/com/cloud/utils/db/Merovingian2Test.java @@ -19,13 +19,14 @@ import junit.framework.Assert; import junit.framework.TestCase; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Before; import org.junit.Test; public class Merovingian2Test extends TestCase { - static final Logger s_logger = Logger.getLogger(Merovingian2Test.class); + protected Logger logger = LogManager.getLogger(Merovingian2Test.class); Merovingian2 _lockController = Merovingian2.createLockController(1234); @Override @@ -43,15 +44,15 @@ protected void tearDown() throws Exception { @Test public void testLockAndRelease() { - s_logger.info("Testing first acquire"); + logger.info("Testing first acquire"); boolean result = _lockController.acquire("first" + 1234, 5); Assert.assertTrue(result); - s_logger.info("Testing acquire of different lock"); + logger.info("Testing acquire of different lock"); result = _lockController.acquire("second" + 1234, 5); Assert.assertTrue(result); - s_logger.info("Testing reacquire of the same lock"); + logger.info("Testing reacquire of the same lock"); result = _lockController.acquire("first" + 1234, 5); Assert.assertTrue(result); @@ -61,14 +62,14 @@ public void testLockAndRelease() { count = _lockController.owns("second" + 1234); Assert.assertEquals(count, 1); - s_logger.info("Testing release of the first lock"); + logger.info("Testing release of the first lock"); result = _lockController.release("first" + 1234); Assert.assertTrue(result); count = _lockController.owns("first" + 1234); Assert.assertEquals(count, 1); - s_logger.info("Testing release of the second lock"); + logger.info("Testing release of the second lock"); result = _lockController.release("second" + 1234); Assert.assertTrue(result); diff --git a/framework/direct-download/pom.xml b/framework/direct-download/pom.xml index 3bb32319aaf9..1915377f2224 100644 --- a/framework/direct-download/pom.xml +++ b/framework/direct-download/pom.xml @@ -32,7 +32,7 @@ cloudstack-framework org.apache.cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/events/pom.xml b/framework/events/pom.xml index 21930ce23336..3f457920cc9a 100644 --- a/framework/events/pom.xml +++ b/framework/events/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/events/src/main/java/org/apache/cloudstack/framework/events/Event.java b/framework/events/src/main/java/org/apache/cloudstack/framework/events/Event.java index 4a3eaf9e68c0..7a14f385fa15 100644 --- a/framework/events/src/main/java/org/apache/cloudstack/framework/events/Event.java +++ b/framework/events/src/main/java/org/apache/cloudstack/framework/events/Event.java @@ -20,22 +20,49 @@ package org.apache.cloudstack.framework.events; import com.google.gson.Gson; +import com.google.gson.annotations.Expose; public class Event { + @Expose(serialize = false, deserialize = false) + Long eventId; + @Expose(serialize = false, deserialize = false) + String eventUuid; String eventCategory; String eventType; String eventSource; String resourceType; String resourceUUID; String description; + @Expose(serialize = false, deserialize = false) + Long resourceAccountId; + @Expose(serialize = false, deserialize = false) + String resourceAccountUuid; + @Expose(serialize = false, deserialize = false) + Long resourceDomainId; public Event(String eventSource, String eventCategory, String eventType, String resourceType, String resourceUUID) { - this.eventCategory = eventCategory; - this.eventType = eventType; - this.eventSource = eventSource; - this.resourceType = resourceType; - this.resourceUUID = resourceUUID; + setEventCategory(eventCategory); + setEventType(eventType); + setEventSource(eventSource); + setResourceType(resourceType); + setResourceUUID(resourceUUID); + } + + public Long getEventId() { + return eventId; + } + + public void setEventId(Long eventId) { + this.eventId = eventId; + } + + public String getEventUuid() { + return eventUuid; + } + + public void setEventUuid(String eventUuid) { + this.eventUuid = eventUuid; } public String getEventCategory() { @@ -68,7 +95,7 @@ public String getDescription() { public void setDescription(Object message) { Gson gson = new Gson(); - this.description = gson.toJson(message).toString(); + this.description = gson.toJson(message); } public void setDescription(String description) { @@ -90,4 +117,28 @@ public void setResourceUUID(String uuid) { public String getResourceUUID() { return resourceUUID; } + + public Long getResourceAccountId() { + return resourceAccountId; + } + + public void setResourceAccountId(Long resourceAccountId) { + this.resourceAccountId = resourceAccountId; + } + + public String getResourceAccountUuid() { + return resourceAccountUuid; + } + + public void setResourceAccountUuid(String resourceAccountUuid) { + this.resourceAccountUuid = resourceAccountUuid; + } + + public Long getResourceDomainId() { + return resourceDomainId; + } + + public void setResourceDomainId(Long resourceDomainId) { + this.resourceDomainId = resourceDomainId; + } } diff --git a/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventBus.java b/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventBus.java index 8c8c08fcfdf2..6cd6256ce81d 100644 --- a/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventBus.java +++ b/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventBus.java @@ -27,6 +27,8 @@ */ public interface EventBus { + String getName(); + /** * publish an event on to the event bus * diff --git a/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventDistributor.java b/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventDistributor.java new file mode 100644 index 000000000000..01185359d6f9 --- /dev/null +++ b/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventDistributor.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cloudstack.framework.events; + +import java.util.Map; + +import com.cloud.utils.component.Manager; + +public interface EventDistributor extends Manager { + /** + * Publish an event on to all the available event buses + * + * @param event event that needs to be published on the event bus + * @return Map of bus names and EventBusException for buses that failed with + * exception + */ + Map publish(Event event); +} diff --git a/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventDistributorImpl.java b/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventDistributorImpl.java new file mode 100644 index 000000000000..a67ff5cc9266 --- /dev/null +++ b/framework/events/src/main/java/org/apache/cloudstack/framework/events/EventDistributorImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cloudstack.framework.events; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; + +import org.apache.commons.lang3.StringUtils; + +import com.cloud.utils.component.ManagerBase; + +public class EventDistributorImpl extends ManagerBase implements EventDistributor { + + List eventBuses; + + public void setEventBuses(List eventBuses) { + this.eventBuses = eventBuses; + } + + @PostConstruct + public void init() { + logger.trace("Found {} event buses : {}", () -> eventBuses.size(), + () -> StringUtils.join(eventBuses.stream().map(x->x.getClass().getName()).toArray())); + } + + @Override + public Map publish(Event event) { + Map exceptions = new HashMap<>(); + if (event == null) { + return exceptions; + } + logger.trace("Publishing event [category: {}, type: {}]: {} to {} event buses", + event.getEventCategory(), event.getEventType(), + event.getDescription(), eventBuses.size()); + for (EventBus bus : eventBuses) { + try { + bus.publish(event); + } catch (EventBusException e) { + logger.warn("Failed to publish event [category: {}, type: {}] on bus {}", + event.getEventCategory(), event.getEventType(), bus.getName()); + logger.trace(event.getDescription()); + exceptions.put(bus.getName(), e); + } + } + return exceptions; + } + +} diff --git a/framework/events/src/test/java/org/apache/cloudstack/framework/events/EventDistributorImplTest.java b/framework/events/src/test/java/org/apache/cloudstack/framework/events/EventDistributorImplTest.java new file mode 100644 index 000000000000..8a8dd91b9d83 --- /dev/null +++ b/framework/events/src/test/java/org/apache/cloudstack/framework/events/EventDistributorImplTest.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.framework.events; + +import java.util.List; +import java.util.Map; + +import org.apache.commons.collections.MapUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class EventDistributorImplTest { + + @InjectMocks + EventDistributorImpl eventDistributor = new EventDistributorImpl(); + + @Test + public void testSetEventBuses() { + Assert.assertNull(ReflectionTestUtils.getField(eventDistributor, "eventBuses")); + EventBus eventBus = Mockito.mock(EventBus.class); + EventBus eventBus1 = Mockito.mock(EventBus.class); + eventDistributor.setEventBuses(List.of(eventBus, eventBus1)); + Assert.assertNotNull(ReflectionTestUtils.getField(eventDistributor, "eventBuses")); + } + + @Test + public void testPublishNullEvent() { + Map exceptionMap = eventDistributor.publish(null); + Assert.assertTrue(MapUtils.isEmpty(exceptionMap)); + } + + @Test + public void testPublishOneReturnsException() throws EventBusException { + String busName = "Test"; + EventBus eventBus = Mockito.mock(EventBus.class); + Mockito.doReturn(busName).when(eventBus).getName(); + Mockito.doThrow(EventBusException.class).when(eventBus).publish(Mockito.any(Event.class)); + EventBus eventBus1 = Mockito.mock(EventBus.class); + Mockito.doNothing().when(eventBus1).publish(Mockito.any(Event.class)); + eventDistributor.eventBuses = List.of(eventBus, eventBus1); + Map exceptionMap = eventDistributor.publish(Mockito.mock(Event.class)); + Assert.assertTrue(MapUtils.isNotEmpty(exceptionMap)); + Assert.assertEquals(1, exceptionMap.size()); + Assert.assertTrue(exceptionMap.containsKey(busName)); + } +} diff --git a/framework/ipc/pom.xml b/framework/ipc/pom.xml index 8f8a9d2de3ae..3c03ed04e283 100644 --- a/framework/ipc/pom.xml +++ b/framework/ipc/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java index b9aa12bc5b00..2eafe21e5936 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java @@ -29,11 +29,12 @@ import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; @SuppressWarnings("rawtypes") public class AsyncCallbackDispatcher implements AsyncCompletionCallback { - private static final Logger s_logger = Logger.getLogger(AsyncCallbackDispatcher.class); + protected Logger logger = LogManager.getLogger(getClass()); private Method _callbackMethod; private final T _targetObject; @@ -100,7 +101,7 @@ public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg }); return t; } catch (Throwable e) { - s_logger.error("Unexpected exception", e); + logger.error("Unexpected exception", e); } return null; diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/client/ClientTransportProvider.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/client/ClientTransportProvider.java index ae28f900e544..b2fbd60351a1 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/client/ClientTransportProvider.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/client/ClientTransportProvider.java @@ -23,7 +23,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.framework.serializer.MessageSerializer; import org.apache.cloudstack.framework.transport.TransportEndpoint; @@ -34,7 +35,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory; public class ClientTransportProvider implements TransportProvider { - final static Logger s_logger = Logger.getLogger(ClientTransportProvider.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final int DEFAULT_WORKER_POOL_SIZE = 5; private final Map _endpointSites = new HashMap(); @@ -72,7 +73,7 @@ protected void runInContext() { try { _connection.connect(_serverAddress, _serverPort); } catch (Throwable e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "error during ipc client initialization: " + e.getLocalizedMessage()); } } diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageBusBase.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageBusBase.java index c0713567cd6e..742fd90c33e0 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageBusBase.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageBusBase.java @@ -26,7 +26,8 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.framework.serializer.MessageSerializer; @@ -41,7 +42,7 @@ public class MessageBusBase implements MessageBus { private final SubscriptionNode _subscriberRoot; private MessageSerializer _messageSerializer; - private static final Logger s_logger = Logger.getLogger(MessageBusBase.class); + protected Logger logger = LogManager.getLogger(getClass()); public MessageBusBase() { _gate = new Gate(); @@ -65,8 +66,8 @@ public void subscribe(String subject, MessageSubscriber subscriber) { assert (subject != null); assert (subscriber != null); if (_gate.enter()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus subscribe"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus subscribe"); } try { SubscriptionNode current = locate(subject, null, true); @@ -85,8 +86,8 @@ public void subscribe(String subject, MessageSubscriber subscriber) { @Override public void unsubscribe(String subject, MessageSubscriber subscriber) { if (_gate.enter()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus unsubscribe"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus unsubscribe"); } try { if (subject != null) { @@ -109,8 +110,8 @@ public void unsubscribe(String subject, MessageSubscriber subscriber) { @Override public void clearAll() { if (_gate.enter()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus clearAll"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus clearAll"); } try { _subscriberRoot.clearAll(); @@ -128,8 +129,8 @@ public void clearAll() { @Override public void prune() { if (_gate.enter()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus prune"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus prune"); } try { doPrune(); @@ -164,11 +165,11 @@ public void publish(String senderAddress, String subject, PublishScope scope, Ob // publish cannot be in DB transaction, which may hold DB lock too long, and we are guarding this here if (!noDbTxn()){ String errMsg = "NO EVENT PUBLISH CAN BE WRAPPED WITHIN DB TRANSACTION!"; - s_logger.error(errMsg, new CloudRuntimeException(errMsg)); + logger.error(errMsg, new CloudRuntimeException(errMsg)); } if (_gate.enter(true)) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus publish"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus publish"); } try { List chainFromTop = new ArrayList(); @@ -326,7 +327,7 @@ public boolean enter(boolean wait) { try { wait(); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while guarding re-entrance on message bus."); + logger.debug("[ignored] interrupted while guarding re-entrance on message bus."); } } else { break; @@ -346,8 +347,8 @@ public void leave() { onGateOpen(); } finally { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Open gate of message bus"); + if (logger.isTraceEnabled()) { + logger.trace("Open gate of message bus"); } _reentranceCount--; assert (_reentranceCount == 0); diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDetector.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDetector.java index 4bcf9b1ebf42..6e8919ddc066 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDetector.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDetector.java @@ -18,10 +18,11 @@ */ package org.apache.cloudstack.framework.messagebus; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class MessageDetector implements MessageSubscriber { - private static final Logger s_logger = Logger.getLogger(MessageDetector.class); + protected Logger logger = LogManager.getLogger(getClass()); private MessageBus _messageBus; private String[] _subjects; @@ -33,7 +34,7 @@ public MessageDetector() { public void waitAny(long timeoutInMilliseconds) { if (timeoutInMilliseconds < 100) { - s_logger.warn("waitAny is passed with a too short time-out interval. " + timeoutInMilliseconds + "ms"); + logger.warn("waitAny is passed with a too short time-out interval. " + timeoutInMilliseconds + "ms"); timeoutInMilliseconds = 100; } @@ -41,7 +42,7 @@ public void waitAny(long timeoutInMilliseconds) { try { wait(timeoutInMilliseconds); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while waiting on any message."); + logger.debug("[ignored] interrupted while waiting on any message."); } } } diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDispatcher.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDispatcher.java index e93bbc2ad4ab..5584aa11ef9c 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDispatcher.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDispatcher.java @@ -25,10 +25,11 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class MessageDispatcher implements MessageSubscriber { - private static final Logger s_logger = Logger.getLogger(MessageDispatcher.class); + protected Logger logger = LogManager.getLogger(getClass()); private static Map, List> s_handlerCache = new HashMap, List>(); @@ -63,7 +64,7 @@ public static void removeDispatcher(Object targetObject) { } } - public static boolean dispatch(Object target, String subject, String senderAddress, Object args) { + public boolean dispatch(Object target, String subject, String senderAddress, Object args) { assert (subject != null); assert (target != null); @@ -74,20 +75,20 @@ public static boolean dispatch(Object target, String subject, String senderAddre try { handler.invoke(target, subject, senderAddress, args); } catch (IllegalArgumentException e) { - s_logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); + logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); throw new RuntimeException("IllegalArgumentException when invoking event handler for subject: " + subject); } catch (IllegalAccessException e) { - s_logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); + logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); throw new RuntimeException("IllegalAccessException when invoking event handler for subject: " + subject); } catch (InvocationTargetException e) { - s_logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); + logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); throw new RuntimeException("InvocationTargetException when invoking event handler for subject: " + subject); } return true; } - public static Method resolveHandler(Class handlerClz, String subject) { + public Method resolveHandler(Class handlerClz, String subject) { synchronized (s_handlerCache) { List handlerList = s_handlerCache.get(handlerClz); if (handlerList != null) { @@ -100,7 +101,7 @@ public static Method resolveHandler(Class handlerClz, String subject) { } } } else { - s_logger.error("Handler class " + handlerClz.getName() + " is not registered"); + logger.error("Handler class " + handlerClz.getName() + " is not registered"); } } @@ -112,8 +113,8 @@ private static boolean match(String expression, String param) { } private void buildHandlerMethodCache(Class handlerClz) { - if (s_logger.isInfoEnabled()) - s_logger.info("Build message handler cache for " + handlerClz.getName()); + if (logger.isInfoEnabled()) + logger.info("Build message handler cache for " + handlerClz.getName()); synchronized (s_handlerCache) { List handlerList = s_handlerCache.get(handlerClz); @@ -130,20 +131,20 @@ private void buildHandlerMethodCache(Class handlerClz) { method.setAccessible(true); handlerList.add(method); - if (s_logger.isInfoEnabled()) - s_logger.info("Add message handler " + handlerClz.getName() + "." + method.getName() + " to cache"); + if (logger.isInfoEnabled()) + logger.info("Add message handler " + handlerClz.getName() + "." + method.getName() + " to cache"); } } clz = clz.getSuperclass(); } } else { - if (s_logger.isInfoEnabled()) - s_logger.info("Message handler for class " + handlerClz.getName() + " is already in cache"); + if (logger.isInfoEnabled()) + logger.info("Message handler for class " + handlerClz.getName() + " is already in cache"); } } - if (s_logger.isInfoEnabled()) - s_logger.info("Done building message handler cache for " + handlerClz.getName()); + if (logger.isInfoEnabled()) + logger.info("Done building message handler cache for " + handlerClz.getName()); } } diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java index 24ccfe42afc5..3cc643956e93 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java @@ -32,7 +32,8 @@ import java.util.jar.JarEntry; import java.util.jar.JarInputStream; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; // @@ -40,7 +41,7 @@ // Credit: http://internna.blogspot.com/2007/11/java-5-retrieving-all-classes-from.html // public class OnwireClassRegistry { - private static final Logger s_logger = Logger.getLogger(OnwireClassRegistry.class); + protected Logger logger = LogManager.getLogger(getClass()); private List packages = new ArrayList(); private final Map> registry = new HashMap>(); @@ -89,7 +90,7 @@ public Class getOnwireClass(String onwireName) { return registry.get(onwireName); } - static Set> getClasses(String packageName) { + private Set> getClasses(String packageName) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); return getClasses(loader, packageName); } @@ -98,7 +99,7 @@ static Set> getClasses(String packageName) { // Following helper methods can be put in a separated helper class, // will do that later // - static Set> getClasses(ClassLoader loader, String packageName) { + private Set> getClasses(ClassLoader loader, String packageName) { Set> classes = new HashSet>(); String path = packageName.replace('.', '/'); try { @@ -123,14 +124,14 @@ static Set> getClasses(ClassLoader loader, String packageName) { } } } catch (IOException e) { - s_logger.debug("Encountered IOException", e); + logger.debug("Encountered IOException", e); } catch (ClassNotFoundException e) { - s_logger.info("[ignored] class not found", e); + logger.info("[ignored] class not found", e); } return classes; } - static Set> getFromDirectory(File directory, String packageName) throws ClassNotFoundException { + private Set> getFromDirectory(File directory, String packageName) throws ClassNotFoundException { Set> classes = new HashSet>(); if (directory.exists()) { for (String file : directory.list()) { @@ -140,9 +141,9 @@ static Set> getFromDirectory(File directory, String packageName) throws Class clazz = Class.forName(name); classes.add(clazz); } catch (ClassNotFoundException e) { - s_logger.info("[ignored] class not found in directory " + directory, e); + logger.info("[ignored] class not found in directory " + directory, e); } catch (Exception e) { - s_logger.debug("Encountered unexpect exception! ", e); + logger.debug("Encountered unexpect exception! ", e); } } else { File f = new File(directory.getPath() + "/" + file); @@ -155,7 +156,7 @@ static Set> getFromDirectory(File directory, String packageName) throws return classes; } - static Set> getFromJARFile(String jar, String packageName) throws IOException, ClassNotFoundException { + private Set> getFromJARFile(String jar, String packageName) throws IOException, ClassNotFoundException { Set> classes = new HashSet>(); try (JarInputStream jarFile = new JarInputStream(new FileInputStream(jar));) { JarEntry jarEntry; @@ -170,7 +171,7 @@ static Set> getFromJARFile(String jar, String packageName) throws IOExc Class clz = Class.forName(className.replace('/', '.')); classes.add(clz); } catch (ClassNotFoundException | NoClassDefFoundError e) { - s_logger.warn("Unable to load class from jar file", e); + logger.warn("Unable to load class from jar file", e); } } } diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/server/ServerTransportProvider.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/server/ServerTransportProvider.java index 06215a78b70d..2302fe4e39bc 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/server/ServerTransportProvider.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/server/ServerTransportProvider.java @@ -27,7 +27,8 @@ import org.apache.cloudstack.framework.transport.TransportPdu; import org.apache.cloudstack.framework.transport.TransportProvider; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bouncycastle.jce.provider.BouncyCastleProvider; import java.security.SecureRandom; @@ -38,7 +39,7 @@ import java.util.concurrent.Executors; public class ServerTransportProvider implements TransportProvider { - private static final Logger s_logger = Logger.getLogger(ServerTransportProvider.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final int DEFAULT_WORKER_POOL_SIZE = 5; @@ -150,7 +151,7 @@ protected void runInContext() { site.processOutput(); site.ackOutputProcessSignal(); } catch (Throwable e) { - s_logger.error("Unhandled exception", e); + logger.error("Unhandled exception", e); } } }); diff --git a/framework/ipc/src/main/resources/META-INF/cloudstack/core/spring-framework-ipc-core-context.xml b/framework/ipc/src/main/resources/META-INF/cloudstack/core/spring-framework-ipc-core-context.xml index 926a84a33ad7..9c9df4f579fb 100644 --- a/framework/ipc/src/main/resources/META-INF/cloudstack/core/spring-framework-ipc-core-context.xml +++ b/framework/ipc/src/main/resources/META-INF/cloudstack/core/spring-framework-ipc-core-context.xml @@ -25,7 +25,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" - > + > @@ -47,5 +47,5 @@ - + diff --git a/framework/ipc/src/test/resources/SampleManagementServerAppContext.xml b/framework/ipc/src/test/resources/SampleManagementServerAppContext.xml index fb21f2c2f50f..f6afd1620f81 100644 --- a/framework/ipc/src/test/resources/SampleManagementServerAppContext.xml +++ b/framework/ipc/src/test/resources/SampleManagementServerAppContext.xml @@ -18,13 +18,13 @@ under the License. --> @@ -51,12 +51,12 @@ - + - + diff --git a/framework/ipc/src/test/resources/log4j-cloud.xml b/framework/ipc/src/test/resources/log4j-cloud.xml index e9b1918b6e60..6bd50829d825 100644 --- a/framework/ipc/src/test/resources/log4j-cloud.xml +++ b/framework/ipc/src/test/resources/log4j-cloud.xml @@ -17,78 +17,57 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/jobs/pom.xml b/framework/jobs/pom.xml index 6da7a858ebae..a82f514635f6 100644 --- a/framework/jobs/pom.xml +++ b/framework/jobs/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java index 5575ab394ee6..465a80b62c7f 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java @@ -16,7 +16,8 @@ // under the License. package org.apache.cloudstack.framework.jobs; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.jobs.dao.AsyncJobJoinMapDao; @@ -33,7 +34,7 @@ import com.cloud.user.User; public class AsyncJobExecutionContext { - private static final Logger s_logger = Logger.getLogger(AsyncJobExecutionContext.class); + protected static Logger LOGGER = LogManager.getLogger(AsyncJobExecutionContext.class); private AsyncJob _job; @@ -132,24 +133,24 @@ public void disjoinJob(long joinedJobId) throws InsufficientCapacityException, Object exception = JobSerializerHelper.fromObjectSerializedString(record.getJoinResult()); if (exception != null && exception instanceof Exception) { if (exception instanceof InsufficientCapacityException) { - s_logger.error("Job " + joinedJobId + " failed with InsufficientCapacityException"); + LOGGER.error("Job " + joinedJobId + " failed with InsufficientCapacityException"); throw (InsufficientCapacityException)exception; } else if (exception instanceof ConcurrentOperationException) { - s_logger.error("Job " + joinedJobId + " failed with ConcurrentOperationException"); + LOGGER.error("Job " + joinedJobId + " failed with ConcurrentOperationException"); throw (ConcurrentOperationException)exception; } else if (exception instanceof ResourceUnavailableException) { - s_logger.error("Job " + joinedJobId + " failed with ResourceUnavailableException"); + LOGGER.error("Job " + joinedJobId + " failed with ResourceUnavailableException"); throw (ResourceUnavailableException)exception; } else { - s_logger.error("Job " + joinedJobId + " failed with exception"); + LOGGER.error("Job " + joinedJobId + " failed with exception"); throw new RuntimeException((Exception)exception); } } } else { - s_logger.error("Job " + joinedJobId + " failed without providing an error object"); + LOGGER.error("Job " + joinedJobId + " failed without providing an error object"); throw new RuntimeException("Job " + joinedJobId + " failed without providing an error object"); } } @@ -172,7 +173,7 @@ public static AsyncJobExecutionContext getCurrentExecutionContext() { // TODO, this has security implications, operations carried from API layer should always // set its context, otherwise, the fall-back here will use system security context // - s_logger.warn("Job is executed without a context, setup psudo job for the executing thread"); + LOGGER.warn("Job is executed without a context, setup psudo job for the executing thread"); if (CallContext.current() != null) context = registerPseudoExecutionContext(CallContext.current().getCallingAccountId(), CallContext.current().getCallingUserId()); diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobDaoImpl.java index 1914ff714602..a2f1f36b8637 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobDaoImpl.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.cloudstack.api.ApiConstants; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; import org.apache.cloudstack.jobs.JobInfo; @@ -37,7 +36,6 @@ import com.cloud.utils.db.TransactionLegacy; public class AsyncJobDaoImpl extends GenericDaoBase implements AsyncJobDao { - private static final Logger s_logger = Logger.getLogger(AsyncJobDaoImpl.class.getName()); private final SearchBuilder pendingAsyncJobSearch; private final SearchBuilder pendingAsyncJobsSearch; @@ -121,7 +119,7 @@ public AsyncJobVO findInstancePendingAsyncJob(String instanceType, long instance List l = listIncludingRemovedBy(sc); if (l != null && l.size() > 0) { if (l.size() > 1) { - s_logger.warn("Instance " + instanceType + "-" + instanceId + " has multiple pending async-job"); + logger.warn("Instance " + instanceType + "-" + instanceId + " has multiple pending async-job"); } return l.get(0); @@ -208,9 +206,9 @@ public void resetJobProcess(long msid, int jobResultCode, String jobResultMessag pstmt.setLong(6, msid); pstmt.execute(); } catch (SQLException e) { - s_logger.warn("Unable to reset job status for management server " + msid, e); + logger.warn("Unable to reset job status for management server " + msid, e); } catch (Throwable e) { - s_logger.warn("Unable to reset job status for management server " + msid, e); + logger.warn("Unable to reset job status for management server " + msid, e); } } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java index d70864c755b6..da7ba36c919f 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO; import org.apache.cloudstack.jobs.JobInfo; @@ -39,7 +38,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class AsyncJobJoinMapDaoImpl extends GenericDaoBase implements AsyncJobJoinMapDao { - public static final Logger s_logger = Logger.getLogger(AsyncJobJoinMapDaoImpl.class); private final SearchBuilder RecordSearch; private final SearchBuilder RecordSearchByOwner; @@ -202,7 +200,7 @@ public void completeJoin(long joinJobId, JobInfo.Status joinStatus, String joinR // // txn.commit(); // } catch (SQLException e) { -// s_logger.error("Unexpected exception", e); +// logger.error("Unexpected exception", e); // } // // return standaloneList; diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueDaoImpl.java index 00bd08d0a2ab..18a9160b6da4 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueDaoImpl.java @@ -22,7 +22,6 @@ import java.util.Date; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.impl.SyncQueueVO; @@ -33,7 +32,6 @@ import com.cloud.utils.db.TransactionLegacy; public class SyncQueueDaoImpl extends GenericDaoBase implements SyncQueueDao { - private static final Logger s_logger = Logger.getLogger(SyncQueueDaoImpl.class.getName()); SearchBuilder TypeIdSearch = createSearchBuilder(); @@ -60,9 +58,9 @@ public void ensureQueue(String syncObjType, long syncObjId) { pstmt.setString(4, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), dt)); pstmt.execute(); } catch (SQLException e) { - s_logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); + logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); } catch (Throwable e) { - s_logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); + logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); } } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueItemDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueItemDaoImpl.java index 29c3f1b289fb..756cbb7efb0f 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueItemDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueItemDaoImpl.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO; @@ -42,7 +41,6 @@ @DB public class SyncQueueItemDaoImpl extends GenericDaoBase implements SyncQueueItemDao { - private static final Logger s_logger = Logger.getLogger(SyncQueueItemDaoImpl.class); final GenericSearchBuilder queueIdSearch; final GenericSearchBuilder queueActiveItemSearch; @@ -116,9 +114,9 @@ public List getNextQueueItems(int maxItems) { l.add(item); } } catch (SQLException e) { - s_logger.error("Unexpected sql exception, ", e); + logger.error("Unexpected sql exception, ", e); } catch (Throwable e) { - s_logger.error("Unexpected exception, ", e); + logger.error("Unexpected exception, ", e); } return l; } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDao.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDao.java index 89601e6b5d20..b3bfda0334cf 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDao.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDao.java @@ -39,4 +39,5 @@ public interface VmWorkJobDao extends GenericDao { void expungeCompletedWorkJobs(Date cutDate); void expungeLeftoverWorkJobs(long msid); + int expungeByVmList(List vmIds, Long batchSize); } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java index 4a10727546ea..3b167498a377 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java @@ -24,11 +24,10 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; - import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO; import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO.Step; import org.apache.cloudstack.jobs.JobInfo; +import org.apache.commons.collections.CollectionUtils; import com.cloud.utils.DateUtil; import com.cloud.utils.db.Filter; @@ -43,7 +42,6 @@ import com.cloud.vm.VirtualMachine; public class VmWorkJobDaoImpl extends GenericDaoBase implements VmWorkJobDao { - private static final Logger s_logger = Logger.getLogger(VmWorkJobDaoImpl.class); protected SearchBuilder PendingWorkJobSearch; protected SearchBuilder PendingWorkJobByCommandSearch; @@ -159,8 +157,8 @@ public void expungeCompletedWorkJobs(final Date cutDate) { sc.setParameters("dispatcher", "VmWorkJobDispatcher"); List expungeList = listBy(sc); for (VmWorkJobVO job : expungeList) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Expunge completed work job-" + job.getId()); + if (logger.isDebugEnabled()) + logger.debug("Expunge completed work job-" + job.getId()); expunge(job.getId()); _baseJobDao.expunge(job.getId()); } @@ -190,10 +188,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) { pstmt.execute(); } catch (SQLException e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "SQL failed to delete vm work job: " + e.getLocalizedMessage()); } catch (Throwable e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "caught an error during delete vm work job: " + e.getLocalizedMessage()); } @@ -205,13 +203,25 @@ public void doInTransactionWithoutResult(TransactionStatus status) { pstmt.execute(); } catch (SQLException e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "SQL failed to delete async job: " + e.getLocalizedMessage()); } catch (Throwable e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "caught an error during delete async job: " + e.getLocalizedMessage()); } } }); } + + @Override + public int expungeByVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getVmInstanceId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java index 3c0f81d0bc19..47bf27bd6c4b 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java @@ -64,9 +64,6 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.management.ManagementServerHost; import org.apache.cloudstack.utils.identity.ManagementServerNode; -import org.apache.log4j.Logger; -import org.apache.log4j.MDC; -import org.apache.log4j.NDC; import com.cloud.cluster.ClusterManagerListener; import com.cloud.network.Network; @@ -109,6 +106,8 @@ import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; +import org.apache.logging.log4j.ThreadContext; + public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, ClusterManagerListener, Configurable { // Advanced public static final ConfigKey JobExpireMinutes = new ConfigKey("Advanced", Long.class, "job.expire.minutes", "1440", @@ -120,7 +119,6 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, "Time in seconds to wait in acquiring lock to submit a vm worker job", false); private static final ConfigKey HidePassword = new ConfigKey("Advanced", Boolean.class, "log.hide.password", "true", "If set to true, the password is hidden", true, ConfigKey.Scope.Global); - private static final Logger s_logger = Logger.getLogger(AsyncJobManagerImpl.class); private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds @@ -240,8 +238,8 @@ public long submitAsyncJob(AsyncJob job, boolean scheduleJobExecutionInContext) publishOnEventBus(job, "submit"); scheduleExecution(job, scheduleJobExecutionInContext); - if (s_logger.isDebugEnabled()) { - s_logger.debug("submit async job-" + job.getId() + ", details: " + StringUtils.cleanString(job.toString())); + if (logger.isDebugEnabled()) { + logger.debug("submit async job-" + job.getId() + ", details: " + StringUtils.cleanString(job.toString())); } return job.getId(); } @@ -283,7 +281,7 @@ public Long doInTransaction(TransactionStatus status) { } } catch (Exception e) { String errMsg = "Unable to schedule async job for command " + job.getCmd() + ", unexpected exception."; - s_logger.warn(errMsg, e); + logger.warn(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -292,16 +290,16 @@ public Long doInTransaction(TransactionStatus status) { @DB public void completeAsyncJob(final long jobId, final Status jobStatus, final int resultCode, final String resultObject) { String resultObj = null; - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { resultObj = convertHumanReadableJson(obfuscatePassword(resultObject, HidePassword.value())); - s_logger.debug("Complete async job-" + jobId + ", jobStatus: " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObj); + logger.debug("Complete async job-" + jobId + ", jobStatus: " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObj); } final AsyncJobVO job = _jobDao.findById(jobId); if (job == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus + ", resultCode: " + resultCode + ", result: " + + if (logger.isDebugEnabled()) { + logger.debug("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObj); } // still purge item from queue to avoid any blocking @@ -310,8 +308,8 @@ public void completeAsyncJob(final long jobId, final Status jobStatus, final int } if (job.getStatus() != JobInfo.Status.IN_PROGRESS) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("job-" + jobId + " is already completed."); + if (logger.isDebugEnabled()) { + logger.debug("job-" + jobId + " is already completed."); } // still purge item from queue to avoid any blocking _queueMgr.purgeAsyncJobQueueItemId(jobId); @@ -322,18 +320,18 @@ public void completeAsyncJob(final long jobId, final Status jobStatus, final int job.setResult(resultObject); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Publish async job-" + jobId + " complete on message bus"); + if (logger.isDebugEnabled()) { + logger.debug("Publish async job-" + jobId + " complete on message bus"); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Wake up jobs related to job-" + jobId); + if (logger.isDebugEnabled()) { + logger.debug("Wake up jobs related to job-" + jobId); } final List wakeupList = Transaction.execute(new TransactionCallback>() { @Override public List doInTransaction(final TransactionStatus status) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Update db status for job-" + jobId); + if (logger.isDebugEnabled()) { + logger.debug("Update db status for job-" + jobId); } job.setCompleteMsid(getMsid()); job.setStatus(jobStatus); @@ -351,8 +349,8 @@ public List doInTransaction(final TransactionStatus status) { job.setExecutingMsid(null); _jobDao.update(jobId, job); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Wake up jobs joined with job-" + jobId + " and disjoin all subjobs created from job- " + jobId); + if (logger.isDebugEnabled()) { + logger.debug("Wake up jobs joined with job-" + jobId + " and disjoin all subjobs created from job- " + jobId); } final List wakeupList = wakeupByJoinedJobCompletion(jobId); _joinMapDao.disjoinAllJobs(jobId); @@ -392,14 +390,14 @@ private String convertHumanReadableJson(String resultObj) { @Override @DB public void updateAsyncJobStatus(final long jobId, final int processStatus, final String resultObject) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus + ", result: " + resultObject); + if (logger.isDebugEnabled()) { + logger.debug("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus + ", result: " + resultObject); } final AsyncJobVO job = _jobDao.findById(jobId); if (job == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus); + if (logger.isDebugEnabled()) { + logger.debug("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus); } return; @@ -422,8 +420,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) { @Override @DB public void updateAsyncJobAttachment(final long jobId, final String instanceType, final Long instanceId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Update async-job attachment, job-" + jobId + ", instanceType: " + instanceType + ", instanceId: " + instanceId); + if (logger.isDebugEnabled()) { + logger.debug("Update async-job attachment, job-" + jobId + ", instanceType: " + instanceType + ", instanceId: " + instanceId); } final AsyncJobVO job = _jobDao.findById(jobId); @@ -488,8 +486,8 @@ public void completeJoin(long joinJobId, JobInfo.Status joinStatus, String joinR @Override public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObjId, long queueSizeLimit) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sync job-" + job.getId() + " execution on object " + syncObjType + "." + syncObjId); + if (logger.isDebugEnabled()) { + logger.debug("Sync job-" + job.getId() + " execution on object " + syncObjType + "." + syncObjId); } SyncQueueVO queue = null; @@ -565,7 +563,7 @@ private AsyncJobDispatcher findWakeupDispatcher(AsyncJob job) { return dispatcher; } } else { - s_logger.warn("job-" + job.getId() + " is scheduled for wakeup run, but there is no joining info anymore"); + logger.warn("job-" + job.getId() + " is scheduled for wakeup run, but there is no joining info anymore"); } } return null; @@ -589,19 +587,19 @@ public void run() { String related = job.getRelated(); String logContext = job.getShortUuid(); if (related != null && !related.isEmpty()) { - NDC.push("job-" + related + "/" + "job-" + job.getId()); + ThreadContext.push("job-" + related + "/" + "job-" + job.getId()); AsyncJob relatedJob = _jobDao.findByIdIncludingRemoved(Long.parseLong(related)); if (relatedJob != null) { logContext = relatedJob.getShortUuid(); } } else { - NDC.push("job-" + job.getId()); + ThreadContext.push("job-" + job.getId()); } - MDC.put("logcontextid", logContext); + ThreadContext.put("logcontextid", logContext); try { super.run(); } finally { - NDC.pop(); + ThreadContext.pop(); } } @@ -618,8 +616,8 @@ protected void runInContext() { } catch (Exception e) { // Due to co-existence of normal-dispatched-job/wakeup-dispatched-job, MBean register() call // is expected to fail under situations - if (s_logger.isTraceEnabled()) - s_logger.trace("Unable to register active job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); + if (logger.isTraceEnabled()) + logger.trace("Unable to register active job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); } _jobMonitor.registerActiveTask(runNumber, job.getId()); @@ -632,11 +630,11 @@ protected void runInContext() { logContext = relatedJob.getShortUuid(); } } - MDC.put("logcontextid", logContext); + ThreadContext.put("logcontextid", logContext); // execute the job - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing " + StringUtils.cleanString(job.toString())); + if (logger.isDebugEnabled()) { + logger.debug("Executing " + StringUtils.cleanString(job.toString())); } if ((getAndResetPendingSignals(job) & AsyncJob.Constants.SIGNAL_MASK_WAKEUP) != 0) { @@ -645,25 +643,25 @@ protected void runInContext() { jobDispatcher.runJob(job); } else { // TODO, job wakeup is not in use yet - if (s_logger.isTraceEnabled()) - s_logger.trace("Unable to find a wakeup dispatcher from the joined job: " + job); + if (logger.isTraceEnabled()) + logger.trace("Unable to find a wakeup dispatcher from the joined job: {}", () -> StringUtils.cleanString(job.toString())); } } else { AsyncJobDispatcher jobDispatcher = getDispatcher(job.getDispatcher()); if (jobDispatcher != null) { jobDispatcher.runJob(job); } else { - s_logger.error("Unable to find job dispatcher, job will be cancelled"); + logger.error("Unable to find job dispatcher, job will be cancelled"); completeAsyncJob(job.getId(), JobInfo.Status.FAILED, ApiErrorCode.INTERNAL_ERROR.getHttpCode(), null); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Done executing " + job.getCmd() + " for job-" + job.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Done executing " + job.getCmd() + " for job-" + job.getId()); } } catch (Throwable e) { - s_logger.error("Unexpected exception", e); + logger.error("Unexpected exception", e); completeAsyncJob(job.getId(), JobInfo.Status.FAILED, ApiErrorCode.INTERNAL_ERROR.getHttpCode(), null); } finally { // guard final clause as well @@ -678,8 +676,8 @@ protected void runInContext() { } catch (Exception e) { // Due to co-existence of normal-dispatched-job/wakeup-dispatched-job, MBean unregister() call // is expected to fail under situations - if (s_logger.isTraceEnabled()) - s_logger.trace("Unable to unregister job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); + if (logger.isTraceEnabled()) + logger.trace("Unable to unregister job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); } // @@ -689,7 +687,7 @@ protected void runInContext() { _jobMonitor.unregisterActiveTask(runNumber); } catch (Throwable e) { - s_logger.error("Double exception", e); + logger.error("Double exception", e); } } } @@ -709,8 +707,8 @@ private int getAndResetPendingSignals(AsyncJob job) { private void executeQueueItem(SyncQueueItemVO item, boolean fromPreviousSession) { AsyncJobVO job = _jobDao.findById(item.getContentId()); if (job != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Schedule queued job-" + job.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Schedule queued job-" + job.getId()); } job.setSyncSource(item); @@ -724,37 +722,37 @@ private void executeQueueItem(SyncQueueItemVO item, boolean fromPreviousSession) job.setExecutingMsid(getMsid()); _jobDao.update(job.getId(), job); } catch (Exception e) { - s_logger.warn("Unexpected exception while dispatching job-" + item.getContentId(), e); + logger.warn("Unexpected exception while dispatching job-" + item.getContentId(), e); try { _queueMgr.returnItem(item.getId()); } catch (Throwable thr) { - s_logger.error("Unexpected exception while returning job-" + item.getContentId() + " to queue", thr); + logger.error("Unexpected exception while returning job-" + item.getContentId() + " to queue", thr); } } try { scheduleExecution(job); } catch (RejectedExecutionException e) { - s_logger.warn("Execution for job-" + job.getId() + " is rejected, return it to the queue for next turn"); + logger.warn("Execution for job-" + job.getId() + " is rejected, return it to the queue for next turn"); try { _queueMgr.returnItem(item.getId()); } catch (Exception e2) { - s_logger.error("Unexpected exception while returning job-" + item.getContentId() + " to queue", e2); + logger.error("Unexpected exception while returning job-" + item.getContentId() + " to queue", e2); } try { job.setExecutingMsid(null); _jobDao.update(job.getId(), job); } catch (Exception e3) { - s_logger.warn("Unexpected exception while update job-" + item.getContentId() + " msid for bookkeeping"); + logger.warn("Unexpected exception while update job-" + item.getContentId() + " msid for bookkeeping"); } } } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find related job for queue item: " + item.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find related job for queue item: " + item.toString()); } _queueMgr.purgeItem(item.getId()); @@ -767,8 +765,8 @@ public void releaseSyncSource() { assert (executionContext != null); if (executionContext.getSyncSource() != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Release sync source for job-" + executionContext.getJob().getId() + " sync source: " + executionContext.getSyncSource().getContentType() + + if (logger.isDebugEnabled()) { + logger.debug("Release sync source for job-" + executionContext.getJob().getId() + " sync source: " + executionContext.getSyncSource().getContentType() + "-" + executionContext.getSyncSource().getContentId()); } @@ -825,8 +823,8 @@ private void checkQueue(long queueId) { try { SyncQueueItemVO item = _queueMgr.dequeueFromOne(queueId, getMsid()); if (item != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing sync queue item: " + item.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Executing sync queue item: " + item.toString()); } executeQueueItem(item, false); @@ -834,7 +832,7 @@ private void checkQueue(long queueId) { break; } } catch (Throwable e) { - s_logger.error("Unexpected exception when kicking sync queue-" + queueId, e); + logger.error("Unexpected exception when kicking sync queue-" + queueId, e); break; } } @@ -862,15 +860,15 @@ protected void runInContext() { protected void reallyRun() { try { if (!isAsyncJobsEnabled()) { - s_logger.info("A shutdown has been triggered. Not executing any async job"); + logger.info("A shutdown has been triggered. Not executing any async job"); return; } List l = _queueMgr.dequeueFromAny(getMsid(), MAX_ONETIME_SCHEDULE_SIZE); if (l != null && l.size() > 0) { for (SyncQueueItemVO item : l) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Execute sync-queue item: " + item.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Execute sync-queue item: " + item.toString()); } executeQueueItem(item, false); } @@ -884,7 +882,7 @@ protected void reallyRun() { scheduleExecution(job, false); } } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to execute queue item, ", e); + logger.error("Unexpected exception when trying to execute queue item, ", e); } } }; @@ -911,7 +909,7 @@ protected void runInContext() { public void reallyRun() { try { - s_logger.trace("Begin cleanup expired async-jobs"); + logger.trace("Begin cleanup expired async-jobs"); // forcefully cancel blocking queue items if they've been staying there for too long List blockItems = _queueMgr.getBlockedQueueItems(JobCancelThresholdMinutes.value() * 60000, false); @@ -919,7 +917,7 @@ public void reallyRun() { for (SyncQueueItemVO item : blockItems) { try { if (item.getContentType().equalsIgnoreCase(SyncQueueItem.AsyncJobContentType)) { - s_logger.info("Remove Job-" + item.getContentId() + " from Queue-" + item.getId() + " since it has been blocked for too long"); + logger.info("Remove Job-" + item.getContentId() + " from Queue-" + item.getId() + " since it has been blocked for too long"); completeAsyncJob(item.getContentId(), JobInfo.Status.FAILED, 0, "Job is cancelled as it has been blocking others for too long"); _jobMonitor.unregisterByJobId(item.getContentId()); @@ -928,7 +926,7 @@ public void reallyRun() { // purge the item and resume queue processing _queueMgr.purgeItem(item.getId()); } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to remove job from sync queue, ", e); + logger.error("Unexpected exception when trying to remove job from sync queue, ", e); } } } @@ -940,12 +938,12 @@ public void reallyRun() { List unfinishedJobs = _jobDao.getExpiredUnfinishedJobs(cutTime, 100); for (AsyncJobVO job : unfinishedJobs) { try { - s_logger.info("Expunging unfinished job-" + job.getId()); + logger.info("Expunging unfinished job-" + job.getId()); _jobMonitor.unregisterByJobId(job.getId()); expungeAsyncJob(job); } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to expunge job-" + job.getId(), e); + logger.error("Unexpected exception when trying to expunge job-" + job.getId(), e); } } @@ -953,17 +951,17 @@ public void reallyRun() { List completedJobs = _jobDao.getExpiredCompletedJobs(cutTime, 100); for (AsyncJobVO job : completedJobs) { try { - s_logger.info("Expunging completed job-" + job.getId()); + logger.info("Expunging completed job-" + job.getId()); expungeAsyncJob(job); } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to expunge job-" + job.getId(), e); + logger.error("Unexpected exception when trying to expunge job-" + job.getId(), e); } } - s_logger.trace("End cleanup expired async-jobs"); + logger.trace("End cleanup expired async-jobs"); } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to execute queue item, ", e); + logger.error("Unexpected exception when trying to execute queue item, ", e); } } }; @@ -1058,10 +1056,10 @@ public boolean configure(String name, Map params) throws Configu int apiPoolSize = cloudMaxActive / 2; int workPoolSize = (cloudMaxActive * 2) / 3; - s_logger.info("Start AsyncJobManager API executor thread pool in size " + apiPoolSize); + logger.info("Start AsyncJobManager API executor thread pool in size " + apiPoolSize); _apiJobExecutor = Executors.newFixedThreadPool(apiPoolSize, new NamedThreadFactory(AsyncJobManager.API_JOB_POOL_THREAD_PREFIX)); - s_logger.info("Start AsyncJobManager Work executor thread pool in size " + workPoolSize); + logger.info("Start AsyncJobManager Work executor thread pool in size " + workPoolSize); _workerJobExecutor = Executors.newFixedThreadPool(workPoolSize, new NamedThreadFactory(AsyncJobManager.WORK_JOB_POOL_THREAD_PREFIX)); } catch (final Exception e) { throw new ConfigurationException("Unable to load db.properties to configure AsyncJobManagerImpl"); @@ -1108,8 +1106,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) { // reset job status for all jobs running on this ms node final List jobs = _jobDao.getResetJobs(msid); for (final AsyncJobVO job : jobs) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cancel left-over job-" + job.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Cancel left-over job-" + job.getId()); } cleanupResources(job); job.setStatus(JobInfo.Status.FAILED); @@ -1120,8 +1118,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) { job.setLastUpdated(currentGMTTime); job.setRemoved(currentGMTTime); _jobDao.update(job.getId(), job); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Purge queue item for cancelled job-" + job.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Purge queue item for cancelled job-" + job.getId()); } _queueMgr.purgeAsyncJobQueueItemId(job.getId()); } @@ -1129,7 +1127,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { } }); } catch (Throwable e) { - s_logger.warn("Unexpected exception in cleaning up left over jobs for mamagement server node " + msid, e); + logger.warn("Unexpected exception in cleaning up left over jobs for mamagement server node " + msid, e); } } @@ -1141,7 +1139,7 @@ protected boolean cleanupResources(AsyncJobVO job) { try { ApiCommandResourceType resourceType = ApiCommandResourceType.fromString(job.getInstanceType()); if (resourceType == null) { - s_logger.warn("Unknown ResourceType. Skip Cleanup: " + job.getInstanceType()); + logger.warn("Unknown ResourceType. Skip Cleanup: " + job.getInstanceType()); return true; } switch (resourceType) { @@ -1153,7 +1151,7 @@ protected boolean cleanupResources(AsyncJobVO job) { return cleanupNetwork(job.getInstanceId()); } } catch (Exception e) { - s_logger.warn("Error while cleaning up resource: [" + job.getInstanceType().toString() + "] with Id: " + job.getInstanceId(), e); + logger.warn("Error while cleaning up resource: [" + job.getInstanceType().toString() + "] with Id: " + job.getInstanceId(), e); return false; } return true; @@ -1162,49 +1160,49 @@ protected boolean cleanupResources(AsyncJobVO job) { private boolean cleanupVolume(final long volumeId) { VolumeInfo vol = volFactory.getVolume(volumeId); if (vol == null) { - s_logger.warn("Volume not found. Skip Cleanup. VolumeId: " + volumeId); + logger.warn("Volume not found. Skip Cleanup. VolumeId: " + volumeId); return true; } if (vol.getState().isTransitional()) { - s_logger.debug("Cleaning up volume with Id: " + volumeId); + logger.debug("Cleaning up volume with Id: " + volumeId); boolean status = vol.stateTransit(Volume.Event.OperationFailed); cleanupFailedVolumesCreatedFromSnapshots(volumeId); return status; } - s_logger.debug("Volume not in transition state. Skip cleanup. VolumeId: " + volumeId); + logger.debug("Volume not in transition state. Skip cleanup. VolumeId: " + volumeId); return true; } private boolean cleanupVirtualMachine(final long vmId) throws Exception { VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(vmId); if (vmInstanceVO == null) { - s_logger.warn("Instance not found. Skip Cleanup. InstanceId: " + vmId); + logger.warn("Instance not found. Skip Cleanup. InstanceId: " + vmId); return true; } if (vmInstanceVO.getState().isTransitional()) { - s_logger.debug("Cleaning up Instance with Id: " + vmId); + logger.debug("Cleaning up Instance with Id: " + vmId); return virtualMachineManager.stateTransitTo(vmInstanceVO, VirtualMachine.Event.OperationFailed, vmInstanceVO.getHostId()); } - s_logger.debug("Instance not in transition state. Skip cleanup. InstanceId: " + vmId); + logger.debug("Instance not in transition state. Skip cleanup. InstanceId: " + vmId); return true; } private boolean cleanupNetwork(final long networkId) throws Exception { NetworkVO networkVO = networkDao.findById(networkId); if (networkVO == null) { - s_logger.warn("Network not found. Skip Cleanup. NetworkId: " + networkId); + logger.warn("Network not found. Skip Cleanup. NetworkId: " + networkId); return true; } if (Network.State.Implementing.equals(networkVO.getState())) { try { - s_logger.debug("Cleaning up Network with Id: " + networkId); + logger.debug("Cleaning up Network with Id: " + networkId); return networkOrchestrationService.stateTransitTo(networkVO, Network.Event.OperationFailed); } catch (final NoTransitionException e) { networkVO.setState(Network.State.Shutdown); networkDao.update(networkVO.getId(), networkVO); } } - s_logger.debug("Network not in transition state. Skip cleanup. NetworkId: " + networkId); + logger.debug("Network not in transition state. Skip cleanup. NetworkId: " + networkId); return true; } @@ -1216,7 +1214,7 @@ private void cleanupFailedVolumesCreatedFromSnapshots(final long volumeId) { _volsDao.remove(volumeId); } } catch (Exception e) { - s_logger.error("Unexpected exception while removing concurrent request meta data :" + e.getLocalizedMessage()); + logger.error("Unexpected exception while removing concurrent request meta data :" + e.getLocalizedMessage()); } } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobMonitor.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobMonitor.java index b1cac3e79a53..b2216cb75025 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobMonitor.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobMonitor.java @@ -25,7 +25,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.AsyncJob; import org.apache.cloudstack.framework.jobs.AsyncJobManager; @@ -37,7 +36,6 @@ import com.cloud.utils.component.ManagerBase; public class AsyncJobMonitor extends ManagerBase { - public static final Logger s_logger = Logger.getLogger(AsyncJobMonitor.class); @Inject private MessageBus _messageBus; @@ -86,7 +84,7 @@ private void heartbeat() { synchronized (this) { for (Map.Entry entry : _activeTasks.entrySet()) { if (entry.getValue().millisSinceLastJobHeartbeat() > _inactivityWarningThresholdMs) { - s_logger.warn("Task (job-" + entry.getValue().getJobId() + ") has been pending for " + logger.warn("Task (job-" + entry.getValue().getJobId() + ") has been pending for " + entry.getValue().millisSinceLastJobHeartbeat() / 1000 + " seconds"); } } @@ -110,7 +108,7 @@ protected void runInContext() { public void registerActiveTask(long runNumber, long jobId) { synchronized (this) { - s_logger.info("Add job-" + jobId + " into job monitoring"); + logger.info("Add job-" + jobId + " into job monitoring"); assert (_activeTasks.get(runNumber) == null); @@ -130,7 +128,7 @@ public void unregisterActiveTask(long runNumber) { ActiveTaskRecord record = _activeTasks.get(runNumber); assert (record != null); if (record != null) { - s_logger.info("Remove job-" + record.getJobId() + " from job monitoring"); + logger.info("Remove job-" + record.getJobId() + " from job monitoring"); if (record.isPoolThread()) _activePoolThreads.decrementAndGet(); @@ -148,7 +146,7 @@ public void unregisterByJobId(long jobId) { while (it.hasNext()) { Map.Entry entry = it.next(); if (entry.getValue().getJobId() == jobId) { - s_logger.info("Remove Job-" + entry.getValue().getJobId() + " from job monitoring due to job cancelling"); + logger.info("Remove Job-" + entry.getValue().getJobId() + " from job monitoring due to job cancelling"); if (entry.getValue().isPoolThread()) _activePoolThreads.decrementAndGet(); diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java index 735d7cf73e20..fa1d175c45f9 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java @@ -27,7 +27,8 @@ import java.lang.reflect.Type; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.exception.CloudRuntimeException; import com.google.gson.Gson; @@ -45,14 +46,14 @@ * Note: toPairList and appendPairList only support simple POJO objects currently */ public class JobSerializerHelper { - private static final Logger s_logger = Logger.getLogger(JobSerializerHelper.class); + protected static Logger LOGGER = LogManager.getLogger(JobSerializerHelper.class); public static final String token = "/"; private static Gson s_gson; static { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setVersion(1.5); - s_logger.debug("Job GSON Builder initialized."); + LOGGER.debug("Job GSON Builder initialized."); gsonBuilder.registerTypeAdapter(Class.class, new ClassTypeAdapter()); gsonBuilder.registerTypeAdapter(Throwable.class, new ThrowableTypeAdapter()); s_gson = gsonBuilder.create(); diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java index 2f97991e3e31..3397daa58191 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java @@ -22,7 +22,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.dao.SyncQueueDao; import org.apache.cloudstack.framework.jobs.dao.SyncQueueItemDao; @@ -36,7 +35,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManager { - public static final Logger s_logger = Logger.getLogger(SyncQueueManagerImpl.class.getName()); @Inject private SyncQueueDao _syncQueueDao; @@ -70,7 +68,7 @@ public SyncQueueVO doInTransaction(TransactionStatus status) { } }); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } return null; } @@ -84,7 +82,7 @@ public SyncQueueItemVO dequeueFromOne(final long queueId, final Long msid) { public SyncQueueItemVO doInTransaction(TransactionStatus status) { SyncQueueVO queueVO = _syncQueueDao.findById(queueId); if(queueVO == null) { - s_logger.error("Sync queue(id: " + queueId + ") does not exist"); + logger.error("Sync queue(id: " + queueId + ") does not exist"); return null; } @@ -109,19 +107,19 @@ public SyncQueueItemVO doInTransaction(TransactionStatus status) { return itemVO; } else { - if (s_logger.isDebugEnabled()) - s_logger.debug("Sync queue (" + queueId + ") is currently empty"); + if (logger.isDebugEnabled()) + logger.debug("Sync queue (" + queueId + ") is currently empty"); } } else { - if (s_logger.isDebugEnabled()) - s_logger.debug("There is a pending process in sync queue(id: " + queueId + ")"); + if (logger.isDebugEnabled()) + logger.debug("There is a pending process in sync queue(id: " + queueId + ")"); } return null; } }); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } return null; @@ -169,7 +167,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { return resultList; } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } return null; @@ -200,14 +198,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) { } }); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } } @Override @DB public void returnItem(final long queueItemId) { - s_logger.info("Returning queue item " + queueItemId + " back to queue for second try in case of DB deadlock"); + logger.info("Returning queue item " + queueItemId + " back to queue for second try in case of DB deadlock"); try { Transaction.execute(new TransactionCallbackNoReturn() { @Override @@ -228,7 +226,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { } }); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } } @@ -247,8 +245,8 @@ private boolean queueReadyToProcess(SyncQueueVO queueVO) { if (nActiveItems < queueVO.getQueueSizeLimit()) return true; - if (s_logger.isDebugEnabled()) - s_logger.debug("Queue (queue id, sync type, sync id) - (" + queueVO.getId() + if (logger.isDebugEnabled()) + logger.debug("Queue (queue id, sync type, sync id) - (" + queueVO.getId() + "," + queueVO.getSyncObjType() + ", " + queueVO.getSyncObjId() + ") is reaching concurrency limit " + queueVO.getQueueSizeLimit()); return false; @@ -266,8 +264,8 @@ public void purgeAsyncJobQueueItemId(long asyncJobId) { public void cleanupActiveQueueItems(Long msid, boolean exclusive) { List l = getActiveQueueItems(msid, false); for (SyncQueueItemVO item : l) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Discard left-over queue item: " + item.toString()); + if (logger.isInfoEnabled()) { + logger.info("Discard left-over queue item: " + item.toString()); } purgeItem(item.getId()); } diff --git a/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/AsyncJobTestDispatcher.java b/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/AsyncJobTestDispatcher.java index eb30a804978a..604eae74afc3 100644 --- a/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/AsyncJobTestDispatcher.java +++ b/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/AsyncJobTestDispatcher.java @@ -20,15 +20,12 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.jobs.JobInfo.Status; import com.cloud.utils.component.AdapterBase; public class AsyncJobTestDispatcher extends AdapterBase implements AsyncJobDispatcher { - private static final Logger s_logger = - Logger.getLogger(AsyncJobTestDispatcher.class); @Inject private AsyncJobManager _asyncJobMgr; @@ -45,14 +42,14 @@ public AsyncJobTestDispatcher() { public void runJob(final AsyncJob job) { _testDashboard.increaseConcurrency(); - s_logger.info("Execute job " + job.getId() + ", current concurrency " + _testDashboard.getConcurrencyCount()); + logger.info("Execute job " + job.getId() + ", current concurrency " + _testDashboard.getConcurrencyCount()); int interval = 3000; try { Thread.sleep(interval); } catch (InterruptedException e) { - s_logger.debug("[ignored] ."); + logger.debug("[ignored] ."); } _asyncJobMgr.completeAsyncJob(job.getId(), Status.SUCCEEDED, 0, null); diff --git a/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImplTest.java b/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImplTest.java new file mode 100644 index 000000000000..3e2bc15b1e0c --- /dev/null +++ b/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImplTest.java @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.framework.jobs.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; + +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@RunWith(MockitoJUnitRunner.class) +public class VmWorkJobDaoImplTest { + + @Spy + VmWorkJobDaoImpl vmWorkJobDaoImpl; + + @Test + public void testExpungeByVmListNoVms() { + Assert.assertEquals(0, vmWorkJobDaoImpl.expungeByVmList( + new ArrayList<>(), 100L)); + Assert.assertEquals(0, vmWorkJobDaoImpl.expungeByVmList( + null, 100L)); + } + + @Test + public void testExpungeByVmList() { + SearchBuilder sb = Mockito.mock(SearchBuilder.class); + SearchCriteria sc = Mockito.mock(SearchCriteria.class); + Mockito.when(sb.create()).thenReturn(sc); + Mockito.doAnswer((Answer) invocationOnMock -> { + Long batchSize = (Long)invocationOnMock.getArguments()[1]; + return batchSize == null ? 0 : batchSize.intValue(); + }).when(vmWorkJobDaoImpl).batchExpunge(Mockito.any(SearchCriteria.class), Mockito.anyLong()); + Mockito.when(vmWorkJobDaoImpl.createSearchBuilder()).thenReturn(sb); + final VmWorkJobVO mockedVO = Mockito.mock(VmWorkJobVO.class); + Mockito.when(sb.entity()).thenReturn(mockedVO); + List vmIds = List.of(1L, 2L); + Object[] array = vmIds.toArray(); + Long batchSize = 50L; + Assert.assertEquals(batchSize.intValue(), vmWorkJobDaoImpl.expungeByVmList(List.of(1L, 2L), batchSize)); + Mockito.verify(sc).setParameters("vmIds", array); + Mockito.verify(vmWorkJobDaoImpl, Mockito.times(1)) + .batchExpunge(sc, batchSize); + } +} diff --git a/framework/jobs/src/test/resources/AsyncJobManagerTestContext.xml b/framework/jobs/src/test/resources/AsyncJobManagerTestContext.xml index 4e5d76758777..e838c8da34df 100644 --- a/framework/jobs/src/test/resources/AsyncJobManagerTestContext.xml +++ b/framework/jobs/src/test/resources/AsyncJobManagerTestContext.xml @@ -22,7 +22,7 @@ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd @@ -34,5 +34,5 @@ class="org.apache.cloudstack.framework.jobs.AsyncJobManagerTestConfiguration" /> - + diff --git a/framework/jobs/src/test/resources/commonContext.xml b/framework/jobs/src/test/resources/commonContext.xml index 80d57f1d5f8c..b19bd755b48a 100644 --- a/framework/jobs/src/test/resources/commonContext.xml +++ b/framework/jobs/src/test/resources/commonContext.xml @@ -1,19 +1,19 @@ - > listeners = new CopyOnWriteArrayList>(); @@ -87,7 +88,7 @@ public T callWithContext(Callable callable) throws Exception { if (firstError == null) { firstError = t; } - log.error("Failed onEnterContext for listener: " + listener, t); + logger.error("Failed onEnterContext for listener: " + listener, t); } /* Stack data structure is used because in between onEnter and onLeave @@ -113,7 +114,7 @@ public T callWithContext(Callable callable) throws Exception { invocation.listener.onLeaveContext(invocation.data, reentry); } catch (Throwable t) { lastError = t; - log.error("Failed onLeaveContext for listener: [" + invocation.listener + "]", t); + logger.error("Failed onLeaveContext for listener: [" + invocation.listener + "]", t); } } diff --git a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/threadlocal/ManagedThreadLocal.java b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/threadlocal/ManagedThreadLocal.java index f323d9a212a1..96b9ad80324b 100644 --- a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/threadlocal/ManagedThreadLocal.java +++ b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/threadlocal/ManagedThreadLocal.java @@ -21,7 +21,8 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.managed.context.ManagedContextUtils; @@ -35,7 +36,7 @@ protected Map initialValue() { }; private static boolean s_validateContext = false; - private static final Logger log = Logger.getLogger(ManagedThreadLocal.class); + protected static Logger LOGGER = LogManager.getLogger(ManagedThreadLocal.class); @SuppressWarnings("unchecked") @Override @@ -71,7 +72,7 @@ public void remove() { private static void validateInContext(Object tl) { if (s_validateContext && !ManagedContextUtils.isInContext()) { String msg = "Using a managed thread local in a non managed context this WILL cause errors at runtime. TL [" + tl + "]"; - log.error(msg, new IllegalStateException(msg)); + LOGGER.error(msg, new IllegalStateException(msg)); } } diff --git a/framework/pom.xml b/framework/pom.xml index 94ca8877117e..79b1036eae76 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT diff --git a/framework/quota/pom.xml b/framework/quota/pom.xml index df49fbf4d6da..2e608d7a248f 100644 --- a/framework/quota/pom.xml +++ b/framework/quota/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManager.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManager.java index 44204e8d1167..f4ee2362c7e8 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManager.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManager.java @@ -16,11 +16,14 @@ //under the License. package org.apache.cloudstack.quota; +import com.cloud.user.AccountVO; import com.cloud.utils.component.Manager; import org.apache.cloudstack.quota.QuotaAlertManagerImpl.DeferredQuotaEmail; +import org.apache.cloudstack.quota.constant.QuotaConfig; public interface QuotaAlertManager extends Manager { + boolean isQuotaEmailTypeEnabledForAccount(AccountVO account, QuotaConfig.QuotaEmailTemplateTypes quotaEmailTemplateType); void checkAndSendQuotaAlertEmails(); void sendQuotaAlert(DeferredQuotaEmail emailToBeSent); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java index 555757ec8471..b26b3171f5b5 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java @@ -29,18 +29,20 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.constant.QuotaConfig.QuotaEmailTemplateTypes; import org.apache.cloudstack.quota.dao.QuotaAccountDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.text.StrSubstitutor; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.ObjectUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.domain.DomainVO; @@ -64,7 +66,6 @@ @Component public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertManager { - private static final Logger s_logger = Logger.getLogger(QuotaAlertManagerImpl.class); @Inject private AccountDao _accountDao; @@ -81,7 +82,10 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana @Inject private QuotaManager _quotaManager; - private boolean _lockAccountEnforcement = false; + @Inject + private QuotaEmailConfigurationDao quotaEmailConfigurationDao; + + protected boolean _lockAccountEnforcement = false; private String senderAddress; protected SMTPMailSender mailSender; @@ -126,69 +130,114 @@ public boolean configure(String name, Map params) throws Configu @Override public boolean start() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Starting Alert Manager"); + if (logger.isInfoEnabled()) { + logger.info("Starting Alert Manager"); } return true; } @Override public boolean stop() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Stopping Alert Manager"); + if (logger.isInfoEnabled()) { + logger.info("Stopping Alert Manager"); } return true; } + /** + * Returns whether a Quota email type is enabled or not for the provided account. + */ + @Override + public boolean isQuotaEmailTypeEnabledForAccount(AccountVO account, QuotaEmailTemplateTypes quotaEmailTemplateType) { + boolean quotaEmailsEnabled = QuotaConfig.QuotaEnableEmails.valueIn(account.getAccountId()); + if (!quotaEmailsEnabled) { + logger.debug("Configuration [{}] is disabled for account [{}]. Therefore, the account will not receive Quota email of type [{}].", QuotaConfig.QuotaEnableEmails.key(), account, quotaEmailTemplateType); + return false; + } + + QuotaEmailConfigurationVO quotaEmail = quotaEmailConfigurationDao.findByAccountIdAndEmailTemplateType(account.getAccountId(), quotaEmailTemplateType); + + boolean emailEnabled = quotaEmail == null || quotaEmail.isEnabled(); + if (emailEnabled) { + logger.debug("Quota email [{}] is enabled for account [{}].", quotaEmailTemplateType, account); + } else { + logger.debug("Quota email [{}] has been manually disabled for account [{}] through the API quotaConfigureEmail.", quotaEmailTemplateType, account); + } + return emailEnabled; + } + + @Override public void checkAndSendQuotaAlertEmails() { List deferredQuotaEmailList = new ArrayList(); - final BigDecimal zeroBalance = new BigDecimal(0); + + logger.info("Checking and sending quota alert emails."); for (final QuotaAccountVO quotaAccount : _quotaAcc.listAllQuotaAccount()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("checkAndSendQuotaAlertEmails accId=" + quotaAccount.getId()); - } - BigDecimal accountBalance = quotaAccount.getQuotaBalance(); - Date balanceDate = quotaAccount.getQuotaBalanceDate(); - Date alertDate = quotaAccount.getQuotaAlertDate(); - int lockable = quotaAccount.getQuotaEnforce(); - BigDecimal thresholdBalance = quotaAccount.getQuotaMinBalance(); - if (accountBalance != null) { - AccountVO account = _accountDao.findById(quotaAccount.getId()); - if (account == null) { - continue; // the account is removed - } - if (s_logger.isDebugEnabled()) { - s_logger.debug("checkAndSendQuotaAlertEmails: Check id=" + account.getId() + " bal=" + accountBalance + ", alertDate=" + alertDate + ", lockable=" + lockable); - } - if (accountBalance.compareTo(zeroBalance) < 0) { - if (_lockAccountEnforcement && (lockable == 1)) { - if (_quotaManager.isLockable(account)) { - s_logger.info("Locking account " + account.getAccountName() + " due to quota < 0."); - lockAccount(account.getId()); - } - } - if (alertDate == null || (balanceDate.after(alertDate) && getDifferenceDays(alertDate, new Date()) > 1)) { - s_logger.info("Sending alert " + account.getAccountName() + " due to quota < 0."); - deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY)); - } - } else if (accountBalance.compareTo(thresholdBalance) < 0) { - if (alertDate == null || (balanceDate.after(alertDate) && getDifferenceDays(alertDate, new Date()) > 1)) { - s_logger.info("Sending alert " + account.getAccountName() + " due to quota below threshold."); - deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW)); - } - } - } + checkQuotaAlertEmailForAccount(deferredQuotaEmailList, quotaAccount); } for (DeferredQuotaEmail emailToBeSent : deferredQuotaEmailList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("checkAndSendQuotaAlertEmails: Attempting to send quota alert email to users of account: " + emailToBeSent.getAccount().getAccountName()); - } + logger.debug("Attempting to send a quota alert email to users of account [{}].", emailToBeSent.getAccount().getAccountName()); sendQuotaAlert(emailToBeSent); } } + /** + * Checks a given quota account to see if they should receive any emails. First by checking if it has any balance at all, if its account can be found, then checks + * if they should receive either QUOTA_EMPTY or QUOTA_LOW emails, taking into account if these email templates are disabled or not for that account. + * */ + protected void checkQuotaAlertEmailForAccount(List deferredQuotaEmailList, QuotaAccountVO quotaAccount) { + logger.debug("Checking {} for email alerts.", quotaAccount); + BigDecimal accountBalance = quotaAccount.getQuotaBalance(); + + if (accountBalance == null) { + logger.debug("{} has a null balance, therefore it will not receive quota alert emails.", quotaAccount); + return; + } + + AccountVO account = _accountDao.findById(quotaAccount.getId()); + if (account == null) { + logger.debug("Account of {} is removed, thus it will not receive quota alert emails.", quotaAccount); + return; + } + + checkBalanceAndAddToEmailList(deferredQuotaEmailList, quotaAccount, account, accountBalance); + } + + private void checkBalanceAndAddToEmailList(List deferredQuotaEmailList, QuotaAccountVO quotaAccount, AccountVO account, BigDecimal accountBalance) { + Date balanceDate = quotaAccount.getQuotaBalanceDate(); + Date alertDate = quotaAccount.getQuotaAlertDate(); + int lockable = quotaAccount.getQuotaEnforce(); + BigDecimal thresholdBalance = quotaAccount.getQuotaMinBalance(); + + logger.debug("Checking {} with accountBalance [{}], alertDate [{}] and lockable [{}] to see if a quota alert email should be sent.", account, + accountBalance, DateUtil.displayDateInTimezone(QuotaManagerImpl.getUsageAggregationTimeZone(), alertDate), lockable); + + boolean shouldSendEmail = alertDate == null || (balanceDate.after(alertDate) && getDifferenceDays(alertDate, new Date()) > 1); + + if (accountBalance.compareTo(BigDecimal.ZERO) < 0) { + if (_lockAccountEnforcement && lockable == 1 && _quotaManager.isLockable(account)) { + logger.info("Locking {}, as quota balance is lower than 0.", account); + lockAccount(account.getId()); + } + + boolean quotaEmptyEmailEnabled = isQuotaEmailTypeEnabledForAccount(account, QuotaEmailTemplateTypes.QUOTA_EMPTY); + if (quotaEmptyEmailEnabled && shouldSendEmail) { + logger.debug("Adding {} to the deferred emails list, as quota balance is lower than 0.", account); + deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaEmailTemplateTypes.QUOTA_EMPTY)); + return; + } + } else if (accountBalance.compareTo(thresholdBalance) < 0) { + boolean quotaLowEmailEnabled = isQuotaEmailTypeEnabledForAccount(account, QuotaEmailTemplateTypes.QUOTA_LOW); + if (quotaLowEmailEnabled && shouldSendEmail) { + logger.debug("Adding {} to the deferred emails list, as quota balance [{}] is below the threshold [{}].", account, accountBalance, thresholdBalance); + deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaEmailTemplateTypes.QUOTA_LOW)); + return; + } + } + logger.debug("{} will not receive any quota alert emails in this round.", account); + } + @Override public void sendQuotaAlert(DeferredQuotaEmail emailToBeSent) { final AccountVO account = emailToBeSent.getAccount(); @@ -222,8 +271,8 @@ public void sendQuotaAlert(DeferredQuotaEmail emailToBeSent) { final Map subjectOptionMap = generateOptionMap(account, userNames, accountDomain, balanceStr, usageStr, emailType, false); final Map bodyOptionMap = generateOptionMap(account, userNames, accountDomain, balanceStr, usageStr, emailType, true); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Sending quota alert with values: accountName [%s], accountID [%s], accountUsers [%s], domainName [%s], domainID [%s].", + if (logger.isDebugEnabled()) { + logger.debug(String.format("Sending quota alert with values: accountName [%s], accountID [%s], accountUsers [%s], domainName [%s], domainID [%s].", account.getAccountName(), account.getUuid(), userNames, accountDomain.getName(), accountDomain.getUuid())); } @@ -237,14 +286,14 @@ public void sendQuotaAlert(DeferredQuotaEmail emailToBeSent) { sendQuotaAlert(account, emailRecipients, subject, body); emailToBeSent.sentSuccessfully(_quotaAcc); } catch (Exception e) { - s_logger.error(String.format("Unable to send quota alert email (subject=%s; body=%s) to account %s (%s) recipients (%s) due to error (%s)", subject, body, account.getAccountName(), + logger.error(String.format("Unable to send quota alert email (subject=%s; body=%s) to account %s (%s) recipients (%s) due to error (%s)", subject, body, account.getAccountName(), account.getUuid(), emailRecipients, e)); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Exception", e); + if (logger.isDebugEnabled()) { + logger.debug("Exception", e); } } } else { - s_logger.error(String.format("No quota email template found for type %s, cannot send quota alert email to account %s(%s)", emailType, account.getAccountName(), account.getUuid())); + logger.error(String.format("No quota email template found for type %s, cannot send quota alert email to account %s(%s)", emailType, account.getAccountName(), account.getUuid())); } } @@ -286,7 +335,7 @@ public Map generateOptionMap(AccountVO accountVO, String userNam return optionMap; } - public static long getDifferenceDays(Date d1, Date d2) { + public long getDifferenceDays(Date d1, Date d2) { long diff = d2.getTime() - d1.getTime(); return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS); } @@ -304,15 +353,15 @@ protected boolean lockAccount(long accountId) { acctForUpdate.setState(State.LOCKED); success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); } else { - if (s_logger.isInfoEnabled()) { - s_logger.info("Attempting to lock a non-enabled account, current state is " + account.getState() + " (accountId: " + accountId + "), locking failed."); + if (logger.isInfoEnabled()) { + logger.info("Attempting to lock a non-enabled account, current state is " + account.getState() + " (accountId: " + accountId + "), locking failed."); } } } else { - s_logger.warn("Failed to lock account " + accountId + ", account not found."); + logger.warn("Failed to lock account " + accountId + ", account not found."); } } catch (Exception e) { - s_logger.error("Exception occurred while locking account by Quota Alert Manager", e); + logger.error("Exception occurred while locking account by Quota Alert Manager", e); throw e; } finally { TransactionLegacy.open(opendb).close(); @@ -387,7 +436,7 @@ protected void sendQuotaAlert(Account account, List emails, String subje mailProperties.setContentType("text/html; charset=utf-8"); if (CollectionUtils.isEmpty(emails)) { - s_logger.warn(String.format("Account [%s] does not have users with email registered, " + logger.warn(String.format("Account [%s] does not have users with email registered, " + "therefore we are unable to send quota alert email with subject [%s] and content [%s].", account.getUuid(), subject, body)); return; } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java index f222f6596cf5..226a47bb7dfa 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java @@ -20,6 +20,7 @@ import java.math.RoundingMode; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.LinkedHashSet; @@ -36,6 +37,7 @@ import org.apache.cloudstack.quota.activationrule.presetvariables.GenericPresetVariable; import org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariableHelper; import org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariables; +import org.apache.cloudstack.quota.activationrule.presetvariables.Tariff; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.quota.dao.QuotaAccountDao; @@ -50,13 +52,12 @@ import org.apache.cloudstack.utils.bytescale.ByteScaleUtils; import org.apache.cloudstack.utils.jsinterpreter.JsInterpreter; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.cloudstack.utils.usage.UsageUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.time.DateUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVO; @@ -69,7 +70,6 @@ @Component public class QuotaManagerImpl extends ManagerBase implements QuotaManager { - private static final Logger s_logger = Logger.getLogger(QuotaManagerImpl.class.getName()); @Inject private AccountDao _accountDao; @@ -89,8 +89,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { @Inject protected PresetVariableHelper presetVariableHelper; - private TimeZone _usageTimezone; - private int _aggregationDuration = 0; + private static TimeZone usageAggregationTimeZone = TimeZone.getTimeZone("GMT"); static final BigDecimal GiB_DECIMAL = BigDecimal.valueOf(ByteScaleUtils.GiB); List lockablesAccountTypes = Arrays.asList(Account.Type.NORMAL, Account.Type.DOMAIN_ADMIN); @@ -116,36 +115,28 @@ public boolean configure(String name, Map params) throws Configu mergeConfigs(configs, params); } - String aggregationRange = configs.get("usage.stats.job.aggregation.range"); - String timeZoneStr = configs.get("usage.aggregation.timezone"); - - if (timeZoneStr == null) { - timeZoneStr = "GMT"; - } - _usageTimezone = TimeZone.getTimeZone(timeZoneStr); - - _aggregationDuration = Integer.parseInt(aggregationRange); - if (_aggregationDuration < UsageUtils.USAGE_AGGREGATION_RANGE_MIN) { - s_logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + UsageUtils.USAGE_AGGREGATION_RANGE_MIN); - _aggregationDuration = UsageUtils.USAGE_AGGREGATION_RANGE_MIN; - } - s_logger.info("Usage timezone = " + _usageTimezone + " AggregationDuration=" + _aggregationDuration); + String usageAggregationTimeZoneStr = ObjectUtils.defaultIfNull(configs.get("usage.aggregation.timezone"), "GMT"); + usageAggregationTimeZone = TimeZone.getTimeZone(usageAggregationTimeZoneStr); return true; } + public static TimeZone getUsageAggregationTimeZone() { + return usageAggregationTimeZone; + } + @Override public boolean start() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Starting Quota Manager"); + if (logger.isInfoEnabled()) { + logger.info("Starting Quota Manager"); } return true; } @Override public boolean stop() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Stopping Quota Manager"); + if (logger.isInfoEnabled()) { + logger.info("Stopping Quota Manager"); } return true; } @@ -154,7 +145,7 @@ protected void processQuotaBalanceForAccount(AccountVO accountVo, List new Pair<>(quotaUsageVO.getStartDate(), quotaUsageVO.getEndDate())) .collect(Collectors.toCollection(LinkedHashSet::new)); - s_logger.info(String.format("Processing quota balance for account[%s] between [%s] and [%s].", accountToString, startDate, lastQuotaUsageEndDate)); + logger.info(String.format("Processing quota balance for account[{}] between [{}] and [{}].", accountToString, startDate, lastQuotaUsageEndDate)); long accountId = accountVo.getAccountId(); long domainId = accountVo.getDomainId(); @@ -220,13 +211,13 @@ protected BigDecimal retrieveBalanceForUsageCalculation(long accountId, long dom accountBalance = accountBalance.add(aggregateCreditBetweenDates(accountId, domainId, new Date(0), startDate, accountToString)); QuotaBalanceVO firstBalance = new QuotaBalanceVO(accountId, domainId, accountBalance, startDate); - s_logger.debug(String.format("Persisting the first quota balance [%s] for account [%s].", firstBalance, accountToString)); + logger.debug(String.format("Persisting the first quota balance [%s] for account [%s].", firstBalance, accountToString)); _quotaBalanceDao.saveQuotaBalance(firstBalance); } else { QuotaBalanceVO lastRealBalance = _quotaBalanceDao.findLastBalanceEntry(accountId, domainId, startDate); if (lastRealBalance == null) { - s_logger.warn(String.format("Account [%s] has quota usage entries, however it does not have a quota balance.", accountToString)); + logger.warn("Account [{}] has quota usage entries, however it does not have a quota balance.", accountToString); } else { accountBalance = accountBalance.add(lastRealBalance.getCreditBalance()); } @@ -253,17 +244,20 @@ protected void saveQuotaAccount(long accountId, BigDecimal aggregatedUsage, Date protected BigDecimal aggregateCreditBetweenDates(Long accountId, Long domainId, Date startDate, Date endDate, String accountToString) { List creditsReceived = _quotaBalanceDao.findCreditBalance(accountId, domainId, startDate, endDate); - s_logger.debug(String.format("Account [%s] has [%s] credit entries before [%s].", accountToString, creditsReceived.size(), endDate)); + logger.debug("Account [{}] has [{}] credit entries before [{}].", accountToString, creditsReceived.size(), + DateUtil.displayDateInTimezone(usageAggregationTimeZone, endDate)); BigDecimal aggregatedUsage = BigDecimal.ZERO; - s_logger.debug(String.format("Aggregating the account [%s] credit entries before [%s].", accountToString, endDate)); + logger.debug("Aggregating the account [{}] credit entries before [{}].", accountToString, + DateUtil.displayDateInTimezone(usageAggregationTimeZone, endDate)); for (QuotaBalanceVO credit : creditsReceived) { aggregatedUsage = aggregatedUsage.add(credit.getCreditBalance()); } - s_logger.debug(String.format("The aggregation of the account [%s] credit entries before [%s] resulted in the value [%s].", accountToString, endDate, aggregatedUsage)); + logger.debug("The aggregation of the account [{}] credit entries before [{}] resulted in the value [{}].", + accountToString, DateUtil.displayDateInTimezone(usageAggregationTimeZone, endDate), aggregatedUsage); return aggregatedUsage; } @@ -273,7 +267,7 @@ public boolean calculateQuotaUsage() { List accounts = _accountDao.listAll(); String accountsToString = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(accounts, "id", "uuid", "accountName", "domainId"); - s_logger.info(String.format("Starting quota usage calculation for accounts [%s].", accountsToString)); + logger.info(String.format("Starting quota usage calculation for accounts [%s].", accountsToString)); Map, Boolean>> mapQuotaTariffsPerUsageType = createMapQuotaTariffsPerUsageType(); @@ -281,7 +275,7 @@ public boolean calculateQuotaUsage() { List usageRecords = getPendingUsageRecordsForQuotaAggregation(account); if (usageRecords == null) { - s_logger.debug(String.format("Account [%s] does not have pending usage records. Skipping to next account.", account.reflectionToString())); + logger.debug(String.format("Account [%s] does not have pending usage records. Skipping to next account.", account.reflectionToString())); continue; } @@ -289,7 +283,7 @@ public boolean calculateQuotaUsage() { processQuotaBalanceForAccount(account, quotaUsages); } - s_logger.info(String.format("Finished quota usage calculation for accounts [%s].", accountsToString)); + logger.info(String.format("Finished quota usage calculation for accounts [%s].", accountsToString)); return true; } @@ -305,7 +299,7 @@ protected List getPendingUsageRecordsForQuotaAggregation(AccountVO acco return null; } - s_logger.debug(String.format("Retrieved [%s] pending usage records for account [%s].", usageRecords.second(), account.reflectionToString())); + logger.debug(String.format("Retrieved [%s] pending usage records for account [%s].", usageRecords.second(), account.reflectionToString())); return records; } @@ -313,7 +307,7 @@ protected List getPendingUsageRecordsForQuotaAggregation(AccountVO acco protected List createQuotaUsagesAccordingToQuotaTariffs(AccountVO account, List usageRecords, Map, Boolean>> mapQuotaTariffsPerUsageType) { String accountToString = account.reflectionToString(); - s_logger.info(String.format("Calculating quota usage of [%s] usage records for account [%s].", usageRecords.size(), accountToString)); + logger.info("Calculating quota usage of [{}] usage records for account [{}].", usageRecords.size(), accountToString); List> pairsUsageAndQuotaUsage = new ArrayList<>(); @@ -321,7 +315,7 @@ protected List createQuotaUsagesAccordingToQuotaTariffs(AccountVO for (UsageVO usageRecord : usageRecords) { int usageType = usageRecord.getUsageType(); - if (Boolean.FALSE.equals(shouldCalculateUsageRecord(account,usageRecord))) { + if (!shouldCalculateUsageRecord(account, usageRecord)) { pairsUsageAndQuotaUsage.add(new Pair<>(usageRecord, null)); continue; } @@ -337,7 +331,7 @@ protected List createQuotaUsagesAccordingToQuotaTariffs(AccountVO pairsUsageAndQuotaUsage.add(new Pair<>(usageRecord, quotaUsage)); } } catch (Exception e) { - s_logger.error(String.format("Failed to calculate the quota usage for account [%s] due to [%s].", accountToString, e.getMessage()), e); + logger.error(String.format("Failed to calculate the quota usage for account [%s] due to [%s].", accountToString, e.getMessage()), e); return new ArrayList<>(); } @@ -346,8 +340,8 @@ protected List createQuotaUsagesAccordingToQuotaTariffs(AccountVO protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO usageRecord) { if (Boolean.FALSE.equals(QuotaConfig.QuotaAccountEnabled.valueIn(accountVO.getAccountId()))) { - s_logger.debug(String.format("Considering usage record [%s] as calculated and skipping it because account [%s] has the quota plugin disabled.", - usageRecord, accountVO.reflectionToString())); + logger.debug("Considering usage record [{}] as calculated and skipping it because account [{}] has the quota plugin disabled.", + usageRecord.toString(usageAggregationTimeZone), accountVO.reflectionToString()); return false; } return true; @@ -373,20 +367,32 @@ protected List persistUsagesAndQuotaUsagesAndRetrievePersistedQuot protected BigDecimal aggregateQuotaTariffsValues(UsageVO usageRecord, List quotaTariffs, boolean hasAnyQuotaTariffWithActivationRule, JsInterpreter jsInterpreter, String accountToString) { - String usageRecordToString = usageRecord.toString(); - s_logger.debug(String.format("Validating usage record [%s] for account [%s] against [%s] quota tariffs.", usageRecordToString, accountToString, - quotaTariffs.size())); + String usageRecordToString = usageRecord.toString(usageAggregationTimeZone); + logger.debug("Validating usage record [{}] for account [{}] against [{}] quota tariffs.", usageRecordToString, accountToString, quotaTariffs.size()); PresetVariables presetVariables = getPresetVariables(hasAnyQuotaTariffWithActivationRule, usageRecord); BigDecimal aggregatedQuotaTariffsValue = BigDecimal.ZERO; + quotaTariffs.sort(Comparator.comparing(QuotaTariffVO::getPosition)); + + List lastTariffs = new ArrayList<>(); + + for (QuotaTariffVO quotaTariff : quotaTariffs) { if (isQuotaTariffInPeriodToBeApplied(usageRecord, quotaTariff, accountToString)) { - aggregatedQuotaTariffsValue = aggregatedQuotaTariffsValue.add(getQuotaTariffValueToBeApplied(quotaTariff, jsInterpreter, presetVariables)); + + BigDecimal tariffValue = getQuotaTariffValueToBeApplied(quotaTariff, jsInterpreter, presetVariables, lastTariffs); + + aggregatedQuotaTariffsValue = aggregatedQuotaTariffsValue.add(tariffValue); + + Tariff tariffPresetVariable = new Tariff(); + tariffPresetVariable.setId(quotaTariff.getUuid()); + tariffPresetVariable.setValue(tariffValue); + lastTariffs.add(tariffPresetVariable); } } - s_logger.debug(String.format("The aggregation of the quota tariffs resulted in the value [%s] for the usage record [%s]. We will use this value to calculate the final" + logger.debug(String.format("The aggregation of the quota tariffs resulted in the value [%s] for the usage record [%s]. We will use this value to calculate the final" + " usage value.", aggregatedQuotaTariffsValue, usageRecordToString)); return aggregatedQuotaTariffsValue; @@ -410,36 +416,37 @@ protected PresetVariables getPresetVariables(boolean hasAnyQuotaTariffWithActiva *

  • If the activation rule result in something else, returns {@link BigDecimal#ZERO}.
  • * */ - protected BigDecimal getQuotaTariffValueToBeApplied(QuotaTariffVO quotaTariff, JsInterpreter jsInterpreter, PresetVariables presetVariables) { + protected BigDecimal getQuotaTariffValueToBeApplied(QuotaTariffVO quotaTariff, JsInterpreter jsInterpreter, PresetVariables presetVariables, List lastAppliedTariffsList) { String activationRule = quotaTariff.getActivationRule(); BigDecimal quotaTariffValue = quotaTariff.getCurrencyValue(); - String quotaTariffToString = quotaTariff.toString(); + String quotaTariffToString = quotaTariff.toString(usageAggregationTimeZone); if (StringUtils.isEmpty(activationRule)) { - s_logger.debug(String.format("Quota tariff [%s] does not have an activation rule, therefore we will use the quota tariff value [%s] in the calculation.", + logger.debug(String.format("Quota tariff [%s] does not have an activation rule, therefore we will use the quota tariff value [%s] in the calculation.", quotaTariffToString, quotaTariffValue)); return quotaTariffValue; } injectPresetVariablesIntoJsInterpreter(jsInterpreter, presetVariables); + jsInterpreter.injectVariable("lastTariffs", lastAppliedTariffsList.toString()); String scriptResult = jsInterpreter.executeScript(activationRule).toString(); if (NumberUtils.isParsable(scriptResult)) { - s_logger.debug(String.format("The script [%s] of quota tariff [%s] had a numeric value [%s], therefore we will use it in the calculation.", activationRule, + logger.debug(String.format("The script [%s] of quota tariff [%s] had a numeric value [%s], therefore we will use it in the calculation.", activationRule, quotaTariffToString, scriptResult)); return new BigDecimal(scriptResult); } if (BooleanUtils.toBoolean(scriptResult)) { - s_logger.debug(String.format("The script [%s] of quota tariff [%s] had a true boolean result, therefore we will use the quota tariff's value [%s] in the calculation.", + logger.debug(String.format("The script [%s] of quota tariff [%s] had a true boolean result, therefore we will use the quota tariff's value [%s] in the calculation.", activationRule, quotaTariffToString, quotaTariffValue)); return quotaTariffValue; } - s_logger.debug(String.format("The script [%s] of quota tariff [%s] had the result [%s], therefore we will not use this quota tariff in the calculation.", activationRule, + logger.debug(String.format("The script [%s] of quota tariff [%s] had the result [%s], therefore we will not use this quota tariff in the calculation.", activationRule, quotaTariffToString, quotaTariffValue)); return BigDecimal.ZERO; @@ -475,10 +482,11 @@ protected boolean isQuotaTariffInPeriodToBeApplied(UsageVO usageRecord, QuotaTar Date quotaTariffEndDate = quotaTariff.getEndDate(); if ((quotaTariffEndDate != null && usageRecordStartDate.after(quotaTariffEndDate)) || usageRecordEndDate.before(quotaTariffStartDate)) { - s_logger.debug(String.format("Not applying quota tariff [%s] in usage record [%s] of account [%s] due to it is out of the period to be applied. Period of the usage" - + " record [startDate: %s, endDate: %s], period of the quota tariff [startDate: %s, endDate: %s].", quotaTariff, usageRecord.toString(), accountToString, - DateUtil.getOutputString(usageRecordStartDate), DateUtil.getOutputString(usageRecordEndDate), DateUtil.getOutputString(quotaTariffStartDate), - DateUtil.getOutputString(quotaTariffEndDate))); + logger.debug("Not applying quota tariff [{}] in usage record [{}] of account [{}] due to it is out of the period to be applied. Period of the usage" + + " record [startDate: {}, endDate: {}], period of the quota tariff [startDate: {}, endDate: {}].", quotaTariff.toString(usageAggregationTimeZone), + usageRecord.toString(usageAggregationTimeZone), accountToString, DateUtil.displayDateInTimezone(usageAggregationTimeZone, usageRecordStartDate), + DateUtil.displayDateInTimezone(usageAggregationTimeZone, usageRecordEndDate), DateUtil.displayDateInTimezone(usageAggregationTimeZone, quotaTariffStartDate), + DateUtil.displayDateInTimezone(usageAggregationTimeZone, quotaTariffEndDate)); return false; } @@ -504,23 +512,23 @@ protected Map, Boolean>> createMapQuotaTariffs } protected QuotaUsageVO createQuotaUsageAccordingToUsageUnit(UsageVO usageRecord, BigDecimal aggregatedQuotaTariffsValue, String accountToString) { - String usageRecordToString = usageRecord.toString(); + String usageRecordToString = usageRecord.toString(usageAggregationTimeZone); if (aggregatedQuotaTariffsValue.equals(BigDecimal.ZERO)) { - s_logger.debug(String.format("Usage record [%s] for account [%s] does not have quota tariffs to be calculated, therefore we will mark it as calculated.", - usageRecordToString, accountToString)); + logger.debug("No tariffs were applied to usage record [{}] of account [{}] or they resulted in 0; We will only mark the usage record as calculated.", + usageRecordToString, accountToString); return null; } QuotaTypes quotaType = QuotaTypes.listQuotaTypes().get(usageRecord.getUsageType()); String quotaUnit = quotaType.getQuotaUnit(); - s_logger.debug(String.format("Calculating value of usage record [%s] for account [%s] according to the aggregated quota tariffs value [%s] and its usage unit [%s].", + logger.debug(String.format("Calculating value of usage record [%s] for account [%s] according to the aggregated quota tariffs value [%s] and its usage unit [%s].", usageRecordToString, accountToString, aggregatedQuotaTariffsValue, quotaUnit)); BigDecimal usageValue = getUsageValueAccordingToUsageUnitType(usageRecord, aggregatedQuotaTariffsValue, quotaUnit); - s_logger.debug(String.format("The calculation of the usage record [%s] for account [%s] according to the aggregated quota tariffs value [%s] and its usage unit [%s] " + logger.debug(String.format("The calculation of the usage record [%s] for account [%s] according to the aggregated quota tariffs value [%s] and its usage unit [%s] " + "resulted in the value [%s].", usageRecordToString, accountToString, aggregatedQuotaTariffsValue, quotaUnit, usageValue)); QuotaUsageVO quotaUsageVo = new QuotaUsageVO(); @@ -565,7 +573,7 @@ protected BigDecimal getUsageValueAccordingToUsageUnitType(UsageVO usageRecord, protected BigDecimal getCostPerHour(BigDecimal costPerMonth, Date date) { BigDecimal hoursInCurrentMonth = BigDecimal.valueOf(DateUtil.getHoursInCurrentMonth(date)); - s_logger.trace(String.format("Dividing tariff cost per month [%s] by [%s] to get the tariffs cost per hour.", costPerMonth, hoursInCurrentMonth)); + logger.trace(String.format("Dividing tariff cost per month [%s] by [%s] to get the tariffs cost per hour.", costPerMonth, hoursInCurrentMonth)); return costPerMonth.divide(hoursInCurrentMonth, 8, RoundingMode.HALF_EVEN); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaStatementImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaStatementImpl.java index 9523c874558d..5ee327fb9a5c 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaStatementImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaStatementImpl.java @@ -31,9 +31,10 @@ import org.apache.cloudstack.quota.QuotaAlertManagerImpl.DeferredQuotaEmail; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.dao.QuotaAccountDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; +import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.user.AccountVO; @@ -42,7 +43,6 @@ @Component public class QuotaStatementImpl extends ManagerBase implements QuotaStatement { - private static final Logger s_logger = Logger.getLogger(QuotaStatementImpl.class); @Inject private AccountDao _accountDao; @@ -55,6 +55,12 @@ public class QuotaStatementImpl extends ManagerBase implements QuotaStatement { @Inject private ConfigurationDao _configDao; + @Inject + private QuotaEmailConfigurationDao quotaEmailConfigurationDao; + + @Inject + private QuotaEmailTemplatesDao quotaEmailTemplatesDao; + final public static int s_LAST_STATEMENT_SENT_DAYS = 6; //ideally should be less than 7 days public enum QuotaStatementPeriods { @@ -91,16 +97,16 @@ public boolean configure(String name, Map params) throws Configu @Override public boolean start() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Starting Statement Manager"); + if (logger.isInfoEnabled()) { + logger.info("Starting Statement Manager"); } return true; } @Override public boolean stop() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Stopping Statement Manager"); + if (logger.isInfoEnabled()) { + logger.info("Stopping Statement Manager"); } return true; } @@ -113,35 +119,40 @@ public void sendStatement() { if (quotaAccount.getQuotaBalance() == null) { continue; // no quota usage for this account ever, ignore } + AccountVO account = _accountDao.findById(quotaAccount.getId()); + if (account == null) { + logger.debug("Could not find an account corresponding to [{}]. Therefore, the statement email will not be sent.", quotaAccount); + continue; + } + + boolean quotaStatementEmailEnabled = _quotaAlert.isQuotaEmailTypeEnabledForAccount(account, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT); + if (!quotaStatementEmailEnabled) { + logger.debug("{} has [{}] email disabled. Therefore the email will not be sent.", quotaAccount, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT); + continue; + } //check if it is statement time Calendar interval[] = statementTime(Calendar.getInstance(), _period); Date lastStatementDate = quotaAccount.getLastStatementDate(); if (interval != null) { - AccountVO account = _accountDao.findById(quotaAccount.getId()); - if (account != null) { - if (lastStatementDate == null || getDifferenceDays(lastStatementDate, new Date()) >= s_LAST_STATEMENT_SENT_DAYS + 1) { - BigDecimal quotaUsage = _quotaUsage.findTotalQuotaUsage(account.getAccountId(), account.getDomainId(), null, interval[0].getTime(), interval[1].getTime()); - s_logger.info("For account=" + quotaAccount.getId() + ", quota used = " + quotaUsage); - // send statement - deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, quotaUsage, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT)); - } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("For " + quotaAccount.getId() + " the statement has been sent recently"); - - } - } + if (lastStatementDate == null || getDifferenceDays(lastStatementDate, new Date()) >= s_LAST_STATEMENT_SENT_DAYS + 1) { + BigDecimal quotaUsage = _quotaUsage.findTotalQuotaUsage(account.getAccountId(), account.getDomainId(), null, interval[0].getTime(), interval[1].getTime()); + logger.info("Quota statement for account [{}] has an usage of [{}].", quotaAccount, quotaUsage); + + // send statement + deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, quotaUsage, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT)); + } else { + logger.debug("Quota statement has already been sent recently to account [{}].", quotaAccount); } } else if (lastStatementDate != null) { - s_logger.info("For " + quotaAccount.getId() + " it is already more than " + getDifferenceDays(lastStatementDate, new Date()) - + " days, will send statement in next cycle"); + logger.info("For account {} it is already more than {} days, will send statement in next cycle.", quotaAccount.getId(), getDifferenceDays(lastStatementDate, new Date())); } } for (DeferredQuotaEmail emailToBeSent : deferredQuotaEmailList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Attempting to send quota STATEMENT email to users of account: " + emailToBeSent.getAccount().getAccountName()); + if (logger.isDebugEnabled()) { + logger.debug("Attempting to send quota STATEMENT email to users of account: " + emailToBeSent.getAccount().getAccountName()); } _quotaAlert.sendQuotaAlert(emailToBeSent); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java index c0b1f762f70e..37c90ab0bcd9 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Account.java @@ -17,7 +17,9 @@ package org.apache.cloudstack.quota.activationrule.presetvariables; -public class Account extends GenericPresetVariable{ +public class Account extends GenericPresetVariable { + @PresetVariableDefinition(description = "Role of the account. This field will not exist if the account is a project.") + private Role role; public Role getRole() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/BackupOffering.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/BackupOffering.java index 457e71a141f2..d8457d294ec3 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/BackupOffering.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/BackupOffering.java @@ -20,6 +20,7 @@ package org.apache.cloudstack.quota.activationrule.presetvariables; public class BackupOffering extends GenericPresetVariable { + @PresetVariableDefinition(description = "External ID of the backup offering that generated the backup.") private String externalId; public String getExternalId() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java index b42c32a584e1..1d294276d470 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputeOffering.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.quota.activationrule.presetvariables; public class ComputeOffering extends GenericPresetVariable { + @PresetVariableDefinition(description = "A boolean informing if the compute offering is customized or not.") private boolean customized; public boolean isCustomized() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputingResources.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputingResources.java index d4f335b081c9..9c86d2d6e0c9 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputingResources.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/ComputingResources.java @@ -21,8 +21,13 @@ import org.apache.commons.lang3.builder.ToStringStyle; public class ComputingResources { + @PresetVariableDefinition(description = "Current VM's memory (in MiB).") private Integer memory; + + @PresetVariableDefinition(description = "Current VM's vCPUs.") private Integer cpuNumber; + + @PresetVariableDefinition(description = "Current VM's CPU speed (in MHz).") private Integer cpuSpeed; public Integer getMemory() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Domain.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Domain.java index 01b702feb1a9..6d83da4cd8fb 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Domain.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Domain.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.quota.activationrule.presetvariables; public class Domain extends GenericPresetVariable { + @PresetVariableDefinition(description = "Path of the domain owner of the resource.") private String path; public String getPath() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/GenericPresetVariable.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/GenericPresetVariable.java index b081e57611f0..f59f23abdc15 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/GenericPresetVariable.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/GenericPresetVariable.java @@ -23,8 +23,12 @@ import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; public class GenericPresetVariable { + @PresetVariableDefinition(description = "ID of the resource.") private String id; + + @PresetVariableDefinition(description = "Name of the resource.") private String name; + protected transient Set fieldNamesToIncludeInToString = new HashSet<>(); public String getId() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Host.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Host.java index fef3e4376dcb..4a0fd2f5a078 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Host.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Host.java @@ -20,8 +20,10 @@ import java.util.List; public class Host extends GenericPresetVariable { + @PresetVariableDefinition(description = "List of tags of the host where the VM is running (i.e.: [\"a\", \"b\"]).") private List tags; + @PresetVariableDefinition(description = "Whether the tag is a rule interpreted in JavaScript.") private Boolean isTagARule; public List getTags() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableDefinition.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableDefinition.java new file mode 100644 index 000000000000..0e10a8af9d12 --- /dev/null +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableDefinition.java @@ -0,0 +1,42 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.quota.activationrule.presetvariables; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Describes the preset variable and indicates to which Quota usage types it is loaded. + */ +@Target(FIELD) +@Retention(RUNTIME) +public @interface PresetVariableDefinition { + /** + * An array indicating for which Quota usage types the preset variable is loaded. + * @return an array with the usage types for which the preset variable is loaded. + */ + int[] supportedTypes() default 0; + + /** + * A {@link String} describing the preset variable. + * @return the description of the preset variable. + */ + String description() default ""; +} diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java index 849ef7791618..d5df3ae8a913 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java @@ -51,7 +51,8 @@ import org.apache.cloudstack.utils.bytescale.ByteScaleUtils; import org.apache.cloudstack.utils.jsinterpreter.JsInterpreter; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenterVO; @@ -103,7 +104,7 @@ @Component public class PresetVariableHelper { - protected Logger logger = Logger.getLogger(PresetVariableHelper.class); + protected Logger logger = LogManager.getLogger(PresetVariableHelper.class); @Inject AccountDao accountDao; diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariables.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariables.java index 2fb6e1ac131d..b27bf589c167 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariables.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariables.java @@ -19,11 +19,22 @@ public class PresetVariables { + @PresetVariableDefinition(description = "Account owner of the resource.") private Account account; + + @PresetVariableDefinition(description = "Domain owner of the resource.") private Domain domain; + + @PresetVariableDefinition(description = "Project owner of the resource. This field will not exist if the resource belongs to an account.") private GenericPresetVariable project; + + @PresetVariableDefinition(description = "Type of the record used. Examples for this are: VirtualMachine, DomainRouter, SourceNat, KVM.") private String resourceType; + + @PresetVariableDefinition(description = "Data related to the resource being processed.") private Value value; + + @PresetVariableDefinition(description = "Zone where the resource is.") private GenericPresetVariable zone; public Account getAccount() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Role.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Role.java index fc4716fc309e..3f953b3a4ff8 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Role.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Role.java @@ -20,6 +20,7 @@ import org.apache.cloudstack.acl.RoleType; public class Role extends GenericPresetVariable { + @PresetVariableDefinition(description = "Role type of the resource's owner.") private RoleType type; public RoleType getType() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Storage.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Storage.java index 6be1dfb025a2..9b6cfb310922 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Storage.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Storage.java @@ -22,9 +22,13 @@ import com.cloud.storage.ScopeType; public class Storage extends GenericPresetVariable { + @PresetVariableDefinition(description = "List of string representing the tags of the storage where the volume is (i.e.: [\"a\", \"b\"]).") private List tags; + @PresetVariableDefinition(description = "Whether the tag is a rule interpreted in JavaScript. Applicable only for primary storages.") private Boolean isTagARule; + + @PresetVariableDefinition(description = "Scope of the storage where the volume is. Values can be: ZONE, CLUSTER or HOST. Applicable only for primary storages.") private ScopeType scope; public List getTags() { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Tariff.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Tariff.java new file mode 100644 index 000000000000..3703820a1a40 --- /dev/null +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Tariff.java @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.quota.activationrule.presetvariables; + +import java.math.BigDecimal; + +public class Tariff extends GenericPresetVariable { + private BigDecimal value; + + public BigDecimal getValue() { + return value; + } + + public void setValue(BigDecimal value) { + this.value = value; + fieldNamesToIncludeInToString.add("value"); + } +} diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java index a1dc7b3c1bb0..d87146d8798e 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/Value.java @@ -23,25 +23,75 @@ import com.cloud.storage.Snapshot; import com.cloud.storage.Storage.ProvisioningType; import com.cloud.vm.snapshot.VMSnapshot; +import org.apache.cloudstack.quota.constant.QuotaTypes; public class Value extends GenericPresetVariable { + + @PresetVariableDefinition(description = "ID of the resource.", supportedTypes = {QuotaTypes.ALLOCATED_VM, QuotaTypes.RUNNING_VM, QuotaTypes.VOLUME, QuotaTypes.TEMPLATE, + QuotaTypes.ISO, QuotaTypes.SNAPSHOT, QuotaTypes.NETWORK_OFFERING, QuotaTypes.VM_SNAPSHOT}) + private String id; + + @PresetVariableDefinition(description = "Name of the resource.", supportedTypes = {QuotaTypes.ALLOCATED_VM, QuotaTypes.RUNNING_VM, QuotaTypes.VOLUME, QuotaTypes.TEMPLATE, + QuotaTypes.ISO, QuotaTypes.SNAPSHOT, QuotaTypes.NETWORK_OFFERING, QuotaTypes.VM_SNAPSHOT}) + private String name; + + @PresetVariableDefinition(description = "Host where the VM is running.", supportedTypes = {QuotaTypes.RUNNING_VM}) private Host host; + + @PresetVariableDefinition(description = "OS of the VM/template.", supportedTypes = {QuotaTypes.RUNNING_VM, QuotaTypes.ALLOCATED_VM, QuotaTypes.TEMPLATE, QuotaTypes.ISO}) private String osName; + + @PresetVariableDefinition(description = "A list of resources of the account between the start and end date of the usage record being calculated " + + "(i.e.: [{zoneId: ..., domainId:...}]).") private List accountResources; + + @PresetVariableDefinition(supportedTypes = {QuotaTypes.ALLOCATED_VM, QuotaTypes.RUNNING_VM, QuotaTypes.VOLUME, QuotaTypes.TEMPLATE, QuotaTypes.ISO, QuotaTypes.SNAPSHOT, + QuotaTypes.VM_SNAPSHOT}, description = "List of tags of the resource in the format key:value (i.e.: {\"a\":\"b\", \"c\":\"d\"}).") private Map tags; + + @PresetVariableDefinition(description = "Tag of the network offering.", supportedTypes = {QuotaTypes.NETWORK_OFFERING}) private String tag; + + @PresetVariableDefinition(description = "Size of the resource (in MiB).", supportedTypes = {QuotaTypes.TEMPLATE, QuotaTypes.ISO, QuotaTypes.VOLUME, QuotaTypes.SNAPSHOT, + QuotaTypes.BACKUP}) private Long size; + + @PresetVariableDefinition(description = "Virtual size of the backup.", supportedTypes = {QuotaTypes.BACKUP}) private Long virtualSize; + + @PresetVariableDefinition(description = "Provisioning type of the resource. Values can be: thin, sparse or fat.", supportedTypes = {QuotaTypes.VOLUME}) private ProvisioningType provisioningType; + + @PresetVariableDefinition(description = "Type of the snapshot. Values can be: MANUAL, RECURRING, HOURLY, DAILY, WEEKLY and MONTHLY.", supportedTypes = {QuotaTypes.SNAPSHOT}) private Snapshot.Type snapshotType; + + @PresetVariableDefinition(description = "Type of the VM snapshot. Values can be: Disk or DiskAndMemory.", supportedTypes = {QuotaTypes.VM_SNAPSHOT}) private VMSnapshot.Type vmSnapshotType; + + @PresetVariableDefinition(description = "Computing offering of the VM.", supportedTypes = {QuotaTypes.RUNNING_VM, QuotaTypes.ALLOCATED_VM}) private ComputeOffering computeOffering; + + @PresetVariableDefinition(description = "Template/ISO with which the VM was created.", supportedTypes = {QuotaTypes.RUNNING_VM, QuotaTypes.ALLOCATED_VM}) private GenericPresetVariable template; + + @PresetVariableDefinition(description = "Disk offering of the volume.", supportedTypes = {QuotaTypes.VOLUME}) private GenericPresetVariable diskOffering; + + @PresetVariableDefinition(description = "Storage where the volume or snapshot is. While handling with snapshots, this value can be from the primary storage if the global " + + "setting 'snapshot.backup.to.secondary' is false, otherwise it will be from secondary storage.", supportedTypes = {QuotaTypes.VOLUME, QuotaTypes.SNAPSHOT}) private Storage storage; + + @PresetVariableDefinition(description = "Computing resources consumed by the VM.", supportedTypes = {QuotaTypes.RUNNING_VM}) private ComputingResources computingResources; + + @PresetVariableDefinition(description = "Backup offering of the backup.", supportedTypes = {QuotaTypes.BACKUP}) private BackupOffering backupOffering; + + @PresetVariableDefinition(description = "The hypervisor where the resource was deployed. Values can be: XenServer, KVM, VMware, Hyperv, BareMetal, Ovm, Ovm3 and LXC.", + supportedTypes = {QuotaTypes.RUNNING_VM, QuotaTypes.ALLOCATED_VM, QuotaTypes.VM_SNAPSHOT, QuotaTypes.SNAPSHOT}) private String hypervisorType; + + @PresetVariableDefinition(description = "The volume format. Values can be: RAW, VHD, VHDX, OVA and QCOW2.", supportedTypes = {QuotaTypes.VOLUME, QuotaTypes.VOLUME_SECONDARY}) private String volumeFormat; private String state; diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java index 59aa54424cf0..81b4643eb450 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java @@ -48,16 +48,16 @@ public interface QuotaConfig { public static final ConfigKey QuotaSmtpPort = new ConfigKey("Advanced", String.class, "quota.usage.smtp.port", "", "Quota SMTP port.", true); - public static final ConfigKey QuotaSmtpAuthType = new ConfigKey("Advanced", String.class, "quota.usage.smtp.useAuth", "", + public static final ConfigKey QuotaSmtpAuthType = new ConfigKey("Advanced", Boolean.class, "quota.usage.smtp.useAuth", "false", "If true, use secure SMTP authentication when sending emails.", true); public static final ConfigKey QuotaSmtpSender = new ConfigKey("Advanced", String.class, "quota.usage.smtp.sender", "", "Sender of quota alert email (will be in the From header of the email).", true); public static final ConfigKey QuotaSmtpEnabledSecurityProtocols = new ConfigKey("Advanced", String.class, "quota.usage.smtp.enabledSecurityProtocols", "", - "White-space separated security protocols; ex: \"TLSv1 TLSv1.1\". Supported protocols: SSLv2Hello, SSLv3, TLSv1, TLSv1.1 and TLSv1.2.", true); + "White-space separated security protocols; ex: \"TLSv1 TLSv1.1\". Supported protocols: SSLv2Hello, SSLv3, TLSv1, TLSv1.1 and TLSv1.2.", true, ConfigKey.Kind.WhitespaceSeparatedListWithOptions, "SSLv2Hello,SSLv3,TLSv1,TLSv1.1,TLSv1.2"); - public static final ConfigKey QuotaSmtpUseStartTLS = new ConfigKey("Advanced", String.class, "quota.usage.smtp.useStartTLS", "false", + public static final ConfigKey QuotaSmtpUseStartTLS = new ConfigKey("Advanced", Boolean.class, "quota.usage.smtp.useStartTLS", "false", "If set to true and if we enable security via quota.usage.smtp.useAuth, this will enable StartTLS to secure the connection.", true); public static final ConfigKey QuotaActivationRuleTimeout = new ConfigKey<>("Advanced", Long.class, "quota.activationrule.timeout", "2000", "The maximum runtime," @@ -72,6 +72,9 @@ public interface QuotaConfig { ConfigKey QuotaEmailFooter = new ConfigKey<>("Advanced", String.class, "quota.email.footer", "", "Text to be added as a footer for quota emails. Line breaks are not automatically inserted between this section and the body.", true, ConfigKey.Scope.Domain); + ConfigKey QuotaEnableEmails = new ConfigKey<>("Advanced", Boolean.class, "quota.enable.emails", "true", + "Indicates whether Quota emails should be sent or not to accounts. When enabled, the behavior for each account can be overridden through the API quotaConfigureEmail.", true, ConfigKey.Scope.Account); + enum QuotaEmailTemplateTypes { QUOTA_LOW, QUOTA_EMPTY, QUOTA_UNLOCK_ACCOUNT, QUOTA_STATEMENT } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaTypes.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaTypes.java index 3ed162b2ba1e..947183577a88 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaTypes.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaTypes.java @@ -22,6 +22,7 @@ import org.apache.cloudstack.usage.UsageTypes; import org.apache.cloudstack.usage.UsageUnitTypes; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; public class QuotaTypes extends UsageTypes { private final Integer quotaType; @@ -100,4 +101,13 @@ static public String getDescription(int quotaType) { } return null; } + + static public QuotaTypes getQuotaType(int quotaType) { + return quotaTypeMap.get(quotaType); + } + + @Override + public String toString() { + return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "quotaType", "quotaName"); + } } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.java index 084abcfc2b5d..b03b75f04f7a 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.java @@ -21,7 +21,6 @@ import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.vo.QuotaAccountVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.Pair; @@ -34,7 +33,6 @@ @Component public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao { - public static final Logger s_logger = Logger.getLogger(QuotaAccountDaoImpl.class); @Override public List listAllQuotaAccount() { @@ -44,7 +42,7 @@ public List listAllQuotaAccount() { accountsWithQuotaEnabled.add(account); continue; } - s_logger.trace(String.format("Account [%s] has the quota plugin disabled. Thus, it will not receive quota emails.", account)); + logger.trace(String.format("Account [%s] has the quota plugin disabled. Thus, it will not receive quota emails.", account)); } return accountsWithQuotaEnabled; } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java index 0ca7d9dbf8d9..01272d1a6184 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java @@ -23,7 +23,6 @@ import java.util.List; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Filter; @@ -37,7 +36,6 @@ @Component public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao { - private static final Logger s_logger = Logger.getLogger(QuotaBalanceDaoImpl.class.getName()); @Override public QuotaBalanceVO findLastBalanceEntry(final Long accountId, final Long domainId, final Date beforeThis) { @@ -158,8 +156,8 @@ public List doInTransaction(final TransactionStatus status) { // get records before startDate to find start balance for (QuotaBalanceVO entry : quotaUsageRecords) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("FindQuotaBalance Entry=" + entry); + if (logger.isDebugEnabled()) { + logger.debug("FindQuotaBalance Entry=" + entry); } if (entry.getCreditsId() > 0) { trimmedRecords.add(entry); @@ -178,12 +176,12 @@ public BigDecimal lastQuotaBalance(final Long accountId, final Long domainId, Da List quotaBalance = lastQuotaBalanceVO(accountId, domainId, startDate); BigDecimal finalBalance = new BigDecimal(0); if (quotaBalance.isEmpty()) { - s_logger.info("There are no balance entries on or before the requested date."); + logger.info("There are no balance entries on or before the requested date."); return finalBalance; } for (QuotaBalanceVO entry : quotaBalance) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("lastQuotaBalance Entry=" + entry); + if (logger.isDebugEnabled()) { + logger.debug("lastQuotaBalance Entry=" + entry); } finalBalance = finalBalance.add(entry.getCreditBalance()); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDao.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDao.java new file mode 100644 index 000000000000..4bb3395cc114 --- /dev/null +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDao.java @@ -0,0 +1,36 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.quota.dao; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.quota.constant.QuotaConfig; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; + +import java.util.List; + +public interface QuotaEmailConfigurationDao extends GenericDao { + + QuotaEmailConfigurationVO findByAccountIdAndEmailTemplateId(long accountId, long emailTemplateId); + + QuotaEmailConfigurationVO updateQuotaEmailConfiguration(QuotaEmailConfigurationVO quotaEmailConfigurationVO); + + void persistQuotaEmailConfiguration(QuotaEmailConfigurationVO quotaEmailConfigurationVO); + + List listByAccount(long accountId); + + QuotaEmailConfigurationVO findByAccountIdAndEmailTemplateType(long accountId, QuotaConfig.QuotaEmailTemplateTypes quotaEmailTemplateType); +} diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDaoImpl.java new file mode 100644 index 000000000000..9466340ad053 --- /dev/null +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDaoImpl.java @@ -0,0 +1,105 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.quota.dao; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import com.cloud.utils.db.TransactionLegacy; +import org.apache.cloudstack.quota.constant.QuotaConfig; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; +import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.util.List; + +@Component +public class QuotaEmailConfigurationDaoImpl extends GenericDaoBase implements QuotaEmailConfigurationDao { + + @Inject + private QuotaEmailTemplatesDao quotaEmailTemplatesDao; + + private SearchBuilder searchBuilderFindByIds; + + private SearchBuilder searchBuilderFindByTemplateName; + + private SearchBuilder searchBuilderFindByTemplateTypeAndAccountId; + + @PostConstruct + public void init() { + searchBuilderFindByIds = createSearchBuilder(); + searchBuilderFindByIds.and("account_id", searchBuilderFindByIds.entity().getAccountId(), SearchCriteria.Op.EQ); + searchBuilderFindByIds.and("email_template_id", searchBuilderFindByIds.entity().getEmailTemplateId(), SearchCriteria.Op.EQ); + searchBuilderFindByIds.done(); + + searchBuilderFindByTemplateName = quotaEmailTemplatesDao.createSearchBuilder(); + searchBuilderFindByTemplateName.and("template_name", searchBuilderFindByTemplateName.entity().getTemplateName(), SearchCriteria.Op.EQ); + + searchBuilderFindByTemplateTypeAndAccountId = createSearchBuilder(); + searchBuilderFindByTemplateTypeAndAccountId.and("account_id", searchBuilderFindByTemplateTypeAndAccountId.entity().getAccountId(), SearchCriteria.Op.EQ); + searchBuilderFindByTemplateTypeAndAccountId.join("email_template_id", searchBuilderFindByTemplateName, searchBuilderFindByTemplateName.entity().getId(), + searchBuilderFindByTemplateTypeAndAccountId.entity().getEmailTemplateId(), JoinBuilder.JoinType.INNER); + + searchBuilderFindByTemplateName.done(); + searchBuilderFindByTemplateTypeAndAccountId.done(); + } + + @Override + public QuotaEmailConfigurationVO findByAccountIdAndEmailTemplateId(long accountId, long emailTemplateId) { + SearchCriteria sc = searchBuilderFindByIds.create(); + sc.setParameters("account_id", accountId); + sc.setParameters("email_template_id", emailTemplateId); + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> findOneBy(sc)); + } + + @Override + public QuotaEmailConfigurationVO updateQuotaEmailConfiguration(QuotaEmailConfigurationVO quotaEmailConfigurationVO) { + SearchCriteria sc = searchBuilderFindByIds.create(); + sc.setParameters("account_id", quotaEmailConfigurationVO.getAccountId()); + sc.setParameters("email_template_id", quotaEmailConfigurationVO.getEmailTemplateId()); + Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> update(quotaEmailConfigurationVO, sc)); + + return quotaEmailConfigurationVO; + } + + @Override + public void persistQuotaEmailConfiguration(QuotaEmailConfigurationVO quotaEmailConfigurationVO) { + Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> persist(quotaEmailConfigurationVO)); + } + + @Override + public List listByAccount(long accountId) { + SearchCriteria sc = searchBuilderFindByIds.create(); + sc.setParameters("account_id", accountId); + + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback>) status -> listBy(sc)); + } + + @Override + public QuotaEmailConfigurationVO findByAccountIdAndEmailTemplateType(long accountId, QuotaConfig.QuotaEmailTemplateTypes quotaEmailTemplateType) { + SearchCriteria sc = searchBuilderFindByTemplateTypeAndAccountId.create(); + sc.setParameters("account_id", accountId); + sc.setJoinParameters("email_template_id", "template_name", quotaEmailTemplateType.toString()); + + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> findOneBy(sc)); + } +} diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDao.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDao.java index 573a75397442..346bb9a4a6a2 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDao.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDao.java @@ -24,4 +24,6 @@ public interface QuotaEmailTemplatesDao extends GenericDao { List listAllQuotaEmailTemplates(String templateName); boolean updateQuotaEmailTemplate(QuotaEmailTemplatesVO template); + + QuotaEmailTemplatesVO findById(long id); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java index e774a52648ec..c27f2df299bf 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -33,7 +32,6 @@ @Component public class QuotaEmailTemplatesDaoImpl extends GenericDaoBase implements QuotaEmailTemplatesDao { - private static final Logger s_logger = Logger.getLogger(QuotaEmailTemplatesDaoImpl.class); protected SearchBuilder QuotaEmailTemplateSearch; @@ -68,4 +66,9 @@ public Boolean doInTransaction(final TransactionStatus status) { } }); } + + @Override + public QuotaEmailTemplatesVO findById(long id) { + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> QuotaEmailTemplatesDaoImpl.super.findById(id)); + } } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDao.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDao.java index 4f13fb331800..419bb0ad7d26 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDao.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDao.java @@ -28,17 +28,9 @@ public interface QuotaTariffDao extends GenericDao { Pair, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, Long startIndex, Long pageSize); - QuotaTariffVO findByName(String name); - - QuotaTariffVO findTariffPlanByUsageType(int quotaType, Date onOrBefore); - - Pair, Integer> listAllTariffPlans(); + Pair, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, boolean listOnlyRemoved, Long startIndex, Long pageSize, String keyword); - Pair, Integer> listAllTariffPlans(final Long startIndex, final Long pageSize); - - Pair, Integer> listAllTariffPlans(Date onOrBefore); - - Pair, Integer> listAllTariffPlans(Date onOrBefore, Long startIndex, Long pageSize); + QuotaTariffVO findByName(String name); Boolean updateQuotaTariff(QuotaTariffVO plan); diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java index f73a7447d3e4..d36c698f44db 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java @@ -16,15 +16,11 @@ //under the License. package org.apache.cloudstack.quota.dao; -import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.List; -import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.Pair; @@ -35,11 +31,9 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.db.TransactionCallback; import com.cloud.utils.db.TransactionLegacy; -import com.cloud.utils.db.TransactionStatus; @Component public class QuotaTariffDaoImpl extends GenericDaoBase implements QuotaTariffDao { - private static final Logger s_logger = Logger.getLogger(QuotaTariffDaoImpl.class.getName()); private final SearchBuilder searchUsageType; private final SearchBuilder listAllIncludedUsageType; @@ -47,7 +41,7 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl public QuotaTariffDaoImpl() { super(); searchUsageType = createSearchBuilder(); - searchUsageType.and("usage_type", searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ); + searchUsageType.and("usageType", searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ); searchUsageType.done(); listAllIncludedUsageType = createSearchBuilder(); @@ -56,111 +50,28 @@ public QuotaTariffDaoImpl() { listAllIncludedUsageType.done(); } - @Override - public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, final Date effectiveDate) { - return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback() { - @Override - public QuotaTariffVO doInTransaction(final TransactionStatus status) { - List result = new ArrayList<>(); - final Filter filter = new Filter(QuotaTariffVO.class, "updatedOn", false, 0L, 1L); - final SearchCriteria sc = listAllIncludedUsageType.create(); - sc.setParameters("onorbefore", effectiveDate); - sc.setParameters("quotatype", quotaType); - result = search(sc, filter); - if (result != null && !result.isEmpty()) { - return result.get(0); - } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("QuotaTariffDaoImpl::findTariffPlanByUsageType: Missing quota type " + quotaType); - } - return null; - } - } - }); - } - - @Override - public Pair, Integer> listAllTariffPlans() { - return listAllTariffPlans(null, null); - } - - @Override - public Pair, Integer> listAllTariffPlans(final Long startIndex, final Long pageSize) { - return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback, Integer>>() { - @Override - public Pair, Integer> doInTransaction(final TransactionStatus status) { - return searchAndCount(null, new Filter(QuotaTariffVO.class, "updatedOn", false, startIndex, pageSize)); - } - }); - } - - - private List paginateList(final List list, final Long startIndex, final Long pageSize) { - if (startIndex == null || pageSize == null) { - return list; - } - if (list.size() < startIndex){ - return Collections.emptyList(); - } - return list.subList(startIndex.intValue(), (int) Math.min(startIndex + pageSize, list.size())); - } - - @Override - public Pair, Integer> listAllTariffPlans(final Date effectiveDate) { - return listAllTariffPlans(effectiveDate, null, null); - } - - @Override - public Pair, Integer> listAllTariffPlans(final Date effectiveDate, final Long startIndex, final Long pageSize) { - return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback, Integer>>() { - @Override - public Pair, Integer> doInTransaction(final TransactionStatus status) { - List tariffs = new ArrayList(); - final Filter filter = new Filter(QuotaTariffVO.class, "updatedOn", false, 0L, 1L); - final SearchCriteria sc = listAllIncludedUsageType.create(); - sc.setParameters("onorbefore", effectiveDate); - for (Integer quotaType : QuotaTypes.listQuotaTypes().keySet()) { - sc.setParameters("quotatype", quotaType); - List result = search(sc, filter); - if (result != null && !result.isEmpty()) { - tariffs.add(result.get(0)); - if (s_logger.isDebugEnabled()) { - s_logger.debug("ListAllTariffPlans on or before " + effectiveDate + " quota type " + result.get(0).getUsageTypeDescription() + " , effective Date=" - + result.get(0).getEffectiveOn() + " val=" + result.get(0).getCurrencyValue()); - } - } - } - return new Pair<>(paginateList(tariffs, startIndex, pageSize), tariffs.size()); - } - }); - } - @Override public Boolean updateQuotaTariff(final QuotaTariffVO plan) { - return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback() { - @Override - public Boolean doInTransaction(final TransactionStatus status) { - return update(plan.getId(), plan); - } - }); + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> update(plan.getId(), plan)); } @Override public QuotaTariffVO addQuotaTariff(final QuotaTariffVO plan) { if (plan.getIdObj() != null) { - throw new IllegalStateException("The QuotaTariffVO being added should not have an Id set "); + throw new IllegalStateException("The QuotaTariffVO being added should not have an Id set."); } - return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback() { - @Override - public QuotaTariffVO doInTransaction(final TransactionStatus status) { - return persist(plan); - } - }); + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> persist(plan)); } @Override public Pair, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, Long startIndex, Long pageSize) { - SearchCriteria searchCriteria = createListQuotaTariffsSearchCriteria(startDate, endDate, usageType, name, uuid); + return listQuotaTariffs(startDate, endDate, usageType, name, uuid, listAll, false, startIndex, pageSize, null); + } + + @Override + public Pair, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, boolean listOnlyRemoved, Long startIndex, Long pageSize, String keyword) { + SearchCriteria searchCriteria = createListQuotaTariffsSearchCriteria(startDate, endDate, usageType, name, uuid, listOnlyRemoved, keyword); + Filter sorter = new Filter(QuotaTariffVO.class, "usageType", false, startIndex, pageSize); sorter.addOrderBy(QuotaTariffVO.class, "effectiveOn", false); sorter.addOrderBy(QuotaTariffVO.class, "updatedOn", false); @@ -168,39 +79,34 @@ public Pair, Integer> listQuotaTariffs(Date startDate, Date return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback, Integer>>) status -> searchAndCount(searchCriteria, sorter, listAll)); } - protected SearchCriteria createListQuotaTariffsSearchCriteria(Date startDate, Date endDate, Integer usageType, String name, String uuid) { - SearchCriteria searchCriteria = createListQuotaTariffsSearchBuilder(startDate, endDate, usageType, name, uuid).create(); + protected SearchCriteria createListQuotaTariffsSearchCriteria(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listOnlyRemoved, String keyword) { + SearchCriteria searchCriteria = createListQuotaTariffsSearchBuilder(listOnlyRemoved).create(); - searchCriteria.setParametersIfNotNull("start_date", startDate); - searchCriteria.setParametersIfNotNull("end_date", endDate); - searchCriteria.setParametersIfNotNull("usage_type", usageType); + searchCriteria.setParametersIfNotNull("startDate", startDate); + searchCriteria.setParametersIfNotNull("endDate", endDate); + searchCriteria.setParametersIfNotNull("usageType", usageType); searchCriteria.setParametersIfNotNull("name", name); searchCriteria.setParametersIfNotNull("uuid", uuid); + if (keyword != null) { + searchCriteria.setParameters("nameLike", "%" + keyword + "%"); + } + return searchCriteria; } - protected SearchBuilder createListQuotaTariffsSearchBuilder(Date startDate, Date endDate, Integer usageType, String name, String uuid) { + protected SearchBuilder createListQuotaTariffsSearchBuilder(boolean listOnlyRemoved) { SearchBuilder searchBuilder = createSearchBuilder(); - if (startDate != null) { - searchBuilder.and("start_date", searchBuilder.entity().getEffectiveOn(), SearchCriteria.Op.GTEQ); - } - - if (endDate != null) { - searchBuilder.and("end_date", searchBuilder.entity().getEndDate(), SearchCriteria.Op.LTEQ); - } - - if (usageType != null) { - searchBuilder.and("usage_type", searchBuilder.entity().getUsageType(), SearchCriteria.Op.EQ); - } - - if (name != null) { - searchBuilder.and("name", searchBuilder.entity().getName(), SearchCriteria.Op.EQ); - } + searchBuilder.and("startDate", searchBuilder.entity().getEffectiveOn(), SearchCriteria.Op.GTEQ); + searchBuilder.and("endDate", searchBuilder.entity().getEndDate(), SearchCriteria.Op.LTEQ); + searchBuilder.and("usageType", searchBuilder.entity().getUsageType(), SearchCriteria.Op.EQ); + searchBuilder.and("name", searchBuilder.entity().getName(), SearchCriteria.Op.EQ); + searchBuilder.and("uuid", searchBuilder.entity().getUuid(), SearchCriteria.Op.EQ); + searchBuilder.and("nameLike", searchBuilder.entity().getName(), SearchCriteria.Op.LIKE); - if (uuid != null) { - searchBuilder.and("uuid", searchBuilder.entity().getUuid(), SearchCriteria.Op.EQ); + if (listOnlyRemoved) { + searchBuilder.and("removed", searchBuilder.entity().getRemoved(), SearchCriteria.Op.NNULL); } return searchBuilder; @@ -212,7 +118,7 @@ public QuotaTariffVO findByName(String name) { List quotaTariffs = pairQuotaTariffs.first(); if (CollectionUtils.isEmpty(quotaTariffs)) { - s_logger.debug(String.format("Could not find quota tariff with name [%s].", name)); + logger.debug(String.format("Could not find quota tariff with name [%s].", name)); return null; } @@ -225,7 +131,7 @@ public QuotaTariffVO findByUuid(String uuid) { List quotaTariffs = pairQuotaTariffs.first(); if (CollectionUtils.isEmpty(quotaTariffs)) { - s_logger.debug(String.format("Could not find quota tariff with UUID [%s].", uuid)); + logger.debug(String.format("Could not find quota tariff with UUID [%s].", uuid)); return null; } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java index 9134a4472b43..32b9c8d1d64c 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.cloudstack.quota.vo.QuotaUsageVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Filter; @@ -36,7 +35,6 @@ @Component public class QuotaUsageDaoImpl extends GenericDaoBase implements QuotaUsageDao { - private static final Logger s_logger = Logger.getLogger(QuotaUsageDaoImpl.class); @Override public BigDecimal findTotalQuotaUsage(final Long accountId, final Long domainId, final Integer usageType, final Date startDate, final Date endDate) { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaEmailConfigurationVO.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaEmailConfigurationVO.java new file mode 100644 index 000000000000..e50c7ce62504 --- /dev/null +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaEmailConfigurationVO.java @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.quota.vo; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name = "quota_email_configuration") +public class QuotaEmailConfigurationVO { + + @Column(name = "account_id") + private long accountId; + + @Column(name = "email_template_id") + private long emailTemplateId; + + @Column(name = "enabled") + private boolean enabled; + + public QuotaEmailConfigurationVO() { + } + + public QuotaEmailConfigurationVO(long accountId, long emailTemplateId, boolean enable) { + this.accountId = accountId; + this.emailTemplateId = emailTemplateId; + this.enabled = enable; + } + + public long getAccountId() { + return accountId; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public long getEmailTemplateId() { + return emailTemplateId; + } + + public void setEmailTemplateId(long emailTemplateId) { + this.emailTemplateId = emailTemplateId; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } +} diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaTariffVO.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaTariffVO.java index d7721d88cbbc..bd6aeb134180 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaTariffVO.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaTariffVO.java @@ -16,11 +16,13 @@ //under the License. package org.apache.cloudstack.quota.vo; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.quota.QuotaTariff; import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import com.cloud.utils.db.GenericDao; +import org.apache.commons.lang3.StringUtils; import javax.persistence.Column; import javax.persistence.Entity; @@ -33,6 +35,7 @@ import java.math.BigDecimal; import java.util.Date; +import java.util.TimeZone; import java.util.UUID; @Entity @@ -90,6 +93,10 @@ public class QuotaTariffVO implements QuotaTariff { @Temporal(value = TemporalType.TIMESTAMP) private Date endDate; + @Column(name = "position") + protected Integer position; + + public QuotaTariffVO() { } @@ -117,6 +124,7 @@ public QuotaTariffVO(QuotaTariffVO that) { this.setDescription(that.getDescription()); this.setActivationRule(that.getActivationRule()); this.setEndDate(that.getEndDate()); + this.setPosition(that.getPosition()); } public void setId(Long id) { @@ -260,8 +268,23 @@ public boolean setUsageTypeData(int usageType) { return true; } + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } + + @Override public String toString() { - return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "uuid", "name", "effectiveOn", "endDate"); - }; + return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "uuid", "name", "usageName"); + } + + public String toString(TimeZone timeZone) { + String startDateString = DateUtil.displayDateInTimezone(timeZone, getEffectiveOn()); + String endDateString = DateUtil.displayDateInTimezone(timeZone, getEndDate()); + return String.format("%s,\"startDate\":\"%s\",\"endDate\":\"%s\"}", StringUtils.chop(this.toString()), startDateString, endDateString); + } } diff --git a/framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml b/framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml index 5f1c274f0492..e634321208f4 100644 --- a/framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml +++ b/framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml @@ -30,5 +30,6 @@ + diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java index ae2f2e9926e6..54d4f1d5b690 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java @@ -30,9 +30,12 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.dao.QuotaAccountDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDaoImpl; import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,7 +43,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; @@ -71,6 +74,9 @@ public class QuotaAlertManagerImplTest extends TestCase { @Mock private ConfigurationDao configDao; + @Mock + private QuotaEmailConfigurationDaoImpl quotaEmailConfigurationDaoMock; + @Mock private QuotaAccountVO quotaAccountVOMock; @@ -92,43 +98,142 @@ public class QuotaAlertManagerImplTest extends TestCase { @Before public void setup() throws IllegalAccessException, NoSuchFieldException, ConfigurationException { - TransactionLegacy.open("QuotaAlertManagerImplTest"); - } - - @Test - public void testCheckAndSendQuotaAlertEmails() { AccountVO accountVO = new AccountVO(); accountVO.setId(2L); accountVO.setDomainId(1L); accountVO.setType(Account.Type.NORMAL); Mockito.when(accountDao.findById(Mockito.anyLong())).thenReturn(accountVO); - QuotaAccountVO acc = new QuotaAccountVO(2L); - acc.setQuotaBalance(new BigDecimal(404)); - acc.setQuotaMinBalance(new BigDecimal(100)); - acc.setQuotaBalanceDate(new Date()); - acc.setQuotaAlertDate(null); - acc.setQuotaEnforce(0); - List accounts = new ArrayList<>(); - accounts.add(acc); - Mockito.when(quotaAcc.listAllQuotaAccount()).thenReturn(accounts); + Mockito.doReturn(new BigDecimal(404)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(new BigDecimal(100)).when(quotaAccountVOMock).getQuotaMinBalance(); + Mockito.doReturn(balanceDateMock).when(quotaAccountVOMock).getQuotaBalanceDate(); + Mockito.doReturn(null).when(quotaAccountVOMock).getQuotaAlertDate(); + Mockito.doReturn(0).when(quotaAccountVOMock).getQuotaEnforce(); - // Don't test sendQuotaAlert yet - Mockito.doNothing().when(quotaAlertManager).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); - Mockito.lenient().doReturn(true).when(quotaAlertManager).lockAccount(Mockito.anyLong()); + TransactionLegacy.open("QuotaAlertManagerImplTest"); + } + + @Test + public void isQuotaEmailTypeEnabledForAccountTestConfigurationIsEnabledAndEmailIsConfiguredReturnConfiguredValue() { + boolean expectedValue = !QuotaConfig.QuotaEnableEmails.value(); + QuotaEmailConfigurationVO quotaEmailConfigurationVoMock = Mockito.mock(QuotaEmailConfigurationVO.class); + Mockito.when(quotaEmailConfigurationVoMock.isEnabled()).thenReturn(expectedValue); + Mockito.doReturn(quotaEmailConfigurationVoMock).when(quotaEmailConfigurationDaoMock).findByAccountIdAndEmailTemplateType(Mockito.anyLong(), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class)); + + boolean result = quotaAlertManager.isQuotaEmailTypeEnabledForAccount(accountMock, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY); + + Assert.assertEquals(expectedValue, result); + } - // call real method on send monthly statement - Mockito.doCallRealMethod().when(quotaAlertManager).checkAndSendQuotaAlertEmails(); + @Test + public void isQuotaEmailTypeEnabledForAccountTestConfigurationIsEnabledAndEmailIsNotConfiguredReturnDefaultValue() { + boolean defaultValue = QuotaConfig.QuotaEnableEmails.value(); + + boolean result = quotaAlertManager.isQuotaEmailTypeEnabledForAccount(accountMock, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY); + + Assert.assertEquals(defaultValue, result); + } + + @Test + public void checkQuotaAlertEmailForAccountTestNullAccountBalance() { + Mockito.doReturn(null).when(quotaAccountVOMock).getQuotaBalance(); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(accountDao, Mockito.never()).findById(Mockito.any()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestNullAccount() { + Mockito.doReturn(new BigDecimal(1)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(null).when(accountDao).findById(Mockito.any()); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAccountVOMock, Mockito.never()).getQuotaBalanceDate(); + } + + @Test + public void checkQuotaAlertEmailForAccountTestEnoughBalance() { + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager, Mockito.never()).lockAccount(Mockito.anyLong()); + Mockito.verify(deferredQuotaEmailListMock, Mockito.never()).add(Mockito.any()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndLockAccountEnforcementFalse() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager._lockAccountEnforcement = false; + Mockito.doReturn(1).when(quotaAccountVOMock).getQuotaEnforce(); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager, Mockito.never()).lockAccount(Mockito.anyLong()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndLockableFalse() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager._lockAccountEnforcement = true; + Mockito.doReturn(1).when(quotaAccountVOMock).getQuotaEnforce(); + Mockito.doReturn(false).when(quotaManagerMock).isLockable(Mockito.any()); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager, Mockito.never()).lockAccount(Mockito.anyLong()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndIsLockableFalse() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager._lockAccountEnforcement = true; + Mockito.doReturn(1).when(quotaAccountVOMock).getQuotaEnforce(); + Mockito.doReturn(false).when(quotaManagerMock).isLockable(Mockito.any()); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager, Mockito.never()).lockAccount(Mockito.anyLong()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndLockAccount() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager._lockAccountEnforcement = true; + Mockito.doReturn(1).when(quotaAccountVOMock).getQuotaEnforce(); + Mockito.doReturn(true).when(quotaManagerMock).isLockable(Mockito.any()); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager).lockAccount(Mockito.anyLong()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndAlertDateNotNullAndBalanceDateNotAfter() { + Mockito.doReturn(new Date()).when(quotaAccountVOMock).getQuotaAlertDate(); + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(false).when(balanceDateMock).after(Mockito.any()); + + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(deferredQuotaEmailListMock, Mockito.never()).add(Mockito.any()); + } + + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndAlertDateNotNullAndGetDifferenceDaysSmallerThanOne() { + Mockito.doReturn(new Date()).when(quotaAccountVOMock).getQuotaAlertDate(); + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(true).when(balanceDateMock).after(Mockito.any()); + Mockito.doReturn(0L).when(quotaAlertManager).getDifferenceDays(Mockito.any(), Mockito.any()); + + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(deferredQuotaEmailListMock, Mockito.never()).add(Mockito.any()); + } + + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndAlertDateNotNullAndBalanceAfterAndDifferenceBiggerThanOne() { + Mockito.doReturn(new Date()).when(quotaAccountVOMock).getQuotaAlertDate(); + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(true).when(balanceDateMock).after(Mockito.any()); + Mockito.doReturn(2).when(quotaAlertManager).getDifferenceDays(Mockito.any(), Mockito.any()); + + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(deferredQuotaEmailListMock).add(Mockito.any()); + } - // Case1: valid balance, no email should be sent - quotaAlertManager.checkAndSendQuotaAlertEmails(); - Mockito.verify(quotaAlertManager, Mockito.times(0)).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndAlertDateNull() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); - // Case2: low balance, email should be sent - accounts.get(0).setQuotaBalance(new BigDecimal(99)); - //Mockito.when(quotaAcc.listAll()).thenReturn(accounts); - quotaAlertManager.checkAndSendQuotaAlertEmails(); - Mockito.verify(quotaAlertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(deferredQuotaEmailListMock).add(Mockito.any()); } @Test @@ -177,7 +282,7 @@ public void testSendQuotaAlert() throws UnsupportedEncodingException, MessagingE quotaAlertManager.sendQuotaAlert(email); assertTrue(email.getSendDate() != null); - Mockito.verify(quotaAlertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(), Mockito.anyListOf(String.class), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(quotaAlertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(), Mockito.anyList(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(quotaAlertManager.mailSender, Mockito.times(1)).sendMail(Mockito.any(SMTPMailProperties.class)); } @@ -196,12 +301,12 @@ public void addHeaderAndFooterTestIfHeaderAndFootersAreNotAddedIfEmpty() { @Test public void testGetDifferenceDays() { Date now = new Date(); - assertTrue(QuotaAlertManagerImpl.getDifferenceDays(now, now) == 0L); + assertTrue(quotaAlertManager.getDifferenceDays(now, now) == 0L); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("UTC")); Calendar c2 = (Calendar)c.clone(); c2.add(Calendar.DATE, 1); - assertEquals(1L, QuotaAlertManagerImpl.getDifferenceDays(c.getTime(), c2.getTime())); + assertEquals(1L, quotaAlertManager.getDifferenceDays(c.getTime(), c2.getTime())); } @Test diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaManagerImplTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaManagerImplTest.java index e53051f2925b..5dfc12f7ef89 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaManagerImplTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaManagerImplTest.java @@ -29,6 +29,7 @@ import org.apache.cloudstack.quota.activationrule.presetvariables.GenericPresetVariable; import org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariableHelper; import org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariables; +import org.apache.cloudstack.quota.activationrule.presetvariables.Tariff; import org.apache.cloudstack.quota.activationrule.presetvariables.Value; import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.quota.dao.QuotaTariffDao; @@ -395,7 +396,7 @@ public void getQuotaTariffValueToBeAppliedTestActivationRuleIsNullReturnTariffVa Mockito.doReturn(null).when(quotaTariffVoMock).getActivationRule(); Mockito.doReturn(BigDecimal.ONE).when(quotaTariffVoMock).getCurrencyValue(); - BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, null, null); + BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, null, null, null); Assert.assertEquals(BigDecimal.ONE, result); } @@ -405,7 +406,7 @@ public void getQuotaTariffValueToBeAppliedTestActivationRuleIsEmptyReturnTariffV Mockito.doReturn("").when(quotaTariffVoMock).getActivationRule(); Mockito.doReturn(BigDecimal.TEN).when(quotaTariffVoMock).getCurrencyValue(); - BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, null, null); + BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, null, null, null); Assert.assertEquals(BigDecimal.TEN, result); } @@ -413,13 +414,15 @@ public void getQuotaTariffValueToBeAppliedTestActivationRuleIsEmptyReturnTariffV @Test public void getQuotaTariffValueToBeAppliedTestScriptResultIsNumberReturnIt() { BigDecimal expected = new BigDecimal(50.1); + List lastTariffs = createLastAppliedTariffsPresetVariableList(0); + Mockito.doReturn(" ").when(quotaTariffVoMock).getActivationRule(); Mockito.doReturn(BigDecimal.TEN).when(quotaTariffVoMock).getCurrencyValue(); Mockito.doNothing().when(quotaManagerImplSpy).injectPresetVariablesIntoJsInterpreter(Mockito.any(), Mockito.any()); Mockito.doReturn(expected).when(jsInterpreterMock).executeScript(Mockito.anyString()); - BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, jsInterpreterMock, presetVariablesMock); + BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, jsInterpreterMock, presetVariablesMock, lastTariffs); Assert.assertEquals(expected, result); } @@ -427,37 +430,42 @@ public void getQuotaTariffValueToBeAppliedTestScriptResultIsNumberReturnIt() { @Test public void getQuotaTariffValueToBeAppliedTestScriptResultIsTrueReturnTariffValue() { BigDecimal expected = new BigDecimal(236.84); + List lastTariffs = createLastAppliedTariffsPresetVariableList(0); Mockito.doReturn(" ").when(quotaTariffVoMock).getActivationRule(); Mockito.doReturn(expected).when(quotaTariffVoMock).getCurrencyValue(); Mockito.doNothing().when(quotaManagerImplSpy).injectPresetVariablesIntoJsInterpreter(Mockito.any(), Mockito.any()); Mockito.doReturn(true).when(jsInterpreterMock).executeScript(Mockito.anyString()); - BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, jsInterpreterMock, presetVariablesMock); + BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, jsInterpreterMock, presetVariablesMock, lastTariffs); Assert.assertEquals(expected, result); } @Test public void getQuotaTariffValueToBeAppliedTestScriptResultIsFalseReturnZero() { + List lastTariffs = createLastAppliedTariffsPresetVariableList(0); + Mockito.doReturn(" ").when(quotaTariffVoMock).getActivationRule(); Mockito.doReturn(BigDecimal.TEN).when(quotaTariffVoMock).getCurrencyValue(); Mockito.doNothing().when(quotaManagerImplSpy).injectPresetVariablesIntoJsInterpreter(Mockito.any(), Mockito.any()); Mockito.doReturn(false).when(jsInterpreterMock).executeScript(Mockito.anyString()); - BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, jsInterpreterMock, presetVariablesMock); + BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, jsInterpreterMock, presetVariablesMock, lastTariffs); Assert.assertEquals(BigDecimal.ZERO, result); } @Test public void getQuotaTariffValueToBeAppliedTestScriptResultIsNotBooleanNorNumericReturnZero() { + List lastTariffs = createLastAppliedTariffsPresetVariableList(0); + Mockito.doReturn(" ").when(quotaTariffVoMock).getActivationRule(); Mockito.doReturn(BigDecimal.TEN).when(quotaTariffVoMock).getCurrencyValue(); Mockito.doNothing().when(quotaManagerImplSpy).injectPresetVariablesIntoJsInterpreter(Mockito.any(), Mockito.any()); Mockito.doReturn("test").when(jsInterpreterMock).executeScript(Mockito.anyString()); - BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, jsInterpreterMock, presetVariablesMock); + BigDecimal result = quotaManagerImplSpy.getQuotaTariffValueToBeApplied(quotaTariffVoMock, jsInterpreterMock, presetVariablesMock, lastTariffs); Assert.assertEquals(BigDecimal.ZERO, result); } @@ -477,10 +485,7 @@ public void getPresetVariablesTestHasTariffsWithActivationRuleReturnPresetVariab @Test public void aggregateQuotaTariffsValuesTestTariffsWereNotInPeriodToBeAppliedReturnZero() { - List tariffs = new ArrayList<>(); - tariffs.add(new QuotaTariffVO()); - tariffs.add(new QuotaTariffVO()); - tariffs.add(new QuotaTariffVO()); + List tariffs = createTariffList(); Mockito.doReturn(false).when(quotaManagerImplSpy).isQuotaTariffInPeriodToBeApplied(Mockito.any(), Mockito.any(), Mockito.anyString()); BigDecimal result = quotaManagerImplSpy.aggregateQuotaTariffsValues(usageVoMock, tariffs, false, jsInterpreterMock, ""); @@ -497,13 +502,10 @@ public void aggregateQuotaTariffsValuesTestTariffsIsEmptyReturnZero() { @Test public void aggregateQuotaTariffsValuesTestTariffsAreInPeriodToBeAppliedReturnAggregation() { - List tariffs = new ArrayList<>(); - tariffs.add(new QuotaTariffVO()); - tariffs.add(new QuotaTariffVO()); - tariffs.add(new QuotaTariffVO()); + List tariffs = createTariffList(); Mockito.doReturn(true, false, true).when(quotaManagerImplSpy).isQuotaTariffInPeriodToBeApplied(Mockito.any(), Mockito.any(), Mockito.anyString()); - Mockito.doReturn(BigDecimal.TEN).when(quotaManagerImplSpy).getQuotaTariffValueToBeApplied(Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doReturn(BigDecimal.TEN).when(quotaManagerImplSpy).getQuotaTariffValueToBeApplied(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); BigDecimal result = quotaManagerImplSpy.aggregateQuotaTariffsValues(usageVoMock, tariffs, false, jsInterpreterMock, ""); Assert.assertEquals(BigDecimal.TEN.multiply(new BigDecimal(2)), result); @@ -528,4 +530,25 @@ public void persistUsagesAndQuotaUsagesAndRetrievePersistedQuotaUsagesTestReturn Assert.assertEquals(quotaUsageVoMock1, result.get(0)); Assert.assertEquals(quotaUsageVoMock2, result.get(1)); } + + private static List createTariffList() { + List tariffs = new ArrayList<>(); + tariffs.add(new QuotaTariffVO()); + tariffs.add(new QuotaTariffVO()); + tariffs.add(new QuotaTariffVO()); + tariffs.forEach(quotaTariffVO -> quotaTariffVO.setPosition(1)); + return tariffs; + } + + private static List createLastAppliedTariffsPresetVariableList(int numberOfTariffs) { + List lastTariffs = new ArrayList<>(); + for (int i = 0; i < numberOfTariffs; i++) { + Tariff tariff = new Tariff(); + tariff.setId(String.valueOf(i)); + tariff.setValue(BigDecimal.valueOf(i)); + lastTariffs.add(tariff); + } + return lastTariffs; + } + } diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java index 1b28f66b2bb9..507834fef41c 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.quota; -import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.math.BigDecimal; import java.util.ArrayList; @@ -24,21 +23,25 @@ import java.util.Date; import java.util.List; -import javax.mail.MessagingException; import javax.naming.ConfigurationException; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.quota.QuotaStatementImpl.QuotaStatementPeriods; +import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.dao.QuotaAccountDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDaoImpl; +import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; +import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.AccountVO; import com.cloud.user.dao.AccountDao; @@ -60,7 +63,20 @@ public class QuotaStatementTest extends TestCase { @Mock QuotaAlertManager alertManager; + @Mock + QuotaEmailConfigurationDaoImpl quotaEmailConfigurationDaoMock; + + @Mock + QuotaEmailTemplatesDao quotaEmailTemplatesDaoMock; + + @Mock + QuotaEmailTemplatesVO quotaEmailTemplatesVOMock; + + @Mock + List listMock; + @Spy + @InjectMocks QuotaStatementImpl quotaStatement = new QuotaStatementImpl(); private void injectMockToField(Object mock, String fieldName) throws NoSuchFieldException, IllegalAccessException { @@ -227,7 +243,10 @@ public void testStatementPeriodYEARLY() { @Test - public void testSendStatement() throws UnsupportedEncodingException, MessagingException { + public void sendStatementTestUnconfiguredEmail() { + boolean defaultConfigurationValue = QuotaConfig.QuotaEnableEmails.value(); + Mockito.doReturn(defaultConfigurationValue).when(alertManager).isQuotaEmailTypeEnabledForAccount(Mockito.any(AccountVO.class), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class)); + Calendar date = Calendar.getInstance(); AccountVO accountVO = new AccountVO(); accountVO.setId(2L); @@ -252,4 +271,46 @@ public void testSendStatement() throws UnsupportedEncodingException, MessagingEx } } + @Test + public void sendStatementTestEnabledEmail() { + Mockito.doReturn(true).when(alertManager).isQuotaEmailTypeEnabledForAccount(Mockito.any(AccountVO.class), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class)); + + Calendar date = Calendar.getInstance(); + AccountVO accountVO = new AccountVO(); + accountVO.setId(2L); + accountVO.setDomainId(1L); + Mockito.lenient().when(accountDao.findById(Mockito.anyLong())).thenReturn(accountVO); + + QuotaAccountVO acc = new QuotaAccountVO(2L); + acc.setQuotaBalance(new BigDecimal(404)); + acc.setLastStatementDate(null); + List accounts = new ArrayList<>(); + accounts.add(acc); + Mockito.lenient().when(quotaAcc.listAllQuotaAccount()).thenReturn(accounts); + + Mockito.lenient().when(quotaUsage.findTotalQuotaUsage(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.any(Date.class), Mockito.any(Date.class))) + .thenReturn(new BigDecimal(100)); + + // call real method on send monthly statement + quotaStatement.sendStatement(); + Calendar period[] = quotaStatement.statementTime(date, QuotaStatementPeriods.MONTHLY); + if (period != null){ + Mockito.verify(alertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); + } + } + + @Test + public void sendStatementTestDisabledEmail() { + QuotaAccountVO quotaAccountVoMock = Mockito.mock(QuotaAccountVO.class); + Mockito.when(quotaAccountVoMock.getQuotaBalance()).thenReturn(BigDecimal.ONE); + Mockito.when(quotaAcc.listAllQuotaAccount()).thenReturn(List.of(quotaAccountVoMock)); + AccountVO accountVoMock = Mockito.mock(AccountVO.class); + Mockito.doReturn(accountVoMock).when(accountDao).findById(Mockito.anyLong()); + Mockito.doReturn(false).when(alertManager).isQuotaEmailTypeEnabledForAccount(Mockito.any(AccountVO.class), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class)); + + quotaStatement.sendStatement(); + + Mockito.verify(quotaStatement, Mockito.never()).statementTime(Mockito.any(), Mockito.any()); + } + } diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/ValueTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/ValueTest.java index 4d0162b33c98..bad33da88367 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/ValueTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/activationrule/presetvariables/ValueTest.java @@ -25,6 +25,20 @@ @RunWith(MockitoJUnitRunner.class) public class ValueTest { + @Test + public void setIdTestAddFieldIdToCollection() { + Value variable = new Value(); + variable.setId(null); + Assert.assertTrue(variable.fieldNamesToIncludeInToString.contains("id")); + } + + @Test + public void setNameTestAddFieldNameToCollection() { + Value variable = new Value(); + variable.setName(null); + Assert.assertTrue(variable.fieldNamesToIncludeInToString.contains("name")); + } + @Test public void setHostTestAddFieldHostToCollection() { Value variable = new Value(); diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java index fc9b4af0ed2f..c1e59f99863a 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java @@ -22,7 +22,7 @@ import org.apache.cloudstack.usage.UsageTypes; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.List; import java.util.Map; diff --git a/framework/rest/pom.xml b/framework/rest/pom.xml index 309df04149f6..d1ffff3c7bdd 100644 --- a/framework/rest/pom.xml +++ b/framework/rest/pom.xml @@ -22,7 +22,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml cloud-framework-rest @@ -68,7 +68,7 @@ com.sun.xml.bind jaxb-impl - ${cs.jaxb.version} + ${cs.jaxb.impl.version} org.apache.cxf diff --git a/framework/security/pom.xml b/framework/security/pom.xml index 295f61d46daf..f41d5460bb76 100644 --- a/framework/security/pom.xml +++ b/framework/security/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/security/src/main/java/org/apache/cloudstack/framework/security/keys/KeysManagerImpl.java b/framework/security/src/main/java/org/apache/cloudstack/framework/security/keys/KeysManagerImpl.java index 15bb49c65ff4..fa092ebdd3c6 100644 --- a/framework/security/src/main/java/org/apache/cloudstack/framework/security/keys/KeysManagerImpl.java +++ b/framework/security/src/main/java/org/apache/cloudstack/framework/security/keys/KeysManagerImpl.java @@ -23,7 +23,8 @@ import javax.net.ssl.KeyManager; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigKey; @@ -50,7 +51,7 @@ * */ public class KeysManagerImpl implements KeysManager, Configurable { - private static final Logger s_logger = Logger.getLogger(KeysManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject ConfigurationDao _configDao; @@ -87,7 +88,7 @@ public String getEncryptionIV() { return EncryptionIV.value(); } - private static String getBase64EncodedRandomKey(int nBits) { + private String getBase64EncodedRandomKey(int nBits) { SecureRandom random; try { random = SecureRandom.getInstance("SHA1PRNG"); @@ -95,7 +96,7 @@ private static String getBase64EncodedRandomKey(int nBits) { random.nextBytes(keyBytes); return Base64.encodeBase64URLSafeString(keyBytes); } catch (NoSuchAlgorithmException e) { - s_logger.error("Unhandled exception: ", e); + logger.error("Unhandled exception: ", e); } return null; } diff --git a/framework/security/src/main/java/org/apache/cloudstack/framework/security/keystore/KeystoreManagerImpl.java b/framework/security/src/main/java/org/apache/cloudstack/framework/security/keystore/KeystoreManagerImpl.java index f89b6eebf9b5..3e01942fb2b1 100644 --- a/framework/security/src/main/java/org/apache/cloudstack/framework/security/keystore/KeystoreManagerImpl.java +++ b/framework/security/src/main/java/org/apache/cloudstack/framework/security/keystore/KeystoreManagerImpl.java @@ -32,7 +32,6 @@ import com.cloud.utils.Pair; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.Ternary; @@ -42,7 +41,6 @@ @Component public class KeystoreManagerImpl extends ManagerBase implements KeystoreManager { - private static final Logger s_logger = Logger.getLogger(KeystoreManagerImpl.class); @Inject private KeystoreDao _ksDao; @@ -52,7 +50,7 @@ public Pair validateCertificate(String certificate, String key, String errMsg = null; if (StringUtils.isAnyEmpty(certificate, key, domainSuffix)) { errMsg = String.format("Invalid parameter found in (certificate, key, domainSuffix) tuple for domain: %s", domainSuffix); - s_logger.error(errMsg); + logger.error(errMsg); return new Pair<>(false, errMsg); } @@ -64,10 +62,10 @@ public Pair validateCertificate(String certificate, String key, return new Pair<>(true, errMsg); } errMsg = String.format("Unable to construct keystore for domain: %s", domainSuffix); - s_logger.error(errMsg); + logger.error(errMsg); } catch (Exception e) { errMsg = String.format("Certificate validation failed due to exception for domain: %s", domainSuffix); - s_logger.error(errMsg, e); + logger.error(errMsg, e); } return new Pair<>(false, errMsg); } @@ -114,9 +112,9 @@ public byte[] getKeystoreBits(String name, String aliasForCertificateInStore, St return CertificateHelper.buildAndSaveKeystore(certs, storePassword); } catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | InvalidKeySpecException | IOException e) { String msg = String.format("Unable to build keystore for %s due to %s", name, e.getClass().getSimpleName()); - s_logger.warn(msg); - if (s_logger.isDebugEnabled()) { - s_logger.debug(msg, e); + logger.warn(msg); + if (logger.isDebugEnabled()) { + logger.debug(msg, e); } } return null; diff --git a/framework/spring/lifecycle/pom.xml b/framework/spring/lifecycle/pom.xml index 11e6343fbe3b..fbdb2e60dc6b 100644 --- a/framework/spring/lifecycle/pom.xml +++ b/framework/spring/lifecycle/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java index ad26fb19fc37..beb535cb2965 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java @@ -18,10 +18,13 @@ */ package org.apache.cloudstack.spring.lifecycle; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.context.SmartLifecycle; public abstract class AbstractSmartLifeCycle implements SmartLifecycle { + protected Logger logger = LogManager.getLogger(getClass()); boolean running = false; @Override diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java index b0c1dcc0760e..b913033259c7 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java @@ -29,7 +29,6 @@ import javax.management.NotCompliantMBeanException; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.utils.component.ComponentLifecycle; import com.cloud.utils.component.SystemIntegrityChecker; @@ -39,7 +38,6 @@ public class CloudStackExtendedLifeCycle extends AbstractBeanCollector { - private static final Logger log = Logger.getLogger(CloudStackExtendedLifeCycle.class); Map> sorted = new TreeMap>(); @@ -59,67 +57,83 @@ public void start() { protected void checkIntegrity() { for (SystemIntegrityChecker checker : getBeans(SystemIntegrityChecker.class)) { - log.info("Running system integrity checker " + checker); + logger.info("Running system integrity checker " + checker); checker.check(); } } public void startBeans() { - log.info("Starting CloudStack Components"); + logger.info("Starting CloudStack Components"); with(new WithComponentLifeCycle() { @Override public void with(ComponentLifecycle lifecycle) { - lifecycle.start(); + logger.info("starting bean {}.", lifecycle.getName()); + try { + lifecycle.start(); + } catch (Exception e) { + logger.error("Error on starting bean {} - {}", lifecycle.getName(), e.getMessage(), e); + } if (lifecycle instanceof ManagementBean) { ManagementBean mbean = (ManagementBean)lifecycle; try { JmxUtil.registerMBean(mbean); } catch (MalformedObjectNameException e) { - log.warn("Unable to register MBean: " + mbean.getName(), e); + logger.warn("Unable to register MBean: " + mbean.getName(), e); } catch (InstanceAlreadyExistsException e) { - log.warn("Unable to register MBean: " + mbean.getName(), e); + logger.warn("Unable to register MBean: " + mbean.getName(), e); } catch (MBeanRegistrationException e) { - log.warn("Unable to register MBean: " + mbean.getName(), e); + logger.warn("Unable to register MBean: " + mbean.getName(), e); } catch (NotCompliantMBeanException e) { - log.warn("Unable to register MBean: " + mbean.getName(), e); + logger.warn("Unable to register MBean: " + mbean.getName(), e); } - log.info("Registered MBean: " + mbean.getName()); + logger.info("Registered MBean: " + mbean.getName()); } } }); - log.info("Done Starting CloudStack Components"); + logger.info("Done Starting CloudStack Components"); } public void stopBeans() { + logger.info("Stopping CloudStack Components"); + with(new WithComponentLifeCycle() { @Override public void with(ComponentLifecycle lifecycle) { - log.info("stopping bean " + lifecycle.getName()); - lifecycle.stop(); + logger.info("stopping bean {}.", lifecycle.getName()); + try { + lifecycle.stop(); + } catch (Exception e) { + logger.error("Error on stopping bean {} - {}", lifecycle.getName(), e.getMessage(), e); + } } }); + + logger.info("Done Stopping CloudStack Components"); } private void configure() { - log.info("Configuring CloudStack Components"); + logger.info("Configuring CloudStack Components"); with(new WithComponentLifeCycle() { @Override public void with(ComponentLifecycle lifecycle) { try { + logger.info("configuring bean {}.", lifecycle.getName()); lifecycle.configure(lifecycle.getName(), lifecycle.getConfigParams()); } catch (ConfigurationException e) { - log.error("Failed to configure " + lifecycle.getName(), e); + logger.error("Failed to configure " + lifecycle.getName(), e); throw new CloudRuntimeException(e); + } catch (Exception e) { + logger.error("Error on configuring bean {} - {}", lifecycle.getName(), e.getMessage(), e); } } }); - log.info("Done Configuring CloudStack Components"); + logger.info("Done Configuring CloudStack Components"); } private void sortBeans() { diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycleStart.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycleStart.java index 0dc72f931958..85d25ffd9a4a 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycleStart.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycleStart.java @@ -45,5 +45,4 @@ public void setLifeCycle(CloudStackExtendedLifeCycle lifeCycle) { public void run() { lifeCycle.startBeans(); } - } diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java index 5c5e9165b172..3a9bb04ce967 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java @@ -22,7 +22,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.utils.component.ComponentLifecycleBase; import com.cloud.utils.component.Named; @@ -30,7 +29,6 @@ public class DumpRegistry extends ComponentLifecycleBase { - private static final Logger log = Logger.getLogger(DumpRegistry.class); List> registries; @@ -55,7 +53,7 @@ public boolean start() { buffer.append(getName(o)); } - log.info("Registry [" + registry.getName() + "] contains [" + buffer + "]"); + logger.info("Registry [" + registry.getName() + "] contains [" + buffer + "]"); } return super.start(); diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java index a077bc8f4f01..47aa82b9dc02 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java @@ -28,7 +28,8 @@ import javax.annotation.PostConstruct; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.BeanNameAware; import org.apache.cloudstack.framework.config.ConfigKey; @@ -38,7 +39,7 @@ public class ExtensionRegistry implements Registry, Configurable, BeanNameAware { - private static final Logger log = Logger.getLogger(ExtensionRegistry.class); + protected Logger logger = LogManager.getLogger(getClass()); String name; String beanName; @@ -111,7 +112,7 @@ public boolean register(Object item) { registered.add(item); } - log.debug("Registering extension [" + name + "] in [" + this.name + "]"); + logger.debug("Registering extension [" + name + "] in [" + this.name + "]"); return true; } diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java index 43efd8461840..19d1fe3acc52 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java @@ -23,7 +23,8 @@ import java.util.Properties; import java.util.Set; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ApplicationContext; @@ -35,7 +36,7 @@ public class RegistryLifecycle implements BeanPostProcessor, SmartLifecycle, ApplicationContextAware { - private static final Logger log = Logger.getLogger(RegistryLifecycle.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final String EXTENSION_EXCLUDE = "extensions.exclude"; public static final String EXTENSION_INCLUDE_PREFIX = "extensions.include."; @@ -70,7 +71,7 @@ protected synchronized boolean isExcluded(Object bean) { boolean result = excludes.contains(name); if (result) { - log.info("Excluding extension [" + name + "] based on configuration"); + logger.info("Excluding extension [" + name + "] based on configuration"); } return result; @@ -109,7 +110,7 @@ public void start() { while (iter.hasNext()) { Object next = iter.next(); if (registry.register(next)) { - log.debug("Registered " + next); + logger.debug("Registered " + next); } else { iter.remove(); } diff --git a/framework/spring/module/pom.xml b/framework/spring/module/pom.xml index e72b7338ba6a..ea39e3a61416 100644 --- a/framework/spring/module/pom.xml +++ b/framework/spring/module/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java index f054d3998ac5..361a66fe1ba5 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java @@ -24,7 +24,8 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.io.Resource; @@ -36,7 +37,7 @@ public class CloudStackSpringContext { - private static final Logger log = Logger.getLogger(CloudStackSpringContext.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final String CLOUDSTACK_CONTEXT_SERVLET_KEY = CloudStackSpringContext.class.getSimpleName(); public static final String CLOUDSTACK_CONTEXT = "META-INF/cloudstack"; @@ -76,8 +77,10 @@ public void registerShutdownHook() { for (String appName : contextMap.keySet()) { ApplicationContext contex = contextMap.get(appName); if (contex instanceof ConfigurableApplicationContext) { - log.trace("registering shutdown hook for bean "+ appName); + logger.trace("Registering shutdown hook for bean {}.", appName); ((ConfigurableApplicationContext)contex).registerShutdownHook(); + } else { + logger.warn("Shutdown hook not registered for bean {}.", appName); } } } @@ -129,7 +132,7 @@ public String[] getConfigLocationsForWeb(String name, String[] configured) { String urlString = r.getURL().toExternalForm(); urlList.add(urlString); } catch (IOException e) { - log.error("Failed to create URL for " + r.getDescription(), e); + logger.error("Failed to create URL for " + r.getDescription(), e); } } diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java index cda07c9dee6a..2a6d0b63e5c2 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java @@ -33,7 +33,8 @@ import java.util.Stack; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -48,7 +49,7 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { - private static final Logger log = Logger.getLogger(DefaultModuleDefinitionSet.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final String DEFAULT_CONFIG_RESOURCES = "DefaultConfigResources"; public static final String DEFAULT_CONFIG_PROPERTIES = "DefaultConfigProperties"; @@ -98,28 +99,28 @@ protected void startContexts() { public void with(ModuleDefinition def, Stack parents) { try { String moduleDefinitionName = def.getName(); - log.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); + logger.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); ApplicationContext context = getApplicationContext(moduleDefinitionName); try { if (context == null) { - log.warn(String.format("Application context not found for module definition [%s]", moduleDefinitionName)); + logger.warn(String.format("Application context not found for module definition [%s]", moduleDefinitionName)); } else if (context.containsBean("moduleStartup")) { Runnable runnable = context.getBean("moduleStartup", Runnable.class); - log.info(String.format("Starting module [%s].", moduleDefinitionName)); + logger.info(String.format("Starting module [%s].", moduleDefinitionName)); runnable.run(); } else { - log.debug(String.format("Could not get module [%s] context bean.", moduleDefinitionName)); + logger.debug(String.format("Could not get module [%s] context bean.", moduleDefinitionName)); } } catch (BeansException e) { - log.warn(String.format("Failed to start module [%s] due to: [%s].", moduleDefinitionName, e.getMessage())); - if (log.isDebugEnabled()) { - log.debug(String.format("module start failure of module [%s] was due to: ", moduleDefinitionName), e); + logger.warn(String.format("Failed to start module [%s] due to: [%s].", moduleDefinitionName, e.getMessage())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("module start failure of module [%s] was due to: ", moduleDefinitionName), e); } } } catch (EmptyStackException e) { - log.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); - if (log.isDebugEnabled()) { - log.debug("Failed to obtain module context: ", e); + logger.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); + if (logger.isDebugEnabled()) { + logger.debug("Failed to obtain module context: ", e); } } } @@ -133,22 +134,22 @@ public void with(ModuleDefinition def, Stack parents) { try { String moduleDefinitionName = def.getName(); if (parents.isEmpty()) { - log.debug(String.format("Could not find module [%s] context as they have no parents.", moduleDefinitionName)); + logger.debug(String.format("Could not find module [%s] context as they have no parents.", moduleDefinitionName)); return; } - log.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); + logger.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); ApplicationContext parent = getApplicationContext(parents.peek().getName()); - log.debug(String.format("Trying to load module [%s] context.", moduleDefinitionName)); + logger.debug(String.format("Trying to load module [%s] context.", moduleDefinitionName)); loadContext(def, parent); } catch (EmptyStackException e) { - log.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); - if (log.isDebugEnabled()) { - log.debug("Failed to obtain module context: ", e); + logger.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); + if (logger.isDebugEnabled()) { + logger.debug("Failed to obtain module context: ", e); } } catch (BeansException e) { - log.warn(String.format("Failed to start module [%s] due to: [%s].", def.getName(), e.getMessage())); - if (log.isDebugEnabled()) { - log.debug(String.format("module start failure of module [%s] was due to: ", def.getName()), e); + logger.warn(String.format("Failed to start module [%s] due to: [%s].", def.getName(), e.getMessage())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("module start failure of module [%s] was due to: ", def.getName()), e); } } } @@ -165,13 +166,13 @@ protected ApplicationContext loadContext(ModuleDefinition def, ApplicationContex context.setClassLoader(def.getClassLoader()); long start = System.currentTimeMillis(); - if (log.isInfoEnabled()) { + if (logger.isInfoEnabled()) { for (Resource resource : resources) { - log.info("Loading module context [" + def.getName() + "] from " + resource); + logger.info("Loading module context [" + def.getName() + "] from " + resource); } } context.refresh(); - log.info("Loaded module context [" + def.getName() + "] in " + (System.currentTimeMillis() - start) + " ms"); + logger.info("Loaded module context [" + def.getName() + "] in " + (System.currentTimeMillis() - start) + " ms"); contexts.put(def.getName(), context); @@ -251,7 +252,7 @@ protected void printHierarchy() { withModule(new WithModule() { @Override public void with(ModuleDefinition def, Stack parents) { - log.info(String.format("Module Hierarchy:%" + ((parents.size() * 2) + 1) + "s%s", "", def.getName())); + logger.info(String.format("Module Hierarchy:%" + ((parents.size() * 2) + 1) + "s%s", "", def.getName())); } }); } @@ -266,7 +267,7 @@ protected void withModule(ModuleDefinition def, Stack parents, return; if (!shouldLoad(def)) { - log.info("Excluding context [" + def.getName() + "] based on configuration"); + logger.info("Excluding context [" + def.getName() + "] based on configuration"); return; } diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java index 549c69d5da9b..3b6133b91b4a 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java @@ -23,7 +23,8 @@ import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.context.ApplicationContext; import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.ContextLoaderListener; @@ -35,7 +36,7 @@ public class CloudStackContextLoaderListener extends ContextLoaderListener { public static final String WEB_PARENT_MODULE = "parentModule"; public static final String WEB_PARENT_MODULE_DEFAULT = "web"; - private static final Logger log = Logger.getLogger(CloudStackContextLoaderListener.class); + protected Logger logger = LogManager.getLogger(getClass()); CloudStackSpringContext cloudStackContext; String configuredParentName; @@ -47,13 +48,13 @@ protected ApplicationContext loadParentContext(ServletContext servletContext) { @Override public void contextInitialized(ServletContextEvent event) { - log.trace("context initialized"); + logger.trace("context initialized"); try { cloudStackContext = new CloudStackSpringContext(); cloudStackContext.registerShutdownHook(); event.getServletContext().setAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY, cloudStackContext); } catch (IOException e) { - log.error("Failed to start CloudStack", e); + logger.error("Failed to start CloudStack", e); throw new RuntimeException("Failed to initialize CloudStack Spring modules", e); } @@ -67,7 +68,7 @@ public void contextInitialized(ServletContextEvent event) { @Override protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) { - log.trace("customize context"); + logger.trace("customize context"); super.customizeContext(servletContext, applicationContext); String[] newLocations = cloudStackContext.getConfigLocationsForWeb(configuredParentName, applicationContext.getConfigLocations()); diff --git a/framework/spring/module/src/test/resources/testhierarchy/base/test-context-inheritable.xml b/framework/spring/module/src/test/resources/testhierarchy/base/test-context-inheritable.xml index d15e8a97919e..ac219a531bb4 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/base/test-context-inheritable.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/base/test-context-inheritable.xml @@ -24,5 +24,5 @@ http://www.springframework.org/schema/context/spring-context.xsd"> - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/base/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/base/test-context.xml index b79711e1f532..a6342820b46f 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/base/test-context.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/base/test-context.xml @@ -26,9 +26,9 @@ - + - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/child1-1/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/child1-1/test-context.xml index 4e8f2db8f9e6..9c63227162f1 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/child1-1/test-context.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/child1-1/test-context.xml @@ -26,9 +26,9 @@ - + - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/child1/test-context-override.xml b/framework/spring/module/src/test/resources/testhierarchy/child1/test-context-override.xml index 0ea8893100f7..59820de453c5 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/child1/test-context-override.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/child1/test-context-override.xml @@ -22,9 +22,9 @@ http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> - + - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/child1/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/child1/test-context.xml index 98b663ebf84f..ecaef681bef2 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/child1/test-context.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/child1/test-context.xml @@ -28,11 +28,11 @@ - + - + - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/child2/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/child2/test-context.xml index 1c4404649ebe..e3577b52f286 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/child2/test-context.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/child2/test-context.xml @@ -26,7 +26,7 @@ - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/excluded/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/excluded/test-context.xml index 2cd049c88bf6..7d069ff61ad6 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/excluded/test-context.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/excluded/test-context.xml @@ -26,7 +26,7 @@ - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/excluded2/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/excluded2/test-context.xml index 192a376e9a97..aaff5b4ed1eb 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/excluded2/test-context.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/excluded2/test-context.xml @@ -26,7 +26,7 @@ - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/orphan-of-excluded/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/orphan-of-excluded/test-context.xml index 08bd33c52bf8..7000fb436f37 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/orphan-of-excluded/test-context.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/orphan-of-excluded/test-context.xml @@ -26,7 +26,7 @@ - + diff --git a/framework/spring/module/src/test/resources/testhierarchy/orphan1/test-context.xml b/framework/spring/module/src/test/resources/testhierarchy/orphan1/test-context.xml index 38e0e326f375..d422ecdd79ce 100644 --- a/framework/spring/module/src/test/resources/testhierarchy/orphan1/test-context.xml +++ b/framework/spring/module/src/test/resources/testhierarchy/orphan1/test-context.xml @@ -26,5 +26,5 @@ - + diff --git a/packaging/README.md b/packaging/README.md index 08e34baeae2d..78057b828b28 100644 --- a/packaging/README.md +++ b/packaging/README.md @@ -6,9 +6,9 @@ These scripts are also used by the CloudStack team to build packages for the off # Requirements The RPM and DEB packages have dependencies on versions of specific libraries. Due to these dependencies the following distributions and their versions are supported by the packages. -* CentOS / RHEL: 7 and 8 -* Debian 7 (Wheezy) and 8 (Jessy) (untested!) -* Ubuntu: 16.04 (Xenial), 18.04 (Bionic) and 20.04 (Focal) +* CentOS / RHEL: 8 and 9 +* Ubuntu: 20.04, 22.04, 24.04 +* Debian 12 (Bookworm, untested!) # Building Using the scripts in the *packaging* directory the RPM and DEB packages can be build. @@ -38,4 +38,4 @@ The commands above will generate Ubuntu 14.04, 16.04, and 22.04 packages which y ## RPM The *package.sh* script can be used to build RPM packages for CloudStack. In the *packaging* script you can run the following command: -``./package.sh --pack oss --distribution centos7`` +``./package.sh --pack oss --distribution el8`` diff --git a/packaging/centos7/cloud.spec b/packaging/centos7/cloud.spec deleted file mode 100644 index 25eba6495c10..000000000000 --- a/packaging/centos7/cloud.spec +++ /dev/null @@ -1,721 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -%define __os_install_post %{nil} -%global debug_package %{nil} - -# DISABLE the post-percentinstall java repacking and line number stripping -# we need to find a way to just disable the java repacking and line number stripping, but not the autodeps - -Name: cloudstack -Summary: CloudStack IaaS Platform -#http://fedoraproject.org/wiki/PackageNamingGuidelines#Pre-Release_packages -%define _maventag %{_fullver} -Release: %{_rel}%{dist} - -%define __python python3 -%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")} - -Version: %{_ver} -License: ASL 2.0 -Vendor: Apache CloudStack -Packager: Apache CloudStack -Group: System Environment/Libraries -# FIXME do groups for every single one of the subpackages -Source0: %{name}-%{_maventag}.tgz -BuildRoot: %{_tmppath}/%{name}-%{_maventag}-%{release}-build - -BuildRequires: java-11-openjdk-devel -BuildRequires: ws-commons-util -BuildRequires: jpackage-utils -BuildRequires: gcc -BuildRequires: glibc-devel -BuildRequires: /usr/bin/mkisofs -BuildRequires: mysql-connector-python -BuildRequires: maven => 3.0.0 -BuildRequires: python-setuptools -BuildRequires: python3 -BuildRequires: python3-pip -BuildRequires: python3-setuptools -BuildRequires: wget -BuildRequires: nodejs - -%description -CloudStack is a highly-scalable elastic, open source, -intelligent IaaS cloud implementation. - -%package management -Summary: CloudStack management server UI -Requires: java-11-openjdk -Requires: tzdata-java -Requires: python -Requires: python3 -Requires: bash -Requires: gawk -Requires: which -Requires: file -Requires: bzip2 -Requires: gzip -Requires: unzip -Requires: /sbin/mount.nfs -Requires: openssh-clients -Requires: nfs-utils -Requires: iproute -Requires: wget -Requires: mysql -Requires: sudo -Requires: /sbin/service -Requires: /sbin/chkconfig -Requires: /usr/bin/ssh-keygen -Requires: genisoimage -Requires: ipmitool -Requires: %{name}-common = %{_ver} -Requires: iptables-services -Requires: qemu-img -Requires: rng-tools -Requires: python3-pip -Requires: python3-setuptools -Group: System Environment/Libraries -%description management -The CloudStack management server is the central point of coordination, -management, and intelligence in CloudStack. - -%package common -Summary: Apache CloudStack common files and scripts -Requires: python -Requires: python3 -Requires: python3-pip -Group: System Environment/Libraries -%description common -The Apache CloudStack files shared between agent and management server -%global __requires_exclude ^libuuid\\.so\\.1$ - -%package agent -Summary: CloudStack Agent for KVM hypervisors -Requires: openssh-clients -Requires: java-11-openjdk -Requires: tzdata-java -Requires: %{name}-common = %{_ver} -Requires: libvirt -Requires: bridge-utils -Requires: ebtables -Requires: iptables -Requires: ethtool -Requires: net-tools -Requires: iproute -Requires: ipset -Requires: perl -Requires: python36-libvirt -Requires: qemu-img -Requires: qemu-kvm -Requires: cryptsetup -Requires: rng-tools -Provides: cloud-agent -Group: System Environment/Libraries -%description agent -The CloudStack agent for KVM hypervisors - -%package baremetal-agent -Summary: CloudStack baremetal agent -Requires: tftp-server -Requires: xinetd -Requires: syslinux -Requires: chkconfig -Requires: dhcp -Requires: httpd -Group: System Environment/Libraries -%description baremetal-agent -The CloudStack baremetal agent - -%package usage -Summary: CloudStack Usage calculation server -Requires: java-11-openjdk -Requires: tzdata-java -Group: System Environment/Libraries -%description usage -The CloudStack usage calculation service - -%package ui -Summary: CloudStack UI -Group: System Environment/Libraries -%description ui -The CloudStack UI - -%package cli -Summary: Apache CloudStack CLI -Provides: python-marvin -Group: System Environment/Libraries -%description cli -Apache CloudStack command line interface - -%package marvin -Summary: Apache CloudStack Marvin library -Requires: python3 -Requires: python3-devel -Requires: python3-pip -Requires: python-pip -Requires: gcc -Requires: python-devel -Requires: libffi-devel -Requires: openssl-devel -Group: System Environment/Libraries -%description marvin -Apache CloudStack Marvin library - -%package integration-tests -Summary: Apache CloudStack Marvin integration tests -Requires: %{name}-marvin = %{_ver} -Group: System Environment/Libraries -%description integration-tests -Apache CloudStack Marvin integration tests - -%if "%{_ossnoss}" == "noredist" -%package mysql-ha -Summary: Apache CloudStack Balancing Strategy for MySQL -Group: System Environmnet/Libraries -%description mysql-ha -Apache CloudStack Balancing Strategy for MySQL - -%endif - -%prep -echo Doing CloudStack build - -%setup -q -n %{name}-%{_maventag} - -%build - -cp packaging/centos7/replace.properties build/replace.properties -echo VERSION=%{_maventag} >> build/replace.properties -echo PACKAGE=%{name} >> build/replace.properties -touch build/gitrev.txt -echo $(git rev-parse HEAD) > build/gitrev.txt - -if [ "%{_ossnoss}" == "NOREDIST" -o "%{_ossnoss}" == "noredist" ] ; then - echo "Adding noredist flag to the maven build" - FLAGS="$FLAGS -Dnoredist" -fi - -if [ "%{_sim}" == "SIMULATOR" -o "%{_sim}" == "simulator" ] ; then - echo "Adding simulator flag to the maven build" - FLAGS="$FLAGS -Dsimulator" -fi - -if [ \"%{_temp}\" != "" ]; then - echo "Adding flags to package requested templates" - FLAGS="$FLAGS `rpm --eval %{?_temp}`" -fi - -mvn -Psystemvm,developer $FLAGS clean package -cd ui && npm install && npm run build && cd .. - -%install -[ ${RPM_BUILD_ROOT} != "/" ] && rm -rf ${RPM_BUILD_ROOT} -# Common directories -mkdir -p ${RPM_BUILD_ROOT}%{_bindir} -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/agent -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/ipallocator -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/cache/%{name}/management/work -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/cache/%{name}/management/temp -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/%{name}/mnt -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/%{name}/management -mkdir -p ${RPM_BUILD_ROOT}%{_initrddir} -mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/default -mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/profile.d -mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/sudoers.d - -# Common -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/vms -mkdir -p ${RPM_BUILD_ROOT}%{python_sitearch}/ -mkdir -p ${RPM_BUILD_ROOT}/usr/bin -cp -r scripts/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts -install -D systemvm/dist/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/vms/ -install python/lib/cloud_utils.py ${RPM_BUILD_ROOT}%{python_sitearch}/cloud_utils.py -cp -r python/lib/cloudutils ${RPM_BUILD_ROOT}%{python_sitearch}/ -python3 -m py_compile ${RPM_BUILD_ROOT}%{python_sitearch}/cloud_utils.py -python3 -m compileall ${RPM_BUILD_ROOT}%{python_sitearch}/cloudutils -cp build/gitrev.txt ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts -cp packaging/centos7/cloudstack-sccs ${RPM_BUILD_ROOT}/usr/bin - -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco -cp -r plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco - -# Management -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/ -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/lib -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/management -mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/run -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup/wheel - -# Setup Jetty -ln -sf /etc/%{name}/management ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/conf -ln -sf /var/log/%{name}/management ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/logs - -install -D client/target/utilities/bin/cloud-migrate-databases ${RPM_BUILD_ROOT}%{_bindir}/%{name}-migrate-databases -install -D client/target/utilities/bin/cloud-set-guest-password ${RPM_BUILD_ROOT}%{_bindir}/%{name}-set-guest-password -install -D client/target/utilities/bin/cloud-set-guest-sshkey ${RPM_BUILD_ROOT}%{_bindir}/%{name}-set-guest-sshkey -install -D client/target/utilities/bin/cloud-setup-databases ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-databases -install -D client/target/utilities/bin/cloud-setup-encryption ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-encryption -install -D client/target/utilities/bin/cloud-setup-management ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-management -install -D client/target/utilities/bin/cloud-setup-baremetal ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-baremetal -install -D client/target/utilities/bin/cloud-sysvmadm ${RPM_BUILD_ROOT}%{_bindir}/%{name}-sysvmadm -install -D client/target/utilities/bin/cloud-update-xenserver-licenses ${RPM_BUILD_ROOT}%{_bindir}/%{name}-update-xenserver-licenses -# Bundle cmk in cloudstack-management -wget https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -O ${RPM_BUILD_ROOT}%{_bindir}/cmk -chmod +x ${RPM_BUILD_ROOT}%{_bindir}/cmk - -cp -r client/target/utilities/scripts/db/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup - -cp -r client/target/cloud-client-ui-%{_maventag}.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/ -cp -r client/target/classes/META-INF/webapp ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/webapp -cp ui/dist/config.json ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/ -cp -r ui/dist/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/webapp/ -rm -f ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/webapp/config.json -ln -sf /etc/%{name}/management/config.json ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/webapp/config.json -mv ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/cloud-client-ui-%{_maventag}.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/lib/cloudstack-%{_maventag}.jar -cp client/target/lib/*jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/lib/ - -# Don't package the scripts in the management webapp -rm -rf ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/webapps/client/WEB-INF/classes/scripts -rm -rf ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/webapps/client/WEB-INF/classes/vms - -for name in db.properties server.properties log4j-cloud.xml environment.properties java.security.ciphers -do - cp client/target/conf/$name ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/$name -done - -ln -sf log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/log4j.xml - -install python/bindir/cloud-external-ipallocator.py ${RPM_BUILD_ROOT}%{_bindir}/%{name}-external-ipallocator.py -install -D client/target/pythonlibs/jasypt-1.9.3.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/lib/jasypt-1.9.3.jar -install -D utils/target/cloud-utils-%{_maventag}-bundled.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/lib/%{name}-utils.jar - -install -D packaging/centos7/cloud-ipallocator.rc ${RPM_BUILD_ROOT}%{_initrddir}/%{name}-ipallocator -install -D packaging/centos7/cloud.limits ${RPM_BUILD_ROOT}%{_sysconfdir}/security/limits.d/cloud -install -D packaging/systemd/cloudstack-management.service ${RPM_BUILD_ROOT}%{_unitdir}/%{name}-management.service -install -D packaging/systemd/cloudstack-management.default ${RPM_BUILD_ROOT}%{_sysconfdir}/default/%{name}-management -install -D server/target/conf/cloudstack-sudoers ${RPM_BUILD_ROOT}%{_sysconfdir}/sudoers.d/%{name}-management -touch ${RPM_BUILD_ROOT}%{_localstatedir}/run/%{name}-management.pid -#install -D server/target/conf/cloudstack-catalina.logrotate ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}-catalina - -# SystemVM template -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/templates/systemvm -cp -r engine/schema/dist/systemvm-templates/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/templates/systemvm -rm -rf ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/templates/systemvm/md5sum.txt - -# UI -mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/ui -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/ -cp -r client/target/classes/META-INF/webapp/WEB-INF ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui -cp ui/dist/config.json ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/ui/ -cp -r ui/dist/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/ -rm -f ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/config.json -ln -sf /etc/%{name}/ui/config.json ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/config.json - -# Package mysql-connector-python -wget -P ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup/wheel https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl -wget -P ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup/wheel https://files.pythonhosted.org/packages/e9/93/4860cebd5ad3ff2664ad3c966490ccb46e3b88458b2095145bca11727ca4/setuptools-47.3.1-py3-none-any.whl -wget -P ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup/wheel https://files.pythonhosted.org/packages/28/05/9867ef8eafd12265267bee138fa2c46ebf34a276ea4cbe184cba4c606e8b/protobuf-3.12.2-cp36-cp36m-manylinux1_x86_64.whl -wget -P ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup/wheel https://files.pythonhosted.org/packages/d1/53/4cf90d2fe81b9cdb55dc180951bcec44ea8685665f1bdb1412501dc362dd/mysql_connector_python-8.0.20-cp36-cp36m-manylinux1_x86_64.whl - -chmod 440 ${RPM_BUILD_ROOT}%{_sysconfdir}/sudoers.d/%{name}-management -chmod 770 ${RPM_BUILD_ROOT}%{_localstatedir}/%{name}/mnt -chmod 770 ${RPM_BUILD_ROOT}%{_localstatedir}/%{name}/management -chmod 770 ${RPM_BUILD_ROOT}%{_localstatedir}/cache/%{name}/management/work -chmod 770 ${RPM_BUILD_ROOT}%{_localstatedir}/cache/%{name}/management/temp -chmod 770 ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/management -chmod 770 ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/agent - -# KVM Agent -mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/agent -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/plugins -install -D packaging/systemd/cloudstack-agent.service ${RPM_BUILD_ROOT}%{_unitdir}/%{name}-agent.service -install -D packaging/systemd/cloudstack-rolling-maintenance@.service ${RPM_BUILD_ROOT}%{_unitdir}/%{name}-rolling-maintenance@.service -install -D packaging/systemd/cloudstack-agent.default ${RPM_BUILD_ROOT}%{_sysconfdir}/default/%{name}-agent -install -D agent/target/transformed/agent.properties ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/agent.properties -install -D agent/target/transformed/environment.properties ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/environment.properties -install -D agent/target/transformed/log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/log4j-cloud.xml -install -D agent/target/transformed/cloud-setup-agent ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-agent -install -D agent/target/transformed/cloudstack-agent-upgrade ${RPM_BUILD_ROOT}%{_bindir}/%{name}-agent-upgrade -install -D agent/target/transformed/cloud-guest-tool ${RPM_BUILD_ROOT}%{_bindir}/%{name}-guest-tool -install -D agent/target/transformed/libvirtqemuhook ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook -install -D agent/target/transformed/rolling-maintenance ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/rolling-maintenance -install -D agent/target/transformed/cloud-ssh ${RPM_BUILD_ROOT}%{_bindir}/%{name}-ssh -install -D agent/target/transformed/cloudstack-agent-profile.sh ${RPM_BUILD_ROOT}%{_sysconfdir}/profile.d/%{name}-agent-profile.sh -install -D agent/target/transformed/cloudstack-agent.logrotate ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}-agent -install -D plugins/hypervisors/kvm/target/cloud-plugin-hypervisor-kvm-%{_maventag}.jar ${RPM_BUILD_ROOT}%{_datadir}/%name-agent/lib/cloud-plugin-hypervisor-kvm-%{_maventag}.jar -cp plugins/hypervisors/kvm/target/dependencies/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib -cp plugins/storage/volume/storpool/target/*.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib -cp plugins/storage/volume/linstor/target/*.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib - -# Usage server -mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/usage -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-usage/lib -install -D usage/target/cloud-usage-%{_maventag}.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-usage/cloud-usage-%{_maventag}.jar -install -D usage/target/transformed/db.properties ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/usage/db.properties -install -D usage/target/transformed/log4j-cloud_usage.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/usage/log4j-cloud.xml -cp usage/target/dependencies/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-usage/lib/ -cp client/target/lib/mysql*jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-usage/lib/ -install -D packaging/systemd/cloudstack-usage.service ${RPM_BUILD_ROOT}%{_unitdir}/%{name}-usage.service -install -D packaging/systemd/cloudstack-usage.default ${RPM_BUILD_ROOT}%{_sysconfdir}/default/%{name}-usage -mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/usage/ - -# CLI -cp -r cloud-cli/cloudtool ${RPM_BUILD_ROOT}%{python_sitearch}/ -install cloud-cli/cloudapis/cloud.py ${RPM_BUILD_ROOT}%{python_sitearch}/cloudapis.py - -# Marvin -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-marvin -cp tools/marvin/dist/Marvin-*.tar.gz ${RPM_BUILD_ROOT}%{_datadir}/%{name}-marvin/ - -# integration-tests -mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-integration-tests -cp -r test/integration/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-integration-tests/ - -# MYSQL HA -if [ "x%{_ossnoss}" == "xnoredist" ] ; then - mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-mysql-ha/lib - cp -r plugins/database/mysql-ha/target/cloud-plugin-database-mysqlha-%{_maventag}.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-mysql-ha/lib -fi - -#License files from whisker -install -D tools/whisker/NOTICE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-management-%{version}/NOTICE -install -D tools/whisker/LICENSE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-management-%{version}/LICENSE -install -D tools/whisker/NOTICE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-common-%{version}/NOTICE -install -D tools/whisker/LICENSE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-common-%{version}/LICENSE -install -D tools/whisker/NOTICE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-agent-%{version}/NOTICE -install -D tools/whisker/LICENSE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-agent-%{version}/LICENSE -install -D tools/whisker/NOTICE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-usage-%{version}/NOTICE -install -D tools/whisker/LICENSE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-usage-%{version}/LICENSE -install -D tools/whisker/NOTICE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-ui-%{version}/NOTICE -install -D tools/whisker/LICENSE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-ui-%{version}/LICENSE -install -D tools/whisker/NOTICE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-cli-%{version}/NOTICE -install -D tools/whisker/LICENSE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-cli-%{version}/LICENSE -install -D tools/whisker/NOTICE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-marvin-%{version}/NOTICE -install -D tools/whisker/LICENSE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-marvin-%{version}/LICENSE -install -D tools/whisker/NOTICE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-integration-tests-%{version}/NOTICE -install -D tools/whisker/LICENSE ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}-integration-tests-%{version}/LICENSE - -%clean -[ ${RPM_BUILD_ROOT} != "/" ] && rm -rf ${RPM_BUILD_ROOT} - -%preun management -/usr/bin/systemctl stop cloudstack-management || true -/usr/bin/systemctl disable cloudstack-management || true - -%pre management -id cloud > /dev/null 2>&1 || /usr/sbin/useradd -M -U -c "CloudStack unprivileged user" \ - -r -s /bin/sh -d %{_localstatedir}/cloudstack/management cloud|| true - -rm -rf %{_localstatedir}/cache/cloudstack - -# in case of upgrade to 4.9+ copy commands.properties if not exists in /etc/cloudstack/management/ -if [ "$1" == "2" ] ; then - if [ -f "%{_datadir}/%{name}-management/webapps/client/WEB-INF/classes/commands.properties" ] && [ ! -f "%{_sysconfdir}/%{name}/management/commands.properties" ] ; then - cp -p %{_datadir}/%{name}-management/webapps/client/WEB-INF/classes/commands.properties %{_sysconfdir}/%{name}/management/commands.properties - fi -fi - -# Remove old tomcat symlinks and env config file -if [ -L "%{_datadir}/%{name}-management/lib" ] -then - rm -f %{_datadir}/%{name}-management/bin - rm -f %{_datadir}/%{name}-management/lib - rm -f %{_datadir}/%{name}-management/temp - rm -f %{_datadir}/%{name}-management/work - rm -f %{_sysconfdir}/default/%{name}-management -fi - -%post management -# Install mysql-connector-python -pip3 install %{_datadir}/%{name}-management/setup/wheel/six-1.15.0-py2.py3-none-any.whl %{_datadir}/%{name}-management/setup/wheel/setuptools-47.3.1-py3-none-any.whl %{_datadir}/%{name}-management/setup/wheel/protobuf-3.12.2-cp36-cp36m-manylinux1_x86_64.whl %{_datadir}/%{name}-management/setup/wheel/mysql_connector_python-8.0.20-cp36-cp36m-manylinux1_x86_64.whl - -pip3 install urllib3 - -/usr/bin/systemctl enable cloudstack-management > /dev/null 2>&1 || true -/usr/bin/systemctl enable --now rngd > /dev/null 2>&1 || true - -grep -s -q "db.cloud.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" || sed -i -e "\$adb.cloud.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" -grep -s -q "db.usage.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" || sed -i -e "\$adb.usage.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" -grep -s -q "db.simulator.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" || sed -i -e "\$adb.simulator.driver=jdbc:mysql" "%{_sysconfdir}/%{name}/management/db.properties" - -# Update DB properties having master and slave(s), with source and replica(s) respectively (for inclusiveness) -grep -s -q "^db.cloud.slaves=" "%{_sysconfdir}/%{name}/management/db.properties" && sed -i "s/^db.cloud.slaves=/db.cloud.replicas=/g" "%{_sysconfdir}/%{name}/management/db.properties" -grep -s -q "^db.cloud.secondsBeforeRetryMaster=" "%{_sysconfdir}/%{name}/management/db.properties" && sed -i "s/^db.cloud.secondsBeforeRetryMaster=/db.cloud.secondsBeforeRetrySource=/g" "%{_sysconfdir}/%{name}/management/db.properties" -grep -s -q "^db.cloud.queriesBeforeRetryMaster=" "%{_sysconfdir}/%{name}/management/db.properties" && sed -i "s/^db.cloud.queriesBeforeRetryMaster=/db.cloud.queriesBeforeRetrySource=/g" "%{_sysconfdir}/%{name}/management/db.properties" -grep -s -q "^db.usage.slaves=" "%{_sysconfdir}/%{name}/management/db.properties" && sed -i "s/^db.usage.slaves=/db.usage.replicas=/g" "%{_sysconfdir}/%{name}/management/db.properties" -grep -s -q "^db.usage.secondsBeforeRetryMaster=" "%{_sysconfdir}/%{name}/management/db.properties" && sed -i "s/^db.usage.secondsBeforeRetryMaster=/db.usage.secondsBeforeRetrySource=/g" "%{_sysconfdir}/%{name}/management/db.properties" -grep -s -q "^db.usage.queriesBeforeRetryMaster=" "%{_sysconfdir}/%{name}/management/db.properties" && sed -i "s/^db.usage.queriesBeforeRetryMaster=/db.usage.queriesBeforeRetrySource=/g" "%{_sysconfdir}/%{name}/management/db.properties" - -if [ ! -f %{_datadir}/cloudstack-common/scripts/vm/hypervisor/xenserver/vhd-util ] ; then - echo Please download vhd-util from http://download.cloudstack.org/tools/vhd-util and put it in - echo %{_datadir}/cloudstack-common/scripts/vm/hypervisor/xenserver/ -fi - -if [ -f %{_sysconfdir}/sysconfig/%{name}-management ] ; then - rm -f %{_sysconfdir}/sysconfig/%{name}-management -fi - -chown -R cloud:cloud /var/log/cloudstack/management - -systemctl daemon-reload - -%posttrans management -# Print help message -if [ -f "/usr/share/cloudstack-common/scripts/installer/cloudstack-help-text" ];then - sed -i "s,^ACS_VERSION=.*,ACS_VERSION=%{_maventag},g" /usr/share/cloudstack-common/scripts/installer/cloudstack-help-text - /usr/share/cloudstack-common/scripts/installer/cloudstack-help-text management -fi - -%preun agent -/sbin/service cloudstack-agent stop || true -if [ "$1" == "0" ] ; then - /sbin/chkconfig --del cloudstack-agent > /dev/null 2>&1 || true -fi - -%pre agent - -# save old configs if they exist (for upgrade). Otherwise we may lose them -# when the old packages are erased. There are a lot of properties files here. -if [ -d "%{_sysconfdir}/cloud" ] ; then - mv %{_sysconfdir}/cloud %{_sysconfdir}/cloud.rpmsave -fi - -%post agent -if [ "$1" == "2" ] ; then - echo "Running %{_bindir}/%{name}-agent-upgrade to update bridge name for upgrade from CloudStack 4.0.x (and before) to CloudStack 4.1 (and later)" - %{_bindir}/%{name}-agent-upgrade -fi -if [ ! -d %{_sysconfdir}/libvirt/hooks ] ; then - mkdir %{_sysconfdir}/libvirt/hooks -fi -cp -a ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook %{_sysconfdir}/libvirt/hooks/qemu -mkdir -m 0755 -p /usr/share/cloudstack-agent/tmp -/usr/bin/systemctl restart libvirtd -/usr/bin/systemctl enable cloudstack-agent > /dev/null 2>&1 || true -/usr/bin/systemctl enable cloudstack-rolling-maintenance@p > /dev/null 2>&1 || true -/usr/bin/systemctl enable --now rngd > /dev/null 2>&1 || true - -# if saved configs from upgrade exist, copy them over -if [ -f "%{_sysconfdir}/cloud.rpmsave/agent/agent.properties" ]; then - mv %{_sysconfdir}/%{name}/agent/agent.properties %{_sysconfdir}/%{name}/agent/agent.properties.rpmnew - cp -p %{_sysconfdir}/cloud.rpmsave/agent/agent.properties %{_sysconfdir}/%{name}/agent - # make sure we only do this on the first install of this RPM, don't want to overwrite on a reinstall - mv %{_sysconfdir}/cloud.rpmsave/agent/agent.properties %{_sysconfdir}/cloud.rpmsave/agent/agent.properties.rpmsave -fi - -systemctl daemon-reload - -%posttrans agent -# Print help message -if [ -f "/usr/share/cloudstack-common/scripts/installer/cloudstack-help-text" ];then - sed -i "s,^ACS_VERSION=.*,ACS_VERSION=%{_maventag},g" /usr/share/cloudstack-common/scripts/installer/cloudstack-help-text - /usr/share/cloudstack-common/scripts/installer/cloudstack-help-text agent -fi - -%pre usage -id cloud > /dev/null 2>&1 || /usr/sbin/useradd -M -U -c "CloudStack unprivileged user" \ - -r -s /bin/sh -d %{_localstatedir}/cloudstack/management cloud|| true - -%preun usage -/sbin/service cloudstack-usage stop || true -if [ "$1" == "0" ] ; then - /sbin/chkconfig --del cloudstack-usage > /dev/null 2>&1 || true -fi - -%post usage -if [ -f "%{_sysconfdir}/%{name}/management/db.properties" ]; then - echo "Replacing usage server's db.properties with a link to the management server's db.properties" - rm -f %{_sysconfdir}/%{name}/usage/db.properties - ln -s %{_sysconfdir}/%{name}/management/db.properties %{_sysconfdir}/%{name}/usage/db.properties - /usr/bin/systemctl enable cloudstack-usage > /dev/null 2>&1 || true -fi - -if [ -f "%{_sysconfdir}/%{name}/management/key" ]; then - echo "Replacing usage server's key with a link to the management server's key" - rm -f %{_sysconfdir}/%{name}/usage/key - ln -s %{_sysconfdir}/%{name}/management/key %{_sysconfdir}/%{name}/usage/key -fi - -if [ ! -f "%{_sysconfdir}/%{name}/usage/key" ]; then - ln -s %{_sysconfdir}/%{name}/management/key %{_sysconfdir}/%{name}/usage/key -fi - -mkdir -p /usr/local/libexec -if [ ! -f "/usr/local/libexec/sanity-check-last-id" ]; then - echo 1 > /usr/local/libexec/sanity-check-last-id -fi -chown cloud:cloud /usr/local/libexec/sanity-check-last-id - -%posttrans usage -# Print help message -if [ -f "/usr/share/cloudstack-common/scripts/installer/cloudstack-help-text" ];then - sed -i "s,^ACS_VERSION=.*,ACS_VERSION=%{_maventag},g" /usr/share/cloudstack-common/scripts/installer/cloudstack-help-text - /usr/share/cloudstack-common/scripts/installer/cloudstack-help-text usage -fi - -%post marvin -pip install --upgrade https://files.pythonhosted.org/packages/ca/ea/1e2553b088bad2f9fa8120c2624f797b2d7450d3b61bb492d29c72e3d3c2/mysql_connector_python-8.0.20-cp27-cp27mu-manylinux1_x86_64.whl -pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz -pip3 install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz -pip3 install --upgrade nose -pip3 install --upgrade urllib3 - -#No default permission as the permission setup is complex -%files management -%defattr(-,root,root,-) -%dir %{_datadir}/%{name}-management -%dir %attr(0770,root,cloud) %{_localstatedir}/%{name}/mnt -%dir %attr(0770,cloud,cloud) %{_localstatedir}/%{name}/management -%dir %attr(0770,root,cloud) %{_localstatedir}/cache/%{name}/management -%dir %attr(0770,root,cloud) %{_localstatedir}/log/%{name}/management -%config(noreplace) %{_sysconfdir}/default/%{name}-management -%config(noreplace) %{_sysconfdir}/sudoers.d/%{name}-management -%config(noreplace) %{_sysconfdir}/security/limits.d/cloud -%config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/db.properties -%config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/server.properties -%config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/config.json -%config(noreplace) %{_sysconfdir}/%{name}/management/log4j-cloud.xml -%config(noreplace) %{_sysconfdir}/%{name}/management/log4j.xml -%config(noreplace) %{_sysconfdir}/%{name}/management/environment.properties -%config(noreplace) %{_sysconfdir}/%{name}/management/java.security.ciphers -%attr(0644,root,root) %{_unitdir}/%{name}-management.service -%attr(0755,cloud,cloud) %{_localstatedir}/run/%{name}-management.pid -%attr(0755,root,root) %{_bindir}/%{name}-setup-management -%attr(0755,root,root) %{_bindir}/%{name}-update-xenserver-licenses -%{_datadir}/%{name}-management/conf -%{_datadir}/%{name}-management/lib/*.jar -%{_datadir}/%{name}-management/logs -%{_datadir}/%{name}-management/templates -%attr(0755,root,root) %{_bindir}/%{name}-setup-databases -%attr(0755,root,root) %{_bindir}/%{name}-migrate-databases -%attr(0755,root,root) %{_bindir}/%{name}-set-guest-password -%attr(0755,root,root) %{_bindir}/%{name}-set-guest-sshkey -%attr(0755,root,root) %{_bindir}/%{name}-sysvmadm -%attr(0755,root,root) %{_bindir}/%{name}-setup-encryption -%attr(0755,root,root) %{_bindir}/cmk -%{_datadir}/%{name}-management/setup/*.sql -%{_datadir}/%{name}-management/setup/*.sh -%{_datadir}/%{name}-management/setup/server-setup.xml -%{_datadir}/%{name}-management/webapp/* -%attr(0755,root,root) %{_bindir}/%{name}-external-ipallocator.py -%attr(0755,root,root) %{_initrddir}/%{name}-ipallocator -%dir %attr(0770,root,root) %{_localstatedir}/log/%{name}/ipallocator -%{_defaultdocdir}/%{name}-management-%{version}/LICENSE -%{_defaultdocdir}/%{name}-management-%{version}/NOTICE -#%attr(0644,root,root) %{_sysconfdir}/logrotate.d/%{name}-catalina -%{_datadir}/%{name}-management/setup/wheel/*.whl - -%files agent -%attr(0755,root,root) %{_bindir}/%{name}-setup-agent -%attr(0755,root,root) %{_bindir}/%{name}-agent-upgrade -%attr(0755,root,root) %{_bindir}/%{name}-guest-tool -%attr(0755,root,root) %{_bindir}/%{name}-ssh -%attr(0644,root,root) %{_unitdir}/%{name}-agent.service -%attr(0644,root,root) %{_unitdir}/%{name}-rolling-maintenance@.service -%config(noreplace) %{_sysconfdir}/default/%{name}-agent -%attr(0644,root,root) %{_sysconfdir}/profile.d/%{name}-agent-profile.sh -%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/logrotate.d/%{name}-agent -%attr(0755,root,root) %{_datadir}/%{name}-common/scripts/network/cisco -%config(noreplace) %{_sysconfdir}/%{name}/agent -%dir %{_localstatedir}/log/%{name}/agent -%attr(0644,root,root) %{_datadir}/%{name}-agent/lib/*.jar -%attr(0755,root,root) %{_datadir}/%{name}-agent/lib/libvirtqemuhook -%attr(0755,root,root) %{_datadir}/%{name}-agent/lib/rolling-maintenance -%dir %{_datadir}/%{name}-agent/plugins -%{_defaultdocdir}/%{name}-agent-%{version}/LICENSE -%{_defaultdocdir}/%{name}-agent-%{version}/NOTICE - -%files common -%dir %attr(0755,root,root) %{python_sitearch}/cloudutils -%dir %attr(0755,root,root) %{_datadir}/%{name}-common/vms -%attr(0755,root,root) %{_datadir}/%{name}-common/scripts -%attr(0755,root,root) /usr/bin/cloudstack-sccs -%attr(0644, root, root) %{_datadir}/%{name}-common/vms/agent.zip -%attr(0644, root, root) %{_datadir}/%{name}-common/vms/cloud-scripts.tgz -%attr(0644, root, root) %{_datadir}/%{name}-common/vms/patch-sysvms.sh -%attr(0644,root,root) %{python_sitearch}/cloud_utils.py -%attr(0644,root,root) %{python_sitearch}/__pycache__/* -%attr(0644,root,root) %{python_sitearch}/cloudutils/* -%attr(0644, root, root) %{_datadir}/%{name}-common/lib/jasypt-1.9.3.jar -%attr(0644, root, root) %{_datadir}/%{name}-common/lib/%{name}-utils.jar -%{_defaultdocdir}/%{name}-common-%{version}/LICENSE -%{_defaultdocdir}/%{name}-common-%{version}/NOTICE - -%files ui -%config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/ui/config.json -%{_datadir}/%{name}-ui/* -%{_defaultdocdir}/%{name}-ui-%{version}/LICENSE -%{_defaultdocdir}/%{name}-ui-%{version}/NOTICE - -%files usage -%attr(0644,root,root) %{_unitdir}/%{name}-usage.service -%config(noreplace) %{_sysconfdir}/default/%{name}-usage -%attr(0644,root,root) %{_datadir}/%{name}-usage/*.jar -%attr(0644,root,root) %{_datadir}/%{name}-usage/lib/*.jar -%dir %attr(0770,root,cloud) %{_localstatedir}/log/%{name}/usage -%attr(0644,root,root) %{_sysconfdir}/%{name}/usage/db.properties -%attr(0644,root,root) %{_sysconfdir}/%{name}/usage/log4j-cloud.xml -%{_defaultdocdir}/%{name}-usage-%{version}/LICENSE -%{_defaultdocdir}/%{name}-usage-%{version}/NOTICE - -%files cli -%attr(0644,root,root) %{python_sitearch}/cloudapis.py -%attr(0644,root,root) %{python_sitearch}/cloudtool/__init__.py -%attr(0644,root,root) %{python_sitearch}/cloudtool/utils.py -%{_defaultdocdir}/%{name}-cli-%{version}/LICENSE -%{_defaultdocdir}/%{name}-cli-%{version}/NOTICE - -%files marvin -%attr(0644,root,root) %{_datadir}/%{name}-marvin/Marvin*.tar.gz -%{_defaultdocdir}/%{name}-marvin-%{version}/LICENSE -%{_defaultdocdir}/%{name}-marvin-%{version}/NOTICE - -%files integration-tests -%attr(0755,root,root) %{_datadir}/%{name}-integration-tests/* -%{_defaultdocdir}/%{name}-integration-tests-%{version}/LICENSE -%{_defaultdocdir}/%{name}-integration-tests-%{version}/NOTICE - -%if "%{_ossnoss}" == "noredist" -%files mysql-ha -%defattr(0644,cloud,cloud,0755) -%attr(0644,root,root) %{_datadir}/%{name}-mysql-ha/lib/* -%endif - -%files baremetal-agent -%attr(0755,root,root) %{_bindir}/cloudstack-setup-baremetal - -%changelog -* Fri Oct 14 2022 Daan Hoogland 4.18.0 -- initialising sanity check pointer file - -* Thu Apr 30 2015 Rohit Yadav 4.6.0 -- Remove awsapi package - -* Wed Nov 19 2014 Hugo Trippaers 4.6.0 -- Create a specific spec for CentOS 7 - -* Fri Jul 4 2014 Hugo Trippaers 4.5.0 -- Add a package for the mysql ha module - -* Fri Oct 5 2012 Hugo Trippaers 4.1.0 -- new style spec file diff --git a/packaging/centos7/replace.properties b/packaging/centos7/replace.properties deleted file mode 100644 index 8c3560dd4622..000000000000 --- a/packaging/centos7/replace.properties +++ /dev/null @@ -1,59 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -DBUSER=cloud -DBPW=cloud -DBROOTPW= -MSLOG=vmops.log -APISERVERLOG=api.log -DBHOST=localhost -DBDRIVER=jdbc:mysql -COMPONENTS-SPEC=components-premium.xml -REMOTEHOST=localhost -AGENTCLASSPATH= -AGENTLOG=/var/log/cloudstack/agent/agent.log -AGENTLOGDIR=/var/log/cloudstack/agent/ -AGENTSYSCONFDIR=/etc/cloudstack/agent -APISERVERLOG=/var/log/cloudstack/management/apilog.log -BINDIR=/usr/bin -COMMONLIBDIR=/usr/share/cloudstack-common -CONFIGUREVARS= -DEPSCLASSPATH= -DOCDIR= -IPALOCATORLOG=/var/log/cloudstack/management/ipallocator.log -JAVADIR=/usr/share/java -LIBEXECDIR=/usr/libexec -LOCKDIR=/var/lock -MSCLASSPATH= -MSCONF=/etc/cloudstack/management -MSENVIRON=/usr/share/cloudstack-management -MSLOG=/var/log/cloudstack/management/management-server.log -MSLOGDIR=/var/log/cloudstack/management/ -MSMNTDIR=/var/cloudstack/mnt -MSUSER=cloud -PIDDIR=/var/run -PLUGINJAVADIR=/usr/share/cloudstack-management/plugin -PREMIUMJAVADIR=/usr/share/cloudstack-management/premium -PYTHONDIR=/usr/lib/python3.6/site-packages/ -SERVERSYSCONFDIR=/etc/sysconfig -SETUPDATADIR=/usr/share/cloudstack-management/setup -SYSCONFDIR=/etc/sysconfig -SYSTEMCLASSPATH= -SYSTEMJARS= -USAGECLASSPATH= -USAGELOG=/var/log/cloudstack/usage/usage.log -USAGESYSCONFDIR=/etc/sysconfig diff --git a/packaging/centos8 b/packaging/centos8 new file mode 120000 index 000000000000..4dad90d45e0c --- /dev/null +++ b/packaging/centos8 @@ -0,0 +1 @@ +el8 \ No newline at end of file diff --git a/packaging/centos8/cloud-ipallocator.rc b/packaging/centos8/cloud-ipallocator.rc deleted file mode 100755 index 255725b94d07..000000000000 --- a/packaging/centos8/cloud-ipallocator.rc +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -# chkconfig: 35 99 10 -# description: Cloud Agent - -# WARNING: if this script is changed, then all other initscripts MUST BE changed to match it as well - -. /etc/rc.d/init.d/functions - -# set environment variables - -SHORTNAME="$(basename $(readlink -f $0))" -PIDFILE=/var/run/"$SHORTNAME".pid -LOCKFILE=/var/lock/subsys/"$SHORTNAME" -LOGFILE=/var/log/cloudstack/ipallocator/ipallocator.log -PROGNAME="External IPAllocator" - -unset OPTIONS -[ -r /etc/sysconfig/"$SHORTNAME" ] && source /etc/sysconfig/"$SHORTNAME" -DAEMONIZE=/usr/bin/cloud-daemonize -PROG=/usr/bin/cloud-external-ipallocator.py -OPTIONS=8083 - -start() { - echo -n $"Starting $PROGNAME: " - if hostname --fqdn >/dev/null 2>&1 ; then - daemon --check=$SHORTNAME --pidfile=${PIDFILE} "$DAEMONIZE" \ - -n "$SHORTNAME" -p "$PIDFILE" -l "$LOGFILE" "$PROG" $OPTIONS - RETVAL=$? - echo - else - failure - echo - echo The host name does not resolve properly to an IP address. Cannot start "$PROGNAME". > /dev/stderr - RETVAL=9 - fi - [ $RETVAL = 0 ] && touch ${LOCKFILE} - return $RETVAL -} - -stop() { - echo -n $"Stopping $PROGNAME: " - killproc -p ${PIDFILE} $SHORTNAME # -d 10 $SHORTNAME - RETVAL=$? - echo - [ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE} -} - - -# See how we were called. -case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status -p ${PIDFILE} $SHORTNAME - RETVAL=$? - ;; - restart) - stop - sleep 3 - start - ;; - condrestart) - if status -p ${PIDFILE} $SHORTNAME >&/dev/null; then - stop - sleep 3 - start - fi - ;; - *) - echo $"Usage: $SHORTNAME {start|stop|restart|condrestart|status|help}" - RETVAL=3 -esac - -exit $RETVAL diff --git a/packaging/debian/replace.properties b/packaging/debian/replace.properties index 5007360a2b70..db88310d81cd 100644 --- a/packaging/debian/replace.properties +++ b/packaging/debian/replace.properties @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/packaging/centos7/cloud-ipallocator.rc b/packaging/el8/cloud-ipallocator.rc similarity index 100% rename from packaging/centos7/cloud-ipallocator.rc rename to packaging/el8/cloud-ipallocator.rc diff --git a/packaging/centos7/cloud.limits b/packaging/el8/cloud.limits similarity index 100% rename from packaging/centos7/cloud.limits rename to packaging/el8/cloud.limits diff --git a/packaging/centos8/cloud.spec b/packaging/el8/cloud.spec similarity index 95% rename from packaging/centos8/cloud.spec rename to packaging/el8/cloud.spec index c1277823b2ca..a88d4b1cbbf9 100644 --- a/packaging/centos8/cloud.spec +++ b/packaging/el8/cloud.spec @@ -36,7 +36,7 @@ Group: System Environment/Libraries Source0: %{name}-%{_maventag}.tgz BuildRoot: %{_tmppath}/%{name}-%{_maventag}-%{release}-build -BuildRequires: java-11-openjdk-devel +BuildRequires: (java-11-openjdk-devel or java-17-openjdk-devel) #BuildRequires: ws-commons-util BuildRequires: jpackage-utils BuildRequires: gcc @@ -52,7 +52,7 @@ intelligent IaaS cloud implementation. %package management Summary: CloudStack management server UI -Requires: java-11-openjdk +Requires: java-17-openjdk Requires: (tzdata-java or timezone-java) Requires: python3 Requires: bash @@ -98,7 +98,7 @@ The Apache CloudStack files shared between agent and management server %package agent Summary: CloudStack Agent for KVM hypervisors Requires: (openssh-clients or openssh) -Requires: java-11-openjdk +Requires: java-17-openjdk Requires: tzdata-java Requires: %{name}-common = %{_ver} Requires: libvirt @@ -109,6 +109,7 @@ Requires: (net-tools or net-tools-deprecated) Requires: iproute Requires: ipset Requires: perl +Requires: rsync Requires: (python3-libvirt or python3-libvirt-python) Requires: (qemu-img or qemu-tools) Requires: qemu-kvm @@ -135,7 +136,7 @@ The CloudStack baremetal agent %package usage Summary: CloudStack Usage calculation server -Requires: java-11-openjdk +Requires: java-17-openjdk Requires: tzdata-java Group: System Environment/Libraries %description usage @@ -181,7 +182,7 @@ echo Doing CloudStack build %build -cp packaging/centos8/replace.properties build/replace.properties +cp packaging/el8/replace.properties build/replace.properties echo VERSION=%{_maventag} >> build/replace.properties echo PACKAGE=%{name} >> build/replace.properties touch build/gitrev.txt @@ -232,7 +233,7 @@ cp -r python/lib/cloudutils ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/python-s python3 -m py_compile ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/python-site/cloud_utils.py python3 -m compileall ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/python-site/cloudutils cp build/gitrev.txt ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts -cp packaging/centos8/cloudstack-sccs ${RPM_BUILD_ROOT}/usr/bin +cp packaging/el8/cloudstack-sccs ${RPM_BUILD_ROOT}/usr/bin mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco cp -r plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco @@ -260,7 +261,8 @@ install -D client/target/utilities/bin/cloud-setup-baremetal ${RPM_BUILD_ROOT}%{ install -D client/target/utilities/bin/cloud-sysvmadm ${RPM_BUILD_ROOT}%{_bindir}/%{name}-sysvmadm install -D client/target/utilities/bin/cloud-update-xenserver-licenses ${RPM_BUILD_ROOT}%{_bindir}/%{name}-update-xenserver-licenses # Bundle cmk in cloudstack-management -wget https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -O ${RPM_BUILD_ROOT}%{_bindir}/cmk +CMK_REL=$(wget -O - "https://api.github.com/repos/apache/cloudstack-cloudmonkey/releases" 2>/dev/null | jq -r '.[0].tag_name') +wget https://github.com/apache/cloudstack-cloudmonkey/releases/download/$CMK_REL/cmk.linux.x86-64 -O ${RPM_BUILD_ROOT}%{_bindir}/cmk chmod +x ${RPM_BUILD_ROOT}%{_bindir}/cmk cp -r client/target/utilities/scripts/db/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup @@ -283,19 +285,20 @@ do cp client/target/conf/$name ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/$name done -ln -sf log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/log4j.xml +ln -sf log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/log4j2.xml install python/bindir/cloud-external-ipallocator.py ${RPM_BUILD_ROOT}%{_bindir}/%{name}-external-ipallocator.py install -D client/target/pythonlibs/jasypt-1.9.3.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/lib/jasypt-1.9.3.jar install -D utils/target/cloud-utils-%{_maventag}-bundled.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/lib/%{name}-utils.jar -install -D packaging/centos8/cloud-ipallocator.rc ${RPM_BUILD_ROOT}%{_initrddir}/%{name}-ipallocator -install -D packaging/centos8/cloud.limits ${RPM_BUILD_ROOT}%{_sysconfdir}/security/limits.d/cloud +install -D packaging/el8/cloud-ipallocator.rc ${RPM_BUILD_ROOT}%{_initrddir}/%{name}-ipallocator +install -D packaging/el8/cloud.limits ${RPM_BUILD_ROOT}%{_sysconfdir}/security/limits.d/cloud install -D packaging/systemd/cloudstack-management.service ${RPM_BUILD_ROOT}%{_unitdir}/%{name}-management.service install -D packaging/systemd/cloudstack-management.default ${RPM_BUILD_ROOT}%{_sysconfdir}/default/%{name}-management install -D server/target/conf/cloudstack-sudoers ${RPM_BUILD_ROOT}%{_sysconfdir}/sudoers.d/%{name}-management touch ${RPM_BUILD_ROOT}%{_localstatedir}/run/%{name}-management.pid #install -D server/target/conf/cloudstack-catalina.logrotate ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}-catalina +install -D server/target/conf/cloudstack-management.logrotate ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}-management # SystemVM template mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/templates/systemvm @@ -360,6 +363,7 @@ cp client/target/lib/mysql*jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-usage/lib/ install -D packaging/systemd/cloudstack-usage.service ${RPM_BUILD_ROOT}%{_unitdir}/%{name}-usage.service install -D packaging/systemd/cloudstack-usage.default ${RPM_BUILD_ROOT}%{_sysconfdir}/default/%{name}-usage mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/usage/ +install -D usage/target/transformed/cloudstack-usage.logrotate ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}-usage # Marvin mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-marvin @@ -556,8 +560,8 @@ if [ -f "/usr/share/cloudstack-common/scripts/installer/cloudstack-help-text" ]; fi %post marvin -pip install --upgrade https://files.pythonhosted.org/packages/08/1f/42d74bae9dd6dcfec67c9ed0f3fa482b1ae5ac5f117ca82ab589ecb3ca19/mysql_connector_python-8.0.31-py2.py3-none-any.whl -pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz +pip3 install --upgrade https://files.pythonhosted.org/packages/08/1f/42d74bae9dd6dcfec67c9ed0f3fa482b1ae5ac5f117ca82ab589ecb3ca19/mysql_connector_python-8.0.31-py2.py3-none-any.whl +pip3 install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz #No default permission as the permission setup is complex %files management @@ -574,9 +578,10 @@ pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz %config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/server.properties %config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/config.json %config(noreplace) %{_sysconfdir}/%{name}/management/log4j-cloud.xml -%config(noreplace) %{_sysconfdir}/%{name}/management/log4j.xml +%config(noreplace) %{_sysconfdir}/%{name}/management/log4j2.xml %config(noreplace) %{_sysconfdir}/%{name}/management/environment.properties %config(noreplace) %{_sysconfdir}/%{name}/management/java.security.ciphers +%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/logrotate.d/%{name}-management %attr(0644,root,root) %{_unitdir}/%{name}-management.service %attr(0755,cloud,cloud) %{_localstatedir}/run/%{name}-management.pid %attr(0755,root,root) %{_bindir}/%{name}-setup-management @@ -648,6 +653,7 @@ pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz %files usage %attr(0644,root,root) %{_unitdir}/%{name}-usage.service %config(noreplace) %{_sysconfdir}/default/%{name}-usage +%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/logrotate.d/%{name}-usage %attr(0644,root,root) %{_datadir}/%{name}-usage/*.jar %attr(0644,root,root) %{_datadir}/%{name}-usage/lib/*.jar %dir %attr(0770,root,cloud) %{_localstatedir}/log/%{name}/usage diff --git a/packaging/centos7/cloudstack-agent.te b/packaging/el8/cloudstack-agent.te similarity index 100% rename from packaging/centos7/cloudstack-agent.te rename to packaging/el8/cloudstack-agent.te diff --git a/packaging/centos7/cloudstack-sccs b/packaging/el8/cloudstack-sccs similarity index 100% rename from packaging/centos7/cloudstack-sccs rename to packaging/el8/cloudstack-sccs diff --git a/packaging/centos8/replace.properties b/packaging/el8/replace.properties similarity index 99% rename from packaging/centos8/replace.properties rename to packaging/el8/replace.properties index 8f1fb11f9995..efeab01166ea 100644 --- a/packaging/centos8/replace.properties +++ b/packaging/el8/replace.properties @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/packaging/el9 b/packaging/el9 index 575742e7ff2f..4dad90d45e0c 120000 --- a/packaging/el9 +++ b/packaging/el9 @@ -1 +1 @@ -centos8 \ No newline at end of file +el8 \ No newline at end of file diff --git a/packaging/package.sh b/packaging/package.sh index bf95f84a11a7..ecffaace48b5 100755 --- a/packaging/package.sh +++ b/packaging/package.sh @@ -22,11 +22,11 @@ Usage: ./package.sh -d DISTRO [OPTIONS]... Package CloudStack for specific distribution and provided options. If there's a "branding" string in the POM version (e.g. x.y.z.a-NAME[-SNAPSHOT]), the branding name will -be used in the final generated package like: cloudstack-management-x.y.z.a-NAME.NUMBER.el7.centos.x86_64 +be used in the final generated package like: cloudstack-management-x.y.z.a-NAME.NUMBER.el.x86_64 note that you can override/provide "branding" string with "-b, --brand" flag as well. Mandatory arguments: - -d, --distribution string Build package for specified distribution ("centos7") + -d, --distribution string Build package for specified distribution ("el8") Optional arguments: -p, --pack string Define which type of libraries to package ("oss"|"OSS"|"noredist"|"NOREDIST") (default "oss") @@ -42,12 +42,12 @@ Other arguments: -h, --help Display this help message and exit Examples: - package.sh --distribution centos7 - package.sh --distribution centos7 --pack oss - package.sh --distribution centos7 --pack noredist - package.sh --distribution centos7 --pack noredist -t "kvm,xen" - package.sh --distribution centos7 --release 42 - package.sh --distribution centos7 --pack noredist --release 42 + package.sh --distribution el8 + package.sh --distribution el8 --pack oss + package.sh --distribution el8 --pack noredist + package.sh --distribution el8 --pack noredist -t "kvm,xen" + package.sh --distribution el8 --release 42 + package.sh --distribution el8 --pack noredist --release 42 USAGE exit 0 diff --git a/packaging/suse15 b/packaging/suse15 index 575742e7ff2f..4dad90d45e0c 120000 --- a/packaging/suse15 +++ b/packaging/suse15 @@ -1 +1 @@ -centos8 \ No newline at end of file +el8 \ No newline at end of file diff --git a/packaging/systemd/cloudstack-agent.service b/packaging/systemd/cloudstack-agent.service index e04d672beaaa..5e2e5db0b210 100644 --- a/packaging/systemd/cloudstack-agent.service +++ b/packaging/systemd/cloudstack-agent.service @@ -31,6 +31,8 @@ EnvironmentFile=/etc/default/cloudstack-agent ExecStart=/usr/bin/java $JAVA_OPTS $JAVA_DEBUG -cp $CLASSPATH $JAVA_CLASS Restart=always RestartSec=10s +StandardOutput=append:/var/log/cloudstack/agent/agent.out +StandardError=append:/var/log/cloudstack/agent/agent.err [Install] WantedBy=multi-user.target diff --git a/packaging/systemd/cloudstack-management.default b/packaging/systemd/cloudstack-management.default index d0b41b4b5641..994a1ee86997 100644 --- a/packaging/systemd/cloudstack-management.default +++ b/packaging/systemd/cloudstack-management.default @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -JAVA_OPTS="-Djava.security.properties=/etc/cloudstack/management/java.security.ciphers -Djava.awt.headless=true -Xmx2G -XX:+UseParallelGC -XX:MaxGCPauseMillis=500 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/cloudstack/management/ -XX:ErrorFile=/var/log/cloudstack/management/cloudstack-management.err " +JAVA_OPTS="-Djava.security.properties=/etc/cloudstack/management/java.security.ciphers -Djava.awt.headless=true -Xmx2G -XX:+UseParallelGC -XX:MaxGCPauseMillis=500 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/cloudstack/management/ -XX:ErrorFile=/var/log/cloudstack/management/cloudstack-management.err --add-opens=java.base/java.lang=ALL-UNNAMED --add-exports=java.base/sun.security.x509=ALL-UNNAMED" CLASSPATH="/usr/share/cloudstack-management/lib/*:/etc/cloudstack/management:/usr/share/cloudstack-common:/usr/share/cloudstack-management/setup:/usr/share/cloudstack-management:/usr/share/java/mysql-connector-java.jar:/usr/share/cloudstack-mysql-ha/lib/*" @@ -24,7 +24,7 @@ BOOTSTRAP_CLASS=org.apache.cloudstack.ServerDaemon ################################################################################################ #You can uncomment one of these options if you want to enable Java remote debugging. # #You can change the parameters at your will. The 'address' field defines the port to be used. # -################################################################################################ +################################################################################################ # This option here should be used with 'systemmd' based operating systems such as CentOS7, Ubuntu 16, and so on. #JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n" diff --git a/packaging/systemd/cloudstack-management.service b/packaging/systemd/cloudstack-management.service index b979f7f375a7..55780af7a5c6 100644 --- a/packaging/systemd/cloudstack-management.service +++ b/packaging/systemd/cloudstack-management.service @@ -35,6 +35,8 @@ EnvironmentFile=/etc/default/cloudstack-management WorkingDirectory=/var/log/cloudstack/management PIDFile=/var/run/cloudstack-management.pid ExecStart=/usr/bin/java $JAVA_DEBUG $JAVA_OPTS -cp $CLASSPATH $BOOTSTRAP_CLASS +StandardOutput=append:/var/log/cloudstack/management/management-server.out +StandardError=append:/var/log/cloudstack/management/management-server.err [Install] WantedBy=multi-user.target diff --git a/packaging/systemd/cloudstack-usage.default b/packaging/systemd/cloudstack-usage.default index 089f3eec09cd..493f40c277a2 100644 --- a/packaging/systemd/cloudstack-usage.default +++ b/packaging/systemd/cloudstack-usage.default @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -JAVA_OPTS="-Xms256m -Xmx2048m" +JAVA_OPTS="-Xms256m -Xmx2048m --add-opens=java.base/java.lang=ALL-UNNAMED" CLASSPATH="/usr/share/cloudstack-usage/*:/usr/share/cloudstack-usage/lib/*:/usr/share/cloudstack-mysql-ha/lib/*:/etc/cloudstack/usage:/usr/share/java/mysql-connector-java.jar" diff --git a/packaging/systemd/cloudstack-usage.service b/packaging/systemd/cloudstack-usage.service index c23814eaac66..bf5bd2a189b9 100644 --- a/packaging/systemd/cloudstack-usage.service +++ b/packaging/systemd/cloudstack-usage.service @@ -35,6 +35,8 @@ Environment=JAVA_PID=$$ ExecStart=/bin/sh -ec '/usr/bin/java -Dpid=${JAVA_PID} $JAVA_OPTS $JAVA_DEBUG -cp $CLASSPATH $JAVA_CLASS' Restart=always RestartSec=10s +StandardOutput=append:/var/log/cloudstack/usage/usage.out +StandardError=append:/var/log/cloudstack/usage/usage.err [Install] WantedBy=multi-user.target diff --git a/plugins/acl/dynamic-role-based/pom.xml b/plugins/acl/dynamic-role-based/pom.xml index 11da092c94b6..b1972a54ba5d 100644 --- a/plugins/acl/dynamic-role-based/pom.xml +++ b/plugins/acl/dynamic-role-based/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java b/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java index 1dfe20a10be2..db40b6e68ddd 100644 --- a/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java +++ b/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java @@ -27,7 +27,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.APICommand; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RolePermissionEntity.Permission; import com.cloud.exception.PermissionDeniedException; @@ -49,7 +48,6 @@ public class DynamicRoleBasedAPIAccessChecker extends AdapterBase implements API private List services; private Map> annotationRoleBasedApisMap = new HashMap>(); - private static final Logger LOGGER = Logger.getLogger(DynamicRoleBasedAPIAccessChecker.class.getName()); protected DynamicRoleBasedAPIAccessChecker() { super(); @@ -92,8 +90,8 @@ public boolean checkApiPermissionByRole(Role role, String apiName, List org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/acl/project-role-based/src/main/java/org/apache/cloudstack/acl/ProjectRoleBasedApiAccessChecker.java b/plugins/acl/project-role-based/src/main/java/org/apache/cloudstack/acl/ProjectRoleBasedApiAccessChecker.java index cffda4681c66..2e7ae23d6f1b 100644 --- a/plugins/acl/project-role-based/src/main/java/org/apache/cloudstack/acl/ProjectRoleBasedApiAccessChecker.java +++ b/plugins/acl/project-role-based/src/main/java/org/apache/cloudstack/acl/ProjectRoleBasedApiAccessChecker.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.acl.RolePermissionEntity.Permission; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.UnavailableCommandException; @@ -49,7 +48,6 @@ public class ProjectRoleBasedApiAccessChecker extends AdapterBase implements AP AccountService accountService; private List services; - private static final Logger LOGGER = Logger.getLogger(ProjectRoleBasedApiAccessChecker.class.getName()); protected ProjectRoleBasedApiAccessChecker() { super(); } @@ -61,9 +59,7 @@ private void denyApiAccess(final String commandName) throws PermissionDeniedExce @Override public boolean isEnabled() { if (!roleService.isEnabled()) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("RoleService is disabled. We will not use ProjectRoleBasedApiAccessChecker."); - } + logger.trace("RoleService is disabled. We will not use ProjectRoleBasedApiAccessChecker."); } return roleService.isEnabled(); } @@ -76,8 +72,8 @@ public List getApisAllowedToUser(Role role, User user, List apiN Project project = CallContext.current().getProject(); if (project == null) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning APIs [%s] for user [%s] as allowed.", apiNames, user)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning APIs [%s] for user [%s] as allowed.", apiNames, user)); } return apiNames; } @@ -88,8 +84,8 @@ public List getApisAllowedToUser(Role role, User user, List apiN if (projectUser.getAccountRole() != ProjectAccount.Role.Admin) { apiNames.removeIf(apiName -> !isPermitted(project, projectUser, apiName)); } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Returning APIs [%s] as allowed for user [%s].", apiNames, user)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Returning APIs [%s] as allowed for user [%s].", apiNames, user)); } return apiNames; } @@ -102,8 +98,8 @@ public List getApisAllowedToUser(Role role, User user, List apiN if (projectAccount.getAccountRole() != ProjectAccount.Role.Admin) { apiNames.removeIf(apiName -> !isPermitted(project, projectAccount, apiName)); } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Returning APIs [%s] as allowed for user [%s].", apiNames, user)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Returning APIs [%s] as allowed for user [%s].", apiNames, user)); } return apiNames; } @@ -116,8 +112,8 @@ public boolean checkAccess(User user, String apiCommandName) throws PermissionDe Project project = CallContext.current().getProject(); if (project == null) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning API [%s] for user [%s] as allowed.", apiCommandName, + if (logger.isTraceEnabled()) { + logger.trace(String.format("Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning API [%s] for user [%s] as allowed.", apiCommandName, user)); } return true; @@ -125,9 +121,7 @@ public boolean checkAccess(User user, String apiCommandName) throws PermissionDe Account userAccount = accountService.getAccount(user.getAccountId()); if (accountService.isRootAdmin(userAccount.getId()) || accountService.isDomainAdmin(userAccount.getAccountId())) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Account [%s] is Root Admin or Domain Admin, all APIs are allowed.", userAccount.getAccountName())); - } + logger.info(String.format("Account [%s] is Root Admin or Domain Admin, all APIs are allowed.", userAccount.getAccountName())); return true; } diff --git a/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/acl/static-role-based/pom.xml b/plugins/acl/static-role-based/pom.xml index 31f361b52c09..62fb60395e09 100644 --- a/plugins/acl/static-role-based/pom.xml +++ b/plugins/acl/static-role-based/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java b/plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java index 7d12178f0f38..3444f967d784 100644 --- a/plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java +++ b/plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java @@ -26,7 +26,6 @@ import javax.naming.ConfigurationException; import com.cloud.exception.UnavailableCommandException; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ @Deprecated public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIAclChecker { - protected static final Logger LOGGER = Logger.getLogger(StaticRoleBasedAPIAccessChecker.class); private Set commandPropertyFiles = new HashSet(); private Set commandNames = new HashSet(); @@ -74,7 +72,7 @@ public StaticRoleBasedAPIAccessChecker() { @Override public boolean isEnabled() { if (roleService.isEnabled()) { - LOGGER.debug("RoleService is enabled. We will use it instead of StaticRoleBasedAPIAccessChecker."); + logger.debug("RoleService is enabled. We will use it instead of StaticRoleBasedAPIAccessChecker."); } return !roleService.isEnabled(); } @@ -180,7 +178,7 @@ private void processMapping(Map configMap) { commandsPropertiesRoleBasedApisMap.get(roleType).add(apiName); } } catch (NumberFormatException nfe) { - LOGGER.error(String.format("Malformed key=value pair for entry: [%s].", entry)); + logger.error(String.format("Malformed key=value pair for entry: [%s].", entry)); } } } diff --git a/plugins/acl/static-role-based/src/main/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml b/plugins/acl/static-role-based/src/main/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml index 633602e76c15..4c6906605020 100644 --- a/plugins/acl/static-role-based/src/main/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml +++ b/plugins/acl/static-role-based/src/main/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml @@ -25,7 +25,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" - > + > diff --git a/plugins/affinity-group-processors/explicit-dedication/pom.xml b/plugins/affinity-group-processors/explicit-dedication/pom.xml index 6f2fa6bccafd..d6827ee13b6e 100644 --- a/plugins/affinity-group-processors/explicit-dedication/pom.xml +++ b/plugins/affinity-group-processors/explicit-dedication/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/explicit-dedication/src/main/java/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java b/plugins/affinity-group-processors/explicit-dedication/src/main/java/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java index 952830284410..ec6674477b07 100644 --- a/plugins/affinity-group-processors/explicit-dedication/src/main/java/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java +++ b/plugins/affinity-group-processors/explicit-dedication/src/main/java/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; -import org.apache.log4j.Logger; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter; @@ -56,7 +55,6 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implements AffinityGroupProcessor { - private static final Logger s_logger = Logger.getLogger(ExplicitDedicationProcessor.class); @Inject protected UserVmDao _vmDao; @Inject @@ -96,8 +94,8 @@ public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, Exclud for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { if (vmGroupMapping != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + "of type 'ExplicitDedication' for VM Id: " + vm.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + "of type 'ExplicitDedication' for VM Id: " + vm.getId()); } long affinityGroupId = vmGroupMapping.getAffinityGroupId(); @@ -234,13 +232,13 @@ public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, Exclud avoid = updateAvoidList(resourceList, avoid, dc); } else { avoid.addDataCenter(dc.getId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("No dedicated resources available for this domain or account under this group"); + if (logger.isDebugEnabled()) { + logger.debug("No dedicated resources available for this domain or account under this group"); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " + avoid.getPodsToAvoid() + ", clusters: " + + if (logger.isDebugEnabled()) { + logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " + avoid.getPodsToAvoid() + ", clusters: " + avoid.getClustersToAvoid() + ", hosts: " + avoid.getHostsToAvoid()); } } @@ -305,8 +303,8 @@ private ExcludeList updateAvoidList(List dedicatedResources for (HostPodVO pod : podList) { DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId()); if (dPod != null && !dedicatedResources.contains(dPod)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Avoiding POD %s [%s] because it is not dedicated.", pod.getName(), pod.getUuid())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Avoiding POD %s [%s] because it is not dedicated.", pod.getName(), pod.getUuid())); } avoidList.addPod(pod.getId()); } else { @@ -346,8 +344,8 @@ private ExcludeList updateAvoidList(List dedicatedResources for (HostPodVO pod : pods) { if (podsInIncludeList != null && !podsInIncludeList.contains(pod.getId())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Avoiding POD %s [%s], as it is not in include list.", pod.getName(), pod.getUuid())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Avoiding POD %s [%s], as it is not in include list.", pod.getName(), pod.getUuid())); } avoidList.addPod(pod.getId()); } @@ -413,8 +411,8 @@ public void handleDeleteGroup(final AffinityGroup group) { if (group != null) { List dedicatedResources = _dedicatedDao.listByAffinityGroupId(group.getId()); if (!dedicatedResources.isEmpty()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing the dedicated resources under group: " + group); + if (logger.isDebugEnabled()) { + logger.debug("Releasing the dedicated resources under group: " + group); } Transaction.execute(new TransactionCallbackNoReturn() { @@ -431,8 +429,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) { } }); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("No dedicated resources to releease under group: " + group); + if (logger.isDebugEnabled()) { + logger.debug("No dedicated resources to releease under group: " + group); } } } diff --git a/plugins/affinity-group-processors/explicit-dedication/src/main/resources/META-INF/cloudstack/explicit-dedication/spring-explicit-dedication-context.xml b/plugins/affinity-group-processors/explicit-dedication/src/main/resources/META-INF/cloudstack/explicit-dedication/spring-explicit-dedication-context.xml index 7e98c3880267..5f049fa3d953 100644 --- a/plugins/affinity-group-processors/explicit-dedication/src/main/resources/META-INF/cloudstack/explicit-dedication/spring-explicit-dedication-context.xml +++ b/plugins/affinity-group-processors/explicit-dedication/src/main/resources/META-INF/cloudstack/explicit-dedication/spring-explicit-dedication-context.xml @@ -32,5 +32,5 @@ - + diff --git a/plugins/affinity-group-processors/host-affinity/pom.xml b/plugins/affinity-group-processors/host-affinity/pom.xml index 5755fcf41c5f..bd9992887171 100644 --- a/plugins/affinity-group-processors/host-affinity/pom.xml +++ b/plugins/affinity-group-processors/host-affinity/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java b/plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java index 072eff09215c..b94cf49e4d94 100644 --- a/plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java +++ b/plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java @@ -32,7 +32,6 @@ import com.cloud.utils.db.TransactionCallbackNoReturn; import com.cloud.utils.db.TransactionStatus; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -47,7 +46,6 @@ public class HostAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor { - private static final Logger s_logger = Logger.getLogger(HostAffinityProcessor.class); @Inject protected VMInstanceDao _vmInstanceDao; @@ -65,7 +63,9 @@ public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, Exclud Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { - _affinityGroupDao.listByIds(affinityGroupIdList, true); + if (!affinityGroupIdList.isEmpty()) { + _affinityGroupDao.listByIds(affinityGroupIdList, true); + } for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { processAffinityGroup(vmGroupMapping, plan, vm, vmList); } @@ -80,7 +80,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { */ protected void processAffinityGroup(AffinityGroupVMMapVO vmGroupMapping, DeploymentPlan plan, VirtualMachine vm, List vmList) { AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId()); - s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); + logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); List groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId()); groupVMIds.remove(vm.getId()); @@ -151,7 +151,9 @@ public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedD return Transaction.execute(new TransactionCallback() { @Override public Boolean doInTransaction(TransactionStatus status) { - _affinityGroupDao.listByIds(affinityGroupIds, true); + if (!affinityGroupIds.isEmpty()) { + _affinityGroupDao.listByIds(affinityGroupIds, true); + } for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { if (!checkAffinityGroup(vmGroupMapping, vm, plannedHostId)) { return false; diff --git a/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java b/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java index 66f3a37ae1b0..3813c81b88f7 100644 --- a/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java +++ b/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java @@ -25,6 +25,7 @@ import com.cloud.vm.dao.VMInstanceDao; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,8 +44,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -99,9 +100,11 @@ public class HostAffinityProcessorTest { @Mock VirtualMachineProfile profile; + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); when(groupVM1.getHostId()).thenReturn(HOST_ID); when(groupVM2.getHostId()).thenReturn(HOST_ID); @@ -124,6 +127,11 @@ public void setup() { when(affinityGroupVMMapDao.findByVmIdType(eq(VM_ID), any())).thenReturn(new ArrayList<>(Arrays.asList(mapVO))); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testProcessAffinityGroupMultipleVMs() { processor.processAffinityGroup(mapVO, plan, vm); diff --git a/plugins/affinity-group-processors/host-anti-affinity/pom.xml b/plugins/affinity-group-processors/host-anti-affinity/pom.xml index 6da88d966b45..b224bbaf34a0 100644 --- a/plugins/affinity-group-processors/host-anti-affinity/pom.xml +++ b/plugins/affinity-group-processors/host-anti-affinity/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/main/java/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/main/java/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java index 970632906c64..4681ce4321ee 100644 --- a/plugins/affinity-group-processors/host-anti-affinity/src/main/java/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java +++ b/plugins/affinity-group-processors/host-anti-affinity/src/main/java/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java @@ -24,13 +24,7 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.utils.DateUtil; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.db.TransactionCallback; -import com.cloud.utils.db.TransactionCallbackNoReturn; -import com.cloud.utils.db.TransactionStatus; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -43,7 +37,12 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.exception.AffinityConflictException; +import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import com.cloud.utils.db.TransactionCallbackNoReturn; +import com.cloud.utils.db.TransactionStatus; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @@ -52,7 +51,6 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor { - private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class); @Inject protected UserVmDao _vmDao; @Inject @@ -80,7 +78,9 @@ public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, Exclud Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(TransactionStatus status) { - _affinityGroupDao.listByIds(affinityGroupIds, true); + if (!affinityGroupIds.isEmpty()) { + _affinityGroupDao.listByIds(affinityGroupIds, true); + } for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { processAffinityGroup(vmGroupMapping, avoid, vm); } @@ -93,8 +93,8 @@ protected void processAffinityGroup(AffinityGroupVMMapVO vmGroupMapping, Exclude if (vmGroupMapping != null) { AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); } List groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId()); @@ -105,16 +105,16 @@ protected void processAffinityGroup(AffinityGroupVMMapVO vmGroupMapping, Exclude if (groupVM != null && !groupVM.isRemoved()) { if (groupVM.getHostId() != null) { avoid.addHost(groupVM.getHostId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host"); + if (logger.isDebugEnabled()) { + logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host"); } } } else if (Arrays.asList(VirtualMachine.State.Starting, VirtualMachine.State.Stopped).contains(groupVM.getState()) && groupVM.getLastHostId() != null) { long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - groupVM.getUpdateTime().getTime()) / 1000; if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) { avoid.addHost(groupVM.getLastHostId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM " + groupVM.getId() + + if (logger.isDebugEnabled()) { + logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host, in Stopped state but has reserved capacity"); } } @@ -145,11 +145,31 @@ public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedD return true; } + for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { + // if more than 1 VM's are present in the group then check for + // conflict due to parallel deployment + List groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(vmGroupMapping.getAffinityGroupId()); + groupVMIds.remove(vm.getId()); + + for (Long groupVMId : groupVMIds) { + VMReservationVO vmReservation = _reservationDao.findByVmId(groupVMId); + if (vmReservation != null && vmReservation.getHostId() != null && vmReservation.getHostId().equals(plannedHostId)) { + if (logger.isDebugEnabled()) { + logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + + " reserved on the same host " + plannedHostId); + } + return false; + } + } + } + List affinityGroupIds = vmGroupMappings.stream().map(AffinityGroupVMMapVO::getAffinityGroupId).collect(Collectors.toList()); return Transaction.execute(new TransactionCallback() { @Override public Boolean doInTransaction(TransactionStatus status) { - _affinityGroupDao.listByIds(affinityGroupIds, true); + if (!affinityGroupIds.isEmpty()) { + _affinityGroupDao.listByIds(affinityGroupIds, true); + } for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { // if more than 1 VM's are present in the group then check for // conflict due to parallel deployment @@ -159,8 +179,8 @@ public Boolean doInTransaction(TransactionStatus status) { for (Long groupVMId : groupVMIds) { VMReservationVO vmReservation = _reservationDao.findByVmId(groupVMId); if (vmReservation != null && vmReservation.getHostId() != null && vmReservation.getHostId().equals(plannedHostId)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + + if (logger.isDebugEnabled()) { + logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + " reserved on the same host " + plannedHostId); } return false; diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/main/resources/META-INF/cloudstack/host-anti-affinity/spring-host-anti-affinity-context.xml b/plugins/affinity-group-processors/host-anti-affinity/src/main/resources/META-INF/cloudstack/host-anti-affinity/spring-host-anti-affinity-context.xml index 362bb470d382..0cfe6b380842 100644 --- a/plugins/affinity-group-processors/host-anti-affinity/src/main/resources/META-INF/cloudstack/host-anti-affinity/spring-host-anti-affinity-context.xml +++ b/plugins/affinity-group-processors/host-anti-affinity/src/main/resources/META-INF/cloudstack/host-anti-affinity/spring-host-anti-affinity-context.xml @@ -33,5 +33,5 @@ - + diff --git a/plugins/affinity-group-processors/non-strict-host-affinity/pom.xml b/plugins/affinity-group-processors/non-strict-host-affinity/pom.xml index 77a731e58a5d..bf751ca41416 100644 --- a/plugins/affinity-group-processors/non-strict-host-affinity/pom.xml +++ b/plugins/affinity-group-processors/non-strict-host-affinity/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/non-strict-host-affinity/src/main/java/org/apache/cloudstack/affinity/NonStrictHostAffinityProcessor.java b/plugins/affinity-group-processors/non-strict-host-affinity/src/main/java/org/apache/cloudstack/affinity/NonStrictHostAffinityProcessor.java index cdb3447f5a52..f227a3ffc8db 100644 --- a/plugins/affinity-group-processors/non-strict-host-affinity/src/main/java/org/apache/cloudstack/affinity/NonStrictHostAffinityProcessor.java +++ b/plugins/affinity-group-processors/non-strict-host-affinity/src/main/java/org/apache/cloudstack/affinity/NonStrictHostAffinityProcessor.java @@ -23,7 +23,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -45,7 +44,6 @@ public class NonStrictHostAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor { - private final Logger logger = Logger.getLogger(this.getClass().getName()); @Inject protected UserVmDao vmDao; @Inject diff --git a/plugins/affinity-group-processors/non-strict-host-affinity/src/main/resources/META-INF/cloudstack/non-strict-host-affinity/spring-non-strict-host-affinity-context.xml b/plugins/affinity-group-processors/non-strict-host-affinity/src/main/resources/META-INF/cloudstack/non-strict-host-affinity/spring-non-strict-host-affinity-context.xml index a80ddb1e3bb2..3d3959b7e2b8 100644 --- a/plugins/affinity-group-processors/non-strict-host-affinity/src/main/resources/META-INF/cloudstack/non-strict-host-affinity/spring-non-strict-host-affinity-context.xml +++ b/plugins/affinity-group-processors/non-strict-host-affinity/src/main/resources/META-INF/cloudstack/non-strict-host-affinity/spring-non-strict-host-affinity-context.xml @@ -33,5 +33,5 @@ - + diff --git a/plugins/affinity-group-processors/non-strict-host-anti-affinity/pom.xml b/plugins/affinity-group-processors/non-strict-host-anti-affinity/pom.xml index b08a3a2b536c..445acfc11d6a 100644 --- a/plugins/affinity-group-processors/non-strict-host-anti-affinity/pom.xml +++ b/plugins/affinity-group-processors/non-strict-host-anti-affinity/pom.xml @@ -32,7 +32,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/non-strict-host-anti-affinity/src/main/resources/META-INF/cloudstack/non-strict-host-anti-affinity/spring-non-strict-host-anti-affinity-context.xml b/plugins/affinity-group-processors/non-strict-host-anti-affinity/src/main/resources/META-INF/cloudstack/non-strict-host-anti-affinity/spring-non-strict-host-anti-affinity-context.xml index 0f42019b2692..8c8a0f4218f2 100644 --- a/plugins/affinity-group-processors/non-strict-host-anti-affinity/src/main/resources/META-INF/cloudstack/non-strict-host-anti-affinity/spring-non-strict-host-anti-affinity-context.xml +++ b/plugins/affinity-group-processors/non-strict-host-anti-affinity/src/main/resources/META-INF/cloudstack/non-strict-host-anti-affinity/spring-non-strict-host-anti-affinity-context.xml @@ -33,5 +33,5 @@ - + diff --git a/plugins/alert-handlers/snmp-alerts/pom.xml b/plugins/alert-handlers/snmp-alerts/pom.xml index 6e480d694e8a..fad47d426f2e 100644 --- a/plugins/alert-handlers/snmp-alerts/pom.xml +++ b/plugins/alert-handlers/snmp-alerts/pom.xml @@ -24,7 +24,7 @@ cloudstack-plugins org.apache.cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -33,8 +33,12 @@ org.apache.servicemix.bundles.snmp4j - ch.qos.reload4j - reload4j + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api diff --git a/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayout.java b/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayout.java index 5761e7041e76..cf9e18bf9cf7 100644 --- a/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayout.java +++ b/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayout.java @@ -17,42 +17,27 @@ package org.apache.cloudstack.alert.snmp; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.message.Message; + import java.util.Date; import java.util.StringTokenizer; -import org.apache.log4j.EnhancedPatternLayout; -import org.apache.log4j.spi.LoggingEvent; - -public class SnmpEnhancedPatternLayout extends EnhancedPatternLayout { +public class SnmpEnhancedPatternLayout { private String _pairDelimiter = "//"; private String _keyValueDelimiter = "::"; private static final int LENGTH_OF_STRING_MESSAGE_AND_KEY_VALUE_DELIMITER = 9; private static final int LENGTH_OF_STRING_MESSAGE = 8; - public String getKeyValueDelimeter() { - return _keyValueDelimiter; - } - - public void setKeyValueDelimiter(String keyValueDelimiter) { - this._keyValueDelimiter = keyValueDelimiter; - } - - public String getPairDelimiter() { - return _pairDelimiter; - } - - public void setPairDelimiter(String pairDelimiter) { - this._pairDelimiter = pairDelimiter; - } - - public SnmpTrapInfo parseEvent(LoggingEvent event) { + public SnmpTrapInfo parseEvent(LogEvent event) { SnmpTrapInfo snmpTrapInfo = null; - final String message = event.getRenderedMessage(); - if (message.contains("alertType") && message.contains("message")) { + Message message = event.getMessage(); + final String formattedMessage = message.getFormattedMessage(); + if (formattedMessage.contains("alertType") && formattedMessage.contains("message")) { snmpTrapInfo = new SnmpTrapInfo(); - final StringTokenizer messageSplitter = new StringTokenizer(message, _pairDelimiter); + final StringTokenizer messageSplitter = new StringTokenizer(formattedMessage, _pairDelimiter); while (messageSplitter.hasMoreTokens()) { final String pairToken = messageSplitter.nextToken(); final StringTokenizer pairSplitter = new StringTokenizer(pairToken, _keyValueDelimiter); @@ -80,11 +65,11 @@ public SnmpTrapInfo parseEvent(LoggingEvent event) { } else if (keyToken.equalsIgnoreCase("clusterId") && !valueToken.equalsIgnoreCase("null")) { snmpTrapInfo.setClusterId(Long.parseLong(valueToken)); } else if (keyToken.equalsIgnoreCase("message") && !valueToken.equalsIgnoreCase("null")) { - snmpTrapInfo.setMessage(getSnmpMessage(message)); + snmpTrapInfo.setMessage(getSnmpMessage(formattedMessage)); } } - snmpTrapInfo.setGenerationTime(new Date(event.getTimeStamp())); + snmpTrapInfo.setGenerationTime(new Date(event.getTimeMillis())); } return snmpTrapInfo; } diff --git a/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppender.java b/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppender.java index 5374e39916d4..d91c60db31d2 100644 --- a/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppender.java +++ b/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppender.java @@ -17,21 +17,32 @@ package org.apache.cloudstack.alert.snmp; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.spi.ErrorCode; -import org.apache.log4j.spi.LoggingEvent; - import com.cloud.utils.net.NetUtils; - -public class SnmpTrapAppender extends AppenderSkeleton { +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.Property; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.layout.PatternLayout; + +@Plugin(name = "SnmpTrapAppender", category = "Core", elementType = "appender", printObject = true) +public class SnmpTrapAppender extends AbstractAppender { + protected static Logger LOGGER = LogManager.getLogger(SnmpTrapAppender.class); private String _delimiter = ","; - private String _snmpManagerIpAddresses; - private String _snmpManagerPorts; - private String _snmpManagerCommunities; + private String snmpManagerIpAddresses; + private String snmpManagerPorts; + private String snmpManagerCommunities; private String _oldSnmpManagerIpAddresses = null; private String _oldSnmpManagerPorts = null; @@ -41,27 +52,21 @@ public class SnmpTrapAppender extends AppenderSkeleton { private List _communities = null; private List _ports = null; - List _snmpHelpers = new ArrayList(); + private SnmpEnhancedPatternLayout snmpEnhancedPatternLayout; - @Override - protected void append(LoggingEvent event) { - SnmpEnhancedPatternLayout snmpEnhancedPatternLayout; - - if (getLayout() == null) { - errorHandler.error("No layout set for the Appender named [" + getName() + ']', null, ErrorCode.MISSING_LAYOUT); - return; - } - - if (getLayout() instanceof SnmpEnhancedPatternLayout) { - snmpEnhancedPatternLayout = (SnmpEnhancedPatternLayout)getLayout(); - } else { - return; - } + List _snmpHelpers = new ArrayList<>(); - if (!isAsSevereAsThreshold(event.getLevel())) { - return; - } + protected SnmpTrapAppender(String name, Filter filter, Layout layout, final boolean ignoreExceptions, final Property[] properties, + String snmpManagerIpAddresses, String snmpManagerPorts, String snmpManagerCommunities) { + super(name, filter, layout, ignoreExceptions, properties); + this.snmpEnhancedPatternLayout = new SnmpEnhancedPatternLayout(); + this.snmpManagerIpAddresses = snmpManagerIpAddresses; + this.snmpManagerPorts = snmpManagerPorts; + this.snmpManagerCommunities = snmpManagerCommunities; + } + @Override + public void append(LogEvent event) { SnmpTrapInfo snmpTrapInfo = snmpEnhancedPatternLayout.parseEvent(event); if (snmpTrapInfo != null && !_snmpHelpers.isEmpty()) { @@ -69,41 +74,57 @@ protected void append(LoggingEvent event) { try { helper.sendSnmpTrap(snmpTrapInfo); } catch (Exception e) { - errorHandler.error(e.getMessage()); + getHandler().error(e.getMessage()); } } } } + @PluginFactory + public static SnmpTrapAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout layout, + @PluginElement("Filter") final Filter filter, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, @PluginElement("properties") final Property[] properties, + @PluginAttribute("SnmpManagerIpAddresses") String snmpManagerIpAddresses, @PluginAttribute("SnmpManagerPorts") String snmpManagerPorts, + @PluginAttribute("SnmpManagerCommunities") String snmpManagerCommunities) { + + if (name == null) { + LOGGER.error("No name provided for SnmpTrapAppender"); + return null; + } + if (layout == null) { + layout = PatternLayout.createDefaultLayout(); + } + return new SnmpTrapAppender(name, filter, layout, ignoreExceptions, properties, snmpManagerIpAddresses, snmpManagerPorts, snmpManagerCommunities); + } + void setSnmpHelpers() { - if (_snmpManagerIpAddresses == null || _snmpManagerIpAddresses.trim().isEmpty() || _snmpManagerCommunities == null || _snmpManagerCommunities.trim().isEmpty() || - _snmpManagerPorts == null || _snmpManagerPorts.trim().isEmpty()) { + if (snmpManagerIpAddresses == null || snmpManagerIpAddresses.trim().isEmpty() || snmpManagerCommunities == null || snmpManagerCommunities.trim().isEmpty() || + snmpManagerPorts == null || snmpManagerPorts.trim().isEmpty()) { reset(); return; } - if (_oldSnmpManagerIpAddresses != null && _oldSnmpManagerIpAddresses.equals(_snmpManagerIpAddresses) && - _oldSnmpManagerCommunities.equals(_snmpManagerCommunities) && _oldSnmpManagerPorts.equals(_snmpManagerPorts)) { + if (_oldSnmpManagerIpAddresses != null && _oldSnmpManagerIpAddresses.equals(snmpManagerIpAddresses) && + _oldSnmpManagerCommunities.equals(snmpManagerCommunities) && _oldSnmpManagerPorts.equals(snmpManagerPorts)) { return; } - _oldSnmpManagerIpAddresses = _snmpManagerIpAddresses; - _oldSnmpManagerPorts = _snmpManagerPorts; - _oldSnmpManagerCommunities = _snmpManagerCommunities; + _oldSnmpManagerIpAddresses = snmpManagerIpAddresses; + _oldSnmpManagerPorts = snmpManagerPorts; + _oldSnmpManagerCommunities = snmpManagerCommunities; - _ipAddresses = parse(_snmpManagerIpAddresses); - _communities = parse(_snmpManagerCommunities); - _ports = parse(_snmpManagerPorts); + _ipAddresses = parse(snmpManagerIpAddresses); + _communities = parse(snmpManagerCommunities); + _ports = parse(snmpManagerPorts); if (!(_ipAddresses.size() == _communities.size() && _ipAddresses.size() == _ports.size())) { reset(); - errorHandler.error(" size of ip addresses , communities, " + "and ports list doesn't match, " + "setting all to null"); + getHandler().error(" size of ip addresses , communities, " + "and ports list doesn't match, " + "setting all to null"); return; } if (!validateIpAddresses() || !validatePorts()) { reset(); - errorHandler.error(" Invalid format for the IP Addresses or Ports parameter "); + getHandler().error(" Invalid format for the IP Addresses or Ports parameter "); return; } @@ -114,7 +135,7 @@ void setSnmpHelpers() { try { _snmpHelpers.add(new SnmpHelper(address, _communities.get(i))); } catch (Exception e) { - errorHandler.error(e.getMessage()); + getHandler().error(e.getMessage()); } } } @@ -126,17 +147,6 @@ private void reset() { _snmpHelpers.clear(); } - @Override - public void close() { - if (!closed) - closed = true; - } - - @Override - public boolean requiresLayout() { - return true; - } - private List parse(String str) { List result = new ArrayList(); @@ -168,38 +178,20 @@ private boolean validateIpAddresses() { return true; } - public String getSnmpManagerIpAddresses() { - return _snmpManagerIpAddresses; - } - public void setSnmpManagerIpAddresses(String snmpManagerIpAddresses) { - this._snmpManagerIpAddresses = snmpManagerIpAddresses; + this.snmpManagerIpAddresses = snmpManagerIpAddresses; setSnmpHelpers(); } - public String getSnmpManagerPorts() { - return _snmpManagerPorts; - } public void setSnmpManagerPorts(String snmpManagerPorts) { - this._snmpManagerPorts = snmpManagerPorts; + this.snmpManagerPorts = snmpManagerPorts; setSnmpHelpers(); } - public String getSnmpManagerCommunities() { - return _snmpManagerCommunities; - } - public void setSnmpManagerCommunities(String snmpManagerCommunities) { - this._snmpManagerCommunities = snmpManagerCommunities; + this.snmpManagerCommunities = snmpManagerCommunities; setSnmpHelpers(); } - public String getDelimiter() { - return _delimiter; - } - - public void setDelimiter(String delimiter) { - this._delimiter = delimiter; - } } diff --git a/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayoutTest.java b/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayoutTest.java index a04d36bede8b..adfc0e27b0e9 100644 --- a/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayoutTest.java +++ b/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayoutTest.java @@ -20,56 +20,57 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.message.Message; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; -import javax.naming.ConfigurationException; - -import org.apache.log4j.spi.LoggingEvent; -import org.junit.Before; import org.junit.Test; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class SnmpEnhancedPatternLayoutTest { - SnmpEnhancedPatternLayout _snmpEnhancedPatternLayout = new SnmpEnhancedPatternLayout(); - @Before - public void setUp() throws ConfigurationException { - _snmpEnhancedPatternLayout.setKeyValueDelimiter("::"); - _snmpEnhancedPatternLayout.setPairDelimiter("//"); - } + @Mock + Message messageMock; + @Mock + LogEvent eventMock; + + @Spy + @InjectMocks + SnmpEnhancedPatternLayout _snmpEnhancedPatternLayout = new SnmpEnhancedPatternLayout(); @Test public void parseAlertTest() { - LoggingEvent event = mock(LoggingEvent.class); setMessage(" alertType:: 14 // dataCenterId:: 1 // podId:: 1 // " + "clusterId:: null // message:: Management" - + " network CIDR is not configured originally. Set it default to 10.102.192.0/22", event); - SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(event); + + " network CIDR is not configured originally. Set it default to 10.102.192.0/22", eventMock); + SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(eventMock); commonAssertions(info, "Management network CIDR is not configured originally. Set it default to 10.102.192" + ".0/22"); } @Test public void ParseAlertWithPairDelimeterInMessageTest() { - LoggingEvent event = mock(LoggingEvent.class); setMessage(" alertType:: 14 // dataCenterId:: 1 // podId:: 1 // " + "clusterId:: null // message:: Management" - + " //network CIDR is not configured originally. Set it default to 10.102.192.0/22", event); - SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(event); + + " //network CIDR is not configured originally. Set it default to 10.102.192.0/22", eventMock); + SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(eventMock); commonAssertions(info, "Management //network CIDR is not configured originally. Set it default to 10.102.192" + ".0/22"); } @Test public void ParseAlertWithKeyValueDelimeterInMessageTest() { - LoggingEvent event = mock(LoggingEvent.class); setMessage(" alertType:: 14 // dataCenterId:: 1 // podId:: 1 // " + "clusterId:: null // message:: Management" - + " ::network CIDR is not configured originally. Set it default to 10.102.192.0/22", event); - SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(event); + + " ::network CIDR is not configured originally. Set it default to 10.102.192.0/22", eventMock); + SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(eventMock); commonAssertions(info, "Management ::network CIDR is not configured originally. Set it default to 10.102.192" + ".0/22"); } @Test public void parseRandomTest() { - LoggingEvent event = mock(LoggingEvent.class); - when(event.getRenderedMessage()).thenReturn("Problem clearing email alert"); - assertNull(" Null value was expected ", _snmpEnhancedPatternLayout.parseEvent(event)); + setMessage("Problem clearing email alert", eventMock); + assertNull(" Null value was expected ", _snmpEnhancedPatternLayout.parseEvent(eventMock)); } private void commonAssertions(SnmpTrapInfo info, String message) { @@ -81,7 +82,8 @@ private void commonAssertions(SnmpTrapInfo info, String message) { assertEquals(" message is not as expected ", message, info.getMessage()); } - private void setMessage(String message, LoggingEvent event) { - when(event.getRenderedMessage()).thenReturn(message); + private void setMessage(String message, LogEvent eventMock) { + Mockito.doReturn(messageMock).when(eventMock).getMessage(); + Mockito.doReturn(message).when(messageMock).getFormattedMessage(); } } diff --git a/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppenderTest.java b/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppenderTest.java index 36fb0c9e5c24..ce207e08266a 100644 --- a/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppenderTest.java +++ b/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppenderTest.java @@ -19,20 +19,11 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import java.util.List; - -import org.apache.log4j.spi.LoggingEvent; import org.junit.Test; -import org.mockito.Mock; public class SnmpTrapAppenderTest { - SnmpTrapAppender _appender = new SnmpTrapAppender(); - LoggingEvent _event = mock(LoggingEvent.class); - SnmpEnhancedPatternLayout _snmpEnhancedPatternLayout = mock(SnmpEnhancedPatternLayout.class); - @Mock - List snmpHelpers; + SnmpTrapAppender _appender = new SnmpTrapAppender("test", null, null, false, null, null, null, null); @Test public void appendTest() { diff --git a/plugins/alert-handlers/syslog-alerts/pom.xml b/plugins/alert-handlers/syslog-alerts/pom.xml index 3d747dc65ef5..54641bd8a8a8 100644 --- a/plugins/alert-handlers/syslog-alerts/pom.xml +++ b/plugins/alert-handlers/syslog-alerts/pom.xml @@ -24,13 +24,17 @@ cloudstack-plugins org.apache.cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml - ch.qos.reload4j - reload4j + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api diff --git a/plugins/alert-handlers/syslog-alerts/src/main/java/org/apache/cloudstack/syslog/AlertsSyslogAppender.java b/plugins/alert-handlers/syslog-alerts/src/main/java/org/apache/cloudstack/syslog/AlertsSyslogAppender.java index b73da2fd4219..a6f511558dc1 100644 --- a/plugins/alert-handlers/syslog-alerts/src/main/java/org/apache/cloudstack/syslog/AlertsSyslogAppender.java +++ b/plugins/alert-handlers/syslog-alerts/src/main/java/org/apache/cloudstack/syslog/AlertsSyslogAppender.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.syslog; +import java.io.Serializable; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; @@ -26,20 +27,31 @@ import java.util.Map; import java.util.StringTokenizer; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.net.SyslogAppender; -import org.apache.log4j.spi.LoggingEvent; import com.cloud.utils.net.NetUtils; - -public class AlertsSyslogAppender extends AppenderSkeleton { - String _syslogHosts = null; - String _delimiter = ","; - List _syslogHostsList = null; - List _syslogAppenders = null; - private String _facility; - private String _pairDelimiter = "//"; - private String _keyValueDelimiter = "::"; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.appender.SyslogAppender; +import org.apache.logging.log4j.core.config.Property; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.impl.Log4jLogEvent; +import org.apache.logging.log4j.core.net.Facility; +import org.apache.logging.log4j.message.SimpleMessage; + +@Plugin(name = "AlertSyslogAppender", category = "Core", elementType = "appender", printObject = true) +public class AlertsSyslogAppender extends AbstractAppender { + String syslogHosts; + String delimiter = ","; + List syslogHostsList = null; + List syslogAppenders = null; + private String facility; + private String pairDelimiter = "//"; + private String keyValueDelimiter = "::"; private int alertType = -1; private long dataCenterId = 0; private long podId = 0; @@ -53,7 +65,7 @@ public class AlertsSyslogAppender extends AppenderSkeleton { private static final Map alertsMap; static { - Map aMap = new HashMap(27); + Map aMap = new HashMap<>(27); aMap.put(0, "availableMemory"); aMap.put(1, "availableCpu"); aMap.put(2, "availableStorage"); @@ -86,70 +98,68 @@ public class AlertsSyslogAppender extends AppenderSkeleton { alertsMap = Collections.unmodifiableMap(aMap); } - @Override - protected void append(LoggingEvent event) { - if (!isAsSevereAsThreshold(event.getLevel())) { - return; - } + protected AlertsSyslogAppender(String name, Filter filter, Layout layout, final boolean ignoreExceptions, final Property[] properties, String facility, + String syslogHosts){ + super(name, filter, layout, ignoreExceptions, properties); + this.facility = facility; + this.syslogHosts = syslogHosts; + } - if (_syslogAppenders != null && !_syslogAppenders.isEmpty()) { + @Override + public void append(LogEvent event) { + if (syslogAppenders != null && !syslogAppenders.isEmpty()) { try { - String logMessage = event.getRenderedMessage(); + String logMessage = event.getMessage().getFormattedMessage(); if (logMessage.contains("alertType") && logMessage.contains("message")) { parseMessage(logMessage); String syslogMessage = createSyslogMessage(); - LoggingEvent syslogEvent = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getLevel(), syslogMessage, null); + LogEvent syslogEvent = new Log4jLogEvent(event.getLoggerName(), event.getMarker(), event.getLoggerFqcn(), event.getLevel(), new SimpleMessage(syslogMessage), event.getThrown()); - for (SyslogAppender syslogAppender : _syslogAppenders) { + for (SyslogAppender syslogAppender : syslogAppenders) { syslogAppender.append(syslogEvent); } } } catch (Exception e) { - errorHandler.error(e.getMessage()); + getHandler().error(e.getMessage()); } } } - @Override - synchronized public void close() { - for (SyslogAppender syslogAppender : _syslogAppenders) { - syslogAppender.close(); - } - } - - @Override - public boolean requiresLayout() { - return true; + @PluginFactory + public static AlertsSyslogAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout layout, + @PluginElement("Filter") final Filter filter, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, @PluginElement("properties") final Property[] properties, + @PluginAttribute("facility") String facility, @PluginAttribute("syslogHosts") String syslogHosts) { + return new AlertsSyslogAppender(name, filter, layout, ignoreExceptions, properties, facility, syslogHosts); } void setSyslogAppenders() { - if (_syslogAppenders == null) { - _syslogAppenders = new ArrayList(); + if (syslogAppenders == null) { + syslogAppenders = new ArrayList(); } - if (_syslogHosts == null || _syslogHosts.trim().isEmpty()) { + if (syslogHosts == null || syslogHosts.trim().isEmpty()) { reset(); return; } - _syslogHostsList = parseSyslogHosts(_syslogHosts); + syslogHostsList = parseSyslogHosts(syslogHosts); if (!validateIpAddresses()) { reset(); - errorHandler.error(" Invalid format for the IP Addresses parameter "); + getHandler().error(" Invalid format for the IP Addresses parameter "); return; } - for (String syslogHost : _syslogHostsList) { - _syslogAppenders.add(new SyslogAppender(getLayout(), syslogHost, SyslogAppender.getFacility(_facility))); + for (String syslogHost : syslogHostsList) { + syslogAppenders.add(SyslogAppender.newSyslogAppenderBuilder().setFacility(Facility.toFacility(facility)).setHost(syslogHost).setLayout(getLayout()).build()); } } private List parseSyslogHosts(String syslogHosts) { List result = new ArrayList(); - final StringTokenizer tokenizer = new StringTokenizer(syslogHosts, _delimiter); + final StringTokenizer tokenizer = new StringTokenizer(syslogHosts, delimiter); while (tokenizer.hasMoreTokens()) { result.add(tokenizer.nextToken().trim()); } @@ -157,7 +167,7 @@ private List parseSyslogHosts(String syslogHosts) { } private boolean validateIpAddresses() { - for (String ipAddress : _syslogHostsList) { + for (String ipAddress : syslogHostsList) { String[] hostTokens = (ipAddress.trim()).split(":"); String ip = hostTokens[0]; @@ -181,10 +191,10 @@ private boolean validateIpAddresses() { } void parseMessage(String logMessage) { - final StringTokenizer messageSplitter = new StringTokenizer(logMessage, _pairDelimiter); + final StringTokenizer messageSplitter = new StringTokenizer(logMessage, pairDelimiter); while (messageSplitter.hasMoreTokens()) { final String pairToken = messageSplitter.nextToken(); - final StringTokenizer pairSplitter = new StringTokenizer(pairToken, _keyValueDelimiter); + final StringTokenizer pairSplitter = new StringTokenizer(pairToken, keyValueDelimiter); String keyToken; String valueToken; @@ -231,60 +241,47 @@ String createSyslogMessage() { } if (alertType >= 0) { - message.append("alertType").append(_keyValueDelimiter).append(" ").append(alertsMap.containsKey(alertType) ? alertsMap.get(alertType) : "unknown") + message.append("alertType").append(keyValueDelimiter).append(" ").append(alertsMap.containsKey(alertType) ? alertsMap.get(alertType) : "unknown") .append(MESSAGE_DELIMITER_STRING); if (dataCenterId != 0) { - message.append("dataCenterId").append(_keyValueDelimiter).append(" ").append(dataCenterId).append(MESSAGE_DELIMITER_STRING); + message.append("dataCenterId").append(keyValueDelimiter).append(" ").append(dataCenterId).append(MESSAGE_DELIMITER_STRING); } if (podId != 0) { - message.append("podId").append(_keyValueDelimiter).append(" ").append(podId).append(MESSAGE_DELIMITER_STRING); + message.append("podId").append(keyValueDelimiter).append(" ").append(podId).append(MESSAGE_DELIMITER_STRING); } if (clusterId != 0) { - message.append("clusterId").append(_keyValueDelimiter).append(" ").append(clusterId).append(MESSAGE_DELIMITER_STRING); + message.append("clusterId").append(keyValueDelimiter).append(" ").append(clusterId).append(MESSAGE_DELIMITER_STRING); } if (sysMessage != null) { - message.append("message").append(_keyValueDelimiter).append(" ").append(sysMessage); + message.append("message").append(keyValueDelimiter).append(" ").append(sysMessage); } else { - errorHandler.error("What is the use of alert without message "); + getHandler().error("What is the use of alert without message "); } } else { - errorHandler.error("Invalid alert Type "); + getHandler().error("Invalid alert Type "); } return message.toString(); } private String getSyslogMessage(String message) { - int lastIndexOfKeyValueDelimiter = message.lastIndexOf(_keyValueDelimiter); + int lastIndexOfKeyValueDelimiter = message.lastIndexOf(keyValueDelimiter); int lastIndexOfMessageInString = message.lastIndexOf("message"); if (lastIndexOfKeyValueDelimiter - lastIndexOfMessageInString <= LENGTH_OF_STRING_MESSAGE_AND_KEY_VALUE_DELIMITER) { - return message.substring(lastIndexOfKeyValueDelimiter + _keyValueDelimiter.length()).trim(); + return message.substring(lastIndexOfKeyValueDelimiter + keyValueDelimiter.length()).trim(); } else if (lastIndexOfMessageInString < lastIndexOfKeyValueDelimiter) { - return message.substring(lastIndexOfMessageInString + _keyValueDelimiter.length() + LENGTH_OF_STRING_MESSAGE).trim(); + return message.substring(lastIndexOfMessageInString + keyValueDelimiter.length() + LENGTH_OF_STRING_MESSAGE).trim(); } - return message.substring(message.lastIndexOf("message" + _keyValueDelimiter) + LENGTH_OF_STRING_MESSAGE_AND_KEY_VALUE_DELIMITER).trim(); + return message.substring(message.lastIndexOf("message" + keyValueDelimiter) + LENGTH_OF_STRING_MESSAGE_AND_KEY_VALUE_DELIMITER).trim(); } private void reset() { - _syslogAppenders.clear(); - } - - public void setFacility(String facility) { - if (facility == null) { - return; - } - - _facility = facility; - if (_syslogAppenders != null && !_syslogAppenders.isEmpty()) { - for (SyslogAppender syslogAppender : _syslogAppenders) { - syslogAppender.setFacility(facility); - } - } + syslogAppenders.clear(); } private String severityOfAlert(int alertType) { @@ -304,40 +301,9 @@ private boolean isCritical(int alertType) { return false; } - public String getFacility() { - return _facility; - } - - public String getSyslogHosts() { - return _syslogHosts; - } - public void setSyslogHosts(String syslogHosts) { - _syslogHosts = syslogHosts; + this.syslogHosts = syslogHosts; setSyslogAppenders(); } - public String getDelimiter() { - return _delimiter; - } - - public void setDelimiter(String delimiter) { - _delimiter = delimiter; - } - - public String getPairDelimiter() { - return _pairDelimiter; - } - - public void setPairDelimiter(String pairDelimiter) { - _pairDelimiter = pairDelimiter; - } - - public String getKeyValueDelimiter() { - return _keyValueDelimiter; - } - - public void setKeyValueDelimiter(String keyValueDelimiter) { - _keyValueDelimiter = keyValueDelimiter; - } } diff --git a/plugins/alert-handlers/syslog-alerts/src/test/java/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java b/plugins/alert-handlers/syslog-alerts/src/test/java/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java index fe071a6c3277..b76a259409c5 100644 --- a/plugins/alert-handlers/syslog-alerts/src/test/java/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java +++ b/plugins/alert-handlers/syslog-alerts/src/test/java/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java @@ -17,41 +17,32 @@ package org.apache.cloudstack.syslog; +import org.apache.logging.log4j.core.config.Property; +import org.apache.logging.log4j.core.layout.PatternLayout; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import javax.naming.ConfigurationException; - -import org.apache.log4j.PatternLayout; -import org.junit.Before; import org.junit.Test; public class AlertsSyslogAppenderTest { - AlertsSyslogAppender _appender = new AlertsSyslogAppender(); - - @Before - public void setUp() throws ConfigurationException { - _appender.setLayout(new PatternLayout("%-5p [%c{3}] (%t:%x) %m%n")); - _appender.setFacility("LOCAL6"); - } - + AlertsSyslogAppender _appender = new AlertsSyslogAppender("test", null, PatternLayout.createDefaultLayout(), true, Property.EMPTY_ARRAY, "LOCAL6", null); @Test public void setSyslogAppendersTest() { _appender.setSyslogHosts("10.1.1.1,10.1.1.2"); - assertEquals(" error Syslog Appenders list size not as expected ", 2, _appender._syslogAppenders.size()); + assertEquals(" error Syslog Appenders list size not as expected ", 2, _appender.syslogAppenders.size()); } @Test public void setSyslogAppendersWithPortTest() { _appender.setSyslogHosts("10.1.1.1:897,10.1.1.2"); - assertEquals(" error Syslog Appenders list size not as expected ", 2, _appender._syslogAppenders.size()); + assertEquals(" error Syslog Appenders list size not as expected ", 2, _appender.syslogAppenders.size()); } @Test public void setSyslogAppendersNegativeTest() { //setting invalid IP for Syslog Hosts _appender.setSyslogHosts("10.1.1."); - assertTrue(" list was expected to be empty", _appender._syslogAppenders.isEmpty()); + assertTrue(" list was expected to be empty", _appender.syslogAppenders.isEmpty()); } @Test diff --git a/plugins/api/discovery/pom.xml b/plugins/api/discovery/pom.xml index 5771dae8110c..6426dcd70a51 100644 --- a/plugins/api/discovery/pom.xml +++ b/plugins/api/discovery/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/api/discovery/src/main/java/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java b/plugins/api/discovery/src/main/java/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java index 8cf643edb04b..aa78a725a34f 100644 --- a/plugins/api/discovery/src/main/java/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java +++ b/plugins/api/discovery/src/main/java/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListApisCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListApisCmd.class.getName()); @Inject ApiDiscoveryService _apiDiscoveryService; diff --git a/plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java b/plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java index eedf1878ec85..452b95cf2c05 100644 --- a/plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java +++ b/plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java @@ -47,7 +47,6 @@ import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.reflections.ReflectionUtils; import org.springframework.stereotype.Component; @@ -63,7 +62,6 @@ @Component public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements ApiDiscoveryService { - private static final Logger s_logger = Logger.getLogger(ApiDiscoveryServiceImpl.class); List _apiAccessCheckers = null; List _services = null; @@ -86,13 +84,13 @@ public boolean start() { s_apiNameDiscoveryResponseMap = new HashMap(); Set> cmdClasses = new LinkedHashSet>(); for (PluggableService service : _services) { - s_logger.debug(String.format("getting api commands of service: %s", service.getClass().getName())); + logger.debug(String.format("getting api commands of service: %s", service.getClass().getName())); cmdClasses.addAll(service.getCommands()); } cmdClasses.addAll(this.getCommands()); cacheResponseMap(cmdClasses); long endTime = System.nanoTime(); - s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms"); + logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms"); } return true; @@ -111,8 +109,8 @@ protected Map> cacheResponseMap(Set> cmdClasses) { } String apiName = apiCmdAnnotation.name(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Found api: " + apiName); + if (logger.isTraceEnabled()) { + logger.trace("Found api: " + apiName); } ApiDiscoveryResponse response = getCmdRequestMap(cmdClass, apiCmdAnnotation); @@ -265,7 +263,7 @@ public ListResponse listApis(User user, String name) { try { apiChecker.checkAccess(user, name); } catch (Exception ex) { - s_logger.error(String.format("API discovery access check failed for [%s] with error [%s].", name, ex.getMessage()), ex); + logger.error(String.format("API discovery access check failed for [%s] with error [%s].", name, ex.getMessage()), ex); return null; } } @@ -283,7 +281,7 @@ public ListResponse listApis(User user, String name) { } if (role.getRoleType() == RoleType.Admin && role.getId() == RoleType.Admin.getId()) { - s_logger.info(String.format("Account [%s] is Root Admin, all APIs are allowed.", + logger.info(String.format("Account [%s] is Root Admin, all APIs are allowed.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(account, "accountName", "uuid"))); } else { for (APIChecker apiChecker : _apiAccessCheckers) { diff --git a/plugins/api/rate-limit/pom.xml b/plugins/api/rate-limit/pom.xml index b93cfb8ba995..2449a23f2d04 100644 --- a/plugins/api/rate-limit/pom.xml +++ b/plugins/api/rate-limit/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -34,7 +34,7 @@ maven-surefire-plugin always - @{argLine} -Xmx2048m -XX:MaxPermSize=1024m + @{argLine} -Xmx2048m -XX:MaxMetaspaceSize=1024m org/apache/cloudstack/ratelimit/integration/* diff --git a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java index 5be0dfcb678c..8f5624f5b951 100644 --- a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java +++ b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ACL; import org.apache.cloudstack.api.APICommand; @@ -39,7 +38,6 @@ @APICommand(name = "resetApiLimit", responseObject = SuccessResponse.class, description = "Reset api count", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ResetApiLimitCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(ResetApiLimitCmd.class.getName()); @Inject diff --git a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java index 027d9bef459c..eafe2782d33f 100644 --- a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java +++ b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -35,7 +34,6 @@ @APICommand(name = "getApiLimit", responseObject = ApiLimitResponse.class, description = "Get API limit count for the caller", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetApiLimitCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(GetApiLimitCmd.class.getName()); @Inject diff --git a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java index 3192727fbeb4..917cd7bb2b46 100644 --- a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java +++ b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.acl.Role; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.acl.APIChecker; @@ -47,7 +46,6 @@ @Component public class ApiRateLimitServiceImpl extends AdapterBase implements APIChecker, ApiRateLimitService { - private static final Logger s_logger = Logger.getLogger(ApiRateLimitServiceImpl.class); /** * True if api rate limiting is enabled @@ -100,7 +98,7 @@ public boolean configure(String name, Map params) throws Configu CacheManager cm = CacheManager.create(); Cache cache = new Cache("api-limit-cache", maxElements, false, false, timeToLive, timeToLive); cm.addCache(cache); - s_logger.info("Limit Cache created with timeToLive=" + timeToLive + ", maxAllowed=" + maxAllowed + ", maxElements=" + maxElements); + logger.info("Limit Cache created with timeToLive=" + timeToLive + ", maxAllowed=" + maxAllowed + ", maxElements=" + maxElements); cacheStore.setCache(cache); _store = cacheStore; @@ -158,7 +156,7 @@ public List getApisAllowedToUser(Role role, User user, List apiN public void throwExceptionDueToApiRateLimitReached(Long accountId) throws RequestLimitException { long expireAfter = _store.get(accountId).getExpireDuration(); String msg = String.format("The given user has reached his/her account api limit, please retry after [%s] ms.", expireAfter); - s_logger.warn(msg); + logger.warn(msg); throw new RequestLimitException(msg); } @@ -176,7 +174,7 @@ public boolean checkAccess(User user, String apiCommandName) throws PermissionDe public boolean checkAccess(Account account, String commandName) { Long accountId = account.getAccountId(); if (_accountService.isRootAdmin(accountId)) { - s_logger.info(String.format("Account [%s] is Root Admin, in this case, API limit does not apply.", + logger.info(String.format("Account [%s] is Root Admin, in this case, API limit does not apply.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(account, "accountName", "uuid"))); return true; } @@ -203,7 +201,7 @@ public boolean hasApiRateLimitBeenExceeded(Long accountId) { int current = entry.incrementAndGet(); if (current <= maxAllowed) { - s_logger.trace(String.format("Account %s has current count [%s].", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(account, "uuid", "accountName"), current)); + logger.trace(String.format("Account %s has current count [%s].", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(account, "uuid", "accountName"), current)); return false; } return true; @@ -212,7 +210,7 @@ public boolean hasApiRateLimitBeenExceeded(Long accountId) { @Override public boolean isEnabled() { if (!enabled) { - s_logger.debug("API rate limiting is disabled. We will not use ApiRateLimitService."); + logger.debug("API rate limiting is disabled. We will not use ApiRateLimitService."); } return enabled; } diff --git a/plugins/api/rate-limit/src/main/resources/META-INF/cloudstack/rate-limit/spring-rate-limit-context.xml b/plugins/api/rate-limit/src/main/resources/META-INF/cloudstack/rate-limit/spring-rate-limit-context.xml index d25c57cb0c5b..c8308092288b 100644 --- a/plugins/api/rate-limit/src/main/resources/META-INF/cloudstack/rate-limit/spring-rate-limit-context.xml +++ b/plugins/api/rate-limit/src/main/resources/META-INF/cloudstack/rate-limit/spring-rate-limit-context.xml @@ -28,5 +28,5 @@ > - + diff --git a/plugins/api/solidfire-intg-test/pom.xml b/plugins/api/solidfire-intg-test/pom.xml index d6f72d2d7ad6..907c5f2968d1 100644 --- a/plugins/api/solidfire-intg-test/pom.xml +++ b/plugins/api/solidfire-intg-test/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetPathForVolumeCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetPathForVolumeCmd.java index ff3c307a87bf..5ff7f82a7b0e 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetPathForVolumeCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetPathForVolumeCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -29,7 +28,6 @@ @APICommand(name = "getPathForVolume", responseObject = ApiPathForVolumeResponse.class, description = "Get the path associated with the provided volume UUID", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetPathForVolumeCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetPathForVolumeCmd.class.getName()); @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.STRING, description = "CloudStack Volume UUID", required = true) private String _volumeUuid; @@ -47,7 +45,7 @@ public long getEntityOwnerId() { @Override public void execute() { - LOGGER.info("'GetPathForVolumeIdCmd.execute' method invoked"); + logger.info("'GetPathForVolumeIdCmd.execute' method invoked"); String pathForVolume = _util.getPathForVolumeUuid(_volumeUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireAccountIdCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireAccountIdCmd.java index af6400ce1c5f..baedb0389d55 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireAccountIdCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireAccountIdCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; @@ -31,7 +30,6 @@ @APICommand(name = "getSolidFireAccountId", responseObject = ApiSolidFireAccountIdResponse.class, description = "Get SolidFire Account ID", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetSolidFireAccountIdCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetSolidFireAccountIdCmd.class.getName()); @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.STRING, description = "CloudStack Account UUID", required = true) private String csAccountUuid; @@ -52,7 +50,7 @@ public long getEntityOwnerId() { @Override public void execute() { - LOGGER.info("'GetSolidFireAccountIdCmd.execute' method invoked"); + logger.info("'GetSolidFireAccountIdCmd.execute' method invoked"); long sfAccountId = manager.getSolidFireAccountId(csAccountUuid, storagePoolUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeAccessGroupIdsCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeAccessGroupIdsCmd.java index 31330f066e55..c250c870f8d7 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeAccessGroupIdsCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeAccessGroupIdsCmd.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; @@ -34,7 +33,6 @@ @APICommand(name = "getSolidFireVolumeAccessGroupIds", responseObject = ApiSolidFireVolumeAccessGroupIdsResponse.class, description = "Get the SF Volume Access Group IDs", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetSolidFireVolumeAccessGroupIdsCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetSolidFireVolumeAccessGroupIdsCmd.class.getName()); @Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.STRING, description = "Cluster UUID", required = true) private String clusterUuid; @@ -61,7 +59,7 @@ public long getEntityOwnerId() { @Override public void execute() { - LOGGER.info("'GetSolidFireVolumeAccessGroupIdsCmd.execute' method invoked"); + logger.info("'GetSolidFireVolumeAccessGroupIdsCmd.execute' method invoked"); long[] sfVagIds = manager.getSolidFireVolumeAccessGroupIds(clusterUuid, storagePoolUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeSizeCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeSizeCmd.java index 9179ec26a8b3..10af3be25b06 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeSizeCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeSizeCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; @@ -31,7 +30,6 @@ @APICommand(name = "getSolidFireVolumeSize", responseObject = ApiSolidFireVolumeSizeResponse.class, description = "Get the SF volume size including Hypervisor Snapshot Reserve", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetSolidFireVolumeSizeCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetSolidFireVolumeSizeCmd.class.getName()); @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.STRING, description = "Volume UUID", required = true) private String volumeUuid; @@ -50,7 +48,7 @@ public long getEntityOwnerId() { @Override public void execute() { - LOGGER.info("'GetSolidFireVolumeSizeCmd.execute' method invoked"); + logger.info("'GetSolidFireVolumeSizeCmd.execute' method invoked"); long sfVolumeSize = manager.getSolidFireVolumeSize(volumeUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeSnapshotDetailsCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeSnapshotDetailsCmd.java index 91fe6bba1cb0..bbb86bec31ed 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeSnapshotDetailsCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeSnapshotDetailsCmd.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -34,7 +33,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetVolumeSnapshotDetailsCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetVolumeSnapshotDetailsCmd.class.getName()); @Parameter(name = ApiConstants.SNAPSHOT_ID, type = CommandType.STRING, description = "CloudStack Snapshot UUID", required = true) private String snapshotUuid; @@ -52,7 +50,7 @@ public long getEntityOwnerId() { @Override public void execute() { - LOGGER.info("'" + GetVolumeSnapshotDetailsCmd.class.getSimpleName() + ".execute' method invoked"); + logger.info("'" + GetVolumeSnapshotDetailsCmd.class.getSimpleName() + ".execute' method invoked"); List responses = util.getSnapshotDetails(snapshotUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeiScsiNameCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeiScsiNameCmd.java index 41ed1069418d..e2063ce9d69a 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeiScsiNameCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeiScsiNameCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -30,7 +29,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetVolumeiScsiNameCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetVolumeiScsiNameCmd.class.getName()); @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.STRING, description = "CloudStack Volume UUID", required = true) private String volumeUuid; @@ -48,7 +46,7 @@ public long getEntityOwnerId() { @Override public void execute() { - LOGGER.info("'GetVolumeiScsiNameCmd.execute' method invoked"); + logger.info("'GetVolumeiScsiNameCmd.execute' method invoked"); String volume_iScsiName = _util.getVolume_iScsiName(volumeUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/solidfire/ApiSolidFireIntegrationTestServiceImpl.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/solidfire/ApiSolidFireIntegrationTestServiceImpl.java index 4adcbbe89d8d..91868f4ef8f0 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/solidfire/ApiSolidFireIntegrationTestServiceImpl.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/solidfire/ApiSolidFireIntegrationTestServiceImpl.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import org.apache.cloudstack.api.command.admin.solidfire.GetPathForVolumeCmd; -// import org.apache.log4j.Logger; import org.apache.cloudstack.api.command.admin.solidfire.GetSolidFireAccountIdCmd; import org.apache.cloudstack.api.command.admin.solidfire.GetSolidFireVolumeAccessGroupIdsCmd; import org.apache.cloudstack.api.command.admin.solidfire.GetVolumeSnapshotDetailsCmd; diff --git a/plugins/api/vmware-sioc/pom.xml b/plugins/api/vmware-sioc/pom.xml index 2c62947149ff..b3c04e603cbe 100644 --- a/plugins/api/vmware-sioc/pom.xml +++ b/plugins/api/vmware-sioc/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/api/command/admin/sioc/UpdateSiocInfoCmd.java b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/api/command/admin/sioc/UpdateSiocInfoCmd.java index 84504d13e4c9..b9dd659905b0 100644 --- a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/api/command/admin/sioc/UpdateSiocInfoCmd.java +++ b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/api/command/admin/sioc/UpdateSiocInfoCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ since = "4.11.0", authorized = {RoleType.Admin}) public class UpdateSiocInfoCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(UpdateSiocInfoCmd.class.getName()); ///////////////////////////////////////////////////// @@ -78,7 +76,7 @@ public long getEntityOwnerId() { @Override public void execute() { - s_logger.info("'UpdateSiocInfoCmd.execute' method invoked"); + logger.info("'UpdateSiocInfoCmd.execute' method invoked"); String msg = "Success"; diff --git a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/sioc/SiocManagerImpl.java b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/sioc/SiocManagerImpl.java index f012dbfa9725..c87ff3dfc827 100644 --- a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/sioc/SiocManagerImpl.java +++ b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/sioc/SiocManagerImpl.java @@ -30,7 +30,8 @@ import org.apache.cloudstack.util.LoginInfo; import org.apache.cloudstack.util.vmware.VMwareUtil; import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenterVO; @@ -63,7 +64,7 @@ @Component public class SiocManagerImpl implements SiocManager { - private static final Logger LOGGER = Logger.getLogger(SiocManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int LOCK_TIME_IN_SECONDS = 3; private static final int ONE_GB_IN_BYTES = 1000000000; private static final int LOWEST_SHARES_PER_VIRTUAL_DISK = 2000; // We want this to be greater than 1,000, which is the VMware default value. @@ -82,7 +83,7 @@ public class SiocManagerImpl implements SiocManager { @Override public void updateSiocInfo(long zoneId, long storagePoolId, int sharesPerGB, int limitIopsPerGB, int iopsNotifyThreshold) throws Exception { - LOGGER.info("'SiocManagerImpl.updateSiocInfo(long, long, int, int, int)' method invoked"); + logger.info("'SiocManagerImpl.updateSiocInfo(long, long, int, int, int)' method invoked"); DataCenterVO zone = zoneDao.findById(zoneId); @@ -250,7 +251,7 @@ private ResultWrapper updateSiocInfo(VMwareUtil.VMwareConnection connection, Map tasks.add(task); - LOGGER.info(getInfoMsg(volumeVO, newShares, newLimitIops)); + logger.info(getInfoMsg(volumeVO, newShares, newLimitIops)); } catch (Exception ex) { throw new Exception("Error: " + ex.getMessage()); } @@ -321,7 +322,7 @@ private ResultWrapper updateSiocInfoForWorkerVM(VMwareUtil.VMwareConnection conn tasks.add(task); - LOGGER.info(getInfoMsgForWorkerVm(newLimitIops)); + logger.info(getInfoMsgForWorkerVm(newLimitIops)); } catch (Exception ex) { throw new Exception("Error: " + ex.getMessage()); } diff --git a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/util/vmware/VMwareUtil.java b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/util/vmware/VMwareUtil.java index 209945fa4714..ae93c3431fc9 100644 --- a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/util/vmware/VMwareUtil.java +++ b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/util/vmware/VMwareUtil.java @@ -35,7 +35,8 @@ import javax.xml.ws.WebServiceException; import org.apache.cloudstack.util.LoginInfo; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder; import com.vmware.vim25.DynamicProperty; @@ -71,7 +72,7 @@ import com.vmware.vim25.VirtualSCSIController; public class VMwareUtil { - private static final Logger s_logger = Logger.getLogger(VMwareUtil.class); + protected static Logger LOGGER = LogManager.getLogger(VMwareUtil.class); private VMwareUtil() {} @@ -315,7 +316,7 @@ public static boolean waitForTask(VMwareConnection connection, ManagedObjectRefe throw new Exception(((LocalizedMethodFault)result[1]).getLocalizedMessage()); } } catch (WebServiceException we) { - s_logger.debug("Cancelling vCenter task because the task failed with the following error: " + we.getLocalizedMessage()); + LOGGER.debug("Cancelling vCenter task because the task failed with the following error: " + we.getLocalizedMessage()); connection.getVimPortType().cancelTask(task); diff --git a/plugins/backup/dummy/pom.xml b/plugins/backup/dummy/pom.xml index 4695a4fba0d0..52fbd085eb2b 100644 --- a/plugins/backup/dummy/pom.xml +++ b/plugins/backup/dummy/pom.xml @@ -23,7 +23,7 @@ cloudstack-plugins org.apache.cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java b/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java index fabc9821fd3e..f162c51a703d 100644 --- a/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java +++ b/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java @@ -24,8 +24,8 @@ import javax.inject.Inject; +import com.cloud.storage.dao.VolumeDao; import org.apache.cloudstack.backup.dao.BackupDao; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; @@ -35,10 +35,11 @@ public class DummyBackupProvider extends AdapterBase implements BackupProvider { - private static final Logger s_logger = Logger.getLogger(DummyBackupProvider.class); @Inject private BackupDao backupDao; + @Inject + private VolumeDao volumeDao; @Override public String getName() { @@ -52,7 +53,7 @@ public String getDescription() { @Override public List listBackupOfferings(Long zoneId) { - s_logger.debug("Listing backup policies on Dummy B&R Plugin"); + logger.debug("Listing backup policies on Dummy B&R Plugin"); BackupOffering policy1 = new BackupOfferingVO(1, "gold-policy", "dummy", "Golden Policy", "Gold description", true); BackupOffering policy2 = new BackupOfferingVO(1, "silver-policy", "dummy", "Silver Policy", "Silver description", true); return Arrays.asList(policy1, policy2); @@ -60,26 +61,26 @@ public List listBackupOfferings(Long zoneId) { @Override public boolean isValidProviderOffering(Long zoneId, String uuid) { - s_logger.debug("Checking if backup offering exists on the Dummy Backup Provider"); + logger.debug("Checking if backup offering exists on the Dummy Backup Provider"); return true; } @Override public boolean assignVMToBackupOffering(VirtualMachine vm, BackupOffering backupOffering) { - s_logger.debug("Creating VM backup for VM " + vm.getInstanceName() + " from backup offering " + backupOffering.getName()); + logger.debug("Creating VM backup for VM " + vm.getInstanceName() + " from backup offering " + backupOffering.getName()); ((VMInstanceVO) vm).setBackupExternalId("dummy-external-backup-id"); return true; } @Override public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) { - s_logger.debug("Restoring vm " + vm.getUuid() + "from backup " + backup.getUuid() + " on the Dummy Backup Provider"); + logger.debug("Restoring vm " + vm.getUuid() + "from backup " + backup.getUuid() + " on the Dummy Backup Provider"); return true; } @Override - public Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid) { - s_logger.debug("Restoring volume " + volumeUuid + "from backup " + backup.getUuid() + " on the Dummy Backup Provider"); + public Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid, Pair vmNameAndState) { + logger.debug("Restoring volume " + volumeUuid + "from backup " + backup.getUuid() + " on the Dummy Backup Provider"); throw new CloudRuntimeException("Dummy plugin does not support this feature"); } @@ -100,7 +101,7 @@ public Map getBackupMetrics(Long zoneId, List + + 4.0.0 + cloud-plugin-backup-nas + Apache CloudStack Plugin - KVM NAS Backup and Recovery Plugin + + cloudstack-plugins + org.apache.cloudstack + 4.20.0.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-plugin-hypervisor-kvm + ${project.version} + + + org.apache.commons + commons-lang3 + ${cs.commons-lang3.version} + + + com.fasterxml.jackson.core + jackson-databind + ${cs.jackson.version} + + + com.github.tomakehurst + wiremock-standalone + ${cs.wiremock.version} + test + + + diff --git a/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java b/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java new file mode 100644 index 000000000000..4a6725abdca5 --- /dev/null +++ b/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java @@ -0,0 +1,442 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.backup; + +import com.cloud.agent.AgentManager; +import com.cloud.dc.dao.ClusterDao; +import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.Status; +import com.cloud.host.dao.HostDao; +import com.cloud.hypervisor.Hypervisor; +import com.cloud.storage.ScopeType; +import com.cloud.storage.StoragePoolHostVO; +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.StoragePoolHostDao; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.utils.Pair; +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.dao.VMInstanceDao; +import org.apache.cloudstack.backup.dao.BackupDao; +import org.apache.cloudstack.backup.dao.BackupOfferingDao; +import org.apache.cloudstack.backup.dao.BackupRepositoryDao; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.apache.commons.collections.CollectionUtils; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import javax.inject.Inject; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.HashMap; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + +public class NASBackupProvider extends AdapterBase implements BackupProvider, Configurable { + private static final Logger LOG = LogManager.getLogger(NASBackupProvider.class); + + @Inject + private BackupDao backupDao; + + @Inject + private BackupRepositoryDao backupRepositoryDao; + + @Inject + private BackupOfferingDao backupOfferingDao; + + @Inject + private HostDao hostDao; + + @Inject + private ClusterDao clusterDao; + + @Inject + private VolumeDao volumeDao; + + @Inject + private StoragePoolHostDao storagePoolHostDao; + + @Inject + private VMInstanceDao vmInstanceDao; + + @Inject + private PrimaryDataStoreDao primaryDataStoreDao; + + @Inject + private AgentManager agentManager; + + protected Host getLastVMHypervisorHost(VirtualMachine vm) { + Long hostId = vm.getLastHostId(); + if (hostId == null) { + LOG.debug("Cannot find last host for vm. This should never happen, please check your database."); + return null; + } + Host host = hostDao.findById(hostId); + + if (host.getStatus() == Status.Up) { + return host; + } else { + // Try to find any Up host in the same cluster + for (final Host hostInCluster : hostDao.findHypervisorHostInCluster(host.getClusterId())) { + if (hostInCluster.getStatus() == Status.Up) { + LOG.debug("Found Host " + hostInCluster.getName()); + return hostInCluster; + } + } + } + // Try to find any Host in the zone + for (final HostVO hostInZone : hostDao.listByDataCenterIdAndHypervisorType(host.getDataCenterId(), Hypervisor.HypervisorType.KVM)) { + if (hostInZone.getStatus() == Status.Up) { + LOG.debug("Found Host " + hostInZone.getName()); + return hostInZone; + } + } + return null; + } + + protected Host getVMHypervisorHost(VirtualMachine vm) { + Long hostId = vm.getHostId(); + if (hostId == null && VirtualMachine.State.Running.equals(vm.getState())) { + throw new CloudRuntimeException(String.format("Unable to find the hypervisor host for %s. Make sure the virtual machine is running", vm.getName())); + } + if (VirtualMachine.State.Stopped.equals(vm.getState())) { + hostId = vm.getLastHostId(); + } + if (hostId == null) { + throw new CloudRuntimeException(String.format("Unable to find the hypervisor host for stopped VM: %s", vm)); + } + final Host host = hostDao.findById(hostId); + if (host == null || !Status.Up.equals(host.getStatus()) || !Hypervisor.HypervisorType.KVM.equals(host.getHypervisorType())) { + throw new CloudRuntimeException("Unable to contact backend control plane to initiate backup"); + } + return host; + } + + @Override + public boolean takeBackup(final VirtualMachine vm) { + final Host host = getVMHypervisorHost(vm); + + final BackupRepository backupRepository = backupRepositoryDao.findByBackupOfferingId(vm.getBackupOfferingId()); + if (backupRepository == null) { + throw new CloudRuntimeException("No valid backup repository found for the VM, please check the attached backup offering"); + } + + final Date creationDate = new Date(); + final String backupPath = String.format("%s/%s", vm.getInstanceName(), + new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(creationDate)); + + BackupVO backupVO = createBackupObject(vm, backupPath); + TakeBackupCommand command = new TakeBackupCommand(vm.getInstanceName(), backupPath); + command.setBackupRepoType(backupRepository.getType()); + command.setBackupRepoAddress(backupRepository.getAddress()); + command.setMountOptions(backupRepository.getMountOptions()); + + if (VirtualMachine.State.Stopped.equals(vm.getState())) { + List vmVolumes = volumeDao.findByInstance(vm.getId()); + List volumePaths = getVolumePaths(vmVolumes); + command.setVolumePaths(volumePaths); + } + + BackupAnswer answer = null; + try { + answer = (BackupAnswer) agentManager.send(host.getId(), command); + } catch (AgentUnavailableException e) { + throw new CloudRuntimeException("Unable to contact backend control plane to initiate backup"); + } catch (OperationTimedoutException e) { + throw new CloudRuntimeException("Operation to initiate backup timed out, please try again"); + } + + if (answer != null && answer.getResult()) { + backupVO.setDate(new Date()); + backupVO.setSize(answer.getSize()); + backupVO.setStatus(Backup.Status.BackedUp); + backupVO.setBackedUpVolumes(BackupManagerImpl.createVolumeInfoFromVolumes(volumeDao.findByInstance(vm.getId()))); + return backupDao.update(backupVO.getId(), backupVO); + } else { + backupVO.setStatus(Backup.Status.Failed); + backupDao.remove(backupVO.getId()); + } + return Objects.nonNull(answer) && answer.getResult(); + } + + private BackupVO createBackupObject(VirtualMachine vm, String backupPath) { + BackupVO backup = new BackupVO(); + backup.setVmId(vm.getId()); + backup.setExternalId(backupPath); + backup.setType("FULL"); + backup.setDate(new Date()); + long virtualSize = 0L; + for (final Volume volume: volumeDao.findByInstance(vm.getId())) { + if (Volume.State.Ready.equals(volume.getState())) { + virtualSize += volume.getSize(); + } + } + backup.setProtectedSize(Long.valueOf(virtualSize)); + backup.setStatus(Backup.Status.BackingUp); + backup.setBackupOfferingId(vm.getBackupOfferingId()); + backup.setAccountId(vm.getAccountId()); + backup.setDomainId(vm.getDomainId()); + backup.setZoneId(vm.getDataCenterId()); + return backupDao.persist(backup); + } + + @Override + public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) { + List backedVolumes = backup.getBackedUpVolumes(); + List volumes = backedVolumes.stream().map(volume -> volumeDao.findByUuid(volume.getUuid())).collect(Collectors.toList()); + + LOG.debug("Restoring vm {} from backup {} on the NAS Backup Provider", vm.getUuid(), backup.getUuid()); + BackupRepository backupRepository = getBackupRepository(vm, backup); + + final Host host = getLastVMHypervisorHost(vm); + RestoreBackupCommand restoreCommand = new RestoreBackupCommand(); + restoreCommand.setBackupPath(backup.getExternalId()); + restoreCommand.setBackupRepoType(backupRepository.getType()); + restoreCommand.setBackupRepoAddress(backupRepository.getAddress()); + restoreCommand.setVmName(vm.getName()); + restoreCommand.setVolumePaths(getVolumePaths(volumes)); + restoreCommand.setVmExists(vm.getRemoved() == null); + restoreCommand.setVmState(vm.getState()); + + BackupAnswer answer = null; + try { + answer = (BackupAnswer) agentManager.send(host.getId(), restoreCommand); + } catch (AgentUnavailableException e) { + throw new CloudRuntimeException("Unable to contact backend control plane to initiate backup"); + } catch (OperationTimedoutException e) { + throw new CloudRuntimeException("Operation to initiate backup timed out, please try again"); + } + return answer.getResult(); + } + + private List getVolumePaths(List volumes) { + List volumePaths = new ArrayList<>(); + for (VolumeVO volume : volumes) { + StoragePoolVO storagePool = primaryDataStoreDao.findById(volume.getPoolId()); + if (Objects.isNull(storagePool)) { + throw new CloudRuntimeException("Unable to find storage pool associated to the volume"); + } + String volumePathPrefix = String.format("/mnt/%s", storagePool.getUuid()); + if (ScopeType.HOST.equals(storagePool.getScope())) { + volumePathPrefix = storagePool.getPath(); + } + volumePaths.add(String.format("%s/%s", volumePathPrefix, volume.getPath())); + } + return volumePaths; + } + + @Override + public Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid, Pair vmNameAndState) { + final VolumeVO volume = volumeDao.findByUuid(volumeUuid); + final VirtualMachine backupSourceVm = vmInstanceDao.findById(backup.getVmId()); + final StoragePoolHostVO dataStore = storagePoolHostDao.findByUuid(dataStoreUuid); + final HostVO hostVO = hostDao.findByIp(hostIp); + + Optional matchingVolume = getBackedUpVolumeInfo(backupSourceVm.getBackupVolumeList(), volumeUuid); + Long backedUpVolumeSize = matchingVolume.isPresent() ? matchingVolume.get().getSize() : 0L; + + LOG.debug("Restoring vm volume" + volumeUuid + "from backup " + backup.getUuid() + " on the NAS Backup Provider"); + BackupRepository backupRepository = getBackupRepository(backupSourceVm, backup); + + VolumeVO restoredVolume = new VolumeVO(Volume.Type.DATADISK, null, backup.getZoneId(), + backup.getDomainId(), backup.getAccountId(), 0, null, + backup.getSize(), null, null, null); + String volumeUUID = UUID.randomUUID().toString(); + restoredVolume.setName("RestoredVol-"+volume.getName()); + restoredVolume.setProvisioningType(volume.getProvisioningType()); + restoredVolume.setUpdated(new Date()); + restoredVolume.setUuid(volumeUUID); + restoredVolume.setRemoved(null); + restoredVolume.setDisplayVolume(true); + restoredVolume.setPoolId(dataStore.getPoolId()); + restoredVolume.setPath(restoredVolume.getUuid()); + restoredVolume.setState(Volume.State.Copying); + restoredVolume.setSize(backedUpVolumeSize); + restoredVolume.setDiskOfferingId(volume.getDiskOfferingId()); + + RestoreBackupCommand restoreCommand = new RestoreBackupCommand(); + restoreCommand.setBackupPath(backup.getExternalId()); + restoreCommand.setBackupRepoType(backupRepository.getType()); + restoreCommand.setBackupRepoAddress(backupRepository.getAddress()); + restoreCommand.setVmName(vmNameAndState.first()); + restoreCommand.setVolumePaths(Collections.singletonList(String.format("%s/%s", dataStore.getLocalPath(), volumeUUID))); + restoreCommand.setDiskType(volume.getVolumeType().name().toLowerCase(Locale.ROOT)); + restoreCommand.setVmExists(null); + restoreCommand.setVmState(vmNameAndState.second()); + restoreCommand.setRestoreVolumeUUID(volumeUuid); + + BackupAnswer answer = null; + try { + answer = (BackupAnswer) agentManager.send(hostVO.getId(), restoreCommand); + } catch (AgentUnavailableException e) { + throw new CloudRuntimeException("Unable to contact backend control plane to initiate backup"); + } catch (OperationTimedoutException e) { + throw new CloudRuntimeException("Operation to initiate backup timed out, please try again"); + } + + if (answer.getResult()) { + try { + volumeDao.persist(restoredVolume); + } catch (Exception e) { + throw new CloudRuntimeException("Unable to create restored volume due to: " + e); + } + } + + return new Pair<>(answer.getResult(), answer.getDetails()); + } + + private BackupRepository getBackupRepository(VirtualMachine vm, Backup backup) { + BackupRepository backupRepository = backupRepositoryDao.findByBackupOfferingId(vm.getBackupOfferingId()); + final String errorMessage = "No valid backup repository found for the VM, please check the attached backup offering"; + if (backupRepository == null) { + logger.warn(errorMessage + "Re-attempting with the backup offering associated with the backup"); + } + backupRepository = backupRepositoryDao.findByBackupOfferingId(backup.getBackupOfferingId()); + if (backupRepository == null) { + throw new CloudRuntimeException(errorMessage); + } + return backupRepository; + } + + private Optional getBackedUpVolumeInfo(List backedUpVolumes, String volumeUuid) { + return backedUpVolumes.stream() + .filter(v -> v.getUuid().equals(volumeUuid)) + .findFirst(); + } + + @Override + public boolean deleteBackup(Backup backup, boolean forced) { + final BackupRepository backupRepository = backupRepositoryDao.findByBackupOfferingId(backup.getBackupOfferingId()); + if (backupRepository == null) { + throw new CloudRuntimeException("No valid backup repository found for the VM, please check the attached backup offering"); + } + + final VirtualMachine vm = vmInstanceDao.findByIdIncludingRemoved(backup.getVmId()); + final Host host = getLastVMHypervisorHost(vm); + + DeleteBackupCommand command = new DeleteBackupCommand(backup.getExternalId(), backupRepository.getType(), + backupRepository.getAddress(), backupRepository.getMountOptions()); + + BackupAnswer answer = null; + try { + answer = (BackupAnswer) agentManager.send(host.getId(), command); + } catch (AgentUnavailableException e) { + throw new CloudRuntimeException("Unable to contact backend control plane to initiate backup"); + } catch (OperationTimedoutException e) { + throw new CloudRuntimeException("Operation to initiate backup timed out, please try again"); + } + + if (answer != null && answer.getResult()) { + return backupDao.remove(backup.getId()); + } + + return false; + } + + @Override + public Map getBackupMetrics(Long zoneId, List vms) { + final Map metrics = new HashMap<>(); + if (CollectionUtils.isEmpty(vms)) { + LOG.warn("Unable to get VM Backup Metrics because the list of VMs is empty."); + return metrics; + } + + for (final VirtualMachine vm : vms) { + Long vmBackupSize = 0L; + Long vmBackupProtectedSize = 0L; + for (final Backup backup: backupDao.listByVmId(null, vm.getId())) { + vmBackupSize += backup.getSize(); + vmBackupProtectedSize += backup.getProtectedSize(); + } + Backup.Metric vmBackupMetric = new Backup.Metric(vmBackupSize,vmBackupProtectedSize); + LOG.debug(String.format("Metrics for VM [uuid: %s, name: %s] is [backup size: %s, data size: %s].", vm.getUuid(), + vm.getInstanceName(), vmBackupMetric.getBackupSize(), vmBackupMetric.getDataSize())); + metrics.put(vm, vmBackupMetric); + } + return metrics; + } + + @Override + public boolean assignVMToBackupOffering(VirtualMachine vm, BackupOffering backupOffering) { + return Hypervisor.HypervisorType.KVM.equals(vm.getHypervisorType()); + } + + @Override + public boolean removeVMFromBackupOffering(VirtualMachine vm) { + return true; + } + + @Override + public boolean willDeleteBackupsOnOfferingRemoval() { + return false; + } + + @Override + public void syncBackups(VirtualMachine vm, Backup.Metric metric) { + // TODO: check and sum/return backups metrics on per VM basis + } + + @Override + public List listBackupOfferings(Long zoneId) { + final List repositories = backupRepositoryDao.listByZoneAndProvider(zoneId, getName()); + final List offerings = new ArrayList<>(); + for (final BackupRepository repository : repositories) { + offerings.add(new NasBackupOffering(repository.getName(), repository.getUuid())); + } + return offerings; + } + + @Override + public boolean isValidProviderOffering(Long zoneId, String uuid) { + return true; + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[]{ + }; + } + + @Override + public String getName() { + return "nas"; + } + + @Override + public String getDescription() { + return "NAS Backup Plugin"; + } + + @Override + public String getConfigComponentName() { + return BackupService.class.getSimpleName(); + } +} diff --git a/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NasBackupOffering.java b/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NasBackupOffering.java new file mode 100644 index 000000000000..91df74166e58 --- /dev/null +++ b/plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NasBackupOffering.java @@ -0,0 +1,75 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.backup; + +import java.util.Date; + +public class NasBackupOffering implements BackupOffering { + + private String name; + private String uid; + + public NasBackupOffering(String name, String uid) { + this.name = name; + this.uid = uid; + } + + @Override + public String getExternalId() { + return uid; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getDescription() { + return "NAS Backup Offering (Repository)"; + } + + @Override + public long getZoneId() { + return -1; + } + + @Override + public boolean isUserDrivenBackupAllowed() { + return true; + } + + @Override + public String getProvider() { + return "nas"; + } + + @Override + public Date getCreated() { + return null; + } + + @Override + public String getUuid() { + return uid; + } + + @Override + public long getId() { + return -1; + } +} diff --git a/plugins/backup/nas/src/main/resources/META-INF/cloudstack/nas/module.properties b/plugins/backup/nas/src/main/resources/META-INF/cloudstack/nas/module.properties new file mode 100644 index 000000000000..2e101ef02314 --- /dev/null +++ b/plugins/backup/nas/src/main/resources/META-INF/cloudstack/nas/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=nas +parent=backup diff --git a/plugins/backup/nas/src/main/resources/META-INF/cloudstack/nas/spring-backup-nas-context.xml b/plugins/backup/nas/src/main/resources/META-INF/cloudstack/nas/spring-backup-nas-context.xml new file mode 100644 index 000000000000..635ca66fbdee --- /dev/null +++ b/plugins/backup/nas/src/main/resources/META-INF/cloudstack/nas/spring-backup-nas-context.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/plugins/backup/networker/pom.xml b/plugins/backup/networker/pom.xml index a4a6c02be696..1124d281d2e4 100644 --- a/plugins/backup/networker/pom.xml +++ b/plugins/backup/networker/pom.xml @@ -25,7 +25,7 @@ cloudstack-plugins org.apache.cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java b/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java index 9703203108a8..0e87ad338871 100644 --- a/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java +++ b/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java @@ -44,7 +44,8 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xml.utils.URI; import org.apache.cloudstack.backup.networker.api.NetworkerBackup; import javax.inject.Inject; @@ -68,7 +69,7 @@ public class NetworkerBackupProvider extends AdapterBase implements BackupProvider, Configurable { public static final String BACKUP_IDENTIFIER = "-CSBKP-"; - private static final Logger LOG = Logger.getLogger(NetworkerBackupProvider.class); + private static final Logger LOG = LogManager.getLogger(NetworkerBackupProvider.class); public ConfigKey NetworkerUrl = new ConfigKey<>("Advanced", String.class, "backup.plugin.networker.url", "https://localhost:9090/nwrestapi/v3", @@ -371,7 +372,7 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) { } @Override - public Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid) { + public Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid, Pair vmNameAndState) { String networkerServer; VolumeVO volume = volumeDao.findByUuid(volumeUuid); VMInstanceVO backupSourceVm = vmInstanceDao.findById(backup.getVmId()); @@ -511,6 +512,7 @@ public boolean takeBackup(VirtualMachine vm) { LOG.info ("EMC Networker finished backup job for vm " + vm.getName() + " with saveset Time: " + saveTime); BackupVO backup = getClient(vm.getDataCenterId()).registerBackupForVm(vm, backupJobStart, saveTime); if (backup != null) { + backup.setBackedUpVolumes(BackupManagerImpl.createVolumeInfoFromVolumes(volumeDao.findByInstance(vm.getId()))); backupDao.persist(backup); return true; } else { diff --git a/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java b/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java index 8bb89b635e98..8aecaa26023e 100644 --- a/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java +++ b/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java @@ -42,7 +42,8 @@ import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import javax.net.ssl.SSLContext; import javax.net.ssl.X509TrustManager; @@ -64,7 +65,7 @@ import static org.apache.cloudstack.backup.NetworkerBackupProvider.BACKUP_IDENTIFIER; public class NetworkerClient { - private static final Logger LOG = Logger.getLogger(NetworkerClient.class); + private static final Logger LOG = LogManager.getLogger(NetworkerClient.class); private final URI apiURI; private final String apiName; private final String apiPassword; diff --git a/plugins/backup/veeam/pom.xml b/plugins/backup/veeam/pom.xml index a3d445756b8c..a317f90388a9 100644 --- a/plugins/backup/veeam/pom.xml +++ b/plugins/backup/veeam/pom.xml @@ -23,7 +23,7 @@ cloudstack-plugins org.apache.cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java index e20f67995b9f..4750e3264aac 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java @@ -39,7 +39,6 @@ import org.apache.cloudstack.framework.config.Configurable; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -65,7 +64,6 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, Configurable { - private static final Logger LOG = Logger.getLogger(VeeamBackupProvider.class); public static final String BACKUP_IDENTIFIER = "-CSBKP-"; public ConfigKey VeeamUrl = new ConfigKey<>("Advanced", String.class, @@ -120,7 +118,7 @@ protected VeeamClient getClient(final Long zoneId) { } catch (URISyntaxException e) { throw new CloudRuntimeException("Failed to parse Veeam API URL: " + e.getMessage()); } catch (NoSuchAlgorithmException | KeyManagementException e) { - LOG.error("Failed to build Veeam API client due to: ", e); + logger.error("Failed to build Veeam API client due to: ", e); } throw new CloudRuntimeException("Failed to build Veeam API client"); } @@ -175,7 +173,7 @@ public boolean assignVMToBackupOffering(final VirtualMachine vm, final BackupOff final String clonedJobName = getGuestBackupName(vm.getInstanceName(), vm.getUuid()); if (!client.cloneVeeamJob(parentJob, clonedJobName)) { - LOG.error("Failed to clone pre-defined Veeam job (backup offering) for backup offering ID: " + backupOffering.getExternalId() + " but will check the list of jobs again if it was eventually succeeded."); + logger.error("Failed to clone pre-defined Veeam job (backup offering) for backup offering ID: " + backupOffering.getExternalId() + " but will check the list of jobs again if it was eventually succeeded."); } for (final BackupOffering job : client.listJobs()) { @@ -184,7 +182,7 @@ public boolean assignVMToBackupOffering(final VirtualMachine vm, final BackupOff if (BooleanUtils.isTrue(clonedJob.getScheduleConfigured()) && !clonedJob.getScheduleEnabled()) { client.toggleJobSchedule(clonedJob.getId()); } - LOG.debug("Veeam job (backup offering) for backup offering ID: " + backupOffering.getExternalId() + " found, now trying to assign the VM to the job."); + logger.debug("Veeam job (backup offering) for backup offering ID: " + backupOffering.getExternalId() + " found, now trying to assign the VM to the job."); final VmwareDatacenter vmwareDC = findVmwareDatacenterForVM(vm); if (client.addVMToVeeamJob(job.getExternalId(), vm.getInstanceName(), vmwareDC.getVcenterHost())) { ((VMInstanceVO) vm).setBackupExternalId(job.getExternalId()); @@ -201,15 +199,15 @@ public boolean removeVMFromBackupOffering(final VirtualMachine vm) { final VmwareDatacenter vmwareDC = findVmwareDatacenterForVM(vm); try { if (!client.removeVMFromVeeamJob(vm.getBackupExternalId(), vm.getInstanceName(), vmwareDC.getVcenterHost())) { - LOG.warn("Failed to remove VM from Veeam Job id: " + vm.getBackupExternalId()); + logger.warn("Failed to remove VM from Veeam Job id: " + vm.getBackupExternalId()); } } catch (Exception e) { - LOG.debug("VM was removed from the job so could not remove again, trying to delete the veeam job now.", e); + logger.debug("VM was removed from the job so could not remove again, trying to delete the veeam job now.", e); } final String clonedJobName = getGuestBackupName(vm.getInstanceName(), vm.getUuid()); if (!client.deleteJobAndBackup(clonedJobName)) { - LOG.warn("Failed to remove Veeam job and backup for job: " + clonedJobName); + logger.warn("Failed to remove Veeam job and backup for job: " + clonedJobName); throw new CloudRuntimeException("Failed to delete Veeam B&R job and backup, an operation may be in progress. Please try again after some time."); } client.syncBackupRepository(); @@ -234,7 +232,7 @@ public boolean deleteBackup(Backup backup, boolean forced) { throw new CloudRuntimeException(String.format("Could not find any VM associated with the Backup [uuid: %s, externalId: %s].", backup.getUuid(), backup.getExternalId())); } if (!forced) { - LOG.debug(String.format("Veeam backup provider does not have a safe way to remove a single restore point, which results in all backup chain being removed. " + logger.debug(String.format("Veeam backup provider does not have a safe way to remove a single restore point, which results in all backup chain being removed. " + "More information about this limitation can be found in the links: [%s, %s].", "https://forums.veeam.com/powershell-f26/removing-a-single-restorepoint-t21061.html", "https://helpcenter.veeam.com/docs/backup/vsphere/retention_separate_vms.html?ver=110")); throw new CloudRuntimeException("Veeam backup provider does not have a safe way to remove a single restore point, which results in all backup chain being removed. " @@ -263,7 +261,7 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) { try { return getClient(vm.getDataCenterId()).restoreFullVM(vm.getInstanceName(), restorePointId); } catch (Exception ex) { - LOG.error(String.format("Failed to restore Full VM due to: %s. Retrying after some preparation", ex.getMessage())); + logger.error(String.format("Failed to restore Full VM due to: %s. Retrying after some preparation", ex.getMessage())); prepareForBackupRestoration(vm); return getClient(vm.getDataCenterId()).restoreFullVM(vm.getInstanceName(), restorePointId); } @@ -273,7 +271,7 @@ private void prepareForBackupRestoration(VirtualMachine vm) { if (!Hypervisor.HypervisorType.VMware.equals(vm.getHypervisorType())) { return; } - LOG.info("Preparing for restoring VM " + vm); + logger.info("Preparing for restoring VM " + vm); PrepareForBackupRestorationCommand command = new PrepareForBackupRestorationCommand(vm.getInstanceName()); Long hostId = virtualMachineManager.findClusterAndHostIdForVm(vm.getId()).second(); if (hostId == null) { @@ -282,7 +280,7 @@ private void prepareForBackupRestoration(VirtualMachine vm) { try { Answer answer = agentMgr.easySend(hostId, command); if (answer != null && answer.getResult()) { - LOG.info("Succeeded to prepare for restoring VM " + vm); + logger.info("Succeeded to prepare for restoring VM " + vm); } else { throw new CloudRuntimeException(String.format("Failed to prepare for restoring VM %s. details: %s", vm, (answer != null ? answer.getDetails() : null))); @@ -293,7 +291,7 @@ private void prepareForBackupRestoration(VirtualMachine vm) { } @Override - public Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid) { + public Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid, Pair vmNameAndState) { final Long zoneId = backup.getZoneId(); final String restorePointId = backup.getExternalId(); return getClient(zoneId).restoreVMToDifferentLocation(restorePointId, hostIp, dataStoreUuid); @@ -303,12 +301,12 @@ public Pair restoreBackedUpVolume(Backup backup, String volumeU public Map getBackupMetrics(final Long zoneId, final List vms) { final Map metrics = new HashMap<>(); if (CollectionUtils.isEmpty(vms)) { - LOG.warn("Unable to get VM Backup Metrics because the list of VMs is empty."); + logger.warn("Unable to get VM Backup Metrics because the list of VMs is empty."); return metrics; } List vmUuids = vms.stream().filter(Objects::nonNull).map(VirtualMachine::getUuid).collect(Collectors.toList()); - LOG.debug(String.format("Get Backup Metrics for VMs: [%s].", String.join(", ", vmUuids))); + logger.debug(String.format("Get Backup Metrics for VMs: [%s].", String.join(", ", vmUuids))); final Map backendMetrics = getClient(zoneId).getBackupMetrics(); for (final VirtualMachine vm : vms) { @@ -317,7 +315,7 @@ public Map getBackupMetrics(final Long zoneId, fi } Metric metric = backendMetrics.get(vm.getUuid()); - LOG.debug(String.format("Metrics for VM [uuid: %s, name: %s] is [backup size: %s, data size: %s].", vm.getUuid(), + logger.debug(String.format("Metrics for VM [uuid: %s, name: %s] is [backup size: %s, data size: %s].", vm.getUuid(), vm.getInstanceName(), metric.getBackupSize(), metric.getDataSize())); metrics.put(vm, metric); } @@ -333,7 +331,7 @@ private Backup checkAndUpdateIfBackupEntryExistsForRestorePoint(List bac for (final Backup backup : backupsInDb) { if (restorePoint.getId().equals(backup.getExternalId())) { if (metric != null) { - LOG.debug(String.format("Update backup with [uuid: %s, external id: %s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].", + logger.debug(String.format("Update backup with [uuid: %s, external id: %s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].", backup.getUuid(), backup.getExternalId(), backup.getSize(), backup.getProtectedSize(), metric.getBackupSize(), metric.getDataSize())); ((BackupVO) backup).setSize(metric.getBackupSize()); @@ -350,7 +348,7 @@ private Backup checkAndUpdateIfBackupEntryExistsForRestorePoint(List bac public void syncBackups(VirtualMachine vm, Backup.Metric metric) { List restorePoints = listRestorePoints(vm); if (CollectionUtils.isEmpty(restorePoints)) { - LOG.debug(String.format("Can't find any restore point to VM: [uuid: %s, name: %s].", vm.getUuid(), vm.getInstanceName())); + logger.debug(String.format("Can't find any restore point to VM: [uuid: %s, name: %s].", vm.getUuid(), vm.getInstanceName())); return; } Transaction.execute(new TransactionCallbackNoReturn() { @@ -381,7 +379,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { backup.setDomainId(vm.getDomainId()); backup.setZoneId(vm.getDataCenterId()); - LOG.debug(String.format("Creating a new entry in backups: [uuid: %s, vm_id: %s, external_id: %s, type: %s, date: %s, backup_offering_id: %s, account_id: %s, " + logger.debug(String.format("Creating a new entry in backups: [uuid: %s, vm_id: %s, external_id: %s, type: %s, date: %s, backup_offering_id: %s, account_id: %s, " + "domain_id: %s, zone_id: %s].", backup.getUuid(), backup.getVmId(), backup.getExternalId(), backup.getType(), backup.getDate(), backup.getBackupOfferingId(), backup.getAccountId(), backup.getDomainId(), backup.getZoneId())); backupDao.persist(backup); @@ -392,7 +390,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { } } for (final Long backupIdToRemove : removeList) { - LOG.warn(String.format("Removing backup with ID: [%s].", backupIdToRemove)); + logger.warn(String.format("Removing backup with ID: [%s].", backupIdToRemove)); backupDao.remove(backupIdToRemove); } } diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java index befeb231015a..d911736090cb 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java @@ -79,7 +79,8 @@ import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -93,7 +94,7 @@ import org.apache.commons.lang3.StringUtils; public class VeeamClient { - private static final Logger LOG = Logger.getLogger(VeeamClient.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String FAILED_TO_DELETE = "Failed to delete"; private final URI apiURI; @@ -193,24 +194,24 @@ protected Integer getVeeamServerVersion() { ); Pair response = executePowerShellCommands(cmds); if (response == null || !response.first() || response.second() == null || StringUtils.isBlank(response.second().trim())) { - LOG.error("Failed to get veeam server version, using default version"); + logger.error("Failed to get veeam server version, using default version"); return 0; } else { Integer majorVersion = NumbersUtil.parseInt(response.second().trim().split("\\.")[0], 0); - LOG.info(String.format("Veeam server full version is %s, major version is %s", response.second().trim(), majorVersion)); + logger.info(String.format("Veeam server full version is %s, major version is %s", response.second().trim(), majorVersion)); return majorVersion; } } private void checkResponseOK(final HttpResponse response) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) { - LOG.debug("Requested Veeam resource does not exist"); + logger.debug("Requested Veeam resource does not exist"); return; } if (!(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK || response.getStatusLine().getStatusCode() == HttpStatus.SC_ACCEPTED) && response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { - LOG.debug(String.format("HTTP request failed, status code is [%s], response is: [%s].", response.getStatusLine().getStatusCode(), response.toString())); + logger.debug(String.format("HTTP request failed, status code is [%s], response is: [%s].", response.getStatusLine().getStatusCode(), response.toString())); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Got invalid API status code returned by the Veeam server"); } } @@ -228,7 +229,7 @@ protected HttpResponse get(final String path) throws IOException { final HttpResponse response = httpClient.execute(request); checkAuthFailure(response); - LOG.debug(String.format("Response received in GET request is: [%s] for URL: [%s].", response.toString(), url)); + logger.debug(String.format("Response received in GET request is: [%s] for URL: [%s].", response.toString(), url)); return response; } @@ -254,7 +255,7 @@ private HttpResponse post(final String path, final Object obj) throws IOExceptio final HttpResponse response = httpClient.execute(request); checkAuthFailure(response); - LOG.debug(String.format("Response received in POST request with body [%s] is: [%s] for URL [%s].", xml, response.toString(), url)); + logger.debug(String.format("Response received in POST request with body [%s] is: [%s] for URL [%s].", xml, response.toString(), url)); return response; } @@ -265,7 +266,7 @@ private HttpResponse delete(final String path) throws IOException { final HttpResponse response = httpClient.execute(request); checkAuthFailure(response); - LOG.debug(String.format("Response received in DELETE request is: [%s] for URL [%s].", response.toString(), url)); + logger.debug(String.format("Response received in DELETE request is: [%s] for URL [%s].", response.toString(), url)); return response; } @@ -274,7 +275,7 @@ private HttpResponse delete(final String path) throws IOException { /////////////////////////////////////////////////////////////////// private String findDCHierarchy(final String vmwareDcName) { - LOG.debug("Trying to find hierarchy ID for vmware datacenter: " + vmwareDcName); + logger.debug("Trying to find hierarchy ID for vmware datacenter: " + vmwareDcName); try { final HttpResponse response = get("/hierarchyRoots"); @@ -287,14 +288,14 @@ private String findDCHierarchy(final String vmwareDcName) { } } } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } throw new CloudRuntimeException("Failed to find hierarchy reference for VMware datacenter " + vmwareDcName + " in Veeam, please ask administrator to check Veeam B&R manager configuration"); } private String lookupVM(final String hierarchyId, final String vmName) { - LOG.debug("Trying to lookup VM from veeam hierarchy:" + hierarchyId + " for vm name:" + vmName); + logger.debug("Trying to lookup VM from veeam hierarchy:" + hierarchyId + " for vm name:" + vmName); try { final HttpResponse response = get(String.format("/lookup?host=%s&type=Vm&name=%s", hierarchyId, vmName)); @@ -310,7 +311,7 @@ private String lookupVM(final String hierarchyId, final String vmName) { } } } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } throw new CloudRuntimeException("Failed to lookup VM " + vmName + " in Veeam, please ask administrator to check Veeam B&R manager configuration"); @@ -336,7 +337,7 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException if (polledTask.getState().equals("Finished")) { final HttpResponse taskDeleteResponse = delete("/tasks/" + task.getTaskId()); if (taskDeleteResponse.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { - LOG.warn("Operation failed for veeam task id=" + task.getTaskId()); + logger.warn("Operation failed for veeam task id=" + task.getTaskId()); } if (polledTask.getResult().getSuccess().equals("true")) { Pair pair = getRelatedLinkPair(polledTask.getLink()); @@ -355,7 +356,7 @@ private boolean checkTaskStatus(final HttpResponse response) throws IOException try { Thread.sleep(this.taskPollInterval * 1000); } catch (InterruptedException e) { - LOG.debug("Failed to sleep while polling for Veeam task status due to: ", e); + logger.debug("Failed to sleep while polling for Veeam task status due to: ", e); } } return false; @@ -377,17 +378,17 @@ protected void checkIfRestoreSessionFinished(String type, String path) throws IO if (session.getResult().equalsIgnoreCase("Failed")) { String sessionUid = session.getUid(); - LOG.error(String.format("Failed to restore backup [%s] of VM [%s] due to [%s].", + logger.error(String.format("Failed to restore backup [%s] of VM [%s] due to [%s].", sessionUid, session.getVmDisplayName(), getRestoreVmErrorDescription(StringUtils.substringAfterLast(sessionUid, ":")))); throw new CloudRuntimeException(String.format("Restore job [%s] failed.", sessionUid)); } - LOG.debug(String.format("Waiting %s seconds, out of a total of %s seconds, for the restore backup process to finish.", j, restoreTimeout)); + logger.debug(String.format("Waiting %s seconds, out of a total of %s seconds, for the restore backup process to finish.", j, restoreTimeout)); try { Thread.sleep(1000); } catch (InterruptedException ignored) { - LOG.trace(String.format("Ignoring InterruptedException [%s] when waiting for restore session finishes.", ignored.getMessage())); + logger.trace(String.format("Ignoring InterruptedException [%s] when waiting for restore session finishes.", ignored.getMessage())); } } throw new CloudRuntimeException("Related job type: " + type + " was not successful"); @@ -407,7 +408,7 @@ private Pair getRelatedLinkPair(List links) { //////////////////////////////////////////////////////// public Ref listBackupRepository(final String backupServerId, final String backupName) { - LOG.debug(String.format("Trying to list backup repository for backup job [name: %s] in server [id: %s].", backupName, backupServerId)); + logger.debug(String.format("Trying to list backup repository for backup job [name: %s] in server [id: %s].", backupName, backupServerId)); try { String repositoryName = getRepositoryNameFromJob(backupName); final HttpResponse response = get(String.format("/backupServers/%s/repositories", backupServerId)); @@ -420,7 +421,7 @@ public Ref listBackupRepository(final String backupServerId, final String backup } } } catch (final IOException e) { - LOG.error(String.format("Failed to list Veeam backup repository used by backup job [name: %s] due to: [%s].", backupName, e.getMessage()), e); + logger.error(String.format("Failed to list Veeam backup repository used by backup job [name: %s] due to: [%s].", backupName, e.getMessage()), e); checkResponseTimeOut(e); } return null; @@ -445,23 +446,23 @@ protected String getRepositoryNameFromJob(String backupName) { } public void listAllBackups() { - LOG.debug("Trying to list Veeam backups"); + logger.debug("Trying to list Veeam backups"); try { final HttpResponse response = get("/backups"); checkResponseOK(response); final ObjectMapper objectMapper = new XmlMapper(); final EntityReferences entityReferences = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class); for (final Ref ref : entityReferences.getRefs()) { - LOG.debug("Veeam Backup found, name: " + ref.getName() + ", uid: " + ref.getUid() + ", type: " + ref.getType()); + logger.debug("Veeam Backup found, name: " + ref.getName() + ", uid: " + ref.getUid() + ", type: " + ref.getType()); } } catch (final IOException e) { - LOG.error("Failed to list Veeam backups due to:", e); + logger.error("Failed to list Veeam backups due to:", e); checkResponseTimeOut(e); } } public List listJobs() { - LOG.debug("Trying to list backup policies that are Veeam jobs"); + logger.debug("Trying to list backup policies that are Veeam jobs"); try { final HttpResponse response = get("/jobs"); checkResponseOK(response); @@ -476,14 +477,14 @@ public List listJobs() { } return policies; } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } return new ArrayList<>(); } public Job listJob(final String jobId) { - LOG.debug("Trying to list veeam job id: " + jobId); + logger.debug("Trying to list veeam job id: " + jobId); try { final HttpResponse response = get(String.format("/jobs/%s?format=Entity", jobId.replace("urn:veeam:Job:", ""))); @@ -492,40 +493,40 @@ public Job listJob(final String jobId) { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper.readValue(response.getEntity().getContent(), Job.class); } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } catch (final ServerApiException e) { - LOG.error(e); + logger.error(e); } return null; } public boolean toggleJobSchedule(final String jobId) { - LOG.debug("Trying to toggle schedule for Veeam job: " + jobId); + logger.debug("Trying to toggle schedule for Veeam job: " + jobId); try { final HttpResponse response = post(String.format("/jobs/%s?action=toggleScheduleEnabled", jobId), null); return checkTaskStatus(response); } catch (final IOException e) { - LOG.error("Failed to toggle Veeam job schedule due to:", e); + logger.error("Failed to toggle Veeam job schedule due to:", e); checkResponseTimeOut(e); } return false; } public boolean startBackupJob(final String jobId) { - LOG.debug("Trying to start ad-hoc backup for Veeam job: " + jobId); + logger.debug("Trying to start ad-hoc backup for Veeam job: " + jobId); try { final HttpResponse response = post(String.format("/jobs/%s?action=start", jobId), null); return checkTaskStatus(response); } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } return false; } public boolean cloneVeeamJob(final Job parentJob, final String clonedJobName) { - LOG.debug("Trying to clone veeam job: " + parentJob.getUid() + " with backup uuid: " + clonedJobName); + logger.debug("Trying to clone veeam job: " + parentJob.getUid() + " with backup uuid: " + clonedJobName); try { final Ref repositoryRef = listBackupRepository(parentJob.getBackupServerId(), parentJob.getName()); if (repositoryRef == null) { @@ -541,13 +542,13 @@ public boolean cloneVeeamJob(final Job parentJob, final String clonedJobName) { final HttpResponse response = post(String.format("/jobs/%s?action=clone", parentJob.getId()), cloneSpec); return checkTaskStatus(response); } catch (final Exception e) { - LOG.warn("Exception caught while trying to clone Veeam job:", e); + logger.warn("Exception caught while trying to clone Veeam job:", e); } return false; } public boolean addVMToVeeamJob(final String jobId, final String vmwareInstanceName, final String vmwareDcName) { - LOG.debug("Trying to add VM to backup offering that is Veeam job: " + jobId); + logger.debug("Trying to add VM to backup offering that is Veeam job: " + jobId); try { final String heirarchyId = findDCHierarchy(vmwareDcName); final String veeamVmRefId = lookupVM(heirarchyId, vmwareInstanceName); @@ -557,14 +558,14 @@ public boolean addVMToVeeamJob(final String jobId, final String vmwareInstanceNa final HttpResponse response = post(String.format("/jobs/%s/includes", jobId), vmToBackupJob); return checkTaskStatus(response); } catch (final IOException e) { - LOG.error("Failed to add VM to Veeam job due to:", e); + logger.error("Failed to add VM to Veeam job due to:", e); checkResponseTimeOut(e); } throw new CloudRuntimeException("Failed to add VM to backup offering likely due to timeout, please check Veeam tasks"); } public boolean removeVMFromVeeamJob(final String jobId, final String vmwareInstanceName, final String vmwareDcName) { - LOG.debug("Trying to remove VM from backup offering that is a Veeam job: " + jobId); + logger.debug("Trying to remove VM from backup offering that is a Veeam job: " + jobId); try { final String hierarchyId = findDCHierarchy(vmwareDcName); final String veeamVmRefId = lookupVM(hierarchyId, vmwareInstanceName); @@ -574,7 +575,7 @@ public boolean removeVMFromVeeamJob(final String jobId, final String vmwareInsta objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); final ObjectsInJob jobObjects = objectMapper.readValue(response.getEntity().getContent(), ObjectsInJob.class); if (jobObjects == null || jobObjects.getObjects() == null) { - LOG.warn("No objects found in the Veeam job " + jobId); + logger.warn("No objects found in the Veeam job " + jobId); return false; } for (final ObjectInJob jobObject : jobObjects.getObjects()) { @@ -583,22 +584,22 @@ public boolean removeVMFromVeeamJob(final String jobId, final String vmwareInsta return checkTaskStatus(deleteResponse); } } - LOG.warn(vmwareInstanceName + " VM was not found to be attached to Veaam job (backup offering): " + jobId); + logger.warn(vmwareInstanceName + " VM was not found to be attached to Veaam job (backup offering): " + jobId); return false; } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } return false; } public boolean restoreFullVM(final String vmwareInstanceName, final String restorePointId) { - LOG.debug("Trying to restore full VM: " + vmwareInstanceName + " from backup"); + logger.debug("Trying to restore full VM: " + vmwareInstanceName + " from backup"); try { final HttpResponse response = post(String.format("/vmRestorePoints/%s?action=restore", restorePointId), null); return checkTaskStatus(response); } catch (final IOException e) { - LOG.error("Failed to restore full VM due to: ", e); + logger.error("Failed to restore full VM due to: ", e); checkResponseTimeOut(e); } throw new CloudRuntimeException("Failed to restore full VM from backup"); @@ -636,9 +637,9 @@ protected Pair executePowerShellCommands(List cmds) { commands, 120000, 120000, 3600000); if (response == null || !response.first()) { - LOG.error(String.format("Veeam PowerShell commands [%s] failed due to: [%s].", commands, response != null ? response.second() : "no PowerShell output returned")); + logger.error(String.format("Veeam PowerShell commands [%s] failed due to: [%s].", commands, response != null ? response.second() : "no PowerShell output returned")); } else { - LOG.debug(String.format("Veeam response for PowerShell commands [%s] is: [%s].", commands, response.second())); + logger.debug(String.format("Veeam response for PowerShell commands [%s] is: [%s].", commands, response.second())); } return response; @@ -666,7 +667,7 @@ public boolean deleteJobAndBackup(final String jobName) { } public boolean deleteBackup(final String restorePointId) { - LOG.debug(String.format("Trying to delete restore point [name: %s].", restorePointId)); + logger.debug(String.format("Trying to delete restore point [name: %s].", restorePointId)); Pair result = executePowerShellCommands(Arrays.asList( String.format("$restorePoint = Get-VBRRestorePoint ^| Where-Object { $_.Id -eq '%s' }", restorePointId), "if ($restorePoint) { Remove-VBRRestorePoint -Oib $restorePoint -Confirm:$false", @@ -679,13 +680,13 @@ public boolean deleteBackup(final String restorePointId) { } public boolean syncBackupRepository() { - LOG.debug("Trying to sync backup repository."); + logger.debug("Trying to sync backup repository."); Pair result = executePowerShellCommands(Arrays.asList( "$repo = Get-VBRBackupRepository", "$Syncs = Sync-VBRBackupRepository -Repository $repo", "while ((Get-VBRSession -ID $Syncs.ID).Result -ne 'Success') { Start-Sleep -Seconds 10 }" )); - LOG.debug("Done syncing backup repository."); + logger.debug("Done syncing backup repository."); return result != null && result.first(); } @@ -698,14 +699,14 @@ public Map getBackupMetrics() { } public Map getBackupMetricsViaVeeamAPI() { - LOG.debug("Trying to get backup metrics via Veeam B&R API"); + logger.debug("Trying to get backup metrics via Veeam B&R API"); try { final HttpResponse response = get(String.format("/backupFiles?format=Entity")); checkResponseOK(response); return processHttpResponseForBackupMetrics(response.getEntity().getContent()); } catch (final IOException e) { - LOG.error("Failed to get backup metrics via Veeam B&R API due to:", e); + logger.error("Failed to get backup metrics via Veeam B&R API due to:", e); checkResponseTimeOut(e); } return new HashMap<>(); @@ -756,7 +757,7 @@ protected Map processHttpResponseForBackupMetrics(final I metrics.put(vmUuid, new Backup.Metric(usedSize, dataSize)); } } catch (final IOException e) { - LOG.error("Failed to process response to get backup metrics via Veeam B&R API due to:", e); + logger.error("Failed to process response to get backup metrics via Veeam B&R API due to:", e); checkResponseTimeOut(e); } return metrics; @@ -794,7 +795,7 @@ public Map getBackupMetricsLegacy() { } protected Map processPowerShellResultForBackupMetrics(final String result) { - LOG.debug("Processing powershell result: " + result); + logger.debug("Processing powershell result: " + result); final String separator = "====="; final Map sizes = new HashMap<>(); @@ -813,7 +814,7 @@ protected Map processPowerShellResultForBackupMetrics(fin } private Backup.RestorePoint getRestorePointFromBlock(String[] parts) { - LOG.debug(String.format("Processing block of restore points: [%s].", StringUtils.join(parts, ", "))); + logger.debug(String.format("Processing block of restore points: [%s].", StringUtils.join(parts, ", "))); String id = null; Date created = null; String type = null; @@ -852,7 +853,7 @@ public List listRestorePointsLegacy(String backupName, Stri if (block.isEmpty()) { continue; } - LOG.debug(String.format("Found restore points from [backupName: %s, vmInternalName: %s] which is: [%s].", backupName, vmInternalName, block)); + logger.debug(String.format("Found restore points from [backupName: %s, vmInternalName: %s] which is: [%s].", backupName, vmInternalName, block)); final String[] parts = block.split("\r\n"); restorePoints.add(getRestorePointFromBlock(parts)); } @@ -868,14 +869,14 @@ public List listRestorePoints(String backupName, String vmI } public List listVmRestorePointsViaVeeamAPI(String vmInternalName) { - LOG.debug(String.format("Trying to list VM restore points via Veeam B&R API for VM %s: ", vmInternalName)); + logger.debug(String.format("Trying to list VM restore points via Veeam B&R API for VM %s: ", vmInternalName)); try { final HttpResponse response = get(String.format("/vmRestorePoints?format=Entity")); checkResponseOK(response); return processHttpResponseForVmRestorePoints(response.getEntity().getContent(), vmInternalName); } catch (final IOException e) { - LOG.error("Failed to list VM restore points via Veeam B&R API due to:", e); + logger.error("Failed to list VM restore points via Veeam B&R API due to:", e); checkResponseTimeOut(e); } return new ArrayList<>(); @@ -890,7 +891,7 @@ public List processHttpResponseForVmRestorePoints(InputStre throw new CloudRuntimeException("Could not get VM restore points via Veeam B&R API"); } for (final VmRestorePoint vmRestorePoint : vmRestorePoints.getVmRestorePoints()) { - LOG.debug(String.format("Processing VM restore point Name=%s, VmDisplayName=%s for vm name=%s", + logger.debug(String.format("Processing VM restore point Name=%s, VmDisplayName=%s for vm name=%s", vmRestorePoint.getName(), vmRestorePoint.getVmDisplayName(), vmInternalName)); if (!vmInternalName.equals(vmRestorePoint.getVmDisplayName())) { continue; @@ -899,7 +900,7 @@ public List processHttpResponseForVmRestorePoints(InputStre List links = vmRestorePoint.getLink(); for (Link link : links) { if (Arrays.asList(BACKUP_FILE_REFERENCE, RESTORE_POINT_REFERENCE).contains(link.getType()) && !link.getRel().equals("Up")) { - LOG.info(String.format("The VM restore point is not ready. Reference: %s, state: %s", link.getType(), link.getRel())); + logger.info(String.format("The VM restore point is not ready. Reference: %s, state: %s", link.getType(), link.getRel())); isReady = false; break; } @@ -910,11 +911,11 @@ public List processHttpResponseForVmRestorePoints(InputStre String vmRestorePointId = vmRestorePoint.getUid().substring(vmRestorePoint.getUid().lastIndexOf(':') + 1); Date created = formatDate(vmRestorePoint.getCreationTimeUtc()); String type = vmRestorePoint.getPointType(); - LOG.debug(String.format("Adding restore point %s, %s, %s", vmRestorePointId, created, type)); + logger.debug(String.format("Adding restore point %s, %s, %s", vmRestorePointId, created, type)); vmRestorePointList.add(new Backup.RestorePoint(vmRestorePointId, created, type)); } } catch (final IOException | ParseException e) { - LOG.error("Failed to process response to get VM restore points via Veeam B&R API due to:", e); + logger.error("Failed to process response to get VM restore points via Veeam B&R API due to:", e); checkResponseTimeOut(e); } return vmRestorePointList; @@ -948,7 +949,7 @@ public Pair restoreVMToDifferentLocation(String restorePointId, * @return the description found in Veeam about the cause of error in the restore process. */ protected String getRestoreVmErrorDescription(String uid) { - LOG.debug(String.format("Trying to find the cause of error in the restore process [%s].", uid)); + logger.debug(String.format("Trying to find the cause of error in the restore process [%s].", uid)); List cmds = Arrays.asList( String.format("$restoreUid = '%s'", uid), "$restore = Get-VBRRestoreSession -Id $restoreUid", diff --git a/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java b/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java index 26b2449b0fe4..63d6896bb85c 100644 --- a/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java +++ b/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java @@ -38,6 +38,7 @@ import org.apache.cloudstack.backup.BackupOffering; import org.apache.cloudstack.backup.veeam.api.RestoreSession; import org.apache.http.HttpResponse; +import org.apache.logging.log4j.Logger; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -58,8 +59,6 @@ public class VeeamClientTest { private VeeamClient mockClient; private static final SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private VeeamClient mock = Mockito.mock(VeeamClient.class); - @Rule public WireMockRule wireMockRule = new WireMockRule(9399); @@ -72,6 +71,7 @@ public void setUp() throws Exception { .withBody(""))); client = new VeeamClient("http://localhost:9399/api/", 12, adminUsername, adminPassword, true, 60, 600, 5, 120); mockClient = Mockito.mock(VeeamClient.class); + mockClient.logger = Mockito.mock(Logger.class); Mockito.when(mockClient.getRepositoryNameFromJob(Mockito.anyString())).thenCallRealMethod(); Mockito.when(mockClient.getVeeamServerVersion()).thenCallRealMethod(); } @@ -175,35 +175,35 @@ public void checkIfRestoreSessionFinishedTestTimeoutException() throws IOExcepti @Test public void getRestoreVmErrorDescriptionTestFindErrorDescription() { Pair response = new Pair<>(true, "Example of error description found in Veeam."); - Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); - Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response); - String result = mock.getRestoreVmErrorDescription("uuid"); + Mockito.when(mockClient.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); + Mockito.when(mockClient.executePowerShellCommands(Mockito.any())).thenReturn(response); + String result = mockClient.getRestoreVmErrorDescription("uuid"); Assert.assertEquals("Example of error description found in Veeam.", result); } @Test public void getRestoreVmErrorDescriptionTestNotFindErrorDescription() { Pair response = new Pair<>(true, "Cannot find restore session with provided uid uuid"); - Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); - Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response); - String result = mock.getRestoreVmErrorDescription("uuid"); + Mockito.when(mockClient.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); + Mockito.when(mockClient.executePowerShellCommands(Mockito.any())).thenReturn(response); + String result = mockClient.getRestoreVmErrorDescription("uuid"); Assert.assertEquals("Cannot find restore session with provided uid uuid", result); } @Test public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsNull() { - Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); - Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(null); - String result = mock.getRestoreVmErrorDescription("uuid"); + Mockito.when(mockClient.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); + Mockito.when(mockClient.executePowerShellCommands(Mockito.any())).thenReturn(null); + String result = mockClient.getRestoreVmErrorDescription("uuid"); Assert.assertEquals("Failed to get the description of the failed restore session [uuid]. Please contact an administrator.", result); } @Test public void getRestoreVmErrorDescriptionTestWhenPowerShellOutputIsFalse() { Pair response = new Pair<>(false, null); - Mockito.when(mock.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); - Mockito.when(mock.executePowerShellCommands(Mockito.any())).thenReturn(response); - String result = mock.getRestoreVmErrorDescription("uuid"); + Mockito.when(mockClient.getRestoreVmErrorDescription("uuid")).thenCallRealMethod(); + Mockito.when(mockClient.executePowerShellCommands(Mockito.any())).thenReturn(response); + String result = mockClient.getRestoreVmErrorDescription("uuid"); Assert.assertEquals("Failed to get the description of the failed restore session [uuid]. Please contact an administrator.", result); } diff --git a/plugins/ca/root-ca/pom.xml b/plugins/ca/root-ca/pom.xml index 6d191d638f12..fe1fb006302b 100644 --- a/plugins/ca/root-ca/pom.xml +++ b/plugins/ca/root-ca/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManager.java b/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManager.java index fb5da50ce162..5ff036fef12f 100644 --- a/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManager.java +++ b/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManager.java @@ -27,13 +27,14 @@ import javax.net.ssl.X509TrustManager; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.certificate.dao.CrlDao; import org.apache.commons.lang3.StringUtils; public final class RootCACustomTrustManager implements X509TrustManager { - private static final Logger LOG = Logger.getLogger(RootCACustomTrustManager.class); + protected Logger logger = LogManager.getLogger(getClass()); private String clientAddress = "Unknown"; private boolean authStrictness = true; @@ -71,12 +72,12 @@ private void printCertificateChain(final X509Certificate[] certificates, final S builder.append("\n Issuer DN:" + certificate.getIssuerDN()); builder.append("\n Alternative Names:" + certificate.getSubjectAlternativeNames()); } - LOG.debug(builder.toString()); + logger.debug(builder.toString()); } @Override public void checkClientTrusted(final X509Certificate[] certificates, final String s) throws CertificateException { - if (LOG.isDebugEnabled()) { + if (logger.isDebugEnabled()) { printCertificateChain(certificates, s); } @@ -86,7 +87,7 @@ public void checkClientTrusted(final X509Certificate[] certificates, final Strin if (authStrictness && primaryClientCertificate == null) { throw new CertificateException("In strict auth mode, certificate(s) are expected from client:" + clientAddress); } else if (primaryClientCertificate == null) { - LOG.info("No certificate was received from client, but continuing since strict auth mode is disabled"); + logger.info("No certificate was received from client, but continuing since strict auth mode is disabled"); return; } @@ -95,7 +96,7 @@ public void checkClientTrusted(final X509Certificate[] certificates, final Strin if (serialNumber == null || crlDao.findBySerial(serialNumber) != null) { final String errorMsg = String.format("Client is using revoked certificate of serial=%x, subject=%s from address=%s", primaryClientCertificate.getSerialNumber(), primaryClientCertificate.getSubjectDN(), clientAddress); - LOG.error(errorMsg); + logger.error(errorMsg); exceptionMsg = (StringUtils.isEmpty(exceptionMsg)) ? errorMsg : (exceptionMsg + ". " + errorMsg); } @@ -105,7 +106,7 @@ public void checkClientTrusted(final X509Certificate[] certificates, final Strin } catch (final CertificateExpiredException | CertificateNotYetValidException e) { final String errorMsg = String.format("Client certificate has expired with serial=%x, subject=%s from address=%s", primaryClientCertificate.getSerialNumber(), primaryClientCertificate.getSubjectDN(), clientAddress); - LOG.error(errorMsg); + logger.error(errorMsg); if (!allowExpiredCertificate) { throw new CertificateException(errorMsg); } @@ -125,17 +126,17 @@ public void checkClientTrusted(final X509Certificate[] certificates, final Strin } if (!certMatchesOwnership) { final String errorMsg = "Certificate ownership verification failed for client: " + clientAddress; - LOG.error(errorMsg); + logger.error(errorMsg); exceptionMsg = (StringUtils.isEmpty(exceptionMsg)) ? errorMsg : (exceptionMsg + ". " + errorMsg); } if (authStrictness && StringUtils.isNotEmpty(exceptionMsg)) { throw new CertificateException(exceptionMsg); } - if (LOG.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (authStrictness) { - LOG.debug("Client/agent connection from ip=" + clientAddress + " has been validated and trusted."); + logger.debug("Client/agent connection from ip=" + clientAddress + " has been validated and trusted."); } else { - LOG.debug("Client/agent connection from ip=" + clientAddress + " accepted without certificate validation."); + logger.debug("Client/agent connection from ip=" + clientAddress + " accepted without certificate validation."); } } diff --git a/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java b/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java index 0ee504075d26..25c45ed2a102 100644 --- a/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java +++ b/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java @@ -65,7 +65,6 @@ import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.bouncycastle.asn1.pkcs.Attribute; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.x509.Extension; @@ -86,7 +85,6 @@ import com.cloud.utils.net.NetUtils; public final class RootCAProvider extends AdapterBase implements CAProvider, Configurable { - private static final Logger LOG = Logger.getLogger(RootCAProvider.class); public static final Integer caValidityYears = 30; public static final String caAlias = "root"; @@ -173,7 +171,7 @@ private Certificate generateCertificateUsingCsr(final String csr, final List domainNames, final List domainN try { return generateCertificateUsingCsr(csr, domainNames, ipAddresses, validityDays); } catch (final CertificateException | IOException | SignatureException | NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | OperatorCreationException e) { - LOG.error("Failed to generate certificate from CSR: ", e); + logger.error("Failed to generate certificate from CSR: ", e); throw new CloudRuntimeException("Failed to generate certificate using CSR due to:" + e.getMessage()); } } @@ -310,16 +308,16 @@ private int getCaValidityDays() { private boolean saveNewRootCAKeypair() { try { - LOG.debug("Generating root CA public/private keys"); + logger.debug("Generating root CA public/private keys"); final KeyPair keyPair = CertUtils.generateRandomKeyPair(2 * CAManager.CertKeySize.value()); if (!configDao.update(rootCAPublicKey.key(), rootCAPublicKey.category(), CertUtils.publicKeyToPem(keyPair.getPublic()))) { - LOG.error("Failed to save RootCA public key"); + logger.error("Failed to save RootCA public key"); } if (!configDao.update(rootCAPrivateKey.key(), rootCAPrivateKey.category(), CertUtils.privateKeyToPem(keyPair.getPrivate()))) { - LOG.error("Failed to save RootCA private key"); + logger.error("Failed to save RootCA private key"); } } catch (final NoSuchProviderException | NoSuchAlgorithmException | IOException e) { - LOG.error("Failed to generate/save RootCA private/public keys due to exception:", e); + logger.error("Failed to generate/save RootCA private/public keys due to exception:", e); } return loadRootCAKeyPair(); } @@ -329,16 +327,16 @@ private boolean saveNewRootCACertificate() { throw new CloudRuntimeException("Cannot issue self-signed root CA certificate as CA keypair is not initialized"); } try { - LOG.debug("Generating root CA certificate"); + logger.debug("Generating root CA certificate"); final X509Certificate rootCaCertificate = CertUtils.generateV3Certificate( null, caKeyPair, caKeyPair.getPublic(), rootCAIssuerDN.value(), CAManager.CertSignatureAlgorithm.value(), getCaValidityDays(), null, null); if (!configDao.update(rootCACertificate.key(), rootCACertificate.category(), CertUtils.x509CertificateToPem(rootCaCertificate))) { - LOG.error("Failed to update RootCA public/x509 certificate"); + logger.error("Failed to update RootCA public/x509 certificate"); } } catch (final CertificateException | NoSuchAlgorithmException | NoSuchProviderException | SignatureException | InvalidKeyException | OperatorCreationException | IOException e) { - LOG.error("Failed to generate RootCA certificate from private/public keys due to exception:", e); + logger.error("Failed to generate RootCA certificate from private/public keys due to exception:", e); return false; } return loadRootCACertificate(); @@ -351,7 +349,7 @@ private boolean loadRootCAKeyPair() { try { caKeyPair = new KeyPair(CertUtils.pemToPublicKey(rootCAPublicKey.value()), CertUtils.pemToPrivateKey(rootCAPrivateKey.value())); } catch (InvalidKeySpecException | IOException e) { - LOG.error("Failed to load saved RootCA private/public keys due to exception:", e); + logger.error("Failed to load saved RootCA private/public keys due to exception:", e); return false; } return caKeyPair.getPrivate() != null && caKeyPair.getPublic() != null; @@ -365,7 +363,7 @@ private boolean loadRootCACertificate() { caCertificate = CertUtils.pemToX509Certificate(rootCACertificate.value()); caCertificate.verify(caKeyPair.getPublic()); } catch (final IOException | CertificateException | NoSuchAlgorithmException | InvalidKeyException | SignatureException | NoSuchProviderException e) { - LOG.error("Failed to load saved RootCA certificate due to exception:", e); + logger.error("Failed to load saved RootCA certificate due to exception:", e); return false; } return caCertificate != null; @@ -387,7 +385,7 @@ private boolean loadManagementKeyStore() { if (serverCertificate == null || serverCertificate.getPrivateKey() == null) { throw new CloudRuntimeException("Failed to generate management server certificate and load management server keystore"); } - LOG.info("Creating new management server certificate and keystore"); + logger.info("Creating new management server certificate and keystore"); try { managementKeyStore = KeyStore.getInstance("JKS"); managementKeyStore.load(null, null); @@ -395,7 +393,7 @@ private boolean loadManagementKeyStore() { managementKeyStore.setKeyEntry(managementAlias, serverCertificate.getPrivateKey(), getKeyStorePassphrase(), new X509Certificate[]{serverCertificate.getClientCertificate(), caCertificate}); } catch (final CertificateException | NoSuchAlgorithmException | KeyStoreException | IOException e) { - LOG.error("Failed to load root CA management-server keystore due to exception: ", e); + logger.error("Failed to load root CA management-server keystore due to exception: ", e); return false; } return managementKeyStore != null; @@ -404,20 +402,20 @@ private boolean loadManagementKeyStore() { protected void addConfiguredManagementIp(List ipList) { String msNetworkCidr = configDao.getValue(Config.ManagementNetwork.key()); try { - LOG.debug(String.format("Trying to find management IP in CIDR range [%s].", msNetworkCidr)); + logger.debug(String.format("Trying to find management IP in CIDR range [%s].", msNetworkCidr)); Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.asIterator().forEachRemaining(networkInterface -> { networkInterface.getInetAddresses().asIterator().forEachRemaining(inetAddress -> { if (NetUtils.isIpWithInCidrRange(inetAddress.getHostAddress(), msNetworkCidr)) { ipList.add(inetAddress.getHostAddress()); - LOG.debug(String.format("Added IP [%s] to the list of IPs in the management server's certificate.", inetAddress.getHostAddress())); + logger.debug(String.format("Added IP [%s] to the list of IPs in the management server's certificate.", inetAddress.getHostAddress())); } }); }); } catch (SocketException e) { String msg = "Exception while trying to gather the management server's network interfaces."; - LOG.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg, e); } } @@ -425,15 +423,15 @@ protected void addConfiguredManagementIp(List ipList) { private boolean setupCA() { if (!loadRootCAKeyPair() && !saveNewRootCAKeypair()) { - LOG.error("Failed to save and load root CA keypair"); + logger.error("Failed to save and load root CA keypair"); return false; } if (!loadRootCACertificate() && !saveNewRootCACertificate()) { - LOG.error("Failed to save and load root CA certificate"); + logger.error("Failed to save and load root CA certificate"); return false; } if (!loadManagementKeyStore()) { - LOG.error("Failed to check and configure management server keystore"); + logger.error("Failed to check and configure management server keystore"); return false; } return true; @@ -458,7 +456,7 @@ public boolean configure(String name, Map params) throws Configu caLock.unlock(); } } else { - LOG.error("Failed to grab lock and setup CA, startup method will try to load the CA certificate and keypair."); + logger.error("Failed to grab lock and setup CA, startup method will try to load the CA certificate and keypair."); } } finally { caLock.releaseRef(); diff --git a/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java b/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java index f879f056372f..d4ded3023321 100644 --- a/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java +++ b/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java @@ -34,7 +34,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.certificate.CrlVO; import com.cloud.certificate.dao.CrlDao; diff --git a/plugins/database/mysql-ha/pom.xml b/plugins/database/mysql-ha/pom.xml index 242323ca6704..37a07784341e 100644 --- a/plugins/database/mysql-ha/pom.xml +++ b/plugins/database/mysql-ha/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/database/mysql-ha/src/main/java/com/cloud/utils/db/StaticStrategy.java b/plugins/database/mysql-ha/src/main/java/com/cloud/utils/db/StaticStrategy.java index 469e58be5177..a72d6968f735 100644 --- a/plugins/database/mysql-ha/src/main/java/com/cloud/utils/db/StaticStrategy.java +++ b/plugins/database/mysql-ha/src/main/java/com/cloud/utils/db/StaticStrategy.java @@ -23,7 +23,8 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.mysql.cj.jdbc.ConnectionImpl; import com.mysql.cj.jdbc.JdbcConnection; @@ -32,7 +33,7 @@ import com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy; public class StaticStrategy implements BalanceStrategy { - private static final Logger s_logger = Logger.getLogger(StaticStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); public StaticStrategy() { } @@ -84,7 +85,7 @@ public JdbcConnection pickConnection(InvocationHandler proxy, List confi try { Thread.sleep(250); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while fail over in progres."); + logger.debug("[ignored] interrupted while fail over in progres."); } // start fresh diff --git a/plugins/database/quota/pom.xml b/plugins/database/quota/pom.xml index d00ca7fe3a52..b574b263020b 100644 --- a/plugins/database/quota/pom.xml +++ b/plugins/database/quota/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -62,5 +62,10 @@ joda-time ${cs.joda-time.version} + + org.apache.cloudstack + cloud-plugin-api-discovery + ${project.version} + diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java index f4e248855fd0..218e3c2b2f91 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseCmd; @@ -36,7 +35,6 @@ @APICommand(name = "quotaBalance", responseObject = QuotaStatementItemResponse.class, description = "Create a quota balance statement", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaBalanceCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaBalanceCmd.class); @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which statement needs to be generated") @@ -45,10 +43,12 @@ public class QuotaBalanceCmd extends BaseCmd { @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "If domain Id is given and the caller is domain admin then the statement is generated for domain.") private Long domainId; - @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "End date range for quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.") + @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "End of the period of the Quota balance." + + ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS) private Date endDate; - @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "Start date range quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.") + @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "Start of the period of the Quota balance. " + + ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS) private Date startDate; @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account") diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaConfigureEmailCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaConfigureEmailCmd.java new file mode 100644 index 000000000000..01d9ffc15295 --- /dev/null +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaConfigureEmailCmd.java @@ -0,0 +1,79 @@ +//Licensed to the Apache Software Foundation (ASF) under one +//or more contributor license agreements. See the NOTICE file +//distributed with this work for additional information +//regarding copyright ownership. The ASF licenses this file +//to you under the Apache License, Version 2.0 (the +//"License"); you may not use this file except in compliance +//with the License. You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, +//software distributed under the License is distributed on an +//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +//KIND, either express or implied. See the License for the +//specific language governing permissions and limitations +//under the License. +package org.apache.cloudstack.api.command; + +import com.cloud.utils.Pair; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.QuotaConfigureEmailResponse; +import org.apache.cloudstack.api.response.QuotaResponseBuilder; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; + +import javax.inject.Inject; + +@APICommand(name = "quotaConfigureEmail", responseObject = QuotaConfigureEmailResponse.class, description = "Configure a quota email template", since = "4.20.0.0", + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class QuotaConfigureEmailCmd extends BaseCmd { + + @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, required = true, + description = "Account ID for which to configure quota template email or min balance") + private long accountId; + + @Parameter(name = ApiConstants.TEMPLATE_NAME, type = CommandType.STRING, description = "Quota email template name which should be configured") + private String templateName; + + @Parameter(name = ApiConstants.ENABLE, type = CommandType.BOOLEAN, description = "If the quota email template should be enabled") + private Boolean enable; + + @Parameter(name = "minbalance", type = CommandType.DOUBLE, description = "New quota account min balance") + private Double minBalance; + + @Inject + private QuotaResponseBuilder responseBuilder; + + @Override + public void execute() { + Pair result = responseBuilder.configureQuotaEmail(this); + QuotaConfigureEmailResponse quotaConfigureEmailResponse = responseBuilder.createQuotaConfigureEmailResponse(result.first(), result.second(), accountId); + quotaConfigureEmailResponse.setResponseName(getCommandName()); + this.setResponseObject(quotaConfigureEmailResponse); + } + + @Override + public long getEntityOwnerId() { + return accountId; + } + + public long getAccountId() { + return accountId; + } + + public String getTemplateName() { + return templateName; + } + + public Boolean getEnable() { + return enable; + } + + public Double getMinBalance() { + return minBalance; + } +} diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java index c47c0ad2d763..8ca29f275ddd 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.QuotaService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -42,7 +41,6 @@ public class QuotaCreditsCmd extends BaseCmd { @Inject QuotaService _quotaService; - public static final Logger s_logger = Logger.getLogger(QuotaStatementCmd.class); @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which quota credits need to be added") diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java index 3cca09c909ec..c7f39037934f 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java @@ -22,13 +22,11 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.QuotaEmailTemplateResponse; import org.apache.cloudstack.api.response.QuotaResponseBuilder; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = "quotaEmailTemplateList", responseObject = QuotaEmailTemplateResponse.class, description = "Lists all quota email templates", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaEmailTemplateListCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(QuotaEmailTemplateListCmd.class); @Inject QuotaResponseBuilder _quotaResponseBuilder; diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java index 36d09864e548..17e7c220d2e6 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java @@ -25,14 +25,12 @@ import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.quota.constant.QuotaConfig; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.Arrays; @APICommand(name = "quotaEmailTemplateUpdate", responseObject = SuccessResponse.class, description = "Updates existing email templates for quota alerts", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaEmailTemplateUpdateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaEmailTemplateUpdateCmd.class); @Inject QuotaResponseBuilder _quotaResponseBuilder; diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java index ad6f12e9cc64..4035a5205e6c 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.response.QuotaEnabledResponse; import org.apache.cloudstack.quota.QuotaService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -30,7 +29,6 @@ @APICommand(name = "quotaIsEnabled", responseObject = QuotaEnabledResponse.class, description = "Return true if the plugin is enabled", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaEnabledCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaEnabledCmd.class); @Inject diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaListEmailConfigurationCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaListEmailConfigurationCmd.java new file mode 100644 index 000000000000..8915158461f8 --- /dev/null +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaListEmailConfigurationCmd.java @@ -0,0 +1,54 @@ +//Licensed to the Apache Software Foundation (ASF) under one +//or more contributor license agreements. See the NOTICE file +//distributed with this work for additional information +//regarding copyright ownership. The ASF licenses this file +//to you under the Apache License, Version 2.0 (the +//"License"); you may not use this file except in compliance +//with the License. You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, +//software distributed under the License is distributed on an +//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +//KIND, either express or implied. See the License for the +//specific language governing permissions and limitations +//under the License. +package org.apache.cloudstack.api.command; + +import com.cloud.user.Account; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.QuotaConfigureEmailResponse; +import org.apache.cloudstack.api.response.QuotaResponseBuilder; + +import javax.inject.Inject; + +@APICommand(name = "quotaListEmailConfiguration", responseObject = QuotaConfigureEmailResponse.class, description = "List quota email template configurations", since = "4.20.0.0", + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class QuotaListEmailConfigurationCmd extends BaseCmd { + + @Parameter(name = ApiConstants.ACCOUNT_ID, type = BaseCmd.CommandType.UUID, entityType = AccountResponse.class, required = true, + description = "Account ID for which to list quota template email configurations") + private long accountId; + + @Inject + private QuotaResponseBuilder responseBuilder; + + @Override + public void execute() { + ListResponse response = new ListResponse<>(); + response.setResponses(responseBuilder.listEmailConfiguration(accountId)); + response.setResponseName(getCommandName()); + setResponseObject(response); + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaPresetVariablesListCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaPresetVariablesListCmd.java new file mode 100644 index 000000000000..8de16dd2741e --- /dev/null +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaPresetVariablesListCmd.java @@ -0,0 +1,66 @@ +//Licensed to the Apache Software Foundation (ASF) under one +//or more contributor license agreements. See the NOTICE file +//distributed with this work for additional information +//regarding copyright ownership. The ASF licenses this file +//to you under the Apache License, Version 2.0 (the +//"License"); you may not use this file except in compliance +//with the License. You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, +//software distributed under the License is distributed on an +//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +//KIND, either express or implied. See the License for the +//specific language governing permissions and limitations +//under the License. +package org.apache.cloudstack.api.command; + +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.QuotaPresetVariablesItemResponse; +import org.apache.cloudstack.api.response.QuotaResponseBuilder; +import org.apache.cloudstack.quota.constant.QuotaTypes; + +import javax.inject.Inject; +import java.util.List; + +@APICommand(name = "quotaPresetVariablesList", responseObject = QuotaPresetVariablesItemResponse.class, description = "List the preset variables available for using in the " + + "Quota tariff activation rules given the usage type.", since = "4.20", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class QuotaPresetVariablesListCmd extends BaseCmd { + + @Inject + QuotaResponseBuilder quotaResponseBuilder; + + @Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, required = true, description = "The usage type for which the preset variables will be retrieved.") + private Integer quotaType; + + @Override + public void execute() { + List responses = quotaResponseBuilder.listQuotaPresetVariables(this); + ListResponse listResponse = new ListResponse<>(); + listResponse.setResponses(responses); + listResponse.setResponseName(getCommandName()); + setResponseObject(listResponse); + } + + public QuotaTypes getQuotaType() { + QuotaTypes quotaTypes = QuotaTypes.getQuotaType(quotaType); + + if (quotaTypes == null) { + throw new InvalidParameterValueException(String.format("Usage type not found for value [%s].", quotaType)); + } + + return quotaTypes; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java index 4d1c233c37a3..4fb33f79672e 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java @@ -31,14 +31,12 @@ import org.apache.cloudstack.api.response.QuotaStatementItemResponse; import org.apache.cloudstack.api.response.QuotaStatementResponse; import org.apache.cloudstack.quota.vo.QuotaUsageVO; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = "quotaStatement", responseObject = QuotaStatementItemResponse.class, description = "Create a quota statement", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaStatementCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaStatementCmd.class); @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Optional, Account Id for which statement needs to be generated") @@ -47,10 +45,12 @@ public class QuotaStatementCmd extends BaseCmd { @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "Optional, If domain Id is given and the caller is domain admin then the statement is generated for domain.") private Long domainId; - @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = true, description = "End date range for quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.") + @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = true, description = "End of the period of the Quota statement. " + + ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS) private Date endDate; - @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "Start date range quota query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.") + @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = true, description = "Start of the period of the Quota statement. " + + ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS) private Date startDate; @Parameter(name = ApiConstants.TYPE, type = CommandType.INTEGER, description = "List quota usage records for the specified usage type") diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java index 9236be1e0f8a..a1ef9b3746a5 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaSummaryResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import java.util.List; @@ -36,7 +35,6 @@ @APICommand(name = "quotaSummary", responseObject = QuotaSummaryResponse.class, description = "Lists balance and quota usage for all accounts", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaSummaryCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(QuotaSummaryCmd.class); @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = false, description = "Optional, Account Id for which statement needs to be generated") private String accountName; diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java index ea2edc3506d5..f1fd4b4afe12 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.QuotaTariffResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.vo.QuotaTariffVO; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -39,7 +38,6 @@ @APICommand(name = "quotaTariffCreate", responseObject = QuotaTariffResponse.class, description = "Creates a quota tariff for a resource.", since = "4.18.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class QuotaTariffCreateCmd extends BaseCmd { - protected Logger logger = Logger.getLogger(getClass()); @Inject QuotaResponseBuilder responseBuilder; @@ -56,20 +54,20 @@ public class QuotaTariffCreateCmd extends BaseCmd { @Parameter(name = "value", type = CommandType.DOUBLE, required = true, description = "The quota tariff value of the resource as per the default unit.") private Double value; - @Parameter(name = ApiConstants.ACTIVATION_RULE, type = CommandType.STRING, description = "Quota tariff's activation rule. It can receive a JS script that results in either " + - "a boolean or a numeric value: if it results in a boolean value, the tariff value will be applied according to the result; if it results in a numeric value, the " + - "numeric value will be applied; if the result is neither a boolean nor a numeric value, the tariff will not be applied. If the rule is not informed, the tariff " + - "value will be applied.", length = 65535) + @Parameter(name = ApiConstants.ACTIVATION_RULE, type = CommandType.STRING, description = ApiConstants.PARAMETER_DESCRIPTION_ACTIVATION_RULE, length = 65535) private String activationRule; - @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The effective start date on/after which the quota tariff is effective. Use yyyy-MM-dd as" - + " the date format, e.g. startDate=2009-06-03. Inform null to use the current date.") + @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The effective start date on/after which the quota tariff is effective. Inform null to " + + "use the current date. " + ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS) private Date startDate; - @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. Use yyyy-MM-dd as the date format, e.g." - + " endDate=2009-06-03.") + @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. If not informed, the tariff will be valid indefinitely. " + + ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS) private Date endDate; + @Parameter(name = ApiConstants.POSITION, type = CommandType.INTEGER, description = "Position in the execution sequence for tariffs of the same type", since = "4.20.0.0") + private Integer position; + @Override public void execute() { CallContext.current().setEventDetails(String.format("Tariff: %s, description: %s, value: %s", getName(), getDescription(), getValue())); @@ -79,7 +77,7 @@ public void execute() { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create new quota tariff."); } - QuotaTariffResponse response = responseBuilder.createQuotaTariffResponse(result); + QuotaTariffResponse response = responseBuilder.createQuotaTariffResponse(result, true); response.setResponseName(getCommandName()); setResponseObject(response); } @@ -141,4 +139,13 @@ public void setEndDate(Date endDate) { public ApiCommandResourceType getApiResourceType() { return ApiCommandResourceType.QuotaTariff; } + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } + + } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java index 6c2aa5866d72..7810760c56e7 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java @@ -29,14 +29,12 @@ import org.apache.cloudstack.api.response.QuotaTariffResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = "quotaTariffDelete", description = "Marks a quota tariff as removed.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0.0", authorized = {RoleType.Admin}) public class QuotaTariffDeleteCmd extends BaseCmd { - protected Logger logger = Logger.getLogger(getClass()); @Inject QuotaResponseBuilder responseBuilder; diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java index b79fd3d9aa82..d054d5459313 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java @@ -17,18 +17,20 @@ package org.apache.cloudstack.api.command; import com.cloud.user.Account; +import com.cloud.user.User; import com.cloud.utils.Pair; import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiArgValidator; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaTariffResponse; +import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -38,7 +40,6 @@ @APICommand(name = "quotaTariffList", responseObject = QuotaTariffResponse.class, description = "Lists all quota tariff plans", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaTariffListCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(QuotaTariffListCmd.class); @Inject QuotaResponseBuilder _responseBuilder; @@ -46,35 +47,44 @@ public class QuotaTariffListCmd extends BaseListCmd { @Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, description = "Usage type of the resource") private Integer usageType; - @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The start date of the quota tariff. Use yyyy-MM-dd as the date format, " - + "e.g. startDate=2009-06-03.") + @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "The start date of the quota tariff. " + + ApiConstants.PARAMETER_DESCRIPTION_START_DATE_POSSIBLE_FORMATS) private Date effectiveDate; - @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. Use yyyy-MM-dd as the date format, e.g. " - + "endDate=2021-11-03.", since = "4.18.0.0") + @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. " + + ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS, since = "4.18.0.0") private Date endDate; @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The name of the quota tariff.", since = "4.18.0.0") private String name; - @Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "False will list only not removed quota tariffs. If set to True, we will " + @Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "False will list only not removed quota tariffs. If set to true, we will " + "list all, including the removed ones. The default is false.", since = "4.18.0.0") private boolean listAll = false; - public QuotaTariffListCmd() { - super(); - } + @Parameter(name = ApiConstants.LIST_ONLY_REMOVED, type = CommandType.BOOLEAN, description = "If set to true, we will list only the removed tariffs." + + " The default is false.") + private boolean listOnlyRemoved = false; + + @Parameter(name = ApiConstants.ID, type = CommandType.STRING, description = "The quota tariff's id.", validations = {ApiArgValidator.UuidString}) + private String id; @Override public void execute() { final Pair, Integer> result = _responseBuilder.listQuotaTariffPlans(this); + User user = CallContext.current().getCallingUser(); + boolean returnActivationRules = _responseBuilder.isUserAllowedToSeeActivationRules(user); + if (!returnActivationRules) { + logger.debug("User [{}] does not have permission to create or update quota tariffs, therefore we will not return the activation rules.", user.getUuid()); + } + final List responses = new ArrayList<>(); - s_logger.trace(String.format("Adding quota tariffs [%s] to response of API quotaTariffList.", ReflectionToStringBuilderUtils.reflectCollection(responses))); + logger.trace("Adding quota tariffs [{}] to response of API quotaTariffList.", ReflectionToStringBuilderUtils.reflectCollection(responses)); for (final QuotaTariffVO resource : result.first()) { - responses.add(_responseBuilder.createQuotaTariffResponse(resource)); + responses.add(_responseBuilder.createQuotaTariffResponse(resource, returnActivationRules)); } final ListResponse response = new ListResponse<>(); @@ -108,4 +118,15 @@ public boolean isListAll() { return listAll; } + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public boolean isListOnlyRemoved() { + return listOnlyRemoved; + } } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java index 0bec1a63dcbe..b57668755075 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.QuotaTariffResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.vo.QuotaTariffVO; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -39,7 +38,6 @@ @APICommand(name = "quotaTariffUpdate", responseObject = QuotaTariffResponse.class, description = "Update the tariff plan for a resource", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class QuotaTariffUpdateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaTariffUpdateCmd.class); @Inject QuotaResponseBuilder _responseBuilder; @@ -54,8 +52,8 @@ public class QuotaTariffUpdateCmd extends BaseCmd { "Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.") private Date startDate; - @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. Use yyyy-MM-dd as the date format, e.g." - + " endDate=2009-06-03.", since = "4.18.0.0") + @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, description = "The end date of the quota tariff. " + + ApiConstants.PARAMETER_DESCRIPTION_END_DATE_POSSIBLE_FORMATS, since = "4.18.0.0") private Date endDate; @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "Quota tariff's name", length = 65535, since = "4.18.0.0") @@ -65,12 +63,13 @@ public class QuotaTariffUpdateCmd extends BaseCmd { since = "4.18.0.0") private String description; - @Parameter(name = ApiConstants.ACTIVATION_RULE, type = CommandType.STRING, description = "Quota tariff's activation rule. It can receive a JS script that results in either " + - "a boolean or a numeric value: if it results in a boolean value, the tariff value will be applied according to the result; if it results in a numeric value, the " + - "numeric value will be applied; if the result is neither a boolean nor a numeric value, the tariff will not be applied. If the rule is not informed, the tariff " + - "value will be applied. Inform empty to remove the activation rule.", length = 65535, since = "4.18.0.0") + @Parameter(name = ApiConstants.ACTIVATION_RULE, type = CommandType.STRING, description = ApiConstants.PARAMETER_DESCRIPTION_ACTIVATION_RULE + + " Inform empty to remove the activation rule.", length = 65535, since = "4.18.0.0") private String activationRule; + @Parameter(name = ApiConstants.POSITION, type = CommandType.INTEGER, description = "Position in the execution sequence for tariffs of the same type", since = "4.20.0.0") + private Integer position; + public Integer getUsageType() { return usageType; } @@ -118,7 +117,7 @@ public void execute() { if (result == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update quota tariff plan"); } - final QuotaTariffResponse response = _responseBuilder.createQuotaTariffResponse(result); + final QuotaTariffResponse response = _responseBuilder.createQuotaTariffResponse(result, true); response.setResponseName(getCommandName()); setResponseObject(response); } @@ -132,4 +131,13 @@ public long getEntityOwnerId() { public ApiCommandResourceType getApiResourceType() { return ApiCommandResourceType.QuotaTariff; } + + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } + } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaUpdateCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaUpdateCmd.java index 6f0e70c66e8a..986b2d4ce981 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaUpdateCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaUpdateCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.quota.QuotaAlertManager; import org.apache.cloudstack.quota.QuotaManager; import org.apache.cloudstack.quota.QuotaStatement; -import org.apache.log4j.Logger; import java.util.Calendar; @@ -33,7 +32,6 @@ @APICommand(name = "quotaUpdate", responseObject = QuotaUpdateResponse.class, description = "Update quota calculations, alerts and statements", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaUpdateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaUpdateCmd.class); @Inject diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaConfigureEmailResponse.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaConfigureEmailResponse.java new file mode 100644 index 000000000000..4f84a2c28283 --- /dev/null +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaConfigureEmailResponse.java @@ -0,0 +1,78 @@ +//Licensed to the Apache Software Foundation (ASF) under one +//or more contributor license agreements. See the NOTICE file +//distributed with this work for additional information +//regarding copyright ownership. The ASF licenses this file +//to you under the Apache License, Version 2.0 (the +//"License"); you may not use this file except in compliance +//with the License. You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, +//software distributed under the License is distributed on an +//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +//KIND, either express or implied. See the License for the +//specific language governing permissions and limitations +//under the License. +package org.apache.cloudstack.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.BaseResponse; + + +public class QuotaConfigureEmailResponse extends BaseResponse { + + @SerializedName("account") + @Param(description = "The configured account's id.") + private String accountId; + + @SerializedName("templatename") + @Param(description = "The template's name.") + private String templateName; + + @SerializedName("enabled") + @Param(description = "Whether the template is enabled.") + private Boolean enabled; + + @SerializedName("minbalance") + @Param(description = "The configured account's min balance.") + private Double minBalance; + + public QuotaConfigureEmailResponse() { + super("quotaconfigureemail"); + setResponseName(""); + } + + public String getAccountId() { + return accountId; + } + + public void setAccountId(String accountId) { + this.accountId = accountId; + } + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public Double getMinBalance() { + return minBalance; + } + + public void setMinBalance(Double minBalance) { + this.minBalance = minBalance; + } +} diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaPresetVariablesItemResponse.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaPresetVariablesItemResponse.java new file mode 100644 index 000000000000..a1b80fd94ebf --- /dev/null +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaPresetVariablesItemResponse.java @@ -0,0 +1,47 @@ +//Licensed to the Apache Software Foundation (ASF) under one +//or more contributor license agreements. See the NOTICE file +//distributed with this work for additional information +//regarding copyright ownership. The ASF licenses this file +//to you under the Apache License, Version 2.0 (the +//"License"); you may not use this file except in compliance +//with the License. You may obtain a copy of the License at +// +//http://www.apache.org/licenses/LICENSE-2.0 +// +//Unless required by applicable law or agreed to in writing, +//software distributed under the License is distributed on an +//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +//KIND, either express or implied. See the License for the +//specific language governing permissions and limitations +//under the License. +package org.apache.cloudstack.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.BaseResponse; + +public class QuotaPresetVariablesItemResponse extends BaseResponse { + @SerializedName("variable") + @Param(description = "variable") + private String variable; + + @SerializedName("description") + @Param(description = "description") + private String description; + + public QuotaPresetVariablesItemResponse() { + super("variables"); + } + + public void setVariable(String variable) { + this.variable = variable; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilder.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilder.java index 36033043bcfd..c635551aeb58 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilder.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilder.java @@ -16,14 +16,18 @@ //under the License. package org.apache.cloudstack.api.response; +import com.cloud.user.User; import org.apache.cloudstack.api.command.QuotaBalanceCmd; +import org.apache.cloudstack.api.command.QuotaConfigureEmailCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; +import org.apache.cloudstack.api.command.QuotaPresetVariablesListCmd; import org.apache.cloudstack.api.command.QuotaStatementCmd; import org.apache.cloudstack.api.command.QuotaTariffCreateCmd; import org.apache.cloudstack.api.command.QuotaTariffListCmd; import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.cloudstack.quota.vo.QuotaUsageVO; @@ -38,7 +42,9 @@ public interface QuotaResponseBuilder { Pair, Integer> listQuotaTariffPlans(QuotaTariffListCmd cmd); - QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO configuration); + QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO quotaTariff, boolean returnActivationRule); + + boolean isUserAllowedToSeeActivationRules(User user); QuotaStatementResponse createQuotaStatementResponse(List quotaUsage); @@ -69,4 +75,17 @@ public interface QuotaResponseBuilder { QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd); boolean deleteQuotaTariff(String quotaTariffUuid); + + /** + * Lists the preset variables for the usage type informed in the command. + * @param cmd used to retrieve the Quota usage type parameter. + * @return the response consisting of a {@link List} of the preset variables and their descriptions. + */ + List listQuotaPresetVariables(QuotaPresetVariablesListCmd cmd); + + Pair configureQuotaEmail(QuotaConfigureEmailCmd cmd); + + QuotaConfigureEmailResponse createQuotaConfigureEmailResponse(QuotaEmailConfigurationVO quotaEmailConfigurationVO, Double minBalance, long accountId); + + List listEmailConfiguration(long accountId); } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java index d7171499b7c8..1c486759e43f 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java @@ -16,11 +16,15 @@ //under the License. package org.apache.cloudstack.api.response; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.time.ZoneId; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import java.util.Collections; @@ -31,38 +35,55 @@ import java.util.List; import java.util.ListIterator; import java.util.function.Consumer; +import java.util.stream.Collectors; import javax.inject.Inject; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.QuotaBalanceCmd; +import org.apache.cloudstack.api.command.QuotaConfigureEmailCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; +import org.apache.cloudstack.api.command.QuotaPresetVariablesListCmd; import org.apache.cloudstack.api.command.QuotaStatementCmd; import org.apache.cloudstack.api.command.QuotaTariffCreateCmd; import org.apache.cloudstack.api.command.QuotaTariffListCmd; import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd; import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.discovery.ApiDiscoveryService; import org.apache.cloudstack.quota.QuotaManager; +import org.apache.cloudstack.quota.QuotaManagerImpl; import org.apache.cloudstack.quota.QuotaService; import org.apache.cloudstack.quota.QuotaStatement; +import org.apache.cloudstack.quota.activationrule.presetvariables.ComputingResources; +import org.apache.cloudstack.quota.activationrule.presetvariables.GenericPresetVariable; +import org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariableDefinition; +import org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariables; +import org.apache.cloudstack.quota.activationrule.presetvariables.Value; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.quota.dao.QuotaAccountDao; import org.apache.cloudstack.quota.dao.QuotaBalanceDao; import org.apache.cloudstack.quota.dao.QuotaCreditsDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.dao.QuotaTariffDao; -import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; +import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; import org.apache.cloudstack.quota.vo.QuotaCreditsVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.cloudstack.quota.vo.QuotaUsageVO; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.domain.DomainVO; @@ -81,7 +102,7 @@ @Component public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { - private static final Logger s_logger = Logger.getLogger(QuotaResponseBuilderImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private QuotaTariffDao _quotaTariffDao; @@ -101,7 +122,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { @Inject private AccountDao _accountDao; @Inject - private QuotaAccountDao _quotaAccountDao; + private QuotaAccountDao quotaAccountDao; @Inject private DomainDao _domainDao; @Inject @@ -110,9 +131,16 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { private QuotaStatement _statement; @Inject private QuotaManager _quotaManager; + @Inject + private QuotaEmailConfigurationDao quotaEmailConfigurationDao; + + private final Class[] assignableClasses = {GenericPresetVariable.class, ComputingResources.class}; + + @Inject + private ApiDiscoveryService apiDiscoveryService; @Override - public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO tariff) { + public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO tariff, boolean returnActivationRule) { final QuotaTariffResponse response = new QuotaTariffResponse(); response.setUsageType(tariff.getUsageType()); response.setUsageName(tariff.getUsageName()); @@ -122,12 +150,15 @@ public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO tariff) { response.setEffectiveOn(tariff.getEffectiveOn()); response.setUsageTypeDescription(tariff.getUsageTypeDescription()); response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value()); - response.setActivationRule(tariff.getActivationRule()); response.setName(tariff.getName()); response.setEndDate(tariff.getEndDate()); response.setDescription(tariff.getDescription()); - response.setUuid(tariff.getUuid()); + response.setId(tariff.getUuid()); response.setRemoved(tariff.getRemoved()); + response.setPosition(tariff.getPosition()); + if (returnActivationRule) { + response.setActivationRule(tariff.getActivationRule()); + } return response; } @@ -162,7 +193,7 @@ public Pair, Integer> createQuotaSummaryResponse(Bool result.add(qr); } } else { - Pair, Integer> data = _quotaAccountDao.listAllQuotaAccount(startIndex, pageSize); + Pair, Integer> data = quotaAccountDao.listAllQuotaAccount(startIndex, pageSize); count = data.second(); for (final QuotaAccountVO quotaAccount : data.first()) { AccountVO account = _accountDao.findById(quotaAccount.getId()); @@ -203,6 +234,11 @@ protected QuotaSummaryResponse getQuotaSummaryResponse(final Account account) { } } + public boolean isUserAllowedToSeeActivationRules(User user) { + List apiList = (List) apiDiscoveryService.listApis(user, null).getResponses(); + return apiList.stream().anyMatch(response -> StringUtils.equalsAny(response.getName(), "quotaTariffCreate", "quotaTariffUpdate")); + } + @Override public QuotaBalanceResponse createQuotaBalanceResponse(List quotaBalance, Date startDate, Date endDate) { if (quotaBalance == null || quotaBalance.isEmpty()) { @@ -233,8 +269,8 @@ public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) { // Iterate in reverse. while (li.hasPrevious()) { QuotaBalanceVO entry = li.previous(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaBalanceResponse: Entry=" + entry); + if (logger.isDebugEnabled()) { + logger.debug("createQuotaBalanceResponse: Entry=" + entry); } if (entry.getCreditsId() > 0) { li.remove(); @@ -250,8 +286,8 @@ public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) { boolean consecutive = true; for (Iterator it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaBalanceResponse: All Credit Entry=" + entry); + if (logger.isDebugEnabled()) { + logger.debug("createQuotaBalanceResponse: All Credit Entry=" + entry); } if (entry.getCreditsId() > 0) { if (consecutive) { @@ -271,9 +307,9 @@ public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) { resp.setStartDate(startDate); resp.setStartQuota(startItem.getCreditBalance()); resp.setEndDate(endDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaBalanceResponse: Start Entry=" + startItem); - s_logger.debug("createQuotaBalanceResponse: End Entry=" + endItem); + if (logger.isDebugEnabled()) { + logger.debug("createQuotaBalanceResponse: Start Entry=" + startItem); + logger.debug("createQuotaBalanceResponse: End Entry=" + endItem); } resp.setEndQuota(endItem.getCreditBalance().add(lastCredits)); } else if (quota_activity > 0) { @@ -313,8 +349,8 @@ public QuotaStatementResponse createQuotaStatementResponse(final List, Integer> listQuotaTariffPlans(final QuotaTariff public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) { String name = cmd.getName(); Double value = cmd.getValue(); - Date endDate = _quotaService.computeAdjustedTime(cmd.getEndDate()); + Date endDate = cmd.getEndDate(); String description = cmd.getDescription(); String activationRule = cmd.getActivationRule(); - Date now = _quotaService.computeAdjustedTime(new Date()); + Date now = new Date(); + Integer position = cmd.getPosition(); warnQuotaTariffUpdateDeprecatedFields(cmd); @@ -405,7 +445,7 @@ public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) { currentQuotaTariff.setRemoved(now); QuotaTariffVO newQuotaTariff = persistNewQuotaTariff(currentQuotaTariff, name, 0, currentQuotaTariffStartDate, cmd.getEntityOwnerId(), endDate, value, description, - activationRule); + activationRule, position); _quotaTariffDao.updateQuotaTariff(currentQuotaTariff); CallContext.current().setEventResourceId(newQuotaTariff.getId()); @@ -417,16 +457,16 @@ protected void warnQuotaTariffUpdateDeprecatedFields(QuotaTariffUpdateCmd cmd) { String warnMessage = "The parameter 's%s' for API 'quotaTariffUpdate' is no longer needed and it will be removed in future releases."; if (cmd.getStartDate() != null) { - s_logger.warn(String.format(warnMessage,"startdate")); + logger.warn(String.format(warnMessage,"startdate")); } if (cmd.getUsageType() != null) { - s_logger.warn(String.format(warnMessage,"usagetype")); + logger.warn(String.format(warnMessage,"usagetype")); } } protected QuotaTariffVO persistNewQuotaTariff(QuotaTariffVO currentQuotaTariff, String name, int usageType, Date startDate, Long entityOwnerId, Date endDate, Double value, - String description, String activationRule) { + String description, String activationRule, Integer position) { QuotaTariffVO newQuotaTariff = getNewQuotaTariffObject(currentQuotaTariff, name, usageType); @@ -438,6 +478,7 @@ protected QuotaTariffVO persistNewQuotaTariff(QuotaTariffVO currentQuotaTariff, validateValueOnCreatingNewQuotaTariff(newQuotaTariff, value); validateStringsOnCreatingNewQuotaTariff(newQuotaTariff::setDescription, description); validateStringsOnCreatingNewQuotaTariff(newQuotaTariff::setActivationRule, activationRule); + validatePositionOnCreatingNewQuotaTariff(newQuotaTariff, position); _quotaTariffDao.addQuotaTariff(newQuotaTariff); return newQuotaTariff; @@ -458,6 +499,13 @@ protected QuotaTariffVO getNewQuotaTariffObject(QuotaTariffVO currentQuotaTariff return newQuotaTariff; } + protected void validatePositionOnCreatingNewQuotaTariff(QuotaTariffVO newQuotaTariff, Integer position) { + if (position != null) { + newQuotaTariff.setPosition(position); + } + } + + protected void validateStringsOnCreatingNewQuotaTariff(Consumer method, String value){ if (value != null) { method.accept(value.isBlank() ? null : value); @@ -476,12 +524,14 @@ protected void validateEndDateOnCreatingNewQuotaTariff(QuotaTariffVO newQuotaTar } if (endDate.compareTo(startDate) < 0) { - throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than the start date [%s]", endDate, startDate)); + throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than the start date [%s].", + endDate, startDate)); } - Date now = _quotaService.computeAdjustedTime(new Date()); + Date now = new Date(); if (endDate.compareTo(now) < 0) { - throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than now [%s].", endDate, now)); + throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than now [%s].", + endDate, now)); } newQuotaTariff.setEndDate(endDate); @@ -489,11 +539,12 @@ protected void validateEndDateOnCreatingNewQuotaTariff(QuotaTariffVO newQuotaTar @Override public QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Double amount, Long updatedBy, Boolean enforce) { - Date despositedOn = _quotaService.computeAdjustedTime(new Date()); + Date despositedOn = new Date(); QuotaBalanceVO qb = _quotaBalanceDao.findLaterBalanceEntry(accountId, domainId, despositedOn); if (qb != null) { - throw new InvalidParameterValueException("Incorrect deposit date: " + despositedOn + " there are balance entries after this date"); + throw new InvalidParameterValueException(String.format("Incorrect deposit date [%s], as there are balance entries after this date.", + despositedOn)); } QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, new BigDecimal(amount), updatedBy); @@ -506,20 +557,19 @@ public QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId, Doubl } final boolean lockAccountEnforcement = "true".equalsIgnoreCase(QuotaConfig.QuotaEnableEnforcement.value()); final BigDecimal currentAccountBalance = _quotaBalanceDao.lastQuotaBalance(accountId, domainId, startOfNextDay(new Date(despositedOn.getTime()))); - if (s_logger.isDebugEnabled()) { - s_logger.debug("AddQuotaCredits: Depositing " + amount + " on adjusted date " + despositedOn + ", current balance " + currentAccountBalance); - } + logger.debug("Depositing [{}] credits on adjusted date [{}]; current balance is [{}].", amount, + DateUtil.displayDateInTimezone(QuotaManagerImpl.getUsageAggregationTimeZone(), despositedOn), currentAccountBalance); // update quota account with the balance _quotaService.saveQuotaAccount(account, currentAccountBalance, despositedOn); if (lockAccountEnforcement) { if (currentAccountBalance.compareTo(new BigDecimal(0)) >= 0) { if (account.getState() == Account.State.LOCKED) { - s_logger.info("UnLocking account " + account.getAccountName() + " , due to positive balance " + currentAccountBalance); + logger.info("UnLocking account " + account.getAccountName() + " , due to positive balance " + currentAccountBalance); _accountMgr.enableAccount(account.getAccountName(), domainId, accountId); } } else { // currentAccountBalance < 0 then lock the account if (_quotaManager.isLockable(account) && account.getState() == Account.State.ENABLED && enforce) { - s_logger.info("Locking account " + account.getAccountName() + " , due to negative balance " + currentAccountBalance); + logger.info("Locking account " + account.getAccountName() + " , due to negative balance " + currentAccountBalance); _accountMgr.lockAccount(account.getAccountName(), domainId, accountId); } } @@ -587,9 +637,10 @@ public QuotaBalanceResponse createQuotaLastBalanceResponse(List QuotaBalanceResponse resp = new QuotaBalanceResponse(); BigDecimal lastCredits = new BigDecimal(0); for (QuotaBalanceVO entry : quotaBalance) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaLastBalanceResponse Date=" + entry.getUpdatedOn() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId()); - } + logger.debug("createQuotaLastBalanceResponse Date={} balance={} credit={}", + DateUtil.displayDateInTimezone(QuotaManagerImpl.getUsageAggregationTimeZone(), entry.getUpdatedOn()), + entry.getCreditBalance(), entry.getCreditsId()); + lastCredits = lastCredits.add(entry.getCreditBalance()); } resp.setStartQuota(lastCredits); @@ -632,11 +683,12 @@ public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) { int usageType = cmd.getUsageType(); Date startDate = cmd.getStartDate(); Date now = new Date(); - startDate = _quotaService.computeAdjustedTime(startDate == null ? now : startDate); - Date endDate = _quotaService.computeAdjustedTime(cmd.getEndDate()); + startDate = startDate == null ? now : startDate; + Date endDate = cmd.getEndDate(); Double value = cmd.getValue(); String description = cmd.getDescription(); String activationRule = cmd.getActivationRule(); + Integer position = ObjectUtils.defaultIfNull(cmd.getPosition(), 1); QuotaTariffVO currentQuotaTariff = _quotaTariffDao.findByName(name); @@ -645,10 +697,11 @@ public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) { } if (startDate.compareTo(now) < 0) { - throw new InvalidParameterValueException(String.format("The quota tariff's start date [%s] cannot be less than now [%s]", startDate, now)); + throw new InvalidParameterValueException(String.format("The value passed as Quota tariff's start date is in the past: [%s]. " + + "Please, inform a date in the future or do not pass the parameter to use the current date and time.", startDate)); } - QuotaTariffVO newQuotaTariff = persistNewQuotaTariff(null, name, usageType, startDate, cmd.getEntityOwnerId(), endDate, value, description, activationRule); + QuotaTariffVO newQuotaTariff = persistNewQuotaTariff(null, name, usageType, startDate, cmd.getEntityOwnerId(), endDate, value, description, activationRule, position); CallContext.current().setEventResourceId(newQuotaTariff.getId()); @@ -663,10 +716,216 @@ public boolean deleteQuotaTariff(String quotaTariffUuid) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Quota tariff with the provided UUID does not exist."); } - quotaTariff.setRemoved(_quotaService.computeAdjustedTime(new Date())); - + quotaTariff.setRemoved(new Date()); CallContext.current().setEventResourceId(quotaTariff.getId()); - return _quotaTariffDao.updateQuotaTariff(quotaTariff); } + + @Override + public List listQuotaPresetVariables(QuotaPresetVariablesListCmd cmd) { + List response; + List> variables = new ArrayList<>(); + + QuotaTypes quotaType = cmd.getQuotaType(); + addAllPresetVariables(PresetVariables.class, quotaType, variables, null); + response = createQuotaPresetVariablesResponse(variables); + + return response; + } + + /** + * Adds all preset variables for the given quota type. It recursively finds all presets variables for the given {@link Class} and puts it in a {@link List}. Each item in the + * list is a {@link Pair} that consists of the variable name and its description. + * + * @param clazz used to find the non-transient fields. If it is equal to the {@link Value} class, then it only gets the declared fields, otherwise, it gets all fields, + * including its parent's fields. + * @param quotaType used to check if the field supports the quota resource type. It uses the annotation method {@link PresetVariableDefinition#supportedTypes()} for this + * verification. + * @param variables the {@link List} which contains the {@link Pair} of the preset variable and its description. + * @param recursiveVariableName {@link String} used for recursively building the preset variable string. + */ + public void addAllPresetVariables(Class clazz, QuotaTypes quotaType, List> variables, String recursiveVariableName) { + Field[] allFields = Value.class.equals(clazz) ? clazz.getDeclaredFields() : FieldUtils.getAllFields(clazz); + List fieldsNonTransients = Arrays.stream(allFields).filter(field -> !Modifier.isTransient(field.getModifiers())).collect(Collectors.toList()); + for (Field field : fieldsNonTransients) { + PresetVariableDefinition presetVariableDefinitionAnnotation = field.getAnnotation(PresetVariableDefinition.class); + Class fieldClass = getClassOfField(field); + String presetVariableName = field.getName(); + + if (presetVariableDefinitionAnnotation == null) { + continue; + } + + if (StringUtils.isNotEmpty(recursiveVariableName)) { + presetVariableName = String.format("%s.%s", recursiveVariableName, field.getName()); + } + filterSupportedTypes(variables, quotaType, presetVariableDefinitionAnnotation, fieldClass, presetVariableName); + } + } + + /** + * Returns the class of the {@link Field} depending on its type. This method is required for retrieving the Class of Generic Types, i.e. {@link List}. + */ + protected Class getClassOfField(Field field){ + if (field.getGenericType() instanceof ParameterizedType) { + ParameterizedType genericType = (ParameterizedType) field.getGenericType(); + return (Class) genericType.getActualTypeArguments()[0]; + } + + return field.getType(); + } + + /** + * Checks if the {@link PresetVariableDefinition} supports the given {@link QuotaTypes}. If it supports it, it adds the preset variable to the {@link List} recursively + * if it is from the one of the classes in the {@link QuotaResponseBuilderImpl#assignableClasses} array or directly if not. + * + * @param variables {@link List} of the {@link Pair} of the preset variable and its description. + * @param quotaType the given {@link QuotaTypes} to filter. + * @param presetVariableDefinitionAnnotation used to check if the quotaType is supported. + * @param fieldClass class of the field used to verify if it is from the {@link GenericPresetVariable} or {@link ComputingResources} classes. If it is, then it calls + * {@link QuotaResponseBuilderImpl#addAllPresetVariables(Class, QuotaTypes, List, String)} to add the preset variable. Otherwise, the {@link Pair} is + * added directly to the variables {@link List}. + * @param presetVariableName {@link String} that contains the recursive created preset variable name. + */ + public void filterSupportedTypes(List> variables, QuotaTypes quotaType, PresetVariableDefinition presetVariableDefinitionAnnotation, Class fieldClass, + String presetVariableName) { + if (Arrays.stream(presetVariableDefinitionAnnotation.supportedTypes()).noneMatch(supportedType -> + supportedType == quotaType.getQuotaType() || supportedType == 0)) { + return; + } + + String presetVariableDescription = presetVariableDefinitionAnnotation.description(); + + Pair pair = new Pair<>(presetVariableName, presetVariableDescription); + variables.add(pair); + + if (isRecursivePresetVariable(fieldClass)) { + addAllPresetVariables(fieldClass, quotaType, variables, presetVariableName); + } + } + + /** + * Returns true if the {@link Class} of the {@link Field} is from one of the classes in the array {@link QuotaResponseBuilderImpl#assignableClasses}, i.e., it is a recursive + * {@link PresetVariables}, returns false otherwise. + */ + private boolean isRecursivePresetVariable(Class fieldClass) { + for (Class clazz : assignableClasses) { + if (clazz.isAssignableFrom(fieldClass)) { + return true; + } + } + return false; + } + + public List createQuotaPresetVariablesResponse(List> variables) { + final List responses = new ArrayList<>(); + + for (Pair variable : variables) { + responses.add(createPresetVariablesItemResponse(variable)); + } + + return responses; + } + + public QuotaPresetVariablesItemResponse createPresetVariablesItemResponse(Pair variable) { + QuotaPresetVariablesItemResponse response = new QuotaPresetVariablesItemResponse(); + response.setVariable(variable.first()); + response.setDescription(variable.second()); + return response; + } + + @Override + public Pair configureQuotaEmail(QuotaConfigureEmailCmd cmd) { + validateQuotaConfigureEmailCmdParameters(cmd); + + Double minBalance = cmd.getMinBalance(); + + if (minBalance != null) { + _quotaService.setMinBalance(cmd.getAccountId(), cmd.getMinBalance()); + } + + QuotaEmailConfigurationVO configurationVO = getQuotaEmailConfigurationVo(cmd); + return new Pair<>(configurationVO, minBalance); + } + + protected QuotaEmailConfigurationVO getQuotaEmailConfigurationVo(QuotaConfigureEmailCmd cmd) { + if (cmd.getTemplateName() == null) { + return null; + } + + List templateVO = _quotaEmailTemplateDao.listAllQuotaEmailTemplates(cmd.getTemplateName()); + if (templateVO.isEmpty()) { + throw new InvalidParameterValueException(String.format("Could not find template with name [%s].", cmd.getTemplateName())); + } + long templateId = templateVO.get(0).getId(); + QuotaEmailConfigurationVO configurationVO = quotaEmailConfigurationDao.findByAccountIdAndEmailTemplateId(cmd.getAccountId(), templateId); + + if (configurationVO == null) { + configurationVO = new QuotaEmailConfigurationVO(cmd.getAccountId(), templateId, cmd.getEnable()); + quotaEmailConfigurationDao.persistQuotaEmailConfiguration(configurationVO); + return configurationVO; + } + + configurationVO.setEnabled(cmd.getEnable()); + return quotaEmailConfigurationDao.updateQuotaEmailConfiguration(configurationVO); + } + + protected void validateQuotaConfigureEmailCmdParameters(QuotaConfigureEmailCmd cmd) { + if (quotaAccountDao.findByIdQuotaAccount(cmd.getAccountId()) == null) { + throw new InvalidParameterValueException("You must have the quota enabled for this account to configure quota emails."); + } + + if (cmd.getTemplateName() == null && cmd.getMinBalance() == null) { + throw new InvalidParameterValueException("You should inform at least the 'minbalance' or both the 'templatename' and 'enable' parameters."); + } + + if ((cmd.getTemplateName() != null && cmd.getEnable() == null) || (cmd.getTemplateName() == null && cmd.getEnable() != null)) { + throw new InvalidParameterValueException("Parameter 'enable' must be informed along with 'templatename'."); + } + } + + public QuotaConfigureEmailResponse createQuotaConfigureEmailResponse(QuotaEmailConfigurationVO quotaEmailConfigurationVO, Double minBalance, long accountId) { + QuotaConfigureEmailResponse quotaConfigureEmailResponse = new QuotaConfigureEmailResponse(); + + Account account = _accountDao.findByIdIncludingRemoved(accountId); + if (quotaEmailConfigurationVO != null) { + QuotaEmailTemplatesVO templateVO = _quotaEmailTemplateDao.findById(quotaEmailConfigurationVO.getEmailTemplateId()); + + quotaConfigureEmailResponse.setAccountId(account.getUuid()); + quotaConfigureEmailResponse.setTemplateName(templateVO.getTemplateName()); + quotaConfigureEmailResponse.setEnabled(quotaEmailConfigurationVO.isEnabled()); + } + + quotaConfigureEmailResponse.setMinBalance(minBalance); + + return quotaConfigureEmailResponse; + } + + @Override + public List listEmailConfiguration(long accountId) { + List emailConfigurationVOList = quotaEmailConfigurationDao.listByAccount(accountId); + Account account = _accountDao.findById(accountId); + QuotaAccountVO quotaAccountVO = quotaAccountDao.findByIdQuotaAccount(accountId); + + List quotaConfigureEmailResponseList = new ArrayList<>(); + for (QuotaEmailConfigurationVO quotaEmailConfigurationVO : emailConfigurationVOList) { + quotaConfigureEmailResponseList.add(createQuotaConfigureEmailResponse(quotaEmailConfigurationVO, account, quotaAccountVO)); + } + + return quotaConfigureEmailResponseList; + } + + protected QuotaConfigureEmailResponse createQuotaConfigureEmailResponse(QuotaEmailConfigurationVO quotaEmailConfigurationVO, Account account, QuotaAccountVO quotaAccountVO) { + QuotaConfigureEmailResponse quotaConfigureEmailResponse = new QuotaConfigureEmailResponse(); + + QuotaEmailTemplatesVO templateVO = _quotaEmailTemplateDao.findById(quotaEmailConfigurationVO.getEmailTemplateId()); + + quotaConfigureEmailResponse.setAccountId(account.getUuid()); + quotaConfigureEmailResponse.setTemplateName(templateVO.getTemplateName()); + quotaConfigureEmailResponse.setEnabled(quotaEmailConfigurationVO.isEnabled()); + + quotaConfigureEmailResponse.setMinBalance(quotaAccountVO.getQuotaMinBalance().doubleValue()); + + return quotaConfigureEmailResponse; + } } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaTariffResponse.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaTariffResponse.java index ce4c5953641d..6d844d78427a 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaTariffResponse.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaTariffResponse.java @@ -19,6 +19,7 @@ import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; import java.math.BigDecimal; @@ -74,28 +75,24 @@ public class QuotaTariffResponse extends BaseResponse { @Param(description = "description") private String description; - @SerializedName("uuid") - @Param(description = "uuid") - private String uuid; + @SerializedName(ApiConstants.ID) + @Param(description = "the ID of the tariff") + private String id; @SerializedName("removed") @Param(description = "when the quota tariff was removed") private Date removed; + @SerializedName("position") + @Param(description = "position in the execution sequence for tariffs of the same type") + private Integer position; + + public QuotaTariffResponse() { super(); this.setObjectName("quotatariff"); } - public QuotaTariffResponse(final int usageType) { - super(); - this.usageType = usageType; - } - - public String getUsageName() { - return usageName; - } - public void setUsageName(String usageName) { this.usageName = usageName; } @@ -108,18 +105,10 @@ public void setUsageType(int usageType) { this.usageType = usageType; } - public String getUsageUnit() { - return usageUnit; - } - public void setUsageUnit(String usageUnit) { this.usageUnit = usageUnit; } - public String getUsageDiscriminator() { - return usageDiscriminator; - } - public void setUsageDiscriminator(String usageDiscriminator) { this.usageDiscriminator = usageDiscriminator; } @@ -132,26 +121,14 @@ public void setTariffValue(BigDecimal tariffValue) { this.tariffValue = tariffValue; } - public String getUsageTypeDescription() { - return usageTypeDescription; - } - public void setUsageTypeDescription(String usageTypeDescription) { this.usageTypeDescription = usageTypeDescription; } - public Date getEffectiveOn() { - return effectiveOn; - } - public void setEffectiveOn(Date effectiveOn) { this.effectiveOn = effectiveOn; } - public String getCurrency() { - return currency; - } - public void setCurrency(String currency) { this.currency = currency; } @@ -188,20 +165,24 @@ public void setDescription(String description) { this.description = description; } - public String getUuid() { - return uuid; + public String getId() { + return id; } - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public Date getRemoved() { - return removed; + public void setId(String id) { + this.id = id; } public void setRemoved(Date removed) { this.removed = removed; } + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } + } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaService.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaService.java index fe634715d89e..8f3c34982c0b 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaService.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaService.java @@ -32,8 +32,6 @@ public interface QuotaService extends PluggableService { List findQuotaBalanceVO(Long accountId, String accountName, Long domainId, Date startDate, Date endDate); - Date computeAdjustedTime(Date date); - void setLockAccount(Long accountId, Boolean state); void setMinBalance(Long accountId, Double balance); diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java index 9179691e9732..17fa7bd8425e 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java @@ -18,7 +18,6 @@ import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; @@ -28,10 +27,13 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.command.QuotaBalanceCmd; +import org.apache.cloudstack.api.command.QuotaConfigureEmailCmd; import org.apache.cloudstack.api.command.QuotaCreditsCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; import org.apache.cloudstack.api.command.QuotaEnabledCmd; +import org.apache.cloudstack.api.command.QuotaListEmailConfigurationCmd; +import org.apache.cloudstack.api.command.QuotaPresetVariablesListCmd; import org.apache.cloudstack.api.command.QuotaStatementCmd; import org.apache.cloudstack.api.command.QuotaSummaryCmd; import org.apache.cloudstack.api.command.QuotaTariffCreateCmd; @@ -51,8 +53,7 @@ import org.apache.cloudstack.quota.vo.QuotaAccountVO; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; import org.apache.cloudstack.quota.vo.QuotaUsageVO; -import org.apache.cloudstack.utils.usage.UsageUtils; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Component; import com.cloud.configuration.Config; @@ -67,7 +68,6 @@ @Component public class QuotaServiceImpl extends ManagerBase implements QuotaService, Configurable, QuotaConfig { - private static final Logger s_logger = Logger.getLogger(QuotaServiceImpl.class); @Inject private AccountDao _accountDao; @@ -85,7 +85,6 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi private QuotaResponseBuilder _respBldr; private TimeZone _usageTimezone; - private int _aggregationDuration = 0; public QuotaServiceImpl() { super(); @@ -94,21 +93,10 @@ public QuotaServiceImpl() { @Override public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - String timeZoneStr = _configDao.getValue(Config.UsageAggregationTimezone.toString()); - String aggregationRange = _configDao.getValue(Config.UsageStatsJobAggregationRange.toString()); - if (timeZoneStr == null) { - timeZoneStr = "GMT"; - } + + String timeZoneStr = ObjectUtils.defaultIfNull(_configDao.getValue(Config.UsageAggregationTimezone.toString()), "GMT"); _usageTimezone = TimeZone.getTimeZone(timeZoneStr); - _aggregationDuration = Integer.parseInt(aggregationRange); - if (_aggregationDuration < UsageUtils.USAGE_AGGREGATION_RANGE_MIN) { - s_logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + UsageUtils.USAGE_AGGREGATION_RANGE_MIN); - _aggregationDuration = UsageUtils.USAGE_AGGREGATION_RANGE_MIN; - } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Usage timezone = " + _usageTimezone + " AggregationDuration=" + _aggregationDuration); - } return true; } @@ -130,6 +118,9 @@ public List> getCommands() { cmdList.add(QuotaEmailTemplateUpdateCmd.class); cmdList.add(QuotaTariffCreateCmd.class); cmdList.add(QuotaTariffDeleteCmd.class); + cmdList.add(QuotaConfigureEmailCmd.class); + cmdList.add(QuotaListEmailConfigurationCmd.class); + cmdList.add(QuotaPresetVariablesListCmd.class); return cmdList; } @@ -142,7 +133,7 @@ public String getConfigComponentName() { public ConfigKey[] getConfigKeys() { return new ConfigKey[] {QuotaPluginEnabled, QuotaEnableEnforcement, QuotaCurrencySymbol, QuotaCurrencyLocale, QuotaStatementPeriod, QuotaSmtpHost, QuotaSmtpPort, QuotaSmtpTimeout, QuotaSmtpUser, QuotaSmtpPassword, QuotaSmtpAuthType, QuotaSmtpSender, QuotaSmtpEnabledSecurityProtocols, QuotaSmtpUseStartTLS, QuotaActivationRuleTimeout, QuotaAccountEnabled, - QuotaEmailHeader, QuotaEmailFooter}; + QuotaEmailHeader, QuotaEmailFooter, QuotaEnableEmails}; } @Override @@ -175,36 +166,32 @@ public List findQuotaBalanceVO(Long accountId, String accountNam if (endDate == null) { // adjust start date to end of day as there is no end date - Date adjustedStartDate = computeAdjustedTime(_respBldr.startOfNextDay(startDate)); - if (s_logger.isDebugEnabled()) { - s_logger.debug("getQuotaBalance1: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", on or before " + adjustedStartDate); + startDate = _respBldr.startOfNextDay(startDate); + if (logger.isDebugEnabled()) { + logger.debug("getQuotaBalance1: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", on or before " + startDate); } - List qbrecords = _quotaBalanceDao.lastQuotaBalanceVO(accountId, domainId, adjustedStartDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found records size=" + qbrecords.size()); + List qbrecords = _quotaBalanceDao.lastQuotaBalanceVO(accountId, domainId, startDate); + if (logger.isDebugEnabled()) { + logger.debug("Found records size=" + qbrecords.size()); } if (qbrecords.isEmpty()) { - s_logger.info("Incorrect Date there are no quota records before this date " + adjustedStartDate); + logger.info("Incorrect Date there are no quota records before this date " + startDate); return qbrecords; } else { return qbrecords; } } else { - Date adjustedStartDate = computeAdjustedTime(startDate); - if (endDate.after(_respBldr.startOfNextDay())) { - throw new InvalidParameterValueException("Incorrect Date Range. End date:" + endDate + " should not be in future. "); - } else if (startDate.before(endDate)) { - Date adjustedEndDate = computeAdjustedTime(endDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("getQuotaBalance2: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate - + " and " + adjustedEndDate); + if (startDate.before(endDate)) { + if (logger.isDebugEnabled()) { + logger.debug("getQuotaBalance2: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", between " + startDate + + " and " + endDate); } - List qbrecords = _quotaBalanceDao.findQuotaBalance(accountId, domainId, adjustedStartDate, adjustedEndDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("getQuotaBalance3: Found records size=" + qbrecords.size()); + List qbrecords = _quotaBalanceDao.findQuotaBalance(accountId, domainId, startDate, endDate); + if (logger.isDebugEnabled()) { + logger.debug("getQuotaBalance3: Found records size=" + qbrecords.size()); } if (qbrecords.isEmpty()) { - s_logger.info("There are no quota records between these dates start date " + adjustedStartDate + " and end date:" + endDate); + logger.info("There are no quota records between these dates start date " + startDate + " and end date:" + endDate); return qbrecords; } else { return qbrecords; @@ -240,44 +227,11 @@ public List getQuotaUsage(Long accountId, String accountName, Long if (startDate.after(endDate)) { throw new InvalidParameterValueException("Incorrect Date Range. Start date: " + startDate + " is after end date:" + endDate); } - if (endDate.after(_respBldr.startOfNextDay())) { - throw new InvalidParameterValueException("Incorrect Date Range. End date:" + endDate + " should not be in future. "); - } - Date adjustedEndDate = computeAdjustedTime(endDate); - Date adjustedStartDate = computeAdjustedTime(startDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Getting quota records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + " and " + adjustedEndDate); - } - return _quotaUsageDao.findQuotaUsage(accountId, domainId, usageType, adjustedStartDate, adjustedEndDate); - } - - @Override - public Date computeAdjustedTime(final Date date) { - if (date == null) { - return null; - } - - Calendar cal = Calendar.getInstance(); - cal.setTime(date); - TimeZone localTZ = cal.getTimeZone(); - int timezoneOffset = cal.get(Calendar.ZONE_OFFSET); - if (localTZ.inDaylightTime(date)) { - timezoneOffset += (60 * 60 * 1000); - } - cal.add(Calendar.MILLISECOND, timezoneOffset); - - Date newTime = cal.getTime(); - - Calendar calTS = Calendar.getInstance(_usageTimezone); - calTS.setTime(newTime); - timezoneOffset = calTS.get(Calendar.ZONE_OFFSET); - if (_usageTimezone.inDaylightTime(date)) { - timezoneOffset += (60 * 60 * 1000); - } - calTS.add(Calendar.MILLISECOND, -1 * timezoneOffset); + logger.debug("Getting quota records of type [{}] for account [{}] in domain [{}], between [{}] and [{}].", + usageType, accountId, domainId, startDate, endDate); - return calTS.getTime(); + return _quotaUsageDao.findQuotaUsage(accountId, domainId, usageType, startDate, endDate); } @Override @@ -302,16 +256,16 @@ public boolean saveQuotaAccount(final AccountVO account, final BigDecimal aggrUs quota_account = new QuotaAccountVO(account.getAccountId()); quota_account.setQuotaBalance(aggrUsage); quota_account.setQuotaBalanceDate(endDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug(quota_account); + if (logger.isDebugEnabled()) { + logger.debug(quota_account); } _quotaAcc.persistQuotaAccount(quota_account); return true; } else { quota_account.setQuotaBalance(aggrUsage); quota_account.setQuotaBalanceDate(endDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug(quota_account); + if (logger.isDebugEnabled()) { + logger.debug(quota_account); } return _quotaAcc.updateQuotaAccount(account.getAccountId(), quota_account); } diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java index 1fdb2956f308..adabc694f25a 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java @@ -28,7 +28,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import junit.framework.TestCase; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java index c66ac6b89c1f..1a73fcd7506a 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java index a357a181c38c..de0220edfa0e 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java index 0492ae84b8df..d6f9f747fa84 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java @@ -24,7 +24,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java index e57109c4761e..a98d3d611de8 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java @@ -16,16 +16,19 @@ // under the License. package org.apache.cloudstack.api.command; +import com.cloud.user.User; import junit.framework.TestCase; import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaTariffResponse; +import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.MockedStatic; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.math.BigDecimal; @@ -40,6 +43,12 @@ public class QuotaTariffListCmdTest extends TestCase { @Mock QuotaResponseBuilder responseBuilder; + @Mock + User userMock; + + @Mock + CallContext callContextMock; + @Test public void testQuotaTariffListCmd() throws NoSuchFieldException, IllegalAccessException { QuotaTariffListCmd cmd = new QuotaTariffListCmd(); @@ -48,17 +57,24 @@ public void testQuotaTariffListCmd() throws NoSuchFieldException, IllegalAccessE rbField.setAccessible(true); rbField.set(cmd, responseBuilder); - List quotaTariffVOList = new ArrayList(); + List quotaTariffVOList = new ArrayList<>(); QuotaTariffVO tariff = new QuotaTariffVO(); tariff.setEffectiveOn(new Date()); tariff.setCurrencyValue(new BigDecimal(100)); tariff.setUsageType(QuotaTypes.VOLUME); quotaTariffVOList.add(new QuotaTariffVO()); - Mockito.when(responseBuilder.listQuotaTariffPlans(Mockito.eq(cmd))).thenReturn(new Pair<>(quotaTariffVOList, quotaTariffVOList.size())); - Mockito.when(responseBuilder.createQuotaTariffResponse(Mockito.any(QuotaTariffVO.class))).thenReturn(new QuotaTariffResponse()); - cmd.execute(); - Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaTariffResponse(Mockito.any(QuotaTariffVO.class)); + try (MockedStatic callContextStaticMock = Mockito.mockStatic(CallContext.class)) { + Mockito.when(responseBuilder.listQuotaTariffPlans(Mockito.eq(cmd))).thenReturn(new Pair<>(quotaTariffVOList, quotaTariffVOList.size())); + callContextStaticMock.when(CallContext::current).thenReturn(callContextMock); + Mockito.when(callContextMock.getCallingUser()).thenReturn(userMock); + Mockito.when(responseBuilder.isUserAllowedToSeeActivationRules(userMock)).thenReturn(true); + Mockito.when(responseBuilder.createQuotaTariffResponse(Mockito.any(QuotaTariffVO.class), Mockito.eq(true))).thenReturn(new QuotaTariffResponse()); + + cmd.execute(); + } + + Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaTariffResponse(Mockito.any(QuotaTariffVO.class), Mockito.eq(true)); } } diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java index 0cb1799ec104..7a4d1a753562 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java @@ -27,7 +27,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.math.BigDecimal; @@ -60,8 +60,8 @@ public void testQuotaTariffUpdateCmd() throws NoSuchFieldException, IllegalAcces } Mockito.when(responseBuilder.updateQuotaTariffPlan(Mockito.eq(cmd))).thenReturn(tariff); - Mockito.when(responseBuilder.createQuotaTariffResponse(Mockito.eq(tariff))).thenReturn(new QuotaTariffResponse()); + Mockito.when(responseBuilder.createQuotaTariffResponse(Mockito.eq(tariff), Mockito.eq(true))).thenReturn(new QuotaTariffResponse()); cmd.execute(); - Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaTariffResponse(Mockito.eq(tariff)); + Mockito.verify(responseBuilder, Mockito.times(1)).createQuotaTariffResponse(Mockito.eq(tariff), Mockito.eq(true)); } } diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java index b960a1be5692..fd3595258937 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java @@ -29,24 +29,36 @@ import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; +import com.cloud.utils.Pair; import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.QuotaConfigureEmailCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.quota.QuotaService; import org.apache.cloudstack.quota.QuotaStatement; +import org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariableDefinition; +import org.apache.cloudstack.quota.activationrule.presetvariables.PresetVariables; +import org.apache.cloudstack.quota.activationrule.presetvariables.Value; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.constant.QuotaTypes; +import org.apache.cloudstack.quota.dao.QuotaAccountDao; import org.apache.cloudstack.quota.dao.QuotaBalanceDao; import org.apache.cloudstack.quota.dao.QuotaCreditsDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.dao.QuotaTariffDao; import org.apache.cloudstack.quota.dao.QuotaUsageDao; +import org.apache.cloudstack.quota.vo.QuotaAccountVO; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; import org.apache.cloudstack.quota.vo.QuotaCreditsVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; import org.apache.cloudstack.quota.vo.QuotaTariffVO; +import org.apache.cloudstack.discovery.ApiDiscoveryService; + import org.apache.commons.lang3.time.DateUtils; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -60,6 +72,7 @@ import com.cloud.user.AccountVO; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; +import com.cloud.user.User; import junit.framework.TestCase; import org.mockito.junit.MockitoJUnitRunner; @@ -82,6 +95,12 @@ public class QuotaResponseBuilderImplTest extends TestCase { @Mock UserDao userDaoMock; + @Mock + User userMock; + + @Mock + ApiDiscoveryService discoveryServiceMock; + @Mock QuotaService quotaServiceMock; @@ -103,6 +122,12 @@ public class QuotaResponseBuilderImplTest extends TestCase { @Mock QuotaUsageDao quotaUsageDaoMock; + @Mock + QuotaAccountDao quotaAccountDaoMock; + + @Mock + QuotaEmailConfigurationDao quotaEmailConfigurationDaoMock; + @InjectMocks QuotaResponseBuilderImpl quotaResponseBuilderSpy = Mockito.spy(QuotaResponseBuilderImpl.class); @@ -114,6 +139,15 @@ public class QuotaResponseBuilderImplTest extends TestCase { @Mock DomainVO domainVOMock; + @Mock + QuotaConfigureEmailCmd quotaConfigureEmailCmdMock; + + @Mock + QuotaAccountVO quotaAccountVOMock; + + @Mock + QuotaEmailTemplatesVO quotaEmailTemplatesVoMock; + private void overrideDefaultQuotaEnabledConfigValue(final Object value) throws IllegalAccessException, NoSuchFieldException { Field f = ConfigKey.class.getDeclaredField("_defaultValue"); f.setAccessible(true); @@ -140,11 +174,29 @@ private QuotaTariffVO makeTariffTestData() { @Test public void testQuotaResponse() { QuotaTariffVO tariffVO = makeTariffTestData(); - QuotaTariffResponse response = quotaResponseBuilderSpy.createQuotaTariffResponse(tariffVO); + QuotaTariffResponse response = quotaResponseBuilderSpy.createQuotaTariffResponse(tariffVO, true); assertTrue(tariffVO.getUsageType() == response.getUsageType()); assertTrue(tariffVO.getCurrencyValue().equals(response.getTariffValue())); } + @Test + public void createQuotaTariffResponseTestIfReturnsActivationRuleWithPermission() { + QuotaTariffVO tariff = makeTariffTestData(); + tariff.setActivationRule("x === 10"); + + QuotaTariffResponse tariffResponse = quotaResponseBuilderSpy.createQuotaTariffResponse(tariff, true); + assertEquals("x === 10", tariffResponse.getActivationRule()); + } + + @Test + public void createQuotaTariffResponseTestIfReturnsActivationRuleWithoutPermission() { + QuotaTariffVO tariff = makeTariffTestData(); + tariff.setActivationRule("x === 10"); + + QuotaTariffResponse tariffResponse = quotaResponseBuilderSpy.createQuotaTariffResponse(tariff, false); + assertNull(tariffResponse.getActivationRule()); + } + @Test public void testAddQuotaCredits() { final long accountId = 2L; @@ -157,7 +209,6 @@ public void testAddQuotaCredits() { Mockito.when(quotaCreditsDaoMock.saveCredits(Mockito.any(QuotaCreditsVO.class))).thenReturn(credit); Mockito.when(quotaBalanceDaoMock.lastQuotaBalance(Mockito.anyLong(), Mockito.anyLong(), Mockito.any(Date.class))).thenReturn(new BigDecimal(111)); - Mockito.when(quotaServiceMock.computeAdjustedTime(Mockito.any(Date.class))).thenReturn(new Date()); AccountVO account = new AccountVO(); account.setState(Account.State.LOCKED); @@ -225,7 +276,6 @@ public void testCreateQuotaLastBalanceResponse() { entry.setCreditBalance(new BigDecimal(100)); quotaBalance.add(entry); quotaBalance.add(entry); - Mockito.lenient().when(quotaServiceMock.computeAdjustedTime(Mockito.any(Date.class))).thenReturn(new Date()); QuotaBalanceResponse resp = quotaResponseBuilderSpy.createQuotaLastBalanceResponse(quotaBalance, null); assertTrue(resp.getStartQuota().compareTo(new BigDecimal(200)) == 0); } @@ -306,16 +356,14 @@ public void validateEndDateOnCreatingNewQuotaTariffTestEndDateLessThanNowThrowIn Date startDate = DateUtils.addDays(date, -100); Date endDate = DateUtils.addDays(new Date(), -1); - Mockito.doReturn(date).when(quotaServiceMock).computeAdjustedTime(Mockito.any(Date.class)); quotaResponseBuilderSpy.validateEndDateOnCreatingNewQuotaTariff(quotaTariffVoMock, startDate, endDate); } @Test public void validateEndDateOnCreatingNewQuotaTariffTestSetValidEndDate() { Date startDate = DateUtils.addDays(date, -100); - Date endDate = date; + Date endDate = DateUtils.addMinutes(new Date(), 1); - Mockito.doReturn(DateUtils.addDays(date, -10)).when(quotaServiceMock).computeAdjustedTime(Mockito.any(Date.class)); quotaResponseBuilderSpy.validateEndDateOnCreatingNewQuotaTariff(quotaTariffVoMock, startDate, endDate); Mockito.verify(quotaTariffVoMock).setEndDate(Mockito.any(Date.class)); } @@ -352,8 +400,10 @@ public void persistNewQuotaTariffTestpersistNewQuotaTariff() { Mockito.doNothing().when(quotaResponseBuilderSpy).validateValueOnCreatingNewQuotaTariff(Mockito.any(QuotaTariffVO.class), Mockito.anyDouble()); Mockito.doNothing().when(quotaResponseBuilderSpy).validateStringsOnCreatingNewQuotaTariff(Mockito.any(Consumer.class), Mockito.anyString()); Mockito.doReturn(quotaTariffVoMock).when(quotaTariffDaoMock).addQuotaTariff(Mockito.any(QuotaTariffVO.class)); + Mockito.doNothing().when(quotaResponseBuilderSpy).validatePositionOnCreatingNewQuotaTariff(Mockito.any(QuotaTariffVO.class), Mockito.anyInt()); + - quotaResponseBuilderSpy.persistNewQuotaTariff(quotaTariffVoMock, "", 1, date, 1l, date, 1.0, "", ""); + quotaResponseBuilderSpy.persistNewQuotaTariff(quotaTariffVoMock, "", 1, date, 1l, date, 1.0, "", "", 2); Mockito.verify(quotaTariffDaoMock).addQuotaTariff(Mockito.any(QuotaTariffVO.class)); } @@ -367,7 +417,6 @@ public void deleteQuotaTariffTestQuotaDoesNotExistThrowsServerApiException() { public void deleteQuotaTariffTestUpdateRemoved() { Mockito.doReturn(quotaTariffVoMock).when(quotaTariffDaoMock).findByUuid(Mockito.anyString()); Mockito.doReturn(true).when(quotaTariffDaoMock).updateQuotaTariff(Mockito.any(QuotaTariffVO.class)); - Mockito.doReturn(new Date()).when(quotaServiceMock).computeAdjustedTime(Mockito.any(Date.class)); Assert.assertTrue(quotaResponseBuilderSpy.deleteQuotaTariff("")); @@ -403,4 +452,197 @@ public void getQuotaSummaryResponseTestAccountIsNotNullQuotaIsEnabledShouldRetur assertTrue(quotaSummaryResponse.getQuotaEnabled()); } + + @Test + public void filterSupportedTypesTestReturnWhenQuotaTypeDoesNotMatch() throws NoSuchFieldException { + List> variables = new ArrayList<>(); + Class clazz = Value.class; + PresetVariableDefinition presetVariableDefinitionAnnotation = clazz.getDeclaredField("host").getAnnotation(PresetVariableDefinition.class); + QuotaTypes quotaType = QuotaTypes.getQuotaType(QuotaTypes.NETWORK_OFFERING); + int expectedVariablesSize = 0; + + quotaResponseBuilderSpy.filterSupportedTypes(variables, quotaType, presetVariableDefinitionAnnotation, clazz, null); + + assertEquals(expectedVariablesSize, variables.size()); + } + + @Test + public void filterSupportedTypesTestAddPresetVariableWhenClassIsNotInstanceOfGenericPresetVariableAndComputingResource() throws NoSuchFieldException { + List> variables = new ArrayList<>(); + Class clazz = PresetVariables.class; + PresetVariableDefinition presetVariableDefinitionAnnotation = clazz.getDeclaredField("resourceType").getAnnotation(PresetVariableDefinition.class); + QuotaTypes quotaType = QuotaTypes.getQuotaType(QuotaTypes.NETWORK_OFFERING); + int expectedVariablesSize = 1; + String expectedVariableName = "variable.name"; + + quotaResponseBuilderSpy.filterSupportedTypes(variables, quotaType, presetVariableDefinitionAnnotation, clazz, "variable.name"); + + assertEquals(expectedVariablesSize, variables.size()); + assertEquals(expectedVariableName, variables.get(0).first()); + } + + @Test + public void filterSupportedTypesTestCallRecursiveMethodWhenIsGenericPresetVariableClassOrComputingResourceClass() throws NoSuchFieldException { + List> variables = new ArrayList<>(); + Class clazz = Value.class; + PresetVariableDefinition presetVariableDefinitionAnnotation = clazz.getDeclaredField("storage").getAnnotation(PresetVariableDefinition.class); + QuotaTypes quotaType = QuotaTypes.getQuotaType(QuotaTypes.VOLUME); + + quotaResponseBuilderSpy.filterSupportedTypes(variables, quotaType, presetVariableDefinitionAnnotation, clazz, "variable.name"); + + Mockito.verify(quotaResponseBuilderSpy, Mockito.atLeastOnce()).addAllPresetVariables(Mockito.any(), Mockito.any(QuotaTypes.class), Mockito.anyList(), + Mockito.anyString()); + } + + @Test (expected = InvalidParameterValueException.class) + public void validateQuotaConfigureEmailCmdParametersTestNullQuotaAccount() { + Mockito.doReturn(null).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test (expected = InvalidParameterValueException.class) + public void validateQuotaConfigureEmailCmdParametersTestNullTemplateNameAndMinBalance() { + Mockito.doReturn(quotaAccountVOMock).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getMinBalance(); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test (expected = InvalidParameterValueException.class) + public void validateQuotaConfigureEmailCmdParametersTestEnableNullAndTemplateNameNotNull() { + Mockito.doReturn(quotaAccountVOMock).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + Mockito.doReturn(QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW.toString()).when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getEnable(); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test + public void validateQuotaConfigureEmailCmdParametersTestNullTemplateName() { + Mockito.doReturn(quotaAccountVOMock).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getEnable(); + Mockito.doReturn(100D).when(quotaConfigureEmailCmdMock).getMinBalance(); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test + public void validateQuotaConfigureEmailCmdParametersTestWithTemplateNameAndEnable() { + Mockito.doReturn(quotaAccountVOMock).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + Mockito.doReturn(QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW.toString()).when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(true).when(quotaConfigureEmailCmdMock).getEnable(); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test + public void getQuotaEmailConfigurationVoTestTemplateNameIsNull() { + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getTemplateName(); + + QuotaEmailConfigurationVO result = quotaResponseBuilderSpy.getQuotaEmailConfigurationVo(quotaConfigureEmailCmdMock); + + Assert.assertNull(result); + } + + @Test (expected = InvalidParameterValueException.class) + public void getQuotaEmailConfigurationVoTestNoTemplateFound() { + Mockito.doReturn("name").when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(new ArrayList()).when(quotaEmailTemplateDaoMock).listAllQuotaEmailTemplates(Mockito.any()); + + quotaResponseBuilderSpy.getQuotaEmailConfigurationVo(quotaConfigureEmailCmdMock); + } + + @Test + public void getQuotaEmailConfigurationVoTestNewConfiguration() { + Mockito.doReturn("name").when(quotaConfigureEmailCmdMock).getTemplateName(); + List templatesVOArrayList = List.of(quotaEmailTemplatesVoMock); + Mockito.doReturn(templatesVOArrayList).when(quotaEmailTemplateDaoMock).listAllQuotaEmailTemplates(Mockito.any()); + Mockito.doReturn(null).when(quotaEmailConfigurationDaoMock).findByAccountIdAndEmailTemplateId(Mockito.anyLong(), Mockito.anyLong()); + + QuotaEmailConfigurationVO result = quotaResponseBuilderSpy.getQuotaEmailConfigurationVo(quotaConfigureEmailCmdMock); + + Mockito.verify(quotaEmailConfigurationDaoMock).persistQuotaEmailConfiguration(Mockito.any()); + assertEquals(0, result.getAccountId()); + assertEquals(0, result.getEmailTemplateId()); + assertFalse(result.isEnabled()); + } + + @Test + public void getQuotaEmailConfigurationVoTestExistingConfiguration() { + Mockito.doReturn("name").when(quotaConfigureEmailCmdMock).getTemplateName(); + List templatesVOArrayList = List.of(quotaEmailTemplatesVoMock); + Mockito.doReturn(templatesVOArrayList).when(quotaEmailTemplateDaoMock).listAllQuotaEmailTemplates(Mockito.any()); + + QuotaEmailConfigurationVO quotaEmailConfigurationVO = new QuotaEmailConfigurationVO(1, 2, true); + Mockito.doReturn(quotaEmailConfigurationVO).when(quotaEmailConfigurationDaoMock).findByAccountIdAndEmailTemplateId(Mockito.anyLong(), Mockito.anyLong()); + Mockito.doReturn(quotaEmailConfigurationVO).when(quotaEmailConfigurationDaoMock).updateQuotaEmailConfiguration(Mockito.any()); + + QuotaEmailConfigurationVO result = quotaResponseBuilderSpy.getQuotaEmailConfigurationVo(quotaConfigureEmailCmdMock); + + Mockito.verify(quotaEmailConfigurationDaoMock).updateQuotaEmailConfiguration(Mockito.any()); + + assertEquals(1, result.getAccountId()); + assertEquals(2, result.getEmailTemplateId()); + assertFalse(result.isEnabled()); + } + + @Test + public void validatePositionOnCreatingNewQuotaTariffTestNullValueDoNothing() { + quotaResponseBuilderSpy.validatePositionOnCreatingNewQuotaTariff(quotaTariffVoMock, null); + Mockito.verify(quotaTariffVoMock, Mockito.never()).setPosition(Mockito.any()); + } + + @Test + public void validatePositionOnCreatingNewQuotaTariffTestAnyValueIsSet() { + Integer position = 1; + quotaResponseBuilderSpy.validatePositionOnCreatingNewQuotaTariff(quotaTariffVoMock, position); + Mockito.verify(quotaTariffVoMock).setPosition(position); + } + + + @Test + public void isUserAllowedToSeeActivationRulesTestWithPermissionToCreateTariff() { + ApiDiscoveryResponse response = new ApiDiscoveryResponse(); + response.setName("quotaTariffCreate"); + + List cmdList = new ArrayList<>(); + cmdList.add(response); + + ListResponse responseList = new ListResponse<>(); + responseList.setResponses(cmdList); + + Mockito.doReturn(responseList).when(discoveryServiceMock).listApis(userMock, null); + + assertTrue(quotaResponseBuilderSpy.isUserAllowedToSeeActivationRules(userMock)); + } + + @Test + public void isUserAllowedToSeeActivationRulesTestWithPermissionToUpdateTariff() { + ApiDiscoveryResponse response = new ApiDiscoveryResponse(); + response.setName("quotaTariffUpdate"); + + List cmdList = new ArrayList<>(); + cmdList.add(response); + + ListResponse responseList = new ListResponse<>(); + responseList.setResponses(cmdList); + + Mockito.doReturn(responseList).when(discoveryServiceMock).listApis(userMock, null); + + assertTrue(quotaResponseBuilderSpy.isUserAllowedToSeeActivationRules(userMock)); + } + + @Test + public void isUserAllowedToSeeActivationRulesTestWithNoPermission() { + ApiDiscoveryResponse response = new ApiDiscoveryResponse(); + response.setName("testCmd"); + + List cmdList = new ArrayList<>(); + cmdList.add(response); + + ListResponse responseList = new ListResponse<>(); + responseList.setResponses(cmdList); + + Mockito.doReturn(responseList).when(discoveryServiceMock).listApis(userMock, null); + + assertFalse(quotaResponseBuilderSpy.isUserAllowedToSeeActivationRules(userMock)); + } } diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java index 310e9ced72fd..19e756d1d973 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java @@ -30,13 +30,12 @@ import org.apache.cloudstack.quota.vo.QuotaAccountVO; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import javax.naming.ConfigurationException; import java.lang.reflect.Field; @@ -99,17 +98,9 @@ public void setup() throws IllegalAccessException, NoSuchFieldException, Configu QuotaResponseBuilderField.set(quotaService, respBldr); Mockito.when(configDao.getValue(Mockito.eq(Config.UsageAggregationTimezone.toString()))).thenReturn("IST"); - Mockito.when(configDao.getValue(Mockito.eq(Config.UsageStatsJobAggregationRange.toString()))).thenReturn("1"); quotaService.configure("randomName", null); } - @Test - public void testComputeAdjustedTime() { - DateTime now = new DateTime(DateTimeZone.UTC); - DateTime result = new DateTime(quotaService.computeAdjustedTime(now.toDate())); - // FIXME: fix this test - } - @Test public void testFindQuotaBalanceVO() { final long accountId = 2L; @@ -124,7 +115,6 @@ public void testFindQuotaBalanceVO() { qb.setAccountId(accountId); records.add(qb); - Mockito.when(respBldr.startOfNextDay()).thenReturn(endDate); Mockito.when(respBldr.startOfNextDay(Mockito.any(Date.class))).thenReturn(startDate); Mockito.when(quotaBalanceDao.findQuotaBalance(Mockito.eq(accountId), Mockito.eq(domainId), Mockito.any(Date.class), Mockito.any(Date.class))).thenReturn(records); Mockito.when(quotaBalanceDao.lastQuotaBalanceVO(Mockito.eq(accountId), Mockito.eq(domainId), Mockito.any(Date.class))).thenReturn(records); @@ -143,7 +133,6 @@ public void testGetQuotaUsage() { final Date startDate = new DateTime().minusDays(2).toDate(); final Date endDate = new Date(); - Mockito.when(respBldr.startOfNextDay()).thenReturn(endDate); quotaService.getQuotaUsage(accountId, accountName, domainId, QuotaTypes.IP_ADDRESS, startDate, endDate); Mockito.verify(quotaUsageDao, Mockito.times(1)).findQuotaUsage(Mockito.eq(accountId), Mockito.eq(domainId), Mockito.eq(QuotaTypes.IP_ADDRESS), Mockito.any(Date.class), Mockito.any(Date.class)); } diff --git a/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/dedicated-resources/pom.xml b/plugins/dedicated-resources/pom.xml index e08b6f5c6e90..5aeecec818de 100644 --- a/plugins/dedicated-resources/pom.xml +++ b/plugins/dedicated-resources/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateClusterCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateClusterCmd.java index 06e0a42df853..5ab1ba73fced 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateClusterCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateClusterCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ @APICommand(name = "dedicateCluster", description = "Dedicate an existing cluster", responseObject = DedicateClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicateClusterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DedicateClusterCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateHostCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateHostCmd.java index cf6c5872fdd4..6fb379f4a871 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateHostCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateHostCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ @APICommand(name = "dedicateHost", description = "Dedicates a host.", responseObject = DedicateHostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicateHostCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DedicateHostCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicatePodCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicatePodCmd.java index 819c4106af5d..2b5e9afab88c 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicatePodCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicatePodCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ @APICommand(name = "dedicatePod", description = "Dedicates a Pod.", responseObject = DedicatePodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicatePodCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DedicatePodCmd.class.getName()); @Inject public DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateZoneCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateZoneCmd.java index c3ce1d3baece..ea91ea5a661a 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateZoneCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateZoneCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ @APICommand(name = "dedicateZone", description = "Dedicates a zones.", responseObject = DedicateZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicateZoneCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DedicateZoneCmd.class.getName()); @Inject public DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedClustersCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedClustersCmd.java index c91e44707638..efdee15ff19c 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedClustersCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedClustersCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ @APICommand(name = "listDedicatedClusters", description = "Lists dedicated clusters.", responseObject = DedicateClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedClustersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedClustersCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedHostsCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedHostsCmd.java index fd27662ddedb..b60509f6b660 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedHostsCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedHostsCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ @APICommand(name = "listDedicatedHosts", description = "Lists dedicated hosts.", responseObject = DedicateHostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedHostsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedHostsCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedPodsCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedPodsCmd.java index 742c5cc96ea9..06eaefe32987 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedPodsCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedPodsCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ @APICommand(name = "listDedicatedPods", description = "Lists dedicated pods.", responseObject = DedicatePodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedPodsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedPodsCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedZonesCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedZonesCmd.java index b8874eab7cd3..c5bc5456f790 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedZonesCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedZonesCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ @APICommand(name = "listDedicatedZones", description = "List dedicated zones.", responseObject = DedicateZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedZonesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedZonesCmd.class.getName()); @Inject DedicatedService _dedicatedservice; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedClusterCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedClusterCmd.java index 9945ba29ca1a..af153e499e90 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedClusterCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedClusterCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "releaseDedicatedCluster", description = "Release the dedication for cluster", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedClusterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedClusterCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedHostCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedHostCmd.java index 22563503061e..81eff262fbc0 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedHostCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedHostCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "releaseDedicatedHost", description = "Release the dedication for host", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedHostCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedHostCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedPodCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedPodCmd.java index ec47a4303408..5f7dadc993fa 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedPodCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedPodCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "releaseDedicatedPod", description = "Release the dedication for the pod", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedPodCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedPodCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedZoneCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedZoneCmd.java index 4b15ddf951c1..cc178d992f27 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedZoneCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedZoneCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ @APICommand(name = "releaseDedicatedZone", description = "Release dedication of zone", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedZoneCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedZoneCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java index cd6d8cf590d4..4f1db396b7c4 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java @@ -23,6 +23,7 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.commons.lang3.StringUtils; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupService; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; @@ -44,7 +45,8 @@ import org.apache.cloudstack.api.response.DedicateZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.configuration.Config; @@ -84,7 +86,7 @@ @Component public class DedicatedResourceManagerImpl implements DedicatedService { - private static final Logger s_logger = Logger.getLogger(DedicatedResourceManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AccountDao _accountDao; @@ -140,7 +142,7 @@ public List dedicateZone(final Long zoneId, final Long doma DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(zoneId); //check if zone is dedicated if (dedicatedZone != null) { - s_logger.error("Zone " + dc.getName() + " is already dedicated"); + logger.error("Zone " + dc.getName() + " is already dedicated"); throw new CloudRuntimeException("Zone " + dc.getName() + " is already dedicated"); } @@ -159,7 +161,7 @@ public List dedicateZone(final Long zoneId, final Long doma if (dPod.getAccountId().equals(accountId)) { podsToRelease.add(dPod); } else { - s_logger.error("Pod " + pod.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); + logger.error("Pod " + pod.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Pod " + pod.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); } } else { @@ -185,7 +187,7 @@ public List dedicateZone(final Long zoneId, final Long doma if (dCluster.getAccountId().equals(accountId)) { clustersToRelease.add(dCluster); } else { - s_logger.error("Cluster " + cluster.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); + logger.error("Cluster " + cluster.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); } @@ -212,7 +214,7 @@ public List dedicateZone(final Long zoneId, final Long doma if (dHost.getAccountId().equals(accountId)) { hostsToRelease.add(dHost); } else { - s_logger.error("Host " + host.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); + logger.error("Host " + host.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Host " + host.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); } } else { @@ -235,9 +237,9 @@ public List dedicateZone(final Long zoneId, final Long doma @Override public List doInTransaction(TransactionStatus status) { // find or create the affinity group by name under this account/domain - AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); + AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal, DedicatedResources.Type.Zone); if (group == null) { - s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); + logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } @@ -256,7 +258,7 @@ public List doInTransaction(TransactionStatus status) { } } catch (Exception e) { - s_logger.error("Unable to dedicate zone due to " + e.getMessage(), e); + logger.error("Unable to dedicate zone due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } @@ -290,7 +292,7 @@ public List dedicatePod(final Long podId, final Long domain DedicatedResourceVO dedicatedZoneOfPod = _dedicatedDao.findByZoneId(pod.getDataCenterId()); //check if pod is dedicated if (dedicatedPod != null) { - s_logger.error("Pod " + pod.getName() + " is already dedicated"); + logger.error("Pod " + pod.getName() + " is already dedicated"); throw new CloudRuntimeException("Pod " + pod.getName() + " is already dedicated"); } @@ -300,7 +302,7 @@ public List dedicatePod(final Long podId, final Long domain if (dedicatedZoneOfPod.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfPod.getDomainId().equals(domainId) || domainIdInChildreanList))) { DataCenterVO zone = _zoneDao.findById(pod.getDataCenterId()); - s_logger.error("Cannot dedicate Pod. Its zone is already dedicated"); + logger.error("Cannot dedicate Pod. Its zone is already dedicated"); throw new CloudRuntimeException("Pod's Zone " + zone.getName() + " is already dedicated"); } } @@ -321,7 +323,7 @@ public List dedicatePod(final Long podId, final Long domain if (dCluster.getAccountId().equals(accountId)) { clustersToRelease.add(dCluster); } else { - s_logger.error("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); + logger.error("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); } @@ -348,7 +350,7 @@ public List dedicatePod(final Long podId, final Long domain if (dHost.getAccountId().equals(accountId)) { hostsToRelease.add(dHost); } else { - s_logger.error("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); + logger.error("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); } } else { @@ -371,10 +373,10 @@ public List dedicatePod(final Long podId, final Long domain @Override public List doInTransaction(TransactionStatus status) { // find or create the affinity group by name under this account/domain - AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); + AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal, DedicatedResources.Type.Pod); if (group == null) { - s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); - throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); + logger.error("Unable to dedicate pod due to, failed to create dedication affinity group"); + throw new CloudRuntimeException("Failed to dedicate pod. Please contact Cloud Support."); } DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, podId, null, null, null, null, group.getId()); try { @@ -384,7 +386,7 @@ public List doInTransaction(TransactionStatus status) { } dedicatedResource = _dedicatedDao.persist(dedicatedResource); } catch (Exception e) { - s_logger.error("Unable to dedicate pod due to " + e.getMessage(), e); + logger.error("Unable to dedicate pod due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate pod. Please contact Cloud Support."); } @@ -419,7 +421,7 @@ public List dedicateCluster(final Long clusterId, final Lon //check if cluster is dedicated if (dedicatedCluster != null) { - s_logger.error("Cluster " + cluster.getName() + " is already dedicated"); + logger.error("Cluster " + cluster.getName() + " is already dedicated"); throw new CloudRuntimeException("Cluster " + cluster.getName() + " is already dedicated"); } @@ -428,7 +430,7 @@ public List dedicateCluster(final Long clusterId, final Lon //can dedicate a cluster to an account/domain if pod is dedicated to parent-domain if (dedicatedPodOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) { - s_logger.error("Cannot dedicate Cluster. Its Pod is already dedicated"); + logger.error("Cannot dedicate Cluster. Its Pod is already dedicated"); HostPodVO pod = _podDao.findById(cluster.getPodId()); throw new CloudRuntimeException("Cluster's Pod " + pod.getName() + " is already dedicated"); } @@ -439,7 +441,7 @@ public List dedicateCluster(final Long clusterId, final Lon //can dedicate a cluster to an account/domain if zone is dedicated to parent-domain if (dedicatedZoneOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) { - s_logger.error("Cannot dedicate Cluster. Its zone is already dedicated"); + logger.error("Cannot dedicate Cluster. Its zone is already dedicated"); DataCenterVO zone = _zoneDao.findById(cluster.getDataCenterId()); throw new CloudRuntimeException("Cluster's Zone " + zone.getName() + " is already dedicated"); } @@ -461,7 +463,7 @@ public List dedicateCluster(final Long clusterId, final Lon if (dHost.getAccountId().equals(accountId)) { hostsToRelease.add(dHost); } else { - s_logger.error("Cannot dedicate Cluster " + cluster.getName() + " to account" + accountName); + logger.error("Cannot dedicate Cluster " + cluster.getName() + " to account" + accountName); throw new CloudRuntimeException("Cannot dedicate Cluster " + cluster.getName() + " to account" + accountName); } } else { @@ -484,10 +486,10 @@ public List dedicateCluster(final Long clusterId, final Lon @Override public List doInTransaction(TransactionStatus status) { // find or create the affinity group by name under this account/domain - AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); + AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal, DedicatedResources.Type.Cluster); if (group == null) { - s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); - throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); + logger.error("Unable to dedicate cluster due to, failed to create dedication affinity group"); + throw new CloudRuntimeException("Failed to dedicate cluster. Please contact Cloud Support."); } DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, clusterId, null, null, null, group.getId()); try { @@ -497,7 +499,7 @@ public List doInTransaction(TransactionStatus status) { } dedicatedResource = _dedicatedDao.persist(dedicatedResource); } catch (Exception e) { - s_logger.error("Unable to dedicate cluster due to " + e.getMessage(), e); + logger.error("Unable to dedicate cluster due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate cluster. Please contact Cloud Support.", e); } @@ -534,7 +536,7 @@ public List dedicateHost(final Long hostId, final Long doma DedicatedResourceVO dedicatedZoneOfHost = _dedicatedDao.findByZoneId(host.getDataCenterId()); if (dedicatedHost != null) { - s_logger.error("Host " + host.getName() + " is already dedicated"); + logger.error("Host " + host.getName() + " is already dedicated"); throw new CloudRuntimeException("Host " + host.getName() + " is already dedicated"); } @@ -544,7 +546,7 @@ public List dedicateHost(final Long hostId, final Long doma if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedClusterOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { ClusterVO cluster = _clusterDao.findById(host.getClusterId()); - s_logger.error("Host's Cluster " + cluster.getName() + " is already dedicated"); + logger.error("Host's Cluster " + cluster.getName() + " is already dedicated"); throw new CloudRuntimeException("Host's Cluster " + cluster.getName() + " is already dedicated"); } } @@ -555,7 +557,7 @@ public List dedicateHost(final Long hostId, final Long doma if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { HostPodVO pod = _podDao.findById(host.getPodId()); - s_logger.error("Host's Pod " + pod.getName() + " is already dedicated"); + logger.error("Host's Pod " + pod.getName() + " is already dedicated"); throw new CloudRuntimeException("Host's Pod " + pod.getName() + " is already dedicated"); } } @@ -566,7 +568,7 @@ public List dedicateHost(final Long hostId, final Long doma if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { DataCenterVO zone = _zoneDao.findById(host.getDataCenterId()); - s_logger.error("Host's Data Center " + zone.getName() + " is already dedicated"); + logger.error("Host's Data Center " + zone.getName() + " is already dedicated"); throw new CloudRuntimeException("Host's Data Center " + zone.getName() + " is already dedicated"); } } @@ -581,10 +583,10 @@ public List dedicateHost(final Long hostId, final Long doma @Override public List doInTransaction(TransactionStatus status) { // find or create the affinity group by name under this account/domain - AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); + AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal, DedicatedResources.Type.Host); if (group == null) { - s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); - throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); + logger.error("Unable to dedicate host due to, failed to create dedication affinity group"); + throw new CloudRuntimeException("Failed to dedicate host. Please contact Cloud Support."); } DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, null, hostId, null, null, group.getId()); try { @@ -594,7 +596,7 @@ public List doInTransaction(TransactionStatus status) { } dedicatedResource = _dedicatedDao.persist(dedicatedResource); } catch (Exception e) { - s_logger.error("Unable to dedicate host due to " + e.getMessage(), e); + logger.error("Unable to dedicate host due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate host. Please contact Cloud Support.", e); } @@ -606,7 +608,7 @@ public List doInTransaction(TransactionStatus status) { } - private AffinityGroup findOrCreateDedicatedAffinityGroup(Long domainId, Long accountId) { + private AffinityGroup findOrCreateDedicatedAffinityGroup(Long domainId, Long accountId, DedicatedResources.Type dedicatedResource) { if (domainId == null) { return null; } @@ -623,24 +625,25 @@ private AffinityGroup findOrCreateDedicatedAffinityGroup(Long domainId, Long acc if (group != null) { return group; } - // default to a groupname with account/domain information - affinityGroupName = "DedicatedGrp-" + accountName; + // defaults to a groupName with resourceType and account/domain information + affinityGroupName = String.format("Dedicated%sGrp-%s", dedicatedResource, accountName); } else { // domain level group group = _affinityGroupDao.findDomainLevelGroupByType(domainId, "ExplicitDedication"); if (group != null) { return group; } - // default to a groupname with account/domain information + + // defaults to a groupName with resourceType and account/domain information String domainName = _domainDao.findById(domainId).getName(); - affinityGroupName = "DedicatedGrp-domain-" + domainName; + affinityGroupName = String.format("Dedicated%sGrp-domain-%s", dedicatedResource, domainName); } - group = _affinityGroupService.createAffinityGroup(accountName, null, domainId, affinityGroupName, "ExplicitDedication", "dedicated resources group"); + String description = String.format("Dedicated %s group", StringUtils.lowerCase(dedicatedResource.toString())); + group = _affinityGroupService.createAffinityGroup(accountName, null, domainId, affinityGroupName, "ExplicitDedication", description); return group; - } private List getVmsOnHost(long hostId) { @@ -665,7 +668,7 @@ private boolean checkHostSuitabilityForExplicitDedication(Long accountId, List - + diff --git a/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java b/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java index cd1d5018529e..c13b8b12d9da 100644 --- a/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java +++ b/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java @@ -18,7 +18,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; import java.io.IOException; @@ -32,7 +32,6 @@ import org.apache.cloudstack.dedicated.DedicatedResourceManagerImpl; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.test.utils.SpringUtils; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -74,7 +73,6 @@ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) public class DedicatedApiUnitTest { - public static final Logger s_logger = Logger.getLogger(DedicatedApiUnitTest.class); @Inject DedicatedResourceManagerImpl _dedicatedService = new DedicatedResourceManagerImpl(); @@ -162,7 +160,7 @@ public void runDedicateZoneTest() { List result = _dedicatedService.dedicateZone(10L, domainId, accountName); Assert.assertNotNull(result); } catch (Exception e) { - s_logger.info("exception in testing dedication of zone " + logger.info("exception in testing dedication of zone " + e.toString()); } } @@ -176,7 +174,7 @@ public void runDedicatePodTest() { List result = _dedicatedService.dedicatePod(10L, domainId, accountName); Assert.assertNotNull(result); } catch (Exception e) { - s_logger.info("exception in testing dedication of pod " + logger.info("exception in testing dedication of pod " + e.toString()); } } @@ -189,7 +187,7 @@ public void runDedicateClusterTest() { List result = _dedicatedService.dedicateCluster(10L, domainId, accountName); Assert.assertNotNull(result); } catch (Exception e) { - s_logger.info("exception in testing dedication of cluster " + logger.info("exception in testing dedication of cluster " + e.toString()); } } @@ -205,7 +203,7 @@ public void runDedicateHostTest() { List result = _dedicatedService.dedicateHost(10L, domainId, accountName); Assert.assertNotNull(result); } catch (Exception e) { - s_logger.info("exception in testing dedication of host " + logger.info("exception in testing dedication of host " + e.toString()); } } diff --git a/plugins/deployment-planners/implicit-dedication/pom.xml b/plugins/deployment-planners/implicit-dedication/pom.xml index 0fc8f8e602cb..b9f8be5d08a3 100644 --- a/plugins/deployment-planners/implicit-dedication/pom.xml +++ b/plugins/deployment-planners/implicit-dedication/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/deployment-planners/implicit-dedication/src/main/java/com/cloud/deploy/ImplicitDedicationPlanner.java b/plugins/deployment-planners/implicit-dedication/src/main/java/com/cloud/deploy/ImplicitDedicationPlanner.java index 2c5a72498bc5..bd1bcf061013 100644 --- a/plugins/deployment-planners/implicit-dedication/src/main/java/com/cloud/deploy/ImplicitDedicationPlanner.java +++ b/plugins/deployment-planners/implicit-dedication/src/main/java/com/cloud/deploy/ImplicitDedicationPlanner.java @@ -25,7 +25,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.configuration.Config; import com.cloud.exception.InsufficientServerCapacityException; @@ -43,7 +42,6 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements DeploymentClusterPlanner { - private static final Logger s_logger = Logger.getLogger(ImplicitDedicationPlanner.class); @Inject private ServiceOfferingDao serviceOfferingDao; @@ -158,12 +156,12 @@ private boolean checkHostSuitabilityForImplicitDedication(Long accountId, List org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/deployment-planners/user-concentrated-pod/src/main/java/com/cloud/deploy/UserConcentratedPodPlanner.java b/plugins/deployment-planners/user-concentrated-pod/src/main/java/com/cloud/deploy/UserConcentratedPodPlanner.java index bc56740eec80..c8ec78dc8f9c 100644 --- a/plugins/deployment-planners/user-concentrated-pod/src/main/java/com/cloud/deploy/UserConcentratedPodPlanner.java +++ b/plugins/deployment-planners/user-concentrated-pod/src/main/java/com/cloud/deploy/UserConcentratedPodPlanner.java @@ -21,14 +21,12 @@ import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; import com.cloud.vm.VirtualMachineProfile; public class UserConcentratedPodPlanner extends FirstFitPlanner implements DeploymentClusterPlanner { - private static final Logger s_logger = Logger.getLogger(UserConcentratedPodPlanner.class); /** * This method should reorder the given list of Cluster Ids by applying any necessary heuristic @@ -62,14 +60,14 @@ private List applyUserConcentrationPodHeuristicToClusters(long zoneId, Lis private List reorderClustersByPods(List clusterIds, List podIds) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Reordering cluster list as per pods ordered by user concentration"); + if (logger.isDebugEnabled()) { + logger.debug("Reordering cluster list as per pods ordered by user concentration"); } Map> podClusterMap = clusterDao.getPodClusterIdMap(clusterIds); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Pod To cluster Map is: " + podClusterMap); + if (logger.isTraceEnabled()) { + logger.trace("Pod To cluster Map is: " + podClusterMap); } List reorderedClusters = new ArrayList(); @@ -88,22 +86,22 @@ private List reorderClustersByPods(List clusterIds, List podId } reorderedClusters.addAll(clusterIds); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Reordered cluster list: " + reorderedClusters); + if (logger.isTraceEnabled()) { + logger.trace("Reordered cluster list: " + reorderedClusters); } return reorderedClusters; } protected List listPodsByUserConcentration(long zoneId, long accountId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying UserConcentratedPod heuristic for account: " + accountId); + if (logger.isDebugEnabled()) { + logger.debug("Applying UserConcentratedPod heuristic for account: " + accountId); } List prioritizedPods = vmDao.listPodIdsHavingVmsforAccount(zoneId, accountId); - if (s_logger.isTraceEnabled()) { - s_logger.trace("List of pods to be considered, after applying UserConcentratedPod heuristic: " + prioritizedPods); + if (logger.isTraceEnabled()) { + logger.trace("List of pods to be considered, after applying UserConcentratedPod heuristic: " + prioritizedPods); } return prioritizedPods; diff --git a/plugins/deployment-planners/user-concentrated-pod/src/main/resources/META-INF/cloudstack/user-concentrated-pod/spring-user-concentrated-pod-context.xml b/plugins/deployment-planners/user-concentrated-pod/src/main/resources/META-INF/cloudstack/user-concentrated-pod/spring-user-concentrated-pod-context.xml index 89246a49585a..d48bc85fde3f 100644 --- a/plugins/deployment-planners/user-concentrated-pod/src/main/resources/META-INF/cloudstack/user-concentrated-pod/spring-user-concentrated-pod-context.xml +++ b/plugins/deployment-planners/user-concentrated-pod/src/main/resources/META-INF/cloudstack/user-concentrated-pod/spring-user-concentrated-pod-context.xml @@ -31,5 +31,5 @@ - + diff --git a/plugins/deployment-planners/user-dispersing/pom.xml b/plugins/deployment-planners/user-dispersing/pom.xml index 7f07caca6848..bbd74bf1a7a2 100644 --- a/plugins/deployment-planners/user-dispersing/pom.xml +++ b/plugins/deployment-planners/user-dispersing/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java b/plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java index 24bc061b2187..c5d81e9a51b8 100644 --- a/plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java +++ b/plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java @@ -25,7 +25,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.configuration.Config; import com.cloud.utils.NumbersUtil; @@ -34,7 +33,6 @@ public class UserDispersingPlanner extends FirstFitPlanner implements DeploymentClusterPlanner { - private static final Logger s_logger = Logger.getLogger(UserDispersingPlanner.class); /** * This method should reorder the given list of Cluster Ids by applying any necessary heuristic @@ -97,8 +95,8 @@ protected List reorderPods(Pair, Map> podCapacity } protected Pair, Map> listClustersByUserDispersion(long id, boolean isZone, long accountId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying Userdispersion heuristic to clusters for account: " + accountId); + if (logger.isDebugEnabled()) { + logger.debug("Applying Userdispersion heuristic to clusters for account: " + accountId); } Pair, Map> clusterIdsVmCountInfo; if (isZone) { @@ -106,19 +104,19 @@ protected Pair, Map> listClustersByUserDispersion(long } else { clusterIdsVmCountInfo = vmInstanceDao.listClusterIdsInPodByVmCount(id, accountId); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("List of clusters in ascending order of number of VMs: " + clusterIdsVmCountInfo.first()); + if (logger.isTraceEnabled()) { + logger.trace("List of clusters in ascending order of number of VMs: " + clusterIdsVmCountInfo.first()); } return clusterIdsVmCountInfo; } protected Pair, Map> listPodsByUserDispersion(long dataCenterId, long accountId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying Userdispersion heuristic to pods for account: " + accountId); + if (logger.isDebugEnabled()) { + logger.debug("Applying Userdispersion heuristic to pods for account: " + accountId); } Pair, Map> podIdsVmCountInfo = vmInstanceDao.listPodIdsInZoneByVmCount(dataCenterId, accountId); - if (s_logger.isTraceEnabled()) { - s_logger.trace("List of pods in ascending order of number of VMs: " + podIdsVmCountInfo.first()); + if (logger.isTraceEnabled()) { + logger.trace("List of pods in ascending order of number of VMs: " + podIdsVmCountInfo.first()); } return podIdsVmCountInfo; @@ -130,25 +128,25 @@ private List orderByApplyingWeights(Pair, Map> ca Map capacityMap = capacityInfo.second(); Map vmCountMap = vmCountInfo.second(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Capacity Id list: " + capacityOrderedIds + " , capacityMap:" + capacityMap); + if (logger.isTraceEnabled()) { + logger.trace("Capacity Id list: " + capacityOrderedIds + " , capacityMap:" + capacityMap); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Vm Count Id list: " + vmCountOrderedIds + " , vmCountMap:" + vmCountMap); + if (logger.isTraceEnabled()) { + logger.trace("Vm Count Id list: " + vmCountOrderedIds + " , vmCountMap:" + vmCountMap); } List idsReorderedByWeights = new ArrayList(); float capacityWeight = (1.0f - _userDispersionWeight); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying userDispersionWeight: " + _userDispersionWeight); + if (logger.isDebugEnabled()) { + logger.debug("Applying userDispersionWeight: " + _userDispersionWeight); } //normalize the vmCountMap LinkedHashMap normalisedVmCountIdMap = new LinkedHashMap(); Long totalVmsOfAccount = vmInstanceDao.countRunningAndStartingByAccount(accountId); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Total VMs for account: " + totalVmsOfAccount); + if (logger.isDebugEnabled()) { + logger.debug("Total VMs for account: " + totalVmsOfAccount); } for (Long id : vmCountOrderedIds) { Double normalisedCount = vmCountMap.get(id) / totalVmsOfAccount; @@ -177,8 +175,8 @@ private List orderByApplyingWeights(Pair, Map> ca idsReorderedByWeights.addAll(idList); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Reordered Id list: " + idsReorderedByWeights); + if (logger.isTraceEnabled()) { + logger.trace("Reordered Id list: " + idsReorderedByWeights); } return idsReorderedByWeights; diff --git a/plugins/drs/cluster/balanced/pom.xml b/plugins/drs/cluster/balanced/pom.xml index f4fd9ec89b3a..743a5f2bc984 100644 --- a/plugins/drs/cluster/balanced/pom.xml +++ b/plugins/drs/cluster/balanced/pom.xml @@ -27,7 +27,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/drs/cluster/balanced/src/main/java/org/apache/cloudstack/cluster/Balanced.java b/plugins/drs/cluster/balanced/src/main/java/org/apache/cloudstack/cluster/Balanced.java index ea234c2b794e..c799ac872c00 100644 --- a/plugins/drs/cluster/balanced/src/main/java/org/apache/cloudstack/cluster/Balanced.java +++ b/plugins/drs/cluster/balanced/src/main/java/org/apache/cloudstack/cluster/Balanced.java @@ -24,7 +24,8 @@ import com.cloud.utils.Ternary; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.VirtualMachine; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.naming.ConfigurationException; import java.util.ArrayList; @@ -35,7 +36,7 @@ public class Balanced extends AdapterBase implements ClusterDrsAlgorithm { - private static final Logger logger = Logger.getLogger(Balanced.class); + private static final Logger logger = LogManager.getLogger(Balanced.class); @Override public boolean needsDrs(long clusterId, List> cpuList, diff --git a/plugins/drs/cluster/condensed/pom.xml b/plugins/drs/cluster/condensed/pom.xml index d0c5d7e58854..60b472bccb56 100644 --- a/plugins/drs/cluster/condensed/pom.xml +++ b/plugins/drs/cluster/condensed/pom.xml @@ -27,7 +27,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java b/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java index dc1546f9f6af..3a8befa628b1 100644 --- a/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java +++ b/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java @@ -24,7 +24,8 @@ import com.cloud.utils.Ternary; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.VirtualMachine; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.naming.ConfigurationException; import java.util.ArrayList; @@ -36,7 +37,7 @@ public class Condensed extends AdapterBase implements ClusterDrsAlgorithm { - private static final Logger logger = Logger.getLogger(Condensed.class); + private static final Logger logger = LogManager.getLogger(Condensed.class); @Override public boolean needsDrs(long clusterId, List> cpuList, diff --git a/plugins/event-bus/inmemory/pom.xml b/plugins/event-bus/inmemory/pom.xml index 6e763d19e894..be85e8afd8dc 100644 --- a/plugins/event-bus/inmemory/pom.xml +++ b/plugins/event-bus/inmemory/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/event-bus/inmemory/src/main/java/org/apache/cloudstack/mom/inmemory/InMemoryEventBus.java b/plugins/event-bus/inmemory/src/main/java/org/apache/cloudstack/mom/inmemory/InMemoryEventBus.java index b7d74df980f7..0c00c0639fd9 100644 --- a/plugins/event-bus/inmemory/src/main/java/org/apache/cloudstack/mom/inmemory/InMemoryEventBus.java +++ b/plugins/event-bus/inmemory/src/main/java/org/apache/cloudstack/mom/inmemory/InMemoryEventBus.java @@ -25,7 +25,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.events.Event; import org.apache.cloudstack.framework.events.EventBus; @@ -38,7 +37,6 @@ public class InMemoryEventBus extends ManagerBase implements EventBus { - private static final Logger s_logger = Logger.getLogger(InMemoryEventBus.class); private final static Map> subscribers; @@ -62,6 +60,8 @@ public UUID subscribe(EventTopic topic, EventSubscriber subscriber) throws Event if (subscriber == null || topic == null) { throw new EventBusException("Invalid EventSubscriber/EventTopic object passed."); } + logger.debug("subscribing '{}' to events of type '{}' from '{}'", subscriber.toString(), topic.getEventType(), topic.getEventSource()); + UUID subscriberId = UUID.randomUUID(); subscribers.put(subscriberId, new Pair(topic, subscriber)); @@ -70,6 +70,7 @@ public UUID subscribe(EventTopic topic, EventSubscriber subscriber) throws Event @Override public void unsubscribe(UUID subscriberId, EventSubscriber subscriber) throws EventBusException { + logger.debug("unsubscribing '{}'", subscriberId); if (subscriberId == null) { throw new EventBusException("Cannot unregister a null subscriberId."); } @@ -87,7 +88,9 @@ public void unsubscribe(UUID subscriberId, EventSubscriber subscriber) throws Ev @Override public void publish(Event event) throws EventBusException { + logger.trace("publish '{}'", event.getDescription()); if (subscribers == null || subscribers.isEmpty()) { + logger.trace("no subscribers, no publish"); return; // no subscriber to publish to, so just return } diff --git a/plugins/event-bus/kafka/pom.xml b/plugins/event-bus/kafka/pom.xml index 1377e8eeb29f..44014847548a 100644 --- a/plugins/event-bus/kafka/pom.xml +++ b/plugins/event-bus/kafka/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/event-bus/kafka/src/main/java/org/apache/cloudstack/mom/kafka/KafkaEventBus.java b/plugins/event-bus/kafka/src/main/java/org/apache/cloudstack/mom/kafka/KafkaEventBus.java index 17a58a5d2326..f2589d2d7d09 100644 --- a/plugins/event-bus/kafka/src/main/java/org/apache/cloudstack/mom/kafka/KafkaEventBus.java +++ b/plugins/event-bus/kafka/src/main/java/org/apache/cloudstack/mom/kafka/KafkaEventBus.java @@ -27,7 +27,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.events.Event; import org.apache.cloudstack.framework.events.EventBus; @@ -50,7 +49,6 @@ public class KafkaEventBus extends ManagerBase implements EventBus { private String _topic = null; private Producer _producer; - private static final Logger s_logger = Logger.getLogger(KafkaEventBus.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -89,19 +87,23 @@ public void setName(String name) { @Override public UUID subscribe(EventTopic topic, EventSubscriber subscriber) throws EventBusException { + logger.debug("subscribing '{}' to events of type '{}' from '{}'", subscriber.toString(), topic.getEventType(), topic.getEventSource()); + /* NOOP */ return UUID.randomUUID(); } @Override public void unsubscribe(UUID subscriberId, EventSubscriber subscriber) throws EventBusException { + logger.debug("unsubscribing '{}'", subscriberId); /* NOOP */ } @Override public void publish(Event event) throws EventBusException { - ProducerRecord record = new ProducerRecord(_topic, event.getResourceUUID(), event.getDescription()); - _producer.send(record); + logger.trace("publish '{}'", event.getDescription()); + ProducerRecord newRecord = new ProducerRecord<>(_topic, event.getResourceUUID(), event.getDescription()); + _producer.send(newRecord); } @Override diff --git a/plugins/event-bus/rabbitmq/pom.xml b/plugins/event-bus/rabbitmq/pom.xml index a0a11ae68158..1e04caf026f8 100644 --- a/plugins/event-bus/rabbitmq/pom.xml +++ b/plugins/event-bus/rabbitmq/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java b/plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java index f54c769908d8..e8067e75b406 100644 --- a/plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java +++ b/plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java @@ -34,7 +34,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.rabbitmq.client.BlockedListener; -import org.apache.log4j.Logger; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.AlreadyClosedException; @@ -97,7 +96,6 @@ public static void setUseSsl(String useSsl) { private ExecutorService executorService; private static DisconnectHandler disconnectHandler; private static BlockedConnectionHandler blockedConnectionHandler; - private static final Logger s_logger = Logger.getLogger(RabbitMQEventBus.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -187,11 +185,12 @@ public static void setRetryInterval(Integer retryInterval) { */ @Override public UUID subscribe(EventTopic topic, EventSubscriber subscriber) throws EventBusException { - if (subscriber == null || topic == null) { throw new EventBusException("Invalid EventSubscriber/EventTopic object passed."); } + logger.debug("subscribing '{}' to events of type '{}' from '{}'", subscriber.toString(), topic.getEventType(), topic.getEventSource()); + // create a UUID, that will be used for managing subscriptions and also used as queue name // for on the queue used for the subscriber on the AMQP broker UUID queueId = UUID.randomUUID(); @@ -240,9 +239,9 @@ public void handleDelivery(String queueName, Envelope envelope, AMQP.BasicProper s_subscribers.put(queueName, queueDetails); } catch (AlreadyClosedException closedException) { - s_logger.warn("Connection to AMQP service is lost. Subscription:" + queueName + " will be active after reconnection", closedException); + logger.warn("Connection to AMQP service is lost. Subscription:" + queueName + " will be active after reconnection", closedException); } catch (ConnectException connectException) { - s_logger.warn("Connection to AMQP service is lost. Subscription:" + queueName + " will be active after reconnection", connectException); + logger.warn("Connection to AMQP service is lost. Subscription:" + queueName + " will be active after reconnection", connectException); } catch (Exception e) { throw new EventBusException("Failed to subscribe to event due to " + e.getMessage()); } @@ -252,6 +251,7 @@ public void handleDelivery(String queueName, Envelope envelope, AMQP.BasicProper @Override public void unsubscribe(UUID subscriberId, EventSubscriber subscriber) throws EventBusException { + logger.debug("unsubscribing '{}'", subscriberId); try { String classname = subscriber.getClass().getName(); String queueName = UUID.nameUUIDFromBytes(classname.getBytes()).toString(); @@ -267,6 +267,7 @@ public void unsubscribe(UUID subscriberId, EventSubscriber subscriber) throws Ev // publish event on to the exchange created on AMQP server @Override public void publish(Event event) throws EventBusException { + logger.trace("publish '{}'", event.getDescription()); String routingKey = createRoutingKey(event); String eventDescription = event.getDescription(); @@ -362,7 +363,7 @@ private synchronized Connection getConnection() throws Exception { try { return createConnection(); } catch (KeyManagementException | NoSuchAlgorithmException | IOException | TimeoutException e) { - s_logger.error(String.format("Failed to create a connection to AMQP server [AMQP host:%s, port:%d] due to: %s", amqpHost, port, e)); + logger.error(String.format("Failed to create a connection to AMQP server [AMQP host:%s, port:%d] due to: %s", amqpHost, port, e)); throw e; } } else { @@ -399,7 +400,7 @@ private synchronized void closeConnection() { s_connection.close(); } } catch (Exception e) { - s_logger.warn("Failed to close connection to AMQP server due to " + e.getMessage()); + logger.warn("Failed to close connection to AMQP server due to " + e.getMessage()); } s_connection = null; } @@ -411,7 +412,7 @@ private synchronized void abortConnection() { try { s_connection.abort(); } catch (Exception e) { - s_logger.warn("Failed to abort connection due to " + e.getMessage()); + logger.warn("Failed to abort connection due to " + e.getMessage()); } s_connection = null; } @@ -428,7 +429,7 @@ private Channel createChannel(Connection connection) throws Exception { try { return connection.createChannel(); } catch (java.io.IOException exception) { - s_logger.warn("Failed to create a channel due to " + exception.getMessage()); + logger.warn("Failed to create a channel due to " + exception.getMessage()); throw exception; } } @@ -437,7 +438,7 @@ private void createExchange(Channel channel, String exchangeName) throws Excepti try { channel.exchangeDeclare(exchangeName, "topic", true); } catch (java.io.IOException exception) { - s_logger.error("Failed to create exchange" + exchangeName + " on RabbitMQ server"); + logger.error("Failed to create exchange" + exchangeName + " on RabbitMQ server"); throw exception; } } @@ -447,7 +448,7 @@ private void publishEventToExchange(Channel channel, String exchangeName, String byte[] messageBodyBytes = eventDescription.getBytes(); channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes); } catch (Exception e) { - s_logger.error("Failed to publish event " + routingKey + " on exchange " + exchangeName + " of message broker due to " + e.getMessage()); + logger.error("Failed to publish event " + routingKey + " on exchange " + exchangeName + " of message broker due to " + e.getMessage()); throw e; } } @@ -500,7 +501,7 @@ public synchronized boolean stop() { channel.queueDelete(queueName); channel.abort(); } catch (IOException ioe) { - s_logger.warn("Failed to delete queue: " + queueName + " on AMQP server due to " + ioe.getMessage()); + logger.warn("Failed to delete queue: " + queueName + " on AMQP server due to " + ioe.getMessage()); } } } @@ -514,14 +515,14 @@ private class BlockedConnectionHandler implements BlockedListener { @Override public void handleBlocked(String reason) throws IOException { - s_logger.error("rabbitmq connection is blocked with reason: " + reason); + logger.error("rabbitmq connection is blocked with reason: " + reason); closeConnection(); throw new CloudRuntimeException("unblocking the parent thread as publishing to rabbitmq server is blocked with reason: " + reason); } @Override public void handleUnblocked() throws IOException { - s_logger.info("rabbitmq connection in unblocked"); + logger.info("rabbitmq connection in unblocked"); } } // logic to deal with loss of connection to AMQP server @@ -538,7 +539,7 @@ public void shutdownCompleted(ShutdownSignalException shutdownSignalException) { } abortConnection(); // disconnected to AMQP server, so abort the connection and channels - s_logger.warn("Connection has been shutdown by AMQP server. Attempting to reconnect."); + logger.warn("Connection has been shutdown by AMQP server. Attempting to reconnect."); // initiate re-connect process ReconnectionTask reconnect = new ReconnectionTask(); @@ -616,7 +617,7 @@ public void handleDelivery(String queueName, Envelope envelope, AMQP.BasicProper s_subscribers.put(subscriberId, subscriberDetails); } } catch (Exception e) { - s_logger.warn("Failed to recreate queues and binding for the subscribers due to " + e.getMessage()); + logger.warn("Failed to recreate queues and binding for the subscribers due to " + e.getMessage()); } } return; diff --git a/plugins/event-bus/webhook/pom.xml b/plugins/event-bus/webhook/pom.xml new file mode 100644 index 000000000000..278f4dc0ec59 --- /dev/null +++ b/plugins/event-bus/webhook/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + cloud-mom-webhook + Apache CloudStack Plugin - Webhook Event Bus + + org.apache.cloudstack + cloudstack-plugins + 4.20.0.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-framework-events + ${project.version} + + + org.apache.cloudstack + cloud-engine-api + ${project.version} + + + org.json + json + + + diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/Webhook.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/Webhook.java new file mode 100644 index 000000000000..1cc73ae31df3 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/Webhook.java @@ -0,0 +1,48 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import java.util.Date; + +import org.apache.cloudstack.acl.ControlledEntity; +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +public interface Webhook extends ControlledEntity, Identity, InternalIdentity { + public static final long ID_DUMMY = 0L; + public static final String NAME_DUMMY = "Test"; + enum State { + Enabled, Disabled; + }; + + enum Scope { + Local, Domain, Global; + }; + + long getId(); + String getName(); + String getDescription(); + State getState(); + long getDomainId(); + long getAccountId(); + String getPayloadUrl(); + String getSecretKey(); + boolean isSslVerification(); + Scope getScope(); + Date getCreated(); +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookApiService.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookApiService.java new file mode 100644 index 000000000000..edd77e5b414c --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookApiService.java @@ -0,0 +1,44 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.mom.webhook.api.command.user.CreateWebhookCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.DeleteWebhookCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.DeleteWebhookDeliveryCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.ExecuteWebhookDeliveryCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.ListWebhookDeliveriesCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.ListWebhooksCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.UpdateWebhookCmd; +import org.apache.cloudstack.mom.webhook.api.response.WebhookDeliveryResponse; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; + +import com.cloud.utils.component.PluggableService; +import com.cloud.utils.exception.CloudRuntimeException; + +public interface WebhookApiService extends PluggableService { + + ListResponse listWebhooks(ListWebhooksCmd cmd); + WebhookResponse createWebhook(CreateWebhookCmd cmd) throws CloudRuntimeException; + boolean deleteWebhook(DeleteWebhookCmd cmd) throws CloudRuntimeException; + WebhookResponse updateWebhook(UpdateWebhookCmd cmd) throws CloudRuntimeException; + WebhookResponse createWebhookResponse(long webhookId); + ListResponse listWebhookDeliveries(ListWebhookDeliveriesCmd cmd); + int deleteWebhookDelivery(DeleteWebhookDeliveryCmd cmd) throws CloudRuntimeException; + WebhookDeliveryResponse executeWebhookDelivery(ExecuteWebhookDeliveryCmd cmd) throws CloudRuntimeException; +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookApiServiceImpl.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookApiServiceImpl.java new file mode 100644 index 000000000000..187b140d5d84 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookApiServiceImpl.java @@ -0,0 +1,574 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.SecurityChecker; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.api.command.user.CreateWebhookCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.DeleteWebhookCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.DeleteWebhookDeliveryCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.ExecuteWebhookDeliveryCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.ListWebhookDeliveriesCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.ListWebhooksCmd; +import org.apache.cloudstack.mom.webhook.api.command.user.UpdateWebhookCmd; +import org.apache.cloudstack.mom.webhook.api.response.WebhookDeliveryResponse; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; +import org.apache.cloudstack.mom.webhook.dao.WebhookDao; +import org.apache.cloudstack.mom.webhook.dao.WebhookDeliveryDao; +import org.apache.cloudstack.mom.webhook.dao.WebhookDeliveryJoinDao; +import org.apache.cloudstack.mom.webhook.dao.WebhookJoinDao; +import org.apache.cloudstack.mom.webhook.vo.WebhookDeliveryJoinVO; +import org.apache.cloudstack.mom.webhook.vo.WebhookDeliveryVO; +import org.apache.cloudstack.mom.webhook.vo.WebhookJoinVO; +import org.apache.cloudstack.mom.webhook.vo.WebhookVO; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; + +import com.cloud.api.ApiResponseHelper; +import com.cloud.cluster.ManagementServerHostVO; +import com.cloud.cluster.dao.ManagementServerHostDao; +import com.cloud.domain.Domain; +import com.cloud.domain.dao.DomainDao; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.PermissionDeniedException; +import com.cloud.projects.Project; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.utils.Pair; +import com.cloud.utils.Ternary; +import com.cloud.utils.UriUtils; +import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.rest.HttpConstants; + +public class WebhookApiServiceImpl extends ManagerBase implements WebhookApiService { + + @Inject + AccountManager accountManager; + @Inject + DomainDao domainDao; + @Inject + WebhookDao webhookDao; + @Inject + WebhookJoinDao webhookJoinDao; + @Inject + WebhookDeliveryDao webhookDeliveryDao; + @Inject + WebhookDeliveryJoinDao webhookDeliveryJoinDao; + @Inject + ManagementServerHostDao managementServerHostDao; + @Inject + WebhookService webhookService; + + protected WebhookResponse createWebhookResponse(WebhookJoinVO webhookVO) { + WebhookResponse response = new WebhookResponse(); + response.setObjectName("webhook"); + response.setId(webhookVO.getUuid()); + response.setName(webhookVO.getName()); + response.setDescription(webhookVO.getDescription()); + ApiResponseHelper.populateOwner(response, webhookVO); + response.setState(webhookVO.getState().toString()); + response.setPayloadUrl(webhookVO.getPayloadUrl()); + response.setSecretKey(webhookVO.getSecretKey()); + response.setSslVerification(webhookVO.isSslVerification()); + response.setScope(webhookVO.getScope().toString()); + response.setCreated(webhookVO.getCreated()); + return response; + } + + protected List getIdsOfAccessibleWebhooks(Account caller) { + if (Account.Type.ADMIN.equals(caller.getType())) { + return new ArrayList<>(); + } + String domainPath = null; + if (Account.Type.DOMAIN_ADMIN.equals(caller.getType())) { + Domain domain = domainDao.findById(caller.getDomainId()); + domainPath = domain.getPath(); + } + List webhooks = webhookJoinDao.listByAccountOrDomain(caller.getId(), domainPath); + return webhooks.stream().map(WebhookJoinVO::getId).collect(Collectors.toList()); + } + + protected ManagementServerHostVO basicWebhookDeliveryApiCheck(Account caller, final Long id, final Long webhookId, + final Long managementServerId, final Date startDate, final Date endDate) { + if (id != null) { + WebhookDeliveryVO webhookDeliveryVO = webhookDeliveryDao.findById(id); + if (webhookDeliveryVO == null) { + throw new InvalidParameterValueException("Invalid ID specified"); + } + WebhookVO webhookVO = webhookDao.findById(webhookDeliveryVO.getWebhookId()); + if (webhookVO != null) { + accountManager.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, false, webhookVO); + } + } + if (webhookId != null) { + WebhookVO webhookVO = webhookDao.findById(webhookId); + if (webhookVO == null) { + throw new InvalidParameterValueException("Invalid Webhook specified"); + } + accountManager.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, false, webhookVO); + } + if (endDate != null && startDate != null && endDate.before(startDate)) { + throw new InvalidParameterValueException(String.format("Invalid %s specified", ApiConstants.END_DATE)); + } + ManagementServerHostVO managementServerHostVO = null; + if (managementServerId != null) { + if (!Account.Type.ADMIN.equals(caller.getType())) { + throw new PermissionDeniedException("Invalid parameter specified"); + } + managementServerHostVO = managementServerHostDao.findById(managementServerId); + if (managementServerHostVO == null) { + throw new InvalidParameterValueException("Invalid management server specified"); + } + } + return managementServerHostVO; + } + + protected WebhookDeliveryResponse createWebhookDeliveryResponse(WebhookDeliveryJoinVO webhookDeliveryVO) { + WebhookDeliveryResponse response = new WebhookDeliveryResponse(); + response.setObjectName(WebhookDelivery.class.getSimpleName().toLowerCase()); + response.setId(webhookDeliveryVO.getUuid()); + response.setEventId(webhookDeliveryVO.getEventUuid()); + response.setEventType(webhookDeliveryVO.getEventType()); + response.setWebhookId(webhookDeliveryVO.getWebhookUuId()); + response.setWebhookName(webhookDeliveryVO.getWebhookName()); + response.setManagementServerId(webhookDeliveryVO.getManagementServerUuId()); + response.setManagementServerName(webhookDeliveryVO.getManagementServerName()); + response.setHeaders(webhookDeliveryVO.getHeaders()); + response.setPayload(webhookDeliveryVO.getPayload()); + response.setSuccess(webhookDeliveryVO.isSuccess()); + response.setResponse(webhookDeliveryVO.getResponse()); + response.setStartTime(webhookDeliveryVO.getStartTime()); + response.setEndTime(webhookDeliveryVO.getEndTime()); + return response; + } + + protected WebhookDeliveryResponse createTestWebhookDeliveryResponse(WebhookDelivery webhookDelivery, + Webhook webhook) { + WebhookDeliveryResponse response = new WebhookDeliveryResponse(); + response.setObjectName(WebhookDelivery.class.getSimpleName().toLowerCase()); + response.setId(webhookDelivery.getUuid()); + response.setEventType(WebhookDelivery.TEST_EVENT_TYPE); + if (webhook != null) { + response.setWebhookId(webhook.getUuid()); + response.setWebhookName(webhook.getName()); + } + ManagementServerHostVO msHost = + managementServerHostDao.findByMsid(webhookDelivery.getManagementServerId()); + if (msHost != null) { + response.setManagementServerId(msHost.getUuid()); + response.setManagementServerName(msHost.getName()); + } + response.setHeaders(webhookDelivery.getHeaders()); + response.setPayload(webhookDelivery.getPayload()); + response.setSuccess(webhookDelivery.isSuccess()); + response.setResponse(webhookDelivery.getResponse()); + response.setStartTime(webhookDelivery.getStartTime()); + response.setEndTime(webhookDelivery.getEndTime()); + return response; + } + + /** + * @param cmd + * @return Account + */ + protected Account getOwner(final CreateWebhookCmd cmd) { + final Account caller = CallContext.current().getCallingAccount(); + return accountManager.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId()); + } + + protected String getNormalizedPayloadUrl(String payloadUrl) { + if (StringUtils.isBlank(payloadUrl) || payloadUrl.startsWith("http://") || payloadUrl.startsWith("https://")) { + return payloadUrl; + } + return String.format("http://%s", payloadUrl); + } + + protected void validateWebhookOwnerPayloadUrl(Account owner, String payloadUrl, Webhook currentWebhook) { + WebhookVO webhookVO = webhookDao.findByAccountAndPayloadUrl(owner.getId(), payloadUrl); + if (webhookVO == null) { + return; + } + if (currentWebhook != null && webhookVO.getId() == currentWebhook.getId()) { + return; + } + String error = String.format("Payload URL: %s is already in use by another webhook", payloadUrl); + logger.error(String.format("%s: %s for Account [%s]", error, webhookVO, owner)); + throw new InvalidParameterValueException(error); + } + + @Override + public ListResponse listWebhooks(ListWebhooksCmd cmd) { + final CallContext ctx = CallContext.current(); + final Account caller = ctx.getCallingAccount(); + final Long clusterId = cmd.getId(); + final String stateStr = cmd.getState(); + final String name = cmd.getName(); + final String keyword = cmd.getKeyword(); + final String scopeStr = cmd.getScope(); + List responsesList = new ArrayList<>(); + List permittedAccounts = new ArrayList<>(); + Ternary domainIdRecursiveListProject = + new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null); + accountManager.buildACLSearchParameters(caller, clusterId, cmd.getAccountName(), cmd.getProjectId(), + permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false); + Long domainId = domainIdRecursiveListProject.first(); + Boolean isRecursive = domainIdRecursiveListProject.second(); + Project.ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third(); + + + Filter searchFilter = new Filter(WebhookJoinVO.class, "id", true, cmd.getStartIndex(), + cmd.getPageSizeVal()); + SearchBuilder sb = webhookJoinDao.createSearchBuilder(); + accountManager.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); + sb.and("keyword", sb.entity().getName(), SearchCriteria.Op.LIKE); + sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); + sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ); + SearchCriteria sc = sb.create(); + accountManager.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, + listProjectResourcesCriteria); + Webhook.Scope scope = null; + if (StringUtils.isNotEmpty(scopeStr)) { + try { + scope = Webhook.Scope.valueOf(scopeStr); + } catch (IllegalArgumentException iae) { + throw new InvalidParameterValueException("Invalid scope specified"); + } + } + if ((Webhook.Scope.Global.equals(scope) && !Account.Type.ADMIN.equals(caller.getType())) || + (Webhook.Scope.Domain.equals(scope) && + !List.of(Account.Type.ADMIN, Account.Type.DOMAIN_ADMIN).contains(caller.getType()))) { + throw new InvalidParameterValueException(String.format("Scope %s can not be specified", scope)); + } + Webhook.State state = null; + if (StringUtils.isNotEmpty(stateStr)) { + try { + state = Webhook.State.valueOf(stateStr); + } catch (IllegalArgumentException iae) { + throw new InvalidParameterValueException("Invalid state specified"); + } + } + if (scope != null) { + sc.setParameters("scope", scope.name()); + } + if (state != null) { + sc.setParameters("state", state.name()); + } + if(keyword != null){ + sc.setParameters("keyword", "%" + keyword + "%"); + } + if (clusterId != null) { + sc.setParameters("id", clusterId); + } + if (name != null) { + sc.setParameters("name", name); + } + Pair, Integer> webhooksAndCount = webhookJoinDao.searchAndCount(sc, searchFilter); + for (WebhookJoinVO webhook : webhooksAndCount.first()) { + WebhookResponse response = createWebhookResponse(webhook); + responsesList.add(response); + } + ListResponse response = new ListResponse<>(); + response.setResponses(responsesList, webhooksAndCount.second()); + return response; + } + + @Override + public WebhookResponse createWebhook(CreateWebhookCmd cmd) throws CloudRuntimeException { + final Account owner = getOwner(cmd); + final String name = cmd.getName(); + final String description = cmd.getDescription(); + final String payloadUrl = getNormalizedPayloadUrl(cmd.getPayloadUrl()); + final String secretKey = cmd.getSecretKey(); + final boolean sslVerification = cmd.isSslVerification(); + final String scopeStr = cmd.getScope(); + final String stateStr = cmd.getState(); + Webhook.Scope scope = Webhook.Scope.Local; + if (StringUtils.isNotEmpty(scopeStr)) { + try { + scope = Webhook.Scope.valueOf(scopeStr); + } catch (IllegalArgumentException iae) { + throw new InvalidParameterValueException("Invalid scope specified"); + } + } + if ((Webhook.Scope.Global.equals(scope) && !Account.Type.ADMIN.equals(owner.getType())) || + (Webhook.Scope.Domain.equals(scope) && + !List.of(Account.Type.ADMIN, Account.Type.DOMAIN_ADMIN).contains(owner.getType()))) { + throw new InvalidParameterValueException( + String.format("Scope %s can not be specified for owner %s", scope, owner.getName())); + } + Webhook.State state = Webhook.State.Enabled; + if (StringUtils.isNotEmpty(stateStr)) { + try { + state = Webhook.State.valueOf(stateStr); + } catch (IllegalArgumentException iae) { + throw new InvalidParameterValueException("Invalid state specified"); + } + } + UriUtils.validateUrl(payloadUrl); + validateWebhookOwnerPayloadUrl(owner, payloadUrl, null); + URI uri = URI.create(payloadUrl); + if (sslVerification && !HttpConstants.HTTPS.equalsIgnoreCase(uri.getScheme())) { + throw new InvalidParameterValueException( + String.format("SSL verification can be specified only for HTTPS URLs, %s", payloadUrl)); + } + long domainId = owner.getDomainId(); + Long cmdDomainId = cmd.getDomainId(); + if (cmdDomainId != null && + List.of(Account.Type.ADMIN, Account.Type.DOMAIN_ADMIN).contains(owner.getType()) && + Webhook.Scope.Domain.equals(scope)) { + domainId = cmdDomainId; + } + WebhookVO webhook = new WebhookVO(name, description, state, domainId, owner.getId(), payloadUrl, secretKey, + sslVerification, scope); + webhook = webhookDao.persist(webhook); + return createWebhookResponse(webhook.getId()); + } + + @Override + public boolean deleteWebhook(DeleteWebhookCmd cmd) throws CloudRuntimeException { + final Account caller = CallContext.current().getCallingAccount(); + final long id = cmd.getId(); + Webhook webhook = webhookDao.findById(id); + if (webhook == null) { + throw new InvalidParameterValueException("Unable to find the webhook with the specified ID"); + } + accountManager.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, false, webhook); + return webhookDao.remove(id); + } + + @Override + public WebhookResponse updateWebhook(UpdateWebhookCmd cmd) throws CloudRuntimeException { + final Account caller = CallContext.current().getCallingAccount(); + final long id = cmd.getId(); + final String name = cmd.getName(); + final String description = cmd.getDescription(); + final String payloadUrl = getNormalizedPayloadUrl(cmd.getPayloadUrl()); + String secretKey = cmd.getSecretKey(); + final Boolean sslVerification = cmd.isSslVerification(); + final String scopeStr = cmd.getScope(); + final String stateStr = cmd.getState(); + WebhookVO webhook = webhookDao.findById(id); + if (webhook == null) { + throw new InvalidParameterValueException("Unable to find the webhook with the specified ID"); + } + accountManager.checkAccess(caller, SecurityChecker.AccessType.OperateEntry, false, webhook); + boolean updateNeeded = false; + if (StringUtils.isNotBlank(name)) { + webhook.setName(name); + updateNeeded = true; + } + if (description != null) { + webhook.setDescription(description); + updateNeeded = true; + } + if (StringUtils.isNotEmpty(stateStr)) { + try { + Webhook.State state = Webhook.State.valueOf(stateStr); + webhook.setState(state); + updateNeeded = true; + } catch (IllegalArgumentException iae) { + throw new InvalidParameterValueException("Invalid state specified"); + } + } + Account owner = accountManager.getAccount(webhook.getAccountId()); + if (StringUtils.isNotEmpty(scopeStr)) { + try { + Webhook.Scope scope = Webhook.Scope.valueOf(scopeStr); + if ((Webhook.Scope.Global.equals(scope) && !Account.Type.ADMIN.equals(owner.getType())) || + (Webhook.Scope.Domain.equals(scope) && + !List.of(Account.Type.ADMIN, Account.Type.DOMAIN_ADMIN).contains(owner.getType()))) { + throw new InvalidParameterValueException( + String.format("Scope %s can not be specified for owner %s", scope, owner.getName())); + } + webhook.setScope(scope); + updateNeeded = true; + } catch (IllegalArgumentException iae) { + throw new InvalidParameterValueException("Invalid scope specified"); + } + } + URI uri = URI.create(webhook.getPayloadUrl()); + if (StringUtils.isNotEmpty(payloadUrl)) { + UriUtils.validateUrl(payloadUrl); + validateWebhookOwnerPayloadUrl(owner, payloadUrl, webhook); + uri = URI.create(payloadUrl); + webhook.setPayloadUrl(payloadUrl); + updateNeeded = true; + } + if (sslVerification != null) { + if (Boolean.TRUE.equals(sslVerification) && !HttpConstants.HTTPS.equalsIgnoreCase(uri.getScheme())) { + throw new InvalidParameterValueException( + String.format("SSL verification can be specified only for HTTPS URLs, %s", payloadUrl)); + } + webhook.setSslVerification(sslVerification); + updateNeeded = true; + } + if (secretKey != null) { + if (StringUtils.isBlank(secretKey)) { + secretKey = null; + } + webhook.setSecretKey(secretKey); + updateNeeded = true; + } + if (updateNeeded && !webhookDao.update(id, webhook)) { + return null; + } + return createWebhookResponse(webhook.getId()); + } + + @Override + public WebhookResponse createWebhookResponse(long webhookId) { + WebhookJoinVO webhookVO = webhookJoinDao.findById(webhookId); + return createWebhookResponse(webhookVO); + } + + @Override + public ListResponse listWebhookDeliveries(ListWebhookDeliveriesCmd cmd) { + final CallContext ctx = CallContext.current(); + final Account caller = ctx.getCallingAccount(); + final Long id = cmd.getId(); + final Long webhookId = cmd.getWebhookId(); + final Long managementServerId = cmd.getManagementServerId(); + final String keyword = cmd.getKeyword(); + final Date startDate = cmd.getStartDate(); + final Date endDate = cmd.getEndDate(); + final String eventType = cmd.getEventType(); + List responsesList = new ArrayList<>(); + ManagementServerHostVO host = basicWebhookDeliveryApiCheck(caller, id, webhookId, managementServerId, + startDate, endDate); + + Filter searchFilter = new Filter(WebhookDeliveryJoinVO.class, "id", false, cmd.getStartIndex(), + cmd.getPageSizeVal()); + List webhookIds = new ArrayList<>(); + if (webhookId != null) { + webhookIds.add(webhookId); + } else { + webhookIds.addAll(getIdsOfAccessibleWebhooks(caller)); + } + Pair, Integer> deliveriesAndCount = + webhookDeliveryJoinDao.searchAndCountByListApiParameters(id, webhookIds, + (host != null ? host.getMsid() : null), keyword, startDate, endDate, eventType, searchFilter); + for (WebhookDeliveryJoinVO delivery : deliveriesAndCount.first()) { + WebhookDeliveryResponse response = createWebhookDeliveryResponse(delivery); + responsesList.add(response); + } + ListResponse response = new ListResponse<>(); + response.setResponses(responsesList, deliveriesAndCount.second()); + return response; + } + + @Override + public int deleteWebhookDelivery(DeleteWebhookDeliveryCmd cmd) throws CloudRuntimeException { + final CallContext ctx = CallContext.current(); + final Account caller = ctx.getCallingAccount(); + final Long id = cmd.getId(); + final Long webhookId = cmd.getWebhookId(); + final Long managementServerId = cmd.getManagementServerId(); + final Date startDate = cmd.getStartDate(); + final Date endDate = cmd.getEndDate(); + ManagementServerHostVO host = basicWebhookDeliveryApiCheck(caller, id, webhookId, managementServerId, + startDate, endDate); + int removed = webhookDeliveryDao.deleteByDeleteApiParams(id, webhookId, + (host != null ? host.getMsid() : null), startDate, endDate); + logger.info("{} webhook deliveries removed", removed); + return removed; + } + + @Override + public WebhookDeliveryResponse executeWebhookDelivery(ExecuteWebhookDeliveryCmd cmd) throws CloudRuntimeException { + final CallContext ctx = CallContext.current(); + final Account caller = ctx.getCallingAccount(); + final Long deliveryId = cmd.getId(); + final Long webhookId = cmd.getWebhookId(); + final String payloadUrl = getNormalizedPayloadUrl(cmd.getPayloadUrl()); + final String secretKey = cmd.getSecretKey(); + final Boolean sslVerification = cmd.isSslVerification(); + final String payload = cmd.getPayload(); + final Account owner = accountManager.finalizeOwner(caller, null, null, null); + + if (ObjectUtils.allNull(deliveryId, webhookId) && StringUtils.isBlank(payloadUrl)) { + throw new InvalidParameterValueException(String.format("One of the %s, %s or %s must be specified", + ApiConstants.ID, ApiConstants.WEBHOOK_ID, ApiConstants.PAYLOAD_URL)); + } + WebhookDeliveryVO existingDelivery = null; + WebhookVO webhook = null; + if (deliveryId != null) { + existingDelivery = webhookDeliveryDao.findById(deliveryId); + if (existingDelivery == null) { + throw new InvalidParameterValueException("Invalid webhook delivery specified"); + } + webhook = webhookDao.findById(existingDelivery.getWebhookId()); + } + if (StringUtils.isNotBlank(payloadUrl)) { + UriUtils.validateUrl(payloadUrl); + } + if (webhookId != null) { + webhook = webhookDao.findById(webhookId); + if (webhook == null) { + throw new InvalidParameterValueException("Invalid webhook specified"); + } + if (StringUtils.isNotBlank(payloadUrl)) { + webhook.setPayloadUrl(payloadUrl); + } + if (StringUtils.isNotBlank(secretKey)) { + webhook.setSecretKey(secretKey); + } + if (sslVerification != null) { + webhook.setSslVerification(Boolean.TRUE.equals(sslVerification)); + } + } + if (ObjectUtils.allNull(deliveryId, webhookId)) { + webhook = new WebhookVO(owner.getDomainId(), owner.getId(), payloadUrl, secretKey, + Boolean.TRUE.equals(sslVerification)); + } + WebhookDelivery webhookDelivery = webhookService.executeWebhookDelivery(existingDelivery, webhook, payload); + if (webhookDelivery.getId() != WebhookDelivery.ID_DUMMY) { + return createWebhookDeliveryResponse(webhookDeliveryJoinDao.findById(webhookDelivery.getId())); + } + return createTestWebhookDeliveryResponse(webhookDelivery, webhook); + } + + @Override + public List> getCommands() { + List> cmdList = new ArrayList<>(); + cmdList.add(CreateWebhookCmd.class); + cmdList.add(ListWebhooksCmd.class); + cmdList.add(UpdateWebhookCmd.class); + cmdList.add(DeleteWebhookCmd.class); + cmdList.add(ListWebhookDeliveriesCmd.class); + cmdList.add(DeleteWebhookDeliveryCmd.class); + cmdList.add(ExecuteWebhookDeliveryCmd.class); + return cmdList; + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookDelivery.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookDelivery.java new file mode 100644 index 000000000000..b24891539f9b --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookDelivery.java @@ -0,0 +1,39 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import java.util.Date; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +public interface WebhookDelivery extends Identity, InternalIdentity { + public static final long ID_DUMMY = 0L; + public static final String TEST_EVENT_TYPE = "TEST.WEBHOOK"; + + long getId(); + long getEventId(); + long getWebhookId(); + long getManagementServerId(); + String getHeaders(); + String getPayload(); + boolean isSuccess(); + String getResponse(); + Date getStartTime(); + Date getEndTime(); +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookDeliveryThread.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookDeliveryThread.java new file mode 100644 index 000000000000..ac840c00be32 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookDeliveryThread.java @@ -0,0 +1,287 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import javax.crypto.Mac; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; + +import org.apache.cloudstack.framework.async.AsyncCompletionCallback; +import org.apache.cloudstack.framework.async.AsyncRpcContext; +import org.apache.cloudstack.framework.events.Event; +import org.apache.cloudstack.storage.command.CommandResult; +import org.apache.commons.codec.DecoderException; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.TrustAllStrategy; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicHeader; +import org.apache.http.ssl.SSLContextBuilder; +import org.apache.http.util.EntityUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class WebhookDeliveryThread implements Runnable { + protected static Logger LOGGER = LogManager.getLogger(WebhookDeliveryThread.class); + + private static final String HEADER_X_CS_EVENT_ID = "X-CS-Event-ID"; + private static final String HEADER_X_CS_EVENT = "X-CS-Event"; + private static final String HEADER_X_CS_SIGNATURE = "X-CS-Signature"; + private static final String PREFIX_HEADER_USER_AGENT = "CS-Hookshot/"; + private final Webhook webhook; + private final Event event; + private CloseableHttpClient httpClient; + private String headers; + private String payload; + private String response; + private Date startTime; + private int deliveryTries = 3; + private int deliveryTimeout = 10; + + AsyncCompletionCallback callback; + + protected boolean isValidJson(String json) { + try { + new JSONObject(json); + } catch (JSONException ex) { + try { + new JSONArray(json); + } catch (JSONException ex1) { + return false; + } + } + return true; + } + + protected void setHttpClient() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + if (webhook.isSslVerification()) { + httpClient = HttpClients.createDefault(); + return; + } + httpClient = HttpClients + .custom() + .setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, + TrustAllStrategy.INSTANCE).build()) + .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) + .build(); + } + + protected HttpPost getBasicHttpPostRequest() throws URISyntaxException { + final URI uri = new URI(webhook.getPayloadUrl()); + HttpPost request = new HttpPost(); + RequestConfig.Builder requestConfig = RequestConfig.custom(); + requestConfig.setConnectTimeout(deliveryTimeout * 1000); + requestConfig.setConnectionRequestTimeout(deliveryTimeout * 1000); + requestConfig.setSocketTimeout(deliveryTimeout * 1000); + request.setConfig(requestConfig.build()); + request.setURI(uri); + return request; + } + + protected void updateRequestHeaders(HttpPost request) throws DecoderException, NoSuchAlgorithmException, + InvalidKeyException { + request.addHeader(HEADER_X_CS_EVENT_ID, event.getEventUuid()); + request.addHeader(HEADER_X_CS_EVENT, event.getEventType()); + request.setHeader(HttpHeaders.USER_AGENT, String.format("%s%s", PREFIX_HEADER_USER_AGENT, + event.getResourceAccountUuid())); + if (StringUtils.isNotBlank(webhook.getSecretKey())) { + request.addHeader(HEADER_X_CS_SIGNATURE, generateHMACSignature(payload, webhook.getSecretKey())); + } + List
    headers = new ArrayList<>(Arrays.asList(request.getAllHeaders())); + HttpEntity entity = request.getEntity(); + if (entity.getContentLength() > 0 && !request.containsHeader(HttpHeaders.CONTENT_LENGTH)) { + headers.add(new BasicHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(entity.getContentLength()))); + } + if (entity.getContentType() != null && !request.containsHeader(HttpHeaders.CONTENT_TYPE)) { + headers.add(entity.getContentType()); + } + if (entity.getContentEncoding() != null && !request.containsHeader(HttpHeaders.CONTENT_ENCODING)) { + headers.add(entity.getContentEncoding()); + } + this.headers = StringUtils.join(headers, "\n"); + } + + public WebhookDeliveryThread(Webhook webhook, Event event, + AsyncCompletionCallback callback) { + this.webhook = webhook; + this.event = event; + this.callback = callback; + } + + public void setDeliveryTries(int deliveryTries) { + this.deliveryTries = deliveryTries; + } + + public void setDeliveryTimeout(int deliveryTimeout) { + this.deliveryTimeout = deliveryTimeout; + } + + @Override + public void run() { + LOGGER.debug("Delivering event: {} for {}", event.getEventType(), webhook); + if (event == null) { + LOGGER.warn("Invalid event received for delivering to {}", webhook); + return; + } + payload = event.getDescription(); + LOGGER.trace("Payload: {}", payload); + int attempt = 0; + boolean success = false; + try { + setHttpClient(); + } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) { + response = String.format("Failed to initiate delivery due to : %s", e.getMessage()); + callback.complete(new WebhookDeliveryResult(headers, payload, success, response, new Date())); + return; + } + while (attempt < deliveryTries) { + attempt++; + if (delivery(attempt)) { + success = true; + break; + } + } + callback.complete(new WebhookDeliveryResult(headers, payload, success, response, startTime)); + } + + protected void updateResponseFromRequest(HttpEntity entity) { + try { + this.response = EntityUtils.toString(entity, StandardCharsets.UTF_8); + } catch (IOException e) { + LOGGER.error("Failed to parse response for event: {} for {}", + event.getEventType(), webhook); + this.response = ""; + } + } + + protected boolean delivery(int attempt) { + startTime = new Date(); + try { + HttpPost request = getBasicHttpPostRequest(); + StringEntity input = new StringEntity(payload, + isValidJson(payload) ? ContentType.APPLICATION_JSON : ContentType.TEXT_PLAIN); + request.setEntity(input); + updateRequestHeaders(request); + LOGGER.trace("Delivering event: {} for {} with timeout: {}, " + + "attempt #{}", event.getEventType(), webhook, + deliveryTimeout, attempt); + final CloseableHttpResponse response = httpClient.execute(request); + updateResponseFromRequest(response.getEntity()); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + LOGGER.trace("Successfully delivered event: {} for {}", + event.getEventType(), webhook); + return true; + } + } catch (URISyntaxException | IOException | DecoderException | NoSuchAlgorithmException | + InvalidKeyException e) { + LOGGER.warn("Failed to deliver {}, in attempt #{} due to: {}", + webhook, attempt, e.getMessage()); + response = String.format("Failed due to : %s", e.getMessage()); + } + return false; + } + + public static String generateHMACSignature(String data, String key) + throws InvalidKeyException, NoSuchAlgorithmException, DecoderException { + Mac mac = Mac.getInstance("HMACSHA256"); + SecretKey secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), mac.getAlgorithm()); + mac.init(secretKey); + byte[] dataAsBytes = data.getBytes(StandardCharsets.UTF_8); + byte[] encodedText = mac.doFinal(dataAsBytes); + return new String(Base64.encodeBase64(encodedText)).trim(); + } + + public static class WebhookDeliveryContext extends AsyncRpcContext { + private final Long eventId; + private final Long ruleId; + + public WebhookDeliveryContext(AsyncCompletionCallback callback, Long eventId, Long ruleId) { + super(callback); + this.eventId = eventId; + this.ruleId = ruleId; + } + + public Long getEventId() { + return eventId; + } + + public Long getRuleId() { + return ruleId; + } + } + + public static class WebhookDeliveryResult extends CommandResult { + private final String headers; + private final String payload; + private final Date starTime; + private final Date endTime; + + public WebhookDeliveryResult(String headers, String payload, boolean success, String response, Date starTime) { + super(); + this.headers = headers; + this.payload = payload; + this.setResult(response); + this.setSuccess(success); + this.starTime = starTime; + this.endTime = new Date(); + } + + public String getHeaders() { + return headers; + } + + public String getPayload() { + return payload; + } + + public Date getStarTime() { + return starTime; + } + + public Date getEndTime() { + return endTime; + } + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookEventBus.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookEventBus.java new file mode 100644 index 000000000000..c2dade843618 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookEventBus.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cloudstack.mom.webhook; + +import java.util.Map; +import java.util.UUID; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.framework.events.Event; +import org.apache.cloudstack.framework.events.EventBus; +import org.apache.cloudstack.framework.events.EventBusException; +import org.apache.cloudstack.framework.events.EventSubscriber; +import org.apache.cloudstack.framework.events.EventTopic; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.cloud.utils.component.ManagerBase; +import com.google.gson.Gson; + +public class WebhookEventBus extends ManagerBase implements EventBus { + + protected static Logger LOGGER = LogManager.getLogger(WebhookEventBus.class); + private static Gson gson; + + @Inject + WebhookService webhookService; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + _name = name; + return true; + } + + @Override + public void setName(String name) { + _name = name; + } + + @Override + public UUID subscribe(EventTopic topic, EventSubscriber subscriber) throws EventBusException { + /* NOOP */ + return UUID.randomUUID(); + } + + @Override + public void unsubscribe(UUID subscriberId, EventSubscriber subscriber) throws EventBusException { + /* NOOP */ + } + + @Override + public void publish(Event event) throws EventBusException { + webhookService.handleEvent(event); + } + + @Override + public String getName() { + return _name; + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookService.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookService.java new file mode 100644 index 000000000000..5a5aced288d1 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookService.java @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.cloudstack.framework.events.Event; +import org.apache.cloudstack.framework.events.EventBusException; + +import com.cloud.utils.component.PluggableService; +import com.cloud.utils.exception.CloudRuntimeException; + +public interface WebhookService extends PluggableService, Configurable { + + ConfigKey WebhookDeliveryTimeout = new ConfigKey<>("Advanced", Integer.class, + "webhook.delivery.timeout", "10", + "Wait timeout (in seconds) for a webhook delivery delivery", + true, ConfigKey.Scope.Domain); + + ConfigKey WebhookDeliveryTries = new ConfigKey<>("Advanced", Integer.class, + "webhook.delivery.tries", "3", + "Number of tries to be made for a webhook delivery", + true, ConfigKey.Scope.Domain); + + ConfigKey WebhookDeliveryThreadPoolSize = new ConfigKey<>("Advanced", Integer.class, + "webhook.delivery.thread.pool.size", "5", + "Size of the thread pool for webhook deliveries", + false, ConfigKey.Scope.Global); + + ConfigKey WebhookDeliveriesLimit = new ConfigKey<>("Advanced", Integer.class, + "webhook.deliveries.limit", "10", + "Limit for the number of deliveries to keep in DB per webhook", + true, ConfigKey.Scope.Global); + + ConfigKey WebhookDeliveriesCleanupInitialDelay = new ConfigKey<>("Advanced", Integer.class, + "webhook.deliveries.cleanup.initial.delay", "180", + "Initial delay (in seconds) for webhook deliveries cleanup task", + false, ConfigKey.Scope.Global); + + ConfigKey WebhookDeliveriesCleanupInterval = new ConfigKey<>("Advanced", Integer.class, + "webhook.deliveries.cleanup.interval", "3600", + "Interval (in seconds) for cleaning up webhook deliveries", + false, ConfigKey.Scope.Global); + + void handleEvent(Event event) throws EventBusException; + WebhookDelivery executeWebhookDelivery(WebhookDelivery delivery, Webhook webhook, String payload) + throws CloudRuntimeException; +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookServiceImpl.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookServiceImpl.java new file mode 100644 index 000000000000..58b265a99c06 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/WebhookServiceImpl.java @@ -0,0 +1,354 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.acl.ControlledEntity; +import org.apache.cloudstack.framework.async.AsyncCallFuture; +import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; +import org.apache.cloudstack.framework.async.AsyncCompletionCallback; +import org.apache.cloudstack.framework.async.AsyncRpcContext; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.events.Event; +import org.apache.cloudstack.framework.events.EventBusException; +import org.apache.cloudstack.managed.context.ManagedContextRunnable; +import org.apache.cloudstack.mom.webhook.dao.WebhookDao; +import org.apache.cloudstack.mom.webhook.dao.WebhookDeliveryDao; +import org.apache.cloudstack.mom.webhook.vo.WebhookDeliveryVO; +import org.apache.cloudstack.mom.webhook.vo.WebhookVO; +import org.apache.cloudstack.utils.identity.ManagementServerNode; +import org.apache.cloudstack.webhook.WebhookHelper; +import org.apache.commons.lang3.StringUtils; + +import com.cloud.api.query.vo.EventJoinVO; +import com.cloud.cluster.ManagementServerHostVO; +import com.cloud.cluster.dao.ManagementServerHostDao; +import com.cloud.domain.dao.DomainDao; +import com.cloud.event.EventCategory; +import com.cloud.event.dao.EventJoinDao; +import com.cloud.server.ManagementService; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.utils.Pair; +import com.cloud.utils.component.ComponentContext; +import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.concurrency.NamedThreadFactory; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GlobalLock; +import com.cloud.utils.exception.CloudRuntimeException; + +public class WebhookServiceImpl extends ManagerBase implements WebhookService, WebhookHelper { + public static final String WEBHOOK_JOB_POOL_THREAD_PREFIX = "Webhook-Job-Executor"; + private ExecutorService webhookJobExecutor; + private ScheduledExecutorService webhookDeliveriesCleanupExecutor; + + @Inject + EventJoinDao eventJoinDao; + @Inject + WebhookDao webhookDao; + @Inject + protected WebhookDeliveryDao webhookDeliveryDao; + @Inject + ManagementServerHostDao managementServerHostDao; + @Inject + DomainDao domainDao; + @Inject + AccountManager accountManager; + + protected WebhookDeliveryThread getDeliveryJob(Event event, Webhook webhook, Pair configs) { + WebhookDeliveryThread.WebhookDeliveryContext context = + new WebhookDeliveryThread.WebhookDeliveryContext<>(null, event.getEventId(), webhook.getId()); + AsyncCallbackDispatcher caller = + AsyncCallbackDispatcher.create(this); + caller.setCallback(caller.getTarget().deliveryCompleteCallback(null, null)) + .setContext(context); + WebhookDeliveryThread job = new WebhookDeliveryThread(webhook, event, caller); + job = ComponentContext.inject(job); + job.setDeliveryTries(configs.first()); + job.setDeliveryTimeout(configs.second()); + return job; + } + + protected List getDeliveryJobs(Event event) throws EventBusException { + List jobs = new ArrayList<>(); + if (!EventCategory.ACTION_EVENT.getName().equals(event.getEventCategory())) { + return jobs; + } + if (event.getResourceAccountId() == null) { + logger.warn("Skipping delivering event [ID: {}, description: {}] to any webhook as account ID is missing", + event.getEventId(), event.getDescription()); + throw new EventBusException(String.format("Account missing for the event ID: %s", event.getEventUuid())); + } + List domainIds = new ArrayList<>(); + if (event.getResourceDomainId() != null) { + domainIds.add(event.getResourceDomainId()); + domainIds.addAll(domainDao.getDomainParentIds(event.getResourceDomainId())); + } + List webhooks = + webhookDao.listByEnabledForDelivery(event.getResourceAccountId(), domainIds); + Map> domainConfigs = new HashMap<>(); + for (WebhookVO webhook : webhooks) { + if (!domainConfigs.containsKey(webhook.getDomainId())) { + domainConfigs.put(webhook.getDomainId(), + new Pair<>(WebhookDeliveryTries.valueIn(webhook.getDomainId()), + WebhookDeliveryTimeout.valueIn(webhook.getDomainId()))); + } + Pair configs = domainConfigs.get(webhook.getDomainId()); + WebhookDeliveryThread job = getDeliveryJob(event, webhook, configs); + jobs.add(job); + } + return jobs; + } + + protected Runnable getManualDeliveryJob(WebhookDelivery existingDelivery, Webhook webhook, String payload, + AsyncCallFuture future) { + if (StringUtils.isBlank(payload)) { + payload = "{ \"CloudStack\": \"works!\" }"; + } + long eventId = Webhook.ID_DUMMY; + String eventType = WebhookDelivery.TEST_EVENT_TYPE; + String eventUuid = UUID.randomUUID().toString(); + String description = payload; + String resourceAccountUuid = null; + if (existingDelivery != null) { + EventJoinVO eventJoinVO = eventJoinDao.findById(existingDelivery.getEventId()); + eventId = eventJoinVO.getId(); + eventType = eventJoinVO.getType(); + eventUuid = eventJoinVO.getUuid(); + description = existingDelivery.getPayload(); + resourceAccountUuid = eventJoinVO.getAccountUuid(); + } else { + Account account = accountManager.getAccount(webhook.getAccountId()); + resourceAccountUuid = account.getUuid(); + } + Event event = new Event(ManagementService.Name, EventCategory.ACTION_EVENT.toString(), + eventType, null, null); + event.setEventId(eventId); + event.setEventUuid(eventUuid); + event.setDescription(description); + event.setResourceAccountUuid(resourceAccountUuid); + ManualDeliveryContext context = + new ManualDeliveryContext<>(null, webhook, future); + AsyncCallbackDispatcher caller = + AsyncCallbackDispatcher.create(this); + caller.setCallback(caller.getTarget().manualDeliveryCompleteCallback(null, null)) + .setContext(context); + WebhookDeliveryThread job = new WebhookDeliveryThread(webhook, event, caller); + job.setDeliveryTries(WebhookDeliveryTries.valueIn(webhook.getDomainId())); + job.setDeliveryTimeout(WebhookDeliveryTimeout.valueIn(webhook.getDomainId())); + return job; + } + + protected Void deliveryCompleteCallback( + AsyncCallbackDispatcher callback, + WebhookDeliveryThread.WebhookDeliveryContext context) { + WebhookDeliveryThread.WebhookDeliveryResult result = callback.getResult(); + WebhookDeliveryVO deliveryVO = new WebhookDeliveryVO(context.getEventId(), context.getRuleId(), + ManagementServerNode.getManagementServerId(), result.getHeaders(), result.getPayload(), + result.isSuccess(), result.getResult(), result.getStarTime(), result.getEndTime()); + webhookDeliveryDao.persist(deliveryVO); + return null; + } + + protected Void manualDeliveryCompleteCallback( + AsyncCallbackDispatcher callback, + ManualDeliveryContext context) { + WebhookDeliveryThread.WebhookDeliveryResult result = callback.getResult(); + context.future.complete(result); + return null; + } + + protected long cleanupOldWebhookDeliveries(long deliveriesLimit) { + Filter filter = new Filter(WebhookVO.class, "id", true, 0L, 50L); + Pair, Integer> webhooksAndCount = + webhookDao.searchAndCount(webhookDao.createSearchCriteria(), filter); + List webhooks = webhooksAndCount.first(); + long count = webhooksAndCount.second(); + long processed = 0; + do { + for (WebhookVO webhook : webhooks) { + webhookDeliveryDao.removeOlderDeliveries(webhook.getId(), deliveriesLimit); + processed++; + } + if (processed < count) { + filter.setOffset(processed); + webhooks = webhookDao.listAll(filter); + } + } while (processed < count); + return processed; + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + try { + webhookJobExecutor = Executors.newFixedThreadPool(WebhookDeliveryThreadPoolSize.value(), + new NamedThreadFactory(WEBHOOK_JOB_POOL_THREAD_PREFIX)); + webhookDeliveriesCleanupExecutor = Executors.newScheduledThreadPool(1, + new NamedThreadFactory("Webhook-Deliveries-Cleanup-Worker")); + } catch (final Exception e) { + throw new ConfigurationException("Unable to to configure WebhookServiceImpl"); + } + return true; + } + + @Override + public boolean start() { + long webhookDeliveriesCleanupInitialDelay = WebhookDeliveriesCleanupInitialDelay.value(); + long webhookDeliveriesCleanupInterval = WebhookDeliveriesCleanupInterval.value(); + logger.debug("Scheduling webhook deliveries cleanup task with initial delay={}s and interval={}s", + webhookDeliveriesCleanupInitialDelay, webhookDeliveriesCleanupInterval); + webhookDeliveriesCleanupExecutor.scheduleWithFixedDelay(new WebhookDeliveryCleanupWorker(), + webhookDeliveriesCleanupInitialDelay, webhookDeliveriesCleanupInterval, TimeUnit.SECONDS); + return true; + } + + @Override + public boolean stop() { + webhookJobExecutor.shutdown(); + return true; + } + + @Override + public String getConfigComponentName() { + return WebhookService.class.getName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[]{ + WebhookDeliveryTimeout, + WebhookDeliveryTries, + WebhookDeliveryThreadPoolSize, + WebhookDeliveriesLimit, + WebhookDeliveriesCleanupInitialDelay, + WebhookDeliveriesCleanupInterval + }; + } + + @Override + public void deleteWebhooksForAccount(long accountId) { + webhookDao.deleteByAccount(accountId); + } + + @Override + public List listWebhooksByAccount(long accountId) { + return webhookDao.listByAccount(accountId); + } + + @Override + public void handleEvent(Event event) throws EventBusException { + List jobs = getDeliveryJobs(event); + for(Runnable job : jobs) { + webhookJobExecutor.submit(job); + } + } + + @Override + public WebhookDelivery executeWebhookDelivery(WebhookDelivery delivery, Webhook webhook, String payload) + throws CloudRuntimeException { + AsyncCallFuture future = new AsyncCallFuture<>(); + Runnable job = getManualDeliveryJob(delivery, webhook, payload, future); + webhookJobExecutor.submit(job); + WebhookDeliveryThread.WebhookDeliveryResult result = null; + WebhookDeliveryVO webhookDeliveryVO; + try { + result = future.get(); + if (delivery != null) { + webhookDeliveryVO = new WebhookDeliveryVO(delivery.getEventId(), delivery.getWebhookId(), + ManagementServerNode.getManagementServerId(), result.getHeaders(), result.getPayload(), + result.isSuccess(), result.getResult(), result.getStarTime(), result.getEndTime()); + webhookDeliveryVO = webhookDeliveryDao.persist(webhookDeliveryVO); + } else { + webhookDeliveryVO = new WebhookDeliveryVO(ManagementServerNode.getManagementServerId(), + result.getHeaders(), result.getPayload(), result.isSuccess(), result.getResult(), + result.getStarTime(), result.getEndTime()); + } + } catch (InterruptedException | ExecutionException e) { + logger.error(String.format("Failed to execute test webhook delivery due to: %s", e.getMessage()), e); + throw new CloudRuntimeException("Failed to execute test webhook delivery"); + } + return webhookDeliveryVO; + } + + @Override + public List> getCommands() { + return new ArrayList<>(); + } + + static public class ManualDeliveryContext extends AsyncRpcContext { + final Webhook webhook; + final AsyncCallFuture future; + + public ManualDeliveryContext(AsyncCompletionCallback callback, Webhook webhook, + AsyncCallFuture future) { + super(callback); + this.webhook = webhook; + this.future = future; + } + + } + + public class WebhookDeliveryCleanupWorker extends ManagedContextRunnable { + + protected void runCleanupForLongestRunningManagementServer() { + try { + ManagementServerHostVO msHost = managementServerHostDao.findOneByLongestRuntime(); + if (msHost == null || (msHost.getMsid() != ManagementServerNode.getManagementServerId())) { + logger.debug("Skipping the webhook delivery cleanup task on this management server"); + return; + } + long deliveriesLimit = WebhookDeliveriesLimit.value(); + logger.debug("Clearing old deliveries for webhooks with limit={} using management server {}", + deliveriesLimit, msHost.getMsid()); + long processed = cleanupOldWebhookDeliveries(deliveriesLimit); + logger.debug("Cleared old deliveries with limit={} for {} webhooks", deliveriesLimit, processed); + } catch (Exception e) { + logger.warn("Cleanup task failed to cleanup old webhook deliveries", e); + } + } + + @Override + protected void runInContext() { + GlobalLock gcLock = GlobalLock.getInternLock("WebhookDeliveriesCleanup"); + try { + if (gcLock.lock(3)) { + try { + runCleanupForLongestRunningManagementServer(); + } finally { + gcLock.unlock(); + } + } + } finally { + gcLock.releaseRef(); + } + } + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/CreateWebhookCmd.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/CreateWebhookCmd.java new file mode 100644 index 000000000000..d3d2cf18e1fd --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/CreateWebhookCmd.java @@ -0,0 +1,167 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.acl.SecurityChecker; +import org.apache.cloudstack.api.ACL; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.Webhook; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; + +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "createWebhook", + description = "Creates a Webhook", + responseObject = WebhookResponse.class, + responseView = ResponseObject.ResponseView.Restricted, + entityType = {Webhook.class}, + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = true, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, + since = "4.20.0") +public class CreateWebhookCmd extends BaseCmd { + + @Inject + WebhookApiService webhookApiService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.NAME, type = BaseCmd.CommandType.STRING, required = true, description = "Name for the Webhook") + private String name; + + @Parameter(name = ApiConstants.DESCRIPTION, type = BaseCmd.CommandType.STRING, description = "Description for the Webhook") + private String description; + + @Parameter(name = ApiConstants.STATE, type = BaseCmd.CommandType.STRING, description = "State of the Webhook") + private String state; + + @ACL(accessType = SecurityChecker.AccessType.UseEntry) + @Parameter(name = ApiConstants.ACCOUNT, type = BaseCmd.CommandType.STRING, description = "An optional account for the" + + " Webhook. Must be used with domainId.") + private String accountName; + + @ACL(accessType = SecurityChecker.AccessType.UseEntry) + @Parameter(name = ApiConstants.DOMAIN_ID, type = BaseCmd.CommandType.UUID, entityType = DomainResponse.class, + description = "an optional domainId for the Webhook. If the account parameter is used, domainId must also be used.") + private Long domainId; + + @ACL(accessType = SecurityChecker.AccessType.UseEntry) + @Parameter(name = ApiConstants.PROJECT_ID, type = BaseCmd.CommandType.UUID, entityType = ProjectResponse.class, + description = "Project for the Webhook") + private Long projectId; + + @Parameter(name = ApiConstants.PAYLOAD_URL, + type = BaseCmd.CommandType.STRING, + required = true, + description = "Payload URL of the Webhook") + private String payloadUrl; + + @Parameter(name = ApiConstants.SECRET_KEY, type = BaseCmd.CommandType.STRING, description = "Secret key of the Webhook") + private String secretKey; + + @Parameter(name = ApiConstants.SSL_VERIFICATION, type = BaseCmd.CommandType.BOOLEAN, description = "If set to true then SSL verification will be done for the Webhook otherwise not") + private Boolean sslVerification; + + @Parameter(name = ApiConstants.SCOPE, type = BaseCmd.CommandType.STRING, description = "Scope of the Webhook", + authorized = {RoleType.Admin, RoleType.DomainAdmin}) + private String scope; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getState() { + return state; + } + + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + + public Long getProjectId() { + return projectId; + } + + public String getPayloadUrl() { + return payloadUrl; + } + + public String getSecretKey() { + return secretKey; + } + + public boolean isSslVerification() { + return Boolean.TRUE.equals(sslVerification); + } + + public String getScope() { + return scope; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccountId(); + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ServerApiException { + try { + WebhookResponse response = webhookApiService.createWebhook(this); + if (response == null) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create webhook"); + } + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookCmd.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookCmd.java new file mode 100644 index 000000000000..c9fb01580c2d --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookCmd.java @@ -0,0 +1,84 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.Webhook; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; + +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "deleteWebhook", + description = "Deletes a Webhook", + responseObject = SuccessResponse.class, + entityType = {Webhook.class}, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, + since = "4.20.0") +public class DeleteWebhookCmd extends BaseCmd { + + @Inject + WebhookApiService webhookApiService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, + entityType = WebhookResponse.class, + required = true, + description = "The ID of the Webhook") + private Long id; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public Long getId() { + return id; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccountId(); + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public void execute() throws ServerApiException { + try { + if (!webhookApiService.deleteWebhook(this)) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to delete webhook ID: %d", getId())); + } + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookDeliveryCmd.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookDeliveryCmd.java new file mode 100644 index 000000000000..dcfe71bf1713 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookDeliveryCmd.java @@ -0,0 +1,126 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.util.Date; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ManagementServerResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.WebhookDelivery; +import org.apache.cloudstack.mom.webhook.api.response.WebhookDeliveryResponse; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; + +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "deleteWebhookDelivery", + description = "Deletes Webhook delivery", + responseObject = SuccessResponse.class, + entityType = {WebhookDelivery.class}, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, + since = "4.20.0") +public class DeleteWebhookDeliveryCmd extends BaseCmd { + + @Inject + WebhookApiService webhookApiService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, + entityType = WebhookDeliveryResponse.class, + description = "The ID of the Webhook delivery") + private Long id; + + @Parameter(name = ApiConstants.WEBHOOK_ID, type = BaseCmd.CommandType.UUID, + entityType = WebhookResponse.class, + description = "The ID of the Webhook") + private Long webhookId; + + @Parameter(name = ApiConstants.MANAGEMENT_SERVER_ID, type = BaseCmd.CommandType.UUID, + entityType = ManagementServerResponse.class, + description = "The ID of the management server", + authorized = {RoleType.Admin}) + private Long managementServerId; + + @Parameter(name = ApiConstants.START_DATE, + type = CommandType.DATE, + description = "The start date range for the Webhook delivery " + + "(use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\"). " + + "All deliveries having start date equal to or after the specified date will be considered.") + private Date startDate; + + @Parameter(name = ApiConstants.END_DATE, + type = CommandType.DATE, + description = "The end date range for the Webhook delivery " + + "(use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\"). " + + "All deliveries having end date equal to or before the specified date will be considered.") + private Date endDate; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public Long getId() { + return id; + } + + public Long getWebhookId() { + return webhookId; + } + + public Long getManagementServerId() { + return managementServerId; + } + + public Date getStartDate() { + return startDate; + } + + public Date getEndDate() { + return endDate; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccountId(); + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public void execute() throws ServerApiException { + try { + webhookApiService.deleteWebhookDelivery(this); + SuccessResponse response = new SuccessResponse(getCommandName()); + setResponseObject(response); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ExecuteWebhookDeliveryCmd.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ExecuteWebhookDeliveryCmd.java new file mode 100644 index 000000000000..f31a5481376d --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ExecuteWebhookDeliveryCmd.java @@ -0,0 +1,132 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.WebhookDelivery; +import org.apache.cloudstack.mom.webhook.api.response.WebhookDeliveryResponse; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; + +import com.cloud.utils.exception.CloudRuntimeException; + + +@APICommand(name = "executeWebhookDelivery", + description = "Executes a Webhook delivery", + responseObject = WebhookDeliveryResponse.class, + entityType = {WebhookDelivery.class}, + requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, + since = "4.20.0") +public class ExecuteWebhookDeliveryCmd extends BaseCmd { + + @Inject + WebhookApiService webhookApiService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, + entityType = WebhookDeliveryResponse.class, + description = "The ID of the Webhook delivery for redelivery") + private Long id; + + @Parameter(name = ApiConstants.WEBHOOK_ID, type = CommandType.UUID, + entityType = WebhookResponse.class, + description = "The ID of the Webhook") + private Long webhookId; + + @Parameter(name = ApiConstants.PAYLOAD_URL, + type = BaseCmd.CommandType.STRING, + description = "Payload URL of the Webhook delivery") + private String payloadUrl; + + @Parameter(name = ApiConstants.SECRET_KEY, type = BaseCmd.CommandType.STRING, description = "Secret key of the Webhook delivery") + private String secretKey; + + @Parameter(name = ApiConstants.SSL_VERIFICATION, type = BaseCmd.CommandType.BOOLEAN, description = "If set to true then SSL verification will be done for the Webhook delivery otherwise not") + private Boolean sslVerification; + + @Parameter(name = ApiConstants.PAYLOAD, + type = BaseCmd.CommandType.STRING, + description = "Payload of the Webhook delivery") + private String payload; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public Long getId() { + return id; + } + + public Long getWebhookId() { + return webhookId; + } + + public String getPayloadUrl() { + return payloadUrl; + } + + public String getSecretKey() { + return secretKey; + } + + public Boolean isSslVerification() { + return sslVerification; + } + + public String getPayload() { + return payload; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccountId(); + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ServerApiException { + try { + WebhookDeliveryResponse response = webhookApiService.executeWebhookDelivery(this); + if (response == null) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to test Webhook delivery"); + } + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhookDeliveriesCmd.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhookDeliveriesCmd.java new file mode 100644 index 000000000000..466dad0d1224 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhookDeliveriesCmd.java @@ -0,0 +1,125 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.util.Date; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ManagementServerResponse; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.WebhookDelivery; +import org.apache.cloudstack.mom.webhook.api.response.WebhookDeliveryResponse; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; + +@APICommand(name = "listWebhookDeliveries", + description = "Lists Webhook deliveries", + responseObject = WebhookResponse.class, + responseView = ResponseObject.ResponseView.Restricted, + entityType = {WebhookDelivery.class}, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, + since = "4.20.0") +public class ListWebhookDeliveriesCmd extends BaseListCmd { + + @Inject + WebhookApiService webhookApiService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, + entityType = WebhookDeliveryResponse.class, + description = "The ID of the Webhook delivery") + private Long id; + + @Parameter(name = ApiConstants.WEBHOOK_ID, type = BaseCmd.CommandType.UUID, + entityType = WebhookResponse.class, + description = "The ID of the Webhook") + private Long webhookId; + + @Parameter(name = ApiConstants.MANAGEMENT_SERVER_ID, type = BaseCmd.CommandType.UUID, + entityType = ManagementServerResponse.class, + description = "The ID of the management server", + authorized = {RoleType.Admin}) + private Long managementServerId; + + @Parameter(name = ApiConstants.START_DATE, + type = CommandType.DATE, + description = "The start date range for the Webhook delivery " + + "(use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\"). " + + "All deliveries having start date equal to or after the specified date will be listed.") + private Date startDate; + + @Parameter(name = ApiConstants.END_DATE, + type = CommandType.DATE, + description = "The end date range for the Webhook delivery " + + "(use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\"). " + + "All deliveries having end date equal to or before the specified date will be listed.") + private Date endDate; + + @Parameter(name = ApiConstants.EVENT_TYPE, + type = CommandType.STRING, + description = "The event type of the Webhook delivery") + private String eventType; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public Long getId() { + return id; + } + + public Long getWebhookId() { + return webhookId; + } + + public Long getManagementServerId() { + return managementServerId; + } + + public Date getStartDate() { + return startDate; + } + + public Date getEndDate() { + return endDate; + } + + public String getEventType() { + return eventType; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public void execute() throws ServerApiException { + ListResponse response = webhookApiService.listWebhookDeliveries(this); + response.setResponseName(getCommandName()); + setResponseObject(response); + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhooksCmd.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhooksCmd.java new file mode 100644 index 000000000000..6510c308f6e7 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhooksCmd.java @@ -0,0 +1,95 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.Webhook; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; + +@APICommand(name = "listWebhooks", + description = "Lists Webhooks", + responseObject = WebhookResponse.class, + responseView = ResponseObject.ResponseView.Restricted, + entityType = {Webhook.class}, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, + since = "4.20.0") +public class ListWebhooksCmd extends BaseListProjectAndAccountResourcesCmd { + + @Inject + WebhookApiService webhookApiService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, + entityType = WebhookResponse.class, + description = "The ID of the Webhook") + private Long id; + + @Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "The state of the Webhook") + private String state; + + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The name of the Webhook") + private String name; + + @Parameter(name = ApiConstants.SCOPE, + type = CommandType.STRING, + description = "The scope of the Webhook", + authorized = {RoleType.Admin, RoleType.DomainAdmin}) + private String scope; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public Long getId() { + return id; + } + + public String getState() { + return state; + } + + public String getName() { + return name; + } + + public String getScope() { + return scope; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public void execute() throws ServerApiException { + ListResponse response = webhookApiService.listWebhooks(this); + response.setResponseName(getCommandName()); + setResponseObject(response); + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/UpdateWebhookCmd.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/UpdateWebhookCmd.java new file mode 100644 index 000000000000..c2be1d3f4fa2 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/command/user/UpdateWebhookCmd.java @@ -0,0 +1,136 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import javax.inject.Inject; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.Webhook; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; + +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "updateWebhook", + description = "Updates a Webhook", + responseObject = SuccessResponse.class, + entityType = {Webhook.class}, + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, + since = "4.20.0") +public class UpdateWebhookCmd extends BaseCmd { + + @Inject + WebhookApiService webhookApiService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, + entityType = WebhookResponse.class, + required = true, + description = "The ID of the Webhook") + private Long id; + @Parameter(name = ApiConstants.NAME, type = BaseCmd.CommandType.STRING, description = "Name for the Webhook") + private String name; + + @Parameter(name = ApiConstants.DESCRIPTION, type = BaseCmd.CommandType.STRING, description = "Description for the Webhook") + private String description; + + @Parameter(name = ApiConstants.STATE, type = BaseCmd.CommandType.STRING, description = "State of the Webhook") + private String state; + + @Parameter(name = ApiConstants.PAYLOAD_URL, + type = BaseCmd.CommandType.STRING, + description = "Payload URL of the Webhook") + private String payloadUrl; + + @Parameter(name = ApiConstants.SECRET_KEY, type = BaseCmd.CommandType.STRING, description = "Secret key of the Webhook") + private String secretKey; + + @Parameter(name = ApiConstants.SSL_VERIFICATION, type = BaseCmd.CommandType.BOOLEAN, description = "If set to true then SSL verification will be done for the Webhook otherwise not") + private Boolean sslVerification; + + @Parameter(name = ApiConstants.SCOPE, type = BaseCmd.CommandType.STRING, description = "Scope of the Webhook", + authorized = {RoleType.Admin, RoleType.DomainAdmin}) + private String scope; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public String getState() { + return state; + } + + public String getPayloadUrl() { + return payloadUrl; + } + + public String getSecretKey() { + return secretKey; + } + + public Boolean isSslVerification() { + return sslVerification; + } + + public String getScope() { + return scope; + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccountId(); + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public void execute() throws ServerApiException { + try { + WebhookResponse response = webhookApiService.updateWebhook(this); + if (response == null) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update Webhook"); + } + response.setResponseName(getCommandName()); + setResponseObject(response); + } catch (CloudRuntimeException ex) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); + } + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/response/WebhookDeliveryResponse.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/response/WebhookDeliveryResponse.java new file mode 100644 index 000000000000..6463fe9b48b7 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/response/WebhookDeliveryResponse.java @@ -0,0 +1,136 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.response; + + +import java.util.Date; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.mom.webhook.WebhookDelivery; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +@EntityReference(value = {WebhookDelivery.class}) +public class WebhookDeliveryResponse extends BaseResponse { + @SerializedName(ApiConstants.ID) + @Param(description = "The ID of the Webhook delivery") + private String id; + + @SerializedName(ApiConstants.EVENT_ID) + @Param(description = "The ID of the event") + private String eventId; + + @SerializedName(ApiConstants.EVENT_TYPE) + @Param(description = "The type of the event") + private String eventType; + + @SerializedName(ApiConstants.WEBHOOK_ID) + @Param(description = "The ID of the Webhook") + private String webhookId; + + @SerializedName(ApiConstants.WEBHOOK_NAME) + @Param(description = "The name of the Webhook") + private String webhookName; + + @SerializedName(ApiConstants.MANAGEMENT_SERVER_ID) + @Param(description = "The ID of the management server which executed delivery") + private String managementServerId; + + @SerializedName(ApiConstants.MANAGEMENT_SERVER_NAME) + @Param(description = "The name of the management server which executed delivery") + private String managementServerName; + + @SerializedName(ApiConstants.HEADERS) + @Param(description = "The headers of the webhook delivery") + private String headers; + + @SerializedName(ApiConstants.PAYLOAD) + @Param(description = "The payload of the webhook delivery") + private String payload; + + @SerializedName(ApiConstants.SUCCESS) + @Param(description = "Whether Webhook delivery succeeded or not") + private boolean success; + + @SerializedName(ApiConstants.RESPONSE) + @Param(description = "The response of the webhook delivery") + private String response; + + @SerializedName(ApiConstants.START_DATE) + @Param(description = "The start time of the Webhook delivery") + private Date startTime; + + @SerializedName(ApiConstants.END_DATE) + @Param(description = "The end time of the Webhook delivery") + private Date endTime; + + public void setId(String id) { + this.id = id; + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public void setWebhookId(String webhookId) { + this.webhookId = webhookId; + } + + public void setWebhookName(String webhookName) { + this.webhookName = webhookName; + } + + public void setManagementServerId(String managementServerId) { + this.managementServerId = managementServerId; + } + + public void setManagementServerName(String managementServerName) { + this.managementServerName = managementServerName; + } + + public void setHeaders(String headers) { + this.headers = headers; + } + + public void setPayload(String payload) { + this.payload = payload; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public void setResponse(String response) { + this.response = response; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/response/WebhookResponse.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/response/WebhookResponse.java new file mode 100644 index 000000000000..5e1cca361384 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/api/response/WebhookResponse.java @@ -0,0 +1,158 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.response; + +import java.util.Date; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.api.response.ControlledViewEntityResponse; +import org.apache.cloudstack.mom.webhook.Webhook; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +@EntityReference(value = {Webhook.class}) +public class WebhookResponse extends BaseResponse implements ControlledViewEntityResponse { + @SerializedName(ApiConstants.ID) + @Param(description = "The ID of the Webhook") + private String id; + + @SerializedName(ApiConstants.NAME) + @Param(description = "The name of the Webhook") + private String name; + + @SerializedName(ApiConstants.DESCRIPTION) + @Param(description = "The description of the Webhook") + private String description; + + @SerializedName(ApiConstants.STATE) + @Param(description = "The state of the Webhook") + private String state; + + @SerializedName(ApiConstants.DOMAIN_ID) + @Param(description = "The ID of the domain in which the Webhook exists") + private String domainId; + + @SerializedName(ApiConstants.DOMAIN) + @Param(description = "The name of the domain in which the Webhook exists") + private String domainName; + + @SerializedName(ApiConstants.DOMAIN_PATH) + @Param(description = "path of the domain to which the Webhook belongs") + private String domainPath; + + @SerializedName(ApiConstants.ACCOUNT) + @Param(description = "The account associated with the Webhook") + private String accountName; + + @SerializedName(ApiConstants.PROJECT_ID) + @Param(description = "the project id of the Kubernetes cluster") + private String projectId; + + @SerializedName(ApiConstants.PROJECT) + @Param(description = "the project name of the Kubernetes cluster") + private String projectName; + + @SerializedName(ApiConstants.PAYLOAD_URL) + @Param(description = "The payload URL end point for the Webhook") + private String payloadUrl; + + @SerializedName(ApiConstants.SECRET_KEY) + @Param(description = "The secret key for the Webhook") + private String secretKey; + + @SerializedName(ApiConstants.SSL_VERIFICATION) + @Param(description = "Whether SSL verification is enabled for the Webhook") + private boolean sslVerification; + + @SerializedName(ApiConstants.SCOPE) + @Param(description = "The scope of the Webhook") + private String scope; + + @SerializedName(ApiConstants.CREATED) + @Param(description = "The date when this Webhook was created") + private Date created; + + public void setId(String id) { + this.id = id; + } + + public void setName(String name) { + this.name = name; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setState(String state) { + this.state = state; + } + + @Override + public void setDomainId(String domainId) { + this.domainId = domainId; + } + + @Override + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + @Override + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + @Override + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + @Override + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public void setPayloadUrl(String payloadUrl) { + this.payloadUrl = payloadUrl; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public void setSslVerification(boolean sslVerification) { + this.sslVerification = sslVerification; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public void setCreated(Date created) { + this.created = created; + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDao.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDao.java new file mode 100644 index 000000000000..d26e5db7dbad --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDao.java @@ -0,0 +1,31 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.dao; + +import java.util.List; + +import org.apache.cloudstack.mom.webhook.vo.WebhookVO; + +import com.cloud.utils.db.GenericDao; + +public interface WebhookDao extends GenericDao { + List listByEnabledForDelivery(Long accountId, List domainIds); + void deleteByAccount(long accountId); + List listByAccount(long accountId); + WebhookVO findByAccountAndPayloadUrl(long accountId, String payloadUrl); +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDaoImpl.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDaoImpl.java new file mode 100644 index 000000000000..2ef2269a9b9c --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDaoImpl.java @@ -0,0 +1,99 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.dao; + +import java.util.List; +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.mom.webhook.Webhook; +import org.apache.cloudstack.mom.webhook.vo.WebhookVO; +import org.apache.commons.collections.CollectionUtils; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +public class WebhookDaoImpl extends GenericDaoBase implements WebhookDao { + SearchBuilder accountIdSearch; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + + accountIdSearch = createSearchBuilder(); + accountIdSearch.and("accountId", accountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + + return true; + } + @Override + public List listByEnabledForDelivery(Long accountId, List domainIds) { + SearchBuilder sb = createSearchBuilder(); + sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ); + sb.and().op("scopeGlobal", sb.entity().getScope(), SearchCriteria.Op.EQ); + if (accountId != null) { + sb.or().op("scopeLocal", sb.entity().getScope(), SearchCriteria.Op.EQ); + sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ); + sb.cp(); + } + if (CollectionUtils.isNotEmpty(domainIds)) { + sb.or().op("scopeDomain", sb.entity().getScope(), SearchCriteria.Op.EQ); + sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.IN); + sb.cp(); + } + sb.cp(); + SearchCriteria sc = sb.create(); + sc.setParameters("state", Webhook.State.Enabled.name()); + sc.setParameters("scopeGlobal", Webhook.Scope.Global.name()); + if (accountId != null) { + sc.setParameters("scopeLocal", Webhook.Scope.Local.name()); + sc.setParameters("accountId", accountId); + } + if (CollectionUtils.isNotEmpty(domainIds)) { + sc.setParameters("scopeDomain", Webhook.Scope.Domain.name()); + sc.setParameters("domainId", domainIds.toArray()); + } + return listBy(sc); + } + + @Override + public void deleteByAccount(long accountId) { + SearchCriteria sc = accountIdSearch.create(); + sc.setParameters("accountId", accountId); + remove(sc); + } + + @Override + public List listByAccount(long accountId) { + SearchCriteria sc = accountIdSearch.create(); + sc.setParameters("accountId", accountId); + return listBy(sc); + } + + @Override + public WebhookVO findByAccountAndPayloadUrl(long accountId, String payloadUrl) { + SearchBuilder sb = createSearchBuilder(); + sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ); + sb.and("payloadUrl", sb.entity().getPayloadUrl(), SearchCriteria.Op.EQ); + SearchCriteria sc = sb.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("payloadUrl", payloadUrl); + return findOneBy(sc); + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryDao.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryDao.java new file mode 100644 index 000000000000..0fe76d2904e2 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryDao.java @@ -0,0 +1,29 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.dao; + +import java.util.Date; + +import org.apache.cloudstack.mom.webhook.vo.WebhookDeliveryVO; + +import com.cloud.utils.db.GenericDao; + +public interface WebhookDeliveryDao extends GenericDao { + int deleteByDeleteApiParams(Long id, Long webhookId, Long managementServerId, Date startDate, Date endDate); + void removeOlderDeliveries(long webhookId, long limit); +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryDaoImpl.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryDaoImpl.java new file mode 100644 index 000000000000..088ed53772a3 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryDaoImpl.java @@ -0,0 +1,73 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.dao; + +import java.util.Date; +import java.util.List; + +import org.apache.cloudstack.mom.webhook.vo.WebhookDeliveryVO; + +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +public class WebhookDeliveryDaoImpl extends GenericDaoBase implements WebhookDeliveryDao { + @Override + public int deleteByDeleteApiParams(Long id, Long webhookId, Long managementServerId, Date startDate, + Date endDate) { + SearchBuilder sb = createSearchBuilder(); + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + sb.and("webhookId", sb.entity().getWebhookId(), SearchCriteria.Op.EQ); + sb.and("managementServerId", sb.entity().getManagementServerId(), SearchCriteria.Op.EQ); + sb.and("startDate", sb.entity().getStartTime(), SearchCriteria.Op.GTEQ); + sb.and("endDate", sb.entity().getEndTime(), SearchCriteria.Op.LTEQ); + SearchCriteria sc = sb.create(); + if (id != null) { + sc.setParameters("id", id); + } + if (webhookId != null) { + sc.setParameters("webhookId", webhookId); + } + if (managementServerId != null) { + sc.setParameters("managementServerId", managementServerId); + } + if (startDate != null) { + sc.setParameters("startDate", startDate); + } + if (endDate != null) { + sc.setParameters("endDate", endDate); + } + return remove(sc); + } + + @Override + public void removeOlderDeliveries(long webhookId, long limit) { + Filter searchFilter = new Filter(WebhookDeliveryVO.class, "id", false, 0L, limit); + SearchBuilder sb = createSearchBuilder(); + sb.and("webhookId", sb.entity().getWebhookId(), SearchCriteria.Op.EQ); + SearchCriteria sc = sb.create(); + sc.setParameters("webhookId", webhookId); + List keep = listBy(sc, searchFilter); + SearchBuilder sbDelete = createSearchBuilder(); + sbDelete.and("id", sbDelete.entity().getId(), SearchCriteria.Op.NOTIN); + SearchCriteria scDelete = sbDelete.create(); + scDelete.setParameters("id", keep.stream().map(WebhookDeliveryVO::getId).toArray()); + remove(scDelete); + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryJoinDao.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryJoinDao.java new file mode 100644 index 000000000000..70fec4d7cbfc --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryJoinDao.java @@ -0,0 +1,33 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.dao; + +import java.util.Date; +import java.util.List; + +import org.apache.cloudstack.mom.webhook.vo.WebhookDeliveryJoinVO; + +import com.cloud.utils.Pair; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDao; + +public interface WebhookDeliveryJoinDao extends GenericDao { + Pair, Integer> searchAndCountByListApiParameters(Long id, + List webhookIds, Long managementServerId, final String keyword, final Date startDate, + final Date endDate, final String eventType, Filter searchFilter); +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryJoinDaoImpl.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryJoinDaoImpl.java new file mode 100644 index 000000000000..db84010fbc47 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookDeliveryJoinDaoImpl.java @@ -0,0 +1,71 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.dao; + +import java.util.Date; +import java.util.List; + +import org.apache.cloudstack.mom.webhook.vo.WebhookDeliveryJoinVO; +import org.apache.commons.collections.CollectionUtils; + +import com.cloud.utils.Pair; +import com.cloud.utils.StringUtils; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +public class WebhookDeliveryJoinDaoImpl extends GenericDaoBase + implements WebhookDeliveryJoinDao { + @Override + public Pair, Integer> searchAndCountByListApiParameters(Long id, + List webhookIds, Long managementServerId, String keyword, final Date startDate, + final Date endDate, final String eventType, Filter searchFilter) { + SearchBuilder sb = createSearchBuilder(); + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + sb.and("webhookId", sb.entity().getWebhookId(), SearchCriteria.Op.IN); + sb.and("managementServerId", sb.entity().getManagementServerMsId(), SearchCriteria.Op.EQ); + sb.and("keyword", sb.entity().getPayload(), SearchCriteria.Op.LIKE); + sb.and("startDate", sb.entity().getStartTime(), SearchCriteria.Op.GTEQ); + sb.and("endDate", sb.entity().getEndTime(), SearchCriteria.Op.LTEQ); + sb.and("eventType", sb.entity().getEventType(), SearchCriteria.Op.EQ); + SearchCriteria sc = sb.create(); + if (id != null) { + sc.setParameters("id", id); + } + if (CollectionUtils.isNotEmpty(webhookIds)) { + sc.setParameters("webhookId", webhookIds.toArray()); + } + if (managementServerId != null) { + sc.setParameters("managementServerId", managementServerId); + } + if (keyword != null) { + sc.setParameters("keyword", "%" + keyword + "%"); + } + if (startDate != null) { + sc.setParameters("startDate", startDate); + } + if (endDate != null) { + sc.setParameters("endDate", endDate); + } + if (StringUtils.isNotBlank(eventType)) { + sc.setParameters("eventType", eventType); + } + return searchAndCount(sc, searchFilter); + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookJoinDao.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookJoinDao.java new file mode 100644 index 000000000000..87b4871a14b4 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookJoinDao.java @@ -0,0 +1,28 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.dao; + +import java.util.List; + +import org.apache.cloudstack.mom.webhook.vo.WebhookJoinVO; + +import com.cloud.utils.db.GenericDao; + +public interface WebhookJoinDao extends GenericDao { + List listByAccountOrDomain(long accountId, String domainPath); +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookJoinDaoImpl.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookJoinDaoImpl.java new file mode 100644 index 000000000000..986e8bc2f199 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/dao/WebhookJoinDaoImpl.java @@ -0,0 +1,45 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.dao; + +import java.util.List; + +import org.apache.cloudstack.mom.webhook.vo.WebhookJoinVO; +import org.apache.commons.lang3.StringUtils; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +public class WebhookJoinDaoImpl extends GenericDaoBase implements WebhookJoinDao { + @Override + public List listByAccountOrDomain(long accountId, String domainPath) { + SearchBuilder sb = createSearchBuilder(); + sb.and().op("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ); + if (StringUtils.isNotBlank(domainPath)) { + sb.or("domainPath", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE); + } + sb.cp(); + SearchCriteria sc = sb.create(); + sc.setParameters("accountId", accountId); + if (StringUtils.isNotBlank(domainPath)) { + sc.setParameters("domainPath", domainPath); + } + return listBy(sc); + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookDeliveryJoinVO.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookDeliveryJoinVO.java new file mode 100644 index 000000000000..e36f870c8d95 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookDeliveryJoinVO.java @@ -0,0 +1,182 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.vo; + + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; + +import com.cloud.api.query.vo.BaseViewVO; + +@Entity +@Table(name = "webhook_delivery_view") +public class WebhookDeliveryJoinVO extends BaseViewVO implements InternalIdentity, Identity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "event_id") + private long eventId; + + @Column(name = "event_uuid") + private String eventUuid; + + @Column(name = "event_type") + private String eventType; + + @Column(name = "webhook_id") + private long webhookId; + + @Column(name = "webhook_uuid") + private String webhookUuId; + + @Column(name = "webhook_name") + private String webhookName; + + @Column(name = "mshost_id") + private long managementServerId; + + @Column(name = "mshost_uuid") + private String managementServerUuId; + + @Column(name = "mshost_msid") + private long managementServerMsId; + + @Column(name = "mshost_name") + private String managementServerName; + + @Column(name = "headers", length = 65535) + private String headers; + + @Column(name = "payload", length = 65535) + private String payload; + + @Column(name = "success") + private boolean success; + + @Column(name = "response", length = 65535) + private String response; + + @Column(name = "start_time") + @Temporal(value = TemporalType.TIMESTAMP) + private Date startTime; + + @Column(name = "end_time") + @Temporal(value = TemporalType.TIMESTAMP) + private Date endTime; + + @Override + public long getId() { + return 0; + } + + @Override + public String getUuid() { + return uuid; + } + + public long getEventId() { + return eventId; + } + + public String getEventUuid() { + return eventUuid; + } + + public String getEventType() { + return eventType; + } + + public long getWebhookId() { + return webhookId; + } + + public String getWebhookUuId() { + return webhookUuId; + } + + public String getWebhookName() { + return webhookName; + } + + public long getManagementServerId() { + return managementServerId; + } + + public String getManagementServerUuId() { + return managementServerUuId; + } + + public long getManagementServerMsId() { + return managementServerMsId; + } + + public String getManagementServerName() { + return managementServerName; + } + + public String getHeaders() { + return headers; + } + + public String getPayload() { + return payload; + } + + public boolean isSuccess() { + return success; + } + + public String getResponse() { + return response; + } + + public Date getStartTime() { + return startTime; + } + + public Date getEndTime() { + return endTime; + } + + @Override + public String toString() { + return String.format("WebhookDelivery [%s]", ReflectionToStringBuilderUtils.reflectOnlySelectedFields( + this, "id", "uuid", "webhookId", "startTime", "success")); + } + + public WebhookDeliveryJoinVO() { + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookDeliveryVO.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookDeliveryVO.java new file mode 100644 index 000000000000..e39f57a26637 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookDeliveryVO.java @@ -0,0 +1,174 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.vo; + + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.cloudstack.mom.webhook.WebhookDelivery; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; + +@Entity +@Table(name = "webhook_delivery") +public class WebhookDeliveryVO implements WebhookDelivery { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "event_id") + private long eventId; + + @Column(name = "webhook_id") + private long webhookId; + + @Column(name = "mshost_msid") + private long mangementServerId; + + @Column(name = "headers", length = 65535) + private String headers; + + @Column(name = "payload", length = 65535) + private String payload; + + @Column(name = "success") + private boolean success; + + @Column(name = "response", length = 65535) + private String response; + + @Column(name = "start_time") + @Temporal(value = TemporalType.TIMESTAMP) + private Date startTime; + + @Column(name = "end_time") + @Temporal(value = TemporalType.TIMESTAMP) + private Date endTime; + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public long getEventId() { + return eventId; + } + + @Override + public long getWebhookId() { + return webhookId; + } + + @Override + public long getManagementServerId() { + return mangementServerId; + } + + public String getHeaders() { + return headers; + } + + @Override + public String getPayload() { + return payload; + } + + @Override + public boolean isSuccess() { + return success; + } + + @Override + public String getResponse() { + return response; + } + + @Override + public Date getStartTime() { + return startTime; + } + + @Override + public Date getEndTime() { + return endTime; + } + + @Override + public String toString() { + return String.format("WebhookDelivery [%s]", ReflectionToStringBuilderUtils.reflectOnlySelectedFields( + this, "id", "uuid", "webhookId", "startTime", "success")); + } + + public WebhookDeliveryVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public WebhookDeliveryVO(long eventId, long webhookId, long managementServerId, String headers, String payload, + boolean success, String response, Date startTime, Date endTime) { + this.uuid = UUID.randomUUID().toString(); + this.eventId = eventId; + this.webhookId = webhookId; + this.mangementServerId = managementServerId; + this.headers = headers; + this.payload = payload; + this.success = success; + this.response = response; + this.startTime = startTime; + this.endTime = endTime; + } + + + + /* + * For creating a dummy object for testing delivery + */ + public WebhookDeliveryVO(long managementServerId, String headers, String payload, boolean success, + String response, Date startTime, Date endTime) { + this.id = WebhookDelivery.ID_DUMMY; + this.uuid = UUID.randomUUID().toString(); + this.eventId = WebhookDelivery.ID_DUMMY; + this.webhookId = WebhookDelivery.ID_DUMMY; + this.mangementServerId = managementServerId; + this.headers = headers; + this.payload = payload; + this.success = success; + this.response = response; + this.startTime = startTime; + this.endTime = endTime; + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookJoinVO.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookJoinVO.java new file mode 100644 index 000000000000..f17086095871 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookJoinVO.java @@ -0,0 +1,234 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.vo; + + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.cloudstack.mom.webhook.Webhook; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; + +import com.cloud.api.query.vo.ControlledViewEntity; +import com.cloud.user.Account; +import com.cloud.utils.db.Encrypt; +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "webhook_view") +public class WebhookJoinVO implements ControlledViewEntity { + + @Id + @Column(name = "id", updatable = false, nullable = false) + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "name") + private String name; + + @Column(name = "description", length = 4096) + private String description; + + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + private Webhook.State state; + + @Column(name = "payload_url") + private String payloadUrl; + + @Column(name = "secret_key") + @Encrypt + private String secretKey; + + @Column(name = "ssl_verification") + private boolean sslVerification; + + @Column(name = "scope") + @Enumerated(value = EnumType.STRING) + private Webhook.Scope scope; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name = GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name = "account_id") + private long accountId; + + @Column(name = "account_uuid") + private String accountUuid; + + @Column(name = "account_name") + private String accountName; + + @Column(name = "account_type") + @Enumerated(value = EnumType.STRING) + private Account.Type accountType; + + @Column(name = "domain_id") + private long domainId; + + @Column(name = "domain_uuid") + private String domainUuid; + + @Column(name = "domain_name") + private String domainName; + + @Column(name = "domain_path") + private String domainPath; + + @Column(name = "project_id") + private long projectId; + + @Column(name = "project_uuid") + private String projectUuid; + + @Column(name = "project_name") + private String projectName; + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Webhook.State getState() { + return state; + } + + public String getPayloadUrl() { + return payloadUrl; + } + + public void setPayloadUrl(String payloadUrl) { + this.payloadUrl = payloadUrl; + } + + public String getSecretKey() { + return secretKey; + } + + public Webhook.Scope getScope() { + return scope; + } + + public boolean isSslVerification() { + return sslVerification; + } + + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } + + @Override + public long getDomainId() { + return domainId; + } + + @Override + public String getDomainPath() { + return domainPath; + } + + @Override + public String getDomainUuid() { + return domainUuid; + } + + @Override + public String getDomainName() { + return domainName; + } + + @Override + public Account.Type getAccountType() { + return accountType; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public String getAccountUuid() { + return accountUuid; + } + + @Override + public String getAccountName() { + return accountName; + } + + @Override + public String getProjectUuid() { + return projectUuid; + } + + @Override + public String getProjectName() { + return projectName; + } + + @Override + public Class getEntityType() { + return Webhook.class; + } + + @Override + public String toString() { + return String.format("Webhook [%s]", ReflectionToStringBuilderUtils.reflectOnlySelectedFields( + this, "id", "uuid", "name")); + } + + public WebhookJoinVO() { + } +} diff --git a/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookVO.java b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookVO.java new file mode 100644 index 000000000000..93e3e801423e --- /dev/null +++ b/plugins/event-bus/webhook/src/main/java/org/apache/cloudstack/mom/webhook/vo/WebhookVO.java @@ -0,0 +1,232 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.vo; + + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.cloudstack.mom.webhook.Webhook; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; + +import com.cloud.utils.db.Encrypt; +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "webhook") +public class WebhookVO implements Webhook { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "name") + private String name; + + @Column(name = "description", length = 4096) + private String description; + + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + private State state; + + @Column(name = "domain_id") + private long domainId; + + @Column(name = "account_id") + private long accountId; + + @Column(name = "payload_url") + private String payloadUrl; + + @Column(name = "secret_key") + @Encrypt + private String secretKey; + + @Column(name = "ssl_verification") + private boolean sslVerification; + + @Column(name = "scope") + @Enumerated(value = EnumType.STRING) + private Scope scope; + + @Column(name = GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name = GenericDao.REMOVED_COLUMN) + private Date removed; + + @Override + public long getId() { + return id; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @Override + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + @Override + public long getDomainId() { + return domainId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + @Override + public long getAccountId() { + return accountId; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + @Override + public String getPayloadUrl() { + return payloadUrl; + } + + public void setPayloadUrl(String payloadUrl) { + this.payloadUrl = payloadUrl; + } + + @Override + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + @Override + public Scope getScope() { + return scope; + } + + public void setScope(Scope scope) { + this.scope = scope; + } + + @Override + public boolean isSslVerification() { + return sslVerification; + } + + public void setSslVerification(boolean sslVerification) { + this.sslVerification = sslVerification; + } + + @Override + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } + + @Override + public Class getEntityType() { + return Webhook.class; + } + + @Override + public String toString() { + return String.format("Webhook [%s]",ReflectionToStringBuilderUtils.reflectOnlySelectedFields( + this, "id", "uuid", "name", "payloadUrl")); + } + + public WebhookVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public WebhookVO(String name, String description, State state, long domainId, long accountId, + String payloadUrl, String secretKey, boolean sslVerification, Scope scope) { + this.uuid = UUID.randomUUID().toString(); + this.name = name; + this.description = description; + this.state = state; + this.domainId = domainId; + this.accountId = accountId; + this.payloadUrl = payloadUrl; + this.secretKey = secretKey; + this.sslVerification = sslVerification; + this.scope = scope; + } + + /* + * For creating a dummy rule for testing delivery + */ + public WebhookVO(long domainId, long accountId, String payloadUrl, String secretKey, boolean sslVerification) { + this.uuid = UUID.randomUUID().toString(); + this.id = ID_DUMMY; + this.name = NAME_DUMMY; + this.description = NAME_DUMMY; + this.state = State.Enabled; + this.domainId = domainId; + this.accountId = accountId; + this.payloadUrl = payloadUrl; + this.secretKey = secretKey; + this.sslVerification = sslVerification; + this.scope = Scope.Local; + } +} diff --git a/plugins/event-bus/webhook/src/main/resources/META-INF/cloudstack/webhook/module.properties b/plugins/event-bus/webhook/src/main/resources/META-INF/cloudstack/webhook/module.properties new file mode 100644 index 000000000000..299144ff82a2 --- /dev/null +++ b/plugins/event-bus/webhook/src/main/resources/META-INF/cloudstack/webhook/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=webhook +parent=event diff --git a/plugins/event-bus/webhook/src/main/resources/META-INF/cloudstack/webhook/spring-event-webhook-context.xml b/plugins/event-bus/webhook/src/main/resources/META-INF/cloudstack/webhook/spring-event-webhook-context.xml new file mode 100644 index 000000000000..22f688c781fe --- /dev/null +++ b/plugins/event-bus/webhook/src/main/resources/META-INF/cloudstack/webhook/spring-event-webhook-context.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookApiServiceImplTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookApiServiceImplTest.java new file mode 100644 index 000000000000..dff358069840 --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookApiServiceImplTest.java @@ -0,0 +1,253 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.mom.webhook; + +import java.util.List; + +import org.apache.cloudstack.acl.SecurityChecker; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.api.command.user.DeleteWebhookCmd; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; +import org.apache.cloudstack.mom.webhook.dao.WebhookDao; +import org.apache.cloudstack.mom.webhook.dao.WebhookJoinDao; +import org.apache.cloudstack.mom.webhook.vo.WebhookJoinVO; +import org.apache.cloudstack.mom.webhook.vo.WebhookVO; +import org.apache.commons.collections.CollectionUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.api.ApiResponseHelper; +import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.PermissionDeniedException; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; + +@RunWith(MockitoJUnitRunner.class) +public class WebhookApiServiceImplTest { + + @Mock + WebhookDao webhookDao; + @Mock + WebhookJoinDao webhookJoinDao; + @Mock + AccountManager accountManager; + + @Mock + DomainDao domainDao; + + @InjectMocks + WebhookApiServiceImpl webhookApiServiceImpl = new WebhookApiServiceImpl(); + + private WebhookJoinVO prepareTestWebhookJoinVO() { + String name = "webhook"; + String description = "webhook-description"; + Webhook.State state = Webhook.State.Enabled; + String payloadUrl = "url"; + String secretKey = "key"; + boolean sslVerification = false; + Webhook.Scope scope = Webhook.Scope.Local; + WebhookJoinVO webhookJoinVO = new WebhookJoinVO(); + ReflectionTestUtils.setField(webhookJoinVO, "name", name); + ReflectionTestUtils.setField(webhookJoinVO, "description", description); + ReflectionTestUtils.setField(webhookJoinVO, "state", state); + ReflectionTestUtils.setField(webhookJoinVO, "payloadUrl", payloadUrl); + ReflectionTestUtils.setField(webhookJoinVO, "secretKey", secretKey); + ReflectionTestUtils.setField(webhookJoinVO, "sslVerification", sslVerification); + ReflectionTestUtils.setField(webhookJoinVO, "scope", scope); + return webhookJoinVO; + } + + private void validateWebhookResponseWithWebhookJoinVO(WebhookResponse response, WebhookJoinVO webhookJoinVO) { + Assert.assertEquals(webhookJoinVO.getName(), ReflectionTestUtils.getField(response, "name")); + Assert.assertEquals(webhookJoinVO.getDescription(), ReflectionTestUtils.getField(response, "description")); + Assert.assertEquals(webhookJoinVO.getState().toString(), ReflectionTestUtils.getField(response, "state")); + Assert.assertEquals(webhookJoinVO.getPayloadUrl(), ReflectionTestUtils.getField(response, "payloadUrl")); + Assert.assertEquals(webhookJoinVO.getSecretKey(), ReflectionTestUtils.getField(response, "secretKey")); + Assert.assertEquals(webhookJoinVO.isSslVerification(), ReflectionTestUtils.getField(response, "sslVerification")); + Assert.assertEquals(webhookJoinVO.getScope().toString(), ReflectionTestUtils.getField(response, "scope")); + } + + @Test + public void testCreateWebhookResponse() { + WebhookJoinVO webhookJoinVO = prepareTestWebhookJoinVO(); + try (MockedStatic mockedApiResponseHelper = Mockito.mockStatic(ApiResponseHelper.class)) { + WebhookResponse response = webhookApiServiceImpl.createWebhookResponse(webhookJoinVO); + validateWebhookResponseWithWebhookJoinVO(response, webhookJoinVO); + } + } + + @Test + public void testCreateWebhookResponseId() { + WebhookJoinVO webhookJoinVO = prepareTestWebhookJoinVO(); + long id = 1L; + Mockito.when(webhookJoinDao.findById(id)).thenReturn(webhookJoinVO); + try (MockedStatic mockedApiResponseHelper = Mockito.mockStatic(ApiResponseHelper.class)) { + WebhookResponse response = webhookApiServiceImpl.createWebhookResponse(id); + validateWebhookResponseWithWebhookJoinVO(response, webhookJoinVO); + } + } + + @Test + public void testGetIdsOfAccessibleWebhooksAdmin() { + Account account = Mockito.mock(Account.class); + Mockito.when(account.getType()).thenReturn(Account.Type.ADMIN); + Assert.assertTrue(CollectionUtils.isEmpty(webhookApiServiceImpl.getIdsOfAccessibleWebhooks(account))); + } + + @Test + public void testGetIdsOfAccessibleWebhooksDomainAdmin() { + Long accountId = 1L; + Account account = Mockito.mock(Account.class); + Mockito.when(account.getType()).thenReturn(Account.Type.DOMAIN_ADMIN); + Mockito.when(account.getDomainId()).thenReturn(1L); + Mockito.when(account.getId()).thenReturn(accountId); + String domainPath = "d1"; + DomainVO domain = Mockito.mock(DomainVO.class); + Mockito.when(domain.getPath()).thenReturn(domainPath); + Mockito.when(domainDao.findById(1L)).thenReturn(domain); + WebhookJoinVO webhookJoinVO = Mockito.mock(WebhookJoinVO.class); + Mockito.when(webhookJoinVO.getId()).thenReturn(1L); + Mockito.when(webhookJoinDao.listByAccountOrDomain(accountId, domainPath)).thenReturn(List.of(webhookJoinVO)); + List result = webhookApiServiceImpl.getIdsOfAccessibleWebhooks(account); + Assert.assertTrue(CollectionUtils.isNotEmpty(result)); + Assert.assertEquals(1, result.size()); + } + + @Test + public void testGetIdsOfAccessibleWebhooksNormalUser() { + Long accountId = 1L; + Account account = Mockito.mock(Account.class); + Mockito.when(account.getType()).thenReturn(Account.Type.NORMAL); + Mockito.when(account.getId()).thenReturn(accountId); + WebhookJoinVO webhookJoinVO = Mockito.mock(WebhookJoinVO.class); + Mockito.when(webhookJoinVO.getId()).thenReturn(1L); + Mockito.when(webhookJoinDao.listByAccountOrDomain(accountId, null)).thenReturn(List.of(webhookJoinVO)); + List result = webhookApiServiceImpl.getIdsOfAccessibleWebhooks(account); + Assert.assertTrue(CollectionUtils.isNotEmpty(result)); + Assert.assertEquals(1, result.size()); + } + + @Test(expected = InvalidParameterValueException.class) + public void testDeleteWebhookInvalidWebhook() { + try (MockedStatic callContextMocked = Mockito.mockStatic(CallContext.class)) { + DeleteWebhookCmd cmd = Mockito.mock(DeleteWebhookCmd.class); + Mockito.when(cmd.getId()).thenReturn(1L); + CallContext callContextMock = Mockito.mock(CallContext.class); + callContextMocked.when(CallContext::current).thenReturn(callContextMock); + webhookApiServiceImpl.deleteWebhook(cmd); + } + } + + @Test(expected = PermissionDeniedException.class) + public void testDeleteWebhookNoPermission() { + try (MockedStatic callContextMocked = Mockito.mockStatic(CallContext.class)) { + DeleteWebhookCmd cmd = Mockito.mock(DeleteWebhookCmd.class); + Mockito.when(cmd.getId()).thenReturn(1L); + WebhookVO webhookVO = Mockito.mock(WebhookVO.class); + Mockito.when(webhookDao.findById(1L)).thenReturn(webhookVO); + CallContext callContextMock = Mockito.mock(CallContext.class); + Account account = Mockito.mock(Account.class); + Mockito.when(callContextMock.getCallingAccount()).thenReturn(account); + callContextMocked.when(CallContext::current).thenReturn(callContextMock); + Mockito.doThrow(PermissionDeniedException.class).when(accountManager).checkAccess(account, + SecurityChecker.AccessType.OperateEntry, false, webhookVO); + webhookApiServiceImpl.deleteWebhook(cmd); + } + } + + @Test + public void testDeleteWebhook() { + try (MockedStatic callContextMocked = Mockito.mockStatic(CallContext.class)) { + DeleteWebhookCmd cmd = Mockito.mock(DeleteWebhookCmd.class); + Mockito.when(cmd.getId()).thenReturn(1L); + WebhookVO webhookVO = Mockito.mock(WebhookVO.class); + Mockito.when(webhookDao.findById(1L)).thenReturn(webhookVO); + CallContext callContextMock = Mockito.mock(CallContext.class); + Account account = Mockito.mock(Account.class); + Mockito.when(callContextMock.getCallingAccount()).thenReturn(account); + callContextMocked.when(CallContext::current).thenReturn(callContextMock); + Mockito.doNothing().when(accountManager).checkAccess(account, + SecurityChecker.AccessType.OperateEntry, false, webhookVO); + Mockito.doReturn(true).when(webhookDao).remove(Mockito.anyLong()); + Assert.assertTrue(webhookApiServiceImpl.deleteWebhook(cmd)); + } + } + + @Test + public void testValidateWebhookOwnerPayloadUrlNonExistent() { + Mockito.when(webhookDao.findByAccountAndPayloadUrl(Mockito.anyLong(), Mockito.anyString())).thenReturn(null); + Account account = Mockito.mock(Account.class); + String url = "url"; + webhookApiServiceImpl.validateWebhookOwnerPayloadUrl(account, url, null); + webhookApiServiceImpl.validateWebhookOwnerPayloadUrl(account, url, Mockito.mock(Webhook.class)); + } + + @Test(expected = InvalidParameterValueException.class) + public void testValidateWebhookOwnerPayloadUrlCreateExist() { + Mockito.when(webhookDao.findByAccountAndPayloadUrl(Mockito.anyLong(), Mockito.anyString())) + .thenReturn(Mockito.mock(WebhookVO.class)); + webhookApiServiceImpl.validateWebhookOwnerPayloadUrl(Mockito.mock(Account.class), "url", + null); + } + + private Webhook mockWebhook(long id) { + Webhook webhook = Mockito.mock(Webhook.class); + Mockito.when(webhook.getId()).thenReturn(id); + return webhook; + } + + private WebhookVO mockWebhookVO(long id) { + WebhookVO webhook = Mockito.mock(WebhookVO.class); + Mockito.when(webhook.getId()).thenReturn(id); + return webhook; + } + + @Test + public void testValidateWebhookOwnerPayloadUrlUpdateSameExist() { + WebhookVO webhookVO = mockWebhookVO(1L); + Mockito.when(webhookDao.findByAccountAndPayloadUrl(Mockito.anyLong(), Mockito.anyString())) + .thenReturn(webhookVO); + webhookApiServiceImpl.validateWebhookOwnerPayloadUrl(Mockito.mock(Account.class), "url", + mockWebhook(1L)); + } + + @Test(expected = InvalidParameterValueException.class) + public void testValidateWebhookOwnerPayloadUrlUpdateDifferentExist() { + WebhookVO webhookVO = mockWebhookVO(2L); + Mockito.when(webhookDao.findByAccountAndPayloadUrl(Mockito.anyLong(), Mockito.anyString())) + .thenReturn(webhookVO); + webhookApiServiceImpl.validateWebhookOwnerPayloadUrl(Mockito.mock(Account.class), "url", + mockWebhook(1L)); + } + + @Test + public void testGetNormalizedPayloadUrl() { + Assert.assertEquals("http://abc.com", webhookApiServiceImpl.getNormalizedPayloadUrl("abc.com")); + Assert.assertEquals("http://abc.com", webhookApiServiceImpl.getNormalizedPayloadUrl("http://abc.com")); + Assert.assertEquals("https://abc.com", + webhookApiServiceImpl.getNormalizedPayloadUrl("https://abc.com")); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookDeliveryThreadTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookDeliveryThreadTest.java new file mode 100644 index 000000000000..3be8dee5c2ec --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookDeliveryThreadTest.java @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import org.apache.commons.codec.DecoderException; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class WebhookDeliveryThreadTest { + @InjectMocks + WebhookDeliveryThread webhookDeliveryThread; + + @Test + public void testIsValidJson() { + Assert.assertFalse(webhookDeliveryThread.isValidJson("text")); + Assert.assertTrue(webhookDeliveryThread.isValidJson("{ \"CloudStack\": \"works!\" }")); + Assert.assertTrue(webhookDeliveryThread.isValidJson("[{ \"CloudStack\": \"works!\" }]")); + } + + @Test + public void testGenerateHMACSignature() { + String data = "CloudStack works!"; + String key = "Pj4pnwSUBZ4wQFXw2zWdVY1k5Ku9bIy70wCNG1DmS8keO7QapCLw2Axtgc2nEPYzfFCfB38ATNLt6caDqU2dSw"; + String result = "HYLWSII5Ap23WeSaykNsIo6mOhmV3d18s5p2cq2ebCA="; + try { + String sign = WebhookDeliveryThread.generateHMACSignature(data, key); + Assert.assertEquals(result, sign); + } catch (InvalidKeyException | NoSuchAlgorithmException | DecoderException e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testSetDeliveryTries() { + int tries = 2; + webhookDeliveryThread.setDeliveryTries(tries); + Assert.assertEquals(tries, ReflectionTestUtils.getField(webhookDeliveryThread, "deliveryTries")); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookEventBusTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookEventBusTest.java new file mode 100644 index 000000000000..ebd3f9e828c2 --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/WebhookEventBusTest.java @@ -0,0 +1,106 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook; + +import java.util.HashMap; +import java.util.UUID; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.framework.events.Event; +import org.apache.cloudstack.framework.events.EventBusException; +import org.apache.cloudstack.framework.events.EventSubscriber; +import org.apache.cloudstack.framework.events.EventTopic; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class WebhookEventBusTest { + + @Mock + WebhookService webhookService; + @InjectMocks + WebhookEventBus eventBus = new WebhookEventBus(); + + @Test + public void testConfigure() { + String name = "name"; + try { + Assert.assertTrue(eventBus.configure(name, new HashMap<>())); + String result = (String)ReflectionTestUtils.getField(eventBus, "_name"); + Assert.assertEquals(name, result); + } catch (ConfigurationException e) { + Assert.fail("Error configuring"); + } + } + + @Test + public void testSetName() { + String name = "name"; + eventBus.setName(name); + String result = (String)ReflectionTestUtils.getField(eventBus, "_name"); + Assert.assertEquals(name, result); + } + + @Test + public void testGetName() { + String name = "name"; + ReflectionTestUtils.setField(eventBus, "_name", name); + Assert.assertEquals(name, eventBus.getName()); + } + + @Test + public void testStart() { + Assert.assertTrue(eventBus.start()); + } + + @Test + public void testStop() { + Assert.assertTrue(eventBus.stop()); + } + + @Test + public void testSubscribe() { + try { + Assert.assertNotNull(eventBus.subscribe(Mockito.mock(EventTopic.class), Mockito.mock(EventSubscriber.class))); + } catch (EventBusException e) { + Assert.fail("Error subscribing"); + } + } + + @Test + public void testUnsubscribe() { + try { + eventBus.unsubscribe(Mockito.mock(UUID.class), Mockito.mock(EventSubscriber.class)); + } catch (EventBusException e) { + Assert.fail("Error unsubscribing"); + } + } + + @Test(expected = EventBusException.class) + public void testPublishException() throws EventBusException { + Mockito.doThrow(EventBusException.class).when(webhookService).handleEvent(Mockito.any(Event.class)); + eventBus.publish(Mockito.mock(Event.class)); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/CreateWebhookCmdTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/CreateWebhookCmdTest.java new file mode 100644 index 000000000000..7736a42af04f --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/CreateWebhookCmdTest.java @@ -0,0 +1,173 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.Account; +import com.cloud.user.AccountVO; +import com.cloud.user.User; +import com.cloud.user.UserVO; +import com.cloud.utils.exception.CloudRuntimeException; + +@RunWith(MockitoJUnitRunner.class) +public class CreateWebhookCmdTest { + + @Mock + WebhookApiService webhookApiService; + + private Object getCommandMethodValue(Object obj, String methodName) { + Object result = null; + try { + Method method = obj.getClass().getMethod(methodName); + result = method.invoke(obj); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + Assert.fail(String.format("Failed to get method %s value", methodName)); + } + return result; + } + + private void runStringMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + CreateWebhookCmd cmd = new CreateWebhookCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + String value = UUID.randomUUID().toString(); + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runLongMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + CreateWebhookCmd cmd = new CreateWebhookCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Long value = 100L; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runBooleanMemberTest(String memberName) { + String methodName = "is" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + CreateWebhookCmd cmd = new CreateWebhookCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertFalse((boolean)getCommandMethodValue(cmd, methodName)); + Boolean value = true; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + @Test + public void testGetName() { + runStringMemberTest("name"); + } + + @Test + public void testGetDescription() { + runStringMemberTest("description"); + } + + @Test + public void testGetPayloadUrl() { + runStringMemberTest("payloadUrl"); + } + + @Test + public void testGetSecretKey() { + runStringMemberTest("secretKey"); + } + + @Test + public void testGetScope() { + runStringMemberTest("scope"); + } + + @Test + public void testGetState() { + runStringMemberTest("state"); + } + + @Test + public void testGetAccount() { + runStringMemberTest("accountName"); + } + + @Test + public void testGetDomainId() { + runLongMemberTest("domainId"); + } + + @Test + public void testGetProjectId() { + runLongMemberTest("projectId"); + } + + @Test + public void testIsSslVerification() { + runBooleanMemberTest("sslVerification"); + } + + @Test + public void testGetEntityOwnerId() { + Account account = new AccountVO("testaccount", 1L, "networkdomain", Account.Type.NORMAL, "uuid"); + UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN); + CallContext.register(user, account); + CreateWebhookCmd cmd = new CreateWebhookCmd(); + Assert.assertEquals(account.getId(), cmd.getEntityOwnerId()); + } + + @Test(expected = ServerApiException.class) + public void testExecuteNullResponse() { + CreateWebhookCmd cmd = new CreateWebhookCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.createWebhook(cmd)).thenReturn(null); + cmd.execute(); + } + + @Test(expected = ServerApiException.class) + public void testExecuteCRE() { + CreateWebhookCmd cmd = new CreateWebhookCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.createWebhook(cmd)).thenThrow(CloudRuntimeException.class); + cmd.execute(); + } + + @Test + public void testExecute() { + CreateWebhookCmd cmd = new CreateWebhookCmd(); + cmd.webhookApiService = webhookApiService; + WebhookResponse response = new WebhookResponse(); + Mockito.when(webhookApiService.createWebhook(cmd)).thenReturn(response); + cmd.execute(); + Assert.assertEquals(cmd.getCommandName(), response.getResponseName()); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookCmdTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookCmdTest.java new file mode 100644 index 000000000000..e9aa61aabb83 --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookCmdTest.java @@ -0,0 +1,106 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.Account; +import com.cloud.user.AccountVO; +import com.cloud.user.User; +import com.cloud.user.UserVO; +import com.cloud.utils.exception.CloudRuntimeException; + +@RunWith(MockitoJUnitRunner.class) +public class DeleteWebhookCmdTest { + + @Mock + WebhookApiService webhookApiService; + + private Object getCommandMethodValue(Object obj, String methodName) { + Object result = null; + try { + Method method = obj.getClass().getMethod(methodName); + result = method.invoke(obj); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + Assert.fail(String.format("Failed to get method %s value", methodName)); + } + return result; + } + + private void runLongMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + DeleteWebhookCmd cmd = new DeleteWebhookCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Long value = 100L; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + @Test + public void testGetId() { + runLongMemberTest("id"); + } + + @Test + public void testGetEntityOwnerId() { + Account account = new AccountVO("testaccount", 1L, "networkdomain", Account.Type.NORMAL, "uuid"); + UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN); + CallContext.register(user, account); + DeleteWebhookCmd cmd = new DeleteWebhookCmd(); + Assert.assertEquals(account.getId(), cmd.getEntityOwnerId()); + } + + @Test(expected = ServerApiException.class) + public void testExecuteFalseResponse() { + DeleteWebhookCmd cmd = new DeleteWebhookCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.deleteWebhook(cmd)).thenReturn(false); + cmd.execute(); + } + + @Test(expected = ServerApiException.class) + public void testExecuteCRE() { + DeleteWebhookCmd cmd = new DeleteWebhookCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.deleteWebhook(cmd)).thenThrow(CloudRuntimeException.class); + cmd.execute(); + } + + @Test + public void testExecute() { + DeleteWebhookCmd cmd = new DeleteWebhookCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.deleteWebhook(cmd)).thenReturn(true); + cmd.execute(); + Assert.assertNotNull(cmd.getResponseObject()); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookDeliveryCmdTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookDeliveryCmdTest.java new file mode 100644 index 000000000000..2a090eb7fb12 --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/DeleteWebhookDeliveryCmdTest.java @@ -0,0 +1,108 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.Account; +import com.cloud.user.AccountVO; +import com.cloud.user.User; +import com.cloud.user.UserVO; +import com.cloud.utils.exception.CloudRuntimeException; + +@RunWith(MockitoJUnitRunner.class) +public class DeleteWebhookDeliveryCmdTest { + + @Mock + WebhookApiService webhookApiService; + + private Object getCommandMethodValue(Object obj, String methodName) { + Object result = null; + try { + Method method = obj.getClass().getMethod(methodName); + result = method.invoke(obj); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + Assert.fail(String.format("Failed to get method %s value", methodName)); + } + return result; + } + + private void runLongMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + DeleteWebhookDeliveryCmd cmd = new DeleteWebhookDeliveryCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Long value = 100L; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + @Test + public void testGetId() { + runLongMemberTest("id"); + } + + @Test + public void testGetWebhookId() { + runLongMemberTest("webhookId"); + } + + @Test + public void testGetManagementServerId() { + runLongMemberTest("managementServerId"); + } + + @Test + public void testGetEntityOwnerId() { + Account account = new AccountVO("testaccount", 1L, "networkdomain", Account.Type.NORMAL, "uuid"); + UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN); + CallContext.register(user, account); + DeleteWebhookDeliveryCmd cmd = new DeleteWebhookDeliveryCmd(); + Assert.assertEquals(account.getId(), cmd.getEntityOwnerId()); + } + + @Test(expected = ServerApiException.class) + public void testExecuteCRE() { + DeleteWebhookDeliveryCmd cmd = new DeleteWebhookDeliveryCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.deleteWebhookDelivery(cmd)).thenThrow(CloudRuntimeException.class); + cmd.execute(); + } + + @Test + public void testExecute() { + DeleteWebhookDeliveryCmd cmd = new DeleteWebhookDeliveryCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.deleteWebhookDelivery(cmd)).thenReturn(10); + cmd.execute(); + Assert.assertNotNull(cmd.getResponseObject()); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ExecuteWebhookDeliveryCmdTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ExecuteWebhookDeliveryCmdTest.java new file mode 100644 index 000000000000..84d51a1e18d5 --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ExecuteWebhookDeliveryCmdTest.java @@ -0,0 +1,153 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.api.response.WebhookDeliveryResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.Account; +import com.cloud.user.AccountVO; +import com.cloud.user.User; +import com.cloud.user.UserVO; +import com.cloud.utils.exception.CloudRuntimeException; + +@RunWith(MockitoJUnitRunner.class) +public class ExecuteWebhookDeliveryCmdTest { + + @Mock + WebhookApiService webhookApiService; + + private Object getCommandMethodValue(Object obj, String methodName) { + Object result = null; + try { + Method method = obj.getClass().getMethod(methodName); + result = method.invoke(obj); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + Assert.fail(String.format("Failed to get method %s value", methodName)); + } + return result; + } + + private void runStringMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + ExecuteWebhookDeliveryCmd cmd = new ExecuteWebhookDeliveryCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + String value = UUID.randomUUID().toString(); + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runLongMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + ExecuteWebhookDeliveryCmd cmd = new ExecuteWebhookDeliveryCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Long value = 100L; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runBooleanMemberTest(String memberName) { + String methodName = "is" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + ExecuteWebhookDeliveryCmd cmd = new ExecuteWebhookDeliveryCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Boolean value = true; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + @Test + public void testGetId() { + runLongMemberTest("id"); + } + + @Test + public void testGetWebhookId() { + runLongMemberTest("webhookId"); + } + + @Test + public void testGetPayloadUrl() { + runStringMemberTest("payloadUrl"); + } + + @Test + public void testGetSecretKey() { + runStringMemberTest("secretKey"); + } + + @Test + public void testIsSslVerification() { + runBooleanMemberTest("sslVerification"); + } + + @Test + public void testGetPayload() { + runStringMemberTest("payload"); + } + + @Test + public void testGetEntityOwnerId() { + Account account = new AccountVO("testaccount", 1L, "networkdomain", Account.Type.NORMAL, "uuid"); + UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN); + CallContext.register(user, account); + ExecuteWebhookDeliveryCmd cmd = new ExecuteWebhookDeliveryCmd(); + Assert.assertEquals(account.getId(), cmd.getEntityOwnerId()); + } + + @Test(expected = ServerApiException.class) + public void testExecuteNullResponse() { + ExecuteWebhookDeliveryCmd cmd = new ExecuteWebhookDeliveryCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.executeWebhookDelivery(cmd)).thenReturn(null); + cmd.execute(); + } + + @Test(expected = ServerApiException.class) + public void testExecuteCRE() { + ExecuteWebhookDeliveryCmd cmd = new ExecuteWebhookDeliveryCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.executeWebhookDelivery(cmd)).thenThrow(CloudRuntimeException.class); + cmd.execute(); + } + + @Test + public void testExecute() { + ExecuteWebhookDeliveryCmd cmd = new ExecuteWebhookDeliveryCmd(); + cmd.webhookApiService = webhookApiService; + WebhookDeliveryResponse response = new WebhookDeliveryResponse(); + Mockito.when(webhookApiService.executeWebhookDelivery(cmd)).thenReturn(response); + cmd.execute(); + Assert.assertEquals(cmd.getCommandName(), response.getResponseName()); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhookDeliveriesCmdTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhookDeliveriesCmdTest.java new file mode 100644 index 000000000000..6359b042c408 --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhookDeliveriesCmdTest.java @@ -0,0 +1,141 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.api.response.WebhookDeliveryResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.Account; +import com.cloud.user.AccountVO; +import com.cloud.user.User; +import com.cloud.user.UserVO; + +@RunWith(MockitoJUnitRunner.class) +public class ListWebhookDeliveriesCmdTest { + + @Mock + WebhookApiService webhookApiService; + + private Object getCommandMethodValue(Object obj, String methodName) { + Object result = null; + try { + Method method = obj.getClass().getMethod(methodName); + result = method.invoke(obj); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + Assert.fail(String.format("Failed to get method %s value", methodName)); + } + return result; + } + + private void runLongMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + ListWebhookDeliveriesCmd cmd = new ListWebhookDeliveriesCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Long value = 100L; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runStringMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + ListWebhookDeliveriesCmd cmd = new ListWebhookDeliveriesCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + String value = UUID.randomUUID().toString(); + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runDateMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + ListWebhookDeliveriesCmd cmd = new ListWebhookDeliveriesCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Date value = new Date(); + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + @Test + public void testGetId() { + runLongMemberTest("id"); + } + + @Test + public void testGetWebhookId() { + runLongMemberTest("webhookId"); + } + + @Test + public void testGetManagementServerId() { + runLongMemberTest("managementServerId"); + } + + @Test + public void testStartDate() { + runDateMemberTest("startDate"); + } + + @Test + public void testEndDate() { + runDateMemberTest("endDate"); + } + + @Test + public void testEventType() { + runStringMemberTest("eventType"); + } + + @Test + public void testGetEntityOwnerId() { + Account account = new AccountVO("testaccount", 1L, "networkdomain", Account.Type.NORMAL, "uuid"); + UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN); + CallContext.register(user, account); + ListWebhookDeliveriesCmd cmd = new ListWebhookDeliveriesCmd(); + Assert.assertEquals(account.getId(), cmd.getEntityOwnerId()); + } + + @Test + public void testExecute() { + ListWebhookDeliveriesCmd cmd = new ListWebhookDeliveriesCmd(); + cmd.webhookApiService = webhookApiService; + List responseList = new ArrayList<>(); + ListResponse listResponse = new ListResponse<>(); + listResponse.setResponses(responseList); + Mockito.when(webhookApiService.listWebhookDeliveries(cmd)).thenReturn(listResponse); + cmd.execute(); + Assert.assertNotNull(cmd.getResponseObject()); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhooksCmdTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhooksCmdTest.java new file mode 100644 index 000000000000..1cbf9d1e8361 --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/ListWebhooksCmdTest.java @@ -0,0 +1,105 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ListWebhooksCmdTest { + + @Mock + WebhookApiService webhookApiService; + + private Object getCommandMethodValue(Object obj, String methodName) { + Object result = null; + try { + Method method = obj.getClass().getMethod(methodName); + result = method.invoke(obj); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + Assert.fail(String.format("Failed to get method %s value", methodName)); + } + return result; + } + + private void runStringMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + ListWebhooksCmd cmd = new ListWebhooksCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + String value = UUID.randomUUID().toString(); + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runLongMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + ListWebhooksCmd cmd = new ListWebhooksCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Long value = 100L; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + @Test + public void testGetId() { + runLongMemberTest("id"); + } + + @Test + public void testGetName() { + runStringMemberTest("name"); + } + + @Test + public void testGetState() { + runStringMemberTest("state"); + } + + @Test + public void testGetScope() { + runStringMemberTest("scope"); + } + + @Test + public void testExecute() { + ListWebhooksCmd cmd = new ListWebhooksCmd(); + cmd.webhookApiService = webhookApiService; + List responseList = new ArrayList<>(); + ListResponse listResponse = new ListResponse<>(); + listResponse.setResponses(responseList); + Mockito.when(webhookApiService.listWebhooks(cmd)).thenReturn(listResponse); + cmd.execute(); + Assert.assertNotNull(cmd.getResponseObject()); + } +} diff --git a/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/UpdateWebhookCmdTest.java b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/UpdateWebhookCmdTest.java new file mode 100644 index 000000000000..719e63cadf2c --- /dev/null +++ b/plugins/event-bus/webhook/src/test/java/org/apache/cloudstack/mom/webhook/api/command/user/UpdateWebhookCmdTest.java @@ -0,0 +1,163 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.mom.webhook.api.command.user; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.mom.webhook.WebhookApiService; +import org.apache.cloudstack.mom.webhook.api.response.WebhookResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.Account; +import com.cloud.user.AccountVO; +import com.cloud.user.User; +import com.cloud.user.UserVO; +import com.cloud.utils.exception.CloudRuntimeException; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateWebhookCmdTest { + + @Mock + WebhookApiService webhookApiService; + + private Object getCommandMethodValue(Object obj, String methodName) { + Object result = null; + try { + Method method = obj.getClass().getMethod(methodName); + result = method.invoke(obj); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + Assert.fail(String.format("Failed to get method %s value", methodName)); + } + return result; + } + + private void runStringMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + UpdateWebhookCmd cmd = new UpdateWebhookCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + String value = UUID.randomUUID().toString(); + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runLongMemberTest(String memberName) { + String methodName = "get" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + UpdateWebhookCmd cmd = new UpdateWebhookCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Long value = 100L; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + private void runBooleanMemberTest(String memberName) { + String methodName = "is" + memberName.substring(0, 1).toUpperCase() + memberName.substring(1); + UpdateWebhookCmd cmd = new UpdateWebhookCmd(); + ReflectionTestUtils.setField(cmd, memberName, null); + Assert.assertNull(getCommandMethodValue(cmd, methodName)); + Boolean value = true; + ReflectionTestUtils.setField(cmd, memberName, value); + Assert.assertEquals(value, getCommandMethodValue(cmd, methodName)); + } + + @Test + public void testGetId() { + runLongMemberTest("id"); + } + + @Test + public void testGetName() { + runStringMemberTest("name"); + } + + @Test + public void testGetDescription() { + runStringMemberTest("description"); + } + + @Test + public void testGetPayloadUrl() { + runStringMemberTest("payloadUrl"); + } + + @Test + public void testGetSecretKey() { + runStringMemberTest("secretKey"); + } + + @Test + public void testGetScope() { + runStringMemberTest("scope"); + } + + @Test + public void testGetState() { + runStringMemberTest("state"); + } + + @Test + public void testIsSslVerification() { + runBooleanMemberTest("sslVerification"); + } + + @Test + public void testGetEntityOwnerId() { + Account account = new AccountVO("testaccount", 1L, "networkdomain", Account.Type.NORMAL, "uuid"); + UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN); + CallContext.register(user, account); + UpdateWebhookCmd cmd = new UpdateWebhookCmd(); + Assert.assertEquals(account.getId(), cmd.getEntityOwnerId()); + } + + @Test(expected = ServerApiException.class) + public void testExecuteNullResponse() { + UpdateWebhookCmd cmd = new UpdateWebhookCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.updateWebhook(cmd)).thenReturn(null); + cmd.execute(); + } + + @Test(expected = ServerApiException.class) + public void testExecuteCRE() { + UpdateWebhookCmd cmd = new UpdateWebhookCmd(); + cmd.webhookApiService = webhookApiService; + Mockito.when(webhookApiService.updateWebhook(cmd)).thenThrow(CloudRuntimeException.class); + cmd.execute(); + } + + @Test + public void testExecute() { + UpdateWebhookCmd cmd = new UpdateWebhookCmd(); + cmd.webhookApiService = webhookApiService; + WebhookResponse response = new WebhookResponse(); + Mockito.when(webhookApiService.updateWebhook(cmd)).thenReturn(response); + cmd.execute(); + Assert.assertEquals(cmd.getCommandName(), response.getResponseName()); + } +} diff --git a/plugins/ha-planners/skip-heurestics/pom.xml b/plugins/ha-planners/skip-heurestics/pom.xml index 2fcbdad2d6d2..3dc3989da2cb 100644 --- a/plugins/ha-planners/skip-heurestics/pom.xml +++ b/plugins/ha-planners/skip-heurestics/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/ha-planners/skip-heurestics/src/main/java/com/cloud/deploy/SkipHeuresticsPlanner.java b/plugins/ha-planners/skip-heurestics/src/main/java/com/cloud/deploy/SkipHeuresticsPlanner.java index 6f9d696a1711..c6e2ea4d99f0 100644 --- a/plugins/ha-planners/skip-heurestics/src/main/java/com/cloud/deploy/SkipHeuresticsPlanner.java +++ b/plugins/ha-planners/skip-heurestics/src/main/java/com/cloud/deploy/SkipHeuresticsPlanner.java @@ -17,7 +17,6 @@ package com.cloud.deploy; import com.cloud.vm.VirtualMachineProfile; -import org.apache.log4j.Logger; import javax.naming.ConfigurationException; @@ -25,7 +24,6 @@ import java.util.Map; public class SkipHeuresticsPlanner extends FirstFitPlanner implements HAPlanner { - private static final Logger s_logger = Logger.getLogger(SkipHeuresticsPlanner.class); /** @@ -37,8 +35,8 @@ public class SkipHeuresticsPlanner extends FirstFitPlanner implements HAPlanner @Override protected void removeClustersCrossingThreshold(List clusterListForVmAllocation, ExcludeList avoid, VirtualMachineProfile vmProfile, DeploymentPlan plan){ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Deploying vm during HA process, so skipping disable threshold check"); + if (logger.isDebugEnabled()) { + logger.debug("Deploying vm during HA process, so skipping disable threshold check"); } return; } diff --git a/plugins/ha-planners/skip-heurestics/src/main/resources/META-INF/cloudstack/skip-heurestics/spring-skip-heurestics-context.xml b/plugins/ha-planners/skip-heurestics/src/main/resources/META-INF/cloudstack/skip-heurestics/spring-skip-heurestics-context.xml index 3cb5a55bb158..f28d67c5bc12 100644 --- a/plugins/ha-planners/skip-heurestics/src/main/resources/META-INF/cloudstack/skip-heurestics/spring-skip-heurestics-context.xml +++ b/plugins/ha-planners/skip-heurestics/src/main/resources/META-INF/cloudstack/skip-heurestics/spring-skip-heurestics-context.xml @@ -1,12 +1,12 @@ - org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java index eb9ab7148b28..a71ae26e670d 100644 --- a/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java +++ b/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java @@ -24,7 +24,8 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.ListUtils; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import com.cloud.agent.manager.allocator.HostAllocator; @@ -35,9 +36,11 @@ import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.host.Host; import com.cloud.host.Host.Type; +import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.offering.ServiceOffering; import com.cloud.resource.ResourceManager; +import com.cloud.storage.VMTemplateVO; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.VirtualMachine; @@ -45,7 +48,6 @@ @Component public class RandomAllocator extends AdapterBase implements HostAllocator { - private static final Logger s_logger = Logger.getLogger(RandomAllocator.class); @Inject private HostDao _hostDao; @Inject @@ -57,6 +59,27 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { @Inject private CapacityManager capacityManager; + protected List listHostsByTags(Host.Type type, long dcId, Long podId, Long clusterId, String offeringHostTag, String templateTag) { + List taggedHosts = new ArrayList<>(); + if (offeringHostTag != null) { + taggedHosts.addAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, offeringHostTag)); + } + if (templateTag != null) { + List templateTaggedHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, templateTag); + if (taggedHosts.isEmpty()) { + taggedHosts = templateTaggedHosts; + } else { + taggedHosts.retainAll(templateTaggedHosts); + } + } + if (logger.isDebugEnabled()) { + logger.debug(String.format("Found %d hosts %s with type: %s, zone ID: %d, pod ID: %d, cluster ID: %s, offering host tag(s): %s, template tag: %s", + taggedHosts.size(), + (taggedHosts.isEmpty() ? "" : String.format("(%s)", StringUtils.join(taggedHosts.stream().map(HostVO::getId).toArray(), ","))), + type.name(), dcId, podId, clusterId, offeringHostTag, templateTag)); + } + return taggedHosts; + } private List findSuitableHosts(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { @@ -64,44 +87,47 @@ private List findSuitableHosts(VirtualMachineProfile vmProfile, Deployment Long podId = plan.getPodId(); Long clusterId = plan.getClusterId(); ServiceOffering offering = vmProfile.getServiceOffering(); + List hostsCopy = null; List suitableHosts = new ArrayList<>(); if (type == Host.Type.Storage) { return suitableHosts; } - - String hostTag = offering.getHostTag(); - String hostTagToLog = hostTag != null ? String.format("and complying with host tags [%s]", hostTag) : ""; - String paramAsStringToLog = String.format("zone [%s], pod [%s], cluster [%s] %s", dcId, podId, clusterId, hostTagToLog); - - s_logger.debug(String.format("Looking for hosts in %s.", paramAsStringToLog)); - - List hostsCopy; - + String offeringHostTag = offering.getHostTag(); + VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate(); + String templateTag = template.getTemplateTag(); + String hostTag = null; + if (ObjectUtils.anyNull(offeringHostTag, templateTag)) { + hostTag = offeringHostTag; + hostTag = hostTag == null ? templateTag : String.format("%s, %s", hostTag, templateTag); + logger.debug(String.format("Looking for hosts in dc [%s], pod [%s], cluster [%s] and complying with host tag(s): [%s]", dcId, podId, clusterId, hostTag)); + } else { + logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId); + } if (hosts != null) { // retain all computing hosts, regardless of whether they support routing...it's random after all - hostsCopy = new ArrayList(hosts); - if (hostTag != null) { - hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag)); + hostsCopy = new ArrayList<>(hosts); + if (ObjectUtils.anyNotNull(offeringHostTag, templateTag)) { + hostsCopy.retainAll(listHostsByTags(type, dcId, podId, clusterId, offeringHostTag, templateTag)); } else { hostsCopy.retainAll(_hostDao.listAllHostsThatHaveNoRuleTag(type, clusterId, podId, dcId)); } } else { // list all computing hosts, regardless of whether they support routing...it's random after all - if (hostTag != null) { - hostsCopy = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag); + if (offeringHostTag != null) { + hostsCopy = listHostsByTags(type, dcId, podId, clusterId, offeringHostTag, templateTag); } else { hostsCopy = _hostDao.listAllHostsThatHaveNoRuleTag(type, clusterId, podId, dcId); } } - hostsCopy = ListUtils.union(hostsCopy, _hostDao.findHostsWithTagRuleThatMatchComputeOferringTags(hostTag)); + hostsCopy = ListUtils.union(hostsCopy, _hostDao.findHostsWithTagRuleThatMatchComputeOferringTags(offeringHostTag)); if (hostsCopy.isEmpty()) { - s_logger.info(String.format("No suitable host found for VM [%s] in %s.", vmProfile, paramAsStringToLog)); + logger.info("No suitable host found for VM [{}] in {}.", vmProfile, hostTag); return null; } - s_logger.debug("Random Allocator found " + hostsCopy.size() + " hosts"); + logger.debug("Random Allocator found {} hosts", hostsCopy.size()); if (hostsCopy.isEmpty()) { return suitableHosts; } @@ -112,25 +138,25 @@ private List findSuitableHosts(VirtualMachineProfile vmProfile, Deployment break; } if (avoid.shouldAvoid(host)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " is in avoid set, skipping this and trying other available hosts"); + if (logger.isDebugEnabled()) { + logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " is in avoid set, skipping this and trying other available hosts"); } continue; } Pair cpuCapabilityAndCapacity = capacityManager.checkIfHostHasCpuCapabilityAndCapacity(host, offering, considerReservedCapacity); if (!cpuCapabilityAndCapacity.first() || !cpuCapabilityAndCapacity.second()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Not using host " + host.getId() + "; host has cpu capability? " + cpuCapabilityAndCapacity.first() + ", host has capacity?" + cpuCapabilityAndCapacity.second()); + if (logger.isDebugEnabled()) { + logger.debug("Not using host " + host.getId() + "; host has cpu capability? " + cpuCapabilityAndCapacity.first() + ", host has capacity?" + cpuCapabilityAndCapacity.second()); } continue; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found a suitable host, adding to list: " + host.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Found a suitable host, adding to list: " + host.getId()); } suitableHosts.add(host); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Random Host Allocator returning " + suitableHosts.size() + " suitable hosts"); + if (logger.isDebugEnabled()) { + logger.debug("Random Host Allocator returning " + suitableHosts.size() + " suitable hosts"); } return suitableHosts; } @@ -145,10 +171,10 @@ public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { if (CollectionUtils.isEmpty(hosts)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Random Allocator found 0 hosts as given host list is empty"); + if (logger.isDebugEnabled()) { + logger.debug("Random Allocator found 0 hosts as given host list is empty"); } - return new ArrayList(); + return new ArrayList<>(); } return findSuitableHosts(vmProfile, plan, type, avoid, hosts, returnUpTo, considerReservedCapacity); } diff --git a/plugins/host-allocators/random/src/main/resources/META-INF/cloudstack/host-allocator-random/spring-host-allocator-random-context.xml b/plugins/host-allocators/random/src/main/resources/META-INF/cloudstack/host-allocator-random/spring-host-allocator-random-context.xml index 979ccc43e088..d84eaafaa5a7 100644 --- a/plugins/host-allocators/random/src/main/resources/META-INF/cloudstack/host-allocator-random/spring-host-allocator-random-context.xml +++ b/plugins/host-allocators/random/src/main/resources/META-INF/cloudstack/host-allocator-random/spring-host-allocator-random-context.xml @@ -30,5 +30,5 @@ - + diff --git a/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java b/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java new file mode 100644 index 000000000000..538d7157184a --- /dev/null +++ b/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java @@ -0,0 +1,80 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.agent.manager.allocator.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; + +@RunWith(MockitoJUnitRunner.class) +public class RandomAllocatorTest { + + @Mock + HostDao hostDao; + @InjectMocks + RandomAllocator randomAllocator; + + @Test + public void testListHostsByTags() { + Host.Type type = Host.Type.Routing; + Long id = 1L; + String templateTag = "tag1"; + String offeringTag = "tag2"; + HostVO host1 = Mockito.mock(HostVO.class); + HostVO host2 = Mockito.mock(HostVO.class); + Mockito.when(hostDao.listByHostTag(type, id, id, id, offeringTag)).thenReturn(List.of(host1, host2)); + + // No template tagged host + Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(new ArrayList<>()); + List result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag); + Assert.assertTrue(CollectionUtils.isEmpty(result)); + + // Different template tagged host + HostVO host3 = Mockito.mock(HostVO.class); + Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(List.of(host3)); + result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag); + Assert.assertTrue(CollectionUtils.isEmpty(result)); + + // Matching template tagged host + Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(List.of(host1)); + result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag); + Assert.assertFalse(CollectionUtils.isEmpty(result)); + Assert.assertEquals(1, result.size()); + + // No template tag + result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, null); + Assert.assertFalse(CollectionUtils.isEmpty(result)); + Assert.assertEquals(2, result.size()); + + // No offering tag + result = randomAllocator.listHostsByTags(type, id, id, id, null, templateTag); + Assert.assertFalse(CollectionUtils.isEmpty(result)); + Assert.assertEquals(1, result.size()); + } +} diff --git a/plugins/hypervisors/baremetal/pom.xml b/plugins/hypervisors/baremetal/pom.xml index 3f10b25ccef7..d866c9b47e2f 100755 --- a/plugins/hypervisors/baremetal/pom.xml +++ b/plugins/hypervisors/baremetal/pom.xml @@ -22,7 +22,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml cloud-plugin-hypervisor-baremetal @@ -45,7 +45,7 @@ com.sun.xml.bind jaxb-impl - ${cs.jaxb.version} + ${cs.jaxb.impl.version} diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalDiscoverer.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalDiscoverer.java index 3bdd2e81fb51..321369b24b9e 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalDiscoverer.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalDiscoverer.java @@ -33,7 +33,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.ApiConstants; -import org.apache.log4j.Logger; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; @@ -61,7 +60,6 @@ import com.cloud.vm.dao.VMInstanceDao; public class BareMetalDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter { - protected static final Logger s_logger = Logger.getLogger(BareMetalDiscoverer.class); @Inject protected VMInstanceDao _vmDao = null; @@ -92,25 +90,25 @@ public Map> find(long dcId, Long p if (!url.getScheme().equals("http")) { String msg = "urlString is not http so we're not taking care of the discovery for this: " + url; - s_logger.debug(msg); + logger.debug(msg); return null; } if (clusterId == null) { String msg = "must specify cluster Id when add host"; - s_logger.debug(msg); + logger.debug(msg); throw new RuntimeException(msg); } if (podId == null) { String msg = "must specify pod Id when add host"; - s_logger.debug(msg); + logger.debug(msg); throw new RuntimeException(msg); } ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null || (cluster.getHypervisorType() != HypervisorType.BareMetal)) { - if (s_logger.isInfoEnabled()) - s_logger.info("invalid cluster id or cluster is not for Bare Metal hosts"); + if (logger.isInfoEnabled()) + logger.info("invalid cluster id or cluster is not for Bare Metal hosts"); return null; } @@ -132,14 +130,14 @@ public Map> find(long dcId, Long p + injectScript); } - final Script2 command = new Script2(scriptPath, s_logger); + final Script2 command = new Script2(scriptPath, logger); command.add("ping"); command.add("hostname="+ipmiIp); command.add("usrname="+username); command.add("password="+password, ParamType.PASSWORD); final String result = command.execute(); if (result != null) { - s_logger.warn(String.format("Can not set up ipmi connection(ip=%1$s, username=%2$s, password=%3$s, args) because %4$s", ipmiIp, username, "******", result)); + logger.warn(String.format("Can not set up ipmi connection(ip=%1$s, username=%2$s, password=%3$s, args) because %4$s", ipmiIp, username, "******", result)); return null; } @@ -205,11 +203,11 @@ public Map> find(long dcId, Long p zone.setDhcpProvider(Network.Provider.ExternalDhcpServer.getName()); _dcDao.update(zone.getId(), zone); - s_logger.debug(String.format("Discover Bare Metal host successfully(ip=%1$s, username=%2$s, password=%3$s," + + logger.debug(String.format("Discover Bare Metal host successfully(ip=%1$s, username=%2$s, password=%3$s," + "cpuNum=%4$s, cpuCapacity-%5$s, memCapacity=%6$s)", ipmiIp, username, "******", cpuNum, cpuCapacity, memCapacity)); return resources; } catch (Exception e) { - s_logger.warn("Can not set up bare metal agent", e); + logger.warn("Can not set up bare metal agent", e); } return null; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalGuru.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalGuru.java index f82ad489b8da..a1b306b66c91 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalGuru.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalGuru.java @@ -27,7 +27,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -39,7 +38,6 @@ import com.cloud.vm.VirtualMachineProfile; public class BareMetalGuru extends HypervisorGuruBase implements HypervisorGuru { - private static final Logger s_logger = Logger.getLogger(BareMetalGuru.class); @Inject GuestOSDao _guestOsDao; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalPlanner.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalPlanner.java index c37b51df5e9b..318ac225c8c0 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalPlanner.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalPlanner.java @@ -24,7 +24,6 @@ import com.cloud.utils.NumbersUtil; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import com.cloud.capacity.CapacityManager; import com.cloud.dc.ClusterDetailsDao; @@ -51,7 +50,6 @@ import com.cloud.vm.VirtualMachineProfile; public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { - private static final Logger s_logger = Logger.getLogger(BareMetalPlanner.class); @Inject protected DataCenterDao _dcDao; @Inject @@ -82,7 +80,7 @@ public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan pl DataCenter dc = _dcDao.findById(h.getDataCenterId()); Pod pod = _podDao.findById(h.getPodId()); Cluster c = _clusterDao.findById(h.getClusterId()); - s_logger.debug("Start baremetal vm " + vm.getId() + " on last stayed host " + h.getId()); + logger.debug("Start baremetal vm " + vm.getId() + " on last stayed host " + h.getId()); return new DeployDestination(dc, pod, c, h); } @@ -114,7 +112,7 @@ public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan pl } if (target == null) { - s_logger.warn("Cannot find host with tag " + hostTag + " use capacity from service offering"); + logger.warn("Cannot find host with tag " + hostTag + " use capacity from service offering"); cpu_requested = offering.getCpu() * offering.getSpeed(); ram_requested = offering.getRamSize() * 1024L * 1024L; } else { @@ -126,7 +124,7 @@ public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan pl if (haVmTag == null) { hosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); } else { - s_logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + + logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + cluster.getDataCenterId()); return null; } @@ -138,7 +136,7 @@ public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan pl Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue()); if (_capacityMgr.checkIfHostHasCapacity(h.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true)) { - s_logger.debug("Find host " + h.getId() + " has enough capacity"); + logger.debug("Find host " + h.getId() + " has enough capacity"); DataCenter dc = _dcDao.findById(h.getDataCenterId()); Pod pod = _podDao.findById(h.getPodId()); return new DeployDestination(dc, pod, cluster, h); @@ -146,7 +144,7 @@ public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan pl } } - s_logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, NumbersUtil.toHumanReadableSize(ram_requested))); + logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, NumbersUtil.toHumanReadableSize(ram_requested))); return null; } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java index 8265f951f8a8..940897de3c95 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java @@ -45,14 +45,12 @@ import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd; import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.Date; import java.util.List; public class BareMetalTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter { - private final static Logger s_logger = Logger.getLogger(BareMetalTemplateAdapter.class); @Inject HostDao _hostDao; @Inject @@ -141,7 +139,7 @@ public boolean delete(TemplateProfile profile) { zoneName = "all zones"; } - s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); + logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId()); String eventType = EventTypes.EVENT_TEMPLATE_DELETE; List templateHostVOs = this._tmpltStoreDao.listByTemplate(templateId); @@ -151,7 +149,7 @@ public boolean delete(TemplateProfile profile) { try { lock = _tmpltStoreDao.acquireInLockTable(vo.getId()); if (lock == null) { - s_logger.debug("Failed to acquire lock when deleting templateDataStoreVO with ID: " + vo.getId()); + logger.debug("Failed to acquire lock when deleting templateDataStoreVO with ID: " + vo.getId()); success = false; break; } @@ -184,7 +182,7 @@ public boolean delete(TemplateProfile profile) { } } - s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); + logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); // If there are no more non-destroyed template host entries for this template, delete it if (success && (_tmpltStoreDao.listByTemplate(templateId).size() == 0)) { @@ -194,7 +192,7 @@ public boolean delete(TemplateProfile profile) { try { if (lock == null) { - s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId); + logger.debug("Failed to acquire lock when deleting template with ID: " + templateId); success = false; } else if (_tmpltDao.remove(templateId)) { // Decrement the number of templates and total secondary storage space used by the account. @@ -207,7 +205,7 @@ public boolean delete(TemplateProfile profile) { _tmpltDao.releaseFromLockTable(lock.getId()); } } - s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed."); + logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed."); } return success; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BaremetalManagerImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BaremetalManagerImpl.java index b1aafc692ef1..bf991b77e1cb 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BaremetalManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BaremetalManagerImpl.java @@ -32,7 +32,6 @@ import com.cloud.vm.VMInstanceVO; import com.cloud.vm.dao.VMInstanceDao; import org.apache.cloudstack.api.BaremetalProvisionDoneNotificationCmd; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.AddBaremetalHostCmd; @@ -46,7 +45,6 @@ import com.cloud.vm.VirtualMachine.State; public class BaremetalManagerImpl extends ManagerBase implements BaremetalManager, StateListener { - private static final Logger s_logger = Logger.getLogger(BaremetalManagerImpl.class); @Inject protected HostDao _hostDao; @@ -93,17 +91,17 @@ public boolean postStateTransitionEvent(StateMachine2.Transition t HostVO host = _hostDao.findById(vo.getHostId()); if (host == null) { - s_logger.debug("Skip oldState " + oldState + " to " + "newState " + newState + " transimtion"); + logger.debug("Skip oldState " + oldState + " to " + "newState " + newState + " transimtion"); return true; } _hostDao.loadDetails(host); if (newState == State.Starting) { host.setDetail("vmName", vo.getInstanceName()); - s_logger.debug("Add vmName " + host.getDetail("vmName") + " to host " + host.getId() + " details"); + logger.debug("Add vmName " + host.getDetail("vmName") + " to host " + host.getId() + " details"); } else { if (host.getDetail("vmName") != null && host.getDetail("vmName").equalsIgnoreCase(vo.getInstanceName())) { - s_logger.debug("Remove vmName " + host.getDetail("vmName") + " from host " + host.getId() + " details"); + logger.debug("Remove vmName " + host.getDetail("vmName") + " from host " + host.getId() + " details"); host.getDetails().remove("vmName"); } } @@ -150,7 +148,7 @@ public void notifyProvisionDone(BaremetalProvisionDoneNotificationCmd cmd) { vm.setState(State.Running); vm.setLastHostId(vm.getHostId()); vmDao.update(vm.getId(), vm); - s_logger.debug(String.format("received baremetal provision done notification for vm[id:%s name:%s] running on host[mac:%s, ip:%s]", + logger.debug(String.format("received baremetal provision done notification for vm[id:%s name:%s] running on host[mac:%s, ip:%s]", vm.getId(), vm.getInstanceName(), host.getPrivateMacAddress(), host.getPrivateIpAddress())); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java index fc7596a9dd66..509fd340dae4 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.AddBaremetalPxeCmd; import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd; import org.apache.cloudstack.api.ListBaremetalPxeServersCmd; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.baremetal.IpmISetBootDevCommand; @@ -68,7 +67,6 @@ import com.cloud.vm.VirtualMachineProfile; public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements BaremetalPxeService { - private static final Logger s_logger = Logger.getLogger(BareMetalPingServiceImpl.class); @Inject ResourceManager _resourceMgr; @Inject @@ -107,19 +105,19 @@ public boolean prepare(VirtualMachineProfile profile, NicProfile pxeNic, Network new PreparePxeServerCommand(ip, mac, mask, gateway, dns, tpl, profile.getVirtualMachine().getInstanceName(), dest.getHost().getName()); PreparePxeServerAnswer ans = (PreparePxeServerAnswer)_agentMgr.send(pxeServerId, cmd); if (!ans.getResult()) { - s_logger.warn("Unable tot program PXE server: " + pxeVo.getId() + " because " + ans.getDetails()); + logger.warn("Unable tot program PXE server: " + pxeVo.getId() + " because " + ans.getDetails()); return false; } IpmISetBootDevCommand bootCmd = new IpmISetBootDevCommand(BootDev.pxe); Answer anw = _agentMgr.send(dest.getHost().getId(), bootCmd); if (!anw.getResult()) { - s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + anw.getDetails()); + logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + anw.getDetails()); } return anw.getResult(); } catch (Exception e) { - s_logger.warn("Cannot prepare PXE server", e); + logger.warn("Cannot prepare PXE server", e); return false; } } @@ -150,7 +148,7 @@ public boolean prepareCreateTemplate(Long pxeServerId, UserVm vm, String templat Answer ans = _agentMgr.send(pxeServerId, cmd); return ans.getResult(); } catch (Exception e) { - s_logger.debug("Prepare for creating baremetal template failed", e); + logger.debug("Prepare for creating baremetal template failed", e); return false; } } @@ -219,7 +217,7 @@ public BaremetalPxeVO addPxeServer(AddBaremetalPxeCmd cmd) { try { uri = new URI(cmd.getUrl()); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new IllegalArgumentException(e.getMessage()); } String ipAddress = uri.getHost(); @@ -244,7 +242,7 @@ public BaremetalPxeVO addPxeServer(AddBaremetalPxeCmd cmd) { try { resource.configure("PING PXE resource", params); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new CloudRuntimeException(e.getMessage()); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalResourceBase.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalResourceBase.java index 0cdd0f128224..007640e8aad3 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalResourceBase.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalResourceBase.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -83,7 +82,6 @@ import com.cloud.vm.dao.VMInstanceDao; public class BareMetalResourceBase extends ManagerBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(BareMetalResourceBase.class); protected String _uuid; protected String _zone; protected String _pod; @@ -176,20 +174,20 @@ public boolean configure(String name, Map params) throws Configu try { ipmiIface = configDao.getValue(Config.BaremetalIpmiLanInterface.key()); } catch (Exception e) { - s_logger.debug(e.getMessage(), e); + logger.debug(e.getMessage(), e); } try { ipmiRetryTimes = Integer.parseInt(configDao.getValue(Config.BaremetalIpmiRetryTimes.key())); } catch (Exception e) { - s_logger.debug(e.getMessage(), e); + logger.debug(e.getMessage(), e); } try { provisionDoneNotificationOn = Boolean.valueOf(configDao.getValue(Config.BaremetalProvisionDoneNotificationEnabled.key())); isProvisionDoneNotificationTimeout = Integer.parseInt(configDao.getValue(Config.BaremetalProvisionDoneNotificationTimeout.key())); } catch (Exception e) { - s_logger.debug(e.getMessage(), e); + logger.debug(e.getMessage(), e); } String injectScript = "scripts/util/ipmi.py"; @@ -198,7 +196,7 @@ public boolean configure(String name, Map params) throws Configu throw new ConfigurationException("Cannot find ping script " + scriptPath); } String pythonPath = "/usr/bin/python"; - _pingCommand = new Script2(pythonPath, s_logger); + _pingCommand = new Script2(pythonPath, logger); _pingCommand.add(scriptPath); _pingCommand.add("ping"); _pingCommand.add("interface=" + ipmiIface); @@ -206,7 +204,7 @@ public boolean configure(String name, Map params) throws Configu _pingCommand.add("usrname=" + _username); _pingCommand.add("password=" + _password, ParamType.PASSWORD); - _setPxeBootCommand = new Script2(pythonPath, s_logger); + _setPxeBootCommand = new Script2(pythonPath, logger); _setPxeBootCommand.add(scriptPath); _setPxeBootCommand.add("boot_dev"); _setPxeBootCommand.add("interface=" + ipmiIface); @@ -215,7 +213,7 @@ public boolean configure(String name, Map params) throws Configu _setPxeBootCommand.add("password=" + _password, ParamType.PASSWORD); _setPxeBootCommand.add("dev=pxe"); - _setDiskBootCommand = new Script2(pythonPath, s_logger); + _setDiskBootCommand = new Script2(pythonPath, logger); _setDiskBootCommand.add(scriptPath); _setDiskBootCommand.add("boot_dev"); _setDiskBootCommand.add("interface=" + ipmiIface); @@ -224,7 +222,7 @@ public boolean configure(String name, Map params) throws Configu _setDiskBootCommand.add("password=" + _password, ParamType.PASSWORD); _setDiskBootCommand.add("dev=disk"); - _rebootCommand = new Script2(pythonPath, s_logger); + _rebootCommand = new Script2(pythonPath, logger); _rebootCommand.add(scriptPath); _rebootCommand.add("reboot"); _rebootCommand.add("interface=" + ipmiIface); @@ -232,7 +230,7 @@ public boolean configure(String name, Map params) throws Configu _rebootCommand.add("usrname=" + _username); _rebootCommand.add("password=" + _password, ParamType.PASSWORD); - _getStatusCommand = new Script2(pythonPath, s_logger); + _getStatusCommand = new Script2(pythonPath, logger); _getStatusCommand.add(scriptPath); _getStatusCommand.add("ping"); _getStatusCommand.add("interface=" + ipmiIface); @@ -240,7 +238,7 @@ public boolean configure(String name, Map params) throws Configu _getStatusCommand.add("usrname=" + _username); _getStatusCommand.add("password=" + _password, ParamType.PASSWORD); - _powerOnCommand = new Script2(pythonPath, s_logger); + _powerOnCommand = new Script2(pythonPath, logger); _powerOnCommand.add(scriptPath); _powerOnCommand.add("power"); _powerOnCommand.add("interface=" + ipmiIface); @@ -249,7 +247,7 @@ public boolean configure(String name, Map params) throws Configu _powerOnCommand.add("password=" + _password, ParamType.PASSWORD); _powerOnCommand.add("action=on"); - _powerOffCommand = new Script2(pythonPath, s_logger); + _powerOffCommand = new Script2(pythonPath, logger); _powerOffCommand.add(scriptPath); _powerOffCommand.add("power"); _powerOffCommand.add("interface=" + ipmiIface); @@ -258,7 +256,7 @@ public boolean configure(String name, Map params) throws Configu _powerOffCommand.add("password=" + _password, ParamType.PASSWORD); _powerOffCommand.add("action=soft"); - _forcePowerOffCommand = new Script2(pythonPath, s_logger); + _forcePowerOffCommand = new Script2(pythonPath, logger); _forcePowerOffCommand.add(scriptPath); _forcePowerOffCommand.add("power"); _forcePowerOffCommand.add("interface=" + ipmiIface); @@ -267,7 +265,7 @@ public boolean configure(String name, Map params) throws Configu _forcePowerOffCommand.add("password=" + _password, ParamType.PASSWORD); _forcePowerOffCommand.add("action=off"); - _bootOrRebootCommand = new Script2(pythonPath, s_logger); + _bootOrRebootCommand = new Script2(pythonPath, logger); _bootOrRebootCommand.add(scriptPath); _bootOrRebootCommand.add("boot_or_reboot"); _bootOrRebootCommand.add("interface=" + ipmiIface); @@ -299,11 +297,11 @@ protected boolean doScript(Script cmd, OutputInterpreter interpreter, int retry) res = cmd.execute(interpreter); } if (res != null && res.startsWith("Error: Unable to establish LAN")) { - s_logger.warn("IPMI script timeout(" + cmd.toString() + "), will retry " + retry + " times"); + logger.warn("IPMI script timeout(" + cmd.toString() + "), will retry " + retry + " times"); try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while waiting to retry running script."); + logger.debug("[ignored] interrupted while waiting to retry running script."); } continue; } else if (res == null) { @@ -313,7 +311,7 @@ protected boolean doScript(Script cmd, OutputInterpreter interpreter, int retry) } } - s_logger.warn("IPMI Scirpt failed due to " + res + "(" + cmd.toString() + ")"); + logger.warn("IPMI Scirpt failed due to " + res + "(" + cmd.toString() + ")"); return false; } @@ -379,12 +377,12 @@ public PingCommand getCurrentStatus(long id) { if (!ipmiPing()) { Thread.sleep(1000); if (!ipmiPing()) { - s_logger.warn("Cannot ping ipmi nic " + _ip); + logger.warn("Cannot ping ipmi nic " + _ip); return null; } } } catch (Exception e) { - s_logger.debug("Cannot ping ipmi nic " + _ip, e); + logger.debug("Cannot ping ipmi nic " + _ip, e); return null; } @@ -419,11 +417,11 @@ protected Answer execute(IpmISetBootDevCommand cmd) { String bootDev = cmd.getBootDev().name(); if (!doScript(bootCmd)) { - s_logger.warn("Set " + _ip + " boot dev to " + bootDev + "failed"); + logger.warn("Set " + _ip + " boot dev to " + bootDev + "failed"); return new Answer(cmd, false, "Set " + _ip + " boot dev to " + bootDev + "failed"); } - s_logger.warn("Set " + _ip + " boot dev to " + bootDev + "Success"); + logger.warn("Set " + _ip + " boot dev to " + bootDev + "Success"); return new Answer(cmd, true, "Set " + _ip + " boot dev to " + bootDev + "Success"); } @@ -494,7 +492,7 @@ public Answer executeRequest(Command cmd) { return Answer.createUnsupportedCommandAnswer(cmd); } } catch (Throwable t) { - s_logger.debug(t.getMessage(), t); + logger.debug(t.getMessage(), t); return new Answer(cmd, false, t.getMessage()); } } @@ -545,7 +543,7 @@ protected StopAnswer execute(final StopCommand cmd) { OutputInterpreter.AllLinesParser interpreter = new OutputInterpreter.AllLinesParser(); if (!doScript(_getStatusCommand, interpreter)) { success = true; - s_logger.warn("Cannot get power status of " + getName() + ", assume VM state changed successfully"); + logger.warn("Cannot get power status of " + getName() + ", assume VM state changed successfully"); break; } @@ -600,7 +598,7 @@ protected StartAnswer execute(StartCommand cmd) { try { TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { - s_logger.warn(e.getMessage(), e); + logger.warn(e.getMessage(), e); } q = QueryBuilder.create(VMInstanceVO.class); @@ -614,21 +612,21 @@ protected StartAnswer execute(StartCommand cmd) { return new StartAnswer(cmd); } - s_logger.debug(String.format("still wait for baremetal provision done notification for vm[name:%s], current vm state is %s", vmvo.getInstanceName(), vmvo.getState())); + logger.debug(String.format("still wait for baremetal provision done notification for vm[name:%s], current vm state is %s", vmvo.getInstanceName(), vmvo.getState())); } return new StartAnswer(cmd, String.format("timeout after %s seconds, no baremetal provision done notification received. vm[name:%s] failed to start", isProvisionDoneNotificationTimeout, vm.getName())); } } - s_logger.debug("Start bare metal vm " + vm.getName() + "successfully"); + logger.debug("Start bare metal vm " + vm.getName() + "successfully"); _vmName = vm.getName(); return new StartAnswer(cmd); } protected ReadyAnswer execute(ReadyCommand cmd) { // derived resource should check if the PXE server is ready - s_logger.debug("Bare metal resource " + getName() + " is ready"); + logger.debug("Bare metal resource " + getName() + " is ready"); return new ReadyAnswer(cmd); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java index bf6932f05d43..79590f08ffa4 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.dc.Pod; @@ -59,7 +58,6 @@ import com.cloud.vm.VirtualMachineProfile; public class BaremetaNetworkGuru extends DirectPodBasedNetworkGuru { - private static final Logger s_logger = Logger.getLogger(BaremetaNetworkGuru.class); @Inject private HostDao _hostDao; @Inject @@ -151,14 +149,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) { * nic.setBroadcastUri(null); nic.setIsolationUri(null); */ - s_logger.debug("Allocated a nic " + nic + " for " + vm); + logger.debug("Allocated a nic " + nic + " for " + vm); } private void getBaremetalIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, Network network, String requiredIp) throws InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(pod.getDataCenterId()); if (nic.getIPv4Address() == null) { - s_logger.debug(String.format("Requiring ip address: %s", nic.getIPv4Address())); + logger.debug(String.format("Requiring ip address: %s", nic.getIPv4Address())); PublicIp ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), requiredIp, false, false); nic.setIPv4Address(ip.getAddress().toString()); nic.setFormat(AddressFormat.Ip4); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java index 807babcb09f8..e39b40cfc68b 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.baremetal.database.BaremetalDhcpVO; import com.cloud.dc.DataCenter.NetworkType; @@ -56,7 +55,6 @@ import com.cloud.vm.dao.NicDao; public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProvider { - private static final Logger s_logger = Logger.getLogger(BaremetalDhcpElement.class); private static final Map> capabilities; @Inject @@ -98,7 +96,7 @@ private boolean canHandle(DeployDestination dest, TrafficType trafficType, Guest public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (offering.isSystemOnly() || !canHandle(dest, offering.getTrafficType(), network.getGuestType())) { - s_logger.debug("BaremetalDhcpElement can not handle networkoffering: " + offering.getName()); + logger.debug("BaremetalDhcpElement can not handle networkoffering: " + offering.getName()); return false; } return true; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java index f50681abe7bd..99bedbff05e1 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.AddBaremetalDhcpCmd; import org.apache.cloudstack.api.ListBaremetalDhcpCmd; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -75,7 +74,6 @@ import com.cloud.vm.dao.UserVmDao; public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDhcpManager, ResourceStateAdapter { - private static final org.apache.log4j.Logger s_logger = Logger.getLogger(BaremetalDhcpManagerImpl.class); protected String _name; @Inject DataCenterDao _dcDao; @@ -155,15 +153,15 @@ public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, Vir try { Answer ans = _agentMgr.send(h.getId(), dhcpCommand); if (ans.getResult()) { - s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), + logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName())); return true; } else { - s_logger.debug(errMsg + " " + ans.getDetails()); + logger.debug(errMsg + " " + ans.getDetails()); throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId); } } catch (Exception e) { - s_logger.debug(errMsg, e); + logger.debug(errMsg, e); throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId); } } @@ -226,7 +224,7 @@ public BaremetalDhcpVO addDchpServer(AddBaremetalDhcpCmd cmd) { try { uri = new URI(cmd.getUrl()); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new IllegalArgumentException(e.getMessage()); } @@ -260,7 +258,7 @@ public BaremetalDhcpVO addDchpServer(AddBaremetalDhcpCmd cmd) { throw new CloudRuntimeException("Unsupport DHCP server type: " + cmd.getDhcpType()); } } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new CloudRuntimeException(e.getMessage()); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java index 0d3cdce74e8a..9fe3f6ad5166 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java @@ -27,7 +27,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -44,7 +43,6 @@ import com.cloud.utils.component.ManagerBase; public class BaremetalDhcpResourceBase extends ManagerBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(BaremetalDhcpResourceBase.class); String _name; String _guid; String _username; @@ -129,7 +127,7 @@ public PingCommand getCurrentStatus(long id) { } protected ReadyAnswer execute(ReadyCommand cmd) { - s_logger.debug("External DHCP resource " + _name + " is ready"); + logger.debug("External DHCP resource " + _name + " is ready"); return new ReadyAnswer(cmd); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java index 8fd2c35ced99..e92cbf2c2045 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java @@ -27,7 +27,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -41,14 +40,13 @@ import com.cloud.utils.ssh.SSHCmdHelper; public class BaremetalDhcpdResource extends BaremetalDhcpResourceBase { - private static final Logger s_logger = Logger.getLogger(BaremetalDhcpdResource.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { com.trilead.ssh2.Connection sshConnection = null; try { super.configure(name, params); - s_logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, "******")); + logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, "******")); sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password); if (sshConnection == null) { throw new ConfigurationException(String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); @@ -89,10 +87,10 @@ public boolean configure(String name, Map params) throws Configu throw new ConfigurationException("prepare Dhcpd at " + _ip + " failed, command:" + cmd); } - s_logger.debug("Dhcpd resource configure successfully"); + logger.debug("Dhcpd resource configure successfully"); return true; } catch (Exception e) { - s_logger.debug("Dhcpd resource configure failed", e); + logger.debug("Dhcpd resource configure failed", e); throw new ConfigurationException(e.getMessage()); } finally { SSHCmdHelper.releaseSshConnection(sshConnection); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java index 79f23cc46db2..51acfe93d39e 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java @@ -27,7 +27,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -41,14 +40,13 @@ import com.cloud.utils.ssh.SSHCmdHelper; public class BaremetalDnsmasqResource extends BaremetalDhcpResourceBase { - private static final Logger s_logger = Logger.getLogger(BaremetalDnsmasqResource.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { com.trilead.ssh2.Connection sshConnection = null; try { super.configure(name, params); - s_logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, _password)); + logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, _password)); sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password); if (sshConnection == null) { throw new ConfigurationException(String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); @@ -81,10 +79,10 @@ public boolean configure(String name, Map params) throws Configu } */ - s_logger.debug("Dnsmasq resource configure successfully"); + logger.debug("Dnsmasq resource configure successfully"); return true; } catch (Exception e) { - s_logger.debug("Dnsmasq resorce configure failed", e); + logger.debug("Dnsmasq resorce configure failed", e); throw new ConfigurationException(e.getMessage()); } finally { SSHCmdHelper.releaseSshConnection(sshConnection); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java index dbee3c4a91d4..3775f4effc17 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java @@ -25,7 +25,6 @@ import javax.naming.ConfigurationException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -40,7 +39,6 @@ import com.cloud.utils.ssh.SSHCmdHelper; public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase { - private static final Logger s_logger = Logger.getLogger(BaremetalKickStartPxeResource.class); private static final String Name = "BaremetalKickStartPxeResource"; String _tftpDir; @@ -54,11 +52,11 @@ public boolean configure(String name, Map params) throws Configu com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); - s_logger.debug(String.format("Trying to connect to kickstart PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); + logger.debug(String.format("Trying to connect to kickstart PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to kickstart PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } @@ -132,7 +130,7 @@ private Answer execute(VmDataCommand cmd) { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -143,7 +141,7 @@ private Answer execute(VmDataCommand cmd) { return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Prepare for creating baremetal template failed", e); + logger.debug("Prepare for creating baremetal template failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { @@ -168,7 +166,7 @@ private Answer execute(PrepareKickstartPxeServerCommand cmd) { try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -188,10 +186,10 @@ private Answer execute(PrepareKickstartPxeServerCommand cmd) { return new Answer(cmd, false, "prepare kickstart at pxe server " + _ip + " failed, command:" + script); } - s_logger.debug("Prepare kickstart PXE server successfully"); + logger.debug("Prepare kickstart PXE server successfully"); return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Prepare for kickstart server failed", e); + logger.debug("Prepare for kickstart server failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java index 8fe3d827ed40..169743881ede 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.AddBaremetalPxeCmd; import org.apache.cloudstack.api.ListBaremetalPxeServersCmd; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.baremetal.IpmISetBootDevCommand; @@ -80,7 +79,6 @@ import com.cloud.vm.dao.NicDao; public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase implements BaremetalPxeService { - private static final Logger s_logger = Logger.getLogger(BaremetalKickStartServiceImpl.class); @Inject ResourceManager _resourceMgr; @Inject @@ -170,7 +168,7 @@ public File getSystemVMKeyFile() { throw new CloudRuntimeException(String.format("cannot find id_rsa.cloud")); } if (!keyFile.exists()) { - s_logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); + logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); } return keyFile; } @@ -199,7 +197,7 @@ private boolean preparePxeInBasicZone(VirtualMachineProfile profile, NicProfile cmd.setTemplateUuid(template.getUuid()); Answer aws = _agentMgr.send(pxeVo.getHostId(), cmd); if (!aws.getResult()) { - s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); + logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); return false; } @@ -234,7 +232,7 @@ private boolean preparePxeInAdvancedZone(VirtualMachineProfile profile, NicProfi List tuple = parseKickstartUrl(profile); String cmd = String.format("/opt/cloud/bin/prepare_pxe.sh %s %s %s %s %s %s", tuple.get(1), tuple.get(2), profile.getTemplate().getUuid(), String.format("01-%s", nic.getMacAddress().replaceAll(":", "-")).toLowerCase(), tuple.get(0), nic.getMacAddress().toLowerCase()); - s_logger.debug(String.format("prepare pxe on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd)); + logger.debug(String.format("prepare pxe on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd)); ret = SshHelper.sshExecute(mgmtNic.getIPv4Address(), 3922, "root", getSystemVMKeyFile(), null, cmd); if (!ret.first()) { throw new CloudRuntimeException(String.format("failed preparing PXE in virtual router[id:%s], because %s", vr.getId(), ret.second())); @@ -242,7 +240,7 @@ private boolean preparePxeInAdvancedZone(VirtualMachineProfile profile, NicProfi //String internalServerIp = "10.223.110.231"; cmd = String.format("/opt/cloud/bin/baremetal_snat.sh %s %s %s", mgmtNic.getIPv4Address(), internalServerIp, mgmtNic.getIPv4Gateway()); - s_logger.debug(String.format("prepare SNAT on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd)); + logger.debug(String.format("prepare SNAT on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd)); ret = SshHelper.sshExecute(mgmtNic.getIPv4Address(), 3922, "root", getSystemVMKeyFile(), null, cmd); if (!ret.first()) { throw new CloudRuntimeException(String.format("failed preparing PXE in virtual router[id:%s], because %s", vr.getId(), ret.second())); @@ -267,12 +265,12 @@ public boolean prepare(VirtualMachineProfile profile, NicProfile nic, Network ne IpmISetBootDevCommand bootCmd = new IpmISetBootDevCommand(BootDev.pxe); Answer aws = _agentMgr.send(dest.getHost().getId(), bootCmd); if (!aws.getResult()) { - s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); + logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); } return aws.getResult(); } catch (Exception e) { - s_logger.warn("Cannot prepare PXE server", e); + logger.warn("Cannot prepare PXE server", e); return false; } } @@ -324,7 +322,7 @@ public BaremetalPxeVO addPxeServer(AddBaremetalPxeCmd cmd) { try { uri = new URI(cmd.getUrl()); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new IllegalArgumentException(e.getMessage()); } String ipAddress = uri.getHost(); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java index 416b3d0e3b3b..96b2dbfeb935 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java @@ -29,7 +29,6 @@ import javax.naming.ConfigurationException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -46,7 +45,6 @@ import com.cloud.utils.ssh.SSHCmdHelper; public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { - private static final Logger s_logger = Logger.getLogger(BaremetalPingPxeResource.class); private static final String Name = "BaremetalPingPxeResource"; String _storageServer; String _pingDir; @@ -98,11 +96,11 @@ public boolean configure(String name, Map params) throws Configu com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); - s_logger.debug(String.format("Trying to connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); + logger.debug(String.format("Trying to connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } @@ -152,7 +150,7 @@ protected PreparePxeServerAnswer execute(PreparePxeServerCommand cmd) { try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -162,11 +160,11 @@ protected PreparePxeServerAnswer execute(PreparePxeServerCommand cmd) { if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) { return new PreparePxeServerAnswer(cmd, "prepare PING at " + _ip + " failed, command:" + script); } - s_logger.debug("Prepare Ping PXE server successfully"); + logger.debug("Prepare Ping PXE server successfully"); return new PreparePxeServerAnswer(cmd); } catch (Exception e) { - s_logger.debug("Prepare PING pxe server failed", e); + logger.debug("Prepare PING pxe server failed", e); return new PreparePxeServerAnswer(cmd, e.getMessage()); } finally { if (sshConnection != null) { @@ -180,7 +178,7 @@ protected Answer execute(PrepareCreateTemplateCommand cmd) { try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -190,11 +188,11 @@ protected Answer execute(PrepareCreateTemplateCommand cmd) { if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) { return new Answer(cmd, false, "prepare for creating template failed, command:" + script); } - s_logger.debug("Prepare for creating template successfully"); + logger.debug("Prepare for creating template successfully"); return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Prepare for creating baremetal template failed", e); + logger.debug("Prepare for creating baremetal template failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { @@ -238,7 +236,7 @@ private Answer execute(VmDataCommand cmd) { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -249,7 +247,7 @@ private Answer execute(VmDataCommand cmd) { return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Prepare for creating baremetal template failed", e); + logger.debug("Prepare for creating baremetal template failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeElement.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeElement.java index 17ec90210163..fa708e7be4cc 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeElement.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeElement.java @@ -51,7 +51,6 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.VMInstanceDao; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.HashMap; @@ -59,7 +58,6 @@ import java.util.Set; public class BaremetalPxeElement extends AdapterBase implements NetworkElement { - private static final Logger s_logger = Logger.getLogger(BaremetalPxeElement.class); private static final Map> capabilities; @Inject @@ -110,7 +108,7 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin } if (offering.isSystemOnly() || !canHandle(dest, offering.getTrafficType(), network.getGuestType())) { - s_logger.debug("BaremetalPxeElement can not handle network offering: " + offering.getName()); + logger.debug("BaremetalPxeElement can not handle network offering: " + offering.getName()); return false; } return true; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java index 22f939597338..636ce360d03a 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd; import org.apache.cloudstack.api.ListBaremetalPxeServersCmd; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -71,7 +70,6 @@ import com.cloud.vm.dao.UserVmDao; public class BaremetalPxeManagerImpl extends ManagerBase implements BaremetalPxeManager, ResourceStateAdapter { - private static final org.apache.log4j.Logger s_logger = Logger.getLogger(BaremetalPxeManagerImpl.class); @Inject DataCenterDao _dcDao; @Inject @@ -233,13 +231,13 @@ public boolean addUserData(NicProfile nic, VirtualMachineProfile profile) { try { Answer ans = _agentMgr.send(pxeVo.getHostId(), cmd); if (!ans.getResult()) { - s_logger.debug(String.format("Add userdata to vm:%s failed because %s", vm.getInstanceName(), ans.getDetails())); + logger.debug(String.format("Add userdata to vm:%s failed because %s", vm.getInstanceName(), ans.getDetails())); return false; } else { return true; } } catch (Exception e) { - s_logger.debug(String.format("Add userdata to vm:%s failed", vm.getInstanceName()), e); + logger.debug(String.format("Add userdata to vm:%s failed", vm.getInstanceName()), e); return false; } } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeResourceBase.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeResourceBase.java index 5b5a959d597f..01d1bf62717d 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeResourceBase.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeResourceBase.java @@ -26,7 +26,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -41,7 +40,6 @@ import com.cloud.utils.component.ManagerBase; public class BaremetalPxeResourceBase extends ManagerBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(BaremetalPxeResourceBase.class); String _name; String _guid; String _username; @@ -84,7 +82,7 @@ public boolean configure(String name, Map params) throws Configu } protected ReadyAnswer execute(ReadyCommand cmd) { - s_logger.debug("Pxe resource " + _name + " is ready"); + logger.debug("Pxe resource " + _name + " is ready"); return new ReadyAnswer(cmd); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/Force10BaremetalSwitchBackend.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/Force10BaremetalSwitchBackend.java index e4dd5b1a5d8a..3a013da7858e 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/Force10BaremetalSwitchBackend.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/Force10BaremetalSwitchBackend.java @@ -27,7 +27,8 @@ import com.cloud.utils.xmlobject.XmlObjectParser; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -48,7 +49,7 @@ * Created by frank on 9/2/14. */ public class Force10BaremetalSwitchBackend implements BaremetalSwitchBackend { - private Logger logger = Logger.getLogger(Force10BaremetalSwitchBackend.class); + private Logger logger = LogManager.getLogger(Force10BaremetalSwitchBackend.class); public static final String TYPE = "Force10"; private static List successHttpStatusCode = new ArrayList<>(); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/SecurityGroupHttpClient.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/SecurityGroupHttpClient.java index b100929da961..b00535004640 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/SecurityGroupHttpClient.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/SecurityGroupHttpClient.java @@ -34,7 +34,8 @@ import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; @@ -46,7 +47,7 @@ import java.util.concurrent.TimeUnit; public class SecurityGroupHttpClient { - private static final Logger logger = Logger.getLogger(SecurityGroupHttpClient.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String ARG_NAME = "args"; private static final String COMMAND = "command"; private JAXBContext context; diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalDhcpCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalDhcpCmd.java index 22a1c4eba905..379dee875f4d 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalDhcpCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalDhcpCmd.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.context.CallContext; @@ -38,7 +37,6 @@ @APICommand(name = "addBaremetalDhcp", description = "adds a baremetal dhcp server", responseObject = BaremetalDhcpResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddBaremetalDhcpCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddBaremetalDhcpCmd.class); @Inject BaremetalDhcpManager mgr; @@ -84,7 +82,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Unable to add external dhcp server with url: " + getUrl(), e); + logger.warn("Unable to add external dhcp server with url: " + getUrl(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalPxeCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalPxeCmd.java index 19854a981b5b..a11ae0bae369 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalPxeCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalPxeCmd.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.api.response.PodResponse; @@ -38,7 +37,6 @@ public class AddBaremetalPxeCmd extends BaseAsyncCmd { private static final String s_name = "addbaremetalpxeresponse"; - public static final Logger s_logger = Logger.getLogger(AddBaremetalPxeCmd.class); @Inject BaremetalPxeManager pxeMgr; @@ -86,7 +84,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE rsp.setResponseName(getCommandName()); this.setResponseObject(rsp); } catch (Exception e) { - s_logger.warn("Unable to add external pxe server with url: " + getUrl(), e); + logger.warn("Unable to add external pxe server with url: " + getUrl(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalRctCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalRctCmd.java index 3227cbd24ff1..e7c77c3cd1c4 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalRctCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalRctCmd.java @@ -27,7 +27,6 @@ import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -37,7 +36,6 @@ @APICommand(name = "addBaremetalRct", description = "adds baremetal rack configuration text", responseObject = BaremetalRctResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class AddBaremetalRctCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddBaremetalRctCmd.class); @Inject private BaremetalVlanManager vlanMgr; @@ -68,7 +66,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE BaremetalRctResponse rsp = vlanMgr.addRct(this); this.setResponseObject(rsp); } catch (Exception e) { - s_logger.warn(String.format("unable to add baremetal RCT[%s]", getRctUrl()), e); + logger.warn(String.format("unable to add baremetal RCT[%s]", getRctUrl()), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/BaremetalProvisionDoneNotificationCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/BaremetalProvisionDoneNotificationCmd.java index c712849a27ac..75df9556ba4a 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/BaremetalProvisionDoneNotificationCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/BaremetalProvisionDoneNotificationCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; -import org.apache.log4j.Logger; /** * Created by frank on 9/17/14. @@ -36,7 +35,6 @@ @APICommand(name = "notifyBaremetalProvisionDone", description = "Notify provision has been done on a host. This api is for baremetal virtual router service, not for end user", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class BaremetalProvisionDoneNotificationCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(BaremetalProvisionDoneNotificationCmd.class); private static final String s_name = "baremetalprovisiondone"; @Inject @@ -61,7 +59,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE bmMgr.notifyProvisionDone(this); this.setResponseObject(new SuccessResponse(getCommandName())); } catch (Exception e) { - s_logger.warn(String.format("unable to notify baremetal provision done[mac:%s]", mac), e); + logger.warn(String.format("unable to notify baremetal provision done[mac:%s]", mac), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java index c2691d67ae07..8bb31403d9f9 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -38,7 +37,6 @@ @APICommand(name = "deleteBaremetalRct", description = "deletes baremetal rack configuration text", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class DeleteBaremetalRctCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteBaremetalRctCmd.class); @Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, description = "RCT id", required = true, entityType = BaremetalRctResponse.class) private Long id; @@ -63,7 +61,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } catch (Exception e) { - s_logger.warn(String.format("unable to delete baremetal RCT[%s]", getId()), e); + logger.warn(String.format("unable to delete baremetal RCT[%s]", getId()), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage(), e); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalDhcpCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalDhcpCmd.java index fdc64de25d71..8f4e2338be9b 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalDhcpCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalDhcpCmd.java @@ -27,7 +27,6 @@ import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; @@ -35,7 +34,6 @@ @APICommand(name = "listBaremetalDhcp", description = "list baremetal dhcp servers", responseObject = BaremetalDhcpResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListBaremetalDhcpCmd extends BaseListCmd { - private static final Logger s_logger = Logger.getLogger(ListBaremetalDhcpCmd.class); @Inject BaremetalDhcpManager _dhcpMgr; @@ -90,7 +88,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE response.setObjectName("baremetaldhcps"); this.setResponseObject(response); } catch (Exception e) { - s_logger.debug("Exception happend while executing ListBaremetalDhcpCmd"); + logger.debug("Exception happend while executing ListBaremetalDhcpCmd"); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalPxeServersCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalPxeServersCmd.java index 5f856a5d638f..bcf3f6f44dbe 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalPxeServersCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalPxeServersCmd.java @@ -27,7 +27,6 @@ import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; @@ -35,7 +34,6 @@ @APICommand(name = "listBaremetalPxeServers", description = "list baremetal pxe server", responseObject = BaremetalPxeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListBaremetalPxeServersCmd extends BaseListCmd { - private static final Logger s_logger = Logger.getLogger(ListBaremetalPxeServersCmd.class); @Inject BaremetalPxeManager _pxeMgr; @@ -76,7 +74,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE response.setObjectName("baremetalpxeservers"); this.setResponseObject(response); } catch (Exception e) { - s_logger.debug("Exception happened while executing ListPingPxeServersCmd", e); + logger.debug("Exception happened while executing ListPingPxeServersCmd", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalRctCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalRctCmd.java index 379c8758bf17..d654fece0c76 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalRctCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalRctCmd.java @@ -27,7 +27,6 @@ import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -36,7 +35,6 @@ @APICommand(name = "listBaremetalRct", description = "list baremetal rack configuration", responseObject = BaremetalRctResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class ListBaremetalRctCmd extends BaseListCmd { - private static final Logger s_logger = Logger.getLogger(ListBaremetalRctCmd.class); @Inject BaremetalVlanManager vlanMgr; @@ -55,7 +53,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE response.setObjectName("baremetalrcts"); this.setResponseObject(response); } catch (Exception e) { - s_logger.debug("Exception happened while executing ListBaremetalRctCmd", e); + logger.debug("Exception happened while executing ListBaremetalRctCmd", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/hyperv/conf/log4j-cloud.xml.in b/plugins/hypervisors/hyperv/conf/log4j-cloud.xml.in index fdbba19e9036..104e52233a9e 100644 --- a/plugins/hypervisors/hyperv/conf/log4j-cloud.xml.in +++ b/plugins/hypervisors/hyperv/conf/log4j-cloud.xml.in @@ -17,77 +17,52 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - + + - + + + - - - + + + + + + + + - - - - - - - - - - - - - - - - + + + - - - + + + + - - - - + - - - + + - - - - - - - - - - - + - - - - + - - - - - - - + - - - + - - - - - + + + - + + + + + + + diff --git a/plugins/hypervisors/hyperv/pom.xml b/plugins/hypervisors/hyperv/pom.xml index fbdaceadd100..56b2b6d1503f 100644 --- a/plugins/hypervisors/hyperv/pom.xml +++ b/plugins/hypervisors/hyperv/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -55,7 +55,7 @@ org.codehaus.mojo exec-maven-plugin - 1.2.1 + ${cs.exec-maven-plugin.version} java com.cloud.agent.AgentShell @@ -137,6 +137,7 @@ org.codehaus.mojo exec-maven-plugin + ${cs.exec-maven-plugin.version} compile diff --git a/plugins/hypervisors/hyperv/src/main/java/com/cloud/ha/HypervInvestigator.java b/plugins/hypervisors/hyperv/src/main/java/com/cloud/ha/HypervInvestigator.java index 774efc84b3ae..d820fd5b6d30 100644 --- a/plugins/hypervisors/hyperv/src/main/java/com/cloud/ha/HypervInvestigator.java +++ b/plugins/hypervisors/hyperv/src/main/java/com/cloud/ha/HypervInvestigator.java @@ -22,7 +22,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -36,7 +35,6 @@ import com.cloud.utils.component.AdapterBase; public class HypervInvestigator extends AdapterBase implements Investigator { - private final static Logger s_logger = Logger.getLogger(HypervInvestigator.class); @Inject HostDao _hostDao; @Inject AgentManager _agentMgr; @Inject ResourceManager _resourceMgr; @@ -68,7 +66,7 @@ public Status isAgentAlive(Host agent) { return answer.getResult() ? Status.Down : Status.Up; } } catch (Exception e) { - s_logger.debug("Failed to send command to host: " + neighbor.getId(), e); + logger.debug("Failed to send command to host: " + neighbor.getId(), e); } } diff --git a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java index 51b423052ea9..283f4dc0c96c 100644 --- a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java +++ b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java @@ -29,7 +29,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -72,7 +71,6 @@ * hypervisor and manages its lifecycle. */ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(HypervServerDiscoverer.class); Random _rand = new Random(System.currentTimeMillis()); Map _storageMounts = new HashMap(); @@ -121,7 +119,7 @@ public final void processConnect(final Host agent, final StartupCommand cmd, fin // assert if (startup.getHypervisorType() != HypervisorType.Hyperv) { - s_logger.debug("Not Hyper-V hypervisor, so moving on."); + logger.debug("Not Hyper-V hypervisor, so moving on."); return; } @@ -137,8 +135,8 @@ public final void processConnect(final Host agent, final StartupCommand cmd, fin _clusterDao.update(cluster.getId(), cluster); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Setting up host " + agentId); + if (logger.isDebugEnabled()) { + logger.debug("Setting up host " + agentId); } HostEnvironment env = new HostEnvironment(); @@ -163,14 +161,14 @@ public final void processConnect(final Host agent, final StartupCommand cmd, fin if (reason == null) { reason = " details were null"; } - s_logger.warn("Unable to setup agent " + agentId + " due to " + reason); + logger.warn("Unable to setup agent " + agentId + " due to " + reason); } // Error handling borrowed from XcpServerDiscoverer, may need to be // updated. } catch (AgentUnavailableException e) { - s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e); + logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e); } catch (OperationTimedoutException e) { - s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e); + logger.warn("Unable to setup agent " + agentId + " because it timed out", e); } throw new ConnectionException(true, "Reinitialize agent after setup."); } @@ -213,14 +211,14 @@ public final boolean processTimeout(final long agentId, final long seq) { public final Map> find(final long dcId, final Long podId, final Long clusterId, final URI uri, final String username, final String password, final List hostTags) throws DiscoveryException { - if (s_logger.isInfoEnabled()) { - s_logger.info("Discover host. dc(zone): " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + uri.getHost()); + if (logger.isInfoEnabled()) { + logger.info("Discover host. dc(zone): " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + uri.getHost()); } // Assertions if (podId == null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("No pod is assigned, skipping the discovery in" + " Hyperv discoverer"); + if (logger.isInfoEnabled()) { + logger.info("No pod is assigned, skipping the discovery in" + " Hyperv discoverer"); } return null; } @@ -228,20 +226,20 @@ public final Map> find(final long // in the // database if (cluster == null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("No cluster in database for cluster id " + clusterId); + if (logger.isInfoEnabled()) { + logger.info("No cluster in database for cluster id " + clusterId); } return null; } if (cluster.getHypervisorType() != HypervisorType.Hyperv) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster " + clusterId + "is not for Hyperv hypervisors"); + if (logger.isInfoEnabled()) { + logger.info("Cluster " + clusterId + "is not for Hyperv hypervisors"); } return null; } if (!uri.getScheme().equals("http")) { String msg = "urlString is not http so we're not taking care of" + " the discovery for this: " + uri; - s_logger.debug(msg); + logger.debug(msg); return null; } @@ -253,11 +251,11 @@ public final Map> find(final long String guidWithTail = calcServerResourceGuid(uuidSeed) + "-HypervResource"; if (_resourceMgr.findHostByGuid(guidWithTail) != null) { - s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database."); + logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database."); return null; } - s_logger.info("Creating" + HypervDirectConnectResource.class.getName() + " HypervDirectConnectResource for zone/pod/cluster " + dcId + "/" + podId + "/" + + logger.info("Creating" + HypervDirectConnectResource.class.getName() + " HypervDirectConnectResource for zone/pod/cluster " + dcId + "/" + podId + "/" + clusterId); // Some Hypervisors organise themselves in pools. @@ -298,7 +296,7 @@ public final Map> find(final long Answer pingAns = resource.executeRequest(ping); if (pingAns == null || !pingAns.getResult()) { String errMsg = "Agent not running, or no route to agent on at " + uri; - s_logger.debug(errMsg); + logger.debug(errMsg); throw new DiscoveryException(errMsg); } @@ -309,14 +307,14 @@ public final Map> find(final long return resources; } catch (ConfigurationException e) { _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + uri.getHost(), "Error is " + e.getMessage()); - s_logger.warn("Unable to instantiate " + uri.getHost(), e); + logger.warn("Unable to instantiate " + uri.getHost(), e); } catch (UnknownHostException e) { _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + uri.getHost(), "Error is " + e.getMessage()); - s_logger.warn("Unable to instantiate " + uri.getHost(), e); + logger.warn("Unable to instantiate " + uri.getHost(), e); } catch (Exception e) { String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage(); - s_logger.warn(msg); + logger.warn(msg); } return null; } @@ -393,7 +391,7 @@ public final HostVO createHostVOForDirectConnectAgent(final HostVO host, final S return null; } - s_logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.Hyperv + ". Checking CIDR..."); + logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.Hyperv + ". Checking CIDR..."); HostPodVO pod = _podDao.findById(host.getPodId()); DataCenterVO dc = _dcDao.findById(host.getDataCenterId()); diff --git a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/manager/HypervManagerImpl.java b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/manager/HypervManagerImpl.java index 9490ae07b307..a31637b60deb 100644 --- a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/manager/HypervManagerImpl.java +++ b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/manager/HypervManagerImpl.java @@ -33,7 +33,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.utils.identity.ManagementServerNode; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.configuration.Config; import com.cloud.storage.JavaStorageLayer; @@ -47,7 +48,7 @@ import com.cloud.vm.dao.VMInstanceDao; public class HypervManagerImpl implements HypervManager { - public static final Logger s_logger = Logger.getLogger(HypervManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private String name; private int runLevel; @@ -127,7 +128,7 @@ public void setRunLevel(int level) { public String prepareSecondaryStorageStore(long zoneId) { String secondaryStorageUri = getSecondaryStorageStoreUrl(zoneId); if (secondaryStorageUri == null) { - s_logger.debug("Secondary storage uri for dc " + zoneId + " couldn't be obtained"); + logger.debug("Secondary storage uri for dc " + zoneId + " couldn't be obtained"); } else { prepareSecondaryStorageStore(secondaryStorageUri); } @@ -143,7 +144,7 @@ private String getSecondaryStorageStoreUrl(long zoneId) { } if (secUrl == null) { - s_logger.warn("Secondary storage uri couldn't be retrieved"); + logger.warn("Secondary storage uri couldn't be retrieved"); } return secUrl; @@ -160,7 +161,7 @@ private void prepareSecondaryStorageStore(String storageUrl) { if (!patchFolder.exists()) { if (!patchFolder.mkdirs()) { String msg = "Unable to create systemvm folder on secondary storage. location: " + patchFolder.toString(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } @@ -168,20 +169,20 @@ private void prepareSecondaryStorageStore(String storageUrl) { File srcIso = getSystemVMPatchIsoFile(); File destIso = new File(mountPoint + "/systemvm/" + getSystemVMIsoFileNameOnDatastore()); if (!destIso.exists()) { - s_logger.info("Copy System VM patch ISO file to secondary storage. source ISO: " + + logger.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + destIso.getAbsolutePath()); try { FileUtil.copyfile(srcIso, destIso); } catch (IOException e) { - s_logger.error("Unexpected exception ", e); + logger.error("Unexpected exception ", e); String msg = "Unable to copy systemvm ISO on secondary storage. src location: " + srcIso.toString() + ", dest location: " + destIso; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("SystemVM ISO file " + destIso.getPath() + " already exists"); + if (logger.isTraceEnabled()) { + logger.trace("SystemVM ISO file " + destIso.getPath() + " already exists"); } } } finally { @@ -205,14 +206,14 @@ private String getMountPoint(String storageUrl) { try { uri = new URI(storageUrl); } catch (URISyntaxException e) { - s_logger.error("Invalid storage URL format ", e); + logger.error("Invalid storage URL format ", e); throw new CloudRuntimeException("Unable to create mount point due to invalid storage URL format " + storageUrl); } mountPoint = mount(File.separator + File.separator + uri.getHost() + uri.getPath(), getMountParent(), uri.getScheme(), uri.getQuery()); if (mountPoint == null) { - s_logger.error("Unable to create mount point for " + storageUrl); + logger.error("Unable to create mount point for " + storageUrl); return "/mnt/sec"; } @@ -224,7 +225,7 @@ private String getMountPoint(String storageUrl) { protected String mount(String path, String parent, String scheme, String query) { String mountPoint = setupMountPoint(parent); if (mountPoint == null) { - s_logger.warn("Unable to create a mount point"); + logger.warn("Unable to create a mount point"); return null; } @@ -232,7 +233,7 @@ protected String mount(String path, String parent, String scheme, String query) String result = null; if (scheme.equals("cifs")) { String user = System.getProperty("user.name"); - Script command = new Script(true, "mount", _timeout, s_logger); + Script command = new Script(true, "mount", _timeout, logger); command.add("-t", "cifs"); command.add(path); command.add(mountPoint); @@ -250,7 +251,7 @@ protected String mount(String path, String parent, String scheme, String query) } if (result != null) { - s_logger.warn("Unable to mount " + path + " due to " + result); + logger.warn("Unable to mount " + path + " due to " + result); File file = new File(mountPoint); if (file.exists()) { file.delete(); @@ -259,11 +260,11 @@ protected String mount(String path, String parent, String scheme, String query) } // Change permissions for the mountpoint - script = new Script(true, "chmod", _timeout, s_logger); + script = new Script(true, "chmod", _timeout, logger); script.add("-R", "777", mountPoint); result = script.execute(); if (result != null) { - s_logger.warn("Unable to set permissions for " + mountPoint + " due to " + result); + logger.warn("Unable to set permissions for " + mountPoint + " due to " + result); } return mountPoint; } @@ -280,7 +281,7 @@ private String setupMountPoint(String parent) { break; } } - s_logger.error("Unable to create mount: " + mntPt); + logger.error("Unable to create mount: " + mntPt); } return mountPoint; @@ -306,7 +307,7 @@ private File getSystemVMPatchIsoFile() { assert (isoFile != null); if (!isoFile.exists()) { - s_logger.error("Unable to locate systemvm.iso in your setup at " + isoFile.toString()); + logger.error("Unable to locate systemvm.iso in your setup at " + isoFile.toString()); } return isoFile; } @@ -330,7 +331,7 @@ private String getMountParent() { } private void startupCleanup(String parent) { - s_logger.info("Cleanup mounted mount points used in previous session"); + logger.info("Cleanup mounted mount points used in previous session"); long mshostId = ManagementServerNode.getManagementServerId(); @@ -338,14 +339,14 @@ private void startupCleanup(String parent) { String[] mounts = _storage.listFiles(parent + File.separator + String.valueOf(mshostId) + ".*"); if (mounts != null && mounts.length > 0) { for (String mountPoint : mounts) { - s_logger.info("umount NFS mount from previous session: " + mountPoint); + logger.info("umount NFS mount from previous session: " + mountPoint); String result = null; - Script command = new Script(true, "umount", _timeout, s_logger); + Script command = new Script(true, "umount", _timeout, logger); command.add(mountPoint); result = command.execute(); if (result != null) { - s_logger.warn("Unable to umount " + mountPoint + " due to " + result); + logger.warn("Unable to umount " + mountPoint + " due to " + result); } File file = new File(mountPoint); if (file.exists()) { @@ -356,17 +357,17 @@ private void startupCleanup(String parent) { } private void shutdownCleanup() { - s_logger.info("Cleanup mounted mount points used in current session"); + logger.info("Cleanup mounted mount points used in current session"); synchronized (_storageMounts) { for (String mountPoint : _storageMounts.values()) { - s_logger.info("umount NFS mount: " + mountPoint); + logger.info("umount NFS mount: " + mountPoint); String result = null; - Script command = new Script(true, "umount", _timeout, s_logger); + Script command = new Script(true, "umount", _timeout, logger); command.add(mountPoint); result = command.execute(); if (result != null) { - s_logger.warn("Unable to umount " + mountPoint + " due to " + result); + logger.warn("Unable to umount " + mountPoint + " due to " + result); } File file = new File(mountPoint); if (file.exists()) { diff --git a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java index 6bc1b98a688c..37df91b2c89c 100644 --- a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java +++ b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java @@ -60,7 +60,6 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.BasicClientConnectionManager; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; import org.joda.time.Duration; import com.cloud.agent.api.Answer; @@ -163,7 +162,6 @@ public class HypervDirectConnectResource extends ServerResourceBase implements ServerResource, VirtualRouterDeployer { public static final int DEFAULT_AGENT_PORT = 8250; public static final String HOST_VM_STATE_REPORT_COMMAND = "org.apache.cloudstack.HostVmStateReportCommand"; - private static final Logger s_logger = Logger.getLogger(HypervDirectConnectResource.class.getName()); private static final Gson s_gson = GsonHelper.getGson(); private String zoneId; @@ -206,7 +204,7 @@ public final StartupCommand[] initialize() { // assert if (!configureCalled) { final String errMsg = this.getClass().getName() + " requires configure() be called before" + " initialize()"; - s_logger.error(errMsg); + logger.error(errMsg); } // Create default StartupRoutingCommand, then customise @@ -224,7 +222,7 @@ public final StartupCommand[] initialize() { defaultStartRoutCmd.setStorageIpAddress(agentIp); defaultStartRoutCmd.setPool(clusterGuid); - s_logger.debug("Generated StartupRoutingCommand for agentIp \"" + agentIp + "\""); + logger.debug("Generated StartupRoutingCommand for agentIp \"" + agentIp + "\""); defaultStartRoutCmd.setVersion(this.getClass().getPackage().getImplementationVersion()); @@ -240,7 +238,7 @@ public final StartupCommand[] initialize() { // Assert that host identity is consistent with existing values. if (startCmd == null) { final String errMsg = String.format("Host %s (IP %s)" + "did not return a StartupRoutingCommand", name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } @@ -248,26 +246,26 @@ public final StartupCommand[] initialize() { final String errMsg = String.format("Host %s (IP %s) changed zone/data center. Was " + defaultStartRoutCmd.getDataCenter() + " NOW its " + startCmd.getDataCenter(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } if (!startCmd.getPod().equals(defaultStartRoutCmd.getPod())) { final String errMsg = String.format("Host %s (IP %s) changed pod. Was " + defaultStartRoutCmd.getPod() + " NOW its " + startCmd.getPod(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } if (!startCmd.getCluster().equals(defaultStartRoutCmd.getCluster())) { final String errMsg = String.format("Host %s (IP %s) changed cluster. Was " + defaultStartRoutCmd.getCluster() + " NOW its " + startCmd.getCluster(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } if (!startCmd.getGuid().equals(defaultStartRoutCmd.getGuid())) { final String errMsg = String.format("Host %s (IP %s) changed guid. Was " + defaultStartRoutCmd.getGuid() + " NOW its " + startCmd.getGuid(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } @@ -275,13 +273,13 @@ public final StartupCommand[] initialize() { final String errMsg = String.format("Host %s (IP %s) IP address. Was " + defaultStartRoutCmd.getPrivateIpAddress() + " NOW its " + startCmd.getPrivateIpAddress(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } if (!startCmd.getName().equals(defaultStartRoutCmd.getName())) { final String errMsg = String.format("Host %s (IP %s) name. Was " + startCmd.getName() + " NOW its " + defaultStartRoutCmd.getName(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } @@ -301,13 +299,13 @@ public final StartupCommand[] initialize() { if (storePoolCmd == null) { final String frmtStr = "Host %s (IP %s) sent incorrect Command, " + "second parameter should be a " + "StartupStorageCommand"; final String errMsg = String.format(frmtStr, name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } - s_logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details " + s_gson.toJson(startCmds[1])); + logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details " + s_gson.toJson(startCmds[1])); } else { - s_logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details "); + logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details "); } return new StartupCommand[] {startCmd, storePoolCmd}; } @@ -316,14 +314,14 @@ public final StartupCommand[] initialize() { public final PingCommand getCurrentStatus(final long id) { final PingCommand pingCmd = new PingRoutingCommand(getType(), id, getHostVmStateReport()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping host " + name + " (IP " + agentIp + ")"); + if (logger.isDebugEnabled()) { + logger.debug("Ping host " + name + " (IP " + agentIp + ")"); } final Answer pingAns = executeRequest(pingCmd); if (pingAns == null || !pingAns.getResult()) { - s_logger.info("Cannot ping host " + name + " (IP " + agentIp + "), pingAns (blank means null) is:" + pingAns); + logger.info("Cannot ping host " + name + " (IP " + agentIp + "), pingAns (blank means null) is:" + pingAns); return null; } return pingCmd; @@ -335,7 +333,7 @@ public final ArrayList> requestHostVmStateReport() { agentUri = new URI("https", null, agentIp, port, "/api/HypervResource/" + HOST_VM_STATE_REPORT_COMMAND, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return null; } final String incomingCmd = postHttpRequest("{}", agentUri); @@ -349,9 +347,9 @@ public final ArrayList> requestHostVmStateReport() { }.getType()); } catch (final Exception ex) { final String errMsg = "Failed to deserialize Command[] " + incomingCmd; - s_logger.error(errMsg, ex); + logger.error(errMsg, ex); } - s_logger.debug("HostVmStateReportCommand received response " + logger.debug("HostVmStateReportCommand received response " + s_gson.toJson(result)); if (result != null) { if (!result.isEmpty()) { @@ -393,7 +391,7 @@ public final Command[] requestStartupCommand(final Command[] cmd) { } catch (final URISyntaxException e) { // TODO add proper logging final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return null; } final String incomingCmd = postHttpRequest(s_gson.toJson(cmd), agentUri); @@ -406,9 +404,9 @@ public final Command[] requestStartupCommand(final Command[] cmd) { result = s_gson.fromJson(incomingCmd, Command[].class); } catch (final Exception ex) { final String errMsg = "Failed to deserialize Command[] " + incomingCmd; - s_logger.error(errMsg, ex); + logger.error(errMsg, ex); } - s_logger.debug("requestStartupCommand received response " + s_gson.toJson(result)); + logger.debug("requestStartupCommand received response " + s_gson.toJson(result)); if (result.length > 0) { return result; } @@ -432,7 +430,7 @@ public final Answer executeRequest(final Command cmd) { } catch (final URISyntaxException e) { // TODO add proper logging final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return null; } if (cmd instanceof NetworkElementCommand) { @@ -460,7 +458,7 @@ public final Answer executeRequest(final Command cmd) { ((StartCommand)cmd).setSecondaryStorage(secondary); } } else { - s_logger.error("Hyperv manager isn't available. Couldn't check and copy the systemvm iso."); + logger.error("Hyperv manager isn't available. Couldn't check and copy the systemvm iso."); } } } @@ -474,7 +472,7 @@ public final Answer executeRequest(final Command cmd) { // E.g. see Response.getAnswers() final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); final String logResult = cleanPassword(s_gson.toJson(result)); - s_logger.debug("executeRequest received response " + logResult); + logger.debug("executeRequest received response " + logResult); if (result.length > 0) { return result[0]; } @@ -491,7 +489,7 @@ private Answer execute(final CopyCommand cmd) { "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return null; } cleanPassword(cmd.getSrcTO().getDataStore()); @@ -505,7 +503,7 @@ private Answer execute(final CopyCommand cmd) { final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); final String logResult = cleanPassword(s_gson.toJson(result)); - s_logger.debug("executeRequest received response " + logResult); + logger.debug("executeRequest received response " + logResult); if (result.length > 0) { return result[0]; } @@ -524,8 +522,8 @@ private void cleanPassword(final DataStoreTO dataStoreTO) { } private PlugNicAnswer execute(final PlugNicCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource PlugNicCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource PlugNicCommand " + s_gson.toJson(cmd)); } try { @@ -544,19 +542,19 @@ private PlugNicAnswer execute(final PlugNicCommand cmd) { return new PlugNicAnswer(cmd, true, "success"); } final String msg = " Plug Nic failed for the vm as it has reached max limit of NICs to be added"; - s_logger.warn(msg); + logger.warn(msg); return new PlugNicAnswer(cmd, false, msg); } catch (final Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString()); } } private UnPlugNicAnswer execute(final UnPlugNicCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource UnPlugNicCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource UnPlugNicCommand " + s_gson.toJson(cmd)); } try { @@ -574,7 +572,7 @@ private UnPlugNicAnswer execute(final UnPlugNicCommand cmd) { } return new UnPlugNicAnswer(cmd, true, "success"); } catch (final Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new UnPlugNicAnswer(cmd, false, "Unable to execute unPlugNicCommand due to " + e.toString()); } } @@ -589,8 +587,8 @@ public ExecutionResult executeInVR(final String routerIP, final String script, f Pair result; //TODO: Password should be masked, cannot output to log directly - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on VR: " + routerIP + ", script: " + script + " with args: " + args); + if (logger.isDebugEnabled()) { + logger.debug("Run command on VR: " + routerIP + ", script: " + script + " with args: " + args); } try { @@ -598,11 +596,11 @@ public ExecutionResult executeInVR(final String routerIP, final String script, f VRScripts.CONNECTION_TIMEOUT, timeout); } catch (final Exception e) { final String msg = "Command failed due to " + e ; - s_logger.error(msg); + logger.error(msg); result = new Pair(false, msg); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(script + " execution result: " + result.first().toString()); + if (logger.isDebugEnabled()) { + logger.debug(script + " execution result: " + result.first().toString()); } return new ExecutionResult(result.first(), result.second()); } @@ -613,7 +611,7 @@ public ExecutionResult createFileInVR(final String routerIp, final String filePa try { SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes(Charset.forName("UTF-8")), fileName, null); } catch (final Exception e) { - s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e); + logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e); return new ExecutionResult(false, e.getMessage()); } return new ExecutionResult(true, null); @@ -660,8 +658,8 @@ private ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) { boolean addVif = false; if (ip.isAdd() && publicNicInfo == -1) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp()); + if (logger.isDebugEnabled()) { + logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp()); } addVif = true; } @@ -679,7 +677,7 @@ private ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) { else { // we didn't find any eth device available in VR to configure the ip range with new VLAN final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with."; - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } ip.setNicDevId(publicNicInfo); @@ -689,7 +687,7 @@ private ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) { } } } catch (final Throwable e) { - s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); + logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); return new ExecutionResult(false, e.toString()); } return new ExecutionResult(true, null); @@ -711,7 +709,7 @@ protected ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCo } } catch (final Exception e) { final String msg = "Prepare SetupGuestNetwork failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); @@ -735,7 +733,7 @@ private ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd if (ip.isAdd()) { throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with."); } else { - s_logger.debug("VIF to deassociate IP with does not exist, return success"); + logger.debug("VIF to deassociate IP with does not exist, return success"); continue; } } @@ -743,7 +741,7 @@ private ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd ip.setNicDevId(publicNicInfo); } } catch (final Exception e) { - s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception: ", e); + logger.error("Prepare Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.toString()); } @@ -765,7 +763,7 @@ protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand } } catch (final Exception e) { final String msg = "Prepare Ip SNAT failure due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new ExecutionResult(false, e.toString()); } return new ExecutionResult(true, null); @@ -787,7 +785,7 @@ private ExecutionResult prepareNetworkElementCommand(final SetNetworkACLCommand } } catch (final Exception e) { final String msg = "Prepare SetNetworkACL failed due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); @@ -814,29 +812,29 @@ protected Answer execute(final RemoteAccessVpnCfgCommand cmd) { try { final String command = String.format("%s%s %s", "/opt/cloud/bin/", VRScripts.VPN_L2TP, argsBuf.toString()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing " + command); + if (logger.isDebugEnabled()) { + logger.debug("Executing " + command); } final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("RemoteAccessVpnCfg command on domR failed, message: " + result.second()); + logger.error("RemoteAccessVpnCfg command on domR failed, message: " + result.second()); return new Answer(cmd, false, "RemoteAccessVpnCfg command failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("RemoteAccessVpnCfg command on domain router " + argsBuf.toString() + " completed"); + if (logger.isInfoEnabled()) { + logger.info("RemoteAccessVpnCfg command on domain router " + argsBuf.toString() + " completed"); } } catch (final Throwable e) { if (e instanceof RemoteException) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); } final String msg = "RemoteAccessVpnCfg command failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -856,24 +854,24 @@ protected Answer execute(final VpnUsersCfgCommand cmd) { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh "); + if (logger.isDebugEnabled()) { + logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh "); } final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString()); if (!result.first()) { - s_logger.error("VpnUserCfg command on domR failed, message: " + result.second()); + logger.error("VpnUserCfg command on domR failed, message: " + result.second()); return new Answer(cmd, false, "VpnUserCfg command failed due to " + result.second()); } } catch (final Throwable e) { if (e instanceof RemoteException) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); } final String msg = "VpnUserCfg command failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } } @@ -881,8 +879,8 @@ protected Answer execute(final VpnUsersCfgCommand cmd) { return new Answer(cmd); } private SetStaticRouteAnswer execute(final SetStaticRouteCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetStaticRouteCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetStaticRouteCommand: " + s_gson.toJson(cmd)); } boolean endResult = true; @@ -908,19 +906,19 @@ private SetStaticRouteAnswer execute(final SetStaticRouteCommand cmd) { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing script on domain router " + controlIp + ": /opt/cloud/bin/vpc_staticroute.sh " + args); + if (logger.isDebugEnabled()) { + logger.debug("Executing script on domain router " + controlIp + ": /opt/cloud/bin/vpc_staticroute.sh " + args); } if (!result.first()) { - s_logger.error("SetStaticRouteCommand failure on setting one rule. args: " + args); + logger.error("SetStaticRouteCommand failure on setting one rule. args: " + args); results[i++] = "Failed"; endResult = false; } else { results[i++] = null; } } catch (final Throwable e) { - s_logger.error("SetStaticRouteCommand(args: " + args + ") failed on setting one rule due to " + e); + logger.error("SetStaticRouteCommand(args: " + args + ") failed on setting one rule due to " + e); results[i++] = "Failed"; endResult = false; } @@ -933,9 +931,9 @@ protected CheckS2SVpnConnectionsAnswer execute(final CheckS2SVpnConnectionsComma cmdline.append("/opt/cloud/bin/"); cmdline.append(VRScripts.S2SVPN_CHECK); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing resource CheckS2SVpnConnectionsCommand: " + s_gson.toJson(cmd)); - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + cmdline.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Executing resource CheckS2SVpnConnectionsCommand: " + s_gson.toJson(cmd)); + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + cmdline.toString()); } Pair result; @@ -949,26 +947,26 @@ protected CheckS2SVpnConnectionsAnswer execute(final CheckS2SVpnConnectionsComma result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, cmdline.toString()); if (!result.first()) { - s_logger.error("check site-to-site vpn connections command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + + logger.error("check site-to-site vpn connections command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); return new CheckS2SVpnConnectionsAnswer(cmd, false, result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("check site-to-site vpn connections command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("check site-to-site vpn connections command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); } } catch (final Throwable e) { final String msg = "CheckS2SVpnConnectionsCommand failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new CheckS2SVpnConnectionsAnswer(cmd, false, "CheckS2SVpnConneciontsCommand failed"); } return new CheckS2SVpnConnectionsAnswer(cmd, true, result.second()); } protected Answer execute(final Site2SiteVpnCfgCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource Site2SiteVpnCfgCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource Site2SiteVpnCfgCommand " + s_gson.toJson(cmd)); } final String routerIp = getRouterSshControlIp(cmd); @@ -1018,25 +1016,25 @@ protected Answer execute(final Site2SiteVpnCfgCommand cmd) { result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("Setup site2site VPN " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); + logger.error("Setup site2site VPN " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); return new Answer(cmd, false, "Setup site2site VPN falied due to " + result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("setup site 2 site vpn on router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("setup site 2 site vpn on router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); } } catch (final Throwable e) { final String msg = "Setup site2site VPN falied due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, "Setup site2site VPN failed due to " + e.getMessage()); } return new Answer(cmd, true, result.second()); } protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetSourceNatCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetSourceNatCommand " + s_gson.toJson(cmd)); } final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); @@ -1058,7 +1056,7 @@ protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) { if (!result.first()) { final String msg = "SetupGuestNetworkCommand on domain router " + routerIp + " failed. message: " + result.second(); - s_logger.error(msg); + logger.error(msg); return new SetSourceNatAnswer(cmd, false, msg); } @@ -1066,14 +1064,14 @@ protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) { return new SetSourceNatAnswer(cmd, true, "success"); } catch (final Exception e) { final String msg = "Ip SNAT failure due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new SetSourceNatAnswer(cmd, false, msg); } } protected Answer execute(final SetPortForwardingRulesCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetPortForwardingRulesCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetPortForwardingRulesCommand: " + s_gson.toJson(cmd)); } final String controlIp = getRouterSshControlIp(cmd); @@ -1093,19 +1091,19 @@ protected Answer execute(final SetPortForwardingRulesCommand cmd) { try { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall.sh " + args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args); + if (logger.isDebugEnabled()) { + logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args); } if (!result.first()) { - s_logger.error("SetPortForwardingRulesCommand failure on setting one rule. args: " + args); + logger.error("SetPortForwardingRulesCommand failure on setting one rule. args: " + args); results[i++] = "Failed"; endResult = false; } else { results[i++] = null; } } catch (final Throwable e) { - s_logger.error("SetPortForwardingRulesCommand(args: " + args + ") failed on setting one rule due to " + e.getMessage()); + logger.error("SetPortForwardingRulesCommand(args: " + args + ") failed on setting one rule due to " + e.getMessage()); results[i++] = "Failed"; endResult = false; } @@ -1117,9 +1115,9 @@ protected Answer execute(final SetPortForwardingRulesCommand cmd) { protected Answer execute(final CheckRouterCommand cmd) { final String command = String.format("%s%s", "/opt/cloud/bin/", VRScripts.RVR_CHECK); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing resource CheckRouterCommand: " + s_gson.toJson(cmd)); - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); + if (logger.isDebugEnabled()) { + logger.debug("Executing resource CheckRouterCommand: " + s_gson.toJson(cmd)); + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); } Pair result; @@ -1129,17 +1127,17 @@ protected Answer execute(final CheckRouterCommand cmd) { result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("check router command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); + logger.error("check router command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); return new CheckRouterAnswer(cmd, "CheckRouter failed due to " + result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("check router command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("check router command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); } } catch (final Throwable e) { final String msg = "CheckRouterCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new CheckRouterAnswer(cmd, msg); } return new CheckRouterAnswer(cmd, result.second(), true); @@ -1151,8 +1149,8 @@ protected Answer execute(final SetStaticNatRulesCommand cmd) { //return SetVPCStaticNatRules(cmd); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetFirewallRuleCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetFirewallRuleCommand: " + s_gson.toJson(cmd)); } String args = null; @@ -1177,19 +1175,19 @@ protected Answer execute(final SetStaticNatRulesCommand cmd) { final String controlIp = getRouterSshControlIp(cmd); final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall.sh " + args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args); + if (logger.isDebugEnabled()) { + logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args); } if (!result.first()) { - s_logger.error("SetStaticNatRulesCommand failure on setting one rule. args: " + args); + logger.error("SetStaticNatRulesCommand failure on setting one rule. args: " + args); results[i++] = "Failed"; endResult = false; } else { results[i++] = null; } } catch (final Throwable e) { - s_logger.error("SetStaticNatRulesCommand (args: " + args + ") failed on setting one rule due to " + e.getMessage()); + logger.error("SetStaticNatRulesCommand (args: " + args + ") failed on setting one rule due to " + e.getMessage()); results[i++] = "Failed"; endResult = false; } @@ -1198,8 +1196,8 @@ protected Answer execute(final SetStaticNatRulesCommand cmd) { } protected Answer execute(final PingTestCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource PingTestCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource PingTestCommand: " + s_gson.toJson(cmd)); } final String controlIp = cmd.getRouterIp(); final String args = " -c 1 -n -q " + cmd.getPrivateIp(); @@ -1209,7 +1207,7 @@ protected Answer execute(final PingTestCommand cmd) { return new Answer(cmd); } } catch (final Exception e) { - s_logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + e.getMessage()); + logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + e.getMessage()); } return new Answer(cmd, false, "PingTestCommand failed"); } @@ -1218,8 +1216,8 @@ protected Answer execute(final DeleteIpAliasCommand cmd) { cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final List revokedIpAliasTOs = cmd.getDeleteIpAliasTos(); final List activeIpAliasTOs = cmd.getCreateIpAliasTos(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing deleteIpAlias command: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing deleteIpAlias command: " + s_gson.toJson(cmd)); } final StringBuilder args = new StringBuilder(); for (final IpAliasTO ipAliasTO : revokedIpAliasTOs) { @@ -1239,8 +1237,8 @@ protected Answer execute(final DeleteIpAliasCommand cmd) { args.append(ipAliasTO.getNetmask()); args.append("-"); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/deleteIpAlias " + args); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/deleteIpAlias " + args); } try { @@ -1248,18 +1246,18 @@ protected Answer execute(final DeleteIpAliasCommand cmd) { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/deleteIpAlias.sh " + args); if (!result.first()) { - s_logger.error("deleteIpAlias command on domr " + controlIp + " failed, message: " + result.second()); + logger.error("deleteIpAlias command on domr " + controlIp + " failed, message: " + result.second()); return new Answer(cmd, false, "deleteIpAlias failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("deleteIpAlias command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("deleteIpAlias command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "deleteIpAlias failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -1334,27 +1332,27 @@ protected Answer execute(final LoadBalancerConfigCommand cmd) { SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "scp " + tmpCfgFilePath + " /etc/haproxy/haproxy.cfg.new"); if (!result.first()) { - s_logger.error("Unable to copy haproxy configuration file"); + logger.error("Unable to copy haproxy configuration file"); return new Answer(cmd, false, "LoadBalancerConfigCommand failed due to unable to copy haproxy configuration file"); } final String command = String.format("%s%s %s", "/root/", VRScripts.LB, args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domain router " + routerIp + command); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domain router " + routerIp + command); } result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { final String msg = "LoadBalancerConfigCommand on domain router " + routerIp + " failed. message: " + result.second(); - s_logger.error(msg); + logger.error(msg); return new Answer(cmd, false, msg); } - if (s_logger.isInfoEnabled()) { - s_logger.info("LoadBalancerConfigCommand on domain router " + routerIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("LoadBalancerConfigCommand on domain router " + routerIp + " completed"); } } finally { SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "rm " + tmpCfgFilePath); @@ -1362,15 +1360,15 @@ protected Answer execute(final LoadBalancerConfigCommand cmd) { return new Answer(cmd); } catch (final Throwable e) { - s_logger.error("Unexpected exception: " + e.toString(), e); + logger.error("Unexpected exception: " + e.toString(), e); return new Answer(cmd, false, "LoadBalancerConfigCommand failed due to " + e.getMessage()); } } protected Answer execute(final SavePasswordCommand cmd) { - if (s_logger.isInfoEnabled()) { + if (logger.isInfoEnabled()) { - s_logger.info("Executing resource SavePasswordCommand. vmName: " + cmd.getVmName() + ", vmIp: " + cmd.getVmIpAddress() + ", password: " + + logger.info("Executing resource SavePasswordCommand. vmName: " + cmd.getVmName() + ", vmIp: " + cmd.getVmIpAddress() + ", password: " + StringUtils.getMaskedPasswordForDisplay(cmd.getPassword())); } @@ -1381,9 +1379,9 @@ protected Answer execute(final SavePasswordCommand cmd) { // Run save_password_to_domr.sh final String command = String.format("%s%s %s %s %s %s", "/opt/cloud/bin/", VRScripts.PASSWORD, "-v", vmIpAddress, "-p", password); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { final String debugCommand = String.format("%s%s %s %s %s %s", "/opt/cloud/bin/", VRScripts.PASSWORD, "-v", vmIpAddress, "-p", StringUtils.getMaskedPasswordForDisplay(cmd.getPassword())); - s_logger.debug("Run command on domain router " + controlIp + debugCommand); + logger.debug("Run command on domain router " + controlIp + debugCommand); } try { @@ -1391,18 +1389,18 @@ protected Answer execute(final SavePasswordCommand cmd) { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("savepassword command on domain router " + controlIp + " failed, message: " + result.second()); + logger.error("savepassword command on domain router " + controlIp + " failed, message: " + result.second()); return new Answer(cmd, false, "SavePassword failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("savepassword command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("savepassword command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "SavePasswordCommand failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } return new Answer(cmd); @@ -1447,16 +1445,16 @@ protected SetFirewallRulesAnswer execute(final SetFirewallRulesCommand cmd) { result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall_rule.sh " + args); } - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (trafficType == FirewallRule.TrafficType.Egress) { - s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewallRule_egress.sh " + args); + logger.debug("Executing script on domain router " + controlIp + ": /root/firewallRule_egress.sh " + args); } else { - s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewall_rule.sh " + args); + logger.debug("Executing script on domain router " + controlIp + ": /root/firewall_rule.sh " + args); } } if (!result.first()) { - s_logger.error("SetFirewallRulesCommand failure on setting one rule. args: " + args); + logger.error("SetFirewallRulesCommand failure on setting one rule. args: " + args); //FIXME - in the future we have to process each rule separately; now we temporarily set every rule to be false if single rule fails for (int i = 0; i < results.length; i++) { results[i] = "Failed"; @@ -1465,7 +1463,7 @@ protected SetFirewallRulesAnswer execute(final SetFirewallRulesCommand cmd) { return new SetFirewallRulesAnswer(cmd, false, results); } } catch (final Throwable e) { - s_logger.error("SetFirewallRulesCommand(args: " + args + ") failed on setting one rule due to ", e); + logger.error("SetFirewallRulesCommand(args: " + args + ") failed on setting one rule due to ", e); //FIXME - in the future we have to process each rule separately; now we temporarily set every rule to be false if single rule fails for (int i = 0; i < results.length; i++) { results[i] = "Failed"; @@ -1477,15 +1475,15 @@ protected SetFirewallRulesAnswer execute(final SetFirewallRulesCommand cmd) { } protected Answer execute(final VmDataCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource VmDataCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource VmDataCommand: " + s_gson.toJson(cmd)); } final String controlIp = getRouterSshControlIp(cmd); final Map> data = new HashMap>(); data.put(cmd.getVmIpAddress(), cmd.getVmData()); String json = new Gson().toJson(data); - s_logger.debug("VM data JSON IS:" + json); + logger.debug("VM data JSON IS:" + json); json = Base64.encodeBase64String(json.getBytes(Charset.forName("UTF-8"))); final String command = String.format("%s%s %s %s", "/opt/cloud/bin/", VRScripts.VMDATA, "-d", json); @@ -1493,24 +1491,24 @@ protected Answer execute(final VmDataCommand cmd) { try { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("vm_data command on domain router " + controlIp + " failed. messge: " + result.second()); + logger.error("vm_data command on domain router " + controlIp + " failed. messge: " + result.second()); return new Answer(cmd, false, "VmDataCommand failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("vm_data command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("vm_data command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "VmDataCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } return new Answer(cmd); } protected Answer execute(final DhcpEntryCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource DhcpEntryCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource DhcpEntryCommand: " + s_gson.toJson(cmd)); } // ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null @@ -1544,8 +1542,8 @@ protected Answer execute(final DhcpEntryCommand cmd) { final String command = String.format("%s%s %s", "/root/", VRScripts.DHCP, args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); } try { @@ -1553,18 +1551,18 @@ protected Answer execute(final DhcpEntryCommand cmd) { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("dhcp_entry command on domR " + controlIp + " failed, message: " + result.second()); + logger.error("dhcp_entry command on domR " + controlIp + " failed, message: " + result.second()); return new Answer(cmd, false, "DhcpEntry failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("dhcp_entry command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("dhcp_entry command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "DhcpEntryCommand failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -1572,8 +1570,8 @@ protected Answer execute(final DhcpEntryCommand cmd) { } protected Answer execute(final CreateIpAliasCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing createIpAlias command: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing createIpAlias command: " + s_gson.toJson(cmd)); } cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final List ipAliasTOs = cmd.getIpAliasList(); @@ -1586,8 +1584,8 @@ protected Answer execute(final CreateIpAliasCommand cmd) { args.append(ipaliasto.getNetmask()); args.append("-"); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/createIpAlias " + args); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/createIpAlias " + args); } try { @@ -1595,18 +1593,18 @@ protected Answer execute(final CreateIpAliasCommand cmd) { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/createIpAlias.sh " + args); if (!result.first()) { - s_logger.error("CreateIpAlias command on domr " + controlIp + " failed, message: " + result.second()); + logger.error("CreateIpAlias command on domr " + controlIp + " failed, message: " + result.second()); return new Answer(cmd, false, "createipAlias failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("createIpAlias command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("createIpAlias command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "createIpAlias failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -1614,8 +1612,8 @@ protected Answer execute(final CreateIpAliasCommand cmd) { } protected Answer execute(final DnsMasqConfigCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing dnsmasqConfig command: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing dnsmasqConfig command: " + s_gson.toJson(cmd)); } final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final String controlIp = getRouterSshControlIp(cmd); @@ -1639,21 +1637,21 @@ protected Answer execute(final DnsMasqConfigCommand cmd) { final String command = String.format("%s%s %s", "/root/", VRScripts.DHCP, args); final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domain router " + routerIp + ", /root/dnsmasq.sh"); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domain router " + routerIp + ", /root/dnsmasq.sh"); } if (!result.first()) { - s_logger.error("Unable update dnsmasq config file"); + logger.error("Unable update dnsmasq config file"); return new Answer(cmd, false, "dnsmasq config update failed due to: " + result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("dnsmasq config command on domain router " + routerIp + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("dnsmasq config command on domain router " + routerIp + " completed"); } } catch (final Throwable e) { final String msg = "Dnsmasqconfig command failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -1678,7 +1676,7 @@ protected Answer execute(final DnsMasqConfigCommand cmd) { private int findRouterEthDeviceIndex(final String domrName, final String routerIp, final String mac) throws Exception { - s_logger.info("findRouterEthDeviceIndex. mac: " + mac); + logger.info("findRouterEthDeviceIndex. mac: " + mac); // TODO : this is a temporary very inefficient solution, will refactor it later final Pair result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, @@ -1694,14 +1692,14 @@ private int findRouterEthDeviceIndex(final String domrName, final String routerI if (!("all".equalsIgnoreCase(token) || "default".equalsIgnoreCase(token) || "lo".equalsIgnoreCase(token))) { final String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run domr script " + cmd); + if (logger.isDebugEnabled()) { + logger.debug("Run domr script " + cmd); } final Pair result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, // TODO need to find the dev index inside router based on IP address cmd); - if (s_logger.isDebugEnabled()) { - s_logger.debug("result: " + result2.first() + ", output: " + result2.second()); + if (logger.isDebugEnabled()) { + logger.debug("result: " + result2.first() + ", output: " + result2.second()); } if (result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim())) { @@ -1711,7 +1709,7 @@ private int findRouterEthDeviceIndex(final String domrName, final String routerI } } - s_logger.warn("can not find intereface associated with mac: " + mac + ", guest OS may still at loading state, retry..."); + logger.warn("can not find intereface associated with mac: " + mac + ", guest OS may still at loading state, retry..."); } @@ -1720,7 +1718,7 @@ private int findRouterEthDeviceIndex(final String domrName, final String routerI private Pair findRouterFreeEthDeviceIndex(final String routerIp) throws Exception { - s_logger.info("findRouterFreeEthDeviceIndex. mac: "); + logger.info("findRouterFreeEthDeviceIndex. mac: "); // TODO : this is a temporary very inefficient solution, will refactor it later final Pair result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, @@ -1738,14 +1736,14 @@ private Pair findRouterFreeEthDeviceIndex(final String routerIp //TODO: don't check for eth0,1,2, as they will be empty by default. //String cmd = String.format("ip address show %s ", token); final String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run domr script " + cmd); + if (logger.isDebugEnabled()) { + logger.debug("Run domr script " + cmd); } final Pair result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, // TODO need to find the dev index inside router based on IP address cmd); - if (s_logger.isDebugEnabled()) { - s_logger.debug("result: " + result2.first() + ", output: " + result2.second()); + if (logger.isDebugEnabled()) { + logger.debug("result: " + result2.first() + ", output: " + result2.second()); } if (result2.first() && result2.second().trim().length() > 0) { @@ -1755,7 +1753,7 @@ private Pair findRouterFreeEthDeviceIndex(final String routerIp } } - //s_logger.warn("can not find intereface associated with mac: , guest OS may still at loading state, retry..."); + //logger.warn("can not find intereface associated with mac: , guest OS may still at loading state, retry..."); } @@ -1763,8 +1761,8 @@ private Pair findRouterFreeEthDeviceIndex(final String routerIp } protected Answer execute(final IpAssocCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource IPAssocCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource IPAssocCommand: " + s_gson.toJson(cmd)); } int i = 0; @@ -1785,7 +1783,7 @@ protected Answer execute(final IpAssocCommand cmd) { results[i++] = IpAssocAnswer.errorResult; } } catch (final Throwable e) { - s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); + logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); for (; i < cmd.getIpAddresses().length; i++) { results[i++] = IpAssocAnswer.errorResult; @@ -1807,11 +1805,11 @@ protected int getVmFreeNicIndex(final String vmName) { "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } final String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri); final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); - s_logger.debug("GetVmConfigCommand response received " + logger.debug("GetVmConfigCommand response received " + s_gson.toJson(result)); if (result.length > 0) { final GetVmConfigAnswer ans = (GetVmConfigAnswer)result[0]; @@ -1840,11 +1838,11 @@ protected int getVmNics(final String vmName, String vlanid) { "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } final String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri); final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); - s_logger.debug("executeRequest received response " + logger.debug("executeRequest received response " + s_gson.toJson(result)); if (result.length > 0) { final GetVmConfigAnswer ans = (GetVmConfigAnswer)result[0]; @@ -1869,11 +1867,11 @@ protected void modifyNicVlan(final String vmName, final String vlanId, final Str "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } final String ansStr = postHttpRequest(s_gson.toJson(modifynic), agentUri); final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); - s_logger.debug("executeRequest received response " + logger.debug("executeRequest received response " + s_gson.toJson(result)); if (result.length > 0) { } @@ -1890,11 +1888,11 @@ protected void modifyNicVlan(final String vmName, final String vlanId, final int "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } final String ansStr = postHttpRequest(s_gson.toJson(modifyNic), agentUri); final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); - s_logger.debug("executeRequest received response " + logger.debug("executeRequest received response " + s_gson.toJson(result)); if (result.length > 0) { } @@ -1914,13 +1912,13 @@ protected void assignPublicIpAddress(final String vmName, final String privateIp boolean addVif = false; if (add && publicNicInfo == -1) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Plug new NIC to associate" + privateIpAddress + " to " + publicIpAddress); + if (logger.isDebugEnabled()) { + logger.debug("Plug new NIC to associate" + privateIpAddress + " to " + publicIpAddress); } addVif = true; } else if (!add && firstIP) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unplug NIC " + publicNicInfo); + if (logger.isDebugEnabled()) { + logger.debug("Unplug NIC " + publicNicInfo); } } @@ -1937,7 +1935,7 @@ protected void assignPublicIpAddress(final String vmName, final String privateIp else { // we didn't find any eth device available in VR to configure the ip range with new VLAN final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with."; - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } } @@ -1972,29 +1970,29 @@ protected void assignPublicIpAddress(final String vmName, final String privateIp final String command = String.format("%s%s %s","/opt/cloud/bin/", VRScripts.IPASSOC ,args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domain router " + privateIpAddress + command); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domain router " + privateIpAddress + command); } final Pair result = SshHelper.sshExecute(privateIpAddress, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("ipassoc command on domain router " + privateIpAddress + " failed. message: " + result.second()); + logger.error("ipassoc command on domain router " + privateIpAddress + " failed. message: " + result.second()); throw new Exception("ipassoc failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("ipassoc command on domain router " + privateIpAddress + " completed"); + if (logger.isInfoEnabled()) { + logger.info("ipassoc command on domain router " + privateIpAddress + " completed"); } } protected Answer execute(final GetDomRVersionCmd cmd) { final String command = String.format("%s%s", "/opt/cloud/bin/", VRScripts.VERSION); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing resource GetDomRVersionCmd: " + s_gson.toJson(cmd)); - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); + if (logger.isDebugEnabled()) { + logger.debug("Executing resource GetDomRVersionCmd: " + s_gson.toJson(cmd)); + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); } Pair result; @@ -2003,17 +2001,17 @@ protected Answer execute(final GetDomRVersionCmd cmd) { result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("GetDomRVersionCmd on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); + logger.error("GetDomRVersionCmd on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed due to " + result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("GetDomRVersionCmd on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("GetDomRVersionCmd on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); } } catch (final Throwable e) { final String msg = "GetDomRVersionCmd failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new GetDomRVersionAnswer(cmd, msg); } final String[] lines = result.second().split("&"); @@ -2023,21 +2021,21 @@ protected Answer execute(final GetDomRVersionCmd cmd) { return new GetDomRVersionAnswer(cmd, result.second(), lines[0], lines[1]); } - private static String getRouterSshControlIp(final NetworkElementCommand cmd) { + private String getRouterSshControlIp(final NetworkElementCommand cmd) { final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final String routerGuestIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP); final String zoneNetworkType = cmd.getAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE); if (routerGuestIp != null && zoneNetworkType != null && NetworkType.valueOf(zoneNetworkType) == NetworkType.Basic) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("In Basic zone mode, use router's guest IP for SSH control. guest IP : " + routerGuestIp); + if (logger.isDebugEnabled()) { + logger.debug("In Basic zone mode, use router's guest IP for SSH control. guest IP : " + routerGuestIp); } return routerGuestIp; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Use router's private IP for SSH control. IP : " + routerIp); + if (logger.isDebugEnabled()) { + logger.debug("Use router's private IP for SSH control. IP : " + routerIp); } return routerIp; } @@ -2046,8 +2044,8 @@ protected Answer execute(final NetworkUsageCommand cmd) { if (cmd.isForVpc()) { //return VPCNetworkUsage(cmd); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource NetworkUsageCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource NetworkUsageCommand " + s_gson.toJson(cmd)); } if (cmd.getOption() != null && cmd.getOption().equals("create")) { networkUsage(cmd.getPrivateIP(), "create", null); @@ -2072,21 +2070,21 @@ private long[] getNetworkStats(final String privateIP) { stats[1] += Long.parseLong(splitResult[i++]); } } catch (final Throwable e) { - s_logger.warn("Unable to parse return from script return of network usage command: " + e.toString(), e); + logger.warn("Unable to parse return from script return of network usage command: " + e.toString(), e); } } return stats; } protected Answer execute(final SetMonitorServiceCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetMonitorServiceCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetMonitorServiceCommand: " + s_gson.toJson(cmd)); } final String controlIp = getRouterSshControlIp(cmd); final String config = cmd.getConfiguration(); if (org.apache.commons.lang3.StringUtils.isBlank(config)) { - s_logger.error("SetMonitorServiceCommand should have config for this case"); + logger.error("SetMonitorServiceCommand should have config for this case"); return new Answer(cmd, false, "SetMonitorServiceCommand failed due to missing config"); } @@ -2099,14 +2097,14 @@ protected Answer execute(final SetMonitorServiceCommand cmd) { if (!result.first()) { final String msg= "monitor_service.sh failed on domain router " + controlIp + " failed " + result.second(); - s_logger.error(msg); + logger.error(msg); return new Answer(cmd, false, msg); } return new Answer(cmd); } catch (final Throwable e) { - s_logger.error("Unexpected exception: " + e.toString(), e); + logger.error("Unexpected exception: " + e.toString(), e); return new Answer(cmd, false, "SetMonitorServiceCommand failed due to " + e); } } @@ -2116,28 +2114,28 @@ protected CheckSshAnswer execute(final CheckSshCommand cmd) { final String privateIp = cmd.getIp(); final int cmdPort = cmd.getPort(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port, " + privateIp + ":" + cmdPort); } try { final String result = connect(cmd.getName(), privateIp, cmdPort); if (result != null) { - s_logger.error("Can not ping System vm " + vmName + "due to:" + result); + logger.error("Can not ping System vm " + vmName + "due to:" + result); return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result); } } catch (final Exception e) { - s_logger.error("Can not ping System vm " + vmName + "due to exception"); + logger.error("Can not ping System vm " + vmName + "due to exception"); return new CheckSshAnswer(cmd, e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port succeeded for vm " + vmName); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port succeeded for vm " + vmName); } if (VirtualMachineName.isValidRouterName(vmName)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Execute network usage setup command on " + vmName); + if (logger.isDebugEnabled()) { + logger.debug("Execute network usage setup command on " + vmName); } networkUsage(privateIp, "create", null); } @@ -2162,8 +2160,8 @@ protected String networkUsage(final String privateIpAddress, final String option } try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Executing /opt/cloud/bin/netusage.sh " + args + " on DomR " + privateIpAddress); + if (logger.isTraceEnabled()) { + logger.trace("Executing /opt/cloud/bin/netusage.sh " + args + " on DomR " + privateIpAddress); } final Pair result = @@ -2175,7 +2173,7 @@ protected String networkUsage(final String privateIpAddress, final String option return result.second(); } catch (final Throwable e) { - s_logger.error("Unable to execute NetworkUsage command on DomR (" + privateIpAddress + "), domR may not be ready yet. failure due to " + e); + logger.error("Unable to execute NetworkUsage command on DomR (" + privateIpAddress + "), domR may not be ready yet. failure due to " + e); } return null; @@ -2192,12 +2190,12 @@ public File getSystemVMKeyFile() { } assert keyFile != null; if (!keyFile.exists()) { - s_logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); + logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); } return keyFile; } - public static String postHttpRequest(final String jsonCmd, final URI agentUri) { + public String postHttpRequest(final String jsonCmd, final URI agentUri) { // Using Apache's HttpClient for HTTP POST // Java-only approach discussed at on StackOverflow concludes with // comment to use Apache HttpClient @@ -2205,7 +2203,7 @@ public static String postHttpRequest(final String jsonCmd, final URI agentUri) { // use Apache. String logMessage = StringEscapeUtils.unescapeJava(jsonCmd); logMessage = cleanPassword(logMessage); - s_logger.debug("POST request to " + agentUri.toString() + logger.debug("POST request to " + agentUri.toString() + " with contents " + logMessage); // Create request @@ -2225,13 +2223,13 @@ public boolean isTrusted(final X509Certificate[] chain, final String authType) final ClientConnectionManager ccm = new BasicClientConnectionManager(registry); httpClient = new DefaultHttpClient(ccm); } catch (final KeyManagementException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (final UnrecoverableKeyException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (final NoSuchAlgorithmException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (final KeyStoreException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } String result = null; @@ -2246,33 +2244,33 @@ public boolean isTrusted(final X509Certificate[] chain, final String authType) final StringEntity cmdJson = new StringEntity(jsonCmd); request.addHeader("content-type", "application/json"); request.setEntity(cmdJson); - s_logger.debug("Sending cmd to " + agentUri.toString() + logger.debug("Sending cmd to " + agentUri.toString() + " cmd data:" + logMessage); final HttpResponse response = httpClient.execute(request); // Unsupported commands will not route. if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { final String errMsg = "Failed to send : HTTP error code : " + response.getStatusLine().getStatusCode(); - s_logger.error(errMsg); + logger.error(errMsg); final String unsupportMsg = "Unsupported command " + agentUri.getPath() + ". Are you sure you got the right type of" + " server?"; final Answer ans = new UnsupportedAnswer(null, unsupportMsg); - s_logger.error(ans); + logger.error(ans); result = s_gson.toJson(new Answer[] {ans}); } else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { final String errMsg = "Failed send to " + agentUri.toString() + " : HTTP error code : " + response.getStatusLine().getStatusCode(); - s_logger.error(errMsg); + logger.error(errMsg); return null; } else { result = EntityUtils.toString(response.getEntity()); final String logResult = cleanPassword(StringEscapeUtils.unescapeJava(result)); - s_logger.debug("POST response is " + logResult); + logger.debug("POST response is " + logResult); } } catch (final ClientProtocolException protocolEx) { // Problem with HTTP message exchange - s_logger.error(protocolEx); + logger.error(protocolEx); } catch (final IOException connEx) { // Problem with underlying communications - s_logger.error(connEx); + logger.error(connEx); } finally { httpClient.getConnectionManager().shutdown(); } @@ -2354,7 +2352,7 @@ protected String connect(final String vmName, final String ipAddress, final int // VM patching/rebooting time that may need int retry = this.retry; while (System.currentTimeMillis() - startTick <= opsTimeout || --retry > 0) { - s_logger.info("Trying to connect to " + ipAddress); + logger.info("Trying to connect to " + ipAddress); try (SocketChannel sch = SocketChannel.open();) { sch.configureBlocking(true); sch.socket().setSoTimeout(5000); @@ -2363,7 +2361,7 @@ protected String connect(final String vmName, final String ipAddress, final int sch.connect(addr); return null; } catch (final IOException e) { - s_logger.info("Could] not connect to " + ipAddress + " due to " + e.toString()); + logger.info("Could] not connect to " + ipAddress + " due to " + e.toString()); if (e instanceof ConnectException) { // if connection is refused because of VM is being started, // we give it more sleep time @@ -2371,7 +2369,7 @@ protected String connect(final String vmName, final String ipAddress, final int try { Thread.sleep(5000); } catch (final InterruptedException ex) { - s_logger.debug("[ignored] interrupted while waiting to retry connecting to vm after exception: "+e.getLocalizedMessage()); + logger.debug("[ignored] interrupted while waiting to retry connecting to vm after exception: "+e.getLocalizedMessage()); } } } @@ -2379,11 +2377,11 @@ protected String connect(final String vmName, final String ipAddress, final int try { Thread.sleep(1000); } catch (final InterruptedException ex) { - s_logger.debug("[ignored] interrupted while connecting to vm."); + logger.debug("[ignored] interrupted while connecting to vm."); } } - s_logger.info("Unable to logon to " + ipAddress); + logger.info("Unable to logon to " + ipAddress); return "Unable to connect"; } diff --git a/plugins/hypervisors/hyperv/src/main/java/org/apache/cloudstack/storage/motion/HypervStorageMotionStrategy.java b/plugins/hypervisors/hyperv/src/main/java/org/apache/cloudstack/storage/motion/HypervStorageMotionStrategy.java index 19c655b8f21f..0e189d050006 100644 --- a/plugins/hypervisors/hyperv/src/main/java/org/apache/cloudstack/storage/motion/HypervStorageMotionStrategy.java +++ b/plugins/hypervisors/hyperv/src/main/java/org/apache/cloudstack/storage/motion/HypervStorageMotionStrategy.java @@ -34,7 +34,8 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -59,7 +60,7 @@ @Component public class HypervStorageMotionStrategy implements DataMotionStrategy { - private static final Logger s_logger = Logger.getLogger(HypervStorageMotionStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AgentManager agentMgr; @Inject VolumeDao volDao; @Inject VolumeDataFactory volFactory; @@ -99,7 +100,7 @@ public void copyAsync(Map volumeMap, VirtualMachineTO vmT throw new CloudRuntimeException("Unsupported operation requested for moving data."); } } catch (Exception e) { - s_logger.error("copy failed", e); + logger.error("copy failed", e); errMsg = e.toString(); } @@ -124,10 +125,10 @@ private Answer migrateVmWithVolumes(VMInstanceVO vm, VirtualMachineTO to, Host s MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getPrivateIpAddress()); MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), command); if (answer == null) { - s_logger.error("Migration with storage of vm " + vm + " failed."); + logger.error("Migration with storage of vm " + vm + " failed."); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else if (!answer.getResult()) { - s_logger.error("Migration with storage of vm " + vm+ " failed. Details: " + answer.getDetails()); + logger.error("Migration with storage of vm " + vm+ " failed. Details: " + answer.getDetails()); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails()); } else { @@ -137,7 +138,7 @@ private Answer migrateVmWithVolumes(VMInstanceVO vm, VirtualMachineTO to, Host s return answer; } catch (OperationTimedoutException e) { - s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e); + logger.error("Error while migrating vm " + vm + " to host " + destHost, e); throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId()); } } @@ -170,7 +171,7 @@ private void updateVolumePathsAfterMigration(Map volumeTo } if (!updated) { - s_logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated."); + logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated."); } } } diff --git a/plugins/hypervisors/hyperv/src/main/resources/META-INF/cloudstack/hyperv-compute/spring-hyperv-compute-context.xml b/plugins/hypervisors/hyperv/src/main/resources/META-INF/cloudstack/hyperv-compute/spring-hyperv-compute-context.xml index ffb6440d3cfa..5549a6b13d77 100644 --- a/plugins/hypervisors/hyperv/src/main/resources/META-INF/cloudstack/hyperv-compute/spring-hyperv-compute-context.xml +++ b/plugins/hypervisors/hyperv/src/main/resources/META-INF/cloudstack/hyperv-compute/spring-hyperv-compute-context.xml @@ -1,12 +1,12 @@ - org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java index 022501524f7f..8fc748262424 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java @@ -36,13 +36,11 @@ import org.apache.cloudstack.ha.HAManager; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; public class KVMInvestigator extends AdapterBase implements Investigator { - private final static Logger s_logger = Logger.getLogger(KVMInvestigator.class); @Inject private HostDao _hostDao; @Inject @@ -62,7 +60,7 @@ public boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) throws Unkno return haManager.isVMAliveOnHost(host); } Status status = isAgentAlive(host); - s_logger.debug("HA: HOST is ineligible legacy state " + status + " for host " + host.getId()); + logger.debug("HA: HOST is ineligible legacy state " + status + " for host " + host.getId()); if (status == null) { throw new UnknownVM(); } @@ -90,7 +88,7 @@ public Status isAgentAlive(Host agent) { storageSupportHA = storageSupportHa(zonePools); } if (!storageSupportHA) { - s_logger.warn( + logger.warn( "Agent investigation was requested on host " + agent + ", but host does not support investigation because it has no NFS storage. Skipping investigation."); return Status.Disconnected; } @@ -106,7 +104,7 @@ public Status isAgentAlive(Host agent) { hostStatus = answer.getResult() ? Status.Down : Status.Up; } } catch (Exception e) { - s_logger.debug("Failed to send command to host: " + agent.getId()); + logger.debug("Failed to send command to host: " + agent.getId()); } if (hostStatus == null) { hostStatus = Status.Disconnected; @@ -118,18 +116,18 @@ public Status isAgentAlive(Host agent) { || (neighbor.getHypervisorType() != Hypervisor.HypervisorType.KVM && neighbor.getHypervisorType() != Hypervisor.HypervisorType.LXC)) { continue; } - s_logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId()); + logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId()); try { Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); if (answer != null) { neighbourStatus = answer.getResult() ? Status.Down : Status.Up; - s_logger.debug("Neighbouring host:" + neighbor.getId() + " returned status:" + neighbourStatus + " for the investigated host:" + agent.getId()); + logger.debug("Neighbouring host:" + neighbor.getId() + " returned status:" + neighbourStatus + " for the investigated host:" + agent.getId()); if (neighbourStatus == Status.Up) { break; } } } catch (Exception e) { - s_logger.debug("Failed to send command to host: " + neighbor.getId()); + logger.debug("Failed to send command to host: " + neighbor.getId()); } } if (neighbourStatus == Status.Up && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) { @@ -138,7 +136,7 @@ public Status isAgentAlive(Host agent) { if (neighbourStatus == Status.Down && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) { hostStatus = Status.Down; } - s_logger.debug("HA: HOST is ineligible legacy state " + hostStatus + " for host " + agent.getId()); + logger.debug("HA: HOST is ineligible legacy state " + hostStatus + " for host " + agent.getId()); return hostStatus; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverImpl.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverImpl.java index 022eafaca8a0..2a8d87af643e 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverImpl.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverImpl.java @@ -21,7 +21,6 @@ import com.cloud.utils.component.AdapterBase; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.util.Map; @@ -31,7 +30,6 @@ public class DpdkDriverImpl extends AdapterBase implements DpdkDriver { private final String dpdkPortVhostUserType = "dpdkvhostuser"; private final String dpdkPortVhostUserClientType = "dpdkvhostuserclient"; - private static final Logger s_logger = Logger.getLogger(DpdkDriver.class); public DpdkDriverImpl() { } @@ -48,7 +46,7 @@ public String getNextDpdkPort() { * Get the latest DPDK port number created on a DPDK enabled host */ public int getDpdkLatestPortNumberUsed() { - s_logger.debug("Checking the last DPDK port created"); + logger.debug("Checking the last DPDK port created"); String cmd = "ovs-vsctl show | grep Port | grep " + DPDK_PORT_PREFIX + " | " + "awk '{ print $2 }' | sort -rV | head -1"; String port = Script.runSimpleBashScript(cmd); @@ -82,7 +80,7 @@ public void addDpdkPort(String bridgeName, String port, String vlan, DpdkHelper. } String cmd = stringBuilder.toString(); - s_logger.debug("DPDK property enabled, executing: " + cmd); + logger.debug("DPDK property enabled, executing: " + cmd); Script.runSimpleBashScript(cmd); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java index 39ecc9182f00..26b8de530837 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java @@ -31,7 +31,6 @@ import com.cloud.utils.net.NetUtils; import com.cloud.utils.script.OutputInterpreter; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -44,7 +43,6 @@ public class BridgeVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(BridgeVifDriver.class); private int _timeout; private final Object _vnetBridgeMonitor = new Object(); @@ -92,9 +90,9 @@ public void getPifs() { for (File netdev : netdevs) { final File isbridge = new File(netdev.getAbsolutePath() + "/bridge"); final String netdevName = netdev.getName(); - s_logger.debug("looking in file " + netdev.getAbsolutePath() + "/bridge"); + logger.debug("looking in file " + netdev.getAbsolutePath() + "/bridge"); if (isbridge.exists()) { - s_logger.debug("Found bridge " + netdevName); + logger.debug("Found bridge " + netdevName); bridges.add(netdevName); } } @@ -103,7 +101,7 @@ public void getPifs() { String publicBridgeName = _libvirtComputingResource.getPublicBridgeName(); for (final String bridge : bridges) { - s_logger.debug("looking for pif for bridge " + bridge); + logger.debug("looking for pif for bridge " + bridge); final String pif = getPif(bridge); if (_libvirtComputingResource.isPublicBridge(bridge)) { _pifs.put("public", pif); @@ -117,10 +115,10 @@ public void getPifs() { // guest(private) creates bridges on a pif, if private bridge not found try pif direct // This addresses the unnecessary requirement of someone to create an unused bridge just for traffic label if (_pifs.get("private") == null) { - s_logger.debug("guest(private) traffic label '" + guestBridgeName + "' not found as bridge, looking for physical interface"); + logger.debug("guest(private) traffic label '" + guestBridgeName + "' not found as bridge, looking for physical interface"); final File dev = new File("/sys/class/net/" + guestBridgeName); if (dev.exists()) { - s_logger.debug("guest(private) traffic label '" + guestBridgeName + "' found as a physical device"); + logger.debug("guest(private) traffic label '" + guestBridgeName + "' found as a physical device"); _pifs.put("private", guestBridgeName); } } @@ -128,15 +126,15 @@ public void getPifs() { // public creates bridges on a pif, if private bridge not found try pif direct // This addresses the unnecessary requirement of someone to create an unused bridge just for traffic label if (_pifs.get("public") == null) { - s_logger.debug("public traffic label '" + publicBridgeName+ "' not found as bridge, looking for physical interface"); + logger.debug("public traffic label '" + publicBridgeName+ "' not found as bridge, looking for physical interface"); final File dev = new File("/sys/class/net/" + publicBridgeName); if (dev.exists()) { - s_logger.debug("public traffic label '" + publicBridgeName + "' found as a physical device"); + logger.debug("public traffic label '" + publicBridgeName + "' found as a physical device"); _pifs.put("public", publicBridgeName); } } - s_logger.debug("done looking for pifs, no more bridges"); + logger.debug("done looking for pifs, no more bridges"); } private String getPif(final String bridge) { @@ -159,7 +157,7 @@ private String matchPifFileInDirectory(final String bridgeName) { // if bridgeName already refers to a pif, return it as-is return bridgeName; } - s_logger.debug("failing to get physical interface from bridge " + bridgeName + ", does " + brif.getAbsolutePath() + "exist?"); + logger.debug("failing to get physical interface from bridge " + bridgeName + ", does " + brif.getAbsolutePath() + "exist?"); return ""; } @@ -167,13 +165,13 @@ private String matchPifFileInDirectory(final String bridgeName) { for (File anInterface : interfaces) { final String fname = anInterface.getName(); - s_logger.debug("matchPifFileInDirectory: file name '" + fname + "'"); + logger.debug("matchPifFileInDirectory: file name '" + fname + "'"); if (LibvirtComputingResource.isInterface(fname)) { return fname; } } - s_logger.debug("failing to get physical interface from bridge " + bridgeName + ", did not find an eth*, bond*, team*, vlan*, em*, p*p*, ens*, eno*, enp*, or enx* in " + brif.getAbsolutePath()); + logger.debug("failing to get physical interface from bridge " + bridgeName + ", did not find an eth*, bond*, team*, vlan*, em*, p*p*, ens*, eno*, enp*, or enx* in " + brif.getAbsolutePath()); return ""; } @@ -189,10 +187,10 @@ protected boolean isValidProtocolAndVnetId(final String vNetId, final String pro @Override public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter, Map extraConfig) throws InternalErrorException, LibvirtException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("nic=" + nic); + if (logger.isDebugEnabled()) { + logger.debug("nic=" + nic); if (nicAdapter != null && !nicAdapter.isEmpty()) { - s_logger.debug("custom nic adapter=" + nicAdapter); + logger.debug("custom nic adapter=" + nicAdapter); } } @@ -215,7 +213,7 @@ public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicA if (nic.getType() == Networks.TrafficType.Guest) { if (isBroadcastTypeVlanOrVxlan(nic) && isValidProtocolAndVnetId(vNetId, protocol)) { if (trafficLabel != null && !trafficLabel.isEmpty()) { - s_logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel); + logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel); String brName = createVnetBr(vNetId, trafficLabel, protocol); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else { @@ -238,7 +236,7 @@ public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicA } else if (nic.getType() == Networks.TrafficType.Public) { if (isBroadcastTypeVlanOrVxlan(nic) && isValidProtocolAndVnetId(vNetId, protocol)) { if (trafficLabel != null && !trafficLabel.isEmpty()) { - s_logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel); + logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel); String brName = createVnetBr(vNetId, trafficLabel, protocol); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else { @@ -309,7 +307,7 @@ private void createVnet(String vnetId, String pif, String brName, String protoco if (protocol.equals(Networks.BroadcastDomainType.Vxlan.scheme())) { script = _modifyVxlanPath; } - final Script command = new Script(script, _timeout, s_logger); + final Script command = new Script(script, _timeout, logger); command.add("-v", vnetId); command.add("-p", pif); command.add("-b", brName); @@ -355,7 +353,7 @@ private void deleteVnetBr(String brName, boolean deleteBr) { } if (vNetId == null || vNetId.isEmpty()) { - s_logger.debug("unable to get a vNet ID from name " + brName); + logger.debug("unable to get a vNet ID from name " + brName); return; } @@ -366,7 +364,7 @@ private void deleteVnetBr(String brName, boolean deleteBr) { scriptPath = _modifyVlanPath; } - final Script command = new Script(scriptPath, _timeout, s_logger); + final Script command = new Script(scriptPath, _timeout, logger); command.add("-o", "delete"); command.add("-v", vNetId); command.add("-p", pName); @@ -377,7 +375,7 @@ private void deleteVnetBr(String brName, boolean deleteBr) { final String result = command.execute(); if (result != null) { - s_logger.debug("Delete bridge " + brName + " failed: " + result); + logger.debug("Delete bridge " + brName + " failed: " + result); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/DirectVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/DirectVifDriver.java index 5037ad1aec71..71afc9409328 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/DirectVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/DirectVifDriver.java @@ -20,7 +20,6 @@ package com.cloud.hypervisor.kvm.resource; import org.apache.commons.compress.utils.Sets; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -31,7 +30,6 @@ public class DirectVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(DirectVifDriver.class); /** * Experimental driver to configure direct networking in libvirt. This should only diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java index 178728b7f96d..2386e7d2d590 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java @@ -26,7 +26,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -41,7 +40,6 @@ import com.cloud.utils.script.Script; public class IvsVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(IvsVifDriver.class); private int _timeout; private final Object _vnetBridgeMonitor = new Object(); @@ -100,7 +98,7 @@ public InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter, Map s_mapper = new HashMap(); static { s_mapper.put("CentOS 4.5 (32-bit)", "CentOS 4.5"); @@ -133,10 +134,10 @@ public class KVMGuestOsMapper { } - public static String getGuestOsName(String guestOsName) { + public String getGuestOsName(String guestOsName) { String guestOS = s_mapper.get(guestOsName); if (guestOS == null) { - s_logger.debug("Can't find the mapping of guest os: " + guestOsName); + logger.debug("Can't find the mapping of guest os: " + guestOsName); return "Other"; } else { return guestOS; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHABase.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHABase.java index b9abea4f0bce..896426addca1 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHABase.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHABase.java @@ -18,7 +18,8 @@ import java.io.File; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.LibvirtException; import org.libvirt.StoragePool; import org.libvirt.StoragePoolInfo; @@ -32,7 +33,7 @@ import com.cloud.agent.properties.AgentPropertiesFileHandler; public class KVMHABase { - private static final Logger s_logger = Logger.getLogger(KVMHABase.class); + protected Logger logger = LogManager.getLogger(getClass()); private long _timeout = 60000; /* 1 minutes */ protected static String s_heartBeatPath; protected long _heartBeatUpdateTimeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HEARTBEAT_UPDATE_TIMEOUT); @@ -173,14 +174,14 @@ protected String getMountPoint(HAStoragePool storagePool) { } } catch (LibvirtException e) { - s_logger.debug("Ignoring libvirt error.", e); + logger.debug("Ignoring libvirt error.", e); } finally { try { if (pool != null) { pool.free(); } } catch (LibvirtException e) { - s_logger.debug("Ignoring libvirt error.", e); + logger.debug("Ignoring libvirt error.", e); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAChecker.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAChecker.java index 2df70375107b..db6190fa8f28 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAChecker.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAChecker.java @@ -20,12 +20,10 @@ import java.util.concurrent.Callable; import java.util.stream.Collectors; -import org.apache.log4j.Logger; import com.cloud.agent.api.to.HostTO; public class KVMHAChecker extends KVMHABase implements Callable { - private static final Logger s_logger = Logger.getLogger(KVMHAChecker.class); private List storagePools; private HostTO host; private boolean reportFailureIfOneStorageIsDown; @@ -46,7 +44,7 @@ public Boolean checkingHeartBeat() { String hostAndPools = String.format("host IP [%s] in pools [%s]", host.getPrivateNetwork().getIp(), storagePools.stream().map(pool -> pool.getPoolUUID()).collect(Collectors.joining(", "))); - s_logger.debug(String.format("Checking heart beat with KVMHAChecker for %s", hostAndPools)); + logger.debug(String.format("Checking heart beat with KVMHAChecker for %s", hostAndPools)); for (HAStoragePool pool : storagePools) { validResult = pool.getPool().checkingHeartBeat(pool, host); @@ -56,7 +54,7 @@ public Boolean checkingHeartBeat() { } if (!validResult) { - s_logger.warn(String.format("All checks with KVMHAChecker for %s considered it as dead. It may cause a shutdown of the host.", hostAndPools)); + logger.warn(String.format("All checks with KVMHAChecker for %s considered it as dead. It may cause a shutdown of the host.", hostAndPools)); } return validResult; @@ -64,7 +62,7 @@ public Boolean checkingHeartBeat() { @Override public Boolean call() throws Exception { - // s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new + // logger.addAppender(new org.apache.log4j.ConsoleAppender(new // org.apache.log4j.PatternLayout(), "System.out")); return checkingHeartBeat(); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java index eb09408c14ed..cf407bfc08a8 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java @@ -20,7 +20,6 @@ import com.cloud.agent.properties.AgentPropertiesFileHandler; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.utils.script.Script; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; import org.libvirt.StoragePool; @@ -35,7 +34,6 @@ public class KVMHAMonitor extends KVMHABase implements Runnable { - private static final Logger s_logger = Logger.getLogger(KVMHAMonitor.class); private final Map storagePool = new ConcurrentHashMap<>(); private final boolean rebootHostAndAlertManagementOnHeartbeatTimeout; @@ -98,7 +96,7 @@ protected void runHeartBeat() { result = executePoolHeartBeatCommand(uuid, primaryStoragePool, result); if (result != null && rebootHostAndAlertManagementOnHeartbeatTimeout) { - s_logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; stopping cloudstack-agent.", uuid, result)); + logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; stopping cloudstack-agent.", uuid, result)); primaryStoragePool.getPool().createHeartBeatCommand(primaryStoragePool, null, false);; } } @@ -115,11 +113,11 @@ private String executePoolHeartBeatCommand(String uuid, HAStoragePool primarySto result = primaryStoragePool.getPool().createHeartBeatCommand(primaryStoragePool, hostPrivateIp, true); if (result != null) { - s_logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; try: %s of %s.", uuid, result, i, _heartBeatUpdateMaxTries)); + logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; try: %s of %s.", uuid, result, i, _heartBeatUpdateMaxTries)); try { Thread.sleep(_heartBeatUpdateRetrySleep); } catch (InterruptedException e) { - s_logger.debug("[IGNORED] Interrupted between heartbeat retries.", e); + logger.debug("[IGNORED] Interrupted between heartbeat retries.", e); } } else { break; @@ -135,21 +133,21 @@ private void checkForNotExistingPools(Set removedPools, String uuid) { StoragePool storage = conn.storagePoolLookupByUUIDString(uuid); if (storage == null || storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { if (storage == null) { - s_logger.debug(String.format("Libvirt storage pool [%s] not found, removing from HA list.", uuid)); + logger.debug(String.format("Libvirt storage pool [%s] not found, removing from HA list.", uuid)); } else { - s_logger.debug(String.format("Libvirt storage pool [%s] found, but not running, removing from HA list.", uuid)); + logger.debug(String.format("Libvirt storage pool [%s] found, but not running, removing from HA list.", uuid)); } removedPools.add(uuid); } - s_logger.debug(String.format("Found NFS storage pool [%s] in libvirt, continuing.", uuid)); + logger.debug(String.format("Found NFS storage pool [%s] in libvirt, continuing.", uuid)); } catch (LibvirtException e) { - s_logger.debug(String.format("Failed to lookup libvirt storage pool [%s].", uuid), e); + logger.debug(String.format("Failed to lookup libvirt storage pool [%s].", uuid), e); if (e.toString().contains("pool not found")) { - s_logger.debug(String.format("Removing pool [%s] from HA monitor since it was deleted.", uuid)); + logger.debug(String.format("Removing pool [%s] from HA monitor since it was deleted.", uuid)); removedPools.add(uuid); } } @@ -164,7 +162,7 @@ public void run() { try { Thread.sleep(_heartBeatUpdateFreq); } catch (InterruptedException e) { - s_logger.debug("[IGNORED] Interrupted between heartbeats.", e); + logger.debug("[IGNORED] Interrupted between heartbeats.", e); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtCapXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtCapXMLParser.java index 358fafae4b5c..a2b422b8bfb6 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtCapXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtCapXMLParser.java @@ -20,7 +20,6 @@ import java.io.StringReader; import java.util.ArrayList; -import org.apache.log4j.Logger; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -34,7 +33,6 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser { private boolean _archTypex8664 = false; private final StringBuffer _emulator = new StringBuffer(); private final StringBuffer _capXML = new StringBuffer(); - private static final Logger s_logger = Logger.getLogger(LibvirtCapXMLParser.class); private final ArrayList guestOsTypes = new ArrayList(); @Override @@ -63,7 +61,7 @@ public void characters(char[] ch, int start, int length) throws SAXException { } else if (_osType) { guestOsTypes.add(new String(ch, start, length)); } else if (_emulatorFlag) { - s_logger.debug("Found " + new String(ch, start, length) + " as a suiteable emulator"); + logger.debug("Found " + new String(ch, start, length) + " as a suiteable emulator"); _emulator.append(ch, start, length); } } @@ -112,9 +110,9 @@ public String parseCapabilitiesXML(String capXML) { _sp.parse(new InputSource(new StringReader(capXML)), this); return _capXML.toString(); } catch (SAXException se) { - s_logger.warn(se.getMessage()); + logger.warn(se.getMessage()); } catch (IOException ie) { - s_logger.error(ie.getMessage()); + logger.error(ie.getMessage()); } return null; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 342bb87cf41f..abd6e24a5326 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -44,6 +44,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.naming.ConfigurationException; import javax.xml.parsers.DocumentBuilder; @@ -76,7 +78,10 @@ import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xerces.impl.xpath.regex.Match; import org.joda.time.Duration; import org.libvirt.Connect; @@ -231,8 +236,8 @@ * pool | the parent of the storage pool hierarchy * } **/ public class LibvirtComputingResource extends ServerResourceBase implements ServerResource, VirtualRouterDeployer, ResourceStatusUpdater { - protected static Logger s_logger = Logger.getLogger(LibvirtComputingResource.class); + protected static Logger LOGGER = LogManager.getLogger(LibvirtComputingResource.class); private static final String CONFIG_VALUES_SEPARATOR = ","; @@ -325,6 +330,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private String createTmplPath; private String heartBeatPath; private String vmActivityCheckPath; + private String nasBackupPath; private String securityGroupPath; private String ovsPvlanDhcpHostPath; private String ovsPvlanVmPath; @@ -444,7 +450,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected WatchDogModel watchDogModel = WatchDogModel.I6300ESB; private final Map pifs = new HashMap(); - private final Map vmStats = new ConcurrentHashMap(); + private final Map vmStats = new ConcurrentHashMap<>(); private final Map vmDiskStats = new ConcurrentHashMap<>(); @@ -515,17 +521,17 @@ public synchronized void registerStatusUpdater(AgentStatusUpdater updater) { try { Connect conn = LibvirtConnection.getConnection(); if (libvirtDomainListener != null) { - s_logger.debug("Clearing old domain listener"); + LOGGER.debug("Clearing old domain listener"); conn.removeLifecycleListener(libvirtDomainListener); } libvirtDomainListener = new LibvirtDomainListener(updater); conn.addLifecycleListener(libvirtDomainListener); - s_logger.debug("Set up the libvirt domain event lifecycle listener"); + LOGGER.debug("Set up the libvirt domain event lifecycle listener"); } catch (LibvirtException e) { - s_logger.error("Failed to get libvirt connection for domain event lifecycle", e); + LOGGER.error("Failed to get libvirt connection for domain event lifecycle", e); } } else { - s_logger.debug("Libvirt event listening is disabled, not registering status updater"); + LOGGER.debug("Libvirt event listening is disabled, not registering status updater"); } } @@ -536,7 +542,7 @@ public ExecutionResult executeInVR(final String routerIp, final String script, f @Override public ExecutionResult executeInVR(final String routerIp, final String script, final String args, final Duration timeout) { - final Script command = new Script(routerProxyPath, timeout, s_logger); + final Script command = new Script(routerProxyPath, timeout, LOGGER); final AllLinesParser parser = new AllLinesParser(); command.add(script); command.add(routerIp); @@ -548,7 +554,7 @@ public ExecutionResult executeInVR(final String routerIp, final String script, f details = parser.getLines(); } - s_logger.debug("Executing script in VR: " + script); + LOGGER.debug("Executing script in VR: " + script); return new ExecutionResult(command.getExitValue() == 0, details); } @@ -558,12 +564,12 @@ public ExecutionResult createFileInVR(final String routerIp, final String path, final File permKey = new File("/root/.ssh/id_rsa.cloud"); boolean success = true; String details = "Creating file in VR, with ip: " + routerIp + ", file: " + filename; - s_logger.debug(details); + LOGGER.debug(details); try { SshHelper.scpTo(routerIp, 3922, "root", permKey, null, path, content.getBytes(), filename, null); } catch (final Exception e) { - s_logger.warn("Failed to create file " + path + filename + " in VR " + routerIp, e); + LOGGER.warn("Failed to create file " + path + filename + " in VR " + routerIp, e); details = e.getMessage(); success = false; } @@ -713,6 +719,10 @@ public String getVmActivityCheckPath() { return vmActivityCheckPath; } + public String getNasBackupPath() { + return nasBackupPath; + } + public String getOvsPvlanDhcpHostPath() { return ovsPvlanDhcpHostPath; } @@ -750,14 +760,14 @@ public String interpret(final BufferedReader reader) throws IOException { while ((line = reader.readLine()) != null) { final String[] toks = line.trim().split("="); if (toks.length < 2) { - s_logger.warn("Failed to parse Script output: " + line); + LOGGER.warn("Failed to parse Script output: " + line); } else { map.put(toks[0].trim(), toks[1].trim()); } numLines++; } if (numLines == 0) { - s_logger.warn("KeyValueInterpreter: no output lines?"); + LOGGER.warn("KeyValueInterpreter: no output lines?"); } return null; } @@ -811,7 +821,7 @@ private Map getDeveloperProperties() throws ConfigurationExcepti throw new ConfigurationException("Unable to find developer.properties."); } - s_logger.info("developer.properties found at " + file.getAbsolutePath()); + LOGGER.info("developer.properties found at " + file.getAbsolutePath()); try { final Properties properties = PropertiesUtil.loadFromFile(file); @@ -884,7 +894,7 @@ public boolean configure(final String name, final Map params) th try { loadUefiProperties(); } catch (FileNotFoundException e) { - s_logger.error("uefi properties file not found due to: " + e.getLocalizedMessage()); + LOGGER.error("uefi properties file not found due to: " + e.getLocalizedMessage()); } storageLayer = new JavaStorageLayer(); @@ -983,6 +993,11 @@ public boolean configure(final String name, final Map params) th throw new ConfigurationException("Unable to find kvmvmactivity.sh"); } + nasBackupPath = Script.findScript(kvmScriptsDir, "nasbackup.sh"); + if (nasBackupPath == null) { + throw new ConfigurationException("Unable to find nasbackup.sh"); + } + createTmplPath = Script.findScript(storageScriptsDir, "createtmplt.sh"); if (createTmplPath == null) { throw new ConfigurationException("Unable to find the createtmplt.sh"); @@ -1015,7 +1030,7 @@ public boolean configure(final String name, final Map params) th hostHealthCheckScriptPath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HEALTH_CHECK_SCRIPT_PATH); if (StringUtils.isNotBlank(hostHealthCheckScriptPath) && !new File(hostHealthCheckScriptPath).exists()) { - s_logger.info(String.format("Unable to find the host health check script at: %s, " + + logger.info(String.format("Unable to find the host health check script at: %s, " + "discarding it", hostHealthCheckScriptPath)); } @@ -1156,7 +1171,7 @@ public boolean configure(final String name, final Map params) th // destroy default network, see https://libvirt.org/sources/java/javadoc/org/libvirt/Network.html try { Network network = conn.networkLookupByName("default"); - s_logger.debug("Found libvirt default network, destroying it and setting autostart to false"); + LOGGER.debug("Found libvirt default network, destroying it and setting autostart to false"); if (network.isActive() == 1) { network.destroy(); } @@ -1164,7 +1179,7 @@ public boolean configure(final String name, final Map params) th network.setAutostart(false); } } catch (final LibvirtException e) { - s_logger.warn("Ignoring libvirt error.", e); + LOGGER.warn("Ignoring libvirt error.", e); } if (HypervisorType.KVM == hypervisorType) { @@ -1182,17 +1197,17 @@ public boolean configure(final String name, final Map params) th hypervisorLibvirtVersion = conn.getLibVirVersion(); hypervisorQemuVersion = conn.getVersion(); } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } // Enable/disable IO driver for Qemu (in case it is not set CloudStack can also detect if its supported by qemu) enableIoUring = isIoUringEnabled(); - s_logger.info("IO uring driver for Qemu: " + (enableIoUring ? "enabled" : "disabled")); + LOGGER.info("IO uring driver for Qemu: " + (enableIoUring ? "enabled" : "disabled")); final String cpuArchOverride = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_ARCH); if (StringUtils.isNotEmpty(cpuArchOverride)) { guestCpuArch = cpuArchOverride; - s_logger.info("Using guest CPU architecture: " + guestCpuArch); + LOGGER.info("Using guest CPU architecture: " + guestCpuArch); } guestCpuMode = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_MODE); @@ -1200,7 +1215,7 @@ public boolean configure(final String name, final Map params) th guestCpuModel = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_MODEL); if (hypervisorLibvirtVersion < 9 * 1000 + 10) { - s_logger.warn("Libvirt version 0.9.10 required for guest cpu mode, but version " + prettyVersion(hypervisorLibvirtVersion) + + LOGGER.warn("Libvirt version 0.9.10 required for guest cpu mode, but version " + prettyVersion(hypervisorLibvirtVersion) + " detected, so it will be disabled"); guestCpuMode = ""; guestCpuModel = ""; @@ -1251,21 +1266,21 @@ public boolean configure(final String name, final Map params) th */ if (pifs.get("private") == null) { - s_logger.error("Failed to get private nic name"); + LOGGER.error("Failed to get private nic name"); throw new ConfigurationException("Failed to get private nic name"); } if (pifs.get("public") == null) { - s_logger.error("Failed to get public nic name"); + LOGGER.error("Failed to get public nic name"); throw new ConfigurationException("Failed to get public nic name"); } - s_logger.debug("Found pif: " + pifs.get("private") + " on " + privBridgeName + ", pif: " + pifs.get("public") + " on " + publicBridgeName); + LOGGER.debug("Found pif: " + pifs.get("private") + " on " + privBridgeName + ", pif: " + pifs.get("public") + " on " + publicBridgeName); canBridgeFirewall = canBridgeFirewall(pifs.get("public")); localGateway = Script.runSimpleBashScript("ip route show default 0.0.0.0/0|head -1|awk '{print $3}'"); if (localGateway == null) { - s_logger.warn("No default IPv4 gateway found"); + LOGGER.warn("No default IPv4 gateway found"); } migrateDowntime = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_DOWNTIME); @@ -1287,9 +1302,9 @@ public boolean configure(final String name, final Map params) th try { migrateSpeed = Integer.parseInt(tokens[0]); } catch (final NumberFormatException e) { - s_logger.trace("Ignoring migrateSpeed extraction error.", e); + LOGGER.trace("Ignoring migrateSpeed extraction error.", e); } - s_logger.debug("device " + pifs.get("public") + " has speed: " + String.valueOf(migrateSpeed)); + LOGGER.debug("device " + pifs.get("public") + " has speed: " + String.valueOf(migrateSpeed)); } } params.put("vm.migrate.speed", String.valueOf(migrateSpeed)); @@ -1315,7 +1330,7 @@ public boolean configure(final String name, final Map params) th final Thread cleanupMonitor = new Thread(isciCleanupMonitor); cleanupMonitor.start(); } else { - s_logger.info("iscsi session clean up is disabled"); + LOGGER.info("iscsi session clean up is disabled"); } setupMemoryBalloonStatsPeriod(conn); @@ -1334,14 +1349,14 @@ protected List getVmsToSetMemoryBalloonStatsPeriod(Connect conn) { try { vmIds = ArrayUtils.toObject(conn.listDomains()); } catch (final LibvirtException e) { - s_logger.error("Unable to get the list of Libvirt domains on this host.", e); + LOGGER.error("Unable to get the list of Libvirt domains on this host.", e); return vmIdList; } vmIdList.addAll(Arrays.asList(vmIds)); - s_logger.debug(String.format("We have found a total of [%s] VMs (Libvirt domains) on this host: [%s].", vmIdList.size(), vmIdList.toString())); + LOGGER.debug(String.format("We have found a total of [%s] VMs (Libvirt domains) on this host: [%s].", vmIdList.size(), vmIdList.toString())); if (vmIdList.isEmpty()) { - s_logger.info("Skipping the memory balloon stats period setting, since there are no VMs (active Libvirt domains) on this host."); + LOGGER.info("Skipping the memory balloon stats period setting, since there are no VMs (active Libvirt domains) on this host."); } return vmIdList; } @@ -1352,13 +1367,13 @@ protected List getVmsToSetMemoryBalloonStatsPeriod(Connect conn) { */ protected Integer getCurrentVmBalloonStatsPeriod() { if (Boolean.TRUE.equals(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MEMBALLOON_DISABLE))) { - s_logger.info(String.format("The [%s] property is set to 'true', so the memory balloon stats period will be set to 0 for all VMs.", + LOGGER.info(String.format("The [%s] property is set to 'true', so the memory balloon stats period will be set to 0 for all VMs.", AgentProperties.VM_MEMBALLOON_DISABLE.getName())); return 0; } Integer vmBalloonStatsPeriod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MEMBALLOON_STATS_PERIOD); if (vmBalloonStatsPeriod == 0) { - s_logger.info(String.format("The [%s] property is set to '0', this prevents memory statistics from being displayed correctly. " + LOGGER.info(String.format("The [%s] property is set to '0', this prevents memory statistics from being displayed correctly. " + "Adjust (increase) the value of this parameter to correct this.", AgentProperties.VM_MEMBALLOON_STATS_PERIOD.getName())); } return vmBalloonStatsPeriod; @@ -1378,20 +1393,20 @@ protected void setupMemoryBalloonStatsPeriod(Connect conn) { parser.parseDomainXML(dm.getXMLDesc(0)); MemBalloonDef memBalloon = parser.getMemBalloon(); if (!MemBalloonDef.MemBalloonModel.VIRTIO.equals(memBalloon.getMemBalloonModel())) { - s_logger.debug(String.format("Skipping the memory balloon stats period setting for the VM (Libvirt Domain) with ID [%s] and name [%s] because this VM has no memory" + LOGGER.debug(String.format("Skipping the memory balloon stats period setting for the VM (Libvirt Domain) with ID [%s] and name [%s] because this VM has no memory" + " balloon.", vmId, dm.getName())); } String setMemBalloonStatsPeriodCommand = String.format(COMMAND_SET_MEM_BALLOON_STATS_PERIOD, vmId, currentVmBalloonStatsPeriod); String setMemBalloonStatsPeriodResult = Script.runSimpleBashScript(setMemBalloonStatsPeriodCommand); if (StringUtils.isNotBlank(setMemBalloonStatsPeriodResult)) { - s_logger.error(String.format("Unable to set up memory balloon stats period for VM (Libvirt Domain) with ID [%s] due to an error when running the [%s] " + LOGGER.error(String.format("Unable to set up memory balloon stats period for VM (Libvirt Domain) with ID [%s] due to an error when running the [%s] " + "command. Output: [%s].", vmId, setMemBalloonStatsPeriodCommand, setMemBalloonStatsPeriodResult)); continue; } - s_logger.debug(String.format("The memory balloon stats period [%s] has been set successfully for the VM (Libvirt Domain) with ID [%s] and name [%s].", + LOGGER.debug(String.format("The memory balloon stats period [%s] has been set successfully for the VM (Libvirt Domain) with ID [%s] and name [%s].", currentVmBalloonStatsPeriod, vmId, dm.getName())); } catch (final Exception e) { - s_logger.warn(String.format("Failed to set up memory balloon stats period for the VM %s with exception %s", parser.getName(), e.getMessage())); + LOGGER.warn(String.format("Failed to set up memory balloon stats period for the VM %s with exception %s", parser.getName(), e.getMessage())); } } } @@ -1399,12 +1414,12 @@ protected void setupMemoryBalloonStatsPeriod(Connect conn) { private void enableSSLForKvmAgent() { final File keyStoreFile = PropertiesUtil.findConfigFile(KeyStoreUtils.KS_FILENAME); if (keyStoreFile == null) { - s_logger.info("Failed to find keystore file: " + KeyStoreUtils.KS_FILENAME); + LOGGER.info("Failed to find keystore file: " + KeyStoreUtils.KS_FILENAME); return; } String keystorePass = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.KEYSTORE_PASSPHRASE); if (StringUtils.isBlank(keystorePass)) { - s_logger.info("Failed to find passphrase for keystore: " + KeyStoreUtils.KS_FILENAME); + LOGGER.info("Failed to find passphrase for keystore: " + KeyStoreUtils.KS_FILENAME); return; } if (keyStoreFile.exists() && !keyStoreFile.isDirectory()) { @@ -1415,20 +1430,20 @@ private void enableSSLForKvmAgent() { protected void configureLocalStorage() throws ConfigurationException { String localStoragePath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_PATH); - s_logger.debug(String.format("Local Storage Path set: [%s].", localStoragePath)); + LOGGER.debug(String.format("Local Storage Path set: [%s].", localStoragePath)); String localStorageUUIDString = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_UUID); if (localStorageUUIDString == null) { localStorageUUIDString = UUID.randomUUID().toString(); } - s_logger.debug(String.format("Local Storage UUID set: [%s].", localStorageUUIDString)); + LOGGER.debug(String.format("Local Storage UUID set: [%s].", localStorageUUIDString)); String[] localStorageRelativePaths = localStoragePath.split(CONFIG_VALUES_SEPARATOR); String[] localStorageUUIDStrings = localStorageUUIDString.split(CONFIG_VALUES_SEPARATOR); if (localStorageRelativePaths.length != localStorageUUIDStrings.length) { String errorMessage = String.format("The path and UUID of the local storage pools have different length. Path: [%s], UUID: [%s].", localStoragePath, localStorageUUIDString); - s_logger.error(errorMessage); + LOGGER.error(errorMessage); throw new ConfigurationException(errorMessage); } for (String localStorageRelativePath : localStorageRelativePaths) { @@ -1456,7 +1471,7 @@ private void validateLocalStorageUUID(String localStorageUUID) throws Configurat public boolean configureHostParams(final Map params) { final File file = PropertiesUtil.findConfigFile("agent.properties"); if (file == null) { - s_logger.error("Unable to find the file agent.properties"); + LOGGER.error("Unable to find the file agent.properties"); return false; } // Save configurations in agent.properties @@ -1483,25 +1498,25 @@ public boolean configureHostParams(final Map params) { private void configureAgentHooks() { agentHooksBasedir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_BASEDIR); - s_logger.debug("agent.hooks.basedir is " + agentHooksBasedir); + LOGGER.debug("agent.hooks.basedir is " + agentHooksBasedir); agentHooksLibvirtXmlScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_SCRIPT); - s_logger.debug("agent.hooks.libvirt_vm_xml_transformer.script is " + agentHooksLibvirtXmlScript); + LOGGER.debug("agent.hooks.libvirt_vm_xml_transformer.script is " + agentHooksLibvirtXmlScript); agentHooksLibvirtXmlMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_METHOD); - s_logger.debug("agent.hooks.libvirt_vm_xml_transformer.method is " + agentHooksLibvirtXmlMethod); + LOGGER.debug("agent.hooks.libvirt_vm_xml_transformer.method is " + agentHooksLibvirtXmlMethod); agentHooksVmOnStartScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_START_SCRIPT); - s_logger.debug("agent.hooks.libvirt_vm_on_start.script is " + agentHooksVmOnStartScript); + LOGGER.debug("agent.hooks.libvirt_vm_on_start.script is " + agentHooksVmOnStartScript); agentHooksVmOnStartMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_START_METHOD); - s_logger.debug("agent.hooks.libvirt_vm_on_start.method is " + agentHooksVmOnStartMethod); + LOGGER.debug("agent.hooks.libvirt_vm_on_start.method is " + agentHooksVmOnStartMethod); agentHooksVmOnStopScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_STOP_SCRIPT); - s_logger.debug("agent.hooks.libvirt_vm_on_stop.script is " + agentHooksVmOnStopScript); + LOGGER.debug("agent.hooks.libvirt_vm_on_stop.script is " + agentHooksVmOnStopScript); agentHooksVmOnStopMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_STOP_METHOD); - s_logger.debug("agent.hooks.libvirt_vm_on_stop.method is " + agentHooksVmOnStopMethod); + LOGGER.debug("agent.hooks.libvirt_vm_on_stop.method is " + agentHooksVmOnStopMethod); } public boolean isUefiPropertiesFileLoaded() { @@ -1518,14 +1533,14 @@ private void loadUefiProperties() throws FileNotFoundException { throw new FileNotFoundException("Unable to find file uefi.properties."); } - s_logger.info("uefi.properties file found at " + file.getAbsolutePath()); + LOGGER.info("uefi.properties file found at " + file.getAbsolutePath()); try { PropertiesUtil.loadFromFile(uefiProperties, file); - s_logger.info("guest.nvram.template.legacy = " + uefiProperties.getProperty("guest.nvram.template.legacy")); - s_logger.info("guest.loader.legacy = " + uefiProperties.getProperty("guest.loader.legacy")); - s_logger.info("guest.nvram.template.secure = " + uefiProperties.getProperty("guest.nvram.template.secure")); - s_logger.info("guest.loader.secure =" + uefiProperties.getProperty("guest.loader.secure")); - s_logger.info("guest.nvram.path = " + uefiProperties.getProperty("guest.nvram.path")); + LOGGER.info("guest.nvram.template.legacy = " + uefiProperties.getProperty("guest.nvram.template.legacy")); + LOGGER.info("guest.loader.legacy = " + uefiProperties.getProperty("guest.loader.legacy")); + LOGGER.info("guest.nvram.template.secure = " + uefiProperties.getProperty("guest.nvram.template.secure")); + LOGGER.info("guest.loader.secure =" + uefiProperties.getProperty("guest.loader.secure")); + LOGGER.info("guest.nvram.path = " + uefiProperties.getProperty("guest.nvram.path")); } catch (final FileNotFoundException ex) { throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex); } catch (final IOException ex) { @@ -1556,10 +1571,10 @@ protected void configureVifDrivers(final Map params) throws Conf String defaultVifDriverName = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_VIF_DRIVER); if (defaultVifDriverName == null) { if (bridgeType == BridgeType.OPENVSWITCH) { - s_logger.info("No libvirt.vif.driver specified. Defaults to OvsVifDriver."); + LOGGER.info("No libvirt.vif.driver specified. Defaults to OvsVifDriver."); defaultVifDriverName = DEFAULT_OVS_VIF_DRIVER_CLASS_NAME; } else { - s_logger.info("No libvirt.vif.driver specified. Defaults to BridgeVifDriver."); + LOGGER.info("No libvirt.vif.driver specified. Defaults to BridgeVifDriver."); defaultVifDriverName = DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME; } } @@ -1655,15 +1670,15 @@ private void getPifs() { for (int i = 0; i < netdevs.length; i++) { final File isbridge = new File(netdevs[i].getAbsolutePath() + "/bridge"); final String netdevName = netdevs[i].getName(); - s_logger.debug("looking in file " + netdevs[i].getAbsolutePath() + "/bridge"); + LOGGER.debug("looking in file " + netdevs[i].getAbsolutePath() + "/bridge"); if (isbridge.exists()) { - s_logger.debug("Found bridge " + netdevName); + LOGGER.debug("Found bridge " + netdevName); bridges.add(netdevName); } } for (final String bridge : bridges) { - s_logger.debug("looking for pif for bridge " + bridge); + LOGGER.debug("looking for pif for bridge " + bridge); final String pif = getPif(bridge); if (isPublicBridge(bridge)) { pifs.put("public", pif); @@ -1677,10 +1692,10 @@ private void getPifs() { // guest(private) creates bridges on a pif, if private bridge not found try pif direct // This addresses the unnecessary requirement of someone to create an unused bridge just for traffic label if (pifs.get("private") == null) { - s_logger.debug("guest(private) traffic label '" + guestBridgeName + "' not found as bridge, looking for physical interface"); + LOGGER.debug("guest(private) traffic label '" + guestBridgeName + "' not found as bridge, looking for physical interface"); final File dev = new File("/sys/class/net/" + guestBridgeName); if (dev.exists()) { - s_logger.debug("guest(private) traffic label '" + guestBridgeName + "' found as a physical device"); + LOGGER.debug("guest(private) traffic label '" + guestBridgeName + "' found as a physical device"); pifs.put("private", guestBridgeName); } } @@ -1688,15 +1703,15 @@ private void getPifs() { // public creates bridges on a pif, if private bridge not found try pif direct // This addresses the unnecessary requirement of someone to create an unused bridge just for traffic label if (pifs.get("public") == null) { - s_logger.debug("public traffic label '" + publicBridgeName + "' not found as bridge, looking for physical interface"); + LOGGER.debug("public traffic label '" + publicBridgeName + "' not found as bridge, looking for physical interface"); final File dev = new File("/sys/class/net/" + publicBridgeName); if (dev.exists()) { - s_logger.debug("public traffic label '" + publicBridgeName + "' found as a physical device"); + LOGGER.debug("public traffic label '" + publicBridgeName + "' found as a physical device"); pifs.put("public", publicBridgeName); } } - s_logger.debug("done looking for pifs, no more bridges"); + LOGGER.debug("done looking for pifs, no more bridges"); } boolean isGuestBridge(String bridge) { @@ -1705,10 +1720,10 @@ boolean isGuestBridge(String bridge) { private void getOvsPifs() { final String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'"); - s_logger.debug("cmdout was " + cmdout); + LOGGER.debug("cmdout was " + cmdout); final List bridges = Arrays.asList(cmdout.split("%")); for (final String bridge : bridges) { - s_logger.debug("looking for pif for bridge " + bridge); + LOGGER.debug("looking for pif for bridge " + bridge); // String pif = getOvsPif(bridge); // Not really interested in the pif name at this point for ovs // bridges @@ -1721,7 +1736,7 @@ private void getOvsPifs() { } pifs.put(bridge, pif); } - s_logger.debug("done looking for pifs, no more bridges"); + LOGGER.debug("done looking for pifs, no more bridges"); } public boolean isPublicBridge(String bridge) { @@ -1748,7 +1763,7 @@ private String matchPifFileInDirectory(final String bridgeName) { // if bridgeName already refers to a pif, return it as-is return bridgeName; } - s_logger.debug("failing to get physical interface from bridge " + bridgeName + ", does " + brif.getAbsolutePath() + "exist?"); + LOGGER.debug("failing to get physical interface from bridge " + bridgeName + ", does " + brif.getAbsolutePath() + "exist?"); return ""; } @@ -1756,13 +1771,13 @@ private String matchPifFileInDirectory(final String bridgeName) { for (int i = 0; i < interfaces.length; i++) { final String fname = interfaces[i].getName(); - s_logger.debug("matchPifFileInDirectory: file name '" + fname + "'"); + LOGGER.debug("matchPifFileInDirectory: file name '" + fname + "'"); if (isInterface(fname)) { return fname; } } - s_logger.debug("failing to get physical interface from bridge " + bridgeName + ", did not find an eth*, bond*, team*, vlan*, em*, p*p*, ens*, eno*, enp*, or enx* in " + brif.getAbsolutePath()); + LOGGER.debug("failing to get physical interface from bridge " + bridgeName + ", did not find an eth*, bond*, team*, vlan*, em*, p*p*, ens*, eno*, enp*, or enx* in " + brif.getAbsolutePath()); return ""; } @@ -1825,7 +1840,7 @@ private boolean checkBridgeNetwork(final String networkName) { } private boolean checkOvsNetwork(final String networkName) { - s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge"); + LOGGER.debug("Checking if network " + networkName + " exists as openvswitch bridge"); if (networkName == null) { return true; } @@ -1837,13 +1852,13 @@ private boolean checkOvsNetwork(final String networkName) { } public boolean passCmdLine(final String vmName, final String cmdLine) throws InternalErrorException { - final Script command = new Script(patchScriptPath, 300000, s_logger); + final Script command = new Script(patchScriptPath, 300000, LOGGER); String result; command.add("-n", vmName); command.add("-c", cmdLine); result = command.execute(); if (result != null) { - s_logger.error("Passing cmdline failed:" + result); + LOGGER.error("Passing cmdline failed:" + result); return false; } return true; @@ -1902,12 +1917,12 @@ public boolean stop() { try { final Connect conn = LibvirtConnection.getConnection(); if (AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_EVENTS_ENABLED) && libvirtDomainListener != null) { - s_logger.debug("Clearing old domain listener"); + LOGGER.debug("Clearing old domain listener"); conn.removeLifecycleListener(libvirtDomainListener); } conn.close(); } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } return true; @@ -1935,14 +1950,14 @@ public Answer executeRequest(final Command cmd) { public synchronized boolean destroyTunnelNetwork(final String bridge) { findOrCreateTunnelNetwork(bridge); - final Script cmd = new Script(ovsTunnelPath, timeout, s_logger); + final Script cmd = new Script(ovsTunnelPath, timeout, LOGGER); cmd.add("destroy_ovs_bridge"); cmd.add("--bridge", bridge); final String result = cmd.execute(); if (result != null) { - s_logger.debug("OVS Bridge could not be destroyed due to error ==> " + result); + LOGGER.debug("OVS Bridge could not be destroyed due to error ==> " + result); return false; } return true; @@ -1959,9 +1974,9 @@ public synchronized boolean findOrCreateTunnelNetwork(final String nwName) { Script.runSimpleBashScript("ovs-vsctl -- --may-exist add-br " + nwName + " -- set bridge " + nwName + " other_config:ovs-host-setup='-1'"); - s_logger.debug("### KVM network for tunnels created:" + nwName); + LOGGER.debug("### KVM network for tunnels created:" + nwName); } catch (final Exception e) { - s_logger.warn("createTunnelNetwork failed", e); + LOGGER.warn("createTunnelNetwork failed", e); return false; } return true; @@ -1972,7 +1987,7 @@ public synchronized boolean configureTunnelNetwork(final Long networkId, try { final boolean findResult = findOrCreateTunnelNetwork(nwName); if (!findResult) { - s_logger.warn("LibvirtComputingResource.findOrCreateTunnelNetwork() failed! Cannot proceed creating the tunnel."); + LOGGER.warn("LibvirtComputingResource.findOrCreateTunnelNetwork() failed! Cannot proceed creating the tunnel."); return false; } final String configuredHosts = Script @@ -1989,7 +2004,7 @@ public synchronized boolean configureTunnelNetwork(final Long networkId, } } if (!configured) { - final Script cmd = new Script(ovsTunnelPath, timeout, s_logger); + final Script cmd = new Script(ovsTunnelPath, timeout, LOGGER); cmd.add("setup_ovs_bridge"); cmd.add("--key", nwName); cmd.add("--cs_host_id", ((Long)hostId).toString()); @@ -2002,7 +2017,7 @@ public synchronized boolean configureTunnelNetwork(final Long networkId, } } } catch (final Exception e) { - s_logger.warn("createandConfigureTunnelNetwork failed", e); + LOGGER.warn("createandConfigureTunnelNetwork failed", e); return false; } return true; @@ -2030,7 +2045,7 @@ public KVMPhysicalDisk templateToPrimaryDownload(final String templateUrl, final secondaryPool.refresh(); final List disks = secondaryPool.listPhysicalDisks(); if (disks == null || disks.isEmpty()) { - s_logger.error("Failed to get volumes from pool: " + secondaryPool.getUuid()); + LOGGER.error("Failed to get volumes from pool: " + secondaryPool.getUuid()); return null; } for (final KVMPhysicalDisk disk : disks) { @@ -2040,7 +2055,7 @@ public KVMPhysicalDisk templateToPrimaryDownload(final String templateUrl, final } } if (templateVol == null) { - s_logger.error("Failed to get template from pool: " + secondaryPool.getUuid()); + LOGGER.error("Failed to get template from pool: " + secondaryPool.getUuid()); return null; } } else { @@ -2052,7 +2067,7 @@ public KVMPhysicalDisk templateToPrimaryDownload(final String templateUrl, final final KVMPhysicalDisk primaryVol = storagePoolManager.copyPhysicalDisk(templateVol, volUuid, primaryPool, 0); return primaryVol; } catch (final CloudRuntimeException e) { - s_logger.error("Failed to download template to primary storage", e); + LOGGER.error("Failed to download template to primary storage", e); return null; } finally { if (secondaryPool != null) { @@ -2083,7 +2098,7 @@ private String getBroadcastUriFromBridge(final String brName) { final String pif = matchPifFileInDirectory(brName); final Pattern pattern = Pattern.compile("(\\D+)(\\d+)(\\D*)(\\d*)(\\D*)(\\d*)"); final Matcher matcher = pattern.matcher(pif); - s_logger.debug("getting broadcast uri for pif " + pif + " and bridge " + brName); + LOGGER.debug("getting broadcast uri for pif " + pif + " and bridge " + brName); if(matcher.find()) { if (brName.startsWith("brvx")){ return BroadcastDomainType.Vxlan.toUri(matcher.group(2)).toString(); @@ -2095,13 +2110,13 @@ private String getBroadcastUriFromBridge(final String brName) { return BroadcastDomainType.Vlan.toUri(matcher.group(4)).toString(); } else { //untagged or not matching (eth|bond|team)#.# - s_logger.debug("failed to get vNet id from bridge " + brName + LOGGER.debug("failed to get vNet id from bridge " + brName + "attached to physical interface" + pif + ", perhaps untagged interface"); return ""; } } } else { - s_logger.debug("failed to get vNet id from bridge " + brName + "attached to physical interface" + pif); + LOGGER.debug("failed to get vNet id from bridge " + brName + "attached to physical interface" + pif); return ""; } } @@ -2164,7 +2179,7 @@ private ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkComm return new ExecutionResult(true, null); } catch (final LibvirtException e) { final String msg = "Creating guest network failed due to " + e.toString(); - s_logger.warn(msg, e); + LOGGER.warn(msg, e); return new ExecutionResult(false, msg); } } @@ -2203,7 +2218,7 @@ protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand return new ExecutionResult(true, "success"); } catch (final LibvirtException e) { final String msg = "Ip SNAT failure due to " + e.toString(); - s_logger.error(msg, e); + LOGGER.error(msg, e); return new ExecutionResult(false, msg); } } @@ -2225,7 +2240,7 @@ protected ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand c return new ExecutionResult(true, null); } catch (final LibvirtException e) { - s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e); + LOGGER.error("Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.getMessage()); } } @@ -2258,10 +2273,10 @@ public ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) { } return new ExecutionResult(true, null); } catch (final LibvirtException e) { - s_logger.error("ipassoccmd failed", e); + LOGGER.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } catch (final InternalErrorException e) { - s_logger.error("ipassoccmd failed", e); + LOGGER.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } } @@ -2298,10 +2313,10 @@ protected ExecutionResult cleanupNetworkElementCommand(final IpAssocCommand cmd) } } catch (final LibvirtException e) { - s_logger.error("ipassoccmd failed", e); + LOGGER.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } catch (final InternalErrorException e) { - s_logger.error("ipassoccmd failed", e); + LOGGER.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } @@ -2335,14 +2350,14 @@ public PowerState getVmState(final Connect conn, final String vmName) { final PowerState s = convertToPowerState(vms.getInfo().state); return s; } catch (final LibvirtException e) { - s_logger.warn("Can't get vm state " + vmName + e.getMessage() + "retry:" + retry); + LOGGER.error("Could not get state for VM [{}] (retry={}) due to:", vmName, retry, e); } finally { try { if (vms != null) { vms.free(); } } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } } @@ -2354,7 +2369,7 @@ public String networkUsage(final String privateIpAddress, final String option, f } public String networkUsage(final String privateIpAddress, final String option, final String vif, String publicIp) { - final Script getUsage = new Script(routerProxyPath, s_logger); + final Script getUsage = new Script(routerProxyPath, LOGGER); getUsage.add("netusage.sh"); getUsage.add(privateIpAddress); if (option.equals("get")) { @@ -2375,7 +2390,7 @@ public String networkUsage(final String privateIpAddress, final String option, f final OutputInterpreter.OneLineParser usageParser = new OutputInterpreter.OneLineParser(); final String result = getUsage.execute(usageParser); if (result != null) { - s_logger.debug("Failed to execute networkUsage:" + result); + LOGGER.debug("Failed to execute networkUsage:" + result); return null; } return usageParser.getLine(); @@ -2400,7 +2415,7 @@ public long[] getNetworkStats(final String privateIP, String publicIp) { } public String getHaproxyStats(final String privateIP, final String publicIp, final Integer port) { - final Script getHaproxyStatsScript = new Script(routerProxyPath, s_logger); + final Script getHaproxyStatsScript = new Script(routerProxyPath, LOGGER); getHaproxyStatsScript.add("get_haproxy_stats.sh"); getHaproxyStatsScript.add(privateIP); getHaproxyStatsScript.add(publicIp); @@ -2409,7 +2424,7 @@ public String getHaproxyStats(final String privateIP, final String publicIp, fin final OutputInterpreter.OneLineParser statsParser = new OutputInterpreter.OneLineParser(); final String result = getHaproxyStatsScript.execute(statsParser); if (result != null) { - s_logger.debug("Failed to execute haproxy stats:" + result); + LOGGER.debug("Failed to execute haproxy stats:" + result); return null; } return statsParser.getLine(); @@ -2426,7 +2441,7 @@ public long[] getNetworkLbStats(final String privateIp, final String publicIp, f } public String configureVPCNetworkUsage(final String privateIpAddress, final String publicIp, final String option, final String vpcCIDR) { - final Script getUsage = new Script(routerProxyPath, s_logger); + final Script getUsage = new Script(routerProxyPath, LOGGER); getUsage.add("vpc_netusage.sh"); getUsage.add(privateIpAddress); getUsage.add("-l", publicIp); @@ -2447,7 +2462,7 @@ public String configureVPCNetworkUsage(final String privateIpAddress, final Stri final OutputInterpreter.OneLineParser usageParser = new OutputInterpreter.OneLineParser(); final String result = getUsage.execute(usageParser); if (result != null) { - s_logger.debug("Failed to execute VPCNetworkUsage:" + result); + LOGGER.debug("Failed to execute VPCNetworkUsage:" + result); return null; } return usageParser.getLine(); @@ -2499,19 +2514,19 @@ protected void setQuotaAndPeriod(VirtualMachineTO vmTO, CpuTuneDef ctd) { int period = CpuTuneDef.DEFAULT_PERIOD; int quota = (int) (period * cpuQuotaPercentage); if (quota < CpuTuneDef.MIN_QUOTA) { - s_logger.info("Calculated quota (" + quota + ") below the minimum (" + CpuTuneDef.MIN_QUOTA + ") for VM domain " + vmTO.getUuid() + ", setting it to minimum " + + LOGGER.info("Calculated quota (" + quota + ") below the minimum (" + CpuTuneDef.MIN_QUOTA + ") for VM domain " + vmTO.getUuid() + ", setting it to minimum " + "and calculating period instead of using the default"); quota = CpuTuneDef.MIN_QUOTA; period = (int) ((double) quota / cpuQuotaPercentage); if (period > CpuTuneDef.MAX_PERIOD) { - s_logger.info("Calculated period (" + period + ") exceeds the maximum (" + CpuTuneDef.MAX_PERIOD + + LOGGER.info("Calculated period (" + period + ") exceeds the maximum (" + CpuTuneDef.MAX_PERIOD + "), setting it to the maximum"); period = CpuTuneDef.MAX_PERIOD; } } ctd.setQuota(quota); ctd.setPeriod(period); - s_logger.info("Setting quota=" + quota + ", period=" + period + " to VM domain " + vmTO.getUuid()); + LOGGER.info("Setting quota=" + quota + ", period=" + period + " to VM domain " + vmTO.getUuid()); } } @@ -2524,7 +2539,7 @@ protected void enlightenWindowsVm(VirtualMachineTO vmTO, FeaturesDef features) { hyv.setFeature("spinlocks", true); hyv.setRetries(8096); features.addHyperVFeature(hyv); - s_logger.info("Enabling KVM Enlightment Features to VM domain " + vmTO.getUuid()); + LOGGER.info("Enabling KVM Enlightment Features to VM domain " + vmTO.getUuid()); } } @@ -2532,7 +2547,7 @@ protected void enlightenWindowsVm(VirtualMachineTO vmTO, FeaturesDef features) { * Creates VM KVM definitions from virtual machine transfer object specifications. */ public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) { - s_logger.debug(String.format("Creating VM from specifications [%s]", vmTO.toString())); + LOGGER.debug(String.format("Creating VM from specifications [%s]", vmTO.toString())); LibvirtVMDef vm = new LibvirtVMDef(); vm.setDomainName(vmTO.getName()); @@ -2549,10 +2564,10 @@ public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) { if (MapUtils.isNotEmpty(customParams) && customParams.containsKey(GuestDef.BootType.UEFI.toString())) { isUefiEnabled = true; - s_logger.debug(String.format("Enabled UEFI for VM UUID [%s].", uuid)); + LOGGER.debug(String.format("Enabled UEFI for VM UUID [%s].", uuid)); if (isSecureMode(customParams.get(GuestDef.BootType.UEFI.toString()))) { - s_logger.debug(String.format("Enabled Secure Boot for VM UUID [%s].", uuid)); + LOGGER.debug(String.format("Enabled Secure Boot for VM UUID [%s].", uuid)); isSecureBoot = true; } @@ -2561,7 +2576,7 @@ public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) { Map extraConfig = vmTO.getExtraConfig(); if (dpdkSupport && (!extraConfig.containsKey(DpdkHelper.DPDK_NUMA) || !extraConfig.containsKey(DpdkHelper.DPDK_HUGE_PAGES))) { - s_logger.info(String.format("DPDK is enabled for VM [%s], but it needs extra configurations for CPU NUMA and Huge Pages for VM deployment.", vmTO.toString())); + LOGGER.info(String.format("DPDK is enabled for VM [%s], but it needs extra configurations for CPU NUMA and Huge Pages for VM deployment.", vmTO.toString())); } configureVM(vmTO, vm, customParams, isUefiEnabled, isSecureBoot, bootMode, extraConfig, uuid); return vm; @@ -2572,7 +2587,7 @@ public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) { */ private void configureVM(VirtualMachineTO vmTO, LibvirtVMDef vm, Map customParams, boolean isUefiEnabled, boolean isSecureBoot, String bootMode, Map extraConfig, String uuid) { - s_logger.debug(String.format("Configuring VM with UUID [%s].", uuid)); + LOGGER.debug(String.format("Configuring VM with UUID [%s].", uuid)); GuestDef guest = createGuestFromSpec(vmTO, vm, uuid, customParams); if (isUefiEnabled) { @@ -2607,7 +2622,7 @@ private void configureVM(VirtualMachineTO vmTO, LibvirtVMDef vm, Map extraConfig) { if (MapUtils.isNotEmpty(extraConfig) && VirtualMachine.Type.User.equals(vmTO.getType())) { - s_logger.debug(String.format("Appending extra configuration data [%s] to guest VM [%s] domain XML.", extraConfig, vmTO.toString())); + LOGGER.debug(String.format("Appending extra configuration data [%s] to guest VM [%s] domain XML.", extraConfig, vmTO.toString())); addExtraConfigComponent(extraConfig, vm); } } @@ -2780,11 +2795,11 @@ public int calculateCpuShares(VirtualMachineTO vmTO) { if (hostCpuMaxCapacity > 0) { int updatedCpuShares = (int) Math.ceil((requestedCpuShares * CGROUP_V2_UPPER_LIMIT) / (double) hostCpuMaxCapacity); - s_logger.debug(String.format("This host utilizes cgroupv2 (as the max shares value is [%s]), thus, the VM requested shares of [%s] will be converted to " + + logger.debug(String.format("This host utilizes cgroupv2 (as the max shares value is [%s]), thus, the VM requested shares of [%s] will be converted to " + "consider the host limits; the new CPU shares value is [%s].", hostCpuMaxCapacity, requestedCpuShares, updatedCpuShares)); return updatedCpuShares; } - s_logger.debug(String.format("This host does not have a maximum CPU shares set; therefore, this host utilizes cgroupv1 and the VM requested CPU shares [%s] will not be " + + logger.debug(String.format("This host does not have a maximum CPU shares set; therefore, this host utilizes cgroupv1 and the VM requested CPU shares [%s] will not be " + "converted.", requestedCpuShares)); return requestedCpuShares; } @@ -2837,6 +2852,8 @@ protected GuestDef createGuestFromSpec(VirtualMachineTO vmTO, LibvirtVMDef vm, S GuestDef guest = new GuestDef(); configureGuestAndVMHypervisorType(vmTO, vm, guest); + guest.setManufacturer(vmTO.getMetadataManufacturer()); + guest.setProduct(vmTO.getMetadataProductName()); guest.setGuestArch(guestCpuArch != null ? guestCpuArch : vmTO.getArch()); guest.setMachineType(isGuestAarch64() ? VIRT : PC); guest.setBootType(GuestDef.BootType.BIOS); @@ -2908,12 +2925,12 @@ protected GuestResourceDef createGuestResourceDef(VirtualMachineTO vmTO){ protected long getCurrentMemAccordingToMemBallooning(VirtualMachineTO vmTO, long maxRam) { long retVal = maxRam; if (noMemBalloon) { - s_logger.warn(String.format("Setting VM's [%s] current memory as max memory [%s] due to memory ballooning is disabled. If you are using a custom service offering, verify if memory ballooning really should be disabled.", vmTO.toString(), maxRam)); + LOGGER.warn(String.format("Setting VM's [%s] current memory as max memory [%s] due to memory ballooning is disabled. If you are using a custom service offering, verify if memory ballooning really should be disabled.", vmTO.toString(), maxRam)); } else if (vmTO != null && vmTO.getType() != VirtualMachine.Type.User) { - s_logger.warn(String.format("Setting System VM's [%s] current memory as max memory [%s].", vmTO.toString(), maxRam)); + LOGGER.warn(String.format("Setting System VM's [%s] current memory as max memory [%s].", vmTO.toString(), maxRam)); } else { long minRam = ByteScaleUtils.bytesToKibibytes(vmTO.getMinRam()); - s_logger.debug(String.format("Setting VM's [%s] current memory as min memory [%s] due to memory ballooning is enabled.", vmTO.toString(), minRam)); + logger.debug(String.format("Setting VM's [%s] current memory as min memory [%s] due to memory ballooning is enabled.", vmTO.toString(), minRam)); retVal = minRam; } return retVal; @@ -3054,13 +3071,13 @@ public int compare(final DiskTO arg0, final DiskTO arg1) { // check for disk activity, if detected we should exit because vm is running elsewhere if (diskActivityCheckEnabled && physicalDisk != null && physicalDisk.getFormat() == PhysicalDiskFormat.QCOW2) { - s_logger.debug("Checking physical disk file at path " + volPath + " for disk activity to ensure vm is not running elsewhere"); + LOGGER.debug("Checking physical disk file at path " + volPath + " for disk activity to ensure vm is not running elsewhere"); try { HypervisorUtils.checkVolumeFileForActivity(volPath, diskActivityCheckTimeoutSeconds, diskActivityInactiveThresholdMilliseconds, diskActivityCheckFileSizeMin); } catch (final IOException ex) { throw new CloudRuntimeException("Unable to check physical disk file for activity", ex); } - s_logger.debug("Disk activity check cleared"); + LOGGER.debug("Disk activity check cleared"); } // if params contains a rootDiskController key, use its value (this is what other HVs are doing) @@ -3084,6 +3101,13 @@ public int compare(final DiskTO arg0, final DiskTO arg1) { disk.setBusType(DiskDef.DiskBus.SCSI); } } else { + if (pool == null) { + throw new CloudRuntimeException(String.format("Found null pool for volume %s", volume)); + } + + disk.setLogicalBlockIOSize(pool.getSupportedLogicalBlockSize()); + disk.setPhysicalBlockIOSize(pool.getSupportedPhysicalBlockSize()); + if (diskBusType == DiskDef.DiskBus.SCSI ) { disk.setQemuDriver(true); disk.setDiscard(DiscardType.UNMAP); @@ -3140,7 +3164,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) { } } - + pool.customizeLibvirtDiskDef(disk); } if (data instanceof VolumeObjectTO) { @@ -3159,7 +3183,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) { } } if (vm.getDevices() == null) { - s_logger.error("There is no devices for" + vm); + LOGGER.error("There is no devices for" + vm); throw new RuntimeException("There is no devices for" + vm); } vm.getDevices().addDevice(disk); @@ -3190,7 +3214,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) { final int devId = volume.getDiskSeq().intValue(); final String device = mapRbdDevice(physicalDisk); if (device != null) { - s_logger.debug("RBD device on host is: " + device); + LOGGER.debug("RBD device on host is: " + device); final DiskDef diskdef = new DiskDef(); diskdef.defBlockBasedDisk(device, devId, DiskDef.DiskBus.VIRTIO); diskdef.setQemuDriver(false); @@ -3213,10 +3237,10 @@ private KVMPhysicalDisk getPhysicalDiskPrimaryStore(PrimaryDataStoreTO primaryDa * Check if IO_URING is supported by qemu */ protected boolean isIoUringSupportedByQemu() { - s_logger.debug("Checking if iouring is supported"); + LOGGER.debug("Checking if iouring is supported"); String command = getIoUringCheckCommand(); if (org.apache.commons.lang3.StringUtils.isBlank(command)) { - s_logger.debug("Could not check iouring support, disabling it"); + LOGGER.debug("Could not check iouring support, disabling it"); return false; } int exitValue = executeBashScriptAndRetrieveExitValue(command); @@ -3229,7 +3253,7 @@ protected String getIoUringCheckCommand() { File file = new File(qemuPath); if (file.exists()) { String cmd = String.format("ldd %s | grep -Eqe '[[:space:]]liburing\\.so'", qemuPath); - s_logger.debug("Using the check command: " + cmd); + LOGGER.debug("Using the check command: " + cmd); return cmd; } } @@ -3243,7 +3267,7 @@ protected String getIoUringCheckCommand() { * (ii) Libvirt >= 6.3.0 */ public void setDiskIoDriver(DiskDef disk, IoDriverPolicy ioDriver) { - s_logger.debug(String.format("Disk IO driver policy [%s]. The host supports the io_uring policy [%s]", ioDriver, enableIoUring)); + logger.debug(String.format("Disk IO driver policy [%s]. The host supports the io_uring policy [%s]", ioDriver, enableIoUring)); if (ioDriver != null) { if (IoDriverPolicy.IO_URING != ioDriver) { disk.setIoDriver(ioDriver); @@ -3331,7 +3355,7 @@ private void setBurstProperties(final VolumeObjectTO volumeObjectTO, final DiskD private void createVif(final LibvirtVMDef vm, final VirtualMachineTO vmSpec, final NicTO nic, final String nicAdapter, Map extraConfig) throws InternalErrorException, LibvirtException { if (vm.getDevices() == null) { - s_logger.error("LibvirtVMDef object get devices with null result"); + LOGGER.error("LibvirtVMDef object get devices with null result"); throw new InternalErrorException("LibvirtVMDef object get devices with null result"); } final InterfaceDef interfaceDef = getVifDriver(nic.getType(), nic.getName()).plug(nic, vm.getPlatformEmulator(), nicAdapter, extraConfig); @@ -3349,7 +3373,7 @@ public boolean cleanupDisk(final DiskDef disk) { final String path = disk.getDiskPath(); if (StringUtils.isBlank(path)) { - s_logger.debug("Unable to clean up disk with null path (perhaps empty cdrom drive):" + disk); + LOGGER.debug("Unable to clean up disk with null path (perhaps empty cdrom drive):" + disk); return false; } @@ -3378,15 +3402,15 @@ public void detachAndAttachConfigDriveISO(final Connect conn, final String vmNam try { String result = attachOrDetachISO(conn, vmName, configdrive.getDiskPath(), false, CONFIG_DRIVE_ISO_DEVICE_ID); if (result != null) { - s_logger.warn("Detach ConfigDrive ISO with result: " + result); + LOGGER.warn("Detach ConfigDrive ISO with result: " + result); } result = attachOrDetachISO(conn, vmName, configdrive.getDiskPath(), true, CONFIG_DRIVE_ISO_DEVICE_ID); if (result != null) { - s_logger.warn("Attach ConfigDrive ISO with result: " + result); + LOGGER.warn("Attach ConfigDrive ISO with result: " + result); } } catch (final LibvirtException | InternalErrorException | URISyntaxException e) { final String msg = "Detach and attach ConfigDrive ISO failed due to " + e.toString(); - s_logger.warn(msg, e); + LOGGER.warn(msg, e); } } } @@ -3512,6 +3536,10 @@ public synchronized String attachOrDetachDisk(final Connect conn, if (cacheMode != null) { diskdef.setCacheMode(DiskDef.DiskCacheMode.valueOf(cacheMode.toUpperCase())); } + + diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize()); + diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize()); + attachingPool.customizeLibvirtDiskDef(diskdef); } final String xml = diskdef.toString(); @@ -3528,17 +3556,17 @@ protected synchronized String attachOrDetachDevice(final Connect conn, final boo try { dm = conn.domainLookupByName(vmName); if (attach) { - s_logger.debug("Attaching device: " + xml); + LOGGER.debug("Attaching device: " + xml); dm.attachDevice(xml); } else { - s_logger.debug("Detaching device: " + xml); + LOGGER.debug("Detaching device: " + xml); dm.detachDevice(xml); } } catch (final LibvirtException e) { if (attach) { - s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); + LOGGER.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); } else { - s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); + LOGGER.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); } throw e; } finally { @@ -3546,7 +3574,7 @@ protected synchronized String attachOrDetachDevice(final Connect conn, final boo try { dm.free(); } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } } @@ -3582,19 +3610,19 @@ public PingCommand getCurrentStatus(final long id) { */ private HealthCheckResult getHostHealthCheckResult() { if (StringUtils.isBlank(hostHealthCheckScriptPath)) { - s_logger.debug("Host health check script path is not specified"); + logger.debug("Host health check script path is not specified"); return HealthCheckResult.IGNORE; } File script = new File(hostHealthCheckScriptPath); if (!script.exists() || !script.isFile() || !script.canExecute()) { - s_logger.warn(String.format("The host health check script file set at: %s cannot be executed, " + + logger.warn(String.format("The host health check script file set at: %s cannot be executed, " + "reason: %s", hostHealthCheckScriptPath, !script.exists() ? "file does not exist" : "please check file permissions to execute this file")); return HealthCheckResult.IGNORE; } int exitCode = executeBashScriptAndRetrieveExitValue(hostHealthCheckScriptPath); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Host health check script exit code: %s", exitCode)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Host health check script exit code: %s", exitCode)); } return retrieveHealthCheckResultFromExitCode(exitCode); } @@ -3612,7 +3640,7 @@ public Type getType() { } private Map getVersionStrings() { - final Script command = new Script(versionStringPath, timeout, s_logger); + final Script command = new Script(versionStringPath, timeout, LOGGER); final KeyValueInterpreter kvi = new KeyValueInterpreter(); final String result = command.execute(kvi); if (result == null) { @@ -3631,7 +3659,6 @@ public StartupCommand[] initialize() { if (dpdkSupport) { capabilities += ",dpdk"; } - final StartupRoutingCommand cmd = new StartupRoutingCommand(info.getAllocatableCpus(), info.getCpuSpeed(), info.getTotalMemory(), info.getReservedMemory(), capabilities, hypervisorType, RouterPrivateIpStrategy.HostLocal); @@ -3645,11 +3672,15 @@ public StartupCommand[] initialize() { cmd.setGatewayIpAddress(localGateway); cmd.setIqn(getIqn()); cmd.getHostDetails().put(HOST_VOLUME_ENCRYPTION, String.valueOf(hostSupportsVolumeEncryption())); + cmd.setHostTags(getHostTags()); cmd.getHostDetails().put(HOST_INSTANCE_CONVERSION, String.valueOf(hostSupportsInstanceConversion())); HealthCheckResult healthCheckResult = getHostHealthCheckResult(); if (healthCheckResult != HealthCheckResult.IGNORE) { cmd.setHostHealthCheckResult(healthCheckResult == HealthCheckResult.SUCCESS); } + if (StringUtils.isNotBlank(info.getCpuArch())) { + cmd.setCpuArch(info.getCpuArch()); + } if (cmd.getHostDetails().containsKey("Host.OS")) { hostDistro = cmd.getHostDetails().get("Host.OS"); @@ -3674,6 +3705,19 @@ public StartupCommand[] initialize() { return startupCommandsArray; } + protected List getHostTags() { + List hostTagsList = new ArrayList<>(); + String hostTags = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_TAGS); + if (StringUtils.isNotBlank(hostTags)) { + for (String hostTag : hostTags.split(",")) { + if (!hostTagsList.contains(hostTag.trim())) { + hostTagsList.add(hostTag.trim()); + } + } + } + return hostTagsList; + } + /** * Calculates and sets the host CPU max capacity according to the cgroup version of the host. *
      @@ -3687,17 +3731,17 @@ public StartupCommand[] initialize() { */ protected void calculateHostCpuMaxCapacity(int cpuCores, Long cpuSpeed) { String output = Script.runSimpleBashScript(COMMAND_GET_CGROUP_HOST_VERSION); - s_logger.info(String.format("Host uses control group [%s].", output)); + logger.info(String.format("Host uses control group [%s].", output)); if (!CGROUP_V2.equals(output)) { - s_logger.info(String.format("Setting host CPU max capacity to 0, as it uses cgroup v1.", getHostCpuMaxCapacity())); + logger.info(String.format("Setting host CPU max capacity to 0, as it uses cgroup v1.", getHostCpuMaxCapacity())); setHostCpuMaxCapacity(0); return; } - s_logger.info(String.format("Calculating the max shares of the host.")); + logger.info(String.format("Calculating the max shares of the host.")); setHostCpuMaxCapacity(cpuCores * cpuSpeed.intValue()); - s_logger.info(String.format("The max shares of the host is [%d].", getHostCpuMaxCapacity())); + logger.info(String.format("The max shares of the host is [%d].", getHostCpuMaxCapacity())); } private StartupStorageCommand createLocalStoragePool(String localStoragePath, String localStorageUUID, StartupRoutingCommand cmd) { @@ -3714,7 +3758,7 @@ private StartupStorageCommand createLocalStoragePool(String localStoragePath, St sscmd.setDataCenter(dcId); sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL); } catch (final CloudRuntimeException e) { - s_logger.debug("Unable to initialize local storage pool: " + e); + LOGGER.debug("Unable to initialize local storage pool: " + e); } return sscmd; } @@ -3728,7 +3772,7 @@ private String getIqn() { try { final String textToFind = "InitiatorName="; - final Script iScsiAdmCmd = new Script(true, "grep", 0, s_logger); + final Script iScsiAdmCmd = new Script(true, "grep", 0, LOGGER); iScsiAdmCmd.add(textToFind); iScsiAdmCmd.add("/etc/iscsi/initiatorname.iscsi"); @@ -3760,7 +3804,7 @@ public Pair getSourceHostPath(String diskPath) { String sourcePath = null; try { String mountResult = Script.runSimpleBashScript("mount | grep \"" + diskPath + "\""); - s_logger.debug("Got mount result for " + diskPath + "\n\n" + mountResult); + logger.debug("Got mount result for " + diskPath + "\n\n" + mountResult); if (StringUtils.isNotEmpty(mountResult)) { String[] res = mountResult.strip().split(" "); if (res[0].contains(":")) { @@ -3777,7 +3821,7 @@ public Pair getSourceHostPath(String diskPath) { return new Pair<>(sourceHostIp, sourcePath); } } catch (Exception ex) { - s_logger.warn("Failed to list source host and IP for " + diskPath + ex.toString()); + logger.warn("Failed to list source host and IP for " + diskPath + ex.toString()); } return null; } @@ -3790,14 +3834,14 @@ public List getAllVmNames(final Connect conn) { domainNames.add(names[i]); } } catch (final LibvirtException e) { - s_logger.warn("Failed to list defined domains", e); + logger.warn("Failed to list defined domains", e); } int[] ids = null; try { ids = conn.listDomains(); } catch (final LibvirtException e) { - s_logger.warn("Failed to list domains", e); + logger.warn("Failed to list domains", e); return domainNames; } @@ -3807,14 +3851,14 @@ public List getAllVmNames(final Connect conn) { dm = conn.domainLookupByID(ids[i]); domainNames.add(dm.getName()); } catch (final LibvirtException e) { - s_logger.warn("Unable to get vms", e); + LOGGER.warn("Unable to get vms", e); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -3833,7 +3877,7 @@ private HashMap getHostVmStateReport() { conn = LibvirtConnection.getConnectionByType(HypervisorType.KVM.toString()); vmStates.putAll(getHostVmStateReport(conn)); } catch (final LibvirtException e) { - s_logger.debug("Failed to get connection: " + e.getMessage()); + LOGGER.debug("Failed to get connection: " + e.getMessage()); } } @@ -3842,7 +3886,7 @@ private HashMap getHostVmStateReport() { conn = LibvirtConnection.getConnectionByType(HypervisorType.KVM.toString()); vmStates.putAll(getHostVmStateReport(conn)); } catch (final LibvirtException e) { - s_logger.debug("Failed to get connection: " + e.getMessage()); + LOGGER.debug("Failed to get connection: " + e.getMessage()); } } @@ -3858,13 +3902,13 @@ private HashMap getHostVmStateReport(final Conne try { ids = conn.listDomains(); } catch (final LibvirtException e) { - s_logger.warn("Unable to listDomains", e); + LOGGER.warn("Unable to listDomains", e); return null; } try { vms = conn.listDefinedDomains(); } catch (final LibvirtException e) { - s_logger.warn("Unable to listDomains", e); + LOGGER.warn("Unable to listDomains", e); return null; } @@ -3877,7 +3921,7 @@ private HashMap getHostVmStateReport(final Conne final PowerState state = convertToPowerState(ps); - s_logger.trace("VM " + dm.getName() + ": powerstate = " + ps + "; vm state=" + state.toString()); + LOGGER.trace("VM " + dm.getName() + ": powerstate = " + ps + "; vm state=" + state.toString()); final String vmName = dm.getName(); // TODO : for XS/KVM (host-based resource), we require to remove @@ -3888,14 +3932,14 @@ private HashMap getHostVmStateReport(final Conne vmStates.put(vmName, new HostVmStateReportEntry(state, conn.getHostName())); } } catch (final LibvirtException e) { - s_logger.warn("Unable to get vms", e); + LOGGER.warn("Unable to get vms", e); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -3908,7 +3952,7 @@ private HashMap getHostVmStateReport(final Conne final DomainState ps = dm.getInfo().state; final PowerState state = convertToPowerState(ps); final String vmName = dm.getName(); - s_logger.trace("VM " + vmName + ": powerstate = " + ps + "; vm state=" + state.toString()); + LOGGER.trace("VM " + vmName + ": powerstate = " + ps + "; vm state=" + state.toString()); // TODO : for XS/KVM (host-based resource), we require to remove // VM completely from host, for some reason, KVM seems to still keep @@ -3918,14 +3962,14 @@ private HashMap getHostVmStateReport(final Conne vmStates.put(vmName, new HostVmStateReportEntry(state, conn.getHostName())); } } catch (final LibvirtException e) { - s_logger.warn("Unable to get vms", e); + LOGGER.warn("Unable to get vms", e); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -3945,7 +3989,7 @@ public String rebootVM(final Connect conn, final String vmName) throws LibvirtEx dm.reboot(0x1); return null; } catch (final LibvirtException e) { - s_logger.warn("Failed to create vm", e); + LOGGER.warn("Failed to create vm", e); msg = e.getMessage(); } finally { try { @@ -3953,7 +3997,7 @@ public String rebootVM(final Connect conn, final String vmName) throws LibvirtEx dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } @@ -3969,18 +4013,18 @@ public String stopVM(final Connect conn, final String vmName, final boolean forc dm = conn.domainLookupByName(vmName); cleanVMSnapshotMetadata(dm); } catch (LibvirtException e) { - s_logger.debug("Failed to get vm :" + e.getMessage()); + LOGGER.debug("Failed to get vm :" + e.getMessage()); } finally { try { if (dm != null) { dm.free(); } } catch (LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } - s_logger.debug("Try to stop the vm at first"); + LOGGER.debug("Try to stop the vm at first"); if (forceStop) { return stopVMInternal(conn, vmName, true); } @@ -4000,25 +4044,25 @@ public String stopVM(final Connect conn, final String vmName, final boolean forc state = dm.getInfo().state; break; } catch (final LibvirtException e) { - s_logger.debug("Failed to get vm status:" + e.getMessage()); + LOGGER.debug("Failed to get vm status:" + e.getMessage()); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } } if (state == null) { - s_logger.debug("Can't get vm's status, assume it's dead already"); + LOGGER.debug("Can't get vm's status, assume it's dead already"); return null; } if (state != DomainState.VIR_DOMAIN_SHUTOFF) { - s_logger.debug("Try to destroy the vm"); + LOGGER.debug("Try to destroy the vm"); ret = stopVMInternal(conn, vmName, true); if (ret != null) { return ret; @@ -4057,13 +4101,13 @@ protected String stopVMInternal(final Connect conn, final String vmName, final b } catch (final LibvirtException e) { final String error = e.toString(); if (error.contains("Domain not found")) { - s_logger.debug("successfully shut down vm " + vmName); + LOGGER.debug("successfully shut down vm " + vmName); } else { - s_logger.debug("Error in waiting for vm shutdown:" + error); + LOGGER.debug("Error in waiting for vm shutdown:" + error); } } if (retry < 0) { - s_logger.warn("Timed out waiting for domain " + vmName + " to shutdown gracefully"); + LOGGER.warn("Timed out waiting for domain " + vmName + " to shutdown gracefully"); return Script.ERR_TIMEOUT; } else { if (persist == 1) { @@ -4073,13 +4117,13 @@ protected String stopVMInternal(final Connect conn, final String vmName, final b } } catch (final LibvirtException e) { if (e.getMessage().contains("Domain not found")) { - s_logger.debug("VM " + vmName + " doesn't exist, no need to stop it"); + LOGGER.debug("VM " + vmName + " doesn't exist, no need to stop it"); return null; } - s_logger.debug("Failed to stop VM :" + vmName + " :", e); + LOGGER.debug("Failed to stop VM :" + vmName + " :", e); return e.getMessage(); } catch (final InterruptedException ie) { - s_logger.debug("Interrupted sleep"); + LOGGER.debug("Interrupted sleep"); return ie.getMessage(); } finally { try { @@ -4087,7 +4131,7 @@ protected String stopVMInternal(final Connect conn, final String vmName, final b dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } @@ -4108,7 +4152,7 @@ public Integer getVncPort(final Connect conn, final String vmName) throws Libvir dm.free(); } } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } } @@ -4124,7 +4168,7 @@ private boolean IsHVMEnabled(final Connect conn) { } } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } return false; } @@ -4134,7 +4178,7 @@ private String getHypervisorPath(final Connect conn) { try { parser.parseCapabilitiesXML(conn.getCapabilities()); } catch (final LibvirtException e) { - s_logger.debug(e.getMessage()); + LOGGER.debug(e.getMessage()); } return parser.getEmulator(); } @@ -4160,10 +4204,10 @@ public DiskDef.DiskBus getDiskModelFromVMDetail(final VirtualMachineTO vmTO) { String rootDiskController = details.get(VmDetailConstants.ROOT_DISK_CONTROLLER); if (StringUtils.isNotBlank(rootDiskController)) { - s_logger.debug("Passed custom disk controller for ROOT disk " + rootDiskController); + LOGGER.debug("Passed custom disk controller for ROOT disk " + rootDiskController); for (DiskDef.DiskBus bus : DiskDef.DiskBus.values()) { if (bus.toString().equalsIgnoreCase(rootDiskController)) { - s_logger.debug("Found matching enum for disk controller for ROOT disk " + rootDiskController); + LOGGER.debug("Found matching enum for disk controller for ROOT disk " + rootDiskController); return bus; } } @@ -4179,10 +4223,10 @@ public DiskDef.DiskBus getDataDiskModelFromVMDetail(final VirtualMachineTO vmTO) String dataDiskController = details.get(VmDetailConstants.DATA_DISK_CONTROLLER); if (StringUtils.isNotBlank(dataDiskController)) { - s_logger.debug("Passed custom disk controller for DATA disk " + dataDiskController); + LOGGER.debug("Passed custom disk controller for DATA disk " + dataDiskController); for (DiskDef.DiskBus bus : DiskDef.DiskBus.values()) { if (bus.toString().equalsIgnoreCase(dataDiskController)) { - s_logger.debug("Found matching enum for disk controller for DATA disk " + dataDiskController); + LOGGER.debug("Found matching enum for disk controller for DATA disk " + dataDiskController); return bus; } } @@ -4232,7 +4276,7 @@ public List getInterfaces(final Connect conn, final String vmName) return parser.getInterfaces(); } catch (final LibvirtException e) { - s_logger.debug("Failed to get dom xml: " + e.toString()); + LOGGER.debug("Failed to get dom xml: " + e.toString()); return new ArrayList(); } finally { try { @@ -4240,7 +4284,7 @@ public List getInterfaces(final Connect conn, final String vmName) dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -4254,7 +4298,7 @@ public List getDisks(final Connect conn, final String vmName) { return parser.getDisks(); } catch (final LibvirtException e) { - s_logger.debug("Failed to get dom xml: " + e.toString()); + LOGGER.debug("Failed to get dom xml: " + e.toString()); return new ArrayList(); } finally { try { @@ -4262,7 +4306,7 @@ public List getDisks(final Connect conn, final String vmName) { dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -4272,7 +4316,7 @@ private String executeBashScript(final String script) { } private Script createScript(final String script) { - final Script command = new Script("/bin/bash", timeout, s_logger); + final Script command = new Script("/bin/bash", timeout, LOGGER); command.add("-c"); command.add(script); return command; @@ -4374,127 +4418,189 @@ protected String getDiskPathFromDiskDef(DiskDef disk) { return null; } - private class VmStats { - long usedTime; - long tx; - long rx; - long ioRead; - long ioWrote; - long bytesRead; - long bytesWrote; - Calendar timestamp; + private String vmToString(Domain dm) throws LibvirtException { + return String.format("{\"name\":\"%s\",\"uuid\":\"%s\"}", dm.getName(), dm.getUUIDString()); } + /** + * Returns metrics for the period since this function was last called for the specified VM. + * @param conn the Libvirt connection. + * @param vmName name of the VM. + * @return metrics for the period since last time this function was called for the VM. + * @throws LibvirtException + */ public VmStatsEntry getVmStat(final Connect conn, final String vmName) throws LibvirtException { Domain dm = null; try { + LOGGER.debug("Trying to get VM with name [{}].", vmName); dm = getDomain(conn, vmName); if (dm == null) { + LOGGER.warn("Could not get VM with name [{}].", vmName); return null; } - DomainInfo info = dm.getInfo(); - final VmStatsEntry stats = new VmStatsEntry(); - stats.setNumCPUs(info.nrVirtCpu); - stats.setEntityType("vm"); + LibvirtExtendedVmStatsEntry newStats = getVmCurrentStats(dm); + LibvirtExtendedVmStatsEntry oldStats = vmStats.get(vmName); - stats.setMemoryKBs(info.maxMem); - stats.setTargetMemoryKBs(info.memory); - stats.setIntFreeMemoryKBs(getMemoryFreeInKBs(dm)); + VmStatsEntry metrics = calculateVmMetrics(dm, oldStats, newStats); + vmStats.put(vmName, newStats); - /* get cpu utilization */ - VmStats oldStats = null; + return metrics; + } finally { + if (dm != null) { + dm.free(); + } + } + } - final Calendar now = Calendar.getInstance(); + /** + * Returns a VM's current statistics. + * @param dm domain of the VM. + * @return current statistics of the VM. + * @throws LibvirtException + */ + protected LibvirtExtendedVmStatsEntry getVmCurrentStats(final Domain dm) throws LibvirtException { + final LibvirtExtendedVmStatsEntry stats = new LibvirtExtendedVmStatsEntry(); - oldStats = vmStats.get(vmName); + getVmCurrentCpuStats(dm, stats); + getVmCurrentNetworkStats(dm, stats); + getVmCurrentDiskStats(dm, stats); - long elapsedTime = 0; - if (oldStats != null) { - elapsedTime = now.getTimeInMillis() - oldStats.timestamp.getTimeInMillis(); - double utilization = (info.cpuTime - oldStats.usedTime) / ((double)elapsedTime * 1000000); + LOGGER.debug("Retrieved statistics for VM [{}]: [{}].", vmToString(dm), stats); + stats.setTimestamp(Calendar.getInstance()); + return stats; + } - utilization = utilization / info.nrVirtCpu; - if (utilization > 0) { - stats.setCPUUtilization(utilization * 100); - } - } + /** + * Passes a VM's current CPU statistics into the provided LibvirtExtendedVmStatsEntry. + * @param dm domain of the VM. + * @param stats LibvirtExtendedVmStatsEntry that will receive the current CPU statistics. + * @throws LibvirtException + */ + protected void getVmCurrentCpuStats(final Domain dm, final LibvirtExtendedVmStatsEntry stats) throws LibvirtException { + LOGGER.trace("Getting CPU stats for VM [{}].", vmToString(dm)); + stats.setCpuTime(dm.getInfo().cpuTime); + } - /* get network stats */ + /** + * Passes a VM's current network statistics into the provided LibvirtExtendedVmStatsEntry. + * @param dm domain of the VM. + * @param stats LibvirtExtendedVmStatsEntry that will receive the current network statistics. + * @throws LibvirtException + */ + protected void getVmCurrentNetworkStats(final Domain dm, final LibvirtExtendedVmStatsEntry stats) throws LibvirtException { + final String vmAsString = vmToString(dm); + LOGGER.trace("Getting network stats for VM [{}].", vmAsString); + final List vifs = getInterfaces(dm.getConnect(), dm.getName()); + LOGGER.debug("Found [{}] network interface(s) for VM [{}].", vifs.size(), vmAsString); + double rx = 0; + double tx = 0; + for (final InterfaceDef vif : vifs) { + final DomainInterfaceStats ifStats = dm.interfaceStats(vif.getDevName()); + rx += ifStats.rx_bytes; + tx += ifStats.tx_bytes; + } + stats.setNetworkReadKBs(rx / 1024); + stats.setNetworkWriteKBs(tx / 1024); + } - final List vifs = getInterfaces(conn, vmName); - long rx = 0; - long tx = 0; - for (final InterfaceDef vif : vifs) { - final DomainInterfaceStats ifStats = dm.interfaceStats(vif.getDevName()); - rx += ifStats.rx_bytes; - tx += ifStats.tx_bytes; + /** + * Passes a VM's current disk statistics into the provided LibvirtExtendedVmStatsEntry. + * @param dm domain of the VM. + * @param stats LibvirtExtendedVmStatsEntry that will receive the current disk statistics. + * @throws LibvirtException + */ + protected void getVmCurrentDiskStats(final Domain dm, final LibvirtExtendedVmStatsEntry stats) throws LibvirtException { + final String vmAsString = vmToString(dm); + LOGGER.trace("Getting disk stats for VM [{}].", vmAsString); + final List disks = getDisks(dm.getConnect(), dm.getName()); + LOGGER.debug("Found [{}] disk(s) for VM [{}].", disks.size(), vmAsString); + long io_rd = 0; + long io_wr = 0; + double bytes_rd = 0; + double bytes_wr = 0; + for (final DiskDef disk : disks) { + if (disk.getDeviceType() == DeviceType.CDROM || disk.getDeviceType() == DeviceType.FLOPPY) { + LOGGER.debug("Ignoring disk [{}] in VM [{}]'s stats since its deviceType is [{}].", disk.toString().replace("\n", ""), vmAsString, disk.getDeviceType()); + continue; } + final DomainBlockStats blockStats = dm.blockStats(disk.getDiskLabel()); + io_rd += blockStats.rd_req; + io_wr += blockStats.wr_req; + bytes_rd += blockStats.rd_bytes; + bytes_wr += blockStats.wr_bytes; + } + stats.setDiskReadIOs(io_rd); + stats.setDiskWriteIOs(io_wr); + stats.setDiskReadKBs(bytes_rd / 1024); + stats.setDiskWriteKBs(bytes_wr / 1024); + } - if (oldStats != null) { - final double deltarx = rx - oldStats.rx; - if (deltarx > 0) { - stats.setNetworkReadKBs(deltarx / 1024); - } - final double deltatx = tx - oldStats.tx; - if (deltatx > 0) { - stats.setNetworkWriteKBs(deltatx / 1024); - } + /** + * Calculates a VM's metrics for the period between the two statistics given as parameters. + * @param dm domain of the VM. + * @param oldStats old statistics. If null, the CPU, network and disk utilization won't be calculated. + * @param newStats new statistics. + * @return metrics for the period between the two statistics. + * @throws LibvirtException + */ + protected VmStatsEntry calculateVmMetrics(final Domain dm, final LibvirtExtendedVmStatsEntry oldStats, final LibvirtExtendedVmStatsEntry newStats) throws LibvirtException { + final VmStatsEntry metrics = new VmStatsEntry(); + final DomainInfo info = dm.getInfo(); + final String vmAsString = vmToString(dm); + + metrics.setEntityType("vm"); + LOGGER.trace("Writing VM [{}]'s CPU and memory information into the metrics.", vmAsString); + metrics.setNumCPUs(info.nrVirtCpu); + metrics.setMemoryKBs(info.maxMem); + metrics.setTargetMemoryKBs(info.memory); + LOGGER.trace("Trying to get free memory for VM [{}].", vmAsString); + metrics.setIntFreeMemoryKBs(getMemoryFreeInKBs(dm)); + + if (oldStats != null) { + LOGGER.debug("Old stats exist for VM [{}]; therefore, the utilization will be calculated.", vmAsString); + + LOGGER.trace("Calculating CPU utilization for VM [{}].", vmAsString); + final Calendar now = Calendar.getInstance(); + long elapsedTime = now.getTimeInMillis() - oldStats.getTimestamp().getTimeInMillis(); + double utilization = (info.cpuTime - oldStats.getCpuTime()) / ((double) elapsedTime * 1000000 * info.nrVirtCpu); + if (utilization > 0) { + metrics.setCPUUtilization(utilization * 100); } - /* get disk stats */ - final List disks = getDisks(conn, vmName); - long io_rd = 0; - long io_wr = 0; - long bytes_rd = 0; - long bytes_wr = 0; - for (final DiskDef disk : disks) { - if (disk.getDeviceType() == DeviceType.CDROM || disk.getDeviceType() == DeviceType.FLOPPY) { - continue; - } - final DomainBlockStats blockStats = dm.blockStats(disk.getDiskLabel()); - io_rd += blockStats.rd_req; - io_wr += blockStats.wr_req; - bytes_rd += blockStats.rd_bytes; - bytes_wr += blockStats.wr_bytes; + LOGGER.trace("Calculating network utilization for VM [{}].", vmAsString); + final double deltarx = newStats.getNetworkReadKBs() - oldStats.getNetworkReadKBs(); + if (deltarx > 0) { + metrics.setNetworkReadKBs(deltarx); } - - if (oldStats != null) { - final long deltaiord = io_rd - oldStats.ioRead; - if (deltaiord > 0) { - stats.setDiskReadIOs(deltaiord); - } - final long deltaiowr = io_wr - oldStats.ioWrote; - if (deltaiowr > 0) { - stats.setDiskWriteIOs(deltaiowr); - } - final double deltabytesrd = bytes_rd - oldStats.bytesRead; - if (deltabytesrd > 0) { - stats.setDiskReadKBs(deltabytesrd / 1024); - } - final double deltabyteswr = bytes_wr - oldStats.bytesWrote; - if (deltabyteswr > 0) { - stats.setDiskWriteKBs(deltabyteswr / 1024); - } + final double deltatx = newStats.getNetworkWriteKBs() - oldStats.getNetworkWriteKBs(); + if (deltatx > 0) { + metrics.setNetworkWriteKBs(deltatx); } - /* save to Hashmap */ - final VmStats newStat = new VmStats(); - newStat.usedTime = info.cpuTime; - newStat.rx = rx; - newStat.tx = tx; - newStat.ioRead = io_rd; - newStat.ioWrote = io_wr; - newStat.bytesRead = bytes_rd; - newStat.bytesWrote = bytes_wr; - newStat.timestamp = now; - vmStats.put(vmName, newStat); - return stats; - } finally { - if (dm != null) { - dm.free(); + LOGGER.trace("Calculating disk utilization for VM [{}].", vmAsString); + final double deltaiord = newStats.getDiskReadIOs() - oldStats.getDiskReadIOs(); + if (deltaiord > 0) { + metrics.setDiskReadIOs(deltaiord); + } + final double deltaiowr = newStats.getDiskWriteIOs() - oldStats.getDiskWriteIOs(); + if (deltaiowr > 0) { + metrics.setDiskWriteIOs(deltaiowr); + } + final double deltabytesrd = newStats.getDiskReadKBs() - oldStats.getDiskReadKBs(); + if (deltabytesrd > 0) { + metrics.setDiskReadKBs(deltabytesrd); + } + final double deltabyteswr = newStats.getDiskWriteKBs() - oldStats.getDiskWriteKBs(); + if (deltabyteswr > 0) { + metrics.setDiskWriteKBs(deltabyteswr); } } + + String metricsAsString = new ReflectionToStringBuilder(metrics, ToStringStyle.JSON_STYLE).setExcludeFieldNames("vmId", "vmUuid").toString(); + LOGGER.debug("Calculated metrics for VM [{}]: [{}].", vmAsString, metricsAsString); + + return metrics; } /** @@ -4506,10 +4612,8 @@ public VmStatsEntry getVmStat(final Connect conn, final String vmName) throws Li */ protected long getMemoryFreeInKBs(Domain dm) throws LibvirtException { MemoryStatistic[] memoryStats = dm.memoryStats(NUMMEMSTATS); - - if(s_logger.isTraceEnabled()){ - s_logger.trace(String.format("Retrieved memory statistics (information about tags can be found on the libvirt documentation):", ArrayUtils.toString(memoryStats))); - } + LOGGER.trace("Retrieved memory statistics (information about tags can be found on the libvirt documentation): {}.", + () -> Stream.of(memoryStats).map(stat -> stat.toString().trim().replace("\n", ",")).collect(Collectors.joining("},{", "[{", "}]"))); long freeMemory = NumberUtils.LONG_MINUS_ONE; @@ -4525,13 +4629,13 @@ protected long getMemoryFreeInKBs(Domain dm) throws LibvirtException { } if (freeMemory == NumberUtils.LONG_MINUS_ONE){ - s_logger.warn("Couldn't retrieve free memory, returning -1."); + LOGGER.warn("Couldn't retrieve free memory, returning -1."); } return freeMemory; } private boolean canBridgeFirewall(final String prvNic) { - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("can_bridge_firewall"); cmd.add("--privnic", prvNic); final String result = cmd.execute(); @@ -4551,7 +4655,7 @@ public boolean destroyNetworkRulesForVM(final Connect conn, final String vmName) final InterfaceDef intf = intfs.get(0); vif = intf.getDevName(); } - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("destroy_network_rules_for_vm"); cmd.add("--vmname", vmName); if (vif != null) { @@ -4597,7 +4701,7 @@ public boolean destroyNetworkRulesForNic(final Connect conn, final String vmName final String brname = intf.getBrName(); final String vif = intf.getDevName(); - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("destroy_network_rules_for_vm"); cmd.add("--vmname", vmName); if (nic.getIp() != null) { @@ -4624,7 +4728,7 @@ public boolean destroyNetworkRulesForNic(final Connect conn, final String vmName public boolean applyDefaultNetworkRules(final Connect conn, final VirtualMachineTO vm, final boolean checkBeforeApply) { NicTO[] nicTOs = new NicTO[] {}; if (vm != null && vm.getNics() != null) { - s_logger.debug("Checking default network rules for vm " + vm.getName()); + LOGGER.debug("Checking default network rules for vm " + vm.getName()); nicTOs = vm.getNics(); } for (NicTO nic : nicTOs) { @@ -4640,7 +4744,7 @@ public boolean applyDefaultNetworkRules(final Connect conn, final VirtualMachine break; } if (!applyDefaultNetworkRulesOnNic(conn, vm.getName(), vm.getId(), nic, isFirstNic, checkBeforeApply)) { - s_logger.error("Unable to apply default network rule for nic " + nic.getName() + " for VM " + vm.getName()); + LOGGER.error("Unable to apply default network rule for nic " + nic.getName() + " for VM " + vm.getName()); return false; } isFirstNic = false; @@ -4688,7 +4792,7 @@ public boolean defaultNetworkRules(final Connect conn, final String vmName, fina final String brname = intf.getBrName(); final String vif = intf.getDevName(); - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("default_network_rules"); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId.toString()); @@ -4729,7 +4833,7 @@ protected boolean post_default_network_rules(final Connect conn, final String vm final String brname = intf.getBrName(); final String vif = intf.getDevName(); - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("post_default_network_rules"); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId.toString()); @@ -4755,7 +4859,7 @@ public boolean configureDefaultNetworkRulesForSystemVm(final Connect conn, final return false; } - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("default_network_rules_systemvm"); cmd.add("--vmname", vmName); cmd.add("--localbrname", linkLocalBridgeName); @@ -4779,7 +4883,7 @@ public boolean addNetworkRules(final String vmName, final String vmId, final Str } final String newRules = rules.replace(" ", ";"); - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("add_network_rules"); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId); @@ -4809,7 +4913,7 @@ public boolean configureNetworkRulesVMSecondaryIP(final Connect conn, final Stri return false; } - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("network_rules_vmSecondaryIp"); cmd.add("--vmname", vmName); cmd.add("--vmmac", vmMac); @@ -4825,7 +4929,7 @@ public boolean configureNetworkRulesVMSecondaryIP(final Connect conn, final Stri public boolean setupTungstenVRouter(final String oper, final String inf, final String subnet, final String route, final String vrf) { - final Script cmd = new Script(setupTungstenVrouterPath, timeout, s_logger); + final Script cmd = new Script(setupTungstenVrouterPath, timeout, logger); cmd.add(oper); cmd.add(inf); cmd.add(subnet); @@ -4838,7 +4942,7 @@ public boolean setupTungstenVRouter(final String oper, final String inf, final S public boolean updateTungstenLoadbalancerStats(final String lbUuid, final String lbStatsPort, final String lbStatsUri, final String lbStatsAuth) { - final Script cmd = new Script(updateTungstenLoadbalancerStatsPath, timeout, s_logger); + final Script cmd = new Script(updateTungstenLoadbalancerStatsPath, timeout, logger); cmd.add(lbUuid); cmd.add(lbStatsPort); cmd.add(lbStatsUri); @@ -4850,7 +4954,7 @@ public boolean updateTungstenLoadbalancerStats(final String lbUuid, final String public boolean updateTungstenLoadbalancerSsl(final String lbUuid, final String sslCertName, final String certificateKey, final String privateKey, final String privateIp, final String port) { - final Script cmd = new Script(updateTungstenLoadbalancerSslPath, timeout, s_logger); + final Script cmd = new Script(updateTungstenLoadbalancerSslPath, timeout, logger); cmd.add(lbUuid); cmd.add(sslCertName); cmd.add(certificateKey); @@ -4863,7 +4967,7 @@ public boolean updateTungstenLoadbalancerSsl(final String lbUuid, final String s } public boolean setupTfRoute(final String privateIpAddress, final String fromNetwork, final String toNetwork) { - final Script setupTfRouteScript = new Script(routerProxyPath, timeout, s_logger); + final Script setupTfRouteScript = new Script(routerProxyPath, timeout, logger); setupTfRouteScript.add("setup_tf_route.py"); setupTfRouteScript.add(privateIpAddress); setupTfRouteScript.add(fromNetwork); @@ -4872,7 +4976,7 @@ public boolean setupTfRoute(final String privateIpAddress, final String fromNetw final OutputInterpreter.OneLineParser setupTfRouteParser = new OutputInterpreter.OneLineParser(); final String result = setupTfRouteScript.execute(setupTfRouteParser); if (result != null) { - s_logger.debug("Failed to execute setup TF Route:" + result); + logger.debug("Failed to execute setup TF Route:" + result); return false; } return true; @@ -4882,7 +4986,7 @@ public boolean cleanupRules() { if (!canBridgeFirewall) { return false; } - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("cleanup_rules"); final String result = cmd.execute(); if (result != null) { @@ -4892,7 +4996,7 @@ public boolean cleanupRules() { } public String getRuleLogsForVms() { - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("get_rule_logs_for_vms"); final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); final String result = cmd.execute(parser); @@ -4906,7 +5010,7 @@ private HashMap> syncNetworkGroups(final long id) { final HashMap> states = new HashMap>(); final String result = getRuleLogsForVms(); - s_logger.trace("syncNetworkGroups: id=" + id + " got: " + result); + LOGGER.trace("syncNetworkGroups: id=" + id + " got: " + result); final String[] rulelogs = result != null ? result.split(";") : new String[0]; for (final String rulesforvm : rulelogs) { final String[] log = rulesforvm.split(","); @@ -4936,12 +5040,12 @@ public Pair getNicStats(final String nicName) { return new Pair(readDouble(nicName, "rx_bytes"), readDouble(nicName, "tx_bytes")); } - static double readDouble(final String nicName, final String fileName) { + double readDouble(final String nicName, final String fileName) { final String path = "/sys/class/net/" + nicName + "/statistics/" + fileName; try { return Double.parseDouble(FileUtils.readFileToString(new File(path))); } catch (final IOException ioe) { - s_logger.warn("Failed to read the " + fileName + " for " + nicName + " from " + path, ioe); + LOGGER.warn("Failed to read the " + fileName + " for " + nicName + " from " + path, ioe); return 0.0; } } @@ -4998,11 +5102,11 @@ public String mapRbdDevice(final KVMPhysicalDisk disk){ } public List> cleanVMSnapshotMetadata(Domain dm) throws LibvirtException { - s_logger.debug("Cleaning the metadata of vm snapshots of vm " + dm.getName()); + LOGGER.debug("Cleaning the metadata of vm snapshots of vm " + dm.getName()); List> vmsnapshots = new ArrayList>(); if (dm.snapshotNum() == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("VM [%s] does not have any snapshots. Skipping cleanup of snapshots for this VM.", dm.getName())); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("VM [%s] does not have any snapshots. Skipping cleanup of snapshots for this VM.", dm.getName())); } return vmsnapshots; } @@ -5010,8 +5114,8 @@ public List> cleanVMSnapshotMetadata(Domain dm) try { DomainSnapshot snapshotCurrent = dm.snapshotCurrent(); String snapshotXML = snapshotCurrent.getXMLDesc(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Current snapshot of VM [%s] has the following XML: [%s].", dm.getName(), snapshotXML)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("Current snapshot of VM [%s] has the following XML: [%s].", dm.getName(), snapshotXML)); } snapshotCurrent.free(); @@ -5026,23 +5130,23 @@ public List> cleanVMSnapshotMetadata(Domain dm) currentSnapshotName = getTagValue("name", rootElement); } catch (ParserConfigurationException | SAXException | IOException e) { - s_logger.error(String.format("Failed to parse snapshot configuration [%s] of VM [%s] due to: [%s].", snapshotXML, dm.getName(), e.getMessage()), e); + LOGGER.error(String.format("Failed to parse snapshot configuration [%s] of VM [%s] due to: [%s].", snapshotXML, dm.getName(), e.getMessage()), e); } } catch (LibvirtException e) { - s_logger.error(String.format("Failed to get the current snapshot of VM [%s] due to: [%s]. Continuing the migration process.", dm.getName(), e.getMessage()), e); + LOGGER.error(String.format("Failed to get the current snapshot of VM [%s] due to: [%s]. Continuing the migration process.", dm.getName(), e.getMessage()), e); } int flags = 2; // VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY = 2 String[] snapshotNames = dm.snapshotListNames(); Arrays.sort(snapshotNames); - s_logger.debug(String.format("Found [%s] snapshots in VM [%s] to clean.", snapshotNames.length, dm.getName())); + LOGGER.debug(String.format("Found [%s] snapshots in VM [%s] to clean.", snapshotNames.length, dm.getName())); for (String snapshotName: snapshotNames) { DomainSnapshot snapshot = dm.snapshotLookupByName(snapshotName); Boolean isCurrent = (currentSnapshotName != null && currentSnapshotName.equals(snapshotName)) ? true: false; vmsnapshots.add(new Ternary(snapshotName, isCurrent, snapshot.getXMLDesc())); } for (String snapshotName: snapshotNames) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Cleaning snapshot [%s] of VM [%s] metadata.", snapshotNames, dm.getName())); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("Cleaning snapshot [%s] of VM [%s] metadata.", snapshotNames, dm.getName())); } DomainSnapshot snapshot = dm.snapshotLookupByName(snapshotName); snapshot.delete(flags); // clean metadata of vm snapshot @@ -5076,12 +5180,12 @@ private static String getTagValue(String tag, Element eElement) { } public void restoreVMSnapshotMetadata(Domain dm, String vmName, List> vmsnapshots) { - s_logger.debug("Restoring the metadata of vm snapshots of vm " + vmName); + LOGGER.debug("Restoring the metadata of vm snapshots of vm " + vmName); for (Ternary vmsnapshot: vmsnapshots) { String snapshotName = vmsnapshot.first(); Boolean isCurrent = vmsnapshot.second(); String snapshotXML = vmsnapshot.third(); - s_logger.debug("Restoring vm snapshot " + snapshotName + " on " + vmName + " with XML:\n " + snapshotXML); + LOGGER.debug("Restoring vm snapshot " + snapshotName + " on " + vmName + " with XML:\n " + snapshotXML); try { int flags = 1; // VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = 1 if (isCurrent) { @@ -5089,7 +5193,7 @@ public void restoreVMSnapshotMetadata(Domain dm, String vmName, List details) { + protected void setCpuTopology(CpuModeDef cmd, int vCpusInDef, Map details) { if (!enableManuallySettingCpuTopologyOnKvmVm) { - s_logger.debug(String.format("Skipping manually setting CPU topology on VM's XML due to it is disabled in agent.properties {\"property\": \"%s\", \"value\": %s}.", + LOGGER.debug(String.format("Skipping manually setting CPU topology on VM's XML due to it is disabled in agent.properties {\"property\": \"%s\", \"value\": %s}.", AgentProperties.ENABLE_MANUALLY_SETTING_CPU_TOPOLOGY_ON_KVM_VM.getName(), enableManuallySettingCpuTopologyOnKvmVm)); return; } - // multi cores per socket, for larger core configs - int numCoresPerSocket = -1; + + int numCoresPerSocket = 1; + int numThreadsPerCore = 1; + if (details != null) { - final String coresPerSocket = details.get(VmDetailConstants.CPU_CORE_PER_SOCKET); - final int intCoresPerSocket = NumbersUtil.parseInt(coresPerSocket, numCoresPerSocket); - if (intCoresPerSocket > 0 && vCpusInDef % intCoresPerSocket == 0) { - numCoresPerSocket = intCoresPerSocket; - } + numCoresPerSocket = NumbersUtil.parseInt(details.get(VmDetailConstants.CPU_CORE_PER_SOCKET), 1); + numThreadsPerCore = NumbersUtil.parseInt(details.get(VmDetailConstants.CPU_THREAD_PER_CORE), 1); } - if (numCoresPerSocket <= 0) { + + if ((numCoresPerSocket * numThreadsPerCore) > vCpusInDef) { + LOGGER.warn(String.format("cores per socket (%d) * threads per core (%d) exceeds total VM cores. Ignoring extra topology", numCoresPerSocket, numThreadsPerCore)); + numCoresPerSocket = 1; + numThreadsPerCore = 1; + } + + if (vCpusInDef % (numCoresPerSocket * numThreadsPerCore) != 0) { + LOGGER.warn(String.format("cores per socket(%d) * threads per core(%d) doesn't divide evenly into total VM cores(%d). Ignoring extra topology", numCoresPerSocket, numThreadsPerCore, vCpusInDef)); + numCoresPerSocket = 1; + numThreadsPerCore = 1; + } + + // Set default coupling (makes 4 or 6 core sockets for larger core configs) + int numTotalSockets = 1; + if (numCoresPerSocket == 1 && numThreadsPerCore == 1) { if (vCpusInDef % 6 == 0) { numCoresPerSocket = 6; } else if (vCpusInDef % 4 == 0) { numCoresPerSocket = 4; } + numTotalSockets = vCpusInDef / numCoresPerSocket; + } else { + int nTotalCores = vCpusInDef / numThreadsPerCore; + numTotalSockets = nTotalCores / numCoresPerSocket; } - if (numCoresPerSocket > 0) { - cmd.setTopology(numCoresPerSocket, vCpusInDef / numCoresPerSocket); - } + + cmd.setTopology(numCoresPerSocket, numThreadsPerCore, numTotalSockets); } public void setBackingFileFormat(String volPath) { @@ -5231,14 +5352,14 @@ public void setBackingFileFormat(String volPath) { // VMs which are created in CloudStack 4.14 and before cannot be started or migrated // in latest Linux distributions due to missing backing file format // Please refer to https://libvirt.org/kbase/backing_chains.html#vm-refuses-to-start-due-to-misconfigured-backing-store-format - s_logger.info("Setting backing file format of " + volPath); + LOGGER.info("Setting backing file format of " + volPath); QemuImgFile backingFile = new QemuImgFile(backingFilePath); Map backingFileinfo = qemu.info(backingFile); String backingFileFmt = backingFileinfo.get(QemuImg.FILE_FORMAT); qemu.rebase(file, backingFile, backingFileFmt, false); } } catch (QemuImgException | LibvirtException e) { - s_logger.error("Failed to set backing file format of " + volPath + " due to : " + e.getMessage(), e); + LOGGER.error("Failed to set backing file format of " + volPath + " due to : " + e.getMessage(), e); } } @@ -5276,7 +5397,7 @@ public static Integer getCpuShares(Domain dm) throws LibvirtException { return Integer.parseInt(c.getValueAsString()); } } - s_logger.warn(String.format("Could not get cpu_shares of domain: [%s]. Returning default value of 0. ", dm.getName())); + LOGGER.warn(String.format("Could not get cpu_shares of domain: [%s]. Returning default value of 0. ", dm.getName())); return 0; } @@ -5322,7 +5443,7 @@ public String createLibvirtVolumeSecret(Connect conn, String consumer, byte[] da Match match = new Match(); if (UuidUtils.getUuidRegex().matches(ex.getMessage(), match)) { secretUuid = match.getCapturedText(0); - s_logger.info(String.format("Reusing previously defined secret '%s' for volume '%s'", secretUuid, consumer)); + LOGGER.info(String.format("Reusing previously defined secret '%s' for volume '%s'", secretUuid, consumer)); } else { throw ex; } @@ -5340,12 +5461,12 @@ public void removeLibvirtVolumeSecret(Connect conn, String secretUuid) throws Li secret.undefine(); } catch (LibvirtException ex) { if (ex.getMessage().contains("Secret not found")) { - s_logger.debug(String.format("Secret uuid %s doesn't exist", secretUuid)); + LOGGER.debug(String.format("Secret uuid %s doesn't exist", secretUuid)); return; } throw ex; } - s_logger.debug(String.format("Undefined secret %s", secretUuid)); + LOGGER.debug(String.format("Undefined secret %s", secretUuid)); } public void cleanOldSecretsByDiskDef(Connect conn, List disks) throws LibvirtException { @@ -5374,7 +5495,7 @@ public void setInterfaceDefQueueSettings(Map details, Integer cp interfaceDef.setMultiQueueNumber(nicMultiqueueNumberInteger); } } catch (NumberFormatException ex) { - s_logger.warn(String.format("VM details %s is not a valid integer value %s", VmDetailConstants.NIC_MULTIQUEUE_NUMBER, nicMultiqueueNumber)); + logger.warn(String.format("VM details %s is not a valid integer value %s", VmDetailConstants.NIC_MULTIQUEUE_NUMBER, nicMultiqueueNumber)); } } String nicPackedEnabled = details.get(VmDetailConstants.NIC_PACKED_VIRTQUEUES_ENABLED); @@ -5382,7 +5503,7 @@ public void setInterfaceDefQueueSettings(Map details, Integer cp try { interfaceDef.setPackedVirtQueues(Boolean.valueOf(nicPackedEnabled)); } catch (NumberFormatException ex) { - s_logger.warn(String.format("VM details %s is not a valid Boolean value %s", VmDetailConstants.NIC_PACKED_VIRTQUEUES_ENABLED, nicPackedEnabled)); + logger.warn(String.format("VM details %s is not a valid Boolean value %s", VmDetailConstants.NIC_PACKED_VIRTQUEUES_ENABLED, nicPackedEnabled)); } } } @@ -5397,11 +5518,11 @@ public String copyVolume(String srcIp, String username, String password, String command.append(remoteFile); command.append(" " + tmpPath); command.append(outputFile); - s_logger.debug(String.format("Converting remote disk file: %s, output file: %s%s (timeout: %d secs)", remoteFile, tmpPath, outputFile, timeoutInSecs)); + logger.debug(String.format("Converting remote disk file: %s, output file: %s%s (timeout: %d secs)", remoteFile, tmpPath, outputFile, timeoutInSecs)); SshHelper.sshExecute(srcIp, 22, username, null, password, command.toString(), timeoutInSecs * 1000); - s_logger.debug("Copying converted remote disk file " + outputFile + " to: " + localDir); + logger.debug("Copying converted remote disk file " + outputFile + " to: " + localDir); SshHelper.scpFrom(srcIp, 22, username, null, password, localDir, tmpPath + outputFile); - s_logger.debug("Successfully copied converted remote disk file to: " + localDir + "/" + outputFile); + logger.debug("Successfully copied converted remote disk file to: " + localDir + "/" + outputFile); return outputFile; } catch (Exception e) { try { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java index 0fa012b2c908..cbb5d85b712c 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java @@ -21,7 +21,8 @@ import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.Library; import org.libvirt.LibvirtException; @@ -30,7 +31,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; public class LibvirtConnection { - private static final Logger s_logger = Logger.getLogger(LibvirtConnection.class); + protected static Logger LOGGER = LogManager.getLogger(LibvirtConnection.class); static private Map s_connections = new HashMap(); static private Connect s_connection; @@ -42,29 +43,29 @@ static public Connect getConnection() throws LibvirtException { } static synchronized public Connect getConnection(String hypervisorURI) throws LibvirtException { - s_logger.debug("Looking for libvirtd connection at: " + hypervisorURI); + LOGGER.debug("Looking for libvirtd connection at: " + hypervisorURI); Connect conn = s_connections.get(hypervisorURI); if (conn == null) { - s_logger.info("No existing libvirtd connection found. Opening a new one"); + LOGGER.info("No existing libvirtd connection found. Opening a new one"); setupEventListener(); conn = new Connect(hypervisorURI, false); - s_logger.debug("Successfully connected to libvirt at: " + hypervisorURI); + LOGGER.debug("Successfully connected to libvirt at: " + hypervisorURI); s_connections.put(hypervisorURI, conn); } else { try { conn.getVersion(); } catch (LibvirtException e) { - s_logger.error("Connection with libvirtd is broken: " + e.getMessage()); + LOGGER.error("Connection with libvirtd is broken: " + e.getMessage()); try { conn.close(); } catch (LibvirtException closeEx) { - s_logger.debug("Ignoring error while trying to close broken connection:" + closeEx.getMessage()); + LOGGER.debug("Ignoring error while trying to close broken connection:" + closeEx.getMessage()); } - s_logger.debug("Opening a new libvirtd connection to: " + hypervisorURI); + LOGGER.debug("Opening a new libvirtd connection to: " + hypervisorURI); setupEventListener(); conn = new Connect(hypervisorURI, false); s_connections.put(hypervisorURI, conn); @@ -84,11 +85,11 @@ static public Connect getConnectionByVmName(String vmName) throws LibvirtExcepti return conn; } } catch (Exception e) { - s_logger.debug("Can not find " + hypervisor.toString() + " connection for Instance: " + vmName + ", continuing."); + LOGGER.debug("Can not find " + hypervisor.toString() + " connection for Instance: " + vmName + ", continuing."); } } - s_logger.warn("Can not find a connection for Instance " + vmName + ". Assuming the default connection."); + LOGGER.warn("Can not find a connection for Instance " + vmName + ". Assuming the default connection."); // return the default connection return getConnection(); } @@ -122,7 +123,7 @@ static String getHypervisorURI(String hypervisorType) { */ private static synchronized void setupEventListener() throws LibvirtException { if (!AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_EVENTS_ENABLED)) { - s_logger.debug("Libvirt event listening is disabled, not setting up event loop"); + LOGGER.debug("Libvirt event listening is disabled, not setting up event loop"); return; } @@ -135,9 +136,9 @@ private static synchronized void setupEventListener() throws LibvirtException { // This blocking call contains a loop of its own that will process events until the event loop is stopped or exception is thrown. Library.runEventLoop(); } catch (LibvirtException e) { - s_logger.error("LibvirtException was thrown in event loop: ", e); + LOGGER.error("LibvirtException was thrown in event loop: ", e); } catch (InterruptedException e) { - s_logger.error("Libvirt event loop was interrupted: ", e); + LOGGER.error("Libvirt event loop was interrupted: ", e); } } }); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainListener.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainListener.java index 281de01c5da5..5adb383c6cd6 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainListener.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainListener.java @@ -15,7 +15,8 @@ package com.cloud.hypervisor.kvm.resource; import com.cloud.resource.AgentStatusUpdater; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Domain; import org.libvirt.LibvirtException; import org.libvirt.event.DomainEvent; @@ -24,7 +25,7 @@ import org.libvirt.event.StoppedDetail; public class LibvirtDomainListener implements LifecycleListener { - private static final Logger LOGGER = Logger.getLogger(LibvirtDomainListener.class); + private static final Logger LOGGER = LogManager.getLogger(LibvirtDomainListener.class); private final AgentStatusUpdater agentStatusUpdater; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java index a0dd270f999b..46620e77fdab 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java @@ -29,7 +29,8 @@ import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.lang3.StringUtils; import org.apache.cloudstack.utils.qemu.QemuObject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -49,7 +50,7 @@ import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.WatchDogDef.WatchDogModel; public class LibvirtDomainXMLParser { - private static final Logger s_logger = Logger.getLogger(LibvirtDomainXMLParser.class); + protected Logger logger = LogManager.getLogger(getClass()); private final List interfaces = new ArrayList(); private MemBalloonDef memBalloonDef = new MemBalloonDef(); private final List diskDefs = new ArrayList(); @@ -332,7 +333,7 @@ public boolean parseDomainXML(String domXML) { String bytes = getAttrValue("rate", "bytes", rng); String period = getAttrValue("rate", "period", rng); if (StringUtils.isAnyEmpty(bytes, period)) { - s_logger.debug(String.format("Bytes and period in the rng section should not be null, please check the VM %s", name)); + logger.debug(String.format("Bytes and period in the rng section should not be null, please check the VM %s", name)); } if (bytes == null) { @@ -390,11 +391,11 @@ public boolean parseDomainXML(String domXML) { extractCpuModeDef(rootElement); return true; } catch (ParserConfigurationException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (SAXException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (IOException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } return false; } @@ -544,8 +545,9 @@ private void extractCpuModeDef(final Element rootElement){ } final String sockets = getAttrValue("topology", "sockets", cpuModeDefElement); final String cores = getAttrValue("topology", "cores", cpuModeDefElement); - if (StringUtils.isNotBlank(sockets) && StringUtils.isNotBlank(cores)) { - cpuModeDef.setTopology(Integer.parseInt(cores), Integer.parseInt(sockets)); + final String threads = getAttrValue("topology", "threads", cpuModeDefElement); + if (StringUtils.isNotBlank(sockets) && StringUtils.isNotBlank(cores) && StringUtils.isNotBlank(threads)) { + cpuModeDef.setTopology(Integer.parseInt(cores), Integer.parseInt(threads), Integer.parseInt(sockets)); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtExtendedVmStatsEntry.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtExtendedVmStatsEntry.java new file mode 100644 index 000000000000..8e0e4a2ae274 --- /dev/null +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtExtendedVmStatsEntry.java @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.hypervisor.kvm.resource; + +import com.cloud.agent.api.VmStatsEntry; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; + +import java.util.Calendar; + +public class LibvirtExtendedVmStatsEntry extends VmStatsEntry { + private long cpuTime; + private Calendar timestamp; + + public LibvirtExtendedVmStatsEntry() { + } + + public long getCpuTime() { + return cpuTime; + } + + public void setCpuTime(long cpuTime) { + this.cpuTime = cpuTime; + } + + public Calendar getTimestamp() { + return timestamp; + } + + public void setTimestamp(Calendar timestamp) { + this.timestamp = timestamp; + } + + @Override + public String toString() { + return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "cpuTime", "networkWriteKBs", "networkReadKBs", "diskReadIOs", "diskWriteIOs", "diskReadKBs", "diskWriteKBs"); + } +} diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtKvmAgentHook.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtKvmAgentHook.java index 2ef65293de2e..edcc5a053269 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtKvmAgentHook.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtKvmAgentHook.java @@ -22,7 +22,8 @@ import groovy.util.GroovyScriptEngine; import groovy.util.ResourceException; import groovy.util.ScriptException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack; import java.io.File; @@ -34,14 +35,14 @@ public class LibvirtKvmAgentHook { private final GroovyScriptEngine gse; private final Binding binding = new Binding(); - private static final Logger s_logger = Logger.getLogger(LibvirtKvmAgentHook.class); + protected Logger logger = LogManager.getLogger(getClass()); public LibvirtKvmAgentHook(String path, String script, String method) throws IOException { this.script = script; this.method = method; File full_path = new File(path, script); if (!full_path.canRead()) { - s_logger.warn("Groovy script '" + full_path.toString() + "' is not available. Transformations will not be applied."); + logger.warn("Groovy script '" + full_path.toString() + "' is not available. Transformations will not be applied."); this.gse = null; } else { this.gse = new GroovyScriptEngine(path); @@ -54,21 +55,21 @@ public boolean isInitialized() { public Object handle(Object arg) throws ResourceException, ScriptException { if (!isInitialized()) { - s_logger.warn("Groovy scripting engine is not initialized. Data transformation skipped."); + logger.warn("Groovy scripting engine is not initialized. Data transformation skipped."); return arg; } GroovyObject cls = (GroovyObject) this.gse.run(this.script, binding); if (null == cls) { - s_logger.warn("Groovy object is not received from script '" + this.script + "'."); + logger.warn("Groovy object is not received from script '" + this.script + "'."); return arg; } else { - Object[] params = {s_logger, arg}; + Object[] params = {logger, arg}; try { Object res = cls.invokeMethod(this.method, params); return res; } catch (MissingMethodExceptionNoStack e) { - s_logger.error("Error occurred when calling method from groovy script, {}", e); + logger.error("Error occurred when calling method from groovy script, {}", e); return arg; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolDef.java index 4f8b2843ec20..09ee45d59089 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolDef.java @@ -24,7 +24,7 @@ public class LibvirtStoragePoolDef { public enum PoolType { - ISCSI("iscsi"), NETFS("netfs"), LOGICAL("logical"), DIR("dir"), RBD("rbd"), GLUSTERFS("glusterfs"), POWERFLEX("powerflex"); + ISCSI("iscsi"), NETFS("netfs"), loggerICAL("logical"), DIR("dir"), RBD("rbd"), GLUSTERFS("glusterfs"), POWERFLEX("powerflex"); String _poolType; PoolType(String poolType) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java index a39ff07708e8..430e4ef851fc 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java @@ -26,7 +26,8 @@ import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -35,7 +36,7 @@ import org.xml.sax.SAXException; public class LibvirtStoragePoolXMLParser { - private static final Logger s_logger = Logger.getLogger(LibvirtStoragePoolXMLParser.class); + protected Logger logger = LogManager.getLogger(getClass()); private List getNFSMountOptsFromRootElement(Element rootElement) { List nfsMountOpts = new ArrayList<>(); @@ -118,11 +119,11 @@ public LibvirtStoragePoolDef parseStoragePoolXML(String poolXML) { } } } catch (ParserConfigurationException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (SAXException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (IOException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } return null; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java index c4132ca1ba3b..1b6f73039ca5 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java @@ -23,7 +23,8 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.cloudstack.utils.security.ParserUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -32,7 +33,7 @@ import org.xml.sax.SAXException; public class LibvirtStorageVolumeXMLParser { - private static final Logger s_logger = Logger.getLogger(LibvirtStorageVolumeXMLParser.class); + protected Logger logger = LogManager.getLogger(getClass()); public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) { DocumentBuilder builder; @@ -51,11 +52,11 @@ public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) { Long capacity = Long.parseLong(getTagValue("capacity", rootElement)); return new LibvirtStorageVolumeDef(VolName, capacity, LibvirtStorageVolumeDef.VolumeFormat.getFormat(format), null, null); } catch (ParserConfigurationException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (SAXException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (IOException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } return null; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index cfd72c28b5af..0f11c12f101f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -26,13 +26,14 @@ import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; public class LibvirtVMDef { - private static final Logger s_logger = Logger.getLogger(LibvirtVMDef.class); + protected static Logger LOGGER = LogManager.getLogger(LibvirtVMDef.class); private String _hvsType; private static long s_libvirtVersion; @@ -94,6 +95,8 @@ public String toString() { } private GuestType _type; + private String manufacturer; + private String product; private BootType _boottype; private BootMode _bootmode; private String _arch; @@ -123,6 +126,28 @@ public GuestType getGuestType() { return _type; } + public String getManufacturer() { + if (StringUtils.isEmpty(manufacturer)) { + return "Apache Software Foundation"; + } + return manufacturer; + } + + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + + public String getProduct() { + if (StringUtils.isEmpty(product)) { + return "CloudStack KVM Hypervisor"; + } + return product; + } + + public void setProduct(String product) { + this.product = product; + } + public void setNvram(String nvram) { _nvram = nvram; } public void setNvramTemplate(String nvramTemplate) { _nvramTemplate = nvramTemplate; } @@ -181,9 +206,10 @@ public String toString() { guestDef.append("\n"); guestDef.append("\n"); - guestDef.append("Apache Software Foundation\n"); - guestDef.append("CloudStack " + _type.toString() + " Hypervisor\n"); + guestDef.append("" + getManufacturer() +"\n"); + guestDef.append("" + getProduct() + "\n"); guestDef.append("" + _uuid + "\n"); + guestDef.append("" + _uuid + "\n"); guestDef.append("\n"); guestDef.append("\n"); @@ -593,6 +619,22 @@ public LibvirtDiskEncryptDetails(String passphraseUuid, QemuObject.EncryptFormat public QemuObject.EncryptFormat getEncryptFormat() { return this.encryptFormat; } } + public static class DiskGeometry { + int cylinders; + int heads; + int sectors; + + public DiskGeometry(int cylinders, int heads, int sectors) { + this.cylinders = cylinders; + this.heads = heads; + this.sectors = sectors; + } + + public String toXml() { + return String.format("\n", this.cylinders, this.heads, this.sectors); + } + } + public enum DeviceType { FLOPPY("floppy"), DISK("disk"), CDROM("cdrom"), LUN("lun"); String _type; @@ -697,6 +739,18 @@ public String toString() { } + public enum BlockIOSize { + SIZE_512("512"), SIZE_4K("4096"); + final String blockSize; + + BlockIOSize(String size) { this.blockSize = size; } + + @Override + public String toString() { + return blockSize; + } + } + private DeviceType _deviceType; /* floppy, disk, cdrom */ private DiskType _diskType; private DiskProtocol _diskProtocol; @@ -730,6 +784,9 @@ public String toString() { private IoDriverPolicy ioDriver; private LibvirtDiskEncryptDetails encryptDetails; private boolean isIothreadsEnabled; + private BlockIOSize logicalBlockIOSize = null; + private BlockIOSize physicalBlockIOSize = null; + private DiskGeometry geometry = null; public DiscardType getDiscard() { return _discard; @@ -755,6 +812,10 @@ public void isIothreadsEnabled(boolean isIothreadsEnabled) { this.isIothreadsEnabled = isIothreadsEnabled; } + public void setPhysicalBlockIOSize(BlockIOSize size) { this.physicalBlockIOSize = size; } + + public void setLogicalBlockIOSize(BlockIOSize size) { this.logicalBlockIOSize = size; } + public void defFileBasedDisk(String filePath, String diskLabel, DiskBus bus, DiskFmtType diskFmtType) { _diskType = DiskType.FILE; _deviceType = DeviceType.DISK; @@ -859,7 +920,7 @@ public void defISODisk(String volPath, Integer devId) { public void defISODisk(String volPath, Integer devId, String diskLabel) { if (devId == null && StringUtils.isBlank(diskLabel)) { - s_logger.debug(String.format("No ID or label informed for volume [%s].", volPath)); + LOGGER.debug(String.format("No ID or label informed for volume [%s].", volPath)); defISODisk(volPath); return; } @@ -869,11 +930,11 @@ public void defISODisk(String volPath, Integer devId, String diskLabel) { _sourcePath = volPath; if (StringUtils.isNotBlank(diskLabel)) { - s_logger.debug(String.format("Using informed label [%s] for volume [%s].", diskLabel, volPath)); + LOGGER.debug(String.format("Using informed label [%s] for volume [%s].", diskLabel, volPath)); _diskLabel = diskLabel; } else { _diskLabel = getDevLabel(devId, DiskBus.IDE, true); - s_logger.debug(String.format("Using device ID [%s] to define the label [%s] for volume [%s].", devId, _diskLabel, volPath)); + LOGGER.debug(String.format("Using device ID [%s] to define the label [%s] for volume [%s].", devId, _diskLabel, volPath)); } _diskFmtType = DiskFmtType.RAW; @@ -1070,9 +1131,20 @@ public void setSerial(String serial) { this._serial = serial; } - public void setLibvirtDiskEncryptDetails(LibvirtDiskEncryptDetails details) { this.encryptDetails = details; } + public void setLibvirtDiskEncryptDetails(LibvirtDiskEncryptDetails details) + { + this.encryptDetails = details; + } + + public LibvirtDiskEncryptDetails getLibvirtDiskEncryptDetails() + { + return this.encryptDetails; + } - public LibvirtDiskEncryptDetails getLibvirtDiskEncryptDetails() { return this.encryptDetails; } + public void setGeometry(DiskGeometry geometry) + { + this.geometry = geometry; + } public String getSourceHost() { return _sourceHost; @@ -1157,6 +1229,21 @@ public String toString() { } diskBuilder.append("/>\n"); + if (geometry != null) { + diskBuilder.append(geometry.toXml()); + } + + if (logicalBlockIOSize != null || physicalBlockIOSize != null) { + diskBuilder.append("\n"); + } + if (_serial != null && !_serial.isEmpty() && _deviceType != DeviceType.LUN) { diskBuilder.append("" + _serial + "\n"); } @@ -1696,6 +1783,7 @@ public static class CpuModeDef { private String _model; private List _features; private int _coresPerSocket = -1; + private int _threadsPerCore = -1; private int _sockets = -1; public void setMode(String mode) { @@ -1712,8 +1800,9 @@ public void setModel(String model) { _model = model; } - public void setTopology(int coresPerSocket, int sockets) { + public void setTopology(int coresPerSocket, int threadsPerCore, int sockets) { _coresPerSocket = coresPerSocket; + _threadsPerCore = threadsPerCore; _sockets = sockets; } @@ -1742,9 +1831,9 @@ public String toString() { } } - // add topology - if (_sockets > 0 && _coresPerSocket > 0) { - modeBuilder.append(""); + // add topology. Note we require sockets, cores, and threads defined + if (_sockets > 0 && _coresPerSocket > 0 && _threadsPerCore > 0) { + modeBuilder.append(""); } // close cpu def @@ -1755,6 +1844,8 @@ public String toString() { public int getCoresPerSocket() { return _coresPerSocket; } + public int getThreadsPerCore() { return _threadsPerCore; } + public int getSockets() { return _sockets; } } public static class SerialDef { @@ -2071,7 +2162,7 @@ public String toString() { } } - public static class MetadataDef { + public class MetadataDef { Map customNodes = new HashMap<>(); public T getMetadataNode(Class fieldClass) { @@ -2081,7 +2172,7 @@ public T getMetadataNode(Class fieldClass) { field = fieldClass.newInstance(); customNodes.put(field.getClass().getName(), field); } catch (InstantiationException | IllegalAccessException e) { - s_logger.debug("No default constructor available in class " + fieldClass.getName() + ", ignoring exception", e); + LOGGER.debug("No default constructor available in class " + fieldClass.getName() + ", ignoring exception", e); } } return field; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtXMLParser.java index 48a379c278f3..f5de9b754120 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtXMLParser.java @@ -24,13 +24,14 @@ import javax.xml.parsers.SAXParserFactory; import org.apache.cloudstack.utils.security.ParserUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class LibvirtXMLParser extends DefaultHandler { - private static final Logger s_logger = Logger.getLogger(LibvirtXMLParser.class); + protected Logger logger = LogManager.getLogger(getClass()); protected static final SAXParserFactory s_spf; static { s_spf = ParserUtils.getSaferSAXParserFactory(); @@ -43,9 +44,9 @@ public LibvirtXMLParser() { _sp = s_spf.newSAXParser(); _initialized = true; } catch (ParserConfigurationException e) { - s_logger.trace("Ignoring xml parser error.", e); + logger.trace("Ignoring xml parser error.", e); } catch (SAXException e) { - s_logger.trace("Ignoring xml parser error.", e); + logger.trace("Ignoring xml parser error.", e); } } @@ -57,9 +58,9 @@ public boolean parseDomainXML(String domXML) { _sp.parse(new InputSource(new StringReader(domXML)), this); return true; } catch (SAXException se) { - s_logger.warn(se.getMessage()); + logger.warn(se.getMessage()); } catch (IOException ie) { - s_logger.error(ie.getMessage()); + logger.error(ie.getMessage()); } return false; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/MigrateKVMAsync.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/MigrateKVMAsync.java index bc94bb47ed81..ae8d06a19866 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/MigrateKVMAsync.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/MigrateKVMAsync.java @@ -22,7 +22,8 @@ import java.util.Set; import java.util.concurrent.Callable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.LibvirtException; @@ -31,7 +32,7 @@ import org.libvirt.TypedUlongParameter; public class MigrateKVMAsync implements Callable { - protected Logger logger = Logger.getLogger(getClass()); + protected Logger logger = LogManager.getLogger(getClass()); private final LibvirtComputingResource libvirtComputingResource; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java index 3c4c9d48c9d6..e3ce9f4b8a62 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java @@ -30,7 +30,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -45,7 +44,6 @@ import com.cloud.utils.script.Script; public class OvsVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(OvsVifDriver.class); private int _timeout; private String _controlCidr = NetUtils.getLinkLocalCIDR(); private DpdkDriver dpdkDriver; @@ -68,10 +66,10 @@ public void configure(Map params) throws ConfigurationException public void getPifs() { final String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'"); - s_logger.debug("cmdout was " + cmdout); + logger.debug("cmdout was " + cmdout); final List bridges = Arrays.asList(cmdout.split("%")); for (final String bridge : bridges) { - s_logger.debug("looking for pif for bridge " + bridge); + logger.debug("looking for pif for bridge " + bridge); // String pif = getOvsPif(bridge); // Not really interested in the pif name at this point for ovs // bridges @@ -84,7 +82,7 @@ public void getPifs() { } _pifs.put(bridge, pif); } - s_logger.debug("done looking for pifs, no more bridges"); + logger.debug("done looking for pifs, no more bridges"); } /** @@ -94,7 +92,7 @@ public void getPifs() { */ protected void plugDPDKInterface(InterfaceDef intf, String trafficLabel, Map extraConfig, String vlanId, String guestOsType, NicTO nic, String nicAdapter) { - s_logger.debug("DPDK support enabled: configuring per traffic label " + trafficLabel); + logger.debug("DPDK support enabled: configuring per traffic label " + trafficLabel); String dpdkOvsPath = _libvirtComputingResource.dpdkOvsPath; if (StringUtils.isBlank(dpdkOvsPath)) { throw new CloudRuntimeException("DPDK is enabled on the host but no OVS path has been provided"); @@ -111,7 +109,7 @@ protected void plugDPDKInterface(InterfaceDef intf, String trafficLabel, Map extraConfig) throws InternalErrorException, LibvirtException { - s_logger.debug("plugging nic=" + nic); + logger.debug("plugging nic=" + nic); LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef(); if (!_libvirtComputingResource.dpdkSupport || !nic.isDpdkEnabled()) { @@ -139,7 +137,7 @@ public InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter, Map _pifs; protected Map _bridges; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceAgentExecutor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceAgentExecutor.java index 7635b81b918c..6ba3d510dd8f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceAgentExecutor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceAgentExecutor.java @@ -21,14 +21,12 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.joda.time.Duration; import java.io.File; public class RollingMaintenanceAgentExecutor extends RollingMaintenanceExecutorBase implements RollingMaintenanceExecutor { - private static final Logger s_logger = Logger.getLogger(RollingMaintenanceAgentExecutor.class); private String output; private boolean success; @@ -41,17 +39,17 @@ public RollingMaintenanceAgentExecutor(String hooksDir) { public Pair startStageExecution(String stage, File scriptFile, int timeout, String payload) { checkHooksDirectory(); Duration duration = Duration.standardSeconds(timeout); - final Script script = new Script(scriptFile.getAbsolutePath(), duration, s_logger); + final Script script = new Script(scriptFile.getAbsolutePath(), duration, logger); final OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); if (StringUtils.isNotEmpty(payload)) { script.add(payload); } - s_logger.info("Executing stage: " + stage + " script: " + script); + logger.info("Executing stage: " + stage + " script: " + script); output = script.execute(parser) + " " + parser.getLines(); if (script.isTimeout()) { String msg = "Script " + scriptFile + " timed out"; - s_logger.error(msg); + logger.error(msg); success = false; return new Pair<>(false, msg); } @@ -62,10 +60,10 @@ public Pair startStageExecution(String stage, File scriptFile, } success = exitValue == 0 || exitValue == exitValueAvoidMaintenance; setAvoidMaintenance(exitValue == exitValueAvoidMaintenance); - s_logger.info("Execution finished for stage: " + stage + " script: " + script + ": " + exitValue); - if (s_logger.isDebugEnabled()) { - s_logger.debug(output); - s_logger.debug("Stage " + stage + " execution finished: " + exitValue); + logger.info("Execution finished for stage: " + stage + " script: " + script + ": " + exitValue); + if (logger.isDebugEnabled()) { + logger.debug(output); + logger.debug("Stage " + stage + " execution finished: " + exitValue); } return new Pair<>(true, "Stage " + stage + " finished"); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceExecutorBase.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceExecutorBase.java index 70c8e1983d61..b74faca0ecf6 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceExecutorBase.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceExecutorBase.java @@ -18,7 +18,8 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.io.File; @@ -30,7 +31,7 @@ public abstract class RollingMaintenanceExecutorBase implements RollingMaintenan static final int exitValueAvoidMaintenance = 70; static final int exitValueTerminatedSignal = 143; - private static final Logger s_logger = Logger.getLogger(RollingMaintenanceExecutor.class); + protected Logger logger = LogManager.getLogger(getClass()); void setTimeout(int timeout) { this.timeout = timeout; @@ -66,7 +67,7 @@ public File getStageScriptFile(String stage) { return new File(scriptPath + ".py"); } else { String msg = "Unable to locate script for stage: " + stage + " in directory: " + hooksDir; - s_logger.warn(msg); + logger.warn(msg); return null; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java index bf8147ac8534..c9edcc104b7c 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java @@ -21,7 +21,6 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; import java.io.IOException; @@ -36,7 +35,6 @@ public class RollingMaintenanceServiceExecutor extends RollingMaintenanceExecuto private static final String resultsFileSuffix = "rolling-maintenance-results"; private static final String outputFileSuffix = "rolling-maintenance-output"; - private static final Logger s_logger = Logger.getLogger(RollingMaintenanceServiceExecutor.class); public RollingMaintenanceServiceExecutor(String hooksDir) { super(hooksDir); @@ -55,15 +53,15 @@ private String generateInstanceName(String stage, String file, String payload) { } private String invokeService(String action, String stage, String file, String payload) { - s_logger.debug("Invoking rolling maintenance service for stage: " + stage + " and file " + file + " with action: " + action); + logger.debug("Invoking rolling maintenance service for stage: " + stage + " and file " + file + " with action: " + action); final OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); - Script command = new Script("/bin/systemctl", s_logger); + Script command = new Script("/bin/systemctl", logger); command.add(action); String service = servicePrefix + "@" + generateInstanceName(stage, file, payload); command.add(service); String result = command.execute(parser); int exitValue = command.getExitValue(); - s_logger.trace("Execution: " + command.toString() + " - exit code: " + exitValue + + logger.trace("Execution: " + command.toString() + " - exit code: " + exitValue + ": " + result + (StringUtils.isNotBlank(parser.getLines()) ? parser.getLines() : "")); return StringUtils.isBlank(result) ? parser.getLines().replace("\n", " ") : result; } @@ -76,7 +74,7 @@ public Pair startStageExecution(String stage, File scriptFile, if (StringUtils.isNotBlank(result)) { throw new CloudRuntimeException("Error starting stage: " + stage + " execution: " + result); } - s_logger.trace("Stage " + stage + "execution started"); + logger.trace("Stage " + stage + "execution started"); return new Pair<>(true, "OK"); } @@ -111,7 +109,7 @@ public boolean isStageRunning(String stage, File scriptFile, String payload) { if (StringUtils.isNotBlank(result) && result.equals("failed")) { String status = invokeService("status", stage, scriptFile.getAbsolutePath(), payload); String errorMsg = "Stage " + stage + " execution failed, status: " + status; - s_logger.error(errorMsg); + logger.error(errorMsg); throw new CloudRuntimeException(errorMsg); } return StringUtils.isNotBlank(result) && result.equals("active"); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBackupSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBackupSnapshotCommandWrapper.java index 780fc35b563e..656a63d3db0a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBackupSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBackupSnapshotCommandWrapper.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.text.MessageFormat; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -56,7 +55,6 @@ @ResourceWrapper(handles = BackupSnapshotCommand.class) public final class LibvirtBackupSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtBackupSnapshotCommandWrapper.class); @Override public Answer execute(final BackupSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -104,7 +102,7 @@ public Answer execute(final BackupSnapshotCommand command, final LibvirtComputin r.confSet("key", primaryPool.getAuthSecret()); r.confSet("client_mount_timeout", "30"); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); final IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir()); final Rbd rbd = new Rbd(io); @@ -113,7 +111,7 @@ public Answer execute(final BackupSnapshotCommand command, final LibvirtComputin try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fh));) { final int chunkSize = 4194304; long offset = 0; - s_logger.debug("Backuping up RBD snapshot " + snapshotName + " to " + snapshotDestPath); + logger.debug("Backuping up RBD snapshot " + snapshotName + " to " + snapshotDestPath); while (true) { final byte[] buf = new byte[chunkSize]; final int bytes = image.read(offset, buf, chunkSize); @@ -123,21 +121,21 @@ public Answer execute(final BackupSnapshotCommand command, final LibvirtComputin bos.write(buf, 0, bytes); offset += bytes; } - s_logger.debug("Completed backing up RBD snapshot " + snapshotName + " to " + snapshotDestPath + ". Bytes written: " + toHumanReadableSize(offset)); + logger.debug("Completed backing up RBD snapshot " + snapshotName + " to " + snapshotDestPath + ". Bytes written: " + toHumanReadableSize(offset)); }catch(final IOException ex) { - s_logger.error("BackupSnapshotAnswer:Exception:"+ ex.getMessage()); + logger.error("BackupSnapshotAnswer:Exception:"+ ex.getMessage()); } r.ioCtxDestroy(io); } catch (final RadosException e) { - s_logger.error("A RADOS operation failed. The error was: " + e.getMessage()); + logger.error("A RADOS operation failed. The error was: " + e.getMessage()); return new BackupSnapshotAnswer(command, false, e.toString(), null, true); } catch (final RbdException e) { - s_logger.error("A RBD operation on " + snapshotDisk.getName() + " failed. The error was: " + e.getMessage()); + logger.error("A RBD operation on " + snapshotDisk.getName() + " failed. The error was: " + e.getMessage()); return new BackupSnapshotAnswer(command, false, e.toString(), null, true); } } else { - final Script scriptCommand = new Script(manageSnapshotPath, cmdsTimeout, s_logger); + final Script scriptCommand = new Script(manageSnapshotPath, cmdsTimeout, logger); scriptCommand.add("-b", snapshotDisk.getPath()); scriptCommand.add("-n", snapshotName); scriptCommand.add("-p", snapshotDestPath); @@ -145,7 +143,7 @@ public Answer execute(final BackupSnapshotCommand command, final LibvirtComputin final String result = scriptCommand.execute(); if (result != null) { - s_logger.debug("Failed to backup snaptshot: " + result); + logger.debug("Failed to backup snaptshot: " + result); return new BackupSnapshotAnswer(command, false, result, null, true); } } @@ -158,7 +156,7 @@ public Answer execute(final BackupSnapshotCommand command, final LibvirtComputin vm = libvirtComputingResource.getDomain(conn, command.getVmName()); state = vm.getInfo().state; } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + logger.trace("Ignoring libvirt error.", e); } } @@ -171,7 +169,7 @@ public Answer execute(final BackupSnapshotCommand command, final LibvirtComputin final String vmUuid = vm.getUUIDString(); final Object[] args = new Object[] {snapshotName, vmUuid}; final String snapshot = snapshotXML.format(args); - s_logger.debug(snapshot); + logger.debug(snapshot); final DomainSnapshot snap = vm.snapshotLookupByName(snapshotName); if (snap != null) { snap.delete(0); @@ -189,12 +187,12 @@ public Answer execute(final BackupSnapshotCommand command, final LibvirtComputin vm.resume(); } } else { - final Script scriptCommand = new Script(manageSnapshotPath, cmdsTimeout, s_logger); + final Script scriptCommand = new Script(manageSnapshotPath, cmdsTimeout, logger); scriptCommand.add("-d", snapshotDisk.getPath()); scriptCommand.add("-n", snapshotName); final String result = scriptCommand.execute(); if (result != null) { - s_logger.debug("Failed to backup snapshot: " + result); + logger.debug("Failed to backup snapshot: " + result); return new BackupSnapshotAnswer(command, false, "Failed to backup snapshot: " + result, null, true); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckAndRepairVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckAndRepairVolumeCommandWrapper.java index cd81a2fbc232..8dcdd09beb2a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckAndRepairVolumeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckAndRepairVolumeCommandWrapper.java @@ -42,7 +42,6 @@ import org.apache.cloudstack.utils.qemu.QemuObject.EncryptFormat; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import java.io.IOException; @@ -53,8 +52,6 @@ @ResourceWrapper(handles = CheckAndRepairVolumeCommand.class) public class LibvirtCheckAndRepairVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCheckAndRepairVolumeCommandWrapper.class); - @Override public Answer execute(CheckAndRepairVolumeCommand command, LibvirtComputingResource serverResource) { final String volumeId = command.getPath(); @@ -105,7 +102,7 @@ private CheckAndRepairVolumeAnswer checkVolume(KVMPhysicalDisk vol, CheckAndRepa EncryptFormat encryptFormat = EncryptFormat.enumValue(command.getEncryptFormat()); byte[] passphrase = command.getPassphrase(); String checkVolumeResult = checkAndRepairVolume(vol, null, encryptFormat, passphrase, serverResource); - s_logger.info(String.format("Check Volume result for the volume %s is %s", vol.getName(), checkVolumeResult)); + logger.info(String.format("Check Volume result for the volume %s is %s", vol.getName(), checkVolumeResult)); CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, true, checkVolumeResult); answer.setVolumeCheckExecutionResult(checkVolumeResult); @@ -119,7 +116,7 @@ private CheckAndRepairVolumeAnswer repairVolume(KVMPhysicalDisk vol, CheckAndRep String repairVolumeResult = checkAndRepairVolume(vol, repair, encryptFormat, passphrase, serverResource); String finalResult = (checkVolumeResult != null ? checkVolumeResult.concat(",") : "") + repairVolumeResult; - s_logger.info(String.format("Repair Volume result for the volume %s is %s", vol.getName(), repairVolumeResult)); + logger.info(String.format("Repair Volume result for the volume %s is %s", vol.getName(), repairVolumeResult)); CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, true, finalResult); answer.setVolumeRepairExecutionResult(repairVolumeResult); @@ -138,7 +135,7 @@ private CheckAndRepairVolumeAnswer checkIfRepairLeaksIsRequired(CheckAndRepairVo jsonNode = objectMapper.readTree(checkVolumeResult); } catch (JsonProcessingException e) { String msg = String.format("Error processing response %s during check volume %s", checkVolumeResult, e.getMessage()); - s_logger.info(msg); + logger.info(msg); return skipRepairVolumeCommand(command, checkVolumeResult, msg); } @@ -157,7 +154,7 @@ private CheckAndRepairVolumeAnswer checkIfRepairLeaksIsRequired(CheckAndRepairVo } private CheckAndRepairVolumeAnswer skipRepairVolumeCommand(CheckAndRepairVolumeCommand command, String checkVolumeResult, String msg) { - s_logger.info(msg); + logger.info(msg); String jsonStringFormat = String.format("{ \"message\": \"%s\" }", msg); String finalResult = (checkVolumeResult != null ? checkVolumeResult.concat(",") : "") + jsonStringFormat; CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, true, finalResult); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckConvertInstanceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckConvertInstanceCommandWrapper.java index d94fddeeb446..d3ebb28b106a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckConvertInstanceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckConvertInstanceCommandWrapper.java @@ -18,8 +18,6 @@ // package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckConvertInstanceAnswer; import com.cloud.agent.api.CheckConvertInstanceCommand; @@ -30,21 +28,19 @@ @ResourceWrapper(handles = CheckConvertInstanceCommand.class) public class LibvirtCheckConvertInstanceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCheckConvertInstanceCommandWrapper.class); - @Override public Answer execute(CheckConvertInstanceCommand cmd, LibvirtComputingResource serverResource) { if (!serverResource.hostSupportsInstanceConversion()) { String msg = String.format("Cannot convert the instance from VMware as the virt-v2v binary is not found on host %s. " + "Please install virt-v2v%s on the host before attempting the instance conversion.", serverResource.getPrivateIp(), serverResource.isUbuntuHost()? ", nbdkit" : ""); - s_logger.info(msg); + logger.info(msg); return new CheckConvertInstanceAnswer(cmd, false, msg); } if (cmd.getCheckWindowsGuestConversionSupport() && !serverResource.hostSupportsWindowsGuestConversion()) { String msg = String.format("Cannot convert the instance from VMware as the virtio-win package is not found on host %s. " + "Please install virtio-win package on the host before attempting the windows guest instance conversion.", serverResource.getPrivateIp()); - s_logger.info(msg); + logger.info(msg); return new CheckConvertInstanceAnswer(cmd, false, msg); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckSshCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckSshCommandWrapper.java index a04ddecd2503..d41cd63fa4ec 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckSshCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckSshCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.check.CheckSshAnswer; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = CheckSshCommand.class) public final class LibvirtCheckSshCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final CheckSshCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -40,8 +38,8 @@ public Answer execute(final CheckSshCommand command, final LibvirtComputingResou final String privateIp = command.getIp(); final int cmdPort = command.getPort(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port, " + privateIp + ":" + cmdPort); } final VirtualRoutingResource virtRouterResource = libvirtComputingResource.getVirtRouterResource(); @@ -49,8 +47,8 @@ public Answer execute(final CheckSshCommand command, final LibvirtComputingResou return new CheckSshAnswer(command, "Can not ping System vm " + vmName + " because of a connection failure"); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port succeeded for vm " + vmName); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port succeeded for vm " + vmName); } return new CheckSshAnswer(command); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckStorageAvailabilityWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckStorageAvailabilityWrapper.java index 3d57ba0d5dea..b1d57f41fb78 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckStorageAvailabilityWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckStorageAvailabilityWrapper.java @@ -28,14 +28,12 @@ import com.cloud.resource.ResourceWrapper; import com.cloud.storage.Storage; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.util.Map; @ResourceWrapper(handles = CheckStorageAvailabilityCommand.class) public class LibvirtCheckStorageAvailabilityWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCheckStorageAvailabilityWrapper.class); @Override public Answer execute(CheckStorageAvailabilityCommand command, LibvirtComputingResource resource) { @@ -44,15 +42,15 @@ public Answer execute(CheckStorageAvailabilityCommand command, LibvirtComputingR for (String poolUuid : poolsMap.keySet()) { Storage.StoragePoolType type = poolsMap.get(poolUuid); - s_logger.debug("Checking if storage pool " + poolUuid + " (" + type + ") is mounted on this host"); + logger.debug("Checking if storage pool " + poolUuid + " (" + type + ") is mounted on this host"); try { KVMStoragePool storagePool = storagePoolMgr.getStoragePool(type, poolUuid); if (storagePool == null) { - s_logger.info("Storage pool " + poolUuid + " is not available"); + logger.info("Storage pool " + poolUuid + " is not available"); return new Answer(command, false, "Storage pool " + poolUuid + " not available"); } } catch (CloudRuntimeException e) { - s_logger.info("Storage pool " + poolUuid + " is not available"); + logger.info("Storage pool " + poolUuid + " is not available"); return new Answer(command, e); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckUrlCommand.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckUrlCommand.java index 0e1bf57a9747..c7dbf8a59bff 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckUrlCommand.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckUrlCommand.java @@ -21,7 +21,6 @@ import org.apache.cloudstack.direct.download.DirectDownloadHelper; import org.apache.cloudstack.agent.directdownload.CheckUrlAnswer; import org.apache.cloudstack.agent.directdownload.CheckUrlCommand; -import org.apache.log4j.Logger; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; import com.cloud.resource.CommandWrapper; @@ -30,7 +29,6 @@ @ResourceWrapper(handles = CheckUrlCommand.class) public class LibvirtCheckUrlCommand extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCheckUrlCommand.class); @Override public CheckUrlAnswer execute(CheckUrlCommand cmd, LibvirtComputingResource serverResource) { @@ -39,14 +37,14 @@ public CheckUrlAnswer execute(CheckUrlCommand cmd, LibvirtComputingResource serv final Integer connectionRequestTimeout = cmd.getConnectionRequestTimeout(); final Integer socketTimeout = cmd.getSocketTimeout(); - s_logger.info(String.format("Checking URL: %s, with connect timeout: %d, connect request timeout: %d, socket timeout: %d", url, connectTimeout, connectionRequestTimeout, socketTimeout)); + logger.info(String.format("Checking URL: %s, with connect timeout: %d, connect request timeout: %d, socket timeout: %d", url, connectTimeout, connectionRequestTimeout, socketTimeout)); Long remoteSize = null; boolean checkResult = DirectDownloadHelper.checkUrlExistence(url, connectTimeout, connectionRequestTimeout, socketTimeout, cmd.isFollowRedirects()); if (checkResult) { remoteSize = DirectDownloadHelper.getFileSize(url, cmd.getFormat(), connectTimeout, connectionRequestTimeout, socketTimeout, cmd.isFollowRedirects()); if (remoteSize == null || remoteSize < 0) { - s_logger.error(String.format("Couldn't properly retrieve the remote size of the template on " + + logger.error(String.format("Couldn't properly retrieve the remote size of the template on " + "url %s, obtained size = %s", url, remoteSize)); return new CheckUrlAnswer(false, remoteSize); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckVolumeCommandWrapper.java index 8b0a5aab4619..c8b0aafd0d6d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckVolumeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckVolumeCommandWrapper.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg; import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import java.util.Map; @@ -42,8 +41,6 @@ @ResourceWrapper(handles = CheckVolumeCommand.class) public final class LibvirtCheckVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCheckVolumeCommandWrapper.class); - @Override public Answer execute(final CheckVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { String result = null; @@ -64,7 +61,7 @@ public Answer execute(final CheckVolumeCommand command, final LibvirtComputingRe } } catch (final Exception e) { - s_logger.error("Error while locating disk: "+ e.getMessage()); + logger.error("Error while locating disk: "+ e.getMessage()); return new Answer(command, false, result); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCleanupPersistentNetworkResourceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCleanupPersistentNetworkResourceCommandWrapper.java index ebc147a73a32..9199be4b84ce 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCleanupPersistentNetworkResourceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCleanupPersistentNetworkResourceCommandWrapper.java @@ -17,7 +17,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CleanupPersistentNetworkResourceAnswer; @@ -31,7 +30,6 @@ @ResourceWrapper(handles = CleanupPersistentNetworkResourceCommand.class) public class LibvirtCleanupPersistentNetworkResourceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCleanupPersistentNetworkResourceCommandWrapper.class); @Override public Answer execute(CleanupPersistentNetworkResourceCommand command, LibvirtComputingResource serverResource) { NicTO nic = command.getNicTO(); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConsoleProxyLoadCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConsoleProxyLoadCommandWrapper.java index 1a2f7cb20b6c..ecfa062ed887 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConsoleProxyLoadCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConsoleProxyLoadCommandWrapper.java @@ -26,7 +26,6 @@ import java.net.URL; import java.net.URLConnection; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -36,7 +35,6 @@ public abstract class LibvirtConsoleProxyLoadCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtConsoleProxyLoadCommandWrapper.class); public Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, final String proxyVmName, final String proxyManagementIp, final int cmdPort) { String result = null; @@ -64,12 +62,12 @@ public Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, fina try { is.close(); } catch (final IOException e) { - s_logger.warn("Exception when closing , console proxy address : " + proxyManagementIp); + logger.warn("Exception when closing , console proxy address : " + proxyManagementIp); success = false; } } } catch (final IOException e) { - s_logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp); + logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp); success = false; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java index f6f6ea1082db..cc955e86d8a4 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapper.java @@ -35,7 +35,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ConvertInstanceAnswer; @@ -62,8 +61,6 @@ @ResourceWrapper(handles = ConvertInstanceCommand.class) public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtConvertInstanceCommandWrapper.class); - private static final List supportedInstanceConvertSourceHypervisors = List.of(Hypervisor.HypervisorType.VMware); @@ -80,7 +77,7 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve if (cmd.getCheckConversionSupport() && !serverResource.hostSupportsInstanceConversion()) { String msg = String.format("Cannot convert the instance %s from VMware as the virt-v2v binary is not found. " + "Please install virt-v2v%s on the host before attempting the instance conversion.", sourceInstanceName, serverResource.isUbuntuHost()? ", nbdkit" : ""); - s_logger.info(msg); + logger.info(msg); return new ConvertInstanceAnswer(cmd, false, msg); } @@ -88,12 +85,15 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve String err = destinationHypervisorType != Hypervisor.HypervisorType.KVM ? String.format("The destination hypervisor type is %s, KVM was expected, cannot handle it", destinationHypervisorType) : String.format("The source hypervisor type %s is not supported for KVM conversion", sourceHypervisorType); - s_logger.error(err); + logger.error(err); return new ConvertInstanceAnswer(cmd, false, err); } final KVMStoragePoolManager storagePoolMgr = serverResource.getStoragePoolMgr(); KVMStoragePool temporaryStoragePool = getTemporaryStoragePool(conversionTemporaryLocation, storagePoolMgr); + + logger.info(String.format("Attempting to convert the instance %s from %s to KVM", + sourceInstanceName, sourceHypervisorType)); final String temporaryConvertPath = temporaryStoragePool.getLocalPath(); String ovfTemplateDirOnConversionLocation; @@ -103,7 +103,7 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve String exportInstanceOVAUrl = getExportInstanceOVAUrl(sourceInstance); if (StringUtils.isBlank(exportInstanceOVAUrl)) { String err = String.format("Couldn't export OVA for the VM %s, due to empty url", sourceInstanceName); - s_logger.error(err); + logger.error(err); return new ConvertInstanceAnswer(cmd, false, err); } @@ -117,7 +117,7 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve ovfExported = exportOVAFromVMOnVcenter(exportInstanceOVAUrl, sourceOVFDirPath, noOfThreads, timeout); if (!ovfExported) { String err = String.format("Export OVA for the VM %s failed", sourceInstanceName); - s_logger.error(err); + logger.error(err); return new ConvertInstanceAnswer(cmd, false, err); } sourceOVFDirPath = String.format("%s%s/", sourceOVFDirPath, sourceInstanceName); @@ -126,7 +126,7 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve sourceOVFDirPath = String.format("%s/%s/", temporaryConvertPath, ovfTemplateDirOnConversionLocation); } - s_logger.info(String.format("Attempting to convert the OVF %s of the instance %s from %s to KVM", ovfTemplateDirOnConversionLocation, sourceInstanceName, sourceHypervisorType)); + logger.info(String.format("Attempting to convert the OVF %s of the instance %s from %s to KVM", ovfTemplateDirOnConversionLocation, sourceInstanceName, sourceHypervisorType)); final String temporaryConvertUuid = UUID.randomUUID().toString(); boolean verboseModeEnabled = serverResource.isConvertInstanceVerboseModeEnabled(); @@ -136,7 +136,7 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve if (!result) { String err = String.format("The virt-v2v conversion for the OVF %s failed. " + "Please check the agent logs for the virt-v2v output", ovfTemplateDirOnConversionLocation); - s_logger.error(err); + logger.error(err); return new ConvertInstanceAnswer(cmd, false, err); } String convertedBasePath = String.format("%s/%s", temporaryConvertPath, temporaryConvertUuid); @@ -157,16 +157,16 @@ public Answer execute(ConvertInstanceCommand cmd, LibvirtComputingResource serve } catch (Exception e) { String error = String.format("Error converting instance %s from %s, due to: %s", sourceInstanceName, sourceHypervisorType, e.getMessage()); - s_logger.error(error, e); + logger.error(error, e); return new ConvertInstanceAnswer(cmd, false, error); } finally { if (ovfExported && StringUtils.isNotBlank(ovfTemplateDirOnConversionLocation)) { String sourceOVFDir = String.format("%s/%s", temporaryConvertPath, ovfTemplateDirOnConversionLocation); - s_logger.debug("Cleaning up exported OVA at dir " + sourceOVFDir); + logger.debug("Cleaning up exported OVA at dir " + sourceOVFDir); FileUtil.deletePath(sourceOVFDir); } if (conversionTemporaryLocation instanceof NfsTO) { - s_logger.debug("Cleaning up secondary storage temporary location"); + logger.debug("Cleaning up secondary storage temporary location"); storagePoolMgr.deleteStoragePool(temporaryStoragePool.getType(), temporaryStoragePool.getUuid()); } } @@ -215,7 +215,7 @@ protected List getTemporaryDisksFromParsedXml(KVMStoragePool po x.getDeviceType() == LibvirtVMDef.DiskDef.DeviceType.DISK).collect(Collectors.toList()); if (CollectionUtils.isEmpty(disksDefs)) { String err = String.format("Cannot find any disk defined on the converted XML domain %s.xml", convertedBasePath); - s_logger.error(err); + logger.error(err); throw new CloudRuntimeException(err); } sanitizeDisksPath(disksDefs); @@ -233,7 +233,7 @@ private List getPhysicalDisksFromDefPaths(List getTemporaryDisksWithPrefixFromTemporaryPool(KVMStoragePool pool, String path, String prefix) { String msg = String.format("Could not parse correctly the converted XML domain, checking for disks on %s with prefix %s", path, prefix); - s_logger.info(msg); + logger.info(msg); pool.refresh(); List disksWithPrefix = pool.listPhysicalDisks() .stream() @@ -241,7 +241,7 @@ protected List getTemporaryDisksWithPrefixFromTemporaryPool(KVM .collect(Collectors.toList()); if (CollectionUtils.isEmpty(disksWithPrefix)) { msg = String.format("Could not find any converted disk with prefix %s on temporary location %s", prefix, path); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } return disksWithPrefix; @@ -251,10 +251,10 @@ private void cleanupDisksAndDomainFromTemporaryLocation(List di KVMStoragePool temporaryStoragePool, String temporaryConvertUuid) { for (KVMPhysicalDisk disk : disks) { - s_logger.info(String.format("Cleaning up temporary disk %s after conversion from temporary location", disk.getName())); + logger.info(String.format("Cleaning up temporary disk %s after conversion from temporary location", disk.getName())); temporaryStoragePool.deletePhysicalDisk(disk.getName(), Storage.ImageFormat.QCOW2); } - s_logger.info(String.format("Cleaning up temporary domain %s after conversion from temporary location", temporaryConvertUuid)); + logger.info(String.format("Cleaning up temporary domain %s after conversion from temporary location", temporaryConvertUuid)); FileUtil.deleteFiles(temporaryStoragePool.getLocalPath(), temporaryConvertUuid, ".xml"); } @@ -273,26 +273,26 @@ protected List moveTemporaryDisksToDestination(List getNfsStoragePoolHostAndPath(KVMStoragePool stora commands.add(new String[]{Script.getExecutableAbsolutePath("mount")}); commands.add(new String[]{Script.getExecutableAbsolutePath("grep"), storagePool.getLocalPath()}); String storagePoolMountPoint = Script.executePipedCommands(commands, 0).second(); - s_logger.debug(String.format("NFS Storage pool: %s - local path: %s, mount point: %s", storagePool.getUuid(), storagePool.getLocalPath(), storagePoolMountPoint)); + logger.debug(String.format("NFS Storage pool: %s - local path: %s, mount point: %s", storagePool.getUuid(), storagePool.getLocalPath(), storagePoolMountPoint)); if (StringUtils.isNotEmpty(storagePoolMountPoint)) { String[] res = storagePoolMountPoint.strip().split(" "); res = res[0].split(":"); @@ -378,7 +378,7 @@ private boolean exportOVAFromVMOnVcenter(String vmExportUrl, String targetOvfDir, int noOfThreads, long timeout) { - Script script = new Script("ovftool", timeout, s_logger); + Script script = new Script("ovftool", timeout, logger); script.add("--noSSLVerify"); if (noOfThreads > 1) { script.add(String.format("--parallelThreads=%s", noOfThreads)); @@ -387,7 +387,7 @@ private boolean exportOVAFromVMOnVcenter(String vmExportUrl, script.add(targetOvfDir); String logPrefix = "export ovf"; - OutputInterpreter.LineByLineOutputLogger outputLogger = new OutputInterpreter.LineByLineOutputLogger(s_logger, logPrefix); + OutputInterpreter.LineByLineOutputLogger outputLogger = new OutputInterpreter.LineByLineOutputLogger(logger, logPrefix); script.execute(outputLogger); int exitValue = script.getExitValue(); return exitValue == 0; @@ -397,7 +397,7 @@ protected boolean performInstanceConversion(String sourceOVFDirPath, String temporaryConvertFolder, String temporaryConvertUuid, long timeout, boolean verboseModeEnabled) { - Script script = new Script("virt-v2v", timeout, s_logger); + Script script = new Script("virt-v2v", timeout, logger); script.add("--root", "first"); script.add("-i", "ova"); script.add(sourceOVFDirPath); @@ -410,7 +410,7 @@ protected boolean performInstanceConversion(String sourceOVFDirPath, } String logPrefix = String.format("virt-v2v ovf source: %s progress", sourceOVFDirPath); - OutputInterpreter.LineByLineOutputLogger outputLogger = new OutputInterpreter.LineByLineOutputLogger(s_logger, logPrefix); + OutputInterpreter.LineByLineOutputLogger outputLogger = new OutputInterpreter.LineByLineOutputLogger(logger, logPrefix); script.execute(outputLogger); int exitValue = script.getExitValue(); return exitValue == 0; @@ -420,7 +420,7 @@ protected LibvirtDomainXMLParser parseMigratedVMXmlDomain(String installPath) th String xmlPath = String.format("%s.xml", installPath); if (!new File(xmlPath).exists()) { String err = String.format("Conversion failed. Unable to find the converted XML domain, expected %s", xmlPath); - s_logger.error(err); + logger.error(err); throw new CloudRuntimeException(err); } InputStream is = new BufferedInputStream(new FileInputStream(xmlPath)); @@ -431,8 +431,8 @@ protected LibvirtDomainXMLParser parseMigratedVMXmlDomain(String installPath) th return parser; } catch (RuntimeException e) { String err = String.format("Error parsing the converted instance XML domain at %s: %s", xmlPath, e.getMessage()); - s_logger.error(err, e); - s_logger.debug(xml); + logger.error(err, e); + logger.debug(xml); return null; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyRemoteVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyRemoteVolumeCommandWrapper.java index a5e1716da2eb..e6ec05fec23f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyRemoteVolumeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyRemoteVolumeCommandWrapper.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg; import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import java.util.Map; @@ -42,8 +41,6 @@ @ResourceWrapper(handles = CopyRemoteVolumeCommand.class) public final class LibvirtCopyRemoteVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCopyRemoteVolumeCommandWrapper.class); - @Override public Answer execute(final CopyRemoteVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { String srcIp = command.getRemoteIp(); @@ -61,7 +58,7 @@ public Answer execute(final CopyRemoteVolumeCommand command, final LibvirtComput if (storageFilerTO.getType() == Storage.StoragePoolType.Filesystem || storageFilerTO.getType() == Storage.StoragePoolType.NetworkFilesystem) { String filename = libvirtComputingResource.copyVolume(srcIp, username, password, dstPath, srcFile, tmpPath, timeoutInSecs); - s_logger.debug("Volume " + srcFile + " copy successful, copied to file: " + filename); + logger.debug("Volume " + srcFile + " copy successful, copied to file: " + filename); final KVMPhysicalDisk vol = pool.getPhysicalDisk(filename); final String path = vol.getPath(); long size = getVirtualSizeFromFile(path); @@ -71,7 +68,7 @@ public Answer execute(final CopyRemoteVolumeCommand command, final LibvirtComput return new Answer(command, false, msg); } } catch (final Exception e) { - s_logger.error("Error while copying volume file from remote host: " + e.getMessage(), e); + logger.error("Error while copying volume file from remote host: " + e.getMessage(), e); String msg = "Failed to copy volume due to: " + e.getMessage(); return new Answer(command, false, msg); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyToSecondaryStorageWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyToSecondaryStorageWrapper.java index a6baa1c17855..a8ea0d2ce810 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyToSecondaryStorageWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyToSecondaryStorageWrapper.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer; import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageCommand; import org.apache.cloudstack.diagnostics.DiagnosticsService; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = CopyToSecondaryStorageCommand.class) public class LibvirtCopyToSecondaryStorageWrapper extends CommandWrapper { - public static final Logger LOGGER = Logger.getLogger(LibvirtCopyToSecondaryStorageWrapper.class); @Override public Answer execute(CopyToSecondaryStorageCommand command, LibvirtComputingResource libvirtResource) { @@ -64,7 +62,7 @@ public Answer execute(CopyToSecondaryStorageCommand command, LibvirtComputingRes Path path = Paths.get(dataDirectory.getAbsolutePath()); setDirFilePermissions(path); if (existsInSecondaryStore) { - LOGGER.info(String.format("Copying %s from %s to secondary store %s", diagnosticsZipFile, vmSshIp, secondaryStorageUrl)); + logger.info(String.format("Copying %s from %s to secondary store %s", diagnosticsZipFile, vmSshIp, secondaryStorageUrl)); int port = Integer.valueOf(LibvirtComputingResource.DEFAULTDOMRSSHPORT); File permKey = new File(LibvirtComputingResource.SSHPRVKEYPATH); SshHelper.scpFrom(vmSshIp, port, "root", permKey, dataDirectoryInSecondaryStore, diagnosticsZipFile); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java index 0795abf06888..4e42af6899aa 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyVolumeCommandWrapper.java @@ -37,11 +37,9 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; @ResourceWrapper(handles = CopyVolumeCommand.class) public final class LibvirtCopyVolumeCommandWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(LibvirtCopyVolumeCommandWrapper.class); @Override public Answer execute(final CopyVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -164,7 +162,7 @@ private Answer handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails(CopyVol } } catch (Exception e) { - LOGGER.warn("Unable to disconnect from the source device.", e); + logger.warn("Unable to disconnect from the source device.", e); } if (secondaryStoragePool != null) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateCommandWrapper.java index bac5551129a5..5ec00889df96 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.CreateAnswer; @@ -39,7 +38,6 @@ @ResourceWrapper(handles = CreateCommand.class) public final class LibvirtCreateCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCreateCommandWrapper.class); @Override public Answer execute(final CreateCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -80,7 +78,7 @@ public Answer execute(final CreateCommand command, final LibvirtComputingResourc volume.setCacheMode(dskch.getCacheMode()); return new CreateAnswer(command, volume); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to create volume: " + e.toString()); + logger.debug("Failed to create volume: " + e.toString()); return new CreateAnswer(command, e); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java index de3d12f5c100..b05d6f06d742 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.java @@ -24,7 +24,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand; @@ -46,7 +45,6 @@ @ResourceWrapper(handles = CreatePrivateTemplateFromSnapshotCommand.class) public final class LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.class); @Override public Answer execute(final CreatePrivateTemplateFromSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -80,7 +78,7 @@ public Answer execute(final CreatePrivateTemplateFromSnapshotCommand command, fi final String createTmplPath = libvirtComputingResource.createTmplPath(); final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout(); - final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger); + final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, logger); scriptCommand.add("-t", templatePath); scriptCommand.add("-n", tmplFileName); scriptCommand.add("-f", snapshot.getPath()); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.java index 4a7aae512024..de35a1251bba 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand; @@ -60,7 +59,6 @@ @ResourceWrapper(handles = CreatePrivateTemplateFromVolumeCommand.class) public final class LibvirtCreatePrivateTemplateFromVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.class); @Override public Answer execute(final CreatePrivateTemplateFromVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -96,7 +94,7 @@ public Answer execute(final CreatePrivateTemplateFromVolumeCommand command, fina final String createTmplPath = libvirtComputingResource.createTmplPath(); final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout(); - final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger); + final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, logger); scriptCommand.add("-f", disk.getPath()); scriptCommand.add("-t", tmpltPath); scriptCommand.add("-n", command.getUniqueName() + ".qcow2"); @@ -104,11 +102,11 @@ public Answer execute(final CreatePrivateTemplateFromVolumeCommand command, fina final String result = scriptCommand.execute(); if (result != null) { - s_logger.debug("failed to create template: " + result); + logger.debug("failed to create template: " + result); return new CreatePrivateTemplateAnswer(command, false, result); } } else { - s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + command.getUniqueName()); + logger.debug("Converting RBD disk " + disk.getPath() + " into template " + command.getUniqueName()); final QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), primary.getSourcePort(), primary.getAuthUserName(), @@ -122,7 +120,7 @@ public Answer execute(final CreatePrivateTemplateFromVolumeCommand command, fina final QemuImg q = new QemuImg(0); q.convert(srcFile, destFile); } catch (final QemuImgException | LibvirtException e) { - s_logger.error("Failed to create new template while converting " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + + logger.error("Failed to create new template while converting " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); } @@ -142,7 +140,7 @@ public Answer execute(final CreatePrivateTemplateFromVolumeCommand command, fina templFo.flush(); }catch(final IOException ex) { - s_logger.error("CreatePrivateTemplateAnswer:Exception:"+ex.getMessage()); + logger.error("CreatePrivateTemplateAnswer:Exception:"+ex.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateVMSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateVMSnapshotCommandWrapper.java index c7941e7fc897..7cada635a045 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateVMSnapshotCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -35,7 +34,6 @@ @ResourceWrapper(handles = CreateVMSnapshotCommand.class) public final class LibvirtCreateVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCreateVMSnapshotCommandWrapper.class); @Override public Answer execute(final CreateVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -67,14 +65,14 @@ public Answer execute(final CreateVMSnapshotCommand cmd, final LibvirtComputingR return new CreateVMSnapshotAnswer(cmd, cmd.getTarget(), cmd.getVolumeTOs()); } catch (LibvirtException e) { String msg = " Create VM snapshot failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new CreateVMSnapshotAnswer(cmd, false, msg); } finally { if (dm != null) { try { dm.free(); } catch (LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); }; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteBackupCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteBackupCommandWrapper.java new file mode 100644 index 000000000000..4772d3b472cf --- /dev/null +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteBackupCommandWrapper.java @@ -0,0 +1,63 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.hypervisor.kvm.resource.wrapper; + +import com.cloud.agent.api.Answer; +import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.Pair; +import com.cloud.utils.script.Script; +import org.apache.cloudstack.backup.BackupAnswer; +import org.apache.cloudstack.backup.DeleteBackupCommand; + +import java.util.ArrayList; +import java.util.List; + +@ResourceWrapper(handles = DeleteBackupCommand.class) +public class LibvirtDeleteBackupCommandWrapper extends CommandWrapper { + @Override + public Answer execute(DeleteBackupCommand command, LibvirtComputingResource libvirtComputingResource) { + final String backupPath = command.getBackupPath(); + final String backupRepoType = command.getBackupRepoType(); + final String backupRepoAddress = command.getBackupRepoAddress(); + final String mountOptions = command.getMountOptions(); + + List commands = new ArrayList<>(); + commands.add(new String[]{ + libvirtComputingResource.getNasBackupPath(), + "-o", "delete", + "-t", backupRepoType, + "-s", backupRepoAddress, + "-m", mountOptions, + "-p", backupPath + }); + + Pair result = Script.executePipedCommands(commands, libvirtComputingResource.getCmdsTimeout()); + + logger.debug(String.format("Backup delete result: %s , exit code: %s", result.second(), result.first())); + + if (result.first() != 0) { + logger.debug(String.format("Failed to delete VM backup: %s", result.second())); + return new BackupAnswer(command, false, result.second()); + } + return new BackupAnswer(command, true, null); + } +} diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java index f95948d73dd2..58a74d6e0f61 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo; @@ -46,7 +45,6 @@ @ResourceWrapper(handles = DeleteVMSnapshotCommand.class) public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtDeleteVMSnapshotCommandWrapper.class); @Override public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -67,7 +65,7 @@ public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingR oldState = dm.getInfo().state; if (oldState == DomainInfo.DomainState.VIR_DOMAIN_RUNNING) { - s_logger.debug("Suspending domain " + vmName); + logger.debug("Suspending domain " + vmName); dm.suspend(); // suspend the vm to avoid image corruption } @@ -87,7 +85,7 @@ public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingR String msg = " Delete VM snapshot failed due to " + e.toString(); if (dm == null) { - s_logger.debug("Can not find running vm: " + vmName + ", now we are trying to delete the vm snapshot using qemu-img if the format of root volume is QCOW2"); + logger.debug("Can not find running vm: " + vmName + ", now we are trying to delete the vm snapshot using qemu-img if the format of root volume is QCOW2"); VolumeObjectTO rootVolume = null; for (VolumeObjectTO volume: cmd.getVolumeTOs()) { if (volume.getVolumeType() == Volume.Type.ROOT) { @@ -107,7 +105,7 @@ public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingR commands.add(new String[]{Script.getExecutableAbsolutePath("grep"), "^" + sanitizeBashCommandArgument(cmd.getTarget().getSnapshotName()) + "$"}); String qemu_img_snapshot = Script.executePipedCommands(commands, 0).second(); if (qemu_img_snapshot == null) { - s_logger.info("Cannot find snapshot " + cmd.getTarget().getSnapshotName() + " in file " + rootDisk.getPath() + ", return true"); + logger.info("Cannot find snapshot " + cmd.getTarget().getSnapshotName() + " in file " + rootDisk.getPath() + ", return true"); return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs()); } int result = Script.executeCommandForExitValue(qemuImgPath, "snapshot", "-d", @@ -121,14 +119,14 @@ public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingR } } } else if (snapshot == null) { - s_logger.debug("Can not find vm snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + ", return true"); + logger.debug("Can not find vm snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + ", return true"); return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs()); } else if (tryingResume) { - s_logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e); + logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e); return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs()); } - s_logger.warn(msg, e); + logger.warn(msg, e); return new DeleteVMSnapshotAnswer(cmd, false, msg); } finally { if (dm != null) { @@ -136,12 +134,12 @@ public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingR try { dm = libvirtComputingResource.getDomain(conn, vmName); if (oldState == DomainInfo.DomainState.VIR_DOMAIN_RUNNING && dm.getInfo().state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) { - s_logger.debug("Resuming domain " + vmName); + logger.debug("Resuming domain " + vmName); dm.resume(); } dm.free(); } catch (LibvirtException e) { - s_logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e); + logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDestroyCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDestroyCommandWrapper.java index 361d194189ee..b9106cec42f6 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDestroyCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDestroyCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.DestroyCommand; @@ -34,7 +33,6 @@ @ResourceWrapper(handles = DestroyCommand.class) public final class LibvirtDestroyCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtDestroyCommandWrapper.class); @Override public Answer execute(final DestroyCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -45,7 +43,7 @@ public Answer execute(final DestroyCommand command, final LibvirtComputingResour pool.deletePhysicalDisk(vol.getPath(), null); return new Answer(command, true, "Success"); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to delete volume: " + e.toString()); + logger.debug("Failed to delete volume: " + e.toString()); return new Answer(command, false, e.toString()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFenceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFenceCommandWrapper.java index 9a6ee7a41700..f1037d64384c 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFenceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFenceCommandWrapper.java @@ -25,7 +25,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.FenceAnswer; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = FenceCommand.class) public final class LibvirtFenceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtFenceCommandWrapper.class); @Override public Answer execute(final FenceCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -56,7 +54,7 @@ public Answer execute(final FenceCommand command, final LibvirtComputingResource */ if (pools.size() == 0) { String logline = "No NFS storage pools found. No way to safely fence " + command.getVmName() + " on host " + command.getHostGuid(); - s_logger.warn(logline); + logger.warn(logline); return new FenceAnswer(command, false, logline); } @@ -71,10 +69,10 @@ public Answer execute(final FenceCommand command, final LibvirtComputingResource return new FenceAnswer(command); } } catch (final InterruptedException e) { - s_logger.warn("Unable to fence", e); + logger.warn("Unable to fence", e); return new FenceAnswer(command, false, e.getMessage()); } catch (final ExecutionException e) { - s_logger.warn("Unable to fence", e); + logger.warn("Unable to fence", e); return new FenceAnswer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFreezeThawVMCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFreezeThawVMCommandWrapper.java index 808d3a20bfbe..a6f2bcc93408 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFreezeThawVMCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtFreezeThawVMCommandWrapper.java @@ -20,7 +20,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; import org.apache.cloudstack.utils.qemu.QemuCommand; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = FreezeThawVMCommand.class) public class LibvirtFreezeThawVMCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtFreezeThawVMCommandWrapper.class); @Override public Answer execute(FreezeThawVMCommand command, LibvirtComputingResource serverResource) { @@ -60,13 +58,13 @@ public Answer execute(FreezeThawVMCommand command, LibvirtComputingResource serv } String result = getResultOfQemuCommand(command.getOption(), domain); - s_logger.debug(String.format("Result of %s command is %s", command.getOption(), result)); + logger.debug(String.format("Result of %s command is %s", command.getOption(), result)); if (result == null || (result.startsWith("error"))) { return new FreezeThawVMAnswer(command, false, String.format("Failed to %s vm %s due to result status is: %s", command.getOption(), vmName, result)); } String status = getResultOfQemuCommand(FreezeThawVMCommand.STATUS, domain); - s_logger.debug(String.format("Status of %s command is %s", command.getOption(), status)); + logger.debug(String.format("Status of %s command is %s", command.getOption(), status)); if (status != null && new JsonParser().parse(status).isJsonObject()) { String statusResult = new JsonParser().parse(status).getAsJsonObject().get("return").getAsString(); if (statusResult.equals(command.getOption())) { @@ -83,7 +81,7 @@ public Answer execute(FreezeThawVMCommand command, LibvirtComputingResource serv try { domain.free(); } catch (LibvirtException e) { - s_logger.trace("Ingore error ", e); + logger.trace("Ingore error ", e); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java index 5e5835edd019..1af16e72ec09 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetHostStatsCommandWrapper.java @@ -29,12 +29,10 @@ import com.cloud.utils.Pair; import org.apache.cloudstack.utils.linux.CPUStat; import org.apache.cloudstack.utils.linux.MemStat; -import org.apache.log4j.Logger; @ResourceWrapper(handles = GetHostStatsCommand.class) public final class LibvirtGetHostStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetHostStatsCommandWrapper.class); @Override public Answer execute(final GetHostStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java index 942a68b80740..114b27d3a5b7 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java @@ -32,7 +32,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.vm.UnmanagedInstanceTO; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainBlockInfo; @@ -46,8 +45,6 @@ @ResourceWrapper(handles = GetRemoteVmsCommand.class) public final class LibvirtGetRemoteVmsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetRemoteVmsCommandWrapper.class); - @Override public Answer execute(final GetRemoteVmsCommand command, final LibvirtComputingResource libvirtComputingResource) { String remoteIp = command.getRemoteIp(); @@ -56,27 +53,28 @@ public Answer execute(final GetRemoteVmsCommand command, final LibvirtComputingR try { Connect conn = LibvirtConnection.getConnection(hypervisorURI); final List allVmNames = libvirtComputingResource.getAllVmNames(conn); - s_logger.info(String.format("Found %d VMs on the remote host %s", allVmNames.size(), remoteIp)); + logger.info(String.format("Found %d VMs on the remote host %s", allVmNames.size(), remoteIp)); for (String name : allVmNames) { final Domain domain = libvirtComputingResource.getDomain(conn, name); final DomainInfo.DomainState ps = domain.getInfo().state; final VirtualMachine.PowerState state = libvirtComputingResource.convertToPowerState(ps); - s_logger.debug(String.format("Remote VM %s - powerstate: %s, state: %s", domain.getName(), ps.toString(), state.toString())); + + logger.debug(String.format("Remote VM %s - powerstate: %s, state: %s", domain.getName(), ps.toString(), state.toString())); if (state == VirtualMachine.PowerState.PowerOff) { try { UnmanagedInstanceTO instance = getUnmanagedInstance(libvirtComputingResource, domain, conn); unmanagedInstances.put(instance.getName(), instance); } catch (Exception e) { - s_logger.error("Couldn't fetch remote VM " + domain.getName() + " details, due to: " + e.getMessage(), e); + logger.error("Couldn't fetch remote VM " + domain.getName() + " details, due to: " + e.getMessage(), e); } } domain.free(); } - s_logger.debug("Found " + unmanagedInstances.size() + " stopped VMs on remote host " + remoteIp); + logger.debug("Found " + unmanagedInstances.size() + " stopped VMs on remote host " + remoteIp); return new GetRemoteVmsAnswer(command, "", unmanagedInstances); } catch (final LibvirtException e) { - s_logger.error("Failed to list stopped VMs on remote host " + remoteIp + ", due to: " + e.getMessage(), e); + logger.error("Failed to list stopped VMs on remote host " + remoteIp + ", due to: " + e.getMessage(), e); if (e.getMessage().toLowerCase().contains("connection refused")) { return new Answer(command, false, "Unable to connect to remote host " + remoteIp + ", please check the libvirtd tcp connectivity and retry"); } @@ -106,7 +104,7 @@ private UnmanagedInstanceTO getUnmanagedInstance(LibvirtComputingResource libvir return instance; } catch (Exception e) { - s_logger.debug("Unable to retrieve remote unmanaged instance info, due to: " + e.getMessage(), e); + logger.debug("Unable to retrieve remote unmanaged instance info, due to: " + e.getMessage(), e); throw new CloudRuntimeException("Unable to retrieve remote unmanaged instance info, due to: " + e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetUnmanagedInstancesCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetUnmanagedInstancesCommandWrapper.java index d7818f7f5f31..9495646bad54 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetUnmanagedInstancesCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetUnmanagedInstancesCommandWrapper.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.vm.UnmanagedInstanceTO; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainBlockInfo; @@ -42,13 +41,12 @@ @ResourceWrapper(handles=GetUnmanagedInstancesCommand.class) public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(LibvirtGetUnmanagedInstancesCommandWrapper.class); private static final int requiredVncPasswordLength = 22; @Override public GetUnmanagedInstancesAnswer execute(GetUnmanagedInstancesCommand command, LibvirtComputingResource libvirtComputingResource) { - LOGGER.info("Fetching unmanaged instances on host"); + logger.info("Fetching unmanaged instance on host"); HashMap unmanagedInstances = new HashMap<>(); try { @@ -65,7 +63,7 @@ public GetUnmanagedInstancesAnswer execute(GetUnmanagedInstancesCommand command, } } catch (Exception e) { String err = String.format("Error listing unmanaged instances: %s", e.getMessage()); - LOGGER.error(err, e); + logger.error(err, e); return new GetUnmanagedInstancesAnswer(command, err); } @@ -81,7 +79,7 @@ private List getDomains(GetUnmanagedInstancesCommand command, final Domain domain = libvirtComputingResource.getDomain(conn, vmNameCmd); if (domain == null) { String msg = String.format("VM %s not found", vmNameCmd); - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -104,14 +102,14 @@ private List getDomains(GetUnmanagedInstancesCommand command, private void checkIfVmExists(String vmNameCmd,final Domain domain) throws LibvirtException { if (StringUtils.isNotEmpty(vmNameCmd) && !vmNameCmd.equals(domain.getName())) { - LOGGER.error("GetUnmanagedInstancesCommand: exact vm name not found " + vmNameCmd); + logger.error("GetUnmanagedInstancesCommand: exact vm name not found " + vmNameCmd); throw new CloudRuntimeException("GetUnmanagedInstancesCommand: exact vm name not found " + vmNameCmd); } } private void checkIfVmIsManaged(GetUnmanagedInstancesCommand command,String vmNameCmd,final Domain domain) throws LibvirtException { if (command.hasManagedInstance(domain.getName())) { - LOGGER.error("GetUnmanagedInstancesCommand: vm already managed " + vmNameCmd); + logger.error("GetUnmanagedInstancesCommand: vm already managed " + vmNameCmd); throw new CloudRuntimeException("GetUnmanagedInstancesCommand: vm already managed " + vmNameCmd); } } @@ -137,7 +135,7 @@ private UnmanagedInstanceTO getUnmanagedInstance(LibvirtComputingResource libvir return instance; } catch (Exception e) { - LOGGER.info("Unable to retrieve unmanaged instance info. " + e.getMessage(), e); + logger.info("Unable to retrieve unmanaged instance info. " + e.getMessage(), e); return null; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmDiskStatsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmDiskStatsCommandWrapper.java index 6316be9fbf38..6edd667ddcc9 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmDiskStatsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmDiskStatsCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = GetVmDiskStatsCommand.class) public final class LibvirtGetVmDiskStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmDiskStatsCommandWrapper.class); @Override public Answer execute(final GetVmDiskStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -56,12 +54,12 @@ public Answer execute(final GetVmDiskStatsCommand command, final LibvirtComputin vmDiskStatsNameMap.put(vmName, statEntry); } catch (LibvirtException e) { - s_logger.warn("Can't get vm disk stats: " + e.toString() + ", continue"); + logger.warn("Can't get vm disk stats: " + e.toString() + ", continue"); } } return new GetVmDiskStatsAnswer(command, "", command.getHostName(), vmDiskStatsNameMap); } catch (final LibvirtException e) { - s_logger.debug("Can't get vm disk stats: " + e.toString()); + logger.debug("Can't get vm disk stats: " + e.toString()); return new GetVmDiskStatsAnswer(command, null, null, null); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java index da2839d9cee9..61c20f96bacc 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmIpAddressCommandWrapper.java @@ -22,8 +22,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetVmIpAddressCommand; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; @@ -35,7 +33,6 @@ @ResourceWrapper(handles = GetVmIpAddressCommand.class) public final class LibvirtGetVmIpAddressCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmIpAddressCommandWrapper.class); @Override public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -73,7 +70,7 @@ public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputin ip = ipAddr; break; } - s_logger.debug("GetVmIp: "+ vmName + " Ip: "+ipAddr+" does not belong to network "+networkCidr); + logger.debug("GetVmIp: "+ vmName + " Ip: "+ipAddr+" does not belong to network "+networkCidr); } } } else { @@ -85,7 +82,7 @@ public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputin commands.add(new String[]{sed_path, "-e", "s/^\"//", "-e", "s/\"$//"}); String ipList = Script.executePipedCommands(commands, 0).second(); if(ipList != null) { - s_logger.debug("GetVmIp: "+ vmName + "Ips: "+ipList); + logger.debug("GetVmIp: "+ vmName + "Ips: "+ipList); String[] ips = ipList.split("\n"); for (String ipAddr : ips){ // Check if the IP belongs to the network @@ -93,13 +90,13 @@ public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputin ip = ipAddr; break; } - s_logger.debug("GetVmIp: "+ vmName + " Ip: "+ipAddr+" does not belong to network "+networkCidr); + logger.debug("GetVmIp: "+ vmName + " Ip: "+ipAddr+" does not belong to network "+networkCidr); } } } if(ip != null){ result = true; - s_logger.debug("GetVmIp: "+ vmName + " Found Ip: "+ip); + logger.debug("GetVmIp: "+ vmName + " Found Ip: "+ip); } return new Answer(command, result, ip); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmNetworkStatsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmNetworkStatsCommandWrapper.java index 20ee4fd9dea8..03321122c4ae 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmNetworkStatsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmNetworkStatsCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = GetVmNetworkStatsCommand.class) public final class LibvirtGetVmNetworkStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmNetworkStatsCommandWrapper.class); @Override public Answer execute(final GetVmNetworkStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -56,12 +54,12 @@ public Answer execute(final GetVmNetworkStatsCommand command, final LibvirtCompu vmNetworkStatsNameMap.put(vmName, statEntry); } catch (LibvirtException e) { - s_logger.warn("Can't get vm network stats: " + e.toString() + ", continue"); + logger.warn("Can't get vm network stats: " + e.toString() + ", continue"); } } return new GetVmNetworkStatsAnswer(command, "", command.getHostName(), vmNetworkStatsNameMap); } catch (final LibvirtException e) { - s_logger.debug("Can't get vm network stats: " + e.toString()); + logger.debug("Can't get vm network stats: " + e.toString()); return new GetVmNetworkStatsAnswer(command, null, null, null); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmStatsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmStatsCommandWrapper.java index 24853d0a2e81..834b0e834dff 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmStatsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmStatsCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = GetVmStatsCommand.class) public final class LibvirtGetVmStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmStatsCommandWrapper.class); @Override public Answer execute(final GetVmStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -57,12 +55,12 @@ public Answer execute(final GetVmStatsCommand command, final LibvirtComputingRes vmStatsNameMap.put(vmName, statEntry); } catch (LibvirtException e) { - s_logger.warn("Can't get vm stats: " + e.toString() + ", continue"); + logger.warn("Can't get vm stats: " + e.toString() + ", continue"); } } return new GetVmStatsAnswer(command, vmStatsNameMap); } catch (final LibvirtException e) { - s_logger.debug("Can't get vm stats: " + e.toString()); + logger.debug("Can't get vm stats: " + e.toString()); return new GetVmStatsAnswer(command, null); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVolumeStatCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVolumeStatCommandWrapper.java index 2a9c886f449e..5619fcd91390 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVolumeStatCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVolumeStatCommandWrapper.java @@ -19,8 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetVolumeStatAnswer; import com.cloud.agent.api.GetVolumeStatCommand; @@ -35,7 +33,6 @@ @ResourceWrapper(handles = GetVolumeStatCommand.class) public final class LibvirtGetVolumeStatCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVolumeStatCommandWrapper.class); @Override public Answer execute(final GetVolumeStatCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -59,7 +56,7 @@ public Answer execute(final GetVolumeStatCommand cmd, final LibvirtComputingReso return new GetVolumeStatAnswer(cmd, disk.getSize(), disk.getVirtualSize()); } catch (CloudRuntimeException e) { - s_logger.error("Can't get volume stats, due to: " + e.getMessage(), e); + logger.error("Can't get volume stats, due to: " + e.getMessage(), e); return new GetVolumeStatAnswer(cmd, false, "Can't get volume stats, due to: " + e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVolumeStatsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVolumeStatsCommandWrapper.java index a2f50ac6555f..677af99ed157 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVolumeStatsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVolumeStatsCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.HashMap; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = GetVolumeStatsCommand.class) public final class LibvirtGetVolumeStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmDiskStatsCommandWrapper.class); @Override public Answer execute(final GetVolumeStatsCommand cmd, final LibvirtComputingResource libvirtComputingResource) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java index 3d2f7282b06b..135d447fbb2a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder; import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.HandleConfigDriveIsoAnswer; @@ -42,7 +41,6 @@ @ResourceWrapper(handles = HandleConfigDriveIsoCommand.class) public final class LibvirtHandleConfigDriveCommandWrapper extends CommandWrapper { - private static final Logger LOG = Logger.getLogger(LibvirtHandleConfigDriveCommandWrapper.class); @Override public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -50,11 +48,11 @@ public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtCo try { if (command.isCreate()) { - LOG.debug("Creating config drive: " + command.getIsoFile()); + logger.debug("Creating config drive: " + command.getIsoFile()); NetworkElement.Location location = NetworkElement.Location.PRIMARY; if (command.isHostCachePreferred()) { - LOG.debug("Using the KVM host for config drive"); + logger.debug("Using the KVM host for config drive"); mountPoint = libvirtComputingResource.getConfigPath(); location = NetworkElement.Location.HOST; } else { @@ -79,14 +77,14 @@ public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtCo } if (pool.supportsConfigDriveIso()) { - LOG.debug("Using the pool: " + poolUuid + " for config drive"); + logger.debug("Using the pool: " + poolUuid + " for config drive"); mountPoint = pool.getLocalPath(); } else if (command.getUseHostCacheOnUnsupportedPool()) { - LOG.debug("Config drive for KVM is not supported for pool type: " + poolType.toString() + ", using the KVM host"); + logger.debug("Config drive for KVM is not supported for pool type: " + poolType.toString() + ", using the KVM host"); mountPoint = libvirtComputingResource.getConfigPath(); location = NetworkElement.Location.HOST; } else { - LOG.debug("Config drive for KVM is not supported for pool type: " + poolType.toString()); + logger.debug("Config drive for KVM is not supported for pool type: " + poolType.toString()); return new HandleConfigDriveIsoAnswer(command, "Config drive for KVM is not supported for pool type: " + poolType.toString()); } } @@ -98,7 +96,7 @@ public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtCo return new HandleConfigDriveIsoAnswer(command, "Invalid config drive ISO data received"); } if (isoFile.exists()) { - LOG.debug("An old config drive iso already exists"); + logger.debug("An old config drive iso already exists"); } Files.createDirectories(isoPath.getParent()); @@ -106,7 +104,7 @@ public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtCo return new HandleConfigDriveIsoAnswer(command, location); } else { - LOG.debug("Deleting config drive: " + command.getIsoFile()); + logger.debug("Deleting config drive: " + command.getIsoFile()); Path configDrivePath = null; if (command.isHostCachePreferred()) { @@ -138,10 +136,10 @@ public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtCo return new HandleConfigDriveIsoAnswer(command); } } catch (final IOException e) { - LOG.debug("Failed to handle config drive due to " + e.getMessage(), e); + logger.debug("Failed to handle config drive due to " + e.getMessage(), e); return new HandleConfigDriveIsoAnswer(command, "Failed due to exception: " + e.getMessage()); } catch (final CloudRuntimeException e) { - LOG.debug("Failed to handle config drive due to " + e.getMessage(), e); + logger.debug("Failed to handle config drive due to " + e.getMessage(), e); return new HandleConfigDriveIsoAnswer(command, "Failed due to exception: " + e.toString()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtManageSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtManageSnapshotCommandWrapper.java index 0e2492c146fe..ec900e9981e0 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtManageSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtManageSnapshotCommandWrapper.java @@ -22,7 +22,6 @@ import java.io.File; import java.text.MessageFormat; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -49,7 +48,6 @@ @ResourceWrapper(handles = ManageSnapshotCommand.class) public final class LibvirtManageSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtManageSnapshotCommandWrapper.class); @Override public Answer execute(final ManageSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -66,7 +64,7 @@ public Answer execute(final ManageSnapshotCommand command, final LibvirtComputin vm = libvirtComputingResource.getDomain(conn, command.getVmName()); state = vm.getInfo().state; } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + logger.trace("Ignoring libvirt error.", e); } } @@ -83,7 +81,7 @@ public Answer execute(final ManageSnapshotCommand command, final LibvirtComputin final String vmUuid = vm.getUUIDString(); final Object[] args = new Object[] {snapshotName, vmUuid}; final String snapshot = snapshotXML.format(args); - s_logger.debug(snapshot); + logger.debug(snapshot); if (command.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.CREATE_SNAPSHOT)) { vm.snapshotCreateXML(snapshot); } else { @@ -121,31 +119,31 @@ public Answer execute(final ManageSnapshotCommand command, final LibvirtComputin r.confSet("key", primaryPool.getAuthSecret()); r.confSet("client_mount_timeout", "30"); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); final IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir()); final Rbd rbd = new Rbd(io); final RbdImage image = rbd.open(disk.getName()); if (command.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.CREATE_SNAPSHOT)) { - s_logger.debug("Attempting to create RBD snapshot " + disk.getName() + "@" + snapshotName); + logger.debug("Attempting to create RBD snapshot " + disk.getName() + "@" + snapshotName); image.snapCreate(snapshotName); } else { - s_logger.debug("Attempting to remove RBD snapshot " + disk.getName() + "@" + snapshotName); + logger.debug("Attempting to remove RBD snapshot " + disk.getName() + "@" + snapshotName); image.snapRemove(snapshotName); } rbd.close(image); r.ioCtxDestroy(io); } catch (final Exception e) { - s_logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage()); + logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage()); } } else { /* VM is not running, create a snapshot by ourself */ final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout(); final String manageSnapshotPath = libvirtComputingResource.manageSnapshotPath(); - final Script scriptCommand = new Script(manageSnapshotPath, cmdsTimeout, s_logger); + final Script scriptCommand = new Script(manageSnapshotPath, cmdsTimeout, logger); if (command.getCommandSwitch().equalsIgnoreCase(ManageSnapshotCommand.CREATE_SNAPSHOT)) { scriptCommand.add("-c", disk.getPath()); } else { @@ -155,14 +153,14 @@ public Answer execute(final ManageSnapshotCommand command, final LibvirtComputin scriptCommand.add("-n", snapshotName); final String result = scriptCommand.execute(); if (result != null) { - s_logger.debug("Failed to manage snapshot: " + result); + logger.debug("Failed to manage snapshot: " + result); return new ManageSnapshotAnswer(command, false, "Failed to manage snapshot: " + result); } } } return new ManageSnapshotAnswer(command, command.getSnapshotId(), disk.getPath() + File.separator + snapshotName, true, null); } catch (final LibvirtException e) { - s_logger.debug("Failed to manage snapshot: " + e.toString()); + logger.debug("Failed to manage snapshot: " + e.toString()); return new ManageSnapshotAnswer(command, false, "Failed to manage snapshot: " + e.toString()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java index 5ba174acd391..e15a32876927 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java @@ -50,7 +50,6 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -93,7 +92,6 @@ public final class LibvirtMigrateCommandWrapper extends CommandWrapper vlanToPersistenceMap = command.getVlanToPersistenceMap(); final String destinationUri = createMigrationURI(command.getDestinationIp(), libvirtComputingResource); final List migrateDiskInfoList = command.getMigrateDiskInfoList(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Trying to migrate VM [%s] to destination host: [%s].", vmName, destinationUri)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Trying to migrate VM [%s] to destination host: [%s].", vmName, destinationUri)); } String result = null; @@ -130,8 +128,8 @@ public Answer execute(final MigrateCommand command, final LibvirtComputingResour conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName); ifaces = libvirtComputingResource.getInterfaces(conn, vmName); disks = libvirtComputingResource.getDisks(conn, vmName); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Found domain with name [%s]. Starting VM migration to host [%s].", vmName, destinationUri)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Found domain with name [%s]. Starting VM migration to host [%s].", vmName, destinationUri)); } VirtualMachineTO to = command.getVirtualMachine(); @@ -159,8 +157,8 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. final String target = command.getDestinationIp(); xmlDesc = dm.getXMLDesc(xmlFlag); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("VM [%s] with XML configuration [%s] will be migrated to host [%s].", vmName, xmlDesc, target)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("VM [%s] with XML configuration [%s] will be migrated to host [%s].", vmName, xmlDesc, target)); } // Limit the VNC password in case the length is greater than 8 characters @@ -172,10 +170,10 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. String oldIsoVolumePath = getOldVolumePath(disks, vmName); String newIsoVolumePath = getNewVolumePathIfDatastoreHasChanged(libvirtComputingResource, conn, to); if (newIsoVolumePath != null && !newIsoVolumePath.equals(oldIsoVolumePath)) { - s_logger.debug(String.format("Editing mount path of iso from %s to %s", oldIsoVolumePath, newIsoVolumePath)); + logger.debug(String.format("Editing mount path of iso from %s to %s", oldIsoVolumePath, newIsoVolumePath)); xmlDesc = replaceDiskSourceFile(xmlDesc, newIsoVolumePath, vmName); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Replaced disk mount point [%s] with [%s] in VM [%s] XML configuration. New XML configuration is [%s].", oldIsoVolumePath, newIsoVolumePath, vmName, xmlDesc)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Replaced disk mount point [%s] with [%s] in VM [%s] XML configuration. New XML configuration is [%s].", oldIsoVolumePath, newIsoVolumePath, vmName, xmlDesc)); } } @@ -205,24 +203,24 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. Set migrateDiskLabels = null; if (migrateStorage) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Changing VM [%s] volumes during migration to host: [%s].", vmName, target)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Changing VM [%s] volumes during migration to host: [%s].", vmName, target)); } xmlDesc = replaceStorage(xmlDesc, mapMigrateStorage, migrateStorageManaged); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Changed VM [%s] XML configuration of used storage. New XML configuration is [%s].", vmName, xmlDesc)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Changed VM [%s] XML configuration of used storage. New XML configuration is [%s].", vmName, xmlDesc)); } migrateDiskLabels = getMigrateStorageDeviceLabels(disks, mapMigrateStorage); } Map dpdkPortsMapping = command.getDpdkInterfaceMapping(); if (MapUtils.isNotEmpty(dpdkPortsMapping)) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Changing VM [%s] DPDK interfaces during migration to host: [%s].", vmName, target)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Changing VM [%s] DPDK interfaces during migration to host: [%s].", vmName, target)); } xmlDesc = replaceDpdkInterfaces(xmlDesc, dpdkPortsMapping); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc)); } } @@ -235,7 +233,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. } //run migration in thread so we can monitor it - s_logger.info(String.format("Starting live migration of instance [%s] to destination host [%s] having the final XML configuration: [%s].", vmName, dconn.getURI(), xmlDesc)); + logger.info(String.format("Starting live migration of instance [%s] to destination host [%s] having the final XML configuration: [%s].", vmName, dconn.getURI(), xmlDesc)); final ExecutorService executor = Executors.newFixedThreadPool(1); boolean migrateNonSharedInc = command.isMigrateNonSharedInc() && !migrateStorageManaged; @@ -254,15 +252,15 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. try { final int setDowntime = dm.migrateSetMaxDowntime(migrateDowntime); if (setDowntime == 0 ) { - s_logger.debug("Set max downtime for migration of " + vmName + " to " + String.valueOf(migrateDowntime) + "ms"); + logger.debug("Set max downtime for migration of " + vmName + " to " + String.valueOf(migrateDowntime) + "ms"); } } catch (final LibvirtException e) { - s_logger.debug("Failed to set max downtime for migration, perhaps migration completed? Error: " + e.getMessage()); + logger.debug("Failed to set max downtime for migration, perhaps migration completed? Error: " + e.getMessage()); } } } if (sleeptime % 1000 == 0) { - s_logger.info("Waiting for migration of " + vmName + " to complete, waited " + sleeptime + "ms"); + logger.info("Waiting for migration of " + vmName + " to complete, waited " + sleeptime + "ms"); } // abort the vm migration if the job is executed more than vm.migrate.wait @@ -272,18 +270,18 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. try { state = dm.getInfo().state; } catch (final LibvirtException e) { - s_logger.info("Couldn't get VM domain state after " + sleeptime + "ms: " + e.getMessage()); + logger.info("Couldn't get VM domain state after " + sleeptime + "ms: " + e.getMessage()); } if (state != null && state == DomainState.VIR_DOMAIN_RUNNING) { try { DomainJobInfo job = dm.getJobInfo(); - s_logger.info(String.format("Aborting migration of VM [%s] with domain job [%s] due to time out after %d seconds.", vmName, job, migrateWait)); + logger.info(String.format("Aborting migration of VM [%s] with domain job [%s] due to time out after %d seconds.", vmName, job, migrateWait)); dm.abortJob(); result = String.format("Migration of VM [%s] was cancelled by CloudStack due to time out after %d seconds.", vmName, migrateWait); - s_logger.debug(result); + logger.debug(result); break; } catch (final LibvirtException e) { - s_logger.error(String.format("Failed to abort the VM migration job of VM [%s] due to: [%s].", vmName, e.getMessage()), e); + logger.error(String.format("Failed to abort the VM migration job of VM [%s] due to: [%s].", vmName, e.getMessage()), e); } } } @@ -295,36 +293,37 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. try { state = dm.getInfo().state; } catch (final LibvirtException e) { - s_logger.info("Couldn't get VM domain state after " + sleeptime + "ms: " + e.getMessage()); + logger.info("Couldn't get VM domain state after " + sleeptime + "ms: " + e.getMessage()); } if (state != null && state == DomainState.VIR_DOMAIN_RUNNING) { try { - s_logger.info("Pausing VM " + vmName + " due to property vm.migrate.pauseafter setting to " + migratePauseAfter + "ms to complete migration"); + logger.info("Pausing VM " + vmName + " due to property vm.migrate.pauseafter setting to " + migratePauseAfter + "ms to complete migration"); dm.suspend(); } catch (final LibvirtException e) { // pause could be racy if it attempts to pause right when vm is finished, simply warn - s_logger.info("Failed to pause vm " + vmName + " : " + e.getMessage()); + logger.info("Failed to pause vm " + vmName + " : " + e.getMessage()); } } } } - s_logger.info(String.format("Migration thread of VM [%s] finished.", vmName)); + logger.info(String.format("Migration thread of VM [%s] finished.", vmName)); destDomain = migrateThread.get(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_DOMAIN_RETRIEVE_TIMEOUT), TimeUnit.SECONDS); if (destDomain != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Cleaning the disks of VM [%s] in the source pool after VM migration finished.", vmName)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Cleaning the disks of VM [%s] in the source pool after VM migration finished.", vmName)); } deleteOrDisconnectDisksOnSourcePool(libvirtComputingResource, migrateDiskInfoList, disks); libvirtComputingResource.cleanOldSecretsByDiskDef(conn, disks); } } catch (final LibvirtException e) { - s_logger.error(String.format("Can't migrate domain [%s] due to: [%s].", vmName, e.getMessage()), e); + logger.error(String.format("Can't migrate domain [%s] due to: [%s].", vmName, e.getMessage()), e); result = e.getMessage(); if (result.startsWith("unable to connect to server") && result.endsWith("refused")) { - result = String.format("Migration was refused connection to destination: %s. Please check libvirt configuration compatibility and firewall rules on the source and destination hosts.", destinationUri); + logger.debug("Migration failed as connection to destination [{}] was refused. Please check libvirt configuration compatibility and firewall rules on the source and destination hosts.", destinationUri); + result = String.format("Failed to migrate domain [%s].", vmName); } } catch (final InterruptedException | ExecutionException @@ -334,7 +333,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. | SAXException | TransformerException | URISyntaxException e) { - s_logger.error(String.format("Can't migrate domain [%s] due to: [%s].", vmName, e.getMessage()), e); + logger.error(String.format("Can't migrate domain [%s] due to: [%s].", vmName, e.getMessage()), e); if (result == null) { result = "Exception during migrate: " + e.getMessage(); } @@ -359,7 +358,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. destDomain.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + logger.trace("Ignoring libvirt error.", e); } } @@ -387,13 +386,13 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0. * */ protected Set getMigrateStorageDeviceLabels(List diskDefinitions, Map mapMigrateStorage) { HashSet setOfLabels = new HashSet<>(); - s_logger.debug(String.format("Searching for disk labels of disks [%s].", mapMigrateStorage.keySet())); + logger.debug("Searching for disk labels of disks [{}].", mapMigrateStorage.keySet()); for (String fileName : mapMigrateStorage.keySet()) { for (DiskDef diskDef : diskDefinitions) { String diskPath = diskDef.getDiskPath(); if (diskPath != null && diskPath.contains(fileName)) { setOfLabels.add(diskDef.getDiskLabel()); - s_logger.debug(String.format("Found label [%s] for disk [%s].", diskDef.getDiskLabel(), fileName)); + logger.debug("Found label [{}] for disk [{}].", diskDef.getDiskLabel(), fileName); break; } } @@ -421,7 +420,7 @@ protected String updateVmSharesIfNeeded(MigrateCommand migrateCommand, String xm int currentCpuShares = libvirtComputingResource.calculateCpuShares(migrateCommand.getVirtualMachine()); if (newVmCpuShares == currentCpuShares) { - s_logger.info(String.format("Current CPU shares [%s] is equal in both hosts; therefore, there is no need to update the CPU shares for the new host.", + logger.info(String.format("Current CPU shares [%s] is equal in both hosts; therefore, there is no need to update the CPU shares for the new host.", currentCpuShares)); return xmlDesc; } @@ -435,7 +434,7 @@ protected String updateVmSharesIfNeeded(MigrateCommand migrateCommand, String xm Node sharesNode = root.getElementsByTagName("shares").item(0); String currentShares = sharesNode.getTextContent(); - s_logger.info(String.format("VM [%s] will have CPU shares altered from [%s] to [%s] as part of migration because the cgroups version differs between hosts.", + logger.info(String.format("VM [%s] will have CPU shares altered from [%s] to [%s] as part of migration because the cgroups version differs between hosts.", migrateCommand.getVmName(), currentShares, newVmCpuShares)); sharesNode.setTextContent(String.valueOf(newVmCpuShares)); return getXml(document); @@ -536,7 +535,7 @@ protected void deleteLocalVolume(String localPath) { StorageVol storageVolLookupByPath = conn.storageVolLookupByPath(localPath); storageVolLookupByPath.delete(0); } catch (LibvirtException e) { - s_logger.error(String.format("Cannot delete local volume [%s] due to: %s", localPath, e)); + logger.error(String.format("Cannot delete local volume [%s] due to: %s", localPath, e)); } } @@ -549,7 +548,7 @@ protected MigrateDiskInfo searchDiskDefOnMigrateDiskInfoList(List { - private static final Logger LOGGER = Logger.getLogger(LibvirtMigrateVolumeCommandWrapper.class); @Override public Answer execute(final MigrateVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -139,17 +137,17 @@ protected MigrateVolumeAnswer migratePowerFlexVolume(final MigrateVolumeCommand parameters[0] = parameter; dm.blockCopy(destDiskLabel, diskdef, parameters, Domain.BlockCopyFlags.REUSE_EXT); - LOGGER.info(String.format("Block copy has started for the volume %s : %s ", destDiskLabel, srcPath)); + logger.info(String.format("Block copy has started for the volume %s : %s ", destDiskLabel, srcPath)); return checkBlockJobStatus(command, dm, destDiskLabel, srcPath, destPath, libvirtComputingResource, conn, srcSecretUUID); } catch (Exception e) { String msg = "Migrate volume failed due to " + e.toString(); - LOGGER.warn(msg, e); + logger.warn(msg, e); if (destDiskLabel != null) { try { dm.blockJobAbort(destDiskLabel, Domain.BlockJobAbortFlags.ASYNC); } catch (LibvirtException ex) { - LOGGER.error("Migrate volume failed while aborting the block job due to " + ex.getMessage()); + logger.error("Migrate volume failed while aborting the block job due to " + ex.getMessage()); } } return new MigrateVolumeAnswer(command, false, msg, null); @@ -158,7 +156,7 @@ protected MigrateVolumeAnswer migratePowerFlexVolume(final MigrateVolumeCommand try { dm.free(); } catch (LibvirtException l) { - LOGGER.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); }; } } @@ -172,11 +170,11 @@ protected MigrateVolumeAnswer checkBlockJobStatus(MigrateVolumeCommand command, DomainBlockJobInfo blockJobInfo = dm.getBlockJobInfo(diskLabel, 0); if (blockJobInfo != null) { blockCopyProgress = (blockJobInfo.end == 0)? blockCopyProgress : 100 * (blockJobInfo.cur / (double) blockJobInfo.end); - LOGGER.debug(String.format("Volume %s : %s, block copy progress: %s%%, current value: %s end value: %s, job info - type: %s, bandwidth: %s", + logger.debug(String.format("Volume %s : %s, block copy progress: %s%%, current value: %s end value: %s, job info - type: %s, bandwidth: %s", diskLabel, srcPath, blockCopyProgress, blockJobInfo.cur, blockJobInfo.end, blockJobInfo.type, blockJobInfo.bandwidth)); if (blockJobInfo.cur == blockJobInfo.end) { if (blockJobInfo.end > 0) { - LOGGER.info(String.format("Block copy completed for the volume %s : %s", diskLabel, srcPath)); + logger.info(String.format("Block copy completed for the volume %s : %s", diskLabel, srcPath)); dm.blockJobAbort(diskLabel, Domain.BlockJobAbortFlags.PIVOT); if (StringUtils.isNotEmpty(srcSecretUUID)) { libvirtComputingResource.removeLibvirtVolumeSecret(conn, srcSecretUUID); @@ -185,12 +183,12 @@ protected MigrateVolumeAnswer checkBlockJobStatus(MigrateVolumeCommand command, } else { // cur = 0, end = 0 - at this point, disk does not have an active block job (so, no need to abort job) String msg = String.format("No active block copy job for the volume %s : %s - job stopped at %s progress", diskLabel, srcPath, blockCopyProgress); - LOGGER.warn(msg); + logger.warn(msg); return new MigrateVolumeAnswer(command, false, msg, null); } } } else { - LOGGER.info("Failed to get the block copy status, trying to abort the job"); + logger.info("Failed to get the block copy status, trying to abort the job"); dm.blockJobAbort(diskLabel, Domain.BlockJobAbortFlags.ASYNC); } waitTimeInSec--; @@ -204,11 +202,11 @@ protected MigrateVolumeAnswer checkBlockJobStatus(MigrateVolumeCommand command, if (waitTimeInSec <= 0) { String msg = "Block copy is taking long time, failing the job"; - LOGGER.error(msg); + logger.error(msg); try { dm.blockJobAbort(diskLabel, Domain.BlockJobAbortFlags.ASYNC); } catch (LibvirtException ex) { - LOGGER.error("Migrate volume failed while aborting the block job due to " + ex.getMessage()); + logger.error("Migrate volume failed while aborting the block job due to " + ex.getMessage()); } return new MigrateVolumeAnswer(command, false, msg, null); } @@ -332,14 +330,14 @@ protected MigrateVolumeAnswer migrateRegularVolume(final MigrateVolumeCommand co storagePoolManager.disconnectPhysicalDisk(destPrimaryDataStore.getPoolType(), destPrimaryDataStore.getUuid(), destPath); } catch (Exception e) { - LOGGER.warn("Unable to disconnect from the destination device.", e); + logger.warn("Unable to disconnect from the destination device.", e); } try { storagePoolManager.disconnectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath); } catch (Exception e) { - LOGGER.warn("Unable to disconnect from the source device.", e); + logger.warn("Unable to disconnect from the source device.", e); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifySshKeysCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifySshKeysCommandWrapper.java index b9af013f77eb..a4d1c070f787 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifySshKeysCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifySshKeysCommandWrapper.java @@ -24,7 +24,6 @@ import java.io.FileOutputStream; import java.io.IOException; -import org.apache.log4j.Logger; import com.cloud.utils.StringUtils; import com.cloud.agent.api.Answer; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = ModifySshKeysCommand.class) public final class LibvirtModifySshKeysCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtModifySshKeysCommandWrapper.class); @Override public Answer execute(final ModifySshKeysCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -52,13 +50,13 @@ public Answer execute(final ModifySshKeysCommand command, final LibvirtComputing String result = null; if (!sshKeysDir.exists()) { // Change permissions for the 700 - final Script script = new Script("mkdir", libvirtComputingResource.getTimeout(), s_logger); + final Script script = new Script("mkdir", libvirtComputingResource.getTimeout(), logger); script.add("-m", "700"); script.add(sshkeyspath); script.execute(); if (!sshKeysDir.exists()) { - s_logger.debug("failed to create directory " + sshkeyspath); + logger.debug("failed to create directory " + sshkeyspath); } } @@ -68,7 +66,7 @@ public Answer execute(final ModifySshKeysCommand command, final LibvirtComputing pubKeyFile.createNewFile(); } catch (final IOException e) { result = "Failed to create file: " + e.toString(); - s_logger.debug(result); + logger.debug(result); } } @@ -78,10 +76,10 @@ public Answer execute(final ModifySshKeysCommand command, final LibvirtComputing } catch (final FileNotFoundException e) { result = "File" + sshpubkeypath + "is not found:" + e.toString(); - s_logger.debug(result); + logger.debug(result); } catch (final IOException e) { result = "Write file " + sshpubkeypath + ":" + e.toString(); - s_logger.debug(result); + logger.debug(result); } } @@ -91,7 +89,7 @@ public Answer execute(final ModifySshKeysCommand command, final LibvirtComputing prvKeyFile.createNewFile(); } catch (final IOException e) { result = "Failed to create file: " + e.toString(); - s_logger.debug(result); + logger.debug(result); } } @@ -103,12 +101,12 @@ public Answer execute(final ModifySshKeysCommand command, final LibvirtComputing } } catch (final FileNotFoundException e) { result = "File" + sshprvkeypath + "is not found:" + e.toString(); - s_logger.debug(result); + logger.debug(result); } catch (final IOException e) { result = "Write file " + sshprvkeypath + ":" + e.toString(); - s_logger.debug(result); + logger.debug(result); } - final Script script = new Script("chmod", libvirtComputingResource.getTimeout(), s_logger); + final Script script = new Script("chmod", libvirtComputingResource.getTimeout(), logger); script.add("600", sshprvkeypath); script.execute(); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyTargetsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyTargetsCommandWrapper.java index 724caad3f227..b05917143d55 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyTargetsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtModifyTargetsCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ModifyTargetsAnswer; @@ -38,7 +37,6 @@ @ResourceWrapper(handles = ModifyTargetsCommand.class) public final class LibvirtModifyTargetsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtModifyTargetsCommandWrapper.class); @Override public Answer execute(final ModifyTargetsCommand command, final LibvirtComputingResource libvirtComputingResource) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesSystemVmCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesSystemVmCommandWrapper.java index 65169a3f23d5..b5ee13920a68 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesSystemVmCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesSystemVmCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = NetworkRulesSystemVmCommand.class) public final class LibvirtNetworkRulesSystemVmCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final NetworkRulesSystemVmCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -43,7 +41,7 @@ public Answer execute(final NetworkRulesSystemVmCommand command, final LibvirtCo final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName()); success = libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, command.getVmName()); } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + logger.trace("Ignoring libvirt error.", e); } return new Answer(command, success, ""); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java index 07c091ee0eee..890558ca3651 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = NetworkRulesVmSecondaryIpCommand.class) public final class LibvirtNetworkRulesVmSecondaryIpCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final NetworkRulesVmSecondaryIpCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -43,7 +41,7 @@ public Answer execute(final NetworkRulesVmSecondaryIpCommand command, final Libv final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName()); result = libvirtComputingResource.configureNetworkRulesVMSecondaryIP(conn, command.getVmName(), command.getVmMac(), command.getVmSecIp(), command.getAction()); } catch (final LibvirtException e) { - s_logger.debug("Could not configure VM secondary IP! => " + e.getLocalizedMessage()); + logger.debug("Could not configure VM secondary IP! => " + e.getLocalizedMessage()); } return new Answer(command, result, ""); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java index fc6839583036..14aaf234c162 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsCreateTunnelAnswer; @@ -32,19 +31,18 @@ @ResourceWrapper(handles = OvsCreateTunnelCommand.class) public final class LibvirtOvsCreateTunnelCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsCreateTunnelCommandWrapper.class); @Override public Answer execute(final OvsCreateTunnelCommand command, final LibvirtComputingResource libvirtComputingResource) { final String bridge = command.getNetworkName(); try { if (!libvirtComputingResource.findOrCreateTunnelNetwork(bridge)) { - s_logger.debug("Error during bridge setup"); + logger.debug("Error during bridge setup"); return new OvsCreateTunnelAnswer(command, false, "Cannot create network", bridge); } libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(), command.getNetworkName()); - final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger); + final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), logger); scriptCommand.add("create_tunnel"); scriptCommand.add("--bridge", bridge); scriptCommand.add("--remote_ip", command.getRemoteIp()); @@ -59,7 +57,7 @@ public Answer execute(final OvsCreateTunnelCommand command, final LibvirtComputi return new OvsCreateTunnelAnswer(command, false, result, bridge); } } catch (final Exception e) { - s_logger.warn("Caught execption when creating ovs tunnel", e); + logger.warn("Caught execption when creating ovs tunnel", e); return new OvsCreateTunnelAnswer(command, false, e.getMessage(), bridge); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyBridgeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyBridgeCommandWrapper.java index 2e70a89b185e..0de9096659a5 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyBridgeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyBridgeCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsDestroyBridgeCommand; @@ -30,14 +29,13 @@ @ResourceWrapper(handles = OvsDestroyBridgeCommand.class) public final class LibvirtOvsDestroyBridgeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsDestroyBridgeCommandWrapper.class); @Override public Answer execute(final OvsDestroyBridgeCommand command, final LibvirtComputingResource libvirtComputingResource) { final boolean result = libvirtComputingResource.destroyTunnelNetwork(command.getBridgeName()); if (!result) { - s_logger.debug("Error trying to destroy OVS Bridge!"); + logger.debug("Error trying to destroy OVS Bridge!"); } return new Answer(command, result, null); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyTunnelCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyTunnelCommandWrapper.java index a1a9851e78fb..83fc26bf0ff4 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyTunnelCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyTunnelCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsDestroyTunnelCommand; @@ -31,18 +30,17 @@ @ResourceWrapper(handles = OvsDestroyTunnelCommand.class) public final class LibvirtOvsDestroyTunnelCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsDestroyTunnelCommandWrapper.class); @Override public Answer execute(final OvsDestroyTunnelCommand command, final LibvirtComputingResource libvirtComputingResource) { try { if (!libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())) { - s_logger.warn("Unable to find tunnel network for GRE key:" + logger.warn("Unable to find tunnel network for GRE key:" + command.getBridgeName()); return new Answer(command, false, "No network found"); } - final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger); + final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), logger); scriptCommand.add("destroy_tunnel"); scriptCommand.add("--bridge", command.getBridgeName()); scriptCommand.add("--iface_name", command.getInPortName()); @@ -53,7 +51,7 @@ public Answer execute(final OvsDestroyTunnelCommand command, final LibvirtComput return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught execption when destroy ovs tunnel", e); + logger.warn("caught execption when destroy ovs tunnel", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java index 117a832a68b9..923c44f48285 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java @@ -25,8 +25,6 @@ import java.net.SocketException; import java.util.Enumeration; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsFetchInterfaceAnswer; import com.cloud.agent.api.OvsFetchInterfaceCommand; @@ -38,7 +36,6 @@ @ResourceWrapper(handles = OvsFetchInterfaceCommand.class) public final class LibvirtOvsFetchInterfaceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsFetchInterfaceCommandWrapper.class); private String getSubnetMaskForAddress(NetworkInterface networkInterface, InetAddress inetAddress) { for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) { @@ -94,7 +91,7 @@ public Ternary getInterfaceDetails(String interfaceName) public Answer execute(final OvsFetchInterfaceCommand command, final LibvirtComputingResource libvirtComputingResource) { final String label = "'" + command.getLabel() + "'"; - s_logger.debug("Will look for network with name-label:" + label); + logger.debug("Will look for network with name-label:" + label); try { Ternary interfaceDetails = getInterfaceDetails(label); return new OvsFetchInterfaceAnswer(command, true, "Interface " + label @@ -102,7 +99,7 @@ public Answer execute(final OvsFetchInterfaceCommand command, final LibvirtCompu interfaceDetails.third()); } catch (final Exception e) { - s_logger.warn("Caught execption when fetching interface", e); + logger.warn("Caught execption when fetching interface", e); return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage()); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsSetupBridgeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsSetupBridgeCommandWrapper.java index 2eb0d082c49f..986495004296 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsSetupBridgeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsSetupBridgeCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsSetupBridgeCommand; @@ -30,7 +29,6 @@ @ResourceWrapper(handles = OvsSetupBridgeCommand.class) public final class LibvirtOvsSetupBridgeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsSetupBridgeCommandWrapper.class); @Override public Answer execute(final OvsSetupBridgeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -41,7 +39,7 @@ public Answer execute(final OvsSetupBridgeCommand command, final LibvirtComputin final boolean finalResult = findResult && configResult; if (!finalResult) { - s_logger.debug("::FAILURE:: OVS Bridge was NOT configured properly!"); + logger.debug("::FAILURE:: OVS Bridge was NOT configured properly!"); } return new Answer(command, finalResult, null); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper.java index 5fc8e8cf70b4..2f5c418d3d79 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand; @@ -31,12 +30,11 @@ @ResourceWrapper(handles = OvsVpcPhysicalTopologyConfigCommand.class) public final class LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper.class); @Override public Answer execute(final OvsVpcPhysicalTopologyConfigCommand command, final LibvirtComputingResource libvirtComputingResource) { try { - final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger); + final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), logger); scriptCommand.add("configure_ovs_bridge_for_network_topology"); scriptCommand.add("--bridge", command.getBridgeName()); scriptCommand.add("--config", command.getVpcConfigInJson()); @@ -48,7 +46,7 @@ public Answer execute(final OvsVpcPhysicalTopologyConfigCommand command, final L return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught exception while updating host with latest routing polcies", e); + logger.warn("caught exception while updating host with latest routing polcies", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.java index e82801995468..b481cecde23c 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand; @@ -31,12 +30,11 @@ @ResourceWrapper(handles = OvsVpcRoutingPolicyConfigCommand.class) public final class LibvirtOvsVpcRoutingPolicyConfigCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final OvsVpcRoutingPolicyConfigCommand command, final LibvirtComputingResource libvirtComputingResource) { try { - final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger); + final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), logger); scriptCommand.add("configure_ovs_bridge_for_routing_policies"); scriptCommand.add("--bridge", command.getBridgeName()); scriptCommand.add("--config", command.getVpcConfigInJson()); @@ -48,7 +46,7 @@ public Answer execute(final OvsVpcRoutingPolicyConfigCommand command, final Libv return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught exception while updating host with latest VPC topology", e); + logger.warn("caught exception while updating host with latest VPC topology", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPatchSystemVmCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPatchSystemVmCommandWrapper.java index 7800e95c39b9..2c8918e620dd 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPatchSystemVmCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPatchSystemVmCommandWrapper.java @@ -31,13 +31,11 @@ import com.cloud.utils.ssh.SshHelper; import com.cloud.utils.validation.ChecksumUtil; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; @ResourceWrapper(handles = PatchSystemVmCommand.class) public class LibvirtPatchSystemVmCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPatchSystemVmCommandWrapper.class); private static int sshPort = Integer.parseInt(LibvirtComputingResource.DEFAULTDOMRSSHPORT); private static File pemFile = new File(LibvirtComputingResource.SSHPRVKEYPATH); @@ -63,7 +61,7 @@ public Answer execute(PatchSystemVmCommand cmd, LibvirtComputingResource serverR if (!StringUtils.isEmpty(checksum) && checksum.equals(scriptChecksum) && !cmd.isForced()) { String msg = String.format("No change in the scripts checksum, not patching systemVM %s", sysVMName); - s_logger.info(msg); + logger.info(msg); return new PatchSystemVmAnswer(cmd, msg, lines[0], lines[1]); } @@ -79,10 +77,11 @@ public Answer execute(PatchSystemVmCommand cmd, LibvirtComputingResource serverR if (patchResult.first()) { String scriptVersion = lines[1]; if (StringUtils.isNotEmpty(patchResult.second())) { + logger.debug("Patch result of systemVM {}: {}", sysVMName, patchResult.second()); String res = patchResult.second().replace("\n", " "); String[] output = res.split(":"); if (output.length != 2) { - s_logger.warn("Failed to get the latest script version"); + logger.warn("Failed to get the latest script version"); } else { scriptVersion = output[1].split(" ")[0]; } @@ -98,12 +97,12 @@ private ExecutionResult getSystemVmVersionAndChecksum(LibvirtComputingResource s result = serverResource.executeInVR(controlIp, VRScripts.VERSION, null); if (!result.isSuccess()) { String errMsg = String.format("GetSystemVMVersionCmd on %s failed, message %s", controlIp, result.getDetails()); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (final Exception e) { final String msg = "GetSystemVMVersionCmd failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg, e); } return result; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPingTestCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPingTestCommandWrapper.java index 6b428c6bc159..605861492487 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPingTestCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPingTestCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.PingTestCommand; @@ -31,7 +30,6 @@ @ResourceWrapper(handles = PingTestCommand.class) public final class LibvirtPingTestCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPingTestCommandWrapper.class); @Override public Answer execute(final PingTestCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -53,13 +51,13 @@ public Answer execute(final PingTestCommand command, final LibvirtComputingResou } protected String doPingTest(final LibvirtComputingResource libvirtComputingResource, final String computingHostIp) { - final Script command = new Script(libvirtComputingResource.getPingTestPath(), 10000, s_logger); + final Script command = new Script(libvirtComputingResource.getPingTestPath(), 10000, logger); command.add("-h", computingHostIp); return command.execute(); } protected String doPingTest(final LibvirtComputingResource libvirtComputingResource, final String domRIp, final String vmIp) { - final Script command = new Script(libvirtComputingResource.getPingTestPath(), 10000, s_logger); + final Script command = new Script(libvirtComputingResource.getPingTestPath(), 10000, logger); command.add("-i", domRIp); command.add("-p", vmIp); return command.execute(); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java index dffa8360c200..b0950376a93d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java @@ -30,7 +30,6 @@ import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; import com.cloud.vm.VirtualMachine; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.LibvirtException; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = PlugNicCommand.class) public final class LibvirtPlugNicCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPlugNicCommandWrapper.class); @Override public Answer execute(final PlugNicCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -57,7 +55,7 @@ public Answer execute(final PlugNicCommand command, final LibvirtComputingResour Integer nicnum = 0; for (final InterfaceDef pluggedNic : pluggedNics) { if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) { - s_logger.debug("found existing nic for mac " + pluggedNic.getMacAddress() + " at index " + nicnum); + logger.debug("found existing nic for mac " + pluggedNic.getMacAddress() + " at index " + nicnum); return new PlugNicAnswer(command, true, "success"); } nicnum++; @@ -82,18 +80,18 @@ public Answer execute(final PlugNicCommand command, final LibvirtComputingResour return new PlugNicAnswer(command, true, "success"); } catch (final LibvirtException e) { final String msg = " Plug Nic failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new PlugNicAnswer(command, false, msg); } catch (final InternalErrorException e) { final String msg = " Plug Nic failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new PlugNicAnswer(command, false, msg); } finally { if (vm != null) { try { vm.free(); } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPostCertificateRenewalCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPostCertificateRenewalCommandWrapper.java index 5f8e2ca7a4ed..49e079348efb 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPostCertificateRenewalCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPostCertificateRenewalCommandWrapper.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.ca.PostCertificateRenewalCommand; import org.apache.cloudstack.ca.SetupCertificateAnswer; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; @@ -30,14 +29,13 @@ @ResourceWrapper(handles = PostCertificateRenewalCommand.class) public final class LibvirtPostCertificateRenewalCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPostCertificateRenewalCommandWrapper.class); @Override public Answer execute(final PostCertificateRenewalCommand command, final LibvirtComputingResource serverResource) { - s_logger.info("Restarting libvirt after certificate provisioning/renewal"); + logger.info("Restarting libvirt after certificate provisioning/renewal"); if (command != null) { final int timeout = 30000; - Script script = new Script(true, "service", timeout, s_logger); + Script script = new Script(true, "service", timeout, logger); script.add("libvirtd"); script.add("restart"); script.execute(); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareForMigrationCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareForMigrationCommandWrapper.java index 77333f87140f..535494877043 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareForMigrationCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareForMigrationCommandWrapper.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.storage.configdrive.ConfigDrive; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -51,7 +50,6 @@ @ResourceWrapper(handles = PrepareForMigrationCommand.class) public final class LibvirtPrepareForMigrationCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPrepareForMigrationCommandWrapper.class); @Override public Answer execute(final PrepareForMigrationCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -61,8 +59,8 @@ public Answer execute(final PrepareForMigrationCommand command, final LibvirtCom return handleRollback(command, libvirtComputingResource); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Preparing host for migrating " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Preparing host for migrating " + vm); } final NicTO[] nics = vm.getNics(); @@ -110,10 +108,10 @@ public Answer execute(final PrepareForMigrationCommand command, final LibvirtCom secretConsumer = volume.getDetails().get(DiskTO.SECRET_CONSUMER_DETAIL); } String secretUuid = libvirtComputingResource.createLibvirtVolumeSecret(conn, secretConsumer, volumeObjectTO.getPassphrase()); - s_logger.debug(String.format("Created libvirt secret %s for disk %s", secretUuid, volumeObjectTO.getPath())); + logger.debug(String.format("Created libvirt secret %s for disk %s", secretUuid, volumeObjectTO.getPath())); volumeObjectTO.clearPassphrase(); } else { - s_logger.debug(String.format("disk %s has no passphrase or encryption", volumeObjectTO)); + logger.debug(String.format("disk %s has no passphrase or encryption", volumeObjectTO)); } } } @@ -144,12 +142,12 @@ protected PrepareForMigrationAnswer createPrepareForMigrationAnswer(PrepareForMi PrepareForMigrationAnswer answer = new PrepareForMigrationAnswer(command); if (MapUtils.isNotEmpty(dpdkInterfaceMapping)) { - s_logger.debug(String.format("Setting DPDK interface for the migration of VM [%s].", vm)); + logger.debug(String.format("Setting DPDK interface for the migration of VM [%s].", vm)); answer.setDpdkInterfaceMapping(dpdkInterfaceMapping); } int newCpuShares = libvirtComputingResource.calculateCpuShares(vm); - s_logger.debug(String.format("Setting CPU shares to [%s] for the migration of VM [%s].", newCpuShares, vm)); + logger.debug(String.format("Setting CPU shares to [%s] for the migration of VM [%s].", newCpuShares, vm)); answer.setNewVmCpuShares(newCpuShares); return answer; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareStorageClientCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareStorageClientCommandWrapper.java index 79afd4696b04..b5cab17ecb14 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareStorageClientCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareStorageClientCommandWrapper.java @@ -21,8 +21,6 @@ import java.util.Map; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.PrepareStorageClientAnswer; import com.cloud.agent.api.PrepareStorageClientCommand; @@ -35,15 +33,13 @@ @ResourceWrapper(handles = PrepareStorageClientCommand.class) public class LibvirtPrepareStorageClientCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPrepareStorageClientCommandWrapper.class); - @Override public Answer execute(PrepareStorageClientCommand cmd, LibvirtComputingResource libvirtComputingResource) { final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr(); Ternary, String> prepareStorageClientResult = storagePoolMgr.prepareStorageClient(cmd.getPoolType(), cmd.getPoolUuid(), cmd.getDetails()); if (!prepareStorageClientResult.first()) { String msg = prepareStorageClientResult.third(); - s_logger.debug("Unable to prepare storage client, due to: " + msg); + logger.debug("Unable to prepare storage client, due to: " + msg); return new PrepareStorageClientAnswer(cmd, false, msg); } Map details = prepareStorageClientResult.second(); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareUnmanageVMInstanceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareUnmanageVMInstanceCommandWrapper.java index 683730890380..601a3da8642f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareUnmanageVMInstanceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareUnmanageVMInstanceCommandWrapper.java @@ -22,27 +22,25 @@ import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; @ResourceWrapper(handles=PrepareUnmanageVMInstanceCommand.class) public final class LibvirtPrepareUnmanageVMInstanceCommandWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(LibvirtPrepareUnmanageVMInstanceCommandWrapper.class); @Override public PrepareUnmanageVMInstanceAnswer execute(PrepareUnmanageVMInstanceCommand command, LibvirtComputingResource libvirtComputingResource) { final String vmName = command.getInstanceName(); final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); - LOGGER.debug(String.format("Verify if KVM instance: [%s] is available before Unmanaging VM.", vmName)); + logger.debug(String.format("Verify if KVM instance: [%s] is available before Unmanaging VM.", vmName)); try { final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName); final Domain domain = libvirtComputingResource.getDomain(conn, vmName); if (domain == null) { - LOGGER.error("Prepare Unmanage VMInstanceCommand: vm not found " + vmName); + logger.error("Prepare Unmanage VMInstanceCommand: vm not found " + vmName); new PrepareUnmanageVMInstanceAnswer(command, false, String.format("Cannot find VM with name [%s] in KVM host.", vmName)); } } catch (Exception e){ - LOGGER.error("PrepareUnmanagedInstancesCommand failed due to " + e.getMessage()); + logger.error("PrepareUnmanagedInstancesCommand failed due to " + e.getMessage()); return new PrepareUnmanageVMInstanceAnswer(command, false, "Error: " + e.getMessage()); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java index 91fb9242fb98..3e4baa9ae3f1 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.joda.time.Duration; import com.cloud.agent.api.Answer; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = PvlanSetupCommand.class) public final class LibvirtPvlanSetupCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPvlanSetupCommandWrapper.class); @Override public Answer execute(final PvlanSetupCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -56,30 +54,30 @@ public Answer execute(final PvlanSetupCommand command, final LibvirtComputingRes if (command.getType() == PvlanSetupCommand.Type.DHCP) { final String ovsPvlanDhcpHostPath = libvirtComputingResource.getOvsPvlanDhcpHostPath(); - final Script script = new Script(ovsPvlanDhcpHostPath, timeout, s_logger); + final Script script = new Script(ovsPvlanDhcpHostPath, timeout, logger); script.add(opr, pvlanType, "-b", guestBridgeName, "-p", primaryPvlan, "-s", isolatedPvlan, "-m", dhcpMac, "-d", dhcpIp); result = script.execute(); if (result != null) { - s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac); + logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac); } else { - s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac); + logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac); } } // We run this even for DHCP servers since they're all vms after all final String ovsPvlanVmPath = libvirtComputingResource.getOvsPvlanVmPath(); - final Script script = new Script(ovsPvlanVmPath, timeout, s_logger); + final Script script = new Script(ovsPvlanVmPath, timeout, logger); script.add(opr, pvlanType, "-b", guestBridgeName, "-p", primaryPvlan, "-s", isolatedPvlan, "-m", vmMac); result = script.execute(); if (result != null) { - s_logger.warn("Failed to program pvlan for vm with mac " + vmMac); + logger.warn("Failed to program pvlan for vm with mac " + vmMac); return new Answer(command, false, result); } else { - s_logger.info("Programmed pvlan for vm with mac " + vmMac); + logger.info("Programmed pvlan for vm with mac " + vmMac); } return new Answer(command, true, result); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReadyCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReadyCommandWrapper.java index c44e39af0d32..8f23e79e4a32 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReadyCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReadyCommandWrapper.java @@ -24,8 +24,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.ReadyAnswer; import com.cloud.agent.api.ReadyCommand; @@ -40,7 +38,6 @@ @ResourceWrapper(handles = ReadyCommand.class) public final class LibvirtReadyCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtReadyCommandWrapper.class); @Override public Answer execute(final ReadyCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -57,16 +54,16 @@ private boolean hostSupportsUefi(boolean isUbuntuHost) { int timeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_SCRIPT_TIMEOUT) * 1000; // Get property value & convert to milliseconds int result; if (isUbuntuHost) { - s_logger.debug("Running command : dpkg -l ovmf"); + logger.debug("Running command : [dpkg -l ovmf] with timeout : " + timeout + " ms"); result = Script.executeCommandForExitValue(timeout, Script.getExecutableAbsolutePath("dpkg"), "-l", "ovmf"); } else { - s_logger.debug("Running command : rpm -qa | grep -i ovmf"); + logger.debug("Running command : [rpm -qa | grep -i ovmf] with timeout : " + timeout + " ms"); List commands = new ArrayList<>(); commands.add(new String[]{Script.getExecutableAbsolutePath("rpm"), "-qa"}); commands.add(new String[]{Script.getExecutableAbsolutePath("grep"), "-i", "ovmf"}); result = Script.executePipedCommands(commands, timeout).first(); } - s_logger.debug("Got result : " + result); + logger.debug("Got result : " + result); return result == 0; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRebootCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRebootCommandWrapper.java index 15a3be4167a6..87617cb2c543 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRebootCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRebootCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -34,7 +33,6 @@ @ResourceWrapper(handles = RebootCommand.class) public final class LibvirtRebootCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRebootCommandWrapper.class); @Override public Answer execute(final RebootCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -49,7 +47,7 @@ public Answer execute(final RebootCommand command, final LibvirtComputingResourc try { vncPort = libvirtComputingResource.getVncPort(conn, command.getVmName()); } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + logger.trace("Ignoring libvirt error.", e); } if (vmSpec != null) { libvirtComputingResource.applyDefaultNetworkRules(conn, vmSpec, false); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java index 558c7f0441ca..f22cfd2a96f9 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtReplugNicCommandWrapper.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.LibvirtException; @@ -38,7 +37,6 @@ @ResourceWrapper(handles = ReplugNicCommand.class) public final class LibvirtReplugNicCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtReplugNicCommandWrapper.class); public enum DomainAffect { CURRENT(0), LIVE(1), CONFIG(2), BOTH(3); @@ -78,15 +76,15 @@ public Answer execute(final ReplugNicCommand command, final LibvirtComputingReso int i = 0; do { i++; - s_logger.debug("ReplugNic: Detaching interface" + oldPluggedNic + " (Attempt: " + i + ")"); + logger.debug("ReplugNic: Detaching interface" + oldPluggedNic + " (Attempt: " + i + ")"); vm.detachDevice(oldPluggedNic.toString()); } while (findPluggedNic(libvirtComputingResource, nic, vmName, conn) != null && i <= 10); - s_logger.debug("ReplugNic: Attaching interface" + interfaceDef); + logger.debug("ReplugNic: Attaching interface" + interfaceDef); vm.attachDevice(interfaceDef.toString()); interfaceDef.setLinkStateUp(true); - s_logger.debug("ReplugNic: Updating interface" + interfaceDef); + logger.debug("ReplugNic: Updating interface" + interfaceDef); vm.updateDeviceFlags(interfaceDef.toString(), DomainAffect.LIVE.getValue()); // We don't know which "traffic type" is associated with @@ -98,14 +96,14 @@ public Answer execute(final ReplugNicCommand command, final LibvirtComputingReso return new ReplugNicAnswer(command, true, "success"); } catch (final LibvirtException | InternalErrorException e) { final String msg = " Plug Nic failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new ReplugNicAnswer(command, false, msg); } finally { if (vm != null) { try { vm.free(); } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtResizeVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtResizeVolumeCommandWrapper.java index 4f1ad728b5d9..6a3901e345cf 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtResizeVolumeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtResizeVolumeCommandWrapper.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.cloudstack.utils.qemu.QemuObject; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo; @@ -63,7 +62,6 @@ @ResourceWrapper(handles = ResizeVolumeCommand.class) public final class LibvirtResizeVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtResizeVolumeCommandWrapper.class); @Override public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -77,7 +75,7 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR if ( currentSize == newSize) { // nothing to do - s_logger.info("No need to resize volume: current size " + toHumanReadableSize(currentSize) + " is same as new size " + toHumanReadableSize(newSize)); + logger.info("No need to resize volume: current size " + toHumanReadableSize(currentSize) + " is same as new size " + toHumanReadableSize(newSize)); return new ResizeVolumeAnswer(command, true, "success", currentSize); } @@ -111,15 +109,15 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR return new ResizeVolumeAnswer(command, false, "Unable to shrink volumes of type " + type); } } else { - s_logger.debug("Volume " + path + " is on a RBD/Linstor storage pool. No need to query for additional information."); + logger.debug("Volume " + path + " is on a RBD/Linstor storage pool. No need to query for additional information."); } - s_logger.debug("Resizing volume: " + path + ", from: " + toHumanReadableSize(currentSize) + ", to: " + toHumanReadableSize(newSize) + ", type: " + type + ", name: " + vmInstanceName + ", shrinkOk: " + shrinkOk); + logger.debug("Resizing volume: " + path + ", from: " + toHumanReadableSize(currentSize) + ", to: " + toHumanReadableSize(newSize) + ", type: " + type + ", name: " + vmInstanceName + ", shrinkOk: " + shrinkOk); /* libvirt doesn't support resizing (C)LVM devices, and corrupts QCOW2 in some scenarios, so we have to do these via qemu-img */ if (pool.getType() != StoragePoolType.CLVM && pool.getType() != StoragePoolType.Linstor && pool.getType() != StoragePoolType.PowerFlex && vol.getFormat() != PhysicalDiskFormat.QCOW2) { - s_logger.debug("Volume " + path + " can be resized by libvirt. Asking libvirt to resize the volume."); + logger.debug("Volume " + path + " can be resized by libvirt. Asking libvirt to resize the volume."); try { final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); @@ -147,12 +145,12 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR with both encrypted and non-encrypted volumes. */ if (!vmIsRunning && command.getPassphrase() != null && command.getPassphrase().length > 0 ) { - s_logger.debug("Invoking qemu-img to resize an offline, encrypted volume"); + logger.debug("Invoking qemu-img to resize an offline, encrypted volume"); QemuObject.EncryptFormat encryptFormat = QemuObject.EncryptFormat.enumValue(command.getEncryptFormat()); resizeEncryptedQcowFile(vol, encryptFormat,newSize, command.getPassphrase(), libvirtComputingResource); } else { - s_logger.debug("Invoking resize script to handle type " + type); - final Script resizecmd = new Script(libvirtComputingResource.getResizeVolumePath(), libvirtComputingResource.getCmdsTimeout(), s_logger); + logger.debug("Invoking resize script to handle type " + type); + final Script resizecmd = new Script(libvirtComputingResource.getResizeVolumePath(), libvirtComputingResource.getCmdsTimeout(), logger); resizecmd.add("-s", String.valueOf(newSize)); resizecmd.add("-c", String.valueOf(currentSize)); resizecmd.add("-p", path); @@ -174,11 +172,11 @@ public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingR pool = storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid()); pool.refresh(); final long finalSize = pool.getPhysicalDisk(volumeId).getVirtualSize(); - s_logger.debug("after resize, size reports as: " + toHumanReadableSize(finalSize) + ", requested: " + toHumanReadableSize(newSize)); + logger.debug("after resize, size reports as: " + toHumanReadableSize(finalSize) + ", requested: " + toHumanReadableSize(newSize)); return new ResizeVolumeAnswer(command, true, "success", finalSize); } catch (final CloudRuntimeException e) { final String error = "Failed to resize volume: " + e.getMessage(); - s_logger.debug(error); + logger.debug(error); return new ResizeVolumeAnswer(command, false, error); } finally { command.clearPassphrase(); @@ -192,7 +190,7 @@ private boolean isVmRunning(final String vmName, final LibvirtComputingResource Domain dom = conn.domainLookupByName(vmName); return (dom != null && dom.getInfo().state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING); } catch (LibvirtException ex) { - s_logger.info(String.format("Did not find a running VM '%s'", vmName)); + logger.info(String.format("Did not find a running VM '%s'", vmName)); } return false; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java new file mode 100644 index 000000000000..23ead355096d --- /dev/null +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java @@ -0,0 +1,203 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.hypervisor.kvm.resource.wrapper; + +import com.cloud.agent.api.Answer; +import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.Pair; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.script.Script; +import com.cloud.vm.VirtualMachine; +import org.apache.cloudstack.backup.BackupAnswer; +import org.apache.cloudstack.backup.RestoreBackupCommand; +import org.apache.commons.lang3.RandomStringUtils; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Locale; +import java.util.Objects; + +@ResourceWrapper(handles = RestoreBackupCommand.class) +public class LibvirtRestoreBackupCommandWrapper extends CommandWrapper { + private static final String BACKUP_TEMP_FILE_PREFIX = "csbackup"; + private static final String MOUNT_COMMAND = "sudo mount -t %s %s %s"; + private static final String UMOUNT_COMMAND = "sudo umount %s"; + private static final String FILE_PATH_PLACEHOLDER = "%s/%s"; + private static final String ATTACH_DISK_COMMAND = " virsh attach-disk %s %s %s --cache none"; + private static final String CURRRENT_DEVICE = "virsh domblklist --domain %s | tail -n 3 | head -n 1 | awk '{print $1}'"; + private static final String RSYNC_COMMAND = "rsync -az %s %s"; + + @Override + public Answer execute(RestoreBackupCommand command, LibvirtComputingResource serverResource) { + String vmName = command.getVmName(); + String backupPath = command.getBackupPath(); + String backupRepoAddress = command.getBackupRepoAddress(); + String backupRepoType = command.getBackupRepoType(); + String mountOptions = command.getMountOptions(); + Boolean vmExists = command.isVmExists(); + String diskType = command.getDiskType(); + List volumePaths = command.getVolumePaths(); + String restoreVolumeUuid = command.getRestoreVolumeUUID(); + + String newVolumeId = null; + if (Objects.isNull(vmExists)) { + String volumePath = volumePaths.get(0); + int lastIndex = volumePath.lastIndexOf("/"); + newVolumeId = volumePath.substring(lastIndex + 1); + restoreVolume(backupPath, backupRepoType, backupRepoAddress, volumePath, diskType, restoreVolumeUuid, + new Pair<>(vmName, command.getVmState())); + } else if (Boolean.TRUE.equals(vmExists)) { + restoreVolumesOfExistingVM(volumePaths, backupPath, backupRepoType, backupRepoAddress, mountOptions); + } else { + restoreVolumesOfDestroyedVMs(volumePaths, vmName, backupPath, backupRepoType, backupRepoAddress, mountOptions); + } + + return new BackupAnswer(command, true, newVolumeId); + } + + private void restoreVolumesOfExistingVM(List volumePaths, String backupPath, + String backupRepoType, String backupRepoAddress, String mountOptions) { + String diskType = "root"; + String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType); + try { + for (int idx = 0; idx < volumePaths.size(); idx++) { + String volumePath = volumePaths.get(idx); + Pair bkpPathAndVolUuid = getBackupPath(mountDirectory, volumePath, backupPath, diskType, null); + diskType = "datadisk"; + try { + replaceVolumeWithBackup(volumePath, bkpPathAndVolUuid.first()); + } catch (IOException e) { + throw new CloudRuntimeException(String.format("Unable to revert backup for volume [%s] due to [%s].", bkpPathAndVolUuid.second(), e.getMessage()), e); + } + } + } finally { + unmountBackupDirectory(mountDirectory); + deleteTemporaryDirectory(mountDirectory); + } + + } + + private void restoreVolumesOfDestroyedVMs(List volumePaths, String vmName, String backupPath, + String backupRepoType, String backupRepoAddress, String mountOptions) { + String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType); + String diskType = "root"; + try { + for (int i = 0; i < volumePaths.size(); i++) { + String volumePath = volumePaths.get(i); + Pair bkpPathAndVolUuid = getBackupPath(mountDirectory, volumePath, backupPath, diskType, null); + diskType = "datadisk"; + try { + replaceVolumeWithBackup(volumePath, bkpPathAndVolUuid.first()); + } catch (IOException e) { + throw new CloudRuntimeException(String.format("Unable to revert backup for volume [%s] due to [%s].", bkpPathAndVolUuid.second(), e.getMessage()), e); + } + } + } finally { + unmountBackupDirectory(mountDirectory); + deleteTemporaryDirectory(mountDirectory); + } + } + + private void restoreVolume(String backupPath, String backupRepoType, String backupRepoAddress, String volumePath, + String diskType, String volumeUUID, Pair vmNameAndState) { + String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType); + Pair bkpPathAndVolUuid; + try { + bkpPathAndVolUuid = getBackupPath(mountDirectory, volumePath, backupPath, diskType, volumeUUID); + try { + replaceVolumeWithBackup(volumePath, bkpPathAndVolUuid.first()); + if (VirtualMachine.State.Running.equals(vmNameAndState.second())) { + if (!attachVolumeToVm(vmNameAndState.first(), volumePath)) { + throw new CloudRuntimeException(String.format("Failed to attach volume to VM: %s", vmNameAndState.first())); + } + } + } catch (IOException e) { + throw new CloudRuntimeException(String.format("Unable to revert backup for volume [%s] due to [%s].", bkpPathAndVolUuid.second(), e.getMessage()), e); + } + } catch (Exception e) { + throw new CloudRuntimeException("Failed to restore volume", e); + } finally { + unmountBackupDirectory(mountDirectory); + deleteTemporaryDirectory(mountDirectory); + } + } + + + private String mountBackupDirectory(String backupRepoAddress, String backupRepoType) { + String randomChars = RandomStringUtils.random(5, true, false); + String mountDirectory = String.format("%s.%s",BACKUP_TEMP_FILE_PREFIX , randomChars); + try { + mountDirectory = Files.createTempDirectory(mountDirectory).toString(); + String mount = String.format(MOUNT_COMMAND, backupRepoType, backupRepoAddress, mountDirectory); + Script.runSimpleBashScript(mount); + } catch (Exception e) { + throw new CloudRuntimeException(String.format("Failed to mount %s to %s", backupRepoType, backupRepoAddress), e); + } + return mountDirectory; + } + + private void unmountBackupDirectory(String backupDirectory) { + try { + String umountCmd = String.format(UMOUNT_COMMAND, backupDirectory); + Script.runSimpleBashScript(umountCmd); + } catch (Exception e) { + throw new CloudRuntimeException(String.format("Failed to unmount backup directory: %s", backupDirectory), e); + } + } + + private void deleteTemporaryDirectory(String backupDirectory) { + try { + Files.deleteIfExists(Paths.get(backupDirectory)); + } catch (IOException e) { + throw new CloudRuntimeException(String.format("Failed to delete backup directory: %s", backupDirectory), e); + } + } + + private Pair getBackupPath(String mountDirectory, String volumePath, String backupPath, String diskType, String volumeUuid) { + String bkpPath = String.format(FILE_PATH_PLACEHOLDER, mountDirectory, backupPath); + int lastIndex = volumePath.lastIndexOf(File.separator); + String volUuid = Objects.isNull(volumeUuid) ? volumePath.substring(lastIndex + 1) : volumeUuid; + String backupFileName = String.format("%s.%s.qcow2", diskType.toLowerCase(Locale.ROOT), volUuid); + bkpPath = String.format(FILE_PATH_PLACEHOLDER, bkpPath, backupFileName); + return new Pair<>(bkpPath, volUuid); + } + + private void replaceVolumeWithBackup(String volumePath, String backupPath) throws IOException { + Script.runSimpleBashScript(String.format(RSYNC_COMMAND, backupPath, volumePath)); + } + + private boolean attachVolumeToVm(String vmName, String volumePath) { + String deviceToAttachDiskTo = getDeviceToAttachDisk(vmName); + int exitValue = Script.runSimpleBashScriptForExitValue(String.format(ATTACH_DISK_COMMAND, vmName, volumePath, deviceToAttachDiskTo)); + return exitValue == 0; + } + + private String getDeviceToAttachDisk(String vmName) { + String currentDevice = Script.runSimpleBashScript(String.format(CURRRENT_DEVICE, vmName)); + char lastChar = currentDevice.charAt(currentDevice.length() - 1); + char incrementedChar = (char) (lastChar + 1); + return currentDevice.substring(0, currentDevice.length() - 1) + incrementedChar; + } +} diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreVMSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreVMSnapshotCommandWrapper.java index ce8c2095660f..0b0187ae668c 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreVMSnapshotCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.Map; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.LibvirtException; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = RestoreVMSnapshotCommand.class) public final class LibvirtRestoreVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRestoreVMSnapshotCommandWrapper.class); @Override public Answer execute(final RestoreVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -65,7 +63,7 @@ public Answer execute(final RestoreVMSnapshotCommand cmd, final LibvirtComputing for (VMSnapshotTO snapshot: snapshots) { VMSnapshotTO parent = snapshotAndParents.get(snapshot.getId()); String vmSnapshotXML = libvirtUtilitiesHelper.generateVMSnapshotXML(snapshot, parent, xmlDesc); - s_logger.debug("Restoring vm snapshot " + snapshot.getSnapshotName() + " on " + vmName + " with XML:\n " + vmSnapshotXML); + logger.debug("Restoring vm snapshot " + snapshot.getSnapshotName() + " on " + vmName + " with XML:\n " + vmSnapshotXML); try { int flags = 1; // VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = 1 if (snapshot.getCurrent()) { @@ -73,7 +71,7 @@ public Answer execute(final RestoreVMSnapshotCommand cmd, final LibvirtComputing } dm.snapshotCreateXML(vmSnapshotXML, flags); } catch (LibvirtException e) { - s_logger.debug("Failed to restore vm snapshot " + snapshot.getSnapshotName() + " on " + vmName); + logger.debug("Failed to restore vm snapshot " + snapshot.getSnapshotName() + " on " + vmName); return new RestoreVMSnapshotAnswer(cmd, false, e.toString()); } } @@ -81,14 +79,14 @@ public Answer execute(final RestoreVMSnapshotCommand cmd, final LibvirtComputing return new RestoreVMSnapshotAnswer(cmd, listVolumeTo, vmState); } catch (LibvirtException e) { String msg = " Restore snapshot failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new RestoreVMSnapshotAnswer(cmd, false, msg); } finally { if (dm != null) { try { dm.free(); } catch (LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); }; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java index 4071c1bcb453..d2f1ef827a15 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.ceph.rados.IoCTX; import com.ceph.rados.Rados; @@ -58,7 +57,6 @@ @ResourceWrapper(handles = RevertSnapshotCommand.class) public class LibvirtRevertSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRevertSnapshotCommandWrapper.class); private static final String MON_HOST = "mon_host"; private static final String KEY = "key"; private static final String CLIENT_MOUNT_TIMEOUT = "client_mount_timeout"; @@ -103,7 +101,7 @@ public Answer execute(final RevertSnapshotCommand command, final LibvirtComputin IoCTX io = rados.ioCtxCreate(primaryPool.getSourceDir()); Rbd rbd = new Rbd(io); - s_logger.debug(String.format("Attempting to rollback RBD snapshot [name:%s], [volumeid:%s], [snapshotid:%s]", snapshot.getName(), volumePath, rbdSnapshotId)); + logger.debug(String.format("Attempting to rollback RBD snapshot [name:%s], [volumeid:%s], [snapshotid:%s]", snapshot.getName(), volumePath, rbdSnapshotId)); RbdImage image = rbd.open(volumePath); image.snapRollBack(rbdSnapshotId); @@ -117,13 +115,13 @@ public Answer execute(final RevertSnapshotCommand command, final LibvirtComputin } if (primaryPool.getType() == StoragePoolType.CLVM) { - Script cmd = new Script(libvirtComputingResource.manageSnapshotPath(), libvirtComputingResource.getCmdsTimeout(), s_logger); + Script cmd = new Script(libvirtComputingResource.manageSnapshotPath(), libvirtComputingResource.getCmdsTimeout(), logger); cmd.add("-v", getFullPathAccordingToStorage(secondaryStoragePool, snapshotRelPath)); cmd.add("-n", snapshotDisk.getName()); cmd.add("-p", snapshotDisk.getPath()); String result = cmd.execute(); if (result != null) { - s_logger.debug("Failed to revert snaptshot: " + result); + logger.debug("Failed to revert snaptshot: " + result); return new Answer(command, false, result); } } else { @@ -135,10 +133,10 @@ public Answer execute(final RevertSnapshotCommand command, final LibvirtComputin } catch (CloudRuntimeException e) { return new Answer(command, false, e.toString()); } catch (RadosException e) { - s_logger.error("Failed to connect to Rados pool while trying to revert snapshot. Exception: ", e); + logger.error("Failed to connect to Rados pool while trying to revert snapshot. Exception: ", e); return new Answer(command, false, e.toString()); } catch (RbdException e) { - s_logger.error("Failed to connect to revert snapshot due to RBD exception: ", e); + logger.error("Failed to connect to revert snapshot due to RBD exception: ", e); return new Answer(command, false, e.toString()); } } @@ -163,11 +161,11 @@ protected void revertVolumeToSnapshot(SnapshotObjectTO snapshotOnPrimaryStorage, String snapshotPath = resultGetSnapshot.first(); SnapshotObjectTO snapshotToPrint = resultGetSnapshot.second(); - s_logger.debug(String.format("Reverting volume [%s] to snapshot [%s].", volumeObjectTo, snapshotToPrint)); + logger.debug(String.format("Reverting volume [%s] to snapshot [%s].", volumeObjectTo, snapshotToPrint)); try { replaceVolumeWithSnapshot(volumePath, snapshotPath); - s_logger.debug(String.format("Successfully reverted volume [%s] to snapshot [%s].", volumeObjectTo, snapshotToPrint)); + logger.debug(String.format("Successfully reverted volume [%s] to snapshot [%s].", volumeObjectTo, snapshotToPrint)); } catch (IOException ex) { throw new CloudRuntimeException(String.format("Unable to revert volume [%s] to snapshot [%s] due to [%s].", volumeObjectTo, snapshotToPrint, ex.getMessage()), ex); } @@ -192,8 +190,8 @@ protected Pair getSnapshot(SnapshotObjectTO snapshotOn snapshotOnSecondaryStorage, snapshotOnSecondaryStorage.getVolume())); } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Snapshot does not exists on primary storage [%s], searching snapshot [%s] on secondary storage [%s].", + if (logger.isTraceEnabled()) { + logger.trace(String.format("Snapshot does not exists on primary storage [%s], searching snapshot [%s] on secondary storage [%s].", kvmStoragePoolPrimary, snapshotOnSecondaryStorage, kvmStoragePoolSecondary)); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertToVMSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertToVMSnapshotCommandWrapper.java index 086d6ef7a89f..02dc80364ac4 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertToVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertToVMSnapshotCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainSnapshot; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = RevertToVMSnapshotCommand.class) public final class LibvirtRevertToVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRevertToVMSnapshotCommandWrapper.class); @Override public Answer execute(final RevertToVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -80,14 +78,14 @@ public Answer execute(final RevertToVMSnapshotCommand cmd, final LibvirtComputin return new RevertToVMSnapshotAnswer(cmd, listVolumeTo, vmState); } catch (LibvirtException e) { String msg = " Revert to VM snapshot failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new RevertToVMSnapshotAnswer(cmd, false, msg); } finally { if (dm != null) { try { dm.free(); } catch (LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); }; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevokeDirectDownloadCertificateWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevokeDirectDownloadCertificateWrapper.java index f230d3f49733..9919689cf3b4 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevokeDirectDownloadCertificateWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevokeDirectDownloadCertificateWrapper.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.agent.directdownload.RevokeDirectDownloadCertificateCommand; import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; @@ -39,7 +38,6 @@ @ResourceWrapper(handles = RevokeDirectDownloadCertificateCommand.class) public class LibvirtRevokeDirectDownloadCertificateWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRevokeDirectDownloadCertificateWrapper.class); /** * Retrieve agent.properties file @@ -61,7 +59,7 @@ private String getKeystorePassword(File agentFile) { try { pass = PropertiesUtil.loadFromFile(agentFile).getProperty(KeyStoreUtils.KS_PASSPHRASE_PROPERTY); } catch (IOException e) { - s_logger.error("Could not get 'keystore.passphrase' property value due to: " + e.getMessage()); + logger.error("Could not get 'keystore.passphrase' property value due to: " + e.getMessage()); } } return pass; @@ -90,15 +88,15 @@ public Answer execute(RevokeDirectDownloadCertificateCommand command, LibvirtCom sanitizeBashCommandArgument(certificateAlias), "-keystore", keyStoreFile, "-storepass", privatePassword); if (existsCmdResult == 1) { - s_logger.error("Certificate alias " + certificateAlias + " does not exist, no need to revoke it"); + logger.error("Certificate alias " + certificateAlias + " does not exist, no need to revoke it"); } else { - s_logger.debug("Revoking certificate alias " + certificateAlias + " from keystore " + keyStoreFile); + logger.debug("Revoking certificate alias " + certificateAlias + " from keystore " + keyStoreFile); Script.executeCommandForExitValue(keyToolPath, "-delete", "-alias", sanitizeBashCommandArgument(certificateAlias), "-keystore", keyStoreFile, "-storepass", - privatePassword);; + privatePassword); } } catch (FileNotFoundException | CloudRuntimeException e) { - s_logger.error("Error while setting up certificate " + certificateAlias, e); + logger.error("Error while setting up certificate " + certificateAlias, e); return new Answer(command, false, e.getMessage()); } return new Answer(command); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRollingMaintenanceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRollingMaintenanceCommandWrapper.java index a1b1af60c9f6..e56386ad3ad3 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRollingMaintenanceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRollingMaintenanceCommandWrapper.java @@ -28,14 +28,12 @@ import com.cloud.resource.ResourceWrapper; import com.cloud.resource.RollingMaintenanceManager; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.File; @ResourceWrapper(handles = RollingMaintenanceCommand.class) public class LibvirtRollingMaintenanceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRollingMaintenanceCommandWrapper.class); @Override public RollingMaintenanceAnswer execute(RollingMaintenanceCommand command, LibvirtComputingResource resource) { @@ -49,16 +47,16 @@ public RollingMaintenanceAnswer execute(RollingMaintenanceCommand command, Libvi if (command.isCheckMaintenanceScript()) { return new RollingMaintenanceAnswer(command, scriptFile != null); } else if (scriptFile == null) { - s_logger.info("No script file defined for stage " + stage + ". Skipping stage..."); + logger.info("No script file defined for stage " + stage + ". Skipping stage..."); return new RollingMaintenanceAnswer(command, true, "Skipped stage " + stage, true); } if (command.isStarted() && executor instanceof RollingMaintenanceAgentExecutor) { String msg = "Stage has been started previously and the agent restarted, setting stage as finished"; - s_logger.info(msg); + logger.info(msg); return new RollingMaintenanceAnswer(command, true, msg, true); } - s_logger.info("Processing stage " + stage); + logger.info("Processing stage " + stage); if (!command.isStarted()) { executor.startStageExecution(stage, scriptFile, timeout, payload); } @@ -69,10 +67,10 @@ public RollingMaintenanceAnswer execute(RollingMaintenanceCommand command, Libvi String output = executor.getStageExecutionOutput(stage, scriptFile); RollingMaintenanceAnswer answer = new RollingMaintenanceAnswer(command, success, output, true); if (executor.getStageAvoidMaintenance(stage, scriptFile)) { - s_logger.info("Avoid maintenance flag added to the answer for the stage " + stage); + logger.info("Avoid maintenance flag added to the answer for the stage " + stage); answer.setAvoidMaintenance(true); } - s_logger.info("Finished processing stage " + stage); + logger.info("Finished processing stage " + stage); return answer; } catch (CloudRuntimeException e) { return new RollingMaintenanceAnswer(command, false, e.getMessage(), false); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSecurityGroupRulesCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSecurityGroupRulesCommandWrapper.java index 3f8aebaf2516..33164264ae80 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSecurityGroupRulesCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSecurityGroupRulesCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = SecurityGroupRulesCmd.class) public final class LibvirtSecurityGroupRulesCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtSecurityGroupRulesCommandWrapper.class); @Override public Answer execute(final SecurityGroupRulesCmd command, final LibvirtComputingResource libvirtComputingResource) { @@ -54,7 +52,7 @@ public Answer execute(final SecurityGroupRulesCmd command, final LibvirtComputin final VirtualMachineTO vm = command.getVmTO(); if (!libvirtComputingResource.applyDefaultNetworkRules(conn, vm, true)) { - s_logger.warn("Failed to program default network rules for vm " + command.getVmName()); + logger.warn("Failed to program default network rules for vm " + command.getVmName()); return new SecurityGroupRuleAnswer(command, false, "programming default network rules failed"); } } catch (final LibvirtException e) { @@ -65,10 +63,10 @@ public Answer execute(final SecurityGroupRulesCmd command, final LibvirtComputin Long.toString(command.getSeqNum()), command.getGuestMac(), command.stringifyRules(), vif, brname, command.getSecIpsString()); if (!result) { - s_logger.warn("Failed to program network rules for vm " + command.getVmName()); + logger.warn("Failed to program network rules for vm " + command.getVmName()); return new SecurityGroupRuleAnswer(command, false, "programming network rules failed"); } else { - s_logger.debug("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp() + ",ingress numrules=" + logger.debug("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp() + ",ingress numrules=" + command.getIngressRuleSet().size() + ",egress numrules=" + command.getEgressRuleSet().size()); return new SecurityGroupRuleAnswer(command); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java index 0774d306b8a1..fcca16ba6186 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.agent.directdownload.SetupDirectDownloadCertificateCommand; import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; @@ -44,7 +43,6 @@ public class LibvirtSetupDirectDownloadCertificateCommandWrapper extends Command private static final String temporaryCertFilePrefix = "CSCERTIFICATE"; - private static final Logger s_logger = Logger.getLogger(LibvirtSetupDirectDownloadCertificateCommandWrapper.class); /** * Retrieve agent.properties file @@ -66,7 +64,7 @@ private String getKeystorePassword(File agentFile) { try { pass = PropertiesUtil.loadFromFile(agentFile).getProperty(KeyStoreUtils.KS_PASSPHRASE_PROPERTY); } catch (IOException e) { - s_logger.error("Could not get 'keystore.passphrase' property value due to: " + e.getMessage()); + logger.error("Could not get 'keystore.passphrase' property value due to: " + e.getMessage()); } } return pass; @@ -83,13 +81,13 @@ private String getKeyStoreFilePath(File agentFile) { * Import certificate from temporary file into keystore */ private void importCertificate(String tempCerFilePath, String keyStoreFile, String certificateName, String privatePassword) { - s_logger.debug("Importing certificate from temporary file to keystore"); + logger.debug("Importing certificate from temporary file to keystore"); String keyToolPath = Script.getExecutableAbsolutePath("keytool"); int result = Script.executeCommandForExitValue(keyToolPath, "-importcert", "file", tempCerFilePath, "-keystore", keyStoreFile, "-alias", sanitizeBashCommandArgument(certificateName), "-storepass", privatePassword, "-noprompt"); if (result != 0) { - s_logger.debug("Certificate " + certificateName + " not imported as it already exist on keystore"); + logger.debug("Certificate " + certificateName + " not imported as it already exist on keystore"); } } @@ -99,7 +97,7 @@ private void importCertificate(String tempCerFilePath, String keyStoreFile, Stri private String createTemporaryFile(File agentFile, String certificateName, String certificate) { String tempCerFilePath = String.format("%s/%s-%s", agentFile.getParent(), temporaryCertFilePrefix, certificateName); - s_logger.debug("Creating temporary certificate file into: " + tempCerFilePath); + logger.debug("Creating temporary certificate file into: " + tempCerFilePath); if (!FileUtil.writeToFile(tempCerFilePath, certificate)) { throw new CloudRuntimeException("Could not create the certificate file on path: " + tempCerFilePath); } @@ -109,22 +107,23 @@ private String createTemporaryFile(File agentFile, String certificateName, Strin /** * Remove temporary file */ + protected void cleanupTemporaryFile(String temporaryFile) { - s_logger.debug("Cleaning up temporary certificate file"); + logger.debug("Cleaning up temporary certificate file"); if (StringUtils.isBlank(temporaryFile)) { - s_logger.debug("Provided temporary certificate file path is empty"); + logger.debug("Provided temporary certificate file path is empty"); return; } try { Path filePath = Paths.get(temporaryFile); if (!Files.exists(filePath)) { - s_logger.debug("Temporary certificate file does not exist: " + temporaryFile); + logger.debug("Temporary certificate file does not exist: " + temporaryFile); return; } Files.delete(filePath); } catch (IOException e) { - s_logger.warn(String.format("Error while cleaning up temporary file: %s", temporaryFile)); - s_logger.debug(String.format("Error while cleaning up temporary file: %s", temporaryFile), e); + logger.warn(String.format("Error while cleaning up temporary file: %s", temporaryFile)); + logger.debug(String.format("Error while cleaning up temporary file: %s", temporaryFile), e); } } @@ -145,7 +144,7 @@ public Answer execute(SetupDirectDownloadCertificateCommand cmd, LibvirtComputin importCertificate(temporaryFile, keyStoreFile, certificateName, privatePassword); cleanupTemporaryFile(temporaryFile); } catch (FileNotFoundException | CloudRuntimeException e) { - s_logger.error("Error while setting up certificate " + certificateName, e); + logger.error("Error while setting up certificate " + certificateName, e); return new Answer(cmd, false, e.getMessage()); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupPersistentNetworkCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupPersistentNetworkCommandWrapper.java index a2ec64451a7c..66be619777dd 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupPersistentNetworkCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupPersistentNetworkCommandWrapper.java @@ -17,7 +17,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.Answer; @@ -33,7 +32,6 @@ @ResourceWrapper(handles = SetupPersistentNetworkCommand.class) public class LibvirtSetupPersistentNetworkCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtSetupPersistentNetworkCommandWrapper.class); @Override public Answer execute(SetupPersistentNetworkCommand command, LibvirtComputingResource serverResource) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java index 7b69993f2e5e..e0c41acea127 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java @@ -24,7 +24,6 @@ import com.cloud.agent.resource.virtualnetwork.VRScripts; import com.cloud.utils.FileUtil; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.DomainInfo.DomainState; import org.libvirt.LibvirtException; @@ -49,7 +48,6 @@ @ResourceWrapper(handles = StartCommand.class) public final class LibvirtStartCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtStartCommandWrapper.class); @Override public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -83,7 +81,7 @@ public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource.createVifs(vmSpec, vm); - s_logger.debug("starting " + vmName + ": " + vm.toString()); + logger.debug("starting " + vmName + ": " + vm.toString()); String vmInitialSpecification = vm.toString(); String vmFinalSpecification = performXmlTransformHook(vmInitialSpecification, libvirtComputingResource); libvirtComputingResource.startVM(conn, vmName, vmFinalSpecification); @@ -92,7 +90,7 @@ public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource.applyDefaultNetworkRules(conn, vmSpec, false); // pass cmdline info to system vms - if (vmSpec.getType() != VirtualMachine.Type.User || (vmSpec.getBootArgs() != null && vmSpec.getBootArgs().contains(UserVmManager.CKS_NODE))) { + if (vmSpec.getType() != VirtualMachine.Type.User || (vmSpec.getBootArgs() != null && (vmSpec.getBootArgs().contains(UserVmManager.CKS_NODE) || vmSpec.getBootArgs().contains(UserVmManager.SHAREDFSVM)))) { // try to patch and SSH into the systemvm for up to 5 minutes for (int count = 0; count < 10; count++) { // wait and try passCmdLine for 30 seconds at most for CLOUDSTACK-2823 @@ -124,12 +122,12 @@ public Answer execute(final StartCommand command, final LibvirtComputingResource FileUtil.scpPatchFiles(controlIp, VRScripts.CONFIG_CACHE_LOCATION, Integer.parseInt(LibvirtComputingResource.DEFAULTDOMRSSHPORT), pemFile, LibvirtComputingResource.systemVmPatchFiles, LibvirtComputingResource.BASEPATH); if (!virtRouterResource.isSystemVMSetup(vmName, controlIp)) { String errMsg = "Failed to patch systemVM"; - s_logger.error(errMsg); + logger.error(errMsg); return new StartAnswer(command, errMsg); } } catch (Exception e) { String errMsg = "Failed to scp files to system VM. Patching of systemVM failed"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return new StartAnswer(command, String.format("%s due to: %s", errMsg, e.getMessage())); } } @@ -138,19 +136,19 @@ public Answer execute(final StartCommand command, final LibvirtComputingResource state = DomainState.VIR_DOMAIN_RUNNING; return new StartAnswer(command); } catch (final LibvirtException e) { - s_logger.warn("LibvirtException ", e); + logger.warn("LibvirtException ", e); if (conn != null) { libvirtComputingResource.handleVmStartFailure(conn, vmName, vm); } return new StartAnswer(command, e.getMessage()); } catch (final InternalErrorException e) { - s_logger.warn("InternalErrorException ", e); + logger.warn("InternalErrorException ", e); if (conn != null) { libvirtComputingResource.handleVmStartFailure(conn, vmName, vm); } return new StartAnswer(command, e.getMessage()); } catch (final URISyntaxException e) { - s_logger.warn("URISyntaxException ", e); + logger.warn("URISyntaxException ", e); if (conn != null) { libvirtComputingResource.handleVmStartFailure(conn, vmName, vm); } @@ -167,7 +165,7 @@ private void performAgentStartHook(String vmName, LibvirtComputingResource libvi LibvirtKvmAgentHook onStartHook = libvirtComputingResource.getStartHook(); onStartHook.handle(vmName); } catch (Exception e) { - s_logger.warn("Exception occurred when handling LibVirt VM onStart hook: {}", e); + logger.warn("Exception occurred when handling LibVirt VM onStart hook: {}", e); } } @@ -178,11 +176,11 @@ private String performXmlTransformHook(String vmInitialSpecification, final Libv LibvirtKvmAgentHook t = libvirtComputingResource.getTransformer(); vmFinalSpecification = (String) t.handle(vmInitialSpecification); if (null == vmFinalSpecification) { - s_logger.warn("Libvirt XML transformer returned NULL, will use XML specification unchanged."); + logger.warn("Libvirt XML transformer returned NULL, will use XML specification unchanged."); vmFinalSpecification = vmInitialSpecification; } } catch(Exception e) { - s_logger.warn("Exception occurred when handling LibVirt XML transformer hook: {}", e); + logger.warn("Exception occurred when handling LibVirt XML transformer hook: {}", e); vmFinalSpecification = vmInitialSpecification; } return vmFinalSpecification; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStopCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStopCommandWrapper.java index 518ee2b6f0a0..1be5a1e949e5 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStopCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStopCommandWrapper.java @@ -25,7 +25,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -48,7 +47,6 @@ @ResourceWrapper(handles = StopCommand.class) public final class LibvirtStopCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtStopCommandWrapper.class); private static final String CMDLINE_PATH = "/var/cache/cloud/cmdline"; private static final String CMDLINE_BACKUP_PATH = "/var/cache/cloud/cmdline.backup"; @@ -66,21 +64,21 @@ public Answer execute(final StopCommand command, final LibvirtComputingResource return new StopAnswer(command, "vm is still running on host", false); } } catch (final Exception e) { - s_logger.debug("Failed to get vm status in case of checkboforecleanup is true", e); + logger.debug("Failed to get vm status in case of checkboforecleanup is true", e); } } File pemFile = new File(LibvirtComputingResource.SSHPRVKEYPATH); try { if(vmName.startsWith("s-") || vmName.startsWith("v-")){ //move the command line file to backup. - s_logger.debug("backing up the cmdline"); + logger.debug("backing up the cmdline"); try{ Pair ret = SshHelper.sshExecute(command.getControlIp(), 3922, "root", pemFile, null,"cp -f "+CMDLINE_PATH+" "+CMDLINE_BACKUP_PATH); if(!ret.first()){ - s_logger.debug("Failed to backup cmdline file due to "+ret.second()); + logger.debug("Failed to backup cmdline file due to "+ret.second()); } } catch (Exception e){ - s_logger.debug("Failed to backup cmdline file due to "+e.getMessage()); + logger.debug("Failed to backup cmdline file due to "+e.getMessage()); } } @@ -137,16 +135,16 @@ public Answer execute(final StopCommand command, final LibvirtComputingResource return new StopAnswer(command, result, true); } catch (final LibvirtException e) { - s_logger.debug("unable to stop VM:"+vmName+" due to"+e.getMessage()); + logger.debug("unable to stop VM:"+vmName+" due to"+e.getMessage()); try{ if(vmName.startsWith("s-") || vmName.startsWith("v-")) - s_logger.debug("restoring cmdline file from backup"); + logger.debug("restoring cmdline file from backup"); Pair ret = SshHelper.sshExecute(command.getControlIp(), 3922, "root", pemFile, null, "mv "+CMDLINE_BACKUP_PATH+" "+CMDLINE_PATH); if(!ret.first()){ - s_logger.debug("unable to restore cmdline due to "+ret.second()); + logger.debug("unable to restore cmdline due to "+ret.second()); } }catch (final Exception ex){ - s_logger.debug("unable to restore cmdline due to:"+ex.getMessage()); + logger.debug("unable to restore cmdline due to:"+ex.getMessage()); } return new StopAnswer(command, e.getMessage(), false); } @@ -157,7 +155,7 @@ private void performAgentStopHook(String vmName, final LibvirtComputingResource LibvirtKvmAgentHook onStopHook = libvirtComputingResource.getStopHook(); onStopHook.handle(vmName); } catch (Exception e) { - s_logger.warn("Exception occurred when handling LibVirt VM onStop hook: {}", e); + logger.warn("Exception occurred when handling LibVirt VM onStop hook: {}", e); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtTakeBackupCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtTakeBackupCommandWrapper.java new file mode 100644 index 000000000000..3c0cc53bb73b --- /dev/null +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtTakeBackupCommandWrapper.java @@ -0,0 +1,84 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.hypervisor.kvm.resource.wrapper; + +import com.amazonaws.util.CollectionUtils; +import com.cloud.agent.api.Answer; +import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.cloud.utils.Pair; +import com.cloud.utils.script.Script; +import org.apache.cloudstack.backup.BackupAnswer; +import org.apache.cloudstack.backup.TakeBackupCommand; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +@ResourceWrapper(handles = TakeBackupCommand.class) +public class LibvirtTakeBackupCommandWrapper extends CommandWrapper { + @Override + public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvirtComputingResource) { + final String vmName = command.getVmName(); + final String backupPath = command.getBackupPath(); + final String backupRepoType = command.getBackupRepoType(); + final String backupRepoAddress = command.getBackupRepoAddress(); + final String mountOptions = command.getMountOptions(); + final List diskPaths = command.getVolumePaths(); + + List commands = new ArrayList<>(); + commands.add(new String[]{ + libvirtComputingResource.getNasBackupPath(), + "-o", "backup", + "-v", vmName, + "-t", backupRepoType, + "-s", backupRepoAddress, + "-m", Objects.nonNull(mountOptions) ? mountOptions : "", + "-p", backupPath, + "-d", (Objects.nonNull(diskPaths) && !diskPaths.isEmpty()) ? String.join(",", diskPaths) : "" + }); + + Pair result = Script.executePipedCommands(commands, libvirtComputingResource.getCmdsTimeout()); + + if (result.first() != 0) { + logger.debug("Failed to take VM backup: " + result.second()); + return new BackupAnswer(command, false, result.second().trim()); + } + + long backupSize = 0L; + if (CollectionUtils.isNullOrEmpty(diskPaths)) { + List outputLines = Arrays.asList(result.second().trim().split("\n")); + if (!outputLines.isEmpty()) { + backupSize = Long.parseLong(outputLines.get(outputLines.size() - 1).trim()); + } + } else { + String[] outputLines = result.second().trim().split("\n"); + for(String line : outputLines) { + backupSize = backupSize + Long.parseLong(line.split(" ")[0].trim()); + } + } + + BackupAnswer answer = new BackupAnswer(command, true, result.second().trim()); + answer.setSize(backupSize); + return answer; + } +} diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnPlugNicCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnPlugNicCommandWrapper.java index e40563b291bf..e31589c0ca0a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnPlugNicCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnPlugNicCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.LibvirtException; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = UnPlugNicCommand.class) public final class LibvirtUnPlugNicCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtUnPlugNicCommandWrapper.class); @Override public Answer execute(final UnPlugNicCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -73,14 +71,14 @@ public Answer execute(final UnPlugNicCommand command, final LibvirtComputingReso return new UnPlugNicAnswer(command, true, "success"); } catch (final LibvirtException e) { final String msg = " Unplug Nic failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new UnPlugNicAnswer(command, false, msg); } finally { if (vm != null) { try { vm.free(); } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnprepareStorageClientCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnprepareStorageClientCommandWrapper.java index f98782fe7481..2f23a934003f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnprepareStorageClientCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnprepareStorageClientCommandWrapper.java @@ -19,8 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; - import com.cloud.agent.api.Answer; import com.cloud.agent.api.UnprepareStorageClientAnswer; import com.cloud.agent.api.UnprepareStorageClientCommand; @@ -33,15 +31,13 @@ @ResourceWrapper(handles = UnprepareStorageClientCommand.class) public class LibvirtUnprepareStorageClientCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtUnprepareStorageClientCommandWrapper.class); - @Override public Answer execute(UnprepareStorageClientCommand cmd, LibvirtComputingResource libvirtComputingResource) { final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr(); Pair unprepareStorageClientResult = storagePoolMgr.unprepareStorageClient(cmd.getPoolType(), cmd.getPoolUuid()); if (!unprepareStorageClientResult.first()) { String msg = unprepareStorageClientResult.second(); - s_logger.debug("Couldn't unprepare storage client, due to: " + msg); + logger.debug("Couldn't unprepare storage client, due to: " + msg); return new UnprepareStorageClientAnswer(cmd, false, msg); } return new UnprepareStorageClientAnswer(cmd, true); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java index 86ab024cbb9b..a2d161ac94bf 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUtilitiesHelper.java @@ -22,7 +22,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -41,7 +42,7 @@ * and the methods wrapped here. */ public class LibvirtUtilitiesHelper { - private static final Logger s_logger = Logger.getLogger(LibvirtUtilitiesHelper.class); + protected static Logger LOGGER = LogManager.getLogger(LibvirtUtilitiesHelper.class); public static final int TIMEOUT = 10000; @@ -129,7 +130,7 @@ protected static Pair isLibvirtVersionEqualOrHigherThanVersionI return new Pair<>(String.valueOf(currentLibvirtVersion), currentLibvirtVersion >= version); } catch (LibvirtException ex) { String exceptionMessage = ex.getMessage(); - s_logger.error(String.format("Unable to validate if the Libvirt's version is equal or higher than [%s] due to [%s]. Returning 'false' as default'.", version, + LOGGER.error(String.format("Unable to validate if the Libvirt's version is equal or higher than [%s] due to [%s]. Returning 'false' as default'.", version, exceptionMessage), ex); return new Pair<>(String.format("Unknown due to [%s]", exceptionMessage), false); } @@ -140,7 +141,7 @@ protected static Pair isLibvirtVersionEqualOrHigherThanVersionI */ public static boolean isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit(Connect conn) { Pair result = isLibvirtVersionEqualOrHigherThanVersionInParameter(conn, LIBVIRT_VERSION_THAT_SUPPORTS_FLAG_DELETE_ON_COMMAND_VIRSH_BLOCKCOMMIT); - s_logger.debug(String.format("The current Libvirt's version [%s]%s supports the flag '--delete' on command 'virsh blockcommit'.", result.first(), + LOGGER.debug(String.format("The current Libvirt's version [%s]%s supports the flag '--delete' on command 'virsh blockcommit'.", result.first(), result.second() ? "" : " does not")); return result.second(); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/FiberChannelAdapter.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/FiberChannelAdapter.java index d5192bfdb718..0a25b89d8c52 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/FiberChannelAdapter.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/FiberChannelAdapter.java @@ -19,15 +19,15 @@ import java.net.InetAddress; import java.net.UnknownHostException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.storage.Storage; import com.cloud.utils.exception.CloudRuntimeException; -@StorageAdaptorInfo(storagePoolType=Storage.StoragePoolType.FiberChannel) public class FiberChannelAdapter extends MultipathSCSIAdapterBase { - private Logger LOGGER = Logger.getLogger(getClass()); + private Logger LOGGER = LogManager.getLogger(getClass()); private String hostname = null; private String hostnameFq = null; @@ -48,6 +48,11 @@ public FiberChannelAdapter() { } } + @Override + public Storage.StoragePoolType getStoragePoolType() { + return Storage.StoragePoolType.FiberChannel; + } + @Override public KVMStoragePool getStoragePool(String uuid) { KVMStoragePool pool = MapStorageUuidToStoragePool.get(uuid); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java index f980cd295bd2..f023457461e9 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java @@ -25,7 +25,8 @@ import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.DiskTO; @@ -36,9 +37,8 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; -@StorageAdaptorInfo(storagePoolType=StoragePoolType.Iscsi) public class IscsiAdmStorageAdaptor implements StorageAdaptor { - private static final Logger s_logger = Logger.getLogger(IscsiAdmStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final Map MapStorageUuidToStoragePool = new HashMap<>(); @@ -51,6 +51,11 @@ public KVMStoragePool createStoragePool(String uuid, String host, int port, Stri return storagePool; } + @Override + public StoragePoolType getStoragePoolType() { + return StoragePoolType.Iscsi; + } + @Override public KVMStoragePool getStoragePool(String uuid) { return MapStorageUuidToStoragePool.get(uuid); @@ -81,7 +86,7 @@ public KVMPhysicalDisk createPhysicalDisk(String volumeUuid, KVMStoragePool pool @Override public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map details) { // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 -o new - Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger); + Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, logger); iScsiAdmCmd.add("-m", "node"); iScsiAdmCmd.add("-T", getIqn(volumeUuid)); @@ -91,12 +96,12 @@ public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map(); - s_logger.debug("Initialize cleanup thread"); + logger.debug("Initialize cleanup thread"); iscsiStorageAdaptor = new IscsiAdmStorageAdaptor(); } @@ -62,7 +63,7 @@ protected void runInContext() { //populate all the iscsi disks currently attached to this host File[] iscsiVolumes = new File(ISCSI_PATH_PREFIX).listFiles(); if (iscsiVolumes == null || iscsiVolumes.length == 0) { - s_logger.debug("No iscsi sessions found for cleanup"); + logger.debug("No iscsi sessions found for cleanup"); return; } @@ -76,7 +77,7 @@ protected void runInContext() { disconnectInactiveSessions(); } catch (LibvirtException e) { - s_logger.warn("[ignored] Error trying to cleanup ", e); + logger.warn("[ignored] Error trying to cleanup ", e); } } @@ -92,7 +93,7 @@ private void initializeDiskStatusMap(File[] iscsiVolumes){ diskStatusMap.clear(); for( File v : iscsiVolumes) { if (isIscsiDisk(v.getAbsolutePath())) { - s_logger.debug("found iscsi disk by cleanup thread, marking inactive: " + v.getAbsolutePath()); + logger.debug("found iscsi disk by cleanup thread, marking inactive: " + v.getAbsolutePath()); diskStatusMap.put(v.getAbsolutePath(), false); } } @@ -105,7 +106,7 @@ private void initializeDiskStatusMap(File[] iscsiVolumes){ private void updateDiskStatusMapWithInactiveIscsiSessions(Connect conn){ try { int[] domains = conn.listDomains(); - s_logger.debug(String.format("found %d domains", domains.length)); + logger.debug(String.format("found %d domains", domains.length)); for (int domId : domains) { Domain dm = conn.domainLookupByID(domId); final String domXml = dm.getXMLDesc(0); @@ -117,12 +118,12 @@ private void updateDiskStatusMapWithInactiveIscsiSessions(Connect conn){ for (final LibvirtVMDef.DiskDef disk : disks) { if (diskStatusMap.containsKey(disk.getDiskPath())&&!disk.getDiskPath().matches(REGEX_PART)) { diskStatusMap.put(disk.getDiskPath(), true); - s_logger.debug("active disk found by cleanup thread" + disk.getDiskPath()); + logger.debug("active disk found by cleanup thread" + disk.getDiskPath()); } } } } catch (LibvirtException e) { - s_logger.warn("[ignored] Error trying to cleanup ", e); + logger.warn("[ignored] Error trying to cleanup ", e); } } @@ -141,10 +142,10 @@ private void disconnectInactiveSessions(){ if (!diskStatusMap.get(diskPath)) { if (Files.exists(Paths.get(diskPath))) { try { - s_logger.info("Cleaning up disk " + diskPath); + logger.info("Cleaning up disk " + diskPath); iscsiStorageAdaptor.disconnectPhysicalDiskByPath(diskPath); } catch (Exception e) { - s_logger.warn("[ignored] Error cleaning up " + diskPath, e); + logger.warn("[ignored] Error cleaning up " + diskPath, e); } } } @@ -159,7 +160,7 @@ public void run() { try { Thread.sleep(CLEANUP_INTERVAL_SEC * 1000); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted between heartbeats."); + logger.debug("[ignored] interrupted between heartbeats."); } Thread monitorThread = new Thread(new Monitor()); @@ -167,7 +168,7 @@ public void run() { try { monitorThread.join(); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted joining monitor."); + logger.debug("[ignored] interrupted joining monitor."); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePool.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePool.java index e801142eb0bc..674799c0bbe3 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePool.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePool.java @@ -21,6 +21,7 @@ import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; +import com.cloud.hypervisor.kvm.resource.LibvirtVMDef; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.joda.time.Duration; @@ -102,4 +103,15 @@ public default KVMPhysicalDisk createPhysicalDisk(String volumeUuid, PhysicalDis public Boolean checkingHeartBeat(HAStoragePool pool, HostTO host); public Boolean vmActivityCheck(HAStoragePool pool, HostTO host, Duration activityScriptTimeout, String volumeUUIDListString, String vmActivityCheckPath, long duration); + + default LibvirtVMDef.DiskDef.BlockIOSize getSupportedLogicalBlockSize() { + return null; + } + + default LibvirtVMDef.DiskDef.BlockIOSize getSupportedPhysicalBlockSize() { + return null; + } + + default void customizeLibvirtDiskDef(LibvirtVMDef.DiskDef disk) { + } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java index 4f25cfa08d59..3c8026c7ffd6 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.hypervisor.kvm.storage; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; import java.net.URI; import java.net.URISyntaxException; import java.util.Arrays; @@ -30,7 +32,8 @@ import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.reflections.Reflections; import com.cloud.agent.api.to.DiskTO; @@ -48,7 +51,7 @@ import com.cloud.vm.VirtualMachine; public class KVMStoragePoolManager { - private static final Logger s_logger = Logger.getLogger(KVMStoragePoolManager.class); + protected Logger logger = LogManager.getLogger(getClass()); private class StoragePoolInformation { String name; @@ -100,35 +103,60 @@ private void addStoragePool(String uuid, StoragePoolInformation pool) { public KVMStoragePoolManager(StorageLayer storagelayer, KVMHAMonitor monitor) { this._haMonitor = monitor; this._storageMapper.put("libvirt", new LibvirtStorageAdaptor(storagelayer)); - // add other storage adaptors here - // this._storageMapper.put("newadaptor", new NewStorageAdaptor(storagelayer)); - this._storageMapper.put(StoragePoolType.ManagedNFS.toString(), new ManagedNfsStorageAdaptor(storagelayer)); - this._storageMapper.put(StoragePoolType.PowerFlex.toString(), new ScaleIOStorageAdaptor(storagelayer)); + // add other storage adaptors manually here - // add any adaptors that wish to register themselves via annotation + // add any adaptors that wish to register themselves via call to adaptor.getStoragePoolType() Reflections reflections = new Reflections("com.cloud.hypervisor.kvm.storage"); - Set> storageAdaptors = reflections.getSubTypesOf(StorageAdaptor.class); - for (Class storageAdaptor : storageAdaptors) { - StorageAdaptorInfo info = storageAdaptor.getAnnotation(StorageAdaptorInfo.class); - if (info != null && info.storagePoolType() != null) { - if (this._storageMapper.containsKey(info.storagePoolType().toString())) { - s_logger.warn(String.format("Duplicate StorageAdaptor type %s, not loading %s", info.storagePoolType().toString(), storageAdaptor.getName())); + Set> storageAdaptorClasses = reflections.getSubTypesOf(StorageAdaptor.class); + for (Class storageAdaptorClass : storageAdaptorClasses) { + logger.debug("Checking pool type for adaptor " + storageAdaptorClass.getName()); + if (Modifier.isAbstract(storageAdaptorClass.getModifiers()) || storageAdaptorClass.isInterface()) { + logger.debug("Skipping registration of abstract class / interface " + storageAdaptorClass.getName()); + continue; + } + if (storageAdaptorClass.isAssignableFrom(LibvirtStorageAdaptor.class)) { + logger.debug("Skipping re-registration of LibvirtStorageAdaptor"); + continue; + } + try { + Constructor storageLayerConstructor = Arrays.stream(storageAdaptorClass.getConstructors()) + .filter(c -> c.getParameterCount() == 1) + .filter(c -> c.getParameterTypes()[0].isAssignableFrom(StorageLayer.class)) + .findFirst().orElse(null); + StorageAdaptor adaptor; + + if (storageLayerConstructor == null) { + adaptor = storageAdaptorClass.getDeclaredConstructor().newInstance(); } else { - try { - s_logger.info(String.format("adding storage adaptor for %s", storageAdaptor.getName())); - this._storageMapper.put(info.storagePoolType().toString(), storageAdaptor.getDeclaredConstructor().newInstance()); - } catch (Exception ex) { - throw new CloudRuntimeException(ex.toString()); + adaptor = (StorageAdaptor) storageLayerConstructor.newInstance(storagelayer); + } + + StoragePoolType storagePoolType = adaptor.getStoragePoolType(); + if (storagePoolType != null) { + if (this._storageMapper.containsKey(storagePoolType.toString())) { + logger.warn(String.format("Duplicate StorageAdaptor type %s, not loading %s", storagePoolType, storageAdaptorClass.getName())); + } else { + logger.info(String.format("Adding storage adaptor for %s", storageAdaptorClass.getName())); + this._storageMapper.put(storagePoolType.toString(), adaptor); } } + } catch (Exception ex) { + throw new CloudRuntimeException("Failed to set up storage adaptors", ex); } } for (Map.Entry adaptors : this._storageMapper.entrySet()) { - s_logger.debug("Registered a StorageAdaptor for " + adaptors.getKey()); + logger.debug("Registered a StorageAdaptor for " + adaptors.getKey()); } } + /** + * Returns true if physical disk copy functionality supported. + */ + public boolean supportsPhysicalDiskCopy(StoragePoolType type) { + return getStorageAdaptor(type).supportsPhysicalDiskCopy(type); + } + public boolean connectPhysicalDisk(StoragePoolType type, String poolUuid, String volPath, Map details) { StorageAdaptor adaptor = getStorageAdaptor(type); KVMStoragePool pool = adaptor.getStoragePool(poolUuid); @@ -162,7 +190,7 @@ public boolean connectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) { result = adaptor.connectPhysicalDisk(vol.getPath(), pool, disk.getDetails()); if (!result) { - s_logger.error("Failed to connect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); + logger.error("Failed to connect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); return result; } } @@ -171,7 +199,7 @@ public boolean connectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) { } public boolean disconnectPhysicalDisk(Map volumeToDisconnect) { - s_logger.debug(String.format("Disconnect physical disks using volume map: %s", volumeToDisconnect.toString())); + logger.debug(String.format("Disconnect physical disks using volume map: %s", volumeToDisconnect.toString())); if (MapUtils.isEmpty(volumeToDisconnect)) { return false; } @@ -180,18 +208,18 @@ public boolean disconnectPhysicalDisk(Map volumeToDisconnect) { String poolType = volumeToDisconnect.get(DiskTO.PROTOCOL_TYPE); StorageAdaptor adaptor = _storageMapper.get(poolType); if (adaptor != null) { - s_logger.info(String.format("Disconnecting physical disk using the storage adaptor found for pool type: %s", poolType)); + logger.info(String.format("Disconnecting physical disk using the storage adaptor found for pool type: %s", poolType)); return adaptor.disconnectPhysicalDisk(volumeToDisconnect); } - s_logger.debug(String.format("Couldn't find the storage adaptor for pool type: %s to disconnect the physical disk, trying with others", poolType)); + logger.debug(String.format("Couldn't find the storage adaptor for pool type: %s to disconnect the physical disk, trying with others", poolType)); } for (Map.Entry set : _storageMapper.entrySet()) { StorageAdaptor adaptor = set.getValue(); if (adaptor.disconnectPhysicalDisk(volumeToDisconnect)) { - s_logger.debug(String.format("Disconnected physical disk using the storage adaptor for pool type: %s", set.getKey())); + logger.debug(String.format("Disconnected physical disk using the storage adaptor for pool type: %s", set.getKey())); return true; } } @@ -200,12 +228,12 @@ public boolean disconnectPhysicalDisk(Map volumeToDisconnect) { } public boolean disconnectPhysicalDiskByPath(String path) { - s_logger.debug(String.format("Disconnect physical disk by path: %s", path)); + logger.debug(String.format("Disconnect physical disk by path: %s", path)); for (Map.Entry set : _storageMapper.entrySet()) { StorageAdaptor adaptor = set.getValue(); if (adaptor.disconnectPhysicalDiskByPath(path)) { - s_logger.debug(String.format("Disconnected physical disk by local path: %s, using the storage adaptor for pool type: %s", path, set.getKey())); + logger.debug(String.format("Disconnected physical disk by local path: %s, using the storage adaptor for pool type: %s", path, set.getKey())); return true; } } @@ -220,7 +248,7 @@ public boolean disconnectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) { We may not know about these yet. This might mean that we can't use the vmspec map, because when we restart the agent we lose all of the info about running VMs. */ - s_logger.debug("disconnectPhysicalDiskViaVmSpec: Attempted to stop a VM that is not yet in our hash map"); + logger.debug("disconnectPhysicalDiskViaVmSpec: Attempted to stop a VM that is not yet in our hash map"); return true; } @@ -233,7 +261,7 @@ public boolean disconnectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) { for (DiskTO disk : disks) { if (disk.getType() != Volume.Type.ISO) { - s_logger.debug("Disconnecting disk " + disk.getPath()); + logger.debug("Disconnecting disk " + disk.getPath()); VolumeObjectTO vol = (VolumeObjectTO)disk.getData(); PrimaryDataStoreTO store = (PrimaryDataStoreTO)vol.getDataStore(); @@ -241,7 +269,7 @@ public boolean disconnectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) { KVMStoragePool pool = getStoragePool(store.getPoolType(), store.getUuid()); if (pool == null) { - s_logger.error("Pool " + store.getUuid() + " of type " + store.getPoolType() + " was not found, skipping disconnect logic"); + logger.error("Pool " + store.getUuid() + " of type " + store.getPoolType() + " was not found, skipping disconnect logic"); continue; } @@ -252,7 +280,7 @@ public boolean disconnectPhysicalDisksViaVmSpec(VirtualMachineTO vmSpec) { boolean subResult = adaptor.disconnectPhysicalDisk(vol.getPath(), pool); if (!subResult) { - s_logger.error("Failed to disconnect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); + logger.error("Failed to disconnect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); result = false; } @@ -325,14 +353,14 @@ public KVMPhysicalDisk getPhysicalDisk(StoragePoolType type, String poolUuid, St return vol; } } catch (Exception e) { - s_logger.debug("Failed to find volume:" + volName + " due to " + e.toString() + ", retry:" + cnt); + logger.debug("Failed to find volume:" + volName + " due to " + e.toString() + ", retry:" + cnt); errMsg = e.toString(); } try { Thread.sleep(3000); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while trying to get storage pool."); + logger.debug("[ignored] interrupted while trying to get storage pool."); } cnt++; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index 3b0e2e5b3713..04662604382a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -18,6 +18,74 @@ */ package com.cloud.hypervisor.kvm.storage; +import static com.cloud.utils.NumbersUtil.toHumanReadableSize; +import static com.cloud.utils.storage.S3.S3Utils.putFile; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer; +import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand; +import org.apache.cloudstack.direct.download.DirectDownloadHelper; +import org.apache.cloudstack.direct.download.DirectTemplateDownloader; +import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; +import org.apache.cloudstack.storage.command.AttachAnswer; +import org.apache.cloudstack.storage.command.AttachCommand; +import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand; +import org.apache.cloudstack.storage.command.CopyCmdAnswer; +import org.apache.cloudstack.storage.command.CopyCommand; +import org.apache.cloudstack.storage.command.CreateObjectAnswer; +import org.apache.cloudstack.storage.command.CreateObjectCommand; +import org.apache.cloudstack.storage.command.DeleteCommand; +import org.apache.cloudstack.storage.command.DettachAnswer; +import org.apache.cloudstack.storage.command.DettachCommand; +import org.apache.cloudstack.storage.command.ForgetObjectCmd; +import org.apache.cloudstack.storage.command.IntroduceObjectCmd; +import org.apache.cloudstack.storage.command.ResignatureAnswer; +import org.apache.cloudstack.storage.command.ResignatureCommand; +import org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer; +import org.apache.cloudstack.storage.command.SnapshotAndCopyCommand; +import org.apache.cloudstack.storage.command.SyncVolumePathCommand; +import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; +import org.apache.cloudstack.storage.to.SnapshotObjectTO; +import org.apache.cloudstack.storage.to.TemplateObjectTO; +import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.apache.cloudstack.utils.qemu.QemuImg; +import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; +import org.apache.cloudstack.utils.qemu.QemuImgException; +import org.apache.cloudstack.utils.qemu.QemuImgFile; +import org.apache.cloudstack.utils.qemu.QemuObject; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.libvirt.Connect; +import org.libvirt.Domain; +import org.libvirt.DomainInfo; +import org.libvirt.DomainSnapshot; +import org.libvirt.LibvirtException; + import com.ceph.rados.IoCTX; import com.ceph.rados.Rados; import com.ceph.rados.exceptions.ErrorCode; @@ -66,78 +134,13 @@ import com.cloud.utils.script.Script; import com.cloud.utils.storage.S3.S3Utils; import com.cloud.vm.VmDetailConstants; -import org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer; -import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand; -import org.apache.cloudstack.direct.download.DirectDownloadHelper; -import org.apache.cloudstack.direct.download.DirectTemplateDownloader; -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; -import org.apache.cloudstack.storage.command.AttachAnswer; -import org.apache.cloudstack.storage.command.AttachCommand; -import org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand; -import org.apache.cloudstack.storage.command.CopyCmdAnswer; -import org.apache.cloudstack.storage.command.CopyCommand; -import org.apache.cloudstack.storage.command.CreateObjectAnswer; -import org.apache.cloudstack.storage.command.CreateObjectCommand; -import org.apache.cloudstack.storage.command.DeleteCommand; -import org.apache.cloudstack.storage.command.DettachAnswer; -import org.apache.cloudstack.storage.command.DettachCommand; -import org.apache.cloudstack.storage.command.ForgetObjectCmd; -import org.apache.cloudstack.storage.command.IntroduceObjectCmd; -import org.apache.cloudstack.storage.command.ResignatureAnswer; -import org.apache.cloudstack.storage.command.ResignatureCommand; -import org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer; -import org.apache.cloudstack.storage.command.SnapshotAndCopyCommand; -import org.apache.cloudstack.storage.command.SyncVolumePathCommand; -import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; -import org.apache.cloudstack.storage.to.SnapshotObjectTO; -import org.apache.cloudstack.storage.to.TemplateObjectTO; -import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.utils.cryptsetup.KeyFile; import org.apache.cloudstack.utils.qemu.QemuImageOptions; -import org.apache.cloudstack.utils.qemu.QemuImg; -import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; -import org.apache.cloudstack.utils.qemu.QemuImgException; -import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.cloudstack.utils.qemu.QemuObject.EncryptFormat; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.log4j.Logger; -import org.libvirt.Connect; -import org.libvirt.Domain; -import org.libvirt.DomainInfo; -import org.libvirt.DomainSnapshot; -import org.libvirt.LibvirtException; - -import javax.naming.ConfigurationException; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -import static com.cloud.utils.NumbersUtil.toHumanReadableSize; -import static com.cloud.utils.storage.S3.S3Utils.putFile; public class KVMStorageProcessor implements StorageProcessor { - private static final Logger s_logger = Logger.getLogger(KVMStorageProcessor.class); + protected Logger logger = LogManager.getLogger(getClass()); private final KVMStoragePoolManager storagePoolMgr; private final LibvirtComputingResource resource; private StorageLayer storageLayer; @@ -187,14 +190,14 @@ public boolean configure(final String name, final Map params) th @Override public SnapshotAndCopyAnswer snapshotAndCopy(final SnapshotAndCopyCommand cmd) { - s_logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for KVMStorageProcessor"); + logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for KVMStorageProcessor"); return new SnapshotAndCopyAnswer(); } @Override public ResignatureAnswer resignature(final ResignatureCommand cmd) { - s_logger.info("'ResignatureAnswer resignature(ResignatureCommand)' not currently used for KVMStorageProcessor"); + logger.info("'ResignatureAnswer resignature(ResignatureCommand)' not currently used for KVMStorageProcessor"); return new ResignatureAnswer(); } @@ -248,7 +251,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { /* Copy volume to primary storage */ tmplVol.setUseAsTemplate(); - s_logger.debug("Copying template to primary storage, template format is " + tmplVol.getFormat() ); + logger.debug("Copying template to primary storage, template format is " + tmplVol.getFormat() ); final KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); KVMPhysicalDisk primaryVol = null; @@ -256,11 +259,11 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { final VolumeObjectTO volume = (VolumeObjectTO)destData; // pass along volume's target size if it's bigger than template's size, for storage types that copy template rather than cloning on deploy if (volume.getSize() != null && volume.getSize() > tmplVol.getVirtualSize()) { - s_logger.debug("Using configured size of " + toHumanReadableSize(volume.getSize())); + logger.debug("Using configured size of " + toHumanReadableSize(volume.getSize())); tmplVol.setSize(volume.getSize()); tmplVol.setVirtualSize(volume.getSize()); } else { - s_logger.debug("Using template's size of " + toHumanReadableSize(tmplVol.getVirtualSize())); + logger.debug("Using template's size of " + toHumanReadableSize(tmplVol.getVirtualSize())); } primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, volume.getUuid(), primaryPool, cmd.getWaitInMillSeconds()); } else if (destData instanceof TemplateObjectTO) { @@ -271,13 +274,13 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { String path = derivePath(primaryStore, destData, details); if (!storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details)) { - s_logger.warn("Failed to connect physical disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); + logger.warn("Failed to connect physical disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); } primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, path != null ? path : destTempl.getUuid(), primaryPool, cmd.getWaitInMillSeconds()); if (!storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path)) { - s_logger.warn("Failed to disconnect physical disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); + logger.warn("Failed to disconnect physical disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); } } else { primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, cmd.getWaitInMillSeconds()); @@ -323,7 +326,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { secondaryPool.delete(); } } catch(final Exception e) { - s_logger.debug("Failed to clean up secondary storage", e); + logger.debug("Failed to clean up secondary storage", e); } } } @@ -356,7 +359,7 @@ private KVMPhysicalDisk templateToPrimaryDownload(final String templateUrl, fina secondaryPool.refresh(); final List disks = secondaryPool.listPhysicalDisks(); if (disks == null || disks.isEmpty()) { - s_logger.error("Failed to get volumes from pool: " + secondaryPool.getUuid()); + logger.error("Failed to get volumes from pool: " + secondaryPool.getUuid()); return null; } for (final KVMPhysicalDisk disk : disks) { @@ -366,7 +369,7 @@ private KVMPhysicalDisk templateToPrimaryDownload(final String templateUrl, fina } } if (templateVol == null) { - s_logger.error("Failed to get template from pool: " + secondaryPool.getUuid()); + logger.error("Failed to get template from pool: " + secondaryPool.getUuid()); return null; } } else { @@ -376,17 +379,17 @@ private KVMPhysicalDisk templateToPrimaryDownload(final String templateUrl, fina /* Copy volume to primary storage */ if (size > templateVol.getSize()) { - s_logger.debug("Overriding provided template's size with new size " + toHumanReadableSize(size)); + logger.debug("Overriding provided template's size with new size " + toHumanReadableSize(size)); templateVol.setSize(size); templateVol.setVirtualSize(size); } else { - s_logger.debug("Using templates disk size of " + toHumanReadableSize(templateVol.getVirtualSize()) + "since size passed was " + toHumanReadableSize(size)); + logger.debug("Using templates disk size of " + toHumanReadableSize(templateVol.getVirtualSize()) + "since size passed was " + toHumanReadableSize(size)); } final KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(templateVol, volUuid, primaryPool, timeout); return primaryVol; } catch (final CloudRuntimeException e) { - s_logger.error("Failed to download template to primary storage", e); + logger.error("Failed to download template to primary storage", e); return null; } finally { if (secondaryPool != null) { @@ -415,22 +418,22 @@ public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { if (primaryPool.getType() == StoragePoolType.CLVM) { templatePath = ((NfsTO)imageStore).getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); - } if (primaryPool.getType() == StoragePoolType.PowerFlex) { + } if (storagePoolMgr.supportsPhysicalDiskCopy(primaryPool.getType())) { Map details = primaryStore.getDetails(); String path = derivePath(primaryStore, destData, details); if (!storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath, details)) { - s_logger.warn("Failed to connect base template volume at path: " + templatePath + ", in storage pool id: " + primaryStore.getUuid()); + logger.warn("Failed to connect base template volume at path: " + templatePath + ", in storage pool id: " + primaryStore.getUuid()); } BaseVol = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath); if (BaseVol == null) { - s_logger.debug("Failed to get the physical disk for base template volume at path: " + templatePath); + logger.debug("Failed to get the physical disk for base template volume at path: " + templatePath); throw new CloudRuntimeException("Failed to get the physical disk for base template volume at path: " + templatePath); } if (!storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details)) { - s_logger.warn("Failed to connect new volume at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); + logger.warn("Failed to connect new volume at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); } BaseVol.setDispName(template.getName()); @@ -467,7 +470,7 @@ public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to create volume: ", e); + logger.debug("Failed to create volume: ", e); return new CopyCmdAnswer(e.toString()); } finally { volume.clearPassphrase(); @@ -539,7 +542,7 @@ public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to copyVolumeFromImageCacheToPrimary: ", e); + logger.debug("Failed to copyVolumeFromImageCacheToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { @@ -587,7 +590,7 @@ public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) { newVol.setFormat(destFormat); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to copyVolumeFromPrimaryToSecondary: ", e); + logger.debug("Failed to copyVolumeFromPrimaryToSecondary: ", e); return new CopyCmdAnswer(e.toString()); } finally { srcVol.clearPassphrase(); @@ -638,7 +641,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) { final String templateName = UUID.randomUUID().toString(); if (primary.getType() != StoragePoolType.RBD) { - final Script command = new Script(_createTmplPath, wait, s_logger); + final Script command = new Script(_createTmplPath, wait, logger); command.add("-f", disk.getPath()); command.add("-t", tmpltPath); command.add(NAME_OPTION, templateName + ".qcow2"); @@ -646,11 +649,11 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) { final String result = command.execute(); if (result != null) { - s_logger.debug("failed to create template: " + result); + logger.debug("failed to create template: " + result); return new CopyCmdAnswer(result); } } else { - s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + templateName); + logger.debug("Converting RBD disk " + disk.getPath() + " into template " + templateName); final QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), primary.getSourcePort(), primary.getAuthUserName(), @@ -712,13 +715,13 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) { return new CopyCmdAnswer(newTemplate); } catch (final QemuImgException e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); return new CopyCmdAnswer(e.toString()); } catch (final IOException e) { - s_logger.debug("Failed to createTemplateFromVolume: ", e); + logger.debug("Failed to createTemplateFromVolume: ", e); return new CopyCmdAnswer(e.toString()); } catch (final Exception e) { - s_logger.debug("Failed to createTemplateFromVolume: ", e); + logger.debug("Failed to createTemplateFromVolume: ", e); return new CopyCmdAnswer(e.toString()); } finally { volume.clearPassphrase(); @@ -794,7 +797,7 @@ else if (srcData instanceof SnapshotObjectTO) { String templateName = UUID.randomUUID().toString(); - s_logger.debug("Converting " + srcDisk.getFormat().toString() + " disk " + srcDisk.getPath() + " into template " + templateName); + logger.debug("Converting " + srcDisk.getFormat().toString() + " disk " + srcDisk.getPath() + " into template " + templateName); String destName = templateFolder + "/" + templateName + ".qcow2"; @@ -853,10 +856,10 @@ else if (srcData instanceof SnapshotObjectTO) { return new CopyCmdAnswer(newTemplate); } catch (Exception ex) { if (isVolume) { - s_logger.debug("Failed to create template from volume: ", ex); + logger.debug("Failed to create template from volume: ", ex); } else { - s_logger.debug("Failed to create template from snapshot: ", ex); + logger.debug("Failed to create template from snapshot: ", ex); } return new CopyCmdAnswer(ex.toString()); @@ -905,7 +908,7 @@ protected Answer copyToObjectStore(final CopyCommand cmd) { newSnapshot.setPath(destPath); return new CopyCmdAnswer(newSnapshot); } catch (final Exception e) { - s_logger.error("failed to upload" + srcPath, e); + logger.error("failed to upload" + srcPath, e); return new CopyCmdAnswer("failed to upload" + srcPath + e.toString()); } finally { try { @@ -916,7 +919,7 @@ protected Answer copyToObjectStore(final CopyCommand cmd) { srcStorePool.delete(); } } catch (final Exception e) { - s_logger.debug("Failed to clean up:", e); + logger.debug("Failed to clean up:", e); } } } @@ -995,10 +998,10 @@ public Answer backupSnapshot(final CopyCommand cmd) { final String rbdSnapshot = snapshotDisk.getPath() + "@" + snapshotName; final String snapshotFile = snapshotDestPath + "/" + snapshotName; try { - s_logger.debug("Attempting to backup RBD snapshot " + rbdSnapshot); + logger.debug("Attempting to backup RBD snapshot " + rbdSnapshot); final File snapDir = new File(snapshotDestPath); - s_logger.debug("Attempting to create " + snapDir.getAbsolutePath() + " recursively for snapshot storage"); + logger.debug("Attempting to create " + snapDir.getAbsolutePath() + " recursively for snapshot storage"); FileUtils.forceMkdir(snapDir); final QemuImgFile srcFile = @@ -1009,7 +1012,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { final QemuImgFile destFile = new QemuImgFile(snapshotFile); destFile.setFormat(PhysicalDiskFormat.QCOW2); - s_logger.debug("Backing up RBD snapshot " + rbdSnapshot + " to " + snapshotFile); + logger.debug("Backing up RBD snapshot " + rbdSnapshot + " to " + snapshotFile); final QemuImg q = new QemuImg(cmd.getWaitInMillSeconds()); q.convert(srcFile, destFile); @@ -1018,20 +1021,20 @@ public Answer backupSnapshot(final CopyCommand cmd) { size = snapFile.length(); } - s_logger.debug("Finished backing up RBD snapshot " + rbdSnapshot + " to " + snapshotFile + " Snapshot size: " + toHumanReadableSize(size)); + logger.debug("Finished backing up RBD snapshot " + rbdSnapshot + " to " + snapshotFile + " Snapshot size: " + toHumanReadableSize(size)); } catch (final FileNotFoundException e) { - s_logger.error("Failed to open " + snapshotDestPath + ". The error was: " + e.getMessage()); + logger.error("Failed to open " + snapshotDestPath + ". The error was: " + e.getMessage()); return new CopyCmdAnswer(e.toString()); } catch (final IOException e) { - s_logger.error("Failed to create " + snapshotDestPath + ". The error was: " + e.getMessage()); + logger.error("Failed to create " + snapshotDestPath + ". The error was: " + e.getMessage()); return new CopyCmdAnswer(e.toString()); } catch (final QemuImgException | LibvirtException e) { - s_logger.error("Failed to backup the RBD snapshot from " + rbdSnapshot + + logger.error("Failed to backup the RBD snapshot from " + rbdSnapshot + " to " + snapshotFile + " the error was: " + e.getMessage()); return new CopyCmdAnswer(e.toString()); } } else { - final Script command = new Script(_manageSnapshotPath, cmd.getWaitInMillSeconds(), s_logger); + final Script command = new Script(_manageSnapshotPath, cmd.getWaitInMillSeconds(), logger); command.add("-b", isCreatedFromVmSnapshot ? snapshotDisk.getPath() : snapshot.getPath()); command.add(NAME_OPTION, snapshotName); command.add("-p", snapshotDestPath); @@ -1041,7 +1044,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { command.add("-t", descName); final String result = command.execute(); if (result != null) { - s_logger.debug("Failed to backup snaptshot: " + result); + logger.debug("Failed to backup snaptshot: " + result); return new CopyCmdAnswer(result); } final File snapFile = new File(snapshotDestPath + "/" + descName); @@ -1055,12 +1058,12 @@ public Answer backupSnapshot(final CopyCommand cmd) { newSnapshot.setPhysicalSize(size); return new CopyCmdAnswer(newSnapshot); } catch (final LibvirtException | CloudRuntimeException e) { - s_logger.debug("Failed to backup snapshot: ", e); + logger.debug("Failed to backup snapshot: ", e); return new CopyCmdAnswer(e.toString()); } finally { srcVolume.clearPassphrase(); if (isCreatedFromVmSnapshot) { - s_logger.debug("Ignoring removal of vm snapshot on primary as this snapshot is created from vm snapshot"); + logger.debug("Ignoring removal of vm snapshot on primary as this snapshot is created from vm snapshot"); } else if (primaryPool != null && primaryPool.getType() != StoragePoolType.RBD) { deleteSnapshotOnPrimary(cmd, snapshot, primaryPool); } @@ -1070,7 +1073,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { secondaryStoragePool.delete(); } } catch (final Exception ex) { - s_logger.debug("Failed to delete secondary storage", ex); + logger.debug("Failed to delete secondary storage", ex); } } } @@ -1089,10 +1092,10 @@ private void deleteSnapshotOnPrimary(final CopyCommand cmd, final SnapshotObject try { Files.deleteIfExists(Paths.get(snapshotPath)); } catch (IOException ex) { - s_logger.error(String.format("Failed to delete snapshot [%s] on primary storage [%s].", snapshotPath, primaryPool.getUuid()), ex); + logger.error(String.format("Failed to delete snapshot [%s] on primary storage [%s].", snapshotPath, primaryPool.getUuid()), ex); } } else { - s_logger.debug(String.format("This backup is temporary, not deleting snapshot [%s] on primary storage [%s]", snapshotPath, primaryPool.getUuid())); + logger.debug(String.format("This backup is temporary, not deleting snapshot [%s] on primary storage [%s]", snapshotPath, primaryPool.getUuid())); } } @@ -1179,7 +1182,7 @@ public Answer dettachIso(final DettachCommand cmd) { private String getDataStoreUrlFromStore(DataStoreTO store) { List supportedPoolType = List.of(StoragePoolType.NetworkFilesystem, StoragePoolType.Filesystem); if (!(store instanceof NfsTO) && (!(store instanceof PrimaryDataStoreTO) || !supportedPoolType.contains(((PrimaryDataStoreTO) store).getPoolType()))) { - s_logger.error(String.format("Unsupported protocol, store: %s", store.getUuid())); + logger.error(String.format("Unsupported protocol, store: %s", store.getUuid())); throw new InvalidParameterValueException("unsupported protocol"); } @@ -1223,11 +1226,11 @@ protected synchronized void attachOrDetachDevice(final Connect conn, final boole dm = conn.domainLookupByName(vmName); if (attach) { - s_logger.debug("Attaching device: " + diskXml); + logger.debug("Attaching device: " + diskXml); dm.attachDevice(diskXml); return; } - s_logger.debug(String.format("Detaching device: [%s].", diskXml)); + logger.debug(String.format("Detaching device: [%s].", diskXml)); dm.detachDevice(diskXml); long wait = waitDetachDevice; while (!checkDetachSuccess(diskPath, dm) && wait > 0) { @@ -1238,13 +1241,13 @@ protected synchronized void attachOrDetachDevice(final Connect conn, final boole "not support the sent detach command or the device is busy at the moment. Try again in a couple of minutes.", waitDetachDevice)); } - s_logger.debug(String.format("The detach command was executed successfully. The device [%s] was removed from the VM instance with UUID [%s].", + logger.debug(String.format("The detach command was executed successfully. The device [%s] was removed from the VM instance with UUID [%s].", diskPath, dm.getUUIDString())); } catch (final LibvirtException e) { if (attach) { - s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); + logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); } else { - s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); + logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); } throw e; } finally { @@ -1252,7 +1255,7 @@ protected synchronized void attachOrDetachDevice(final Connect conn, final boole try { dm.free(); } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); } } } @@ -1267,7 +1270,7 @@ private long getWaitAfterSleep(Domain dm, String diskPath, long wait) throws Lib try { wait -= waitDelayForVirshCommands; Thread.sleep(waitDelayForVirshCommands); - s_logger.trace(String.format("Trying to detach device [%s] from VM instance with UUID [%s]. " + + logger.trace(String.format("Trying to detach device [%s] from VM instance with UUID [%s]. " + "Waiting [%s] milliseconds before assuming the VM was unable to detach the volume.", diskPath, dm.getUUIDString(), wait)); } catch (InterruptedException e) { throw new CloudRuntimeException(e); @@ -1287,7 +1290,7 @@ protected boolean checkDetachSuccess(String diskPath, Domain dm) throws LibvirtE List disks = parser.getDisks(); for (DiskDef diskDef : disks) { if (StringUtils.equals(diskPath, diskDef.getDiskPath())) { - s_logger.debug(String.format("The hypervisor sent the detach command, but it is still possible to identify the device [%s] in the instance with UUID [%s].", + logger.debug(String.format("The hypervisor sent the detach command, but it is still possible to identify the device [%s] in the instance with UUID [%s].", diskPath, dm.getUUIDString())); return false; } @@ -1381,7 +1384,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean if (resource.getHypervisorType() == Hypervisor.HypervisorType.LXC) { final String device = resource.mapRbdDevice(attachingDisk); if (device != null) { - s_logger.debug("RBD device on host is: "+device); + logger.debug("RBD device on host is: "+device); attachingDisk.setPath(device); } } @@ -1395,7 +1398,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean } } if (diskdef == null) { - s_logger.warn(String.format("Could not find disk [%s] attached to VM instance with UUID [%s]. We will set it as detached in the database to ensure consistency.", + logger.warn(String.format("Could not find disk [%s] attached to VM instance with UUID [%s]. We will set it as detached in the database to ensure consistency.", attachingDisk.getPath(), dm.getUUIDString())); return; } @@ -1420,7 +1423,7 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean // For LXC, map image to host and then attach to Vm final String device = resource.mapRbdDevice(attachingDisk); if (device != null) { - s_logger.debug("RBD device on host is: "+device); + logger.debug("RBD device on host is: "+device); diskdef.defBlockBasedDisk(device, devId, busT); } else { throw new InternalErrorException("Error while mapping disk "+attachingDisk.getPath()+" on host"); @@ -1496,6 +1499,9 @@ protected synchronized void attachOrDetachDisk(final Connect conn, final boolean if (ioDriver != null) { resource.setDiskIoDriver(diskdef, resource.getIoDriverForTheStorage(ioDriver.toUpperCase())); } + diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize()); + diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize()); + attachingPool.customizeLibvirtDiskDef(diskdef); } attachOrDetachDevice(conn, attach, vmName, diskdef, waitDetachDevice); @@ -1527,7 +1533,7 @@ public Answer attachVolume(final AttachCommand cmd) { final KVMPhysicalDisk phyDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); final String volCacheMode = vol.getCacheMode() == null ? null : vol.getCacheMode().toString(); - s_logger.debug(String.format("Attaching physical disk %s with format %s", phyDisk.getPath(), phyDisk.getFormat())); + logger.debug(String.format("Attaching physical disk %s with format %s", phyDisk.getPath(), phyDisk.getFormat())); attachOrDetachDisk(conn, true, vmName, phyDisk, disk.getDiskSeq().intValue(), serial, vol.getBytesReadRate(), vol.getBytesReadRateMax(), vol.getBytesReadRateMaxLength(), @@ -1537,14 +1543,14 @@ public Answer attachVolume(final AttachCommand cmd) { return new AttachAnswer(disk); } catch (final LibvirtException e) { - s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); return new AttachAnswer(e.toString()); } catch (final InternalErrorException e) { - s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); return new AttachAnswer(e.toString()); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); return new AttachAnswer(e.toString()); } finally { vol.clearPassphrase(); @@ -1575,13 +1581,13 @@ public Answer dettachVolume(final DettachCommand cmd) { return new DettachAnswer(disk); } catch (final LibvirtException e) { - s_logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); return new DettachAnswer(e.toString()); } catch (final InternalErrorException e) { - s_logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); return new DettachAnswer(e.toString()); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); return new DettachAnswer(e.toString()); } finally { vol.clearPassphrase(); @@ -1610,7 +1616,7 @@ protected KVMPhysicalDisk createLinkedCloneVolume(MigrationOptions migrationOpti * Create full clone volume from VM snapshot */ protected KVMPhysicalDisk createFullCloneVolume(MigrationOptions migrationOptions, VolumeObjectTO volume, KVMStoragePool primaryPool, PhysicalDiskFormat format) { - s_logger.debug("For VM migration with full-clone volume: Creating empty stub disk for source disk " + migrationOptions.getSrcVolumeUuid() + " and size: " + toHumanReadableSize(volume.getSize()) + " and format: " + format); + logger.debug("For VM migration with full-clone volume: Creating empty stub disk for source disk " + migrationOptions.getSrcVolumeUuid() + " and size: " + toHumanReadableSize(volume.getSize()) + " and format: " + format); return primaryPool.createPhysicalDisk(volume.getUuid(), format, volume.getProvisioningType(), volume.getSize(), volume.getPassphrase()); } @@ -1662,7 +1668,7 @@ public Answer createVolume(final CreateObjectCommand cmd) { return new CreateObjectAnswer(newVol); } catch (final Exception e) { - s_logger.debug("Failed to create volume: ", e); + logger.debug("Failed to create volume: ", e); return new CreateObjectAnswer(e.toString()); } finally { volume.clearPassphrase(); @@ -1737,7 +1743,7 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { vm = resource.getDomain(conn, vmName); state = vm.getInfo().state; } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + logger.trace("Ignoring libvirt error.", e); } } @@ -1769,7 +1775,7 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { throw e; } - s_logger.info(String.format("It was not possible to take live disk snapshot for volume [%s], in VM [%s], due to [%s]. We will take full snapshot of the VM" + logger.info(String.format("It was not possible to take live disk snapshot for volume [%s], in VM [%s], due to [%s]. We will take full snapshot of the VM" + " and extract the disk instead. Consider upgrading your QEMU binary.", volume, vmName, e.getMessage())); takeFullVmSnapshotForBinariesThatDoesNotSupportLiveDiskSnapshot(vm, snapshotName, vmName); @@ -1808,22 +1814,22 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { final Rbd rbd = new Rbd(io); final RbdImage image = rbd.open(disk.getName()); - s_logger.debug("Attempting to create RBD snapshot " + disk.getName() + "@" + snapshotName); + logger.debug("Attempting to create RBD snapshot " + disk.getName() + "@" + snapshotName); image.snapCreate(snapshotName); rbd.close(image); r.ioCtxDestroy(io); } catch (final Exception e) { - s_logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage()); + logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage()); } } else if (primaryPool.getType() == StoragePoolType.CLVM) { /* VM is not running, create a snapshot by ourself */ - final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger); + final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, logger); command.add(MANAGE_SNAPSTHOT_CREATE_OPTION, disk.getPath()); command.add(NAME_OPTION, snapshotName); final String result = command.execute(); if (result != null) { - s_logger.debug("Failed to manage snapshot: " + result); + logger.debug("Failed to manage snapshot: " + result); return new CreateObjectAnswer("Failed to manage snapshot: " + result); } } else { @@ -1839,7 +1845,7 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { return new CreateObjectAnswer(newSnapshot); } catch (CloudRuntimeException | LibvirtException | IOException ex) { String errorMsg = String.format("Failed take snapshot for volume [%s], in VM [%s], due to [%s].", volume, vmName, ex.getMessage()); - s_logger.error(errorMsg, ex); + logger.error(errorMsg, ex); return new CreateObjectAnswer(errorMsg); } finally { volume.clearPassphrase(); @@ -1847,7 +1853,7 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { } protected void deleteFullVmSnapshotAfterConvertingItToExternalDiskSnapshot(Domain vm, String snapshotName, VolumeObjectTO volume, String vmName) throws LibvirtException { - s_logger.debug(String.format("Deleting full VM snapshot [%s] of VM [%s] as we already converted it to an external disk snapshot of the volume [%s].", snapshotName, vmName, + logger.debug(String.format("Deleting full VM snapshot [%s] of VM [%s] as we already converted it to an external disk snapshot of the volume [%s].", snapshotName, vmName, volume)); DomainSnapshot domainSnapshot = vm.snapshotLookupByName(snapshotName); @@ -1861,13 +1867,13 @@ protected void extractDiskFromFullVmSnapshot(KVMPhysicalDisk disk, VolumeObjectT try { QemuImg qemuImg = new QemuImg(_cmdsTimeout); - s_logger.debug(String.format("Converting full VM snapshot [%s] of VM [%s] to external disk snapshot of the volume [%s].", snapshotName, vmName, volume)); + logger.debug(String.format("Converting full VM snapshot [%s] of VM [%s] to external disk snapshot of the volume [%s].", snapshotName, vmName, volume)); qemuImg.convert(srcFile, destFile, null, snapshotName, true); } catch (QemuImgException qemuException) { String message = String.format("Could not convert full VM snapshot [%s] of VM [%s] to external disk snapshot of volume [%s] due to [%s].", snapshotName, vmName, volume, qemuException.getMessage()); - s_logger.error(message, qemuException); + logger.error(message, qemuException); throw new CloudRuntimeException(message, qemuException); } finally { deleteFullVmSnapshotAfterConvertingItToExternalDiskSnapshot(vm, snapshotName, volume, vmName); @@ -1879,7 +1885,7 @@ protected void takeFullVmSnapshotForBinariesThatDoesNotSupportLiveDiskSnapshot(D long start = System.currentTimeMillis(); vm.snapshotCreateXML(String.format(XML_CREATE_FULL_VM_SNAPSHOT, snapshotName, vmUuid)); - s_logger.debug(String.format("Full VM Snapshot [%s] of VM [%s] took [%s] seconds to finish.", snapshotName, vmName, (System.currentTimeMillis() - start)/1000)); + logger.debug(String.format("Full VM Snapshot [%s] of VM [%s] took [%s] seconds to finish.", snapshotName, vmName, (System.currentTimeMillis() - start)/1000)); } protected void validateConvertResult(String convertResult, String snapshotPath) throws CloudRuntimeException, IOException { @@ -1907,7 +1913,7 @@ protected void mergeSnapshotIntoBaseFile(Domain vm, String diskLabel, String bas String mergeResult = Script.runSimpleBashScript(mergeCommand); if (mergeResult == null) { - s_logger.debug(String.format("Successfully merged snapshot [%s] into VM [%s] %s base file.", snapshotName, vmName, volume)); + logger.debug(String.format("Successfully merged snapshot [%s] into VM [%s] %s base file.", snapshotName, vmName, volume)); manuallyDeleteUnusedSnapshotFile(isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit, getSnapshotTemporaryPath(baseFilePath, snapshotName)); return; } @@ -1916,7 +1922,7 @@ protected void mergeSnapshotIntoBaseFile(Domain vm, String diskLabel, String bas + " will start to write in the base file again. All changes made between the snapshot and the VM stop will be in the snapshot. If the VM is stopped, the snapshot must be" + " merged into the base file manually.", snapshotName, vmName, volume, mergeCommand, mergeResult); - s_logger.warn(String.format("%s VM XML: [%s].", errorMsg, vm.getXMLDesc(0))); + logger.warn(String.format("%s VM XML: [%s].", errorMsg, vm.getXMLDesc(0))); throw new CloudRuntimeException(errorMsg); } @@ -1928,17 +1934,17 @@ protected void mergeSnapshotIntoBaseFile(Domain vm, String diskLabel, String bas */ protected void manuallyDeleteUnusedSnapshotFile(boolean isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit, String snapshotPath) { if (isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit) { - s_logger.debug(String.format("The current Libvirt's version supports the flag '--delete' on command 'virsh blockcommit', we will skip the manually deletion of the" + logger.debug(String.format("The current Libvirt's version supports the flag '--delete' on command 'virsh blockcommit', we will skip the manually deletion of the" + " unused snapshot file [%s] as it already was automatically deleted.", snapshotPath)); return; } - s_logger.debug(String.format("The current Libvirt's version does not supports the flag '--delete' on command 'virsh blockcommit', therefore we will manually delete the" + logger.debug(String.format("The current Libvirt's version does not supports the flag '--delete' on command 'virsh blockcommit', therefore we will manually delete the" + " unused snapshot file [%s].", snapshotPath)); try { Files.deleteIfExists(Paths.get(snapshotPath)); - s_logger.debug(String.format("Manually deleted unused snapshot file [%s].", snapshotPath)); + logger.debug(String.format("Manually deleted unused snapshot file [%s].", snapshotPath)); } catch (IOException ex) { throw new CloudRuntimeException(String.format("Unable to manually delete unused snapshot file [%s] due to [%s].", snapshotPath, ex.getMessage())); } @@ -1954,7 +1960,7 @@ protected void manuallyDeleteUnusedSnapshotFile(boolean isLibvirtSupportingFlagD protected String convertBaseFileToSnapshotFileInPrimaryStorageDir(KVMStoragePool primaryPool, KVMPhysicalDisk baseFile, String snapshotPath, VolumeObjectTO volume, int wait) { try (KeyFile srcKey = new KeyFile(volume.getPassphrase())) { - s_logger.debug( + logger.debug( String.format("Trying to convert volume [%s] (%s) to snapshot [%s].", volume, baseFile, snapshotPath)); primaryPool.createFolder(TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR); @@ -1964,7 +1970,7 @@ protected String convertBaseFileToSnapshotFileInPrimaryStorageDir(KVMStoragePool snapshotPath, ex.getMessage()); } - s_logger.debug(String.format("Converted volume [%s] (from path \"%s\") to snapshot [%s].", volume, baseFile, + logger.debug(String.format("Converted volume [%s] (from path \"%s\") to snapshot [%s].", volume, baseFile, snapshotPath)); return null; } @@ -2020,7 +2026,7 @@ protected String takeVolumeSnapshot(List disks, String snapshotName, St long start = System.currentTimeMillis(); vm.snapshotCreateXML(createSnapshotXmlFormated, VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY); - s_logger.debug(String.format("Snapshot [%s] took [%s] seconds to finish.", snapshotName, (System.currentTimeMillis() - start)/1000)); + logger.debug(String.format("Snapshot [%s] took [%s] seconds to finish.", snapshotName, (System.currentTimeMillis() - start)/1000)); return diskLabelToSnapshot; } @@ -2094,7 +2100,7 @@ protected void validateAvailableSizeOnPoolToTakeVolumeSnapshot(KVMStoragePool pr diskDescription)); } - s_logger.debug(String.format("Pool [%s] has enough available size [%s] to take volume [%s] snapshot.", poolDescription, availablePoolSize, diskDescription)); + logger.debug(String.format("Pool [%s] has enough available size [%s] to take volume [%s] snapshot.", poolDescription, availablePoolSize, diskDescription)); } protected boolean isAvailablePoolSizeDividedByDiskSizeLesserThanMinRate(long availablePoolSize, long diskSize) { @@ -2107,7 +2113,7 @@ private Rados radosConnect(final KVMStoragePool primaryPool) throws RadosExcepti r.confSet(CEPH_AUTH_KEY, primaryPool.getAuthSecret()); r.confSet(CEPH_CLIENT_MOUNT_TIMEOUT, CEPH_DEFAULT_MOUNT_TIMEOUT); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet(CEPH_MON_HOST)); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet(CEPH_MON_HOST)); return r; } @@ -2120,13 +2126,13 @@ public Answer deleteVolume(final DeleteCommand cmd) { try { pool.getPhysicalDisk(vol.getPath()); } catch (final Exception e) { - s_logger.debug("can't find volume: " + vol.getPath() + ", return true"); + logger.debug("can't find volume: " + vol.getPath() + ", return true"); return new Answer(null); } pool.deletePhysicalDisk(vol.getPath(), vol.getFormat()); return new Answer(null); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to delete volume: ", e); + logger.debug("Failed to delete volume: ", e); return new Answer(null, false, e.toString()); } finally { vol.clearPassphrase(); @@ -2168,7 +2174,7 @@ public Answer createVolumeFromSnapshot(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to createVolumeFromSnapshot: ", e); + logger.debug("Failed to createVolumeFromSnapshot: ", e); return new CopyCmdAnswer(e.toString()); } finally { volume.clearPassphrase(); @@ -2187,11 +2193,11 @@ private KVMPhysicalDisk createVolumeFromRBDSnapshot(CopyCommand cmd, DataTO dest VolumeObjectTO newVol = (VolumeObjectTO) destData; if (StoragePoolType.RBD.equals(primaryStore.getPoolType())) { - s_logger.debug(String.format("Attempting to create volume from RBD snapshot %s", snapshotName)); + logger.debug(String.format("Attempting to create volume from RBD snapshot %s", snapshotName)); if (StoragePoolType.RBD.equals(pool.getPoolType())) { disk = createRBDvolumeFromRBDSnapshot(snapshotDisk, snapshotName, newVol.getUuid(), PhysicalDiskFormat.RAW, newVol.getSize(), destPool, cmd.getWaitInMillSeconds()); - s_logger.debug(String.format("Created RBD volume %s from snapshot %s", disk, snapshotDisk)); + logger.debug(String.format("Created RBD volume %s from snapshot %s", disk, snapshotDisk)); } else { Map details = cmd.getOptions2(); @@ -2204,7 +2210,7 @@ private KVMPhysicalDisk createVolumeFromRBDSnapshot(CopyCommand cmd, DataTO dest destPool, cmd.getWaitInMillSeconds()); storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), path); - s_logger.debug(String.format("Created RBD volume %s from snapshot %s", disk, snapshotDisk)); + logger.debug(String.format("Created RBD volume %s from snapshot %s", disk, snapshotDisk)); } } @@ -2281,12 +2287,12 @@ private KVMPhysicalDisk createRBDvolumeFromRBDSnapshot(KVMPhysicalDisk volume, S } if (!snapFound) { - s_logger.debug(String.format("Could not find snapshot %s on RBD", snapshotName)); + logger.debug(String.format("Could not find snapshot %s on RBD", snapshotName)); return null; } srcImage.snapProtect(snapshotName); - s_logger.debug(String.format("Try to clone snapshot %s on RBD", snapshotName)); + logger.debug(String.format("Try to clone snapshot %s on RBD", snapshotName)); rbd.clone(volume.getName(), snapshotName, io, disk.getName(), LibvirtStorageAdaptor.RBD_FEATURES, 0); RbdImage diskImage = rbd.open(disk.getName()); if (disk.getVirtualSize() > volume.getVirtualSize()) { @@ -2300,7 +2306,7 @@ private KVMPhysicalDisk createRBDvolumeFromRBDSnapshot(KVMPhysicalDisk volume, S rbd.close(srcImage); r.ioCtxDestroy(io); } catch (RadosException | RbdException e) { - s_logger.error(String.format("Failed due to %s", e.getMessage()), e); + logger.error(String.format("Failed due to %s", e.getMessage()), e); disk = null; } @@ -2326,16 +2332,16 @@ public Answer deleteSnapshot(final DeleteCommand cmd) { Rbd rbd = new Rbd(io); RbdImage image = rbd.open(disk.getName()); try { - s_logger.info("Attempting to remove RBD snapshot " + snapshotFullName); + logger.info("Attempting to remove RBD snapshot " + snapshotFullName); if (image.snapIsProtected(snapshotName)) { - s_logger.debug("Unprotecting RBD snapshot " + snapshotFullName); + logger.debug("Unprotecting RBD snapshot " + snapshotFullName); image.snapUnprotect(snapshotName); } image.snapRemove(snapshotName); - s_logger.info("Snapshot " + snapshotFullName + " successfully removed from " + + logger.info("Snapshot " + snapshotFullName + " successfully removed from " + primaryPool.getType().toString() + " pool."); } catch (RbdException e) { - s_logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + + logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); } finally { rbd.close(image); @@ -2343,24 +2349,24 @@ public Answer deleteSnapshot(final DeleteCommand cmd) { } } else if (storagePoolTypesToDeleteSnapshotFile.contains(primaryPool.getType())) { - s_logger.info(String.format("Deleting snapshot (id=%s, name=%s, path=%s, storage type=%s) on primary storage", snapshotTO.getId(), snapshotTO.getName(), + logger.info(String.format("Deleting snapshot (id=%s, name=%s, path=%s, storage type=%s) on primary storage", snapshotTO.getId(), snapshotTO.getName(), snapshotTO.getPath(), primaryPool.getType())); deleteSnapshotFile(snapshotTO); } else { - s_logger.warn("Operation not implemented for storage pool type of " + primaryPool.getType().toString()); + logger.warn("Operation not implemented for storage pool type of " + primaryPool.getType().toString()); throw new InternalErrorException("Operation not implemented for storage pool type of " + primaryPool.getType().toString()); } return new Answer(cmd, true, "Snapshot " + snapshotFullName + " removed successfully."); } catch (RadosException e) { - s_logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + + logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); return new Answer(cmd, false, "Failed to remove snapshot " + snapshotFullName); } catch (RbdException e) { - s_logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + + logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); return new Answer(cmd, false, "Failed to remove snapshot " + snapshotFullName); } catch (Exception e) { - s_logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString()); + logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString()); return new Answer(cmd, false, "Failed to remove snapshot " + snapshotFullName); } finally { volume.clearPassphrase(); @@ -2374,7 +2380,7 @@ public Answer deleteSnapshot(final DeleteCommand cmd) { protected void deleteSnapshotFile(SnapshotObjectTO snapshotObjectTo) throws CloudRuntimeException { try { Files.deleteIfExists(Paths.get(snapshotObjectTo.getPath())); - s_logger.debug(String.format("Deleted snapshot [%s].", snapshotObjectTo)); + logger.debug(String.format("Deleted snapshot [%s].", snapshotObjectTo)); } catch (IOException ex) { throw new CloudRuntimeException(String.format("Unable to delete snapshot [%s] due to [%s].", snapshotObjectTo, ex.getMessage())); } @@ -2398,12 +2404,12 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd) KVMStoragePool destPool = null; try { - s_logger.debug("Verifying temporary location for downloading the template exists on the host"); + logger.debug("Verifying temporary location for downloading the template exists on the host"); String temporaryDownloadPath = resource.getDirectDownloadTemporaryDownloadPath(); if (!isLocationAccessible(temporaryDownloadPath)) { String msg = "The temporary location path for downloading templates does not exist: " + temporaryDownloadPath + " on this host"; - s_logger.error(msg); + logger.error(msg); return new DirectDownloadAnswer(false, msg, true); } @@ -2413,24 +2419,24 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd) templateSize = UriUtils.getRemoteSize(url, cmd.isFollowRedirects()); } - s_logger.debug("Checking for free space on the host for downloading the template with physical size: " + templateSize + " and virtual size: " + cmd.getTemplateSize()); + logger.debug("Checking for free space on the host for downloading the template with physical size: " + templateSize + " and virtual size: " + cmd.getTemplateSize()); if (!isEnoughSpaceForDownloadTemplateOnTemporaryLocation(templateSize)) { String msg = "Not enough space on the defined temporary location to download the template " + cmd.getTemplateId(); - s_logger.error(msg); + logger.error(msg); return new DirectDownloadAnswer(false, msg, true); } destPool = storagePoolMgr.getStoragePool(pool.getPoolType(), pool.getUuid()); downloader = DirectDownloadHelper.getDirectTemplateDownloaderFromCommand(cmd, destPool.getLocalPath(), temporaryDownloadPath); - s_logger.debug("Trying to download template"); + logger.debug("Trying to download template"); Pair result = downloader.downloadTemplate(); if (!result.first()) { - s_logger.warn("Couldn't download template"); + logger.warn("Couldn't download template"); return new DirectDownloadAnswer(false, "Unable to download template", true); } String tempFilePath = result.second(); if (!downloader.validateChecksum()) { - s_logger.warn("Couldn't validate template checksum"); + logger.warn("Couldn't validate template checksum"); return new DirectDownloadAnswer(false, "Checksum validation failed", false); } @@ -2438,16 +2444,16 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd) String destTemplatePath = (destTemplate != null) ? destTemplate.getPath() : null; if (!storagePoolMgr.connectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath, null)) { - s_logger.warn("Unable to connect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); + logger.warn("Unable to connect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); } template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds()); if (!storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath)) { - s_logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); + logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); } } catch (CloudRuntimeException e) { - s_logger.warn("Error downloading template " + cmd.getTemplateId() + " due to: " + e.getMessage()); + logger.warn("Error downloading template " + cmd.getTemplateId() + " due to: " + e.getMessage()); return new DirectDownloadAnswer(false, "Unable to download template: " + e.getMessage(), true); } catch (IllegalArgumentException e) { return new DirectDownloadAnswer(false, "Unable to create direct downloader: " + e.getMessage(), true); @@ -2473,18 +2479,18 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { KVMStoragePool destPool = null; try { - s_logger.debug("Copying src volume (id: " + srcVol.getId() + ", format: " + srcFormat + ", path: " + srcVolumePath + ", primary storage: [id: " + srcPrimaryStore.getId() + ", type: " + srcPrimaryStore.getPoolType() + "]) to dest volume (id: " + + logger.debug("Copying src volume (id: " + srcVol.getId() + ", format: " + srcFormat + ", path: " + srcVolumePath + ", primary storage: [id: " + srcPrimaryStore.getId() + ", type: " + srcPrimaryStore.getPoolType() + "]) to dest volume (id: " + destVol.getId() + ", format: " + destFormat + ", path: " + destVolumePath + ", primary storage: [id: " + destPrimaryStore.getId() + ", type: " + destPrimaryStore.getPoolType() + "])."); if (srcPrimaryStore.isManaged()) { if (!storagePoolMgr.connectPhysicalDisk(srcPrimaryStore.getPoolType(), srcPrimaryStore.getUuid(), srcVolumePath, srcPrimaryStore.getDetails())) { - s_logger.warn("Failed to connect src volume at path: " + srcVolumePath + ", in storage pool id: " + srcPrimaryStore.getUuid()); + logger.warn("Failed to connect src volume at path: " + srcVolumePath + ", in storage pool id: " + srcPrimaryStore.getUuid()); } } final KVMPhysicalDisk volume = storagePoolMgr.getPhysicalDisk(srcPrimaryStore.getPoolType(), srcPrimaryStore.getUuid(), srcVolumePath); if (volume == null) { - s_logger.debug("Failed to get physical disk for volume: " + srcVolumePath); + logger.debug("Failed to get physical disk for volume: " + srcVolumePath); throw new CloudRuntimeException("Failed to get physical disk for volume at path: " + srcVolumePath); } @@ -2495,7 +2501,7 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { String destVolumeName = null; if (destPrimaryStore.isManaged()) { if (!storagePoolMgr.connectPhysicalDisk(destPrimaryStore.getPoolType(), destPrimaryStore.getUuid(), destVolumePath, destPrimaryStore.getDetails())) { - s_logger.warn("Failed to connect dest volume at path: " + destVolumePath + ", in storage pool id: " + destPrimaryStore.getUuid()); + logger.warn("Failed to connect dest volume at path: " + destVolumePath + ", in storage pool id: " + destPrimaryStore.getUuid()); } destVolumeName = derivePath(destPrimaryStore, destData, destPrimaryStore.getDetails()); } else { @@ -2505,7 +2511,9 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { destPool = storagePoolMgr.getStoragePool(destPrimaryStore.getPoolType(), destPrimaryStore.getUuid()); try { - if (srcVol.getPassphrase() != null && srcVol.getVolumeType().equals(Volume.Type.ROOT)) { + Volume.Type volumeType = srcVol.getVolumeType(); + + if (srcVol.getPassphrase() != null && (Volume.Type.ROOT.equals(volumeType) || Volume.Type.DATADISK.equals(volumeType))) { volume.setQemuEncryptFormat(QemuObject.EncryptFormat.LUKS); storagePoolMgr.copyPhysicalDisk(volume, destVolumeName, destPool, cmd.getWaitInMillSeconds(), srcVol.getPassphrase(), destVol.getPassphrase(), srcVol.getProvisioningType()); } else { @@ -2513,7 +2521,7 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { } } catch (Exception e) { // Any exceptions while copying the disk, should send failed answer with the error message String errMsg = String.format("Failed to copy volume: %s to dest storage: %s, due to %s", srcVol.getName(), destPrimaryStore.getName(), e.toString()); - s_logger.debug(errMsg, e); + logger.debug(errMsg, e); throw new CloudRuntimeException(errMsg); } finally { if (srcPrimaryStore.isManaged()) { @@ -2532,7 +2540,7 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { newVol.setEncryptFormat(destVol.getEncryptFormat()); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to copyVolumeFromPrimaryToPrimary: ", e); + logger.debug("Failed to copyVolumeFromPrimaryToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { srcVol.clearPassphrase(); @@ -2554,7 +2562,7 @@ private boolean isLocationAccessible(String temporaryDownloadPath) { */ protected boolean isEnoughSpaceForDownloadTemplateOnTemporaryLocation(Long templateSize) { if (templateSize == null || templateSize == 0L) { - s_logger.info("The server did not provide the template size, assuming there is enough space to download it"); + logger.info("The server did not provide the template size, assuming there is enough space to download it"); return true; } String cmd = String.format("df --output=avail %s -B 1 | tail -1", resource.getDirectDownloadTemporaryDownloadPath()); @@ -2564,7 +2572,7 @@ protected boolean isEnoughSpaceForDownloadTemplateOnTemporaryLocation(Long templ availableBytes = Long.parseLong(resultInBytes); } catch (NumberFormatException e) { String msg = "Could not parse the output " + resultInBytes + " as a number, therefore not able to check for free space"; - s_logger.error(msg, e); + logger.error(msg, e); return false; } return availableBytes >= templateSize; @@ -2572,13 +2580,13 @@ protected boolean isEnoughSpaceForDownloadTemplateOnTemporaryLocation(Long templ @Override public Answer checkDataStoreStoragePolicyCompliance(CheckDataStoreStoragePolicyComplainceCommand cmd) { - s_logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not currently applicable for KVMStorageProcessor"); + logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not currently applicable for KVMStorageProcessor"); return new Answer(cmd,false,"Not currently applicable for KVMStorageProcessor"); } @Override public Answer syncVolumePath(SyncVolumePathCommand cmd) { - s_logger.info("SyncVolumePathCommand not currently applicable for KVMStorageProcessor"); + logger.info("SyncVolumePathCommand not currently applicable for KVMStorageProcessor"); return new Answer(cmd, false, "Not currently applicable for KVMStorageProcessor"); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index cad9d429969c..45a65037340d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -33,8 +33,9 @@ import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.commons.codec.binary.Base64; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; import org.libvirt.Secret; @@ -76,7 +77,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { - private static final Logger s_logger = Logger.getLogger(LibvirtStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private StorageLayer _storageLayer; private String _mountPoint = "/mnt"; private String _manageSnapshotPath; @@ -108,7 +109,7 @@ public boolean createFolder(String uuid, String path, String localPath) { String mountPoint = _mountPoint + File.separator + uuid; if (localPath != null) { - s_logger.debug(String.format("Pool [%s] is of type local or shared mount point; therefore, we will use the local path [%s] to create the folder [%s] (if it does not" + logger.debug(String.format("Pool [%s] is of type local or shared mount point; therefore, we will use the local path [%s] to create the folder [%s] (if it does not" + " exist).", uuid, localPath, path)); mountPoint = localPath; @@ -128,18 +129,18 @@ public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, S destPool.getType(), size, passphrase != null && passphrase.length > 0); if (!poolTypesThatEnableCreateDiskFromTemplateBacking.contains(destPool.getType())) { - s_logger.info(String.format("Skipping creation of %s due to pool type is none of the following types %s.", volumeDesc, poolTypesThatEnableCreateDiskFromTemplateBacking.stream() + logger.info(String.format("Skipping creation of %s due to pool type is none of the following types %s.", volumeDesc, poolTypesThatEnableCreateDiskFromTemplateBacking.stream() .map(type -> type.toString()).collect(Collectors.joining(", ")))); return null; } if (format != PhysicalDiskFormat.QCOW2) { - s_logger.info(String.format("Skipping creation of %s due to format [%s] is not [%s].", volumeDesc, format, PhysicalDiskFormat.QCOW2)); + logger.info(String.format("Skipping creation of %s due to format [%s] is not [%s].", volumeDesc, format, PhysicalDiskFormat.QCOW2)); return null; } - s_logger.info(String.format("Creating %s.", volumeDesc)); + logger.info(String.format("Creating %s.", volumeDesc)); String destPoolLocalPath = destPool.getLocalPath(); String destPath = String.format("%s%s%s", destPoolLocalPath, destPoolLocalPath.endsWith("/") ? "" : "/", name); @@ -154,13 +155,13 @@ public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, S if (keyFile.isSet()) { passphraseObjects.add(QemuObject.prepareSecretForQemuImg(format, QemuObject.EncryptFormat.LUKS, keyFile.toString(), "sec0", options)); } - s_logger.debug(String.format("Passphrase is staged to keyFile: %s", keyFile.isSet())); + logger.debug(String.format("Passphrase is staged to keyFile: %s", keyFile.isSet())); QemuImg qemu = new QemuImg(timeout); qemu.create(destFile, backingFile, options, passphraseObjects); } catch (QemuImgException | LibvirtException | IOException e) { // why don't we throw an exception here? I guess we fail to find the volume later and that results in a failure returned? - s_logger.error(String.format("Failed to create %s in [%s] due to [%s].", volumeDesc, destPath, e.getMessage()), e); + logger.error(String.format("Failed to create %s in [%s] due to [%s].", volumeDesc, destPath, e.getMessage()), e); } return null; @@ -230,7 +231,7 @@ public StorageVol getVolume(StoragePool pool, String volName) { try { vol = pool.storageVolLookupByName(volName); } catch (LibvirtException e) { - s_logger.debug("Could not find volume " + volName + ": " + e.getMessage()); + logger.debug("Could not find volume " + volName + ": " + e.getMessage()); } /** @@ -240,15 +241,15 @@ public StorageVol getVolume(StoragePool pool, String volName) { */ if (vol == null) { try { - s_logger.debug("Refreshing storage pool " + pool.getName()); + logger.debug("Refreshing storage pool " + pool.getName()); refreshPool(pool); } catch (LibvirtException e) { - s_logger.debug("Failed to refresh storage pool: " + e.getMessage()); + logger.debug("Failed to refresh storage pool: " + e.getMessage()); } try { vol = pool.storageVolLookupByName(volName); - s_logger.debug("Found volume " + volName + " in storage pool " + pool.getName() + " after refreshing the pool"); + logger.debug("Found volume " + volName + " in storage pool " + pool.getName() + " after refreshing the pool"); } catch (LibvirtException e) { throw new CloudRuntimeException("Could not find volume " + volName + ": " + e.getMessage()); } @@ -259,7 +260,7 @@ public StorageVol getVolume(StoragePool pool, String volName) { public StorageVol createVolume(Connect conn, StoragePool pool, String uuid, long size, VolumeFormat format) throws LibvirtException { LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), size, format, null, null); - s_logger.debug(volDef.toString()); + logger.debug(volDef.toString()); return pool.storageVolCreateXML(volDef.toString(), 0); } @@ -270,7 +271,7 @@ public void storagePoolRefresh(StoragePool pool) { refreshPool(pool); } } catch (LibvirtException e) { - s_logger.debug("refresh storage pool failed: " + e.toString()); + logger.debug("refresh storage pool failed: " + e.toString()); } } @@ -279,7 +280,7 @@ private void checkNetfsStoragePoolMounted(String uuid) { int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath); if (mountpointResult != 0) { String errMsg = String.format("libvirt failed to mount storage pool %s at %s", uuid, targetPath); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } @@ -290,24 +291,24 @@ private StoragePool createNetfsStoragePool(PoolType fsType, Connect conn, String _storageLayer.mkdir(targetPath); StoragePool sp = null; try { - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); // check whether the pool is already mounted int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath); // if the pool is mounted, try to unmount it if(mountpointResult == 0) { - s_logger.info("Attempting to unmount old mount at " + targetPath); + logger.info("Attempting to unmount old mount at " + targetPath); String result = Script.runSimpleBashScript("umount -l " + targetPath); if (result == null) { - s_logger.info("Succeeded in unmounting " + targetPath); + logger.info("Succeeded in unmounting " + targetPath); } else { - s_logger.error("Failed in unmounting storage"); + logger.error("Failed in unmounting storage"); } } sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { - s_logger.error(e.toString()); + logger.error(e.toString()); throw e; } } @@ -315,17 +316,17 @@ private StoragePool createNetfsStoragePool(PoolType fsType, Connect conn, String private StoragePool createSharedStoragePool(Connect conn, String uuid, String host, String path) { String mountPoint = path; if (!_storageLayer.exists(mountPoint)) { - s_logger.error(mountPoint + " does not exists. Check local.storage.path in agent.properties."); + logger.error(mountPoint + " does not exists. Check local.storage.path in agent.properties."); return null; } LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.DIR, uuid, uuid, host, path, path); StoragePool sp = null; try { - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { - s_logger.error(e.toString()); + logger.error(e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { @@ -336,7 +337,7 @@ private StoragePool createSharedStoragePool(Connect conn, String uuid, String ho } sp.free(); } catch (LibvirtException l) { - s_logger.debug("Failed to define shared mount point storage pool with: " + l.toString()); + logger.debug("Failed to define shared mount point storage pool with: " + l.toString()); } } return null; @@ -349,14 +350,14 @@ private StoragePool createCLVMStoragePool(Connect conn, String uuid, String host String volgroupName = path; volgroupName = volgroupName.replaceFirst("/", ""); - LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.LOGICAL, volgroupName, uuid, host, volgroupPath, volgroupPath); + LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.loggerICAL, volgroupName, uuid, host, volgroupPath, volgroupPath); StoragePool sp = null; try { - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { - s_logger.error(e.toString()); + logger.error(e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { @@ -367,7 +368,7 @@ private StoragePool createCLVMStoragePool(Connect conn, String uuid, String host } sp.free(); } catch (LibvirtException l) { - s_logger.debug("Failed to define clvm storage pool with: " + l.toString()); + logger.debug("Failed to define clvm storage pool with: " + l.toString()); } } return null; @@ -406,7 +407,7 @@ private boolean destroyStoragePoolOnNFSMountOptionsChange(StoragePool sp, Connec return true; } } catch (LibvirtException e) { - s_logger.error("Failure in destroying the pre-existing storage pool for changing the NFS mount options" + e); + logger.error("Failure in destroying the pre-existing storage pool for changing the NFS mount options" + e); } return false; } @@ -424,17 +425,17 @@ private StoragePool createRBDStoragePool(Connect conn, String uuid, String host, sd.setCephName(userInfoTemp[0] + "@" + host + ":" + port + "/" + path); try { - s_logger.debug(sd.toString()); + logger.debug(sd.toString()); s = conn.secretDefineXML(sd.toString()); s.setValue(Base64.decodeBase64(userInfoTemp[1])); } catch (LibvirtException e) { - s_logger.error("Failed to define the libvirt secret: " + e.toString()); + logger.error("Failed to define the libvirt secret: " + e.toString()); if (s != null) { try { s.undefine(); s.free(); } catch (LibvirtException l) { - s_logger.error("Failed to undefine the libvirt secret: " + l.toString()); + logger.error("Failed to undefine the libvirt secret: " + l.toString()); } } return null; @@ -445,11 +446,11 @@ private StoragePool createRBDStoragePool(Connect conn, String uuid, String host, } try { - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { - s_logger.error("Failed to create RBD storage pool: " + e.toString()); + logger.error("Failed to create RBD storage pool: " + e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { @@ -460,17 +461,17 @@ private StoragePool createRBDStoragePool(Connect conn, String uuid, String host, } sp.free(); } catch (LibvirtException l) { - s_logger.error("Failed to undefine RBD storage pool: " + l.toString()); + logger.error("Failed to undefine RBD storage pool: " + l.toString()); } } if (s != null) { try { - s_logger.error("Failed to create the RBD storage pool, cleaning up the libvirt secret"); + logger.error("Failed to create the RBD storage pool, cleaning up the libvirt secret"); s.undefine(); s.free(); } catch (LibvirtException se) { - s_logger.error("Failed to remove the libvirt secret: " + se.toString()); + logger.error("Failed to remove the libvirt secret: " + se.toString()); } } @@ -507,6 +508,12 @@ public LibvirtStorageVolumeDef getStorageVolumeDef(Connect conn, StorageVol vol) return parser.parseStorageVolumeXML(volDefXML); } + @Override + public StoragePoolType getStoragePoolType() { + // This is mapped manually in KVMStoragePoolManager + return null; + } + @Override public KVMStoragePool getStoragePool(String uuid) { return this.getStoragePool(uuid, false); @@ -514,14 +521,14 @@ public KVMStoragePool getStoragePool(String uuid) { @Override public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) { - s_logger.info("Trying to fetch storage pool " + uuid + " from libvirt"); + logger.info("Trying to fetch storage pool " + uuid + " from libvirt"); StoragePool storage = null; try { Connect conn = LibvirtConnection.getConnection(); storage = conn.storagePoolLookupByUUIDString(uuid); if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { - s_logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it."); + logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it."); storage.create(0); } LibvirtStoragePoolDef spd = getStoragePoolDef(conn, storage); @@ -535,7 +542,7 @@ public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) { type = StoragePoolType.Filesystem; } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.RBD) { type = StoragePoolType.RBD; - } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.LOGICAL) { + } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.loggerICAL) { type = StoragePoolType.CLVM; } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.GLUSTERFS) { type = StoragePoolType.Gluster; @@ -577,21 +584,21 @@ public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) { * refresh the pool */ if (refreshInfo) { - s_logger.info("Asking libvirt to refresh storage pool " + uuid); + logger.info("Asking libvirt to refresh storage pool " + uuid); pool.refresh(); } pool.setCapacity(storage.getInfo().capacity); pool.setUsed(storage.getInfo().allocation); pool.setAvailable(storage.getInfo().available); - s_logger.debug("Successfully refreshed pool " + uuid + + logger.debug("Successfully refreshed pool " + uuid + " Capacity: " + toHumanReadableSize(storage.getInfo().capacity) + " Used: " + toHumanReadableSize(storage.getInfo().allocation) + " Available: " + toHumanReadableSize(storage.getInfo().available)); return pool; } catch (LibvirtException e) { - s_logger.debug("Could not find storage pool " + uuid + " in libvirt"); + logger.debug("Could not find storage pool " + uuid + " in libvirt"); throw new CloudRuntimeException(e.toString(), e); } } @@ -632,14 +639,14 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) { } return disk; } catch (LibvirtException e) { - s_logger.debug("Failed to get physical disk:", e); + logger.debug("Failed to get physical disk:", e); throw new CloudRuntimeException(e.toString()); } } @Override public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map details) { - s_logger.info("Attempting to create storage pool " + name + " (" + type.toString() + ") in libvirt"); + logger.info("Attempting to create storage pool " + name + " (" + type.toString() + ") in libvirt"); StoragePool sp = null; Connect conn = null; @@ -654,14 +661,14 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri if (sp != null && sp.isActive() == 0) { sp.undefine(); sp = null; - s_logger.info("Found existing defined storage pool " + name + ". It wasn't running, so we undefined it."); + logger.info("Found existing defined storage pool " + name + ". It wasn't running, so we undefined it."); } if (sp != null) { - s_logger.info("Found existing defined storage pool " + name + ", using it."); + logger.info("Found existing defined storage pool " + name + ", using it."); } } catch (LibvirtException e) { sp = null; - s_logger.warn("Storage pool " + name + " was not found running in libvirt. Need to create it."); + logger.warn("Storage pool " + name + " was not found running in libvirt. Need to create it."); } // libvirt strips trailing slashes off of path, we will too in order to match @@ -675,12 +682,12 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri // if anyone is, undefine the pool so we can define it as requested. // This should be safe since a pool in use can't be removed, and no // volumes are affected by unregistering the pool with libvirt. - s_logger.info("Didn't find an existing storage pool " + name + " by UUID, checking for pools with duplicate paths"); + logger.info("Didn't find an existing storage pool " + name + " by UUID, checking for pools with duplicate paths"); try { String[] poolnames = conn.listStoragePools(); for (String poolname : poolnames) { - s_logger.debug("Checking path of existing pool " + poolname + " against pool we want to create"); + logger.debug("Checking path of existing pool " + poolname + " against pool we want to create"); StoragePool p = conn.storagePoolLookupByName(poolname); LibvirtStoragePoolDef pdef = getStoragePoolDef(conn, p); if (pdef == null) { @@ -689,7 +696,7 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri String targetPath = pdef.getTargetPath(); if (targetPath != null && targetPath.equals(path)) { - s_logger.debug("Storage pool utilizing path '" + path + "' already exists as pool " + poolname + + logger.debug("Storage pool utilizing path '" + path + "' already exists as pool " + poolname + ", undefining so we can re-define with correct name " + name); if (p.isPersistent() == 1) { p.destroy(); @@ -700,7 +707,7 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri } } } catch (LibvirtException e) { - s_logger.error("Failure in attempting to see if an existing storage pool might be using the path of the pool to be created:" + e); + logger.error("Failure in attempting to see if an existing storage pool might be using the path of the pool to be created:" + e); } } @@ -712,22 +719,22 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri if (sp == null) { - s_logger.debug("Attempting to create storage pool " + name); + logger.debug("Attempting to create storage pool " + name); if (type == StoragePoolType.NetworkFilesystem) { try { sp = createNetfsStoragePool(PoolType.NETFS, conn, name, host, path, nfsMountOpts); } catch (LibvirtException e) { - s_logger.error("Failed to create netfs mount: " + host + ":" + path , e); - s_logger.error(e.getStackTrace()); + logger.error("Failed to create netfs mount: " + host + ":" + path , e); + logger.error(e.getStackTrace()); throw new CloudRuntimeException(e.toString()); } } else if (type == StoragePoolType.Gluster) { try { sp = createNetfsStoragePool(PoolType.GLUSTERFS, conn, name, host, path, null); } catch (LibvirtException e) { - s_logger.error("Failed to create glusterfs mount: " + host + ":" + path , e); - s_logger.error(e.getStackTrace()); + logger.error("Failed to create glusterfs mount: " + host + ":" + path , e); + logger.error(e.getStackTrace()); throw new CloudRuntimeException(e.toString()); } } else if (type == StoragePoolType.SharedMountPoint || type == StoragePoolType.Filesystem) { @@ -745,7 +752,7 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri try { if (sp.isActive() == 0) { - s_logger.debug("Attempting to activate pool " + name); + logger.debug("Attempting to activate pool " + name); sp.create(0); } @@ -771,8 +778,8 @@ private boolean destroyStoragePool(Connect conn, String uuid) throws LibvirtExce try { sp = conn.storagePoolLookupByUUIDString(uuid); } catch (LibvirtException exc) { - s_logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed"); - s_logger.warn(exc.getStackTrace()); + logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed"); + logger.warn(exc.getStackTrace()); return true; } @@ -787,7 +794,7 @@ private boolean destroyStoragePool(Connect conn, String uuid) throws LibvirtExce return true; } else { - s_logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed"); + logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed"); return false; } } @@ -797,15 +804,15 @@ private boolean destroyStoragePoolHandleException(Connect conn, String uuid) try { return destroyStoragePool(conn, uuid); } catch (LibvirtException e) { - s_logger.error(String.format("Failed to destroy libvirt pool %s: %s", uuid, e)); + logger.error(String.format("Failed to destroy libvirt pool %s: %s", uuid, e)); } return false; } @Override public boolean deleteStoragePool(String uuid) { - s_logger.info("Attempting to remove storage pool " + uuid + " from libvirt"); - Connect conn; + logger.info("Attempting to remove storage pool " + uuid + " from libvirt"); + Connect conn = null; try { conn = LibvirtConnection.getConnection(); } catch (LibvirtException e) { @@ -813,6 +820,7 @@ public boolean deleteStoragePool(String uuid) { } Secret s = null; + /* * Some storage pools, like RBD also have 'secret' information stored in libvirt * Destroy them if they exist @@ -820,7 +828,7 @@ public boolean deleteStoragePool(String uuid) { try { s = conn.secretLookupByUUIDString(uuid); } catch (LibvirtException e) { - s_logger.info("Storage pool " + uuid + " has no corresponding secret. Not removing any secret."); + logger.info("Storage pool " + uuid + " has no corresponding secret. Not removing any secret."); } try { @@ -830,22 +838,22 @@ public boolean deleteStoragePool(String uuid) { s.free(); } - s_logger.info("Storage pool " + uuid + " was successfully removed from libvirt."); + logger.info("Storage pool " + uuid + " was successfully removed from libvirt."); return true; } catch (LibvirtException e) { // handle ebusy error when pool is quickly destroyed if (e.toString().contains("exit status 16")) { String targetPath = _mountPoint + File.separator + uuid; - s_logger.error("deleteStoragePool removed pool from libvirt, but libvirt had trouble unmounting the pool. Trying umount location " + targetPath + + logger.error("deleteStoragePool removed pool from libvirt, but libvirt had trouble unmounting the pool. Trying umount location " + targetPath + " again in a few seconds"); String result = Script.runSimpleBashScript("sleep 5 && umount " + targetPath); if (result == null) { - s_logger.info("Succeeded in unmounting " + targetPath); + logger.info("Succeeded in unmounting " + targetPath); destroyStoragePoolHandleException(conn, uuid); return true; } - s_logger.error("Failed to unmount " + targetPath); + logger.error("Failed to unmount " + targetPath); } throw new CloudRuntimeException(e.toString(), e); } @@ -855,26 +863,25 @@ public boolean deleteStoragePool(String uuid) { public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, byte[] passphrase) { - s_logger.info("Attempting to create volume " + name + " (" + pool.getType().toString() + ") in pool " + logger.info("Attempting to create volume " + name + " (" + pool.getType().toString() + ") in pool " + pool.getUuid() + " with size " + toHumanReadableSize(size)); - switch (pool.getType()) { - case RBD: - return createPhysicalDiskByLibVirt(name, pool, PhysicalDiskFormat.RAW, provisioningType, size); - case NetworkFilesystem: - case Filesystem: - switch (format) { - case QCOW2: - case RAW: - return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size, passphrase); - case DIR: - case TAR: - return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); - default: - throw new CloudRuntimeException("Unexpected disk format is specified."); - } - default: - return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); + StoragePoolType poolType = pool.getType(); + if (poolType.equals(StoragePoolType.RBD)) { + return createPhysicalDiskByLibVirt(name, pool, PhysicalDiskFormat.RAW, provisioningType, size); + } else if (poolType.equals(StoragePoolType.NetworkFilesystem) || poolType.equals(StoragePoolType.Filesystem)) { + switch (format) { + case QCOW2: + case RAW: + return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size, passphrase); + case DIR: + case TAR: + return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); + default: + throw new CloudRuntimeException("Unexpected disk format is specified."); + } + } else { + return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); } } @@ -891,7 +898,7 @@ private KVMPhysicalDisk createPhysicalDiskByLibVirt(String name, KVMStoragePool LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name, size, libvirtformat, null, null); - s_logger.debug(volDef.toString()); + logger.debug(volDef.toString()); try { StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0); volPath = vol.getPath(); @@ -1012,7 +1019,7 @@ public boolean disconnectPhysicalDiskByPath(String localPath) { @Override public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.ImageFormat format) { - s_logger.info("Attempting to remove volume " + uuid + " from pool " + pool.getUuid()); + logger.info("Attempting to remove volume " + uuid + " from pool " + pool.getUuid()); /** * RBD volume can have snapshots and while they exist libvirt @@ -1022,48 +1029,48 @@ public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.Imag */ if (pool.getType() == StoragePoolType.RBD) { try { - s_logger.info("Unprotecting and Removing RBD snapshots of image " + pool.getSourceDir() + "/" + uuid + " prior to removing the image"); + logger.info("Unprotecting and Removing RBD snapshots of image " + pool.getSourceDir() + "/" + uuid + " prior to removing the image"); Rados r = new Rados(pool.getAuthUserName()); r.confSet("mon_host", pool.getSourceHost() + ":" + pool.getSourcePort()); r.confSet("key", pool.getAuthSecret()); r.confSet("client_mount_timeout", "30"); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); IoCTX io = r.ioCtxCreate(pool.getSourceDir()); Rbd rbd = new Rbd(io); RbdImage image = rbd.open(uuid); - s_logger.debug("Fetching list of snapshots of RBD image " + pool.getSourceDir() + "/" + uuid); + logger.debug("Fetching list of snapshots of RBD image " + pool.getSourceDir() + "/" + uuid); List snaps = image.snapList(); try { for (RbdSnapInfo snap : snaps) { if (image.snapIsProtected(snap.name)) { - s_logger.debug("Unprotecting snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name); + logger.debug("Unprotecting snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name); image.snapUnprotect(snap.name); } else { - s_logger.debug("Snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name + " is not protected."); + logger.debug("Snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name + " is not protected."); } - s_logger.debug("Removing snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name); + logger.debug("Removing snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name); image.snapRemove(snap.name); } - s_logger.info("Successfully unprotected and removed any remaining snapshots (" + snaps.size() + ") of " + logger.info("Successfully unprotected and removed any remaining snapshots (" + snaps.size() + ") of " + pool.getSourceDir() + "/" + uuid + " Continuing to remove the RBD image"); } catch (RbdException e) { - s_logger.error("Failed to remove snapshot with exception: " + e.toString() + + logger.error("Failed to remove snapshot with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); throw new CloudRuntimeException(e.toString() + " - " + ErrorCode.getErrorMessage(e.getReturnValue())); } finally { - s_logger.debug("Closing image and destroying context"); + logger.debug("Closing image and destroying context"); rbd.close(image); r.ioCtxDestroy(io); } } catch (RadosException e) { - s_logger.error("Failed to remove snapshot with exception: " + e.toString() + + logger.error("Failed to remove snapshot with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); throw new CloudRuntimeException(e.toString() + " - " + ErrorCode.getErrorMessage(e.getReturnValue())); } catch (RbdException e) { - s_logger.error("Failed to remove snapshot with exception: " + e.toString() + + logger.error("Failed to remove snapshot with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); throw new CloudRuntimeException(e.toString() + " - " + ErrorCode.getErrorMessage(e.getReturnValue())); } @@ -1072,7 +1079,7 @@ public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.Imag LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool; try { StorageVol vol = getVolume(libvirtPool.getPool(), uuid); - s_logger.debug("Instructing libvirt to remove volume " + uuid + " from pool " + pool.getUuid()); + logger.debug("Instructing libvirt to remove volume " + uuid + " from pool " + pool.getUuid()); if(Storage.ImageFormat.DIR.equals(format)){ deleteDirVol(libvirtPool, vol); } else { @@ -1098,7 +1105,7 @@ public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.Imag public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, String name, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, KVMStoragePool destPool, int timeout, byte[] passphrase) { - s_logger.info("Creating volume " + name + " from template " + template.getName() + " in pool " + destPool.getUuid() + + logger.info("Creating volume " + name + " from template " + template.getName() + " in pool " + destPool.getUuid() + " (" + destPool.getType().toString() + ") with size " + toHumanReadableSize(size)); KVMPhysicalDisk disk = null; @@ -1217,7 +1224,7 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template, QemuImg qemu = new QemuImg(timeout); qemu.convert(srcFile, destFile); } catch (QemuImgException | LibvirtException e) { - s_logger.error("Failed to create " + disk.getPath() + + logger.error("Failed to create " + disk.getPath() + " due to a failed executing of qemu-img: " + e.getMessage()); } } else { @@ -1233,14 +1240,14 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template, try { if ((srcPool.getSourceHost().equals(destPool.getSourceHost())) && (srcPool.getSourceDir().equals(destPool.getSourceDir()))) { /* We are on the same Ceph cluster, but we require RBD format 2 on the source image */ - s_logger.debug("Trying to perform a RBD clone (layering) since we are operating in the same storage pool"); + logger.debug("Trying to perform a RBD clone (layering) since we are operating in the same storage pool"); Rados r = new Rados(srcPool.getAuthUserName()); r.confSet("mon_host", srcPool.getSourceHost() + ":" + srcPool.getSourcePort()); r.confSet("key", srcPool.getAuthSecret()); r.confSet("client_mount_timeout", "30"); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); IoCTX io = r.ioCtxCreate(srcPool.getSourceDir()); Rbd rbd = new Rbd(io); @@ -1248,33 +1255,33 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template, if (srcImage.isOldFormat()) { /* The source image is RBD format 1, we have to do a regular copy */ - s_logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() + + logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() + " is RBD format 1. We have to perform a regular copy (" + toHumanReadableSize(disk.getVirtualSize()) + " bytes)"); rbd.create(disk.getName(), disk.getVirtualSize(), RBD_FEATURES, rbdOrder); RbdImage destImage = rbd.open(disk.getName()); - s_logger.debug("Starting to copy " + srcImage.getName() + " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir()); + logger.debug("Starting to copy " + srcImage.getName() + " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir()); rbd.copy(srcImage, destImage); - s_logger.debug("Finished copying " + srcImage.getName() + " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir()); + logger.debug("Finished copying " + srcImage.getName() + " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir()); rbd.close(destImage); } else { - s_logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() + logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() + " is RBD format 2. We will perform a RBD clone using snapshot " + rbdTemplateSnapName); /* The source image is format 2, we can do a RBD snapshot+clone (layering) */ - s_logger.debug("Checking if RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName() + logger.debug("Checking if RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName() + "@" + rbdTemplateSnapName + " exists prior to attempting a clone operation."); List snaps = srcImage.snapList(); - s_logger.debug("Found " + snaps.size() + " snapshots on RBD image " + srcPool.getSourceDir() + "/" + template.getName()); + logger.debug("Found " + snaps.size() + " snapshots on RBD image " + srcPool.getSourceDir() + "/" + template.getName()); boolean snapFound = false; for (RbdSnapInfo snap : snaps) { if (rbdTemplateSnapName.equals(snap.name)) { - s_logger.debug("RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName() + logger.debug("RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName() + "@" + rbdTemplateSnapName + " already exists."); snapFound = true; break; @@ -1282,20 +1289,20 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template, } if (!snapFound) { - s_logger.debug("Creating RBD snapshot " + rbdTemplateSnapName + " on image " + name); + logger.debug("Creating RBD snapshot " + rbdTemplateSnapName + " on image " + name); srcImage.snapCreate(rbdTemplateSnapName); - s_logger.debug("Protecting RBD snapshot " + rbdTemplateSnapName + " on image " + name); + logger.debug("Protecting RBD snapshot " + rbdTemplateSnapName + " on image " + name); srcImage.snapProtect(rbdTemplateSnapName); } rbd.clone(template.getName(), rbdTemplateSnapName, io, disk.getName(), RBD_FEATURES, rbdOrder); - s_logger.debug("Successfully cloned " + template.getName() + "@" + rbdTemplateSnapName + " to " + disk.getName()); + logger.debug("Successfully cloned " + template.getName() + "@" + rbdTemplateSnapName + " to " + disk.getName()); /* We also need to resize the image if the VM was deployed with a larger root disk size */ if (disk.getVirtualSize() > template.getVirtualSize()) { RbdImage diskImage = rbd.open(disk.getName()); diskImage.resize(disk.getVirtualSize()); rbd.close(diskImage); - s_logger.debug("Resized " + disk.getName() + " to " + toHumanReadableSize(disk.getVirtualSize())); + logger.debug("Resized " + disk.getName() + " to " + toHumanReadableSize(disk.getVirtualSize())); } } @@ -1304,21 +1311,21 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template, r.ioCtxDestroy(io); } else { /* The source pool or host is not the same Ceph cluster, we do a simple copy with Qemu-Img */ - s_logger.debug("Both the source and destination are RBD, but not the same Ceph cluster. Performing a copy"); + logger.debug("Both the source and destination are RBD, but not the same Ceph cluster. Performing a copy"); Rados rSrc = new Rados(srcPool.getAuthUserName()); rSrc.confSet("mon_host", srcPool.getSourceHost() + ":" + srcPool.getSourcePort()); rSrc.confSet("key", srcPool.getAuthSecret()); rSrc.confSet("client_mount_timeout", "30"); rSrc.connect(); - s_logger.debug("Successfully connected to source Ceph cluster at " + rSrc.confGet("mon_host")); + logger.debug("Successfully connected to source Ceph cluster at " + rSrc.confGet("mon_host")); Rados rDest = new Rados(destPool.getAuthUserName()); rDest.confSet("mon_host", destPool.getSourceHost() + ":" + destPool.getSourcePort()); rDest.confSet("key", destPool.getAuthSecret()); rDest.confSet("client_mount_timeout", "30"); rDest.connect(); - s_logger.debug("Successfully connected to source Ceph cluster at " + rDest.confGet("mon_host")); + logger.debug("Successfully connected to source Ceph cluster at " + rDest.confGet("mon_host")); IoCTX sIO = rSrc.ioCtxCreate(srcPool.getSourceDir()); Rbd sRbd = new Rbd(sIO); @@ -1326,14 +1333,14 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template, IoCTX dIO = rDest.ioCtxCreate(destPool.getSourceDir()); Rbd dRbd = new Rbd(dIO); - s_logger.debug("Creating " + disk.getName() + " on the destination cluster " + rDest.confGet("mon_host") + " in pool " + + logger.debug("Creating " + disk.getName() + " on the destination cluster " + rDest.confGet("mon_host") + " in pool " + destPool.getSourceDir()); dRbd.create(disk.getName(), disk.getVirtualSize(), RBD_FEATURES, rbdOrder); RbdImage srcImage = sRbd.open(template.getName()); RbdImage destImage = dRbd.open(disk.getName()); - s_logger.debug("Copying " + template.getName() + " from Ceph cluster " + rSrc.confGet("mon_host") + " to " + disk.getName() + logger.debug("Copying " + template.getName() + " from Ceph cluster " + rSrc.confGet("mon_host") + " to " + disk.getName() + " on cluster " + rDest.confGet("mon_host")); sRbd.copy(srcImage, destImage); @@ -1344,10 +1351,10 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template, rDest.ioCtxDestroy(dIO); } } catch (RadosException e) { - s_logger.error("Failed to perform a RADOS action on the Ceph cluster, the error was: " + e.getMessage()); + logger.error("Failed to perform a RADOS action on the Ceph cluster, the error was: " + e.getMessage()); disk = null; } catch (RbdException e) { - s_logger.error("Failed to perform a RBD action on the Ceph cluster, the error was: " + e.getMessage()); + logger.error("Failed to perform a RBD action on the Ceph cluster, the error was: " + e.getMessage()); disk = null; } } @@ -1409,7 +1416,7 @@ to support snapshots(backuped) as qcow2 files. */ String sourcePath = disk.getPath(); KVMPhysicalDisk newDisk; - s_logger.debug("copyPhysicalDisk: disk size:" + toHumanReadableSize(disk.getSize()) + ", virtualsize:" + toHumanReadableSize(disk.getVirtualSize())+" format:"+disk.getFormat()); + logger.debug("copyPhysicalDisk: disk size:" + toHumanReadableSize(disk.getSize()) + ", virtualsize:" + toHumanReadableSize(disk.getVirtualSize())+" format:"+disk.getFormat()); if (destPool.getType() != StoragePoolType.RBD) { if (disk.getFormat() == PhysicalDiskFormat.TAR) { newDisk = destPool.createPhysicalDisk(name, PhysicalDiskFormat.DIR, Storage.ProvisioningType.THIN, disk.getVirtualSize(), null); @@ -1465,12 +1472,12 @@ to support snapshots(backuped) as qcow2 files. */ newDisk.setVirtualSize(virtualSize); newDisk.setSize(virtualSize); } catch (QemuImgException | LibvirtException e) { - s_logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); + logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); newDisk = null; } } } catch (QemuImgException e) { - s_logger.error("Failed to fetch the information of file " + srcFile.getFileName() + " the error was: " + e.getMessage()); + logger.error("Failed to fetch the information of file " + srcFile.getFileName() + " the error was: " + e.getMessage()); newDisk = null; } } @@ -1479,7 +1486,7 @@ to support snapshots(backuped) as qcow2 files. */ * Using qemu-img we copy the QCOW2 disk to RAW (on RBD) directly. * To do so it's mandatory that librbd on the system is at least 0.67.7 (Ceph Dumpling) */ - s_logger.debug("The source image is not RBD, but the destination is. We will convert into RBD format 2"); + logger.debug("The source image is not RBD, but the destination is. We will convert into RBD format 2"); try { srcFile = new QemuImgFile(sourcePath, sourceFormat); String rbdDestPath = destPool.getSourceDir() + "/" + name; @@ -1490,9 +1497,9 @@ to support snapshots(backuped) as qcow2 files. */ rbdDestPath); destFile = new QemuImgFile(rbdDestFile, destFormat); - s_logger.debug("Starting copy from source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath); + logger.debug("Starting copy from source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath); qemu.convert(srcFile, destFile); - s_logger.debug("Successfully converted source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath); + logger.debug("Successfully converted source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath); /* We have to stat the RBD image to see how big it became afterwards */ Rados r = new Rados(destPool.getAuthUserName()); @@ -1500,7 +1507,7 @@ to support snapshots(backuped) as qcow2 files. */ r.confSet("key", destPool.getAuthSecret()); r.confSet("client_mount_timeout", "30"); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); IoCTX io = r.ioCtxCreate(destPool.getSourceDir()); Rbd rbd = new Rbd(io); @@ -1509,20 +1516,20 @@ to support snapshots(backuped) as qcow2 files. */ RbdImageInfo rbdInfo = image.stat(); newDisk.setSize(rbdInfo.size); newDisk.setVirtualSize(rbdInfo.size); - s_logger.debug("After copy the resulting RBD image " + rbdDestPath + " is " + toHumanReadableSize(rbdInfo.size) + " bytes long"); + logger.debug("After copy the resulting RBD image " + rbdDestPath + " is " + toHumanReadableSize(rbdInfo.size) + " bytes long"); rbd.close(image); r.ioCtxDestroy(io); } catch (QemuImgException | LibvirtException e) { String srcFilename = srcFile != null ? srcFile.getFileName() : null; String destFilename = destFile != null ? destFile.getFileName() : null; - s_logger.error(String.format("Failed to convert from %s to %s the error was: %s", srcFilename, destFilename, e.getMessage())); + logger.error(String.format("Failed to convert from %s to %s the error was: %s", srcFilename, destFilename, e.getMessage())); newDisk = null; } catch (RadosException e) { - s_logger.error("A Ceph RADOS operation failed (" + e.getReturnValue() + "). The error was: " + e.getMessage()); + logger.error("A Ceph RADOS operation failed (" + e.getReturnValue() + "). The error was: " + e.getMessage()); newDisk = null; } catch (RbdException e) { - s_logger.error("A Ceph RBD operation failed (" + e.getReturnValue() + "). The error was: " + e.getMessage()); + logger.error("A Ceph RBD operation failed (" + e.getReturnValue() + "). The error was: " + e.getMessage()); newDisk = null; } } else { @@ -1540,7 +1547,7 @@ to support snapshots(backuped) as qcow2 files. */ try { qemu.convert(srcFile, destFile); } catch (QemuImgException | LibvirtException e) { - s_logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); + logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); newDisk = null; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java index d81b40391d09..52adc59cbe7b 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java @@ -20,7 +20,8 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.joda.time.Duration; import org.libvirt.StoragePool; @@ -39,7 +40,7 @@ import com.cloud.utils.script.Script; public class LibvirtStoragePool implements KVMStoragePool { - private static final Logger s_logger = Logger.getLogger(LibvirtStoragePool.class); + protected Logger logger = LogManager.getLogger(getClass()); protected String uuid; protected long capacity; protected long used; @@ -149,19 +150,19 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUid) { if (disk != null) { return disk; } - s_logger.debug("find volume bypass libvirt volumeUid " + volumeUid); + logger.debug("find volume bypass libvirt volumeUid " + volumeUid); //For network file system or file system, try to use java file to find the volume, instead of through libvirt. BUG:CLOUDSTACK-4459 String localPoolPath = this.getLocalPath(); File f = new File(localPoolPath + File.separator + volumeUuid); if (!f.exists()) { - s_logger.debug("volume: " + volumeUuid + " not exist on storage pool"); + logger.debug("volume: " + volumeUuid + " not exist on storage pool"); throw new CloudRuntimeException("Can't find volume:" + volumeUuid); } disk = new KVMPhysicalDisk(f.getPath(), volumeUuid, this); disk.setFormat(PhysicalDiskFormat.QCOW2); disk.setSize(f.length()); disk.setVirtualSize(f.length()); - s_logger.debug("find volume bypass libvirt disk " + disk.toString()); + logger.debug("find volume bypass libvirt disk " + disk.toString()); return disk; } @@ -271,7 +272,7 @@ public boolean delete() { try { return this._storageAdaptor.deleteStoragePool(this); } catch (Exception e) { - s_logger.debug("Failed to delete storage pool", e); + logger.debug("Failed to delete storage pool", e); } return false; } @@ -309,7 +310,7 @@ public String getHearthBeatPath() { public String createHeartBeatCommand(HAStoragePool primaryStoragePool, String hostPrivateIp, boolean hostValidation) { - Script cmd = new Script(primaryStoragePool.getPool().getHearthBeatPath(), HeartBeatUpdateTimeout, s_logger); + Script cmd = new Script(primaryStoragePool.getPool().getHearthBeatPath(), HeartBeatUpdateTimeout, logger); cmd.add("-i", primaryStoragePool.getPoolIp()); cmd.add("-p", primaryStoragePool.getPoolMountSourcePath()); cmd.add("-m", primaryStoragePool.getMountDestPath()); @@ -339,7 +340,7 @@ public String getStorageNodeId() { public Boolean checkingHeartBeat(HAStoragePool pool, HostTO host) { boolean validResult = false; String hostIp = host.getPrivateNetwork().getIp(); - Script cmd = new Script(getHearthBeatPath(), HeartBeatCheckerTimeout, s_logger); + Script cmd = new Script(getHearthBeatPath(), HeartBeatCheckerTimeout, logger); cmd.add("-i", pool.getPoolIp()); cmd.add("-p", pool.getPoolMountSourcePath()); cmd.add("-m", pool.getMountDestPath()); @@ -350,11 +351,11 @@ public Boolean checkingHeartBeat(HAStoragePool pool, HostTO host) { String result = cmd.execute(parser); String parsedLine = parser.getLine(); - s_logger.debug(String.format("Checking heart beat with KVMHAChecker [{command=\"%s\", result: \"%s\", log: \"%s\", pool: \"%s\"}].", cmd.toString(), result, parsedLine, + logger.debug(String.format("Checking heart beat with KVMHAChecker [{command=\"%s\", result: \"%s\", log: \"%s\", pool: \"%s\"}].", cmd.toString(), result, parsedLine, pool.getPoolIp())); if (result == null && parsedLine.contains("DEAD")) { - s_logger.warn(String.format("Checking heart beat with KVMHAChecker command [%s] returned [%s]. [%s]. It may cause a shutdown of host IP [%s].", cmd.toString(), + logger.warn(String.format("Checking heart beat with KVMHAChecker command [%s] returned [%s]. [%s]. It may cause a shutdown of host IP [%s].", cmd.toString(), result, parsedLine, hostIp)); } else { validResult = true; @@ -364,7 +365,7 @@ public Boolean checkingHeartBeat(HAStoragePool pool, HostTO host) { @Override public Boolean vmActivityCheck(HAStoragePool pool, HostTO host, Duration activityScriptTimeout, String volumeUUIDListString, String vmActivityCheckPath, long duration) { - Script cmd = new Script(vmActivityCheckPath, activityScriptTimeout.getStandardSeconds(), s_logger); + Script cmd = new Script(vmActivityCheckPath, activityScriptTimeout.getStandardSeconds(), logger); cmd.add("-i", pool.getPoolIp()); cmd.add("-p", pool.getPoolMountSourcePath()); cmd.add("-m", pool.getMountDestPath()); @@ -377,10 +378,10 @@ public Boolean vmActivityCheck(HAStoragePool pool, HostTO host, Duration activit String result = cmd.execute(parser); String parsedLine = parser.getLine(); - s_logger.debug(String.format("Checking heart beat with KVMHAVMActivityChecker [{command=\"%s\", result: \"%s\", log: \"%s\", pool: \"%s\"}].", cmd.toString(), result, parsedLine, pool.getPoolIp())); + logger.debug(String.format("Checking heart beat with KVMHAVMActivityChecker [{command=\"%s\", result: \"%s\", log: \"%s\", pool: \"%s\"}].", cmd.toString(), result, parsedLine, pool.getPoolIp())); if (result == null && parsedLine.contains("DEAD")) { - s_logger.warn(String.format("Checking heart beat with KVMHAVMActivityChecker command [%s] returned [%s]. It is [%s]. It may cause a shutdown of host IP [%s].", cmd.toString(), result, parsedLine, host.getPrivateNetwork().getIp())); + logger.warn(String.format("Checking heart beat with KVMHAVMActivityChecker command [%s] returned [%s]. It is [%s]. It may cause a shutdown of host IP [%s].", cmd.toString(), result, parsedLine, host.getPrivateNetwork().getIp())); return false; } else { return true; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java index b23dd9a17904..8ec56b885f23 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java @@ -22,7 +22,8 @@ import java.util.Map; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.LibvirtException; import org.libvirt.StoragePool; @@ -44,7 +45,7 @@ import com.cloud.utils.script.Script; public class ManagedNfsStorageAdaptor implements StorageAdaptor { - private static final Logger s_logger = Logger.getLogger(ManagedNfsStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private String _mountPoint = "/mnt"; private StorageLayer _storageLayer; @@ -65,6 +66,9 @@ public KVMStoragePool createStoragePool(String uuid, String host, int port, Stri return storagePool; } + @Override + public StoragePoolType getStoragePoolType() { return StoragePoolType.ManagedNFS; } + @Override public KVMStoragePool getStoragePool(String uuid) { return getStoragePool(uuid, false); @@ -109,7 +113,7 @@ public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map MapStorageUuidToStoragePool = new HashMap<>(); /** @@ -569,7 +570,7 @@ static void cleanupStaleMaps() { synchronized(CLEANUP_LOCK) { long start = System.currentTimeMillis(); ScriptResult result = runScript(cleanupScript, cleanupTimeoutSecs * 1000); - LOGGER.debug("Multipath Cleanup Job elapsed time (ms): "+ (System.currentTimeMillis() - start) + "; result: " + result.getExitCode(), null); + LOGGER.debug("Multipath Cleanup Job elapsed time (ms): "+ (System.currentTimeMillis() - start) + "; result: " + result.getExitCode()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java index 60986f198a8b..b33f49404ad4 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java @@ -38,11 +38,11 @@ import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.commons.io.filefilter.WildcardFileFilter; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.LibvirtException; import com.cloud.storage.Storage; -import com.cloud.storage.StorageLayer; import com.cloud.storage.StorageManager; import com.cloud.utils.Pair; import com.cloud.utils.Ternary; @@ -51,28 +51,31 @@ import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; -@StorageAdaptorInfo(storagePoolType= Storage.StoragePoolType.PowerFlex) public class ScaleIOStorageAdaptor implements StorageAdaptor { - private static final Logger LOGGER = Logger.getLogger(ScaleIOStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final Map MapStorageUuidToStoragePool = new HashMap<>(); private static final int DEFAULT_DISK_WAIT_TIME_IN_SECS = 60; - private StorageLayer storageLayer; - public ScaleIOStorageAdaptor(StorageLayer storagelayer) { - storageLayer = storagelayer; + public ScaleIOStorageAdaptor() { + } @Override public KVMStoragePool getStoragePool(String uuid) { KVMStoragePool pool = MapStorageUuidToStoragePool.get(uuid); if (pool == null) { - LOGGER.error("Pool: " + uuid + " not found, probably sdc not connected on agent start"); + logger.error("Pool: " + uuid + " not found, probably sdc not connected on agent start"); throw new CloudRuntimeException("Pool: " + uuid + " not found, reconnect sdc and restart agent if sdc not connected on agent start"); } return pool; } + @Override + public Storage.StoragePoolType getStoragePoolType() { + return Storage.StoragePoolType.PowerFlex; + } + @Override public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) { return getStoragePool(uuid); @@ -81,7 +84,7 @@ public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) { @Override public KVMPhysicalDisk getPhysicalDisk(String volumePath, KVMStoragePool pool) { if (StringUtils.isEmpty(volumePath) || pool == null) { - LOGGER.error("Unable to get physical disk, volume path or pool not specified"); + logger.error("Unable to get physical disk, volume path or pool not specified"); return null; } @@ -96,18 +99,18 @@ public KVMPhysicalDisk getPhysicalDisk(String volumePath, KVMStoragePool pool) { diskFilePath = ScaleIOUtil.DISK_PATH + File.separator + diskFileName; final File diskFile = new File(diskFilePath); if (!diskFile.exists()) { - LOGGER.debug("Physical disk file: " + diskFilePath + " doesn't exists on the storage pool: " + pool.getUuid()); + logger.debug("Physical disk file: " + diskFilePath + " doesn't exists on the storage pool: " + pool.getUuid()); return null; } } else { - LOGGER.debug("Try with wildcard filter to get the physical disk: " + volumeId + " on the storage pool: " + pool.getUuid()); + logger.debug("Try with wildcard filter to get the physical disk: " + volumeId + " on the storage pool: " + pool.getUuid()); final File dir = new File(ScaleIOUtil.DISK_PATH); final FileFilter fileFilter = new WildcardFileFilter(ScaleIOUtil.DISK_NAME_PREFIX_FILTER + volumeId); final File[] files = dir.listFiles(fileFilter); if (files != null && files.length == 1) { diskFilePath = files[0].getAbsolutePath(); } else { - LOGGER.debug("Unable to find the physical disk: " + volumeId + " on the storage pool: " + pool.getUuid()); + logger.debug("Unable to find the physical disk: " + volumeId + " on the storage pool: " + pool.getUuid()); return null; } } @@ -137,7 +140,7 @@ public KVMPhysicalDisk getPhysicalDisk(String volumePath, KVMStoragePool pool) { return disk; } catch (Exception e) { - LOGGER.error("Failed to get the physical disk: " + volumePath + " on the storage pool: " + pool.getUuid() + " due to " + e.getMessage()); + logger.error("Failed to get the physical disk: " + volumePath + " on the storage pool: " + pool.getUuid() + " due to " + e.getMessage()); throw new CloudRuntimeException("Failed to get the physical disk: " + volumePath + " on the storage pool: " + pool.getUuid()); } } @@ -202,7 +205,7 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Qemu qemuObjects.add(QemuObject.prepareSecretForQemuImg(disk.getFormat(), disk.getQemuEncryptFormat(), keyFile.toString(), "sec0", options)); QemuImgFile file = new QemuImgFile(disk.getPath(), formattedSize, disk.getFormat()); qemuImg.create(file, null, options, qemuObjects); - LOGGER.debug(String.format("Successfully formatted %s as encrypted QCOW2", file.getFileName())); + logger.debug(String.format("Successfully formatted %s as encrypted QCOW2", file.getFileName())); } catch (QemuImgException | LibvirtException | IOException ex) { throw new CloudRuntimeException("Failed to set up encrypted QCOW on block device " + disk.getPath(), ex); } @@ -223,7 +226,7 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Qemu @Override public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map details) { if (StringUtils.isEmpty(volumePath) || pool == null) { - LOGGER.error("Unable to connect physical disk due to insufficient data"); + logger.error("Unable to connect physical disk due to insufficient data"); throw new CloudRuntimeException("Unable to connect physical disk due to insufficient data"); } @@ -240,7 +243,7 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map 0) { physicalDisk = getPhysicalDisk(volumePath, pool); if (physicalDisk != null && physicalDisk.getSize() > 0) { - LOGGER.debug("Found the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid()); + logger.debug("Found the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid()); return true; } @@ -265,11 +268,11 @@ private boolean waitForDiskToBecomeAvailable(String volumePath, KVMStoragePool p physicalDisk = getPhysicalDisk(volumePath, pool); if (physicalDisk != null && physicalDisk.getSize() > 0) { - LOGGER.debug("Found the volume using id: " + volumePath + " of the storage pool: " + pool.getUuid()); + logger.debug("Found the volume using id: " + volumePath + " of the storage pool: " + pool.getUuid()); return true; } - LOGGER.debug("Unable to find the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid()); + logger.debug("Unable to find the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid()); return false; } @@ -278,17 +281,17 @@ private long getPhysicalDiskSize(String diskPath) { return 0; } - Script diskCmd = new Script("blockdev", LOGGER); + Script diskCmd = new Script("blockdev", logger); diskCmd.add("--getsize64", diskPath); OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); String result = diskCmd.execute(parser); if (result != null) { - LOGGER.warn("Unable to get the disk size at path: " + diskPath); + logger.warn("Unable to get the disk size at path: " + diskPath); return 0; } else { - LOGGER.info("Able to retrieve the disk size at path:" + diskPath); + logger.info("Able to retrieve the disk size at path:" + diskPath); } return Long.parseLong(parser.getLine()); @@ -337,7 +340,7 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt @Override public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMStoragePool destPool, int timeout, byte[] srcPassphrase, byte[]dstPassphrase, Storage.ProvisioningType provisioningType) { if (StringUtils.isEmpty(name) || disk == null || destPool == null) { - LOGGER.error("Unable to copy physical disk due to insufficient data"); + logger.error("Unable to copy physical disk due to insufficient data"); throw new CloudRuntimeException("Unable to copy physical disk due to insufficient data"); } @@ -345,11 +348,11 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt provisioningType = Storage.ProvisioningType.THIN; } - LOGGER.debug("Copy physical disk with size: " + disk.getSize() + ", virtualsize: " + disk.getVirtualSize()+ ", format: " + disk.getFormat()); + logger.debug("Copy physical disk with size: " + disk.getSize() + ", virtualsize: " + disk.getVirtualSize()+ ", format: " + disk.getFormat()); KVMPhysicalDisk destDisk = destPool.getPhysicalDisk(name); if (destDisk == null) { - LOGGER.error("Failed to find the disk: " + name + " of the storage pool: " + destPool.getUuid()); + logger.error("Failed to find the disk: " + name + " of the storage pool: " + destPool.getUuid()); throw new CloudRuntimeException("Failed to find the disk: " + name + " of the storage pool: " + destPool.getUuid()); } @@ -400,33 +403,33 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt } boolean forceSourceFormat = srcQemuFile.getFormat() == QemuImg.PhysicalDiskFormat.RAW; - LOGGER.debug(String.format("Starting copy from source disk %s(%s) to PowerFlex volume %s(%s), forcing source format is %b", srcQemuFile.getFileName(), srcQemuFile.getFormat(), destQemuFile.getFileName(), destQemuFile.getFormat(), forceSourceFormat)); + logger.debug(String.format("Starting copy from source disk %s(%s) to PowerFlex volume %s(%s), forcing source format is %b", srcQemuFile.getFileName(), srcQemuFile.getFormat(), destQemuFile.getFileName(), destQemuFile.getFormat(), forceSourceFormat)); qemuImageOpts.setImageOptsFlag(true); qemu.convert(srcQemuFile, destQemuFile, options, qemuObjects, qemuImageOpts,null, forceSourceFormat); - LOGGER.debug("Successfully converted source disk image " + srcQemuFile.getFileName() + " to PowerFlex volume: " + destDisk.getPath()); + logger.debug("Successfully converted source disk image " + srcQemuFile.getFileName() + " to PowerFlex volume: " + destDisk.getPath()); if (destQemuFile.getFormat() == QemuImg.PhysicalDiskFormat.QCOW2 && !disk.useAsTemplate()) { QemuImageOptions resizeOptions = new QemuImageOptions(destQemuFile.getFormat(), destPath, destKeyName); resizeQcow2ToVolume(destPath, resizeOptions, qemuObjects, timeout); - LOGGER.debug("Resized volume at " + destPath); + logger.debug("Resized volume at " + destPath); } } catch (QemuImgException | LibvirtException | IOException e) { try { Map srcInfo = qemu.info(srcQemuFile); - LOGGER.debug("Source disk info: " + Arrays.asList(srcInfo)); + logger.debug("Source disk info: " + Arrays.asList(srcInfo)); } catch (Exception ignored) { - LOGGER.warn("Unable to get info from source disk: " + disk.getName()); + logger.warn("Unable to get info from source disk: " + disk.getName()); } String errMsg = String.format("Unable to convert/copy from %s to %s, due to: %s", disk.getName(), name, ((StringUtils.isEmpty(e.getMessage())) ? "an unknown error" : e.getMessage())); - LOGGER.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg, e); } finally { if (cryptSetup != null) { try { cryptSetup.close(name); } catch (CryptSetupException ex) { - LOGGER.warn("Failed to clean up LUKS disk after copying disk", ex); + logger.warn("Failed to clean up LUKS disk after copying disk", ex); } } } @@ -464,11 +467,11 @@ public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, S @Override public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFilePath, String destTemplatePath, KVMStoragePool destPool, Storage.ImageFormat format, int timeout) { if (StringUtils.isAnyEmpty(templateFilePath, destTemplatePath) || destPool == null) { - LOGGER.error("Unable to create template from direct download template file due to insufficient data"); + logger.error("Unable to create template from direct download template file due to insufficient data"); throw new CloudRuntimeException("Unable to create template from direct download template file due to insufficient data"); } - LOGGER.debug("Create template from direct download template - file path: " + templateFilePath + ", dest path: " + destTemplatePath + ", format: " + format.toString()); + logger.debug("Create template from direct download template - file path: " + templateFilePath + ", dest path: " + destTemplatePath + ", format: " + format.toString()); File sourceFile = new File(templateFilePath); if (!sourceFile.exists()) { @@ -476,7 +479,7 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP } if (destTemplatePath == null || destTemplatePath.isEmpty()) { - LOGGER.error("Failed to create template, target template disk path not provided"); + logger.error("Failed to create template, target template disk path not provided"); throw new CloudRuntimeException("Target template disk path not provided"); } @@ -485,7 +488,7 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP } if (Storage.ImageFormat.RAW.equals(format) && Storage.ImageFormat.QCOW2.equals(format)) { - LOGGER.error("Failed to create template, unsupported template format: " + format.toString()); + logger.error("Failed to create template, unsupported template format: " + format.toString()); throw new CloudRuntimeException("Unsupported template format: " + format.toString()); } @@ -497,13 +500,13 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP QemuImg qemu = new QemuImg(timeout, true, false); destDisk = destPool.getPhysicalDisk(destTemplatePath); if (destDisk == null) { - LOGGER.error("Failed to find the disk: " + destTemplatePath + " of the storage pool: " + destPool.getUuid()); + logger.error("Failed to find the disk: " + destTemplatePath + " of the storage pool: " + destPool.getUuid()); throw new CloudRuntimeException("Failed to find the disk: " + destTemplatePath + " of the storage pool: " + destPool.getUuid()); } if (isTemplateExtractable(templateFilePath)) { srcTemplateFilePath = sourceFile.getParent() + "/" + UUID.randomUUID().toString(); - LOGGER.debug("Extract the downloaded template " + templateFilePath + " to " + srcTemplateFilePath); + logger.debug("Extract the downloaded template " + templateFilePath + " to " + srcTemplateFilePath); String extractCommand = getExtractCommandForDownloadedFile(templateFilePath, srcTemplateFilePath); Script.runSimpleBashScript(extractCommand); Script.runSimpleBashScript("rm -f " + templateFilePath); @@ -526,12 +529,12 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP destFile = new QemuImgFile(destDisk.getPath(), QemuImg.PhysicalDiskFormat.QCOW2); destFile.setSize(srcFile.getSize()); - LOGGER.debug("Starting copy from source downloaded template " + srcFile.getFileName() + " to PowerFlex template volume: " + destDisk.getPath()); + logger.debug("Starting copy from source downloaded template " + srcFile.getFileName() + " to PowerFlex template volume: " + destDisk.getPath()); qemu.create(destFile); qemu.convert(srcFile, destFile); - LOGGER.debug("Successfully converted source downloaded template " + srcFile.getFileName() + " to PowerFlex template volume: " + destDisk.getPath()); + logger.debug("Successfully converted source downloaded template " + srcFile.getFileName() + " to PowerFlex template volume: " + destDisk.getPath()); } catch (QemuImgException | LibvirtException e) { - LOGGER.error("Failed to convert. The error was: " + e.getMessage(), e); + logger.error("Failed to convert. The error was: " + e.getMessage(), e); destDisk = null; } finally { Script.runSimpleBashScript("rm -f " + srcTemplateFilePath); @@ -566,12 +569,12 @@ public void resizeQcow2ToVolume(String volumePath, QemuImageOptions options, Lis public Ternary, String> prepareStorageClient(Storage.StoragePoolType type, String uuid, Map details) { if (!ScaleIOUtil.isSDCServiceInstalled()) { - LOGGER.debug("SDC service not installed on host, preparing the SDC client not possible"); + logger.debug("SDC service not installed on host, preparing the SDC client not possible"); return new Ternary<>(false, null, "SDC service not installed on host"); } if (!ScaleIOUtil.isSDCServiceEnabled()) { - LOGGER.debug("SDC service not enabled on host, enabling it"); + logger.debug("SDC service not enabled on host, enabling it"); if (!ScaleIOUtil.enableSDCService()) { return new Ternary<>(false, null, "SDC service not enabled on host"); } @@ -590,12 +593,12 @@ public Ternary, String> prepareStorageClient(Storag public Pair unprepareStorageClient(Storage.StoragePoolType type, String uuid) { if (!ScaleIOUtil.isSDCServiceInstalled()) { - LOGGER.debug("SDC service not installed on host, no need to unprepare the SDC client"); + logger.debug("SDC service not installed on host, no need to unprepare the SDC client"); return new Pair<>(true, "SDC service not installed on host, no need to unprepare the SDC client"); } if (!ScaleIOUtil.isSDCServiceEnabled()) { - LOGGER.debug("SDC service not enabled on host, no need to unprepare the SDC client"); + logger.debug("SDC service not enabled on host, no need to unprepare the SDC client"); return new Pair<>(true, "SDC service not enabled on host, no need to unprepare the SDC client"); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java index 80e73e01a863..9a27d44ff924 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java @@ -29,6 +29,8 @@ public interface StorageAdaptor { + StoragePoolType getStoragePoolType(); + public KVMStoragePool getStoragePool(String uuid); // Get the storage pool from libvirt, but control if libvirt should refresh the pool (can take a long time) @@ -109,6 +111,13 @@ KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, */ KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFilePath, String destTemplatePath, KVMStoragePool destPool, Storage.ImageFormat format, int timeout); + /** + * Returns true if storage adaptor supports physical disk copy functionality. + */ + default boolean supportsPhysicalDiskCopy(StoragePoolType type) { + return StoragePoolType.PowerFlex == type; + } + /** * Prepares the storage client. * @param type type of the storage pool diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptorInfo.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptorInfo.java index fce976535f65..8d4b0c60a860 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptorInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptorInfo.java @@ -22,10 +22,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import com.cloud.storage.Storage.StoragePoolType; - @Retention(RetentionPolicy.RUNTIME) @Target({ TYPE }) public @interface StorageAdaptorInfo { - StoragePoolType storagePoolType(); } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index 14922727d34d..81daabf59d76 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.kvm.ha; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.host.Host; import com.cloud.hypervisor.Hypervisor; @@ -33,14 +34,11 @@ import org.apache.cloudstack.ha.provider.host.HAAbstractHostProvider; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement.PowerOperation; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService; -import org.apache.log4j.Logger; import org.joda.time.DateTime; import javax.inject.Inject; -import java.security.InvalidParameterException; public final class KVMHAProvider extends HAAbstractHostProvider implements HAProvider, Configurable { - private final static Logger LOG = Logger.getLogger(KVMHAProvider.class); @Inject protected KVMHostActivityChecker hostActivityChecker; @@ -75,11 +73,11 @@ public boolean recover(Host r) throws HARecoveryException { final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.RESET, null); return resp.getSuccess(); } else { - LOG.warn("OOBM recover operation failed for the host " + r.getName()); + logger.warn("OOBM recover operation failed for the host " + r.getName()); return false; } } catch (Exception e){ - LOG.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); + logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); throw new HARecoveryException(" OOBM service is not configured or enabled for this host " + r.getName(), e); } } @@ -92,11 +90,11 @@ public boolean fence(Host r) throws HAFenceException { final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null); return resp.getSuccess(); } else { - LOG.warn("OOBM fence operation failed for this host " + r.getName()); + logger.warn("OOBM fence operation failed for this host " + r.getName()); return false; } } catch (Exception e){ - LOG.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); + logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName() , e); } } @@ -131,7 +129,7 @@ public Object getConfigValue(final HAProviderConfig name, final Host host) { case MaxDegradedWaitTimeout: return KVMHAConfig.KvmHADegradedMaxPeriod.valueIn(clusterId); default: - throw new InvalidParameterException("Unknown HAProviderConfig " + name.toString()); + throw new InvalidParameterValueException("Unknown HAProviderConfig " + name.toString()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java index 0866d668a439..10d684bbdd32 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java @@ -42,7 +42,6 @@ import org.apache.cloudstack.ha.provider.HealthCheckerInterface; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.commons.lang.ArrayUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -51,7 +50,6 @@ import java.util.List; public class KVMHostActivityChecker extends AdapterBase implements ActivityCheckerInterface, HealthCheckerInterface { - private final static Logger LOG = Logger.getLogger(KVMHostActivityChecker.class); @Inject private VolumeDao volumeDao; @@ -75,7 +73,7 @@ public boolean isActive(Host r, DateTime suspectTime) throws HACheckerException throw e; } catch (Exception e){ String message = String.format("Operation timed out, probably the %s is not reachable.", r.toString()); - LOG.warn(message, e); + logger.warn(message, e); throw new HACheckerException(message, e); } } @@ -93,22 +91,22 @@ private boolean isAgentActive(Host agent) { Status neighbourStatus = Status.Unknown; final CheckOnHostCommand cmd = new CheckOnHostCommand(agent, HighAvailabilityManager.KvmHAFenceHostIfHeartbeatFailsOnStorage.value()); try { - LOG.debug(String.format("Checking %s status...", agent.toString())); + logger.debug(String.format("Checking %s status...", agent.toString())); Answer answer = agentMgr.easySend(agent.getId(), cmd); if (answer != null) { hostStatus = answer.getResult() ? Status.Down : Status.Up; - LOG.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus)); + logger.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus)); if ( hostStatus == Status.Up ){ return true; } } else { - LOG.debug(String.format("Setting %s to \"Disconnected\" status.", agent.toString())); + logger.debug(String.format("Setting %s to \"Disconnected\" status.", agent.toString())); hostStatus = Status.Disconnected; } } catch (Exception e) { - LOG.warn(String.format("Failed to send command CheckOnHostCommand to %s.", agent.toString()), e); + logger.warn(String.format("Failed to send command CheckOnHostCommand to %s.", agent.toString()), e); } List neighbors = resourceManager.listHostsInClusterByStatus(agent.getClusterId(), Status.Up); @@ -118,22 +116,22 @@ private boolean isAgentActive(Host agent) { } try { - LOG.debug(String.format("Investigating %s via neighbouring %s.", agent.toString(), neighbor.toString())); + logger.debug(String.format("Investigating %s via neighbouring %s.", agent.toString(), neighbor.toString())); Answer answer = agentMgr.easySend(neighbor.getId(), cmd); if (answer != null) { neighbourStatus = answer.getResult() ? Status.Down : Status.Up; - LOG.debug(String.format("Neighbouring %s returned status [%s] for the investigated %s.", neighbor.toString(), neighbourStatus, agent.toString())); + logger.debug(String.format("Neighbouring %s returned status [%s] for the investigated %s.", neighbor.toString(), neighbourStatus, agent.toString())); if (neighbourStatus == Status.Up) { break; } } else { - LOG.debug(String.format("Neighbouring %s is Disconnected.", neighbor.toString())); + logger.debug(String.format("Neighbouring %s is Disconnected.", neighbor.toString())); } } catch (Exception e) { - LOG.warn(String.format("Failed to send command CheckOnHostCommand to %s.", neighbor.toString()), e); + logger.warn(String.format("Failed to send command CheckOnHostCommand to %s.", neighbor.toString()), e); } } if (neighbourStatus == Status.Up && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) { @@ -143,7 +141,7 @@ private boolean isAgentActive(Host agent) { hostStatus = Status.Down; } - LOG.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus)); + logger.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus)); return hostStatus == Status.Up; } @@ -157,7 +155,7 @@ private boolean isVMActivtyOnHost(Host agent, DateTime suspectTime) throws HAChe for (StoragePool pool : poolVolMap.keySet()) { activityStatus = verifyActivityOfStorageOnHost(poolVolMap, pool, agent, suspectTime, activityStatus); if (!activityStatus) { - LOG.warn(String.format("It seems that the storage pool [%s] does not have activity on %s.", pool.getId(), agent.toString())); + logger.warn(String.format("It seems that the storage pool [%s] does not have activity on %s.", pool.getId(), agent.toString())); break; } } @@ -169,21 +167,21 @@ protected boolean verifyActivityOfStorageOnHost(HashMap volume_list = poolVolMap.get(pool); final CheckVMActivityOnStoragePoolCommand cmd = new CheckVMActivityOnStoragePoolCommand(agent, pool, volume_list, suspectTime); - LOG.debug(String.format("Checking VM activity for %s on storage pool [%s].", agent.toString(), pool.getId())); + logger.debug(String.format("Checking VM activity for %s on storage pool [%s].", agent.toString(), pool.getId())); try { Answer answer = storageManager.sendToPool(pool, getNeighbors(agent), cmd); if (answer != null) { activityStatus = !answer.getResult(); - LOG.debug(String.format("%s %s activity on storage pool [%s]", agent.toString(), activityStatus ? "has" : "does not have", pool.getId())); + logger.debug(String.format("%s %s activity on storage pool [%s]", agent.toString(), activityStatus ? "has" : "does not have", pool.getId())); } else { String message = String.format("Did not get a valid response for VM activity check for %s on storage pool [%s].", agent.toString(), pool.getId()); - LOG.debug(message); + logger.debug(message); throw new IllegalStateException(message); } } catch (StorageUnavailableException e){ String message = String.format("Storage [%s] is unavailable to do the check, probably the %s is not reachable.", pool.getId(), agent.toString()); - LOG.warn(message, e); + logger.warn(message, e); throw new HACheckerException(message, e); } return activityStatus; @@ -193,14 +191,14 @@ private HashMap> getVolumeUuidOnHost(Host agent) { List vm_list = vmInstanceDao.listByHostId(agent.getId()); List volume_list = new ArrayList(); for (VirtualMachine vm : vm_list) { - LOG.debug(String.format("Retrieving volumes of VM [%s]...", vm.getId())); + logger.debug(String.format("Retrieving volumes of VM [%s]...", vm.getId())); List vm_volume_list = volumeDao.findByInstance(vm.getId()); volume_list.addAll(vm_volume_list); } HashMap> poolVolMap = new HashMap>(); for (Volume vol : volume_list) { - LOG.debug(String.format("Retrieving storage pool [%s] of volume [%s]...", vol.getPoolId(), vol.getId())); + logger.debug(String.format("Retrieving storage pool [%s] of volume [%s]...", vol.getPoolId(), vol.getId())); StoragePool sp = storagePool.findById(vol.getPoolId()); if (!poolVolMap.containsKey(sp)) { List list = new ArrayList(); @@ -217,7 +215,7 @@ private HashMap> getVolumeUuidOnHost(Host agent) { public long[] getNeighbors(Host agent) { List neighbors = new ArrayList(); List cluster_hosts = resourceManager.listHostsInClusterByStatus(agent.getClusterId(), Status.Up); - LOG.debug(String.format("Retrieving all \"Up\" hosts from cluster [%s]...", agent.getClusterId())); + logger.debug(String.format("Retrieving all \"Up\" hosts from cluster [%s]...", agent.getClusterId())); for (HostVO host : cluster_hosts) { if (host.getId() == agent.getId() || (host.getHypervisorType() != Hypervisor.HypervisorType.KVM && host.getHypervisorType() != Hypervisor.HypervisorType.LXC)) { continue; diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/CPUStat.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/CPUStat.java index d180d013a242..9dd14b1b510d 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/CPUStat.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/CPUStat.java @@ -21,10 +21,11 @@ import java.io.FileNotFoundException; import java.util.Scanner; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class CPUStat { - private static final Logger s_logger = Logger.getLogger(CPUStat.class); + protected Logger logger = LogManager.getLogger(getClass()); private Integer _cores; private UptimeStats _lastStats; @@ -58,7 +59,7 @@ private UptimeStats getUptimeAndCpuIdleTime() { String[] stats = scanner.useDelimiter("\\Z").next().split("\\s+"); uptime = new UptimeStats(Double.parseDouble(stats[0]), Double.parseDouble(stats[1])); } catch (FileNotFoundException ex) { - s_logger.warn("File " + _uptimeFile + " not found:" + ex.toString()); + logger.warn("File " + _uptimeFile + " not found:" + ex.toString()); } return uptime; } @@ -87,7 +88,7 @@ public Double getCpuLoadAverage() { try (Scanner scanner = new Scanner(f,"UTF-8");) { load = scanner.useDelimiter("\\Z").next().split("\\s+"); } catch (FileNotFoundException ex) { - s_logger.warn("File " + _uptimeFile + " not found:" + ex.toString()); + logger.warn("File " + _uptimeFile + " not found:" + ex.toString()); } return Double.parseDouble(load[0]); } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index 21da711a9cb9..c0b416410cbc 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -29,7 +29,8 @@ import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.LibvirtException; import org.libvirt.NodeInfo; @@ -46,18 +47,20 @@ public class KVMHostInfo { - private static final Logger LOGGER = Logger.getLogger(KVMHostInfo.class); + protected static Logger LOGGER = LogManager.getLogger(KVMHostInfo.class); private int totalCpus; private int allocatableCpus; private int cpusockets; private long cpuSpeed; + private String cpuArch; private long totalMemory; private long reservedMemory; private long overCommitMemory; private List capabilities = new ArrayList<>(); private static String cpuInfoFreqFileName = "/sys/devices/system/cpu/cpu0/cpufreq/base_frequency"; + private static String cpuArchCommand = "/usr/bin/arch"; public KVMHostInfo(long reservedMemory, long overCommitMemory, long manualSpeed, int reservedCpus) { this.cpuSpeed = manualSpeed; @@ -104,6 +107,10 @@ public List getCapabilities() { return this.capabilities; } + public String getCpuArch() { + return cpuArch; + } + protected static long getCpuSpeed(final String cpabilities, final NodeInfo nodeInfo) { long speed = 0L; speed = getCpuSpeedFromCommandLscpu(); @@ -200,6 +207,7 @@ private void getHostInfoFromLibvirt() { this.cpusockets = hosts.sockets * hosts.nodes; } this.totalCpus = hosts.cpus; + this.cpuArch = getCPUArchFromCommand(); final LibvirtCapXMLParser parser = new LibvirtCapXMLParser(); parser.parseCapabilitiesXML(capabilities); @@ -226,4 +234,9 @@ private void getHostInfoFromLibvirt() { LOGGER.error("Caught libvirt exception while fetching host information", e); } } + + private String getCPUArchFromCommand() { + LOGGER.info("Fetching host CPU arch"); + return Script.runSimpleBashScript(cpuArchCommand); + } } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java index ca9ab4c8308d..bc123b294ce7 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java @@ -32,12 +32,13 @@ import com.cloud.storage.Storage; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import static java.util.regex.Pattern.CASE_INSENSITIVE; public class QemuImg { - private Logger logger = Logger.getLogger(this.getClass()); + private Logger logger = LogManager.getLogger(this.getClass()); public static final String BACKING_FILE = "backing_file"; public static final String BACKING_FILE_FORMAT = "backing_file_format"; diff --git a/plugins/hypervisors/kvm/src/main/resources/META-INF/cloudstack/kvm-compute/spring-kvm-compute-context.xml b/plugins/hypervisors/kvm/src/main/resources/META-INF/cloudstack/kvm-compute/spring-kvm-compute-context.xml index 9bcfdd9c3061..bedaf1851d18 100644 --- a/plugins/hypervisors/kvm/src/main/resources/META-INF/cloudstack/kvm-compute/spring-kvm-compute-context.xml +++ b/plugins/hypervisors/kvm/src/main/resources/META-INF/cloudstack/kvm-compute/spring-kvm-compute-context.xml @@ -37,5 +37,5 @@ - + diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java index 3e18638361c6..2c3a3126f6d1 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java @@ -24,7 +24,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -51,7 +51,7 @@ public class DpdkDriverTest { public void initMocks() { closeable = MockitoAnnotations.openMocks(this); scriptMockedStatic = Mockito.mockStatic(Script.class); - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())).thenReturn(null); + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())).thenReturn(null); extraConfig = new HashMap<>(); } @@ -68,14 +68,14 @@ public void testGetDpdkLatestPortNumberUsedNoDpdkPorts() { @Test public void testGetDpdkLatestPortNumberUsedExistingDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber)); Assert.assertEquals(dpdkPortNumber, driver.getDpdkLatestPortNumberUsed()); } @Test public void testGetNextDpdkPortNoDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(null); String expectedPortName = DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(1); Assert.assertEquals(expectedPortName, driver.getNextDpdkPort()); @@ -83,7 +83,7 @@ public void testGetNextDpdkPortNoDpdkPorts() { @Test public void testGetNextDpdkPortExistingDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber)); String expectedPortName = DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber + 1); Assert.assertEquals(expectedPortName, driver.getNextDpdkPort()); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java index aac7f7343afe..30d0b2ab1635 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java @@ -68,7 +68,7 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.SystemUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; import org.joda.time.Duration; import org.junit.Assert; import org.junit.Before; @@ -82,6 +82,7 @@ import org.libvirt.DomainInterfaceStats; import org.libvirt.LibvirtException; import org.libvirt.MemoryStatistic; +import org.libvirt.NodeInfo; import org.libvirt.SchedUlongParameter; import org.libvirt.StorageVol; import org.libvirt.VcpuInfo; @@ -93,7 +94,6 @@ import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnitRunner; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -243,10 +243,18 @@ public class LibvirtComputingResourceTest { @Mock Domain domainMock; + @Mock + DomainInfo domainInfoMock; + @Mock + DomainInterfaceStats domainInterfaceStatsMock; + @Mock + DomainBlockStats domainBlockStatsMock; private final static long HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IOURING = 6003000; private final static long HYPERVISOR_QEMU_VERSION_SUPPORTS_IOURING = 5000000; + private final static String VM_NAME = "test"; + String hyperVisorType = "kvm"; Random random = new Random(); final String memInfo = "MemTotal: 5830236 kB\n" + @@ -271,7 +279,7 @@ public class LibvirtComputingResourceTest { public void setup() throws Exception { libvirtComputingResourceSpy.qemuSocketsPath = new File("/var/run/qemu"); libvirtComputingResourceSpy.parser = parserMock; - LibvirtComputingResource.s_logger = loggerMock; + LibvirtComputingResource.LOGGER = loggerMock; } /** @@ -922,86 +930,6 @@ public void testUUID() { assertEquals(uuid, oldUuid); } - private static final String VMNAME = "test"; - - @Test - public void testGetVmStat() throws LibvirtException { - final Connect connect = Mockito.mock(Connect.class); - final Domain domain = Mockito.mock(Domain.class); - final DomainInfo domainInfo = new DomainInfo(); - final MemoryStatistic[] domainMem = new MemoryStatistic[2]; - domainMem[0] = Mockito.mock(MemoryStatistic.class); - Mockito.when(domain.getInfo()).thenReturn(domainInfo); - Mockito.when(domain.memoryStats(20)).thenReturn(domainMem); - Mockito.when(domainMem[0].getTag()).thenReturn(4); - Mockito.when(connect.domainLookupByName(VMNAME)).thenReturn(domain); - - // this is testing the interface stats, returns an increasing number of sent and received bytes - - Mockito.when(domain.interfaceStats(nullable(String.class))).thenAnswer(new org.mockito.stubbing.Answer() { - // increment with less than a KB, so this should be less than 1 KB - final static int increment = 1000; - int rxBytes = 1000; - int txBytes = 1000; - - @Override - public DomainInterfaceStats answer(final InvocationOnMock invocation) throws Throwable { - final DomainInterfaceStats domainInterfaceStats = new DomainInterfaceStats(); - domainInterfaceStats.rx_bytes = rxBytes += increment; - domainInterfaceStats.tx_bytes = txBytes += increment; - return domainInterfaceStats; - - } - - }); - - - Mockito.when(domain.blockStats(nullable(String.class))).thenAnswer(new org.mockito.stubbing.Answer() { - // a little less than a KB - final static int increment = 1000; - - int rdBytes = 0; - int wrBytes = 1024; - - @Override - public DomainBlockStats answer(final InvocationOnMock invocation) throws Throwable { - final DomainBlockStats domainBlockStats = new DomainBlockStats(); - - domainBlockStats.rd_bytes = rdBytes += increment; - domainBlockStats.wr_bytes = wrBytes += increment; - return domainBlockStats; - } - - }); - - final LibvirtComputingResource libvirtComputingResource = new LibvirtComputingResource() { - @Override - public List getInterfaces(final Connect conn, final String vmName) { - final InterfaceDef interfaceDef = new InterfaceDef(); - return Arrays.asList(interfaceDef); - } - - @Override - public List getDisks(final Connect conn, final String vmName) { - final DiskDef diskDef = new DiskDef(); - return Arrays.asList(diskDef); - } - - }; - libvirtComputingResource.getVmStat(connect, VMNAME); - final VmStatsEntry vmStat = libvirtComputingResource.getVmStat(connect, VMNAME); - // network traffic as generated by the logic above, must be greater than zero - Assert.assertTrue(vmStat.getNetworkReadKBs() > 0); - Assert.assertTrue(vmStat.getNetworkWriteKBs() > 0); - // IO traffic as generated by the logic above, must be greater than zero - Assert.assertTrue(vmStat.getDiskReadKBs() > 0); - Assert.assertTrue(vmStat.getDiskWriteKBs() > 0); - // Memory limit of VM must be greater than zero - Assert.assertTrue(vmStat.getIntFreeMemoryKBs() >= 0); - Assert.assertTrue(vmStat.getMemoryKBs() >= 0); - Assert.assertTrue(vmStat.getTargetMemoryKBs() >= vmStat.getMemoryKBs()); - } - /* * New Tests */ @@ -6050,7 +5978,7 @@ public void getVmsToSetMemoryBalloonStatsPeriodTestLibvirtError() throws Libvirt List result = libvirtComputingResourceSpy.getVmsToSetMemoryBalloonStatsPeriod(connMock); - Mockito.verify(loggerMock).error(Mockito.anyString(), Mockito.any()); + Mockito.verify(loggerMock).error(Mockito.anyString(), (Throwable) Mockito.any()); Assert.assertTrue(result.isEmpty()); } @@ -6295,4 +6223,196 @@ public void setMaxHostCpuSharesIfCGroupV2TestShouldNotCalculateMaxCpuCapacityIfH Assert.assertEquals(expectedShares, libvirtComputingResourceSpy.getHostCpuMaxCapacity()); } } + + @Test + public void testGetHostTags() throws ConfigurationException { + try (MockedStatic ignored = Mockito.mockStatic(AgentPropertiesFileHandler.class)) { + Mockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.HOST_TAGS))) + .thenReturn("aa,bb,cc,dd"); + + List hostTagsList = libvirtComputingResourceSpy.getHostTags(); + Assert.assertEquals(4, hostTagsList.size()); + Assert.assertEquals("aa,bb,cc,dd", StringUtils.join(hostTagsList, ",")); + } + } + + @Test + public void testGetHostTagsWithSpace() throws ConfigurationException { + try (MockedStatic ignored = Mockito.mockStatic(AgentPropertiesFileHandler.class)) { + Mockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.HOST_TAGS))) + .thenReturn(" aa, bb , cc , dd "); + + List hostTagsList = libvirtComputingResourceSpy.getHostTags(); + Assert.assertEquals(4, hostTagsList.size()); + Assert.assertEquals("aa,bb,cc,dd", StringUtils.join(hostTagsList, ",")); + } + } + + @Test + public void testGetHostTagsWithEmptyPropertyValue() throws ConfigurationException { + try (MockedStatic ignored = Mockito.mockStatic(AgentPropertiesFileHandler.class)) { + Mockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.HOST_TAGS))) + .thenReturn(" "); + + List hostTagsList = libvirtComputingResourceSpy.getHostTags(); + Assert.assertEquals(0, hostTagsList.size()); + Assert.assertEquals("", StringUtils.join(hostTagsList, ",")); + } + } + + @Test + public void getVmStatTestVmIsNullReturnsNull() throws LibvirtException { + doReturn(null).when(libvirtComputingResourceSpy).getDomain(connMock, VM_NAME); + + VmStatsEntry stat = libvirtComputingResourceSpy.getVmStat(connMock, VM_NAME); + + verify(libvirtComputingResourceSpy).getDomain(connMock, VM_NAME); + verify(libvirtComputingResourceSpy, never()).getVmCurrentStats(domainMock); + verify(libvirtComputingResourceSpy, never()).calculateVmMetrics(Mockito.any(), Mockito.any(), Mockito.any()); + Assert.assertNull(stat); + } + + @Test + public void getVmStatTestVmIsNotNullReturnsMetrics() throws LibvirtException { + doReturn(domainMock).when(libvirtComputingResourceSpy).getDomain(connMock, VM_NAME); + doReturn(Mockito.mock(LibvirtExtendedVmStatsEntry.class)).when(libvirtComputingResourceSpy).getVmCurrentStats(domainMock); + doReturn(Mockito.mock(VmStatsEntry.class)).when(libvirtComputingResourceSpy).calculateVmMetrics(Mockito.any(), Mockito.any(), Mockito.any()); + + VmStatsEntry stat = libvirtComputingResourceSpy.getVmStat(connMock, VM_NAME); + + verify(libvirtComputingResourceSpy).getDomain(connMock, VM_NAME); + verify(libvirtComputingResourceSpy).getVmCurrentStats(domainMock); + verify(libvirtComputingResourceSpy).calculateVmMetrics(Mockito.any(), Mockito.any(), Mockito.any()); + Assert.assertNotNull(stat); + } + + private void prepareVmInfoForGetVmCurrentStats() throws LibvirtException { + final NodeInfo nodeInfo = new NodeInfo(); + nodeInfo.cpus = 8; + nodeInfo.memory = 8 * 1024 * 1024; + nodeInfo.sockets = 2; + nodeInfo.threads = 2; + nodeInfo.model = "Foo processor"; + + Mockito.when(domainMock.getName()).thenReturn(VM_NAME); + Mockito.when(domainMock.getConnect()).thenReturn(connMock); + domainInfoMock.cpuTime = 500L; + domainInfoMock.nrVirtCpu = 4; + domainInfoMock.memory = 2048; + domainInfoMock.maxMem = 4096; + Mockito.when(domainMock.getInfo()).thenReturn(domainInfoMock); + final MemoryStatistic[] domainMem = new MemoryStatistic[2]; + domainMem[0] = Mockito.mock(MemoryStatistic.class); + doReturn(1024L).when(libvirtComputingResourceSpy).getMemoryFreeInKBs(domainMock); + + domainInterfaceStatsMock.rx_bytes = 1000L; + domainInterfaceStatsMock.tx_bytes = 2000L; + doReturn(domainInterfaceStatsMock).when(domainMock).interfaceStats(Mockito.any()); + doReturn(List.of(new InterfaceDef())).when(libvirtComputingResourceSpy).getInterfaces(connMock, VM_NAME); + + domainBlockStatsMock.rd_req = 3000L; + domainBlockStatsMock.rd_bytes = 4000L; + domainBlockStatsMock.wr_req = 5000L; + domainBlockStatsMock.wr_bytes = 6000L; + doReturn(domainBlockStatsMock).when(domainMock).blockStats(Mockito.any()); + doReturn(List.of(new DiskDef())).when(libvirtComputingResourceSpy).getDisks(connMock, VM_NAME); + } + + @Test + public void getVmCurrentStatsTestIfStatsAreAsExpected() throws LibvirtException { + prepareVmInfoForGetVmCurrentStats(); + + LibvirtExtendedVmStatsEntry vmStatsEntry = libvirtComputingResourceSpy.getVmCurrentStats(domainMock); + + Assert.assertEquals(domainInfoMock.cpuTime, vmStatsEntry.getCpuTime()); + Assert.assertEquals((double) domainInterfaceStatsMock.rx_bytes / 1024, vmStatsEntry.getNetworkReadKBs(), 0); + Assert.assertEquals((double) domainInterfaceStatsMock.tx_bytes / 1024, vmStatsEntry.getNetworkWriteKBs(), 0); + Assert.assertEquals(domainBlockStatsMock.rd_req, vmStatsEntry.getDiskReadIOs(), 0); + Assert.assertEquals((double) domainBlockStatsMock.rd_bytes / 1024, vmStatsEntry.getDiskReadKBs(), 0); + Assert.assertEquals(domainBlockStatsMock.wr_req, vmStatsEntry.getDiskWriteIOs(), 0); + Assert.assertEquals((double) domainBlockStatsMock.wr_bytes / 1024, vmStatsEntry.getDiskWriteKBs(), 0); + Assert.assertNotNull(vmStatsEntry.getTimestamp()); + } + + @Test + public void getVmCurrentCpuStatsTestIfStatsAreAsExpected() throws LibvirtException { + prepareVmInfoForGetVmCurrentStats(); + + LibvirtExtendedVmStatsEntry vmStatsEntry = new LibvirtExtendedVmStatsEntry(); + libvirtComputingResourceSpy.getVmCurrentCpuStats(domainMock, vmStatsEntry); + + Assert.assertEquals(domainInfoMock.cpuTime, vmStatsEntry.getCpuTime()); + } + + @Test + public void getVmCurrentNetworkStatsTestIfStatsAreAsExpected() throws LibvirtException { + prepareVmInfoForGetVmCurrentStats(); + + LibvirtExtendedVmStatsEntry vmStatsEntry = new LibvirtExtendedVmStatsEntry(); + libvirtComputingResourceSpy.getVmCurrentNetworkStats(domainMock, vmStatsEntry); + + Assert.assertEquals((double) domainInterfaceStatsMock.rx_bytes / 1024, vmStatsEntry.getNetworkReadKBs(), 0); + Assert.assertEquals((double) domainInterfaceStatsMock.tx_bytes / 1024, vmStatsEntry.getNetworkWriteKBs(), 0); + } + + @Test + public void getVmCurrentDiskStatsTestIfStatsAreAsExpected() throws LibvirtException { + prepareVmInfoForGetVmCurrentStats(); + + LibvirtExtendedVmStatsEntry vmStatsEntry = new LibvirtExtendedVmStatsEntry(); + libvirtComputingResourceSpy.getVmCurrentDiskStats(domainMock, vmStatsEntry); + + Assert.assertEquals(domainBlockStatsMock.rd_req, vmStatsEntry.getDiskReadIOs(), 0); + Assert.assertEquals((double) domainBlockStatsMock.rd_bytes / 1024, vmStatsEntry.getDiskReadKBs(), 0); + Assert.assertEquals(domainBlockStatsMock.wr_req, vmStatsEntry.getDiskWriteIOs(), 0); + Assert.assertEquals((double) domainBlockStatsMock.wr_bytes / 1024, vmStatsEntry.getDiskWriteKBs(), 0); + } + + @Test + public void calculateVmMetricsTestOldStatsIsNullDoesNotCalculateUtilization() throws LibvirtException { + prepareVmInfoForGetVmCurrentStats(); + + LibvirtExtendedVmStatsEntry vmStatsEntry = libvirtComputingResourceSpy.getVmCurrentStats(domainMock); + VmStatsEntry metrics = libvirtComputingResourceSpy.calculateVmMetrics(domainMock, null, vmStatsEntry); + + Assert.assertEquals(domainInfoMock.nrVirtCpu, metrics.getNumCPUs()); + Assert.assertEquals(domainInfoMock.maxMem, (long) metrics.getMemoryKBs()); + Assert.assertEquals(libvirtComputingResourceSpy.getMemoryFreeInKBs(domainMock), (long) metrics.getIntFreeMemoryKBs()); + Assert.assertEquals(domainInfoMock.memory, (long) metrics.getTargetMemoryKBs()); + Assert.assertEquals(0, metrics.getCPUUtilization(), 0); + Assert.assertEquals(0, metrics.getNetworkReadKBs(), 0); + Assert.assertEquals(0, metrics.getNetworkWriteKBs(), 0); + Assert.assertEquals(0, metrics.getDiskReadKBs(), 0); + Assert.assertEquals(0, metrics.getDiskReadIOs(), 0); + Assert.assertEquals(0, metrics.getDiskWriteKBs(), 0); + Assert.assertEquals(0, metrics.getDiskWriteIOs(), 0); + } + + @Test + public void calculateVmMetricsTestOldStatsIsNotNullCalculatesUtilization() throws LibvirtException { + prepareVmInfoForGetVmCurrentStats(); + LibvirtExtendedVmStatsEntry oldStats = libvirtComputingResourceSpy.getVmCurrentStats(domainMock); + domainInfoMock.cpuTime *= 3; + domainInterfaceStatsMock.rx_bytes *= 3; + domainInterfaceStatsMock.tx_bytes *= 3; + domainBlockStatsMock.rd_req *= 3; + domainBlockStatsMock.rd_bytes *= 3; + domainBlockStatsMock.wr_req *= 3; + domainBlockStatsMock.wr_bytes *= 3; + LibvirtExtendedVmStatsEntry newStats = libvirtComputingResourceSpy.getVmCurrentStats(domainMock); + + VmStatsEntry metrics = libvirtComputingResourceSpy.calculateVmMetrics(domainMock, oldStats, newStats); + + Assert.assertEquals(domainInfoMock.nrVirtCpu, metrics.getNumCPUs()); + Assert.assertEquals(domainInfoMock.maxMem, (long) metrics.getMemoryKBs()); + Assert.assertEquals(libvirtComputingResourceSpy.getMemoryFreeInKBs(domainMock), (long) metrics.getIntFreeMemoryKBs()); + Assert.assertEquals(domainInfoMock.memory, (long) metrics.getTargetMemoryKBs()); + Assert.assertTrue(metrics.getCPUUtilization() > 0); + Assert.assertEquals(newStats.getNetworkReadKBs() - oldStats.getNetworkReadKBs(), metrics.getNetworkReadKBs(), 0); + Assert.assertEquals(newStats.getNetworkWriteKBs() - oldStats.getNetworkWriteKBs(), metrics.getNetworkWriteKBs(), 0); + Assert.assertEquals(newStats.getDiskReadIOs() - oldStats.getDiskReadIOs(), metrics.getDiskReadIOs(), 0); + Assert.assertEquals(newStats.getDiskWriteIOs() - oldStats.getDiskWriteIOs(), metrics.getDiskWriteIOs(), 0); + Assert.assertEquals(newStats.getDiskReadKBs() - oldStats.getDiskReadKBs(), metrics.getDiskReadKBs(), 0); + Assert.assertEquals(newStats.getDiskWriteKBs() - oldStats.getDiskWriteKBs(), metrics.getDiskWriteKBs(), 0); + } } diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtCpuTopologyTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtCpuTopologyTest.java new file mode 100644 index 000000000000..f5234fc5ae3b --- /dev/null +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtCpuTopologyTest.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.cloud.hypervisor.kvm.resource; + +import com.cloud.vm.VmDetailConstants; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.mockito.Mockito; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +@RunWith(value = Parameterized.class) +public class LibvirtCpuTopologyTest { + private final LibvirtComputingResource libvirtComputingResource = Mockito.spy(new LibvirtComputingResource()); + + private final String desc; + private final Integer coresPerSocket; + private final Integer threadsPerCore; + private final Integer totalVmCores; + private final String expectedXml; + + public LibvirtCpuTopologyTest(String desc, Integer coresPerSocket, Integer threadsPerCore, Integer totalVmCores, String expectedXml) { + this.desc = desc; + this.coresPerSocket = coresPerSocket; + this.threadsPerCore = threadsPerCore; + this.totalVmCores = totalVmCores; + this.expectedXml = expectedXml; + } + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList(new Object[][] { + createTestData("8 cores, 2 per socket",2, null, 8, ""), + createTestData("8 cores, 4 per socket",4, null, 8, ""), + createTestData("8 cores, nothing specified",null, null, 8, ""), + createTestData("12 cores, nothing specified",null, null, 12, ""), + createTestData("8 cores, 2C per socket, 2TPC",2, 2, 8, ""), + createTestData("8 cores, 1C per socket, 2TPC",1, 2, 8, ""), + createTestData("8 cores, default CPS, 2TPC",null, 2, 8, ""), + createTestData("6 cores, default CPS, 2TPC",null, 2, 6, ""), + createTestData("12 cores, 2CPS, 2TPC",2, 2, 12, ""), + createTestData("6 cores, misconfigured cores, CPS, TPC, use default topology",2, 2, 6, ""), + createTestData("odd cores, nothing specified use default topology",null, null, 3, ""), + createTestData("odd cores, uneven CPS use default topology",2, null, 3, ""), + createTestData("8 cores, 2 CPS, odd threads use default topology", 2, 3, 8, ""), + createTestData("1 core, 2 CPS, odd threads use default topology", 2, 1, 1, "") + }); + } + + private static Object[] createTestData(String desc, Integer coresPerSocket, Integer threadsPerCore, int totalVmCores, String expected) { + return new Object[] {desc, coresPerSocket, threadsPerCore, totalVmCores, expected}; + } + + @Test + public void topologyTest() { + LibvirtVMDef.CpuModeDef cpuModeDef = new LibvirtVMDef.CpuModeDef(); + Map details = new HashMap<>(); + + if (coresPerSocket != null) { + details.put(VmDetailConstants.CPU_CORE_PER_SOCKET, coresPerSocket.toString()); + } + + if (threadsPerCore != null) { + details.put(VmDetailConstants.CPU_THREAD_PER_CORE, threadsPerCore.toString()); + } + + if (coresPerSocket == null && threadsPerCore == null) { + details = null; + } + + libvirtComputingResource.setCpuTopology(cpuModeDef, totalVmCores, details); + Assert.assertEquals(desc, expectedXml, cpuModeDef.toString()); + } +} diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java index 3813cb39f3c0..921bbf0c9a87 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java @@ -31,6 +31,7 @@ import junit.framework.TestCase; import org.apache.cloudstack.utils.qemu.QemuObject; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; @@ -267,7 +268,7 @@ public void testDomainXMLParserWithoutModelName() { " aafaaabc-8657-4efc-9c52-3422d4e04088\n" + " 2097152\n" + " 2097152\n" + - " 2\n" + + " 8\n" + " \n" + " hvm\n" + " \n" + @@ -278,6 +279,7 @@ public void testDomainXMLParserWithoutModelName() { " \n" + " \n" + " \n" + + " " + " \n" + " \n" + " \n" + @@ -380,5 +382,8 @@ public void testDomainXMLParserWithoutModelName() { System.out.println("Got exception " + e.getMessage()); throw e; } + Assert.assertEquals("CPU socket count is parsed", 1, libvirtDomainXMLParser.getCpuModeDef().getSockets()); + Assert.assertEquals("CPU cores count is parsed", 4, libvirtDomainXMLParser.getCpuModeDef().getCoresPerSocket()); + Assert.assertEquals("CPU threads count is parsed", 2, libvirtDomainXMLParser.getCpuModeDef().getThreadsPerCore()); } } diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java index 5bc251673552..c41d487b63c5 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java @@ -280,6 +280,57 @@ public void testDiskDefWithEncryption() { assertEquals(expectedXML, disk.toString()); } + @Test + public void testDiskDefWithBlockIO() { + String filePath = "/var/lib/libvirt/images/disk.qcow2"; + String diskLabel = "vda"; + + DiskDef disk = new DiskDef(); + DiskDef.DiskBus bus = DiskDef.DiskBus.VIRTIO; + DiskDef.DiskFmtType type = DiskDef.DiskFmtType.QCOW2; + DiskDef.DiskCacheMode cacheMode = DiskDef.DiskCacheMode.WRITEBACK; + + disk.defFileBasedDisk(filePath, diskLabel, bus, type); + disk.setCacheMode(cacheMode); + disk.setLogicalBlockIOSize(DiskDef.BlockIOSize.SIZE_4K); + + assertEquals(filePath, disk.getDiskPath()); + assertEquals(diskLabel, disk.getDiskLabel()); + assertEquals(bus, disk.getBusType()); + assertEquals(DiskDef.DeviceType.DISK, disk.getDeviceType()); + + String expectedXmlLogical = "\n\n" + + "\n\n\n\n"; + + assertEquals(expectedXmlLogical, disk.toString()); + + String expectedXmlPhysical = "\n\n" + + "\n\n\n\n"; + + disk.setLogicalBlockIOSize(null); + disk.setPhysicalBlockIOSize(DiskDef.BlockIOSize.SIZE_4K); + assertEquals(expectedXmlPhysical, disk.toString()); + + disk.setLogicalBlockIOSize(DiskDef.BlockIOSize.SIZE_512); + String expectedXml = "\n\n" + + "\n\n\n\n"; + assertEquals(expectedXml, disk.toString()); + } + + @Test + public void testDiskDefWithGeometry() { + DiskDef disk = new DiskDef(); + disk.defBlockBasedDisk("disk1", 1, DiskDef.DiskBus.VIRTIO); + disk.setGeometry(new DiskDef.DiskGeometry(16383, 16, 63)); + String expectedXML = "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n"; + assertEquals(expectedXML, disk.toString()); + } + @Test public void testDiskDefWithMultipleHosts() { String path = "/mnt/primary1"; @@ -496,4 +547,17 @@ public void testSCSIDef() { "\n"; assertEquals(expected, str); } + + @Test + public void testTopology() { + LibvirtVMDef.CpuModeDef cpuModeDef = new LibvirtVMDef.CpuModeDef(); + cpuModeDef.setTopology(2, 1, 4); + assertEquals("", cpuModeDef.toString()); + } + + public void testTopologyNoInfo() { + LibvirtVMDef.CpuModeDef cpuModeDef = new LibvirtVMDef.CpuModeDef(); + cpuModeDef.setTopology(-1, -1, 4); + assertEquals("", cpuModeDef.toString()); + } } diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapperTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapperTest.java index 1cc2a60e380c..f0e94e59485d 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapperTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertInstanceCommandWrapperTest.java @@ -168,7 +168,6 @@ public void testSanitizeDisksPath() { @Test public void testMoveTemporaryDisksToDestination() { KVMPhysicalDisk sourceDisk = Mockito.mock(KVMPhysicalDisk.class); - Mockito.when(sourceDisk.getPool()).thenReturn(temporaryPool); List disks = List.of(sourceDisk); String destinationPoolUuid = UUID.randomUUID().toString(); List destinationPools = List.of(destinationPoolUuid); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateVolumeCommandWrapperTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateVolumeCommandWrapperTest.java index c278144b4e1c..4f1eba1a772a 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateVolumeCommandWrapperTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateVolumeCommandWrapperTest.java @@ -39,11 +39,11 @@ import org.libvirt.LibvirtException; import org.libvirt.TypedParameter; import org.mockito.InjectMocks; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; @@ -297,7 +297,7 @@ public void testMigratePowerFlexVolume() throws LibvirtException, ParserConfigur Mockito.doReturn(domxml).when(dm).getXMLDesc(0); - Mockito.doNothing().when(dm).blockCopy(Matchers.anyString(), Matchers.anyString(), Matchers.any(TypedParameter[].class), Matchers.anyInt()); + Mockito.doNothing().when(dm).blockCopy(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(TypedParameter[].class), ArgumentMatchers.anyInt()); MigrateVolumeAnswer answer = new MigrateVolumeAnswer(command, true, null, destPath); Mockito.doReturn(answer).when(libvirtMigrateVolumeCommandWrapper).checkBlockJobStatus(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); @@ -342,7 +342,7 @@ public void testMigratePowerFlexVolumeFailure() throws LibvirtException, ParserC Mockito.doReturn(null).when(destVolumeObjectTO).getPassphrase(); Mockito.doReturn(domxml).when(dm).getXMLDesc(0); - Mockito.doThrow(LibvirtException.class).when(dm).blockCopy(Matchers.anyString(), Matchers.anyString(), Matchers.any(TypedParameter[].class), Matchers.anyInt()); + Mockito.doThrow(LibvirtException.class).when(dm).blockCopy(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.any(TypedParameter[].class), ArgumentMatchers.anyInt()); Answer migrateVolumeAnswer = libvirtMigrateVolumeCommandWrapper.migratePowerFlexVolume(command, libvirtComputingResource); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptorTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptorTest.java index 7db4f114e8cb..07aea0cfbee5 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptorTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptorTest.java @@ -53,7 +53,7 @@ public class ScaleIOStorageAdaptorTest { @Before public void setUp() { mockedScript = Mockito.mockStatic(Script.class); - scaleIOStorageAdaptor = Mockito.spy(new ScaleIOStorageAdaptor(storageLayer)); + scaleIOStorageAdaptor = Mockito.spy(ScaleIOStorageAdaptor.class); } @After diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStoragePoolTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStoragePoolTest.java index 492bc275a3f3..7989f9e6a69e 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStoragePoolTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/ScaleIOStoragePoolTest.java @@ -37,14 +37,12 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.MockedConstruction; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import com.cloud.storage.Storage.StoragePoolType; -import com.cloud.storage.StorageLayer; import com.cloud.utils.script.Script; @RunWith(MockitoJUnitRunner.class) @@ -54,9 +52,6 @@ public class ScaleIOStoragePoolTest { StorageAdaptor adapter; - @Mock - StorageLayer storageLayer; - @Before public void setUp() throws Exception { final String uuid = "345fc603-2d7e-47d2-b719-a0110b3732e6"; @@ -65,7 +60,7 @@ public void setUp() throws Exception { Map details = new HashMap(); details.put(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID, systemId); - adapter = spy(new ScaleIOStorageAdaptor(storageLayer)); + adapter = spy(new ScaleIOStorageAdaptor()); pool = new ScaleIOStoragePool(uuid, "192.168.1.19", 443, "a519be2f00000000", type, details, adapter); } diff --git a/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/kvm/ha/KVMHostHATest.java b/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/kvm/ha/KVMHostHATest.java index 5a7c156272fe..a94fb01475a3 100644 --- a/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/kvm/ha/KVMHostHATest.java +++ b/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/kvm/ha/KVMHostHATest.java @@ -29,7 +29,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; diff --git a/plugins/hypervisors/kvm/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/hypervisors/kvm/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/hypervisors/kvm/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/hypervisors/ovm/pom.xml b/plugins/hypervisors/ovm/pom.xml index 657c3f60b3ea..aad6d80f27d6 100644 --- a/plugins/hypervisors/ovm/pom.xml +++ b/plugins/hypervisors/ovm/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmDiscoverer.java b/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmDiscoverer.java index 46e152838114..82cb61d7a1fd 100644 --- a/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmDiscoverer.java +++ b/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmDiscoverer.java @@ -27,7 +27,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.StartupCommand; @@ -53,7 +52,6 @@ import com.cloud.utils.ssh.SSHCmdHelper; public class OvmDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(OvmDiscoverer.class); protected String _publicNetworkDevice; protected String _privateNetworkDevice; protected String _guestNetworkDevice; @@ -97,25 +95,25 @@ private boolean checkIfExisted(String guid) { if (!url.getScheme().equals("http")) { String msg = "urlString is not http so we're not taking care of the discovery for this: " + url; - s_logger.debug(msg); + logger.debug(msg); return null; } if (clusterId == null) { String msg = "must specify cluster Id when add host"; - s_logger.debug(msg); + logger.debug(msg); throw new CloudRuntimeException(msg); } if (podId == null) { String msg = "must specify pod Id when add host"; - s_logger.debug(msg); + logger.debug(msg); throw new CloudRuntimeException(msg); } ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm)) { - if (s_logger.isInfoEnabled()) - s_logger.info("invalid cluster id or cluster is not for Ovm hypervisors"); + if (logger.isInfoEnabled()) + logger.info("invalid cluster id or cluster is not for Ovm hypervisors"); return null; } @@ -139,7 +137,7 @@ private boolean checkIfExisted(String guid) { throw new CloudRuntimeException("The host " + hostIp + " has been added before"); } - s_logger.debug("Ovm discover is going to disover host having guid " + guid); + logger.debug("Ovm discover is going to disover host having guid " + guid); ClusterVO clu = _clusterDao.findById(clusterId); if (clu.getGuid() == null) { @@ -196,16 +194,16 @@ private boolean checkIfExisted(String guid) { resources.put(ovmResource, details); return resources; } catch (XmlRpcException e) { - s_logger.debug("XmlRpc exception, Unable to discover OVM: " + url, e); + logger.debug("XmlRpc exception, Unable to discover OVM: " + url, e); return null; } catch (UnknownHostException e) { - s_logger.debug("Host name resolve failed exception, Unable to discover OVM: " + url, e); + logger.debug("Host name resolve failed exception, Unable to discover OVM: " + url, e); return null; } catch (ConfigurationException e) { - s_logger.debug("Configure resource failed, Unable to discover OVM: " + url, e); + logger.debug("Configure resource failed, Unable to discover OVM: " + url, e); return null; } catch (Exception e) { - s_logger.debug("Unable to discover OVM: " + url, e); + logger.debug("Unable to discover OVM: " + url, e); return null; } } diff --git a/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmFencer.java b/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmFencer.java index 6a247d914398..60792f0ddb7d 100644 --- a/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmFencer.java +++ b/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmFencer.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.FenceAnswer; @@ -39,7 +38,6 @@ import com.cloud.vm.VirtualMachine; public class OvmFencer extends AdapterBase implements FenceBuilder { - private static final Logger s_logger = Logger.getLogger(OvmFencer.class); @Inject AgentManager _agentMgr; @Inject @@ -69,7 +67,7 @@ public OvmFencer() { @Override public Boolean fenceOff(VirtualMachine vm, Host host) { if (host.getHypervisorType() != HypervisorType.Ovm) { - s_logger.debug("Don't know how to fence non Ovm hosts " + host.getHypervisorType()); + logger.debug("Don't know how to fence non Ovm hosts " + host.getHypervisorType()); return null; } @@ -93,13 +91,13 @@ public Boolean fenceOff(VirtualMachine vm, Host host) { try { answer = (FenceAnswer)_agentMgr.send(h.getId(), fence); } catch (AgentUnavailableException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); + if (logger.isDebugEnabled()) { + logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); } continue; } catch (OperationTimedoutException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); + if (logger.isDebugEnabled()) { + logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); } continue; } @@ -109,8 +107,8 @@ public Boolean fenceOff(VirtualMachine vm, Host host) { } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString()); } return false; diff --git a/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmResourceBase.java b/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmResourceBase.java index cf2f1fbed64d..9d958a9894a4 100644 --- a/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmResourceBase.java +++ b/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/hypervisor/OvmResourceBase.java @@ -29,7 +29,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import com.trilead.ssh2.SCPClient; @@ -134,7 +135,7 @@ import com.cloud.vm.VirtualMachine.PowerState; public class OvmResourceBase implements ServerResource, HypervisorResource { - private static final Logger s_logger = Logger.getLogger(OvmResourceBase.class); + protected Logger logger = LogManager.getLogger(getClass()); String _name; Long _zoneId; Long _podId; @@ -183,7 +184,7 @@ public boolean configure(String name, Map params) throws Configu _agentUserName = (String)params.get("agentusername"); _agentPassword = (String)params.get("agentpassword"); } catch (Exception e) { - s_logger.debug("Configure " + _name + " failed", e); + logger.debug("Configure " + _name + " failed", e); throw new ConfigurationException("Configure " + _name + " failed, " + e.toString()); } @@ -218,7 +219,7 @@ public boolean configure(String name, Map params) throws Configu try { setupServer(); } catch (Exception e) { - s_logger.debug("Setup server failed, ip " + _ip, e); + logger.debug("Setup server failed, ip " + _ip, e); throw new ConfigurationException("Unable to setup server"); } @@ -228,7 +229,7 @@ public boolean configure(String name, Map params) throws Configu OvmHost.registerAsVmServer(_conn); _bridges = OvmBridge.getAllBridges(_conn); } catch (XmlRpcException e) { - s_logger.debug("Get bridges failed", e); + logger.debug("Get bridges failed", e); throw new ConfigurationException("Cannot get bridges on host " + _ip + "," + e.getMessage()); } @@ -251,14 +252,14 @@ public boolean configure(String name, Map params) throws Configu try { _canBridgeFirewall = canBridgeFirewall(); } catch (XmlRpcException e) { - s_logger.error("Failed to detect whether the host supports security groups.", e); + logger.error("Failed to detect whether the host supports security groups.", e); _canBridgeFirewall = false; } */ _canBridgeFirewall = false; - s_logger.debug("OVM host doesn't support security groups."); + logger.debug("OVM host doesn't support security groups."); return true; } @@ -318,9 +319,9 @@ protected void fillHostInfo(StartupRoutingCommand cmd) { d.put("guest.network.device", _guestNetworkName); cmd.setHostDetails(d); - s_logger.debug(String.format("Add a OVM host(%s)", hostDetails.toJson())); + logger.debug(String.format("Add a OVM host(%s)", hostDetails.toJson())); } catch (XmlRpcException e) { - s_logger.debug("XML RPC Exception" + e.getMessage(), e); + logger.debug("XML RPC Exception" + e.getMessage(), e); throw new CloudRuntimeException("XML RPC Exception" + e.getMessage(), e); } } @@ -353,8 +354,8 @@ protected void setupServer() throws IOException { continue; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Copying " + script.getPath() + " to " + s_ovsAgentPath + " on " + _ip + " with permission 0644"); + if (logger.isDebugEnabled()) { + logger.debug("Copying " + script.getPath() + " to " + s_ovsAgentPath + " on " + _ip + " with permission 0644"); } scp.put(script.getPath(), s_ovsAgentPath, "0644"); } @@ -378,7 +379,7 @@ public StartupCommand[] initialize() { cmd.setCaps("hvm"); return new StartupCommand[] {cmd}; } catch (Exception e) { - s_logger.debug("Ovm resource initializes failed", e); + logger.debug("Ovm resource initializes failed", e); return null; } } @@ -389,7 +390,7 @@ public PingCommand getCurrentStatus(long id) { OvmHost.ping(_conn); return new PingRoutingCommand(getType(), id, getHostVmStateReport()); } catch (XmlRpcException e) { - s_logger.debug("Check agent status failed", e); + logger.debug("Check agent status failed", e); return null; } } @@ -401,11 +402,11 @@ protected ReadyAnswer execute(ReadyCommand cmd) { if (d.primaryIp.equalsIgnoreCase(_ip)) { return new ReadyAnswer(cmd); } else { - s_logger.debug("Primary IP changes to " + d.primaryIp + ", it should be " + _ip); + logger.debug("Primary IP changes to " + d.primaryIp + ", it should be " + _ip); return new ReadyAnswer(cmd, "I am not the primary server"); } } catch (XmlRpcException e) { - s_logger.debug("XML RPC Exception" + e.getMessage(), e); + logger.debug("XML RPC Exception" + e.getMessage(), e); throw new CloudRuntimeException("XML RPC Exception" + e.getMessage(), e); } @@ -418,7 +419,7 @@ protected void createNfsSr(StorageFilerTO pool) throws XmlRpcException { d.type = OvmStoragePool.NFS; d.uuid = pool.getUuid(); OvmStoragePool.create(_conn, d); - s_logger.debug(String.format("Created SR (mount point:%1$s)", mountPoint)); + logger.debug(String.format("Created SR (mount point:%1$s)", mountPoint)); } protected void createOCFS2Sr(StorageFilerTO pool) throws XmlRpcException { @@ -427,7 +428,7 @@ protected void createOCFS2Sr(StorageFilerTO pool) throws XmlRpcException { d.type = OvmStoragePool.OCFS2; d.uuid = pool.getUuid(); OvmStoragePool.create(_conn, d); - s_logger.debug(String.format("Created SR (mount point:%1$s)", d.path)); + logger.debug(String.format("Created SR (mount point:%1$s)", d.path)); } private void setupHeartBeat(String poolUuid) { @@ -437,7 +438,7 @@ private void setupHeartBeat(String poolUuid) { s_isHeartBeat = true; } } catch (Exception e) { - s_logger.debug("setup heart beat for " + _ip + " failed", e); + logger.debug("setup heart beat for " + _ip + " failed", e); s_isHeartBeat = false; } } @@ -459,7 +460,7 @@ protected Answer execute(ModifyStoragePoolCommand cmd) { ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, d.totalSpace, d.freeSpace, tInfo); return answer; } catch (Exception e) { - s_logger.debug("ModifyStoragePoolCommand failed", e); + logger.debug("ModifyStoragePoolCommand failed", e); return new Answer(cmd, false, e.getMessage()); } } @@ -475,7 +476,7 @@ protected PrimaryStorageDownloadAnswer execute(final PrimaryStorageDownloadComma Pair res = OvmStoragePool.downloadTemplate(_conn, cmd.getPoolUuid(), secondaryStoragePath); return new PrimaryStorageDownloadAnswer(res.first(), res.second()); } catch (Exception e) { - s_logger.debug("PrimaryStorageDownloadCommand failed", e); + logger.debug("PrimaryStorageDownloadCommand failed", e); return new PrimaryStorageDownloadAnswer(e.getMessage()); } } @@ -497,7 +498,7 @@ protected CreateAnswer execute(CreateCommand cmd) { vol.size, null); return new CreateAnswer(cmd, volume); } catch (Exception e) { - s_logger.debug("CreateCommand failed", e); + logger.debug("CreateCommand failed", e); return new CreateAnswer(cmd, e.getMessage()); } } @@ -637,7 +638,7 @@ protected void cleanup(OvmVm.Details vm) { try { cleanupNetwork(vm.vifs); } catch (XmlRpcException e) { - s_logger.debug("Clean up network for " + vm.name + " failed", e); + logger.debug("Clean up network for " + vm.name + " failed", e); } _vmNetworkStats.remove(vm.name); } @@ -666,7 +667,7 @@ public synchronized StartAnswer execute(StartCommand cmd) { return new StartAnswer(cmd); } catch (Exception e) { - s_logger.debug("Start vm " + vmName + " failed", e); + logger.debug("Start vm " + vmName + " failed", e); cleanup(vmDetails); return new StartAnswer(cmd, e.getMessage()); } @@ -683,7 +684,7 @@ protected Answer execute(GetHostStatsCommand cmd) { HostStatsEntry hostStats = new HostStatsEntry(cmd.getHostId(), cpuUtil, rxBytes, txBytes, "host", totalMemory, freeMemory, 0, 0); return new GetHostStatsAnswer(cmd, hostStats); } catch (Exception e) { - s_logger.debug("Get host stats of " + cmd.getHostName() + " failed", e); + logger.debug("Get host stats of " + cmd.getHostName() + " failed", e); return new Answer(cmd, false, e.getMessage()); } @@ -697,7 +698,7 @@ public StopAnswer execute(StopCommand cmd) { try { vm = OvmVm.getDetails(_conn, vmName); } catch (XmlRpcException e) { - s_logger.debug("Unable to get details of vm: " + vmName + ", treating it as stopped", e); + logger.debug("Unable to get details of vm: " + vmName + ", treating it as stopped", e); return new StopAnswer(cmd, "success", true); } @@ -706,7 +707,7 @@ public StopAnswer execute(StopCommand cmd) { cleanup(vm); return new StopAnswer(cmd, "success", true); } catch (Exception e) { - s_logger.debug("Stop " + vmName + "failed", e); + logger.debug("Stop " + vmName + "failed", e); return new StopAnswer(cmd, e.getMessage(), false); } } @@ -720,7 +721,7 @@ public RebootAnswer execute(RebootCommand cmd) { Integer vncPort = Integer.parseInt(res.get("vncPort")); return new RebootAnswer(cmd, null, vncPort); } catch (Exception e) { - s_logger.debug("Reboot " + vmName + " failed", e); + logger.debug("Reboot " + vmName + " failed", e); return new RebootAnswer(cmd, e.getMessage(), false); } } @@ -728,7 +729,7 @@ public RebootAnswer execute(RebootCommand cmd) { private PowerState toPowerState(String vmName, String s) { PowerState state = s_powerStateMaps.get(s); if (state == null) { - s_logger.debug("Unkown state " + s + " for " + vmName); + logger.debug("Unkown state " + s + " for " + vmName); state = PowerState.PowerUnknown; } return state; @@ -760,7 +761,7 @@ protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) { OvmStoragePool.Details d = OvmStoragePool.getDetailsByUuid(_conn, cmd.getStorageId()); return new GetStorageStatsAnswer(cmd, d.totalSpace, d.usedSpace); } catch (Exception e) { - s_logger.debug("GetStorageStatsCommand on pool " + cmd.getStorageId() + " failed", e); + logger.debug("GetStorageStatsCommand on pool " + cmd.getStorageId() + " failed", e); return new GetStorageStatsAnswer(cmd, e.getMessage()); } } @@ -801,7 +802,7 @@ protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) { VmStatsEntry e = getVmStat(vmName); vmStatsNameMap.put(vmName, e); } catch (XmlRpcException e) { - s_logger.debug("Get vm stat for " + vmName + " failed", e); + logger.debug("Get vm stat for " + vmName + " failed", e); continue; } } @@ -813,15 +814,15 @@ public Answer execute(DestroyCommand cmd) { OvmVolume.destroy(_conn, cmd.getVolume().getPoolUuid(), cmd.getVolume().getPath()); return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Destroy volume " + cmd.getVolume().getName() + " failed", e); + logger.debug("Destroy volume " + cmd.getVolume().getName() + " failed", e); return new Answer(cmd, false, e.getMessage()); } } protected PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) { VirtualMachineTO vm = cmd.getVirtualMachine(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Preparing host for migrating " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Preparing host for migrating " + vm); } NicTO[] nics = vm.getNics(); @@ -832,7 +833,7 @@ protected PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) { return new PrepareForMigrationAnswer(cmd); } catch (Exception e) { - s_logger.warn("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to " + e.toString(), e); + logger.warn("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to " + e.toString(), e); return new PrepareForMigrationAnswer(cmd, e); } } @@ -847,7 +848,7 @@ protected MigrateAnswer execute(final MigrateCommand cmd) { return new MigrateAnswer(cmd, true, "migration succeeded", null); } catch (Exception e) { String msg = "Catch Exception " + e.getClass().getName() + ": Migration failed due to " + e.toString(); - s_logger.debug(msg, e); + logger.debug(msg, e); return new MigrateAnswer(cmd, false, msg, null); } } @@ -860,13 +861,13 @@ protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd HashMap states = getAllVms(); PowerState vmPowerState = states.get(vmName); if (vmPowerState == null) { - s_logger.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand"); + logger.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand"); vmPowerState = PowerState.PowerOff; } return new CheckVirtualMachineAnswer(cmd, vmPowerState, vncPort); } catch (Exception e) { - s_logger.debug("Check migration for " + vmName + " failed", e); + logger.debug("Check migration for " + vmName + " failed", e); return new CheckVirtualMachineAnswer(cmd, PowerState.PowerOff, null); } } @@ -880,7 +881,7 @@ protected GetVncPortAnswer execute(GetVncPortCommand cmd) { Integer vncPort = OvmVm.getVncPort(_conn, cmd.getName()); return new GetVncPortAnswer(cmd, _ip, vncPort); } catch (Exception e) { - s_logger.debug("get vnc port for " + cmd.getName() + " failed", e); + logger.debug("get vnc port for " + cmd.getName() + " failed", e); return new GetVncPortAnswer(cmd, e.getMessage()); } } @@ -895,7 +896,7 @@ protected Answer execute(PingTestCommand cmd) { return new Answer(cmd, true, "success"); } catch (Exception e) { - s_logger.debug("Ping " + cmd.getComputingHostIp() + " failed", e); + logger.debug("Ping " + cmd.getComputingHostIp() + " failed", e); return new Answer(cmd, false, e.getMessage()); } } @@ -905,7 +906,7 @@ protected FenceAnswer execute(FenceCommand cmd) { Boolean res = OvmHost.fence(_conn, cmd.getHostIp()); return new FenceAnswer(cmd, res, res.toString()); } catch (Exception e) { - s_logger.debug("fence " + cmd.getHostIp() + " failed", e); + logger.debug("fence " + cmd.getHostIp() + " failed", e); return new FenceAnswer(cmd, false, e.getMessage()); } } @@ -917,7 +918,7 @@ protected Answer execute(AttachIsoCommand cmd) { OvmVm.detachOrAttachIso(_conn, cmd.getVmName(), isoPath, cmd.isAttach()); return new Answer(cmd); } catch (Exception e) { - s_logger.debug("Attach or detach ISO " + cmd.getIsoPath() + " for " + cmd.getVmName() + " attach:" + cmd.isAttach() + " failed", e); + logger.debug("Attach or detach ISO " + cmd.getIsoPath() + " for " + cmd.getVmName() + " attach:" + cmd.isAttach() + " failed", e); return new Answer(cmd, false, e.getMessage()); } } @@ -932,15 +933,15 @@ private Answer execute(SecurityGroupRulesCmd cmd) { addNetworkRules(cmd.getVmName(), Long.toString(cmd.getVmId()), cmd.getGuestIp(), cmd.getSignature(), String.valueOf(cmd.getSeqNum()), cmd.getGuestMac(), cmd.stringifyRules(), vifDeviceName, bridgeName); } catch (XmlRpcException e) { - s_logger.error(e); + logger.error(e); result = false; } if (!result) { - s_logger.warn("Failed to program network rules for vm " + cmd.getVmName()); + logger.warn("Failed to program network rules for vm " + cmd.getVmName()); return new SecurityGroupRuleAnswer(cmd, false, "programming network rules failed"); } else { - s_logger.info("Programmed network rules for vm " + cmd.getVmName() + " guestIp=" + cmd.getGuestIp() + ":ingress num rules=" + cmd.getIngressRuleSet().size() + + logger.info("Programmed network rules for vm " + cmd.getVmName() + " guestIp=" + cmd.getGuestIp() + ":ingress num rules=" + cmd.getIngressRuleSet().size() + ":egress num rules=" + cmd.getEgressRuleSet().size()); return new SecurityGroupRuleAnswer(cmd); } @@ -951,7 +952,7 @@ private Answer execute(CleanupNetworkRulesCmd cmd) { try { result = cleanupNetworkRules(); } catch (XmlRpcException e) { - s_logger.error(e); + logger.error(e); result = false; } @@ -1013,7 +1014,7 @@ protected OvmVif.Details getVifFromVm(String vmName, Integer deviceId) throws Xm try { vifs = getInterfaces(vmName); } catch (XmlRpcException e) { - s_logger.error("Failed to get VIFs for VM " + vmName, e); + logger.error("Failed to get VIFs for VM " + vmName, e); throw e; } @@ -1044,7 +1045,7 @@ protected Answer execute(PrepareOCFS2NodesCommand cmd) { OvmStoragePool.prepareOCFS2Nodes(_conn, cmd.getClusterName(), params.toString()); return new Answer(cmd, true, "Success"); } catch (XmlRpcException e) { - s_logger.debug("OCFS2 prepare nodes failed", e); + logger.debug("OCFS2 prepare nodes failed", e); return new Answer(cmd, false, e.getMessage()); } } @@ -1069,7 +1070,7 @@ protected CreatePrivateTemplateAnswer execute(final CreatePrivateTemplateFromVol return new CreatePrivateTemplateAnswer(cmd, true, null, res.get("installPath"), Long.parseLong(res.get("virtualSize")), Long.parseLong(res.get("physicalSize")), res.get("templateFileName"), ImageFormat.RAW); } catch (Exception e) { - s_logger.debug("Create template failed", e); + logger.debug("Create template failed", e); return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage()); } } @@ -1091,7 +1092,7 @@ protected CopyVolumeAnswer execute(CopyVolumeCommand cmd) { String res = OvmStoragePool.copyVolume(_conn, secStorageMountPath, volumeFolderOnSecStorage, volumePath, storagePoolUuid, toSec, wait); return new CopyVolumeAnswer(cmd, true, null, null, res); } catch (Exception e) { - s_logger.debug("Copy volume failed", e); + logger.debug("Copy volume failed", e); return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null); } } @@ -1100,15 +1101,15 @@ protected Answer execute(DeleteStoragePoolCommand cmd) { try { OvmStoragePool.delete(_conn, cmd.getPool().getUuid()); } catch (Exception e) { - s_logger.debug("Delete storage pool on host " + _ip + " failed, however, we leave to user for cleanup and tell management server it succeeded", e); + logger.debug("Delete storage pool on host " + _ip + " failed, however, we leave to user for cleanup and tell management server it succeeded", e); } return new Answer(cmd); } protected CheckNetworkAnswer execute(CheckNetworkCommand cmd) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Checking if network name setup is done on the resource"); + if (logger.isDebugEnabled()) { + logger.debug("Checking if network name setup is done on the resource"); } List infoList = cmd.getPhysicalNetworkInfoList(); @@ -1137,7 +1138,7 @@ protected CheckNetworkAnswer execute(CheckNetworkCommand cmd) { } if (errorout) { - s_logger.error(msg); + logger.error(msg); return new CheckNetworkAnswer(cmd, false, msg); } else { return new CheckNetworkAnswer(cmd, true, "Network Setup check by names is done"); @@ -1146,8 +1147,8 @@ protected CheckNetworkAnswer execute(CheckNetworkCommand cmd) { private boolean isNetworkSetupByName(String nameTag) { if (nameTag != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Looking for network setup by name " + nameTag); + if (logger.isDebugEnabled()) { + logger.debug("Looking for network setup by name " + nameTag); } return _bridges.contains(nameTag); } diff --git a/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/object/Connection.java b/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/object/Connection.java index 8d2edac68fa4..0c6a5ebd943c 100644 --- a/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/object/Connection.java +++ b/plugins/hypervisors/ovm/src/main/java/com/cloud/ovm/object/Connection.java @@ -20,7 +20,8 @@ import java.net.URL; import java.util.TimeZone; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.TimingOutCallback; import org.apache.xmlrpc.client.XmlRpcClient; @@ -29,7 +30,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class Connection { - private static final Logger s_logger = Logger.getLogger(Connection.class); + protected Logger logger = LogManager.getLogger(getClass()); private XmlRpcClientConfigImpl _config = new XmlRpcClientConfigImpl(); XmlRpcClient _client; String _username; @@ -95,7 +96,7 @@ public Object callTimeoutInSec(String method, Object[] params, int timeout, bool /* * some parameters including user password should not be printed in log */ - s_logger.debug("Call Ovm agent: " + Coder.toJson(mParams)); + logger.debug("Call Ovm agent: " + Coder.toJson(mParams)); } long startTime = System.currentTimeMillis(); @@ -109,7 +110,7 @@ public Object callTimeoutInSec(String method, Object[] params, int timeout, bool } finally { long endTime = System.currentTimeMillis(); long during = (endTime - startTime) / 1000; // in secs - s_logger.debug("Ovm call " + method + " finished in " + String.valueOf(during) + " secs"); + logger.debug("Ovm call " + method + " finished in " + String.valueOf(during) + " secs"); } } diff --git a/plugins/hypervisors/ovm/src/main/resources/META-INF/cloudstack/ovm-compute/spring-ovm-compute-context.xml b/plugins/hypervisors/ovm/src/main/resources/META-INF/cloudstack/ovm-compute/spring-ovm-compute-context.xml index 09a5964be083..87676ef3a729 100644 --- a/plugins/hypervisors/ovm/src/main/resources/META-INF/cloudstack/ovm-compute/spring-ovm-compute-context.xml +++ b/plugins/hypervisors/ovm/src/main/resources/META-INF/cloudstack/ovm-compute/spring-ovm-compute-context.xml @@ -35,5 +35,5 @@ - + diff --git a/plugins/hypervisors/ovm/src/main/resources/META-INF/cloudstack/ovm-discoverer/spring-ovm-discoverer-context.xml b/plugins/hypervisors/ovm/src/main/resources/META-INF/cloudstack/ovm-discoverer/spring-ovm-discoverer-context.xml index 8a340472b6e2..a4a03f46542e 100644 --- a/plugins/hypervisors/ovm/src/main/resources/META-INF/cloudstack/ovm-discoverer/spring-ovm-discoverer-context.xml +++ b/plugins/hypervisors/ovm/src/main/resources/META-INF/cloudstack/ovm-discoverer/spring-ovm-discoverer-context.xml @@ -30,5 +30,5 @@ - + diff --git a/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/ConfigFileOps.py b/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/ConfigFileOps.py index bd922623656e..6cfa6bb13960 100755 --- a/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/ConfigFileOps.py +++ b/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/ConfigFileOps.py @@ -58,7 +58,7 @@ def getEntry(self, name, separator="="): def save(self): fp = open(self.fileName, "r") newLines = [] - for line in fp.readlines(): + for line in fp.readlines(): matched = False for entry in self.entries: if entry.op == "add": diff --git a/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/OvmCommonModule.py b/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/OvmCommonModule.py index 8cd715dd3b36..eb50a2e0b1c9 100755 --- a/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/OvmCommonModule.py +++ b/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/OvmCommonModule.py @@ -75,7 +75,7 @@ def asciiLoads(jStr): def exceptionIfNoSuccess(str, errMsg=None): if not errMsg: errMsg = str - if not "success" in str: raise Exception("%s (%s)"%(errMsg, str)) + if "success" not in str: raise Exception("%s (%s)"%(errMsg, str)) def successToMap(str, sep=';'): if not str.startswith("success"): raise Exception(str) @@ -135,7 +135,7 @@ def getDomId(vm_name): return execute("xm list | grep " + vm_name + " | awk '{print $2}'").strip() def raiseExceptionIfFail(res): - if not "success" in res and not "SUCC" in res: raise Exception(res) + if "success" not in res and "SUCC" not in res: raise Exception(res) def ipToHeartBeatFileName(ip): return ip.replace('.', '_') + "_HEARTBEAT" diff --git a/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/configureOvm.sh b/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/configureOvm.sh index 2cc3a0c9f260..ccd1704b3225 100755 --- a/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/configureOvm.sh +++ b/plugins/hypervisors/ovm/src/main/scripts/vm/hypervisor/ovm/configureOvm.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/plugins/hypervisors/ovm3/pom.xml b/plugins/hypervisors/ovm3/pom.xml index 23f5d8f2123b..31f761bde78a 100644 --- a/plugins/hypervisors/ovm3/pom.xml +++ b/plugins/hypervisors/ovm3/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -44,8 +44,12 @@ ${cs.commons-lang3.version} - ch.qos.reload4j - reload4j + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java index b7feb1ab23b0..a24ff3b1d364 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/ha/Ovm3Investigator.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -35,7 +34,6 @@ import com.cloud.utils.component.AdapterBase; public class Ovm3Investigator extends AdapterBase implements Investigator { - private static final Logger LOGGER = Logger.getLogger(Ovm3Investigator.class); @Inject HostDao hostDao; @Inject @@ -45,7 +43,7 @@ public class Ovm3Investigator extends AdapterBase implements Investigator { @Override public boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) throws UnknownVM { - LOGGER.debug("isVmAlive: " + vm.getHostName() + " on " + host.getName()); + logger.debug("isVmAlive: " + vm.getHostName() + " on " + host.getName()); if (host.getHypervisorType() != Hypervisor.HypervisorType.Ovm3) { throw new UnknownVM(); } @@ -58,7 +56,7 @@ public boolean isVmAlive(com.cloud.vm.VirtualMachine vm, Host host) throws Unkno @Override public Status isAgentAlive(Host agent) { - LOGGER.debug("isAgentAlive: " + agent.getName()); + logger.debug("isAgentAlive: " + agent.getName()); if (agent.getHypervisorType() != Hypervisor.HypervisorType.Ovm3) { return null; } @@ -74,7 +72,7 @@ public Status isAgentAlive(Host agent) { return answer.getResult() ? Status.Down : Status.Up; } } catch (Exception e) { - LOGGER.error("Failed to send command to host: " + neighbor.getId(), e); + logger.error("Failed to send command to host: " + neighbor.getId(), e); } } diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/CloudstackPlugin.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/CloudstackPlugin.java index 3871787f60ed..298420a04b2a 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/CloudstackPlugin.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/CloudstackPlugin.java @@ -20,11 +20,8 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; public class CloudstackPlugin extends OvmObject { - private static final Logger LOGGER = Logger - .getLogger(CloudstackPlugin.class); private boolean checkstoragestarted = false; public CloudstackPlugin(Connection c) { setClient(c); @@ -48,7 +45,7 @@ public boolean ovsDomrUploadFile(String domr, String path, String file, content); } - public static class ReturnCode { + public class ReturnCode { private Map returnCode = new HashMap() { { put("rc", null); @@ -73,7 +70,7 @@ public Boolean getRc() throws Ovm3ResourceException { } else if (rc instanceof Long) { c = (Long) rc; } else { - LOGGER.debug("Incorrect return code: " + rc); + logger.debug("Incorrect return code: " + rc); return false; } returnCode.put("exit", c); @@ -126,7 +123,7 @@ public boolean dom0CheckPort(String ip, Integer port, Integer retries, Thread.sleep(sleep * 1000); } } catch (Exception e) { - LOGGER.error("Dom0 port check failed: " + e); + logger.error("Dom0 port check failed: " + e); } return x; } diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Connection.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Connection.java index a873be420e1d..c43d36c934b1 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Connection.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Connection.java @@ -22,7 +22,8 @@ import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.TimingOutCallback; import org.apache.xmlrpc.client.XmlRpcClient; @@ -30,7 +31,7 @@ import org.apache.xmlrpc.client.XmlRpcClientRequestImpl; public class Connection extends XmlRpcClient { - private static final Logger LOGGER = Logger.getLogger(Connection.class); + protected Logger logger = LogManager.getLogger(getClass()); private final XmlRpcClientConfigImpl xmlClientConfig = new XmlRpcClientConfigImpl(); private XmlRpcClient xmlClient; private String hostUser = null; @@ -83,7 +84,7 @@ private XmlRpcClient setupXmlClient() { /* reply time is 5 mins */ xmlClientConfig.setReplyTimeout(60 * 15000); if (hostUser != null && hostPass != null) { - LOGGER.debug("Setting username " + hostUser); + logger.debug("Setting username " + hostUser); xmlClientConfig.setBasicUserName(hostUser); xmlClientConfig.setBasicPassword(hostPass); } @@ -91,7 +92,7 @@ private XmlRpcClient setupXmlClient() { client.setConfig(xmlClientConfig); client.setTypeFactory(new RpcTypeFactory(client)); } catch (MalformedURLException e) { - LOGGER.info("Incorrect URL: ", e); + logger.info("Incorrect URL: ", e); } return client; } @@ -109,7 +110,7 @@ public Object callTimeoutInSec(String method, List params, int timeout, boolean debug) throws XmlRpcException { TimingOutCallback callback = new TimingOutCallback(timeout * 1000); if (debug) { - LOGGER.debug("Call Ovm3 agent " + hostName + "(" + hostIp +"): " + method + logger.debug("Call Ovm3 agent " + hostName + "(" + hostIp +"): " + method + " with " + params); } long startTime = System.currentTimeMillis(); @@ -120,22 +121,22 @@ public Object callTimeoutInSec(String method, List params, int timeout, xmlClient.executeAsync(req, callback); return callback.waitForResponse(); } catch (TimingOutCallback.TimeoutException e) { - LOGGER.info("Timeout: ", e); + logger.info("Timeout: ", e); throw new XmlRpcException(e.getMessage()); } catch (XmlRpcException e) { - LOGGER.info("XML RPC Exception occurred: ", e); + logger.info("XML RPC Exception occurred: ", e); throw e; } catch (RuntimeException e) { - LOGGER.info("Runtime Exception: ", e); + logger.info("Runtime Exception: ", e); throw new XmlRpcException(e.getMessage()); } catch (Throwable e) { - LOGGER.error("Holy crap batman!: ", e); + logger.error("Holy crap batman!: ", e); throw new XmlRpcException(e.getMessage(), e); } finally { long endTime = System.currentTimeMillis(); /* in seconds */ float during = (endTime - startTime) / (float) 1000; - LOGGER.debug("Ovm3 call " + method + " finished in " + during + logger.debug("Ovm3 call " + method + " finished in " + during + " secs, on " + hostIp + ":" + hostPort); } } diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Linux.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Linux.java index c0c0f3fa6821..50e2574eb54b 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Linux.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Linux.java @@ -21,12 +21,9 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.w3c.dom.Document; public class Linux extends OvmObject { - private static final Logger LOGGER = Logger - .getLogger(Linux.class); private static final String DEVICE = "Device"; private static final String REMOTEDIR = "Remote_Dir"; private static final String MOUNTPOINT = "Mount_Point"; @@ -210,7 +207,7 @@ public String get(String element) throws Ovm3ResourceException { try { initMaps(); } catch (Ovm3ResourceException e) { - LOGGER.info("Unable to discover host: " + e.getMessage(), e); + logger.info("Unable to discover host: " + e.getMessage(), e); throw e; } if (ovmGeneric.containsKey(element)) { diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Network.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Network.java index 008eb430b0ef..20f2f1eff703 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Network.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Network.java @@ -23,11 +23,9 @@ import java.util.Map; import java.util.Map.Entry; -import org.apache.log4j.Logger; import org.w3c.dom.Document; public class Network extends OvmObject { - private static final Logger LOGGER = Logger.getLogger(Network.class); private static final String START = "start"; private static final String BRIDGE = "Bridge"; private static final String ADDRESS = "Address"; @@ -123,7 +121,7 @@ private Network.Interface getNetIface(String key, String val) return iface.getValue(); } } - LOGGER.debug("Unable to find " + key + " Interface by value: " + val); + logger.debug("Unable to find " + key + " Interface by value: " + val); setSuccess(false); return null; } @@ -150,7 +148,7 @@ public Network.Interface getBridgeByName(String name) && getNetIface("Name", name).getIfType().contentEquals(BRIDGE)) { return getNetIface("Name", name); } - LOGGER.debug("Unable to find bridge by name: " + name); + logger.debug("Unable to find bridge by name: " + name); setSuccess(false); return null; } @@ -161,7 +159,7 @@ public Network.Interface getBridgeByIp(String ip) && getNetIface(ADDRESS, ip).getIfType().contentEquals(BRIDGE)) { return getNetIface(ADDRESS, ip); } - LOGGER.debug("Unable to find bridge by ip: " + ip); + logger.debug("Unable to find bridge by ip: " + ip); setSuccess(false); return null; } diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/OvmObject.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/OvmObject.java index 102478c22ff1..3b7354c34c50 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/OvmObject.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/OvmObject.java @@ -35,7 +35,8 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; @@ -45,8 +46,7 @@ public class OvmObject { private volatile Connection client; private static List emptyParams = new ArrayList(); - private static final Logger LOGGER = Logger - .getLogger(OvmObject.class); + protected Logger logger = LogManager.getLogger(getClass()); private boolean success = false; public OvmObject() { @@ -215,7 +215,7 @@ public String xmlToString(String path, Document xmlDocument) XPathConstants.NODESET); return nodeList.item(0).getNodeValue(); } catch (NullPointerException e) { - LOGGER.info("Got no items back from parsing, returning null: " + e); + logger.info("Got no items back from parsing, returning null: " + e); return null; } catch (XPathExpressionException e) { throw new Ovm3ResourceException("Problem parsing XML to String: ", e); @@ -239,7 +239,7 @@ public Document prepParse(String input) xmlDocument = builder.parse(new InputSource(new StringReader( input))); } catch (SAXException | IOException e) { - LOGGER.info(e.getClass() + ": ", e); + logger.info(e.getClass() + ": ", e); throw new Ovm3ResourceException("Unable to parse XML: ", e); } return xmlDocument; diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Pool.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Pool.java index 6306754185e8..a95664499bbb 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Pool.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Pool.java @@ -23,15 +23,12 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.w3c.dom.Document; /* * synonym to the pool python lib in the ovs-agent */ public class Pool extends OvmObject { - private static final Logger LOGGER = Logger - .getLogger(Pool.class); private final List validRoles = new ArrayList() { { diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/PoolOCFS2.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/PoolOCFS2.java index baf1de930e7c..256f08d13d76 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/PoolOCFS2.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/PoolOCFS2.java @@ -20,12 +20,9 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.w3c.dom.Document; public class PoolOCFS2 extends OvmObject { - private static final Logger LOGGER = Logger - .getLogger(PoolOCFS2.class); private Map poolFileSystem = new HashMap(); private String poolFsTarget; private String poolFsType; @@ -104,7 +101,7 @@ public Boolean createPoolFs(String type, String target, String clustername, return nullIsTrueCallWrapper("create_pool_filesystem", type, target, clustername, fsid, nfsbaseid, managerid, fsid); } else if (hasPoolFs(fsid)) { - LOGGER.debug("PoolFs already exists on this host: " + fsid); + logger.debug("PoolFs already exists on this host: " + fsid); return true; } else { throw new Ovm3ResourceException("Unable to add pool filesystem to host, "+ diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Repository.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Repository.java index 7cbf0e747548..ba4d62e3b795 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Repository.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Repository.java @@ -22,11 +22,9 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.w3c.dom.Document; public class Repository extends OvmObject { - private static final Logger LOGGER = Logger.getLogger(Repository.class); private static final String VERSION = "Version"; private static final String NAMETAG = "[@Name='"; private Object postDiscovery = null; diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Xen.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Xen.java index ddf6a56db630..adb5d6020895 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Xen.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/objects/Xen.java @@ -24,10 +24,8 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; public class Xen extends OvmObject { - private static final Logger LOGGER = Logger.getLogger(Xen.class); private static final String VNCLISTEN = "vnclisten"; private static final String MEMORY = "memory"; private static final String MAXVCPUS = "maxvcpus"; @@ -294,7 +292,7 @@ public Integer getVifIdByMac(String mac) { } c += 1; } - LOGGER.debug("No vif matched mac: " + mac + " in " + vmVifs); + logger.debug("No vif matched mac: " + mac + " in " + vmVifs); return -1; } public Integer getVifIdByIp(String ip) { @@ -308,13 +306,13 @@ public Integer getVifIdByIp(String ip) { } c += 1; } - LOGGER.debug("No vif matched ip: " + ip + " in " + vmVifs); + logger.debug("No vif matched ip: " + ip + " in " + vmVifs); return -1; } public Boolean addVif(Integer id, String bridge, String mac) { if (getVifIdByMac(mac) > 0) { - LOGGER.debug("Already nic with mac present: " + mac); + logger.debug("Already nic with mac present: " + mac); return false; } String vif = "mac=" + mac + ",bridge=" + bridge; @@ -338,15 +336,15 @@ public Boolean removeVif(String bridge, String mac) { String remove = "mac=" + mac + ",bridge=" + bridge; for (String vif : getVmVifs()) { if (vif.equals(remove)) { - LOGGER.debug("leaving out vif: " + remove); + logger.debug("leaving out vif: " + remove); } else { - LOGGER.debug("keeping vif: " + vif); + logger.debug("keeping vif: " + vif); newVifs.add(vif); } } vmParams.put("vif", newVifs); } catch (Exception e) { - LOGGER.debug(e); + logger.debug(e); } return true; } @@ -400,7 +398,7 @@ private Boolean addDisk(String image, String mode) { private Boolean addDiskToDisks(String image, String devName, String mode) { for (String disk : vmDisks) { if (disk.contains(image)) { - LOGGER.debug(vmName + " already has disk " +image+ ":" + devName + ":" + mode); + logger.debug(vmName + " already has disk " +image+ ":" + devName + ":" + mode); return true; } } @@ -417,7 +415,7 @@ public Boolean removeDisk(String image) { return true; } } - LOGGER.debug("No disk found corresponding to image: " + image); + logger.debug("No disk found corresponding to image: " + image); return false; } @@ -445,7 +443,7 @@ private String getVmDiskDetailFromMap(int disk, String dest) { Map o = (Map) vmParams .get("device"); if (o == null) { - LOGGER.info("No devices found" + vmName); + logger.info("No devices found" + vmName); return null; } vmDisk = (Map) o.get("vbd")[disk]; @@ -557,7 +555,7 @@ private Object get(String key) { public Map listVms() throws Ovm3ResourceException { Object[] result = (Object[]) callWrapper("list_vms"); if (result == null) { - LOGGER.debug("no vm results on list_vms"); + logger.debug("no vm results on list_vms"); return null; } @@ -634,7 +632,7 @@ public Boolean listVm(String repoId, String vmId) defVm.setVmParams((Map) callWrapper("list_vm", repoId, vmId)); if (defVm.getVmParams() == null) { - LOGGER.debug("no vm results on list_vm"); + logger.debug("no vm results on list_vm"); return false; } return true; @@ -898,7 +896,7 @@ public Boolean rebootVm(String repoId, String vmId) public Vm getVmConfig(String vmName) throws Ovm3ResourceException { defVm = getRunningVmConfig(vmName); if (defVm == null) { - LOGGER.debug("Unable to retrieve running config for " + vmName); + logger.debug("Unable to retrieve running config for " + vmName); return defVm; } return getVmConfig(defVm.getVmRootDiskPoolId(), defVm.getVmUuid()); @@ -919,7 +917,7 @@ public Vm getVmConfig(String repoId, String vmId) Map x = (Map) callWrapper( "get_vm_config", repoId, vmId); if (x == null) { - LOGGER.debug("Unable to find vm with id:" + vmId + " on repoId:" + repoId); + logger.debug("Unable to find vm with id:" + vmId + " on repoId:" + repoId); return nVm; } nVm.setVmVifs(Arrays.asList(Arrays.copyOf(x.get("vif"), diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3Discoverer.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3Discoverer.java index 3f245273a272..2305dbb6c26e 100755 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3Discoverer.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3Discoverer.java @@ -29,7 +29,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -66,7 +65,6 @@ public class Ovm3Discoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter { - private static final Logger LOGGER = Logger.getLogger(Ovm3Discoverer.class); protected String publicNetworkDevice; protected String privateNetworkDevice; protected String guestNetworkDevice; @@ -123,11 +121,11 @@ private boolean checkIfExisted(String guid) { private boolean CheckUrl(URI url) throws DiscoveryException { if ("http".equals(url.getScheme()) || "https".equals(url.getScheme())) { String msg = "Discovering " + url + ": " + _params; - LOGGER.debug(msg); + logger.debug(msg); } else { String msg = "urlString is not http(s) so we're not taking care of the discovery for this: " + url; - LOGGER.info(msg); + logger.info(msg); throw new DiscoveryException(msg); } return true; @@ -142,13 +140,13 @@ public Map> find(long dcId, CheckUrl(url); if (clusterId == null) { String msg = "must specify cluster Id when add host"; - LOGGER.info(msg); + logger.info(msg); throw new DiscoveryException(msg); } if (podId == null) { String msg = "must specify pod Id when add host"; - LOGGER.info(msg); + logger.info(msg); throw new DiscoveryException(msg); } @@ -156,30 +154,30 @@ public Map> find(long dcId, if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm3)) { String msg = "invalid cluster id or cluster is not for Ovm3 hypervisors"; - LOGGER.info(msg); + logger.info(msg); throw new DiscoveryException(msg); } else { - LOGGER.debug("cluster: " + cluster); + logger.debug("cluster: " + cluster); } String agentUsername = _params.get("agentusername"); if (agentUsername == null) { String msg = "Agent user name must be specified"; - LOGGER.info(msg); + logger.info(msg); throw new DiscoveryException(msg); } String agentPassword = _params.get("agentpassword"); if (agentPassword == null) { String msg = "Agent password must be specified"; - LOGGER.info(msg); + logger.info(msg); throw new DiscoveryException(msg); } String agentPort = _params.get("agentport"); if (agentPort == null) { String msg = "Agent port must be specified"; - LOGGER.info(msg); + logger.info(msg); throw new DiscoveryException(msg); } @@ -193,11 +191,11 @@ public Map> find(long dcId, if (checkIfExisted(guid)) { String msg = "The host " + hostIp + " has been added before"; - LOGGER.info(msg); + logger.info(msg); throw new DiscoveryException(msg); } - LOGGER.debug("Ovm3 discover is going to disover host having guid " + logger.debug("Ovm3 discover is going to disover host having guid " + guid); ClusterVO clu = clusterDao.findById(clusterId); @@ -224,7 +222,7 @@ public Map> find(long dcId, String msg = "Cannot Ssh to Ovm3 host(IP=" + hostIp + ", username=" + username + ", password=*******), discovery failed"; - LOGGER.warn(msg); + logger.warn(msg); throw new DiscoveryException(msg); } @@ -281,17 +279,17 @@ public Map> find(long dcId, resources.put(ovmResource, details); return resources; } catch (UnknownHostException e) { - LOGGER.error( + logger.error( "Host name resolve failed exception, Unable to discover Ovm3 host: " + url.getHost(), e); return null; } catch (ConfigurationException e) { - LOGGER.error( + logger.error( "Configure resource failed, Unable to discover Ovm3 host: " + url.getHost(), e); return null; } catch (IOException | Ovm3ResourceException e) { - LOGGER.error("Unable to discover Ovm3 host: " + url.getHost(), e); + logger.error("Unable to discover Ovm3 host: " + url.getHost(), e); return null; } } @@ -299,7 +297,7 @@ public Map> find(long dcId, @Override public void postDiscovery(List hosts, long msId) throws CloudRuntimeException { - LOGGER.debug("postDiscovery: " + hosts); + logger.debug("postDiscovery: " + hosts); } @Override @@ -315,26 +313,26 @@ public HypervisorType getHypervisorType() { @Override public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { - LOGGER.debug("createHostVOForConnectedAgent: " + host); + logger.debug("createHostVOForConnectedAgent: " + host); return null; } @Override public boolean processAnswers(long agentId, long seq, Answer[] answers) { - LOGGER.debug("processAnswers: " + agentId); + logger.debug("processAnswers: " + agentId); return false; } @Override public boolean processCommands(long agentId, long seq, Command[] commands) { - LOGGER.debug("processCommands: " + agentId); + logger.debug("processCommands: " + agentId); return false; } @Override public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) { - LOGGER.debug("processControlCommand: " + agentId); + logger.debug("processControlCommand: " + agentId); return null; } @@ -346,12 +344,12 @@ public void processHostAdded(long hostId) { @Override public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) { - LOGGER.debug("processConnect"); + logger.debug("processConnect"); } @Override public boolean processDisconnect(long agentId, Status state) { - LOGGER.debug("processDisconnect"); + logger.debug("processDisconnect"); return false; } @@ -370,13 +368,13 @@ public boolean isRecurring() { @Override public int getTimeout() { - LOGGER.debug("getTimeout"); + logger.debug("getTimeout"); return 0; } @Override public boolean processTimeout(long agentId, long seq) { - LOGGER.debug("processTimeout: " + agentId); + logger.debug("processTimeout: " + agentId); return false; } @@ -384,7 +382,7 @@ public boolean processTimeout(long agentId, long seq) { public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map details, List hostTags) { - LOGGER.debug("createHostVOForDirectConnectAgent: " + host); + logger.debug("createHostVOForDirectConnectAgent: " + host); StartupCommand firstCmd = startup[0]; if (!(firstCmd instanceof StartupRoutingCommand)) { return null; @@ -402,7 +400,7 @@ public HostVO createHostVOForDirectConnectAgent(HostVO host, @Override public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { - LOGGER.debug("deleteHost: " + host); + logger.debug("deleteHost: " + host); if (host.getType() != com.cloud.host.Host.Type.Routing || host.getHypervisorType() != HypervisorType.Ovm3) { return null; diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3FenceBuilder.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3FenceBuilder.java index 95ef97deda88..eb83572fc2b8 100755 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3FenceBuilder.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3FenceBuilder.java @@ -23,7 +23,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.FenceAnswer; @@ -41,7 +40,6 @@ public class Ovm3FenceBuilder extends AdapterBase implements FenceBuilder { Map fenceParams; - private static final Logger LOGGER = Logger.getLogger(Ovm3FenceBuilder.class); @Inject AgentManager agentMgr; @Inject @@ -74,11 +72,11 @@ public Ovm3FenceBuilder() { @Override public Boolean fenceOff(VirtualMachine vm, Host host) { if (host.getHypervisorType() != HypervisorType.Ovm3) { - LOGGER.debug("Don't know how to fence non Ovm3 hosts " + logger.debug("Don't know how to fence non Ovm3 hosts " + host.getHypervisorType()); return null; } else { - LOGGER.debug("Fencing " + vm + " on host " + host + logger.debug("Fencing " + vm + " on host " + host + " with params: "+ fenceParams ); } @@ -94,8 +92,8 @@ public Boolean fenceOff(VirtualMachine vm, Host host) { try { answer = (FenceAnswer) agentMgr.send(h.getId(), fence); } catch (AgentUnavailableException | OperationTimedoutException e) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Moving on to the next host because " + if (logger.isDebugEnabled()) { + logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); } continue; @@ -106,8 +104,8 @@ public Boolean fenceOff(VirtualMachine vm, Host host) { } } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Unable to fence off " + vm.toString() + " on " + if (logger.isDebugEnabled()) { + logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString()); } diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorGuru.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorGuru.java index 432474d043ab..77663d9bf045 100755 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorGuru.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorGuru.java @@ -20,7 +20,6 @@ import javax.inject.Inject; import org.apache.cloudstack.storage.command.StorageSubSystemCommand; -import org.apache.log4j.Logger; import com.cloud.agent.api.Command; import com.cloud.agent.api.to.VirtualMachineTO; @@ -33,7 +32,6 @@ import com.cloud.vm.VirtualMachineProfile; public class Ovm3HypervisorGuru extends HypervisorGuruBase implements HypervisorGuru { - private final Logger LOGGER = Logger.getLogger(Ovm3HypervisorGuru.class); @Inject private GuestOSDao guestOsDao; @@ -61,7 +59,7 @@ public boolean trackVmHostChange() { @Override public Pair getCommandHostDelegation(long hostId, Command cmd) { - LOGGER.debug("getCommandHostDelegation: " + cmd.getClass()); + logger.debug("getCommandHostDelegation: " + cmd.getClass()); if (cmd instanceof StorageSubSystemCommand) { StorageSubSystemCommand c = (StorageSubSystemCommand)cmd; c.setExecuteInSequence(true); diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java index e897ca5e5edc..ba4304d349cc 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.storage.command.CopyCommand; import org.apache.cloudstack.storage.command.CreateObjectCommand; import org.apache.cloudstack.storage.command.StorageSubSystemCommand; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -101,7 +100,6 @@ import com.cloud.vm.VirtualMachine.State; public class Ovm3HypervisorResource extends ServerResourceBase implements HypervisorResource { - private static final Logger LOGGER = Logger.getLogger(Ovm3HypervisorResource.class); @Inject private VirtualRoutingResource vrResource; private StorageSubsystemCommandHandler storageHandler; @@ -130,7 +128,7 @@ public Type getType() { */ @Override public StartupCommand[] initialize() { - LOGGER.debug("Ovm3 resource intializing"); + logger.debug("Ovm3 resource intializing"); try { StartupRoutingCommand srCmd = new StartupRoutingCommand(); StartupStorageCommand ssCmd = new StartupStorageCommand(); @@ -138,10 +136,10 @@ public StartupCommand[] initialize() { /* here stuff gets completed, but where should state live ? */ hypervisorsupport.fillHostInfo(srCmd); hypervisorsupport.vmStateMapClear(); - LOGGER.debug("Ovm3 pool " + ssCmd + " " + srCmd); + logger.debug("Ovm3 pool " + ssCmd + " " + srCmd); return new StartupCommand[] {srCmd, ssCmd}; } catch (Exception e) { - LOGGER.debug("Ovm3 resource initializes failed", e); + logger.debug("Ovm3 resource initializes failed", e); return new StartupCommand[] {}; } } @@ -158,19 +156,19 @@ public PingCommand getCurrentStatus(long id) { CloudstackPlugin cSp = new CloudstackPlugin(c); if (!cSp.dom0CheckStorageHealthCheck(configuration.getAgentScriptsDir(), configuration.getAgentCheckStorageScript(), configuration.getCsHostGuid(), configuration.getAgentStorageCheckTimeout(), configuration.getAgentStorageCheckInterval()) && !cSp.dom0CheckStorageHealthCheck()) { - LOGGER.error("Storage health check not running on " + configuration.getAgentHostname()); + logger.error("Storage health check not running on " + configuration.getAgentHostname()); } else if (cSp.dom0CheckStorageHealthCheck()) { - LOGGER.error("Storage health check started on " + configuration.getAgentHostname()); + logger.error("Storage health check started on " + configuration.getAgentHostname()); } else { - LOGGER.debug("Storage health check running on " + configuration.getAgentHostname()); + logger.debug("Storage health check running on " + configuration.getAgentHostname()); } return new PingRoutingCommand(getType(), id, hypervisorsupport.hostVmStateReport()); } else { - LOGGER.debug("Agent did not respond correctly: " + ping + " but got " + pong); + logger.debug("Agent did not respond correctly: " + ping + " but got " + pong); } } catch (Ovm3ResourceException | NullPointerException e) { - LOGGER.debug("Check agent status failed", e); + logger.debug("Check agent status failed", e); return null; } return null; @@ -179,7 +177,7 @@ public PingCommand getCurrentStatus(long id) { @Override public Answer executeRequest(Command cmd) { Class clazz = cmd.getClass(); - LOGGER.debug("executeRequest called: " + cmd.getClass()); + logger.debug("executeRequest called: " + cmd.getClass()); if (cmd instanceof NetworkElementCommand) { return vrResource.executeRequest((NetworkElementCommand)cmd); } else if (clazz == NetworkRulesSystemVmCommand.class) { @@ -252,24 +250,24 @@ public Answer executeRequest(Command cmd) { } else if (clazz == RebootCommand.class) { return execute((RebootCommand)cmd); } - LOGGER.debug("Can't find class for executeRequest " + cmd.getClass() + ", is your direct call missing?"); + logger.debug("Can't find class for executeRequest " + cmd.getClass() + ", is your direct call missing?"); return Answer.createUnsupportedCommandAnswer(cmd); } @Override public void disconnected() { - LOGGER.debug("disconnected seems unused everywhere else"); + logger.debug("disconnected seems unused everywhere else"); } @Override public IAgentControl getAgentControl() { - LOGGER.debug("we don't use IAgentControl"); + logger.debug("we don't use IAgentControl"); return null; } @Override public void setAgentControl(IAgentControl agentControl) { - LOGGER.debug("No use in setting IAgentControl"); + logger.debug("No use in setting IAgentControl"); } @Override @@ -299,7 +297,7 @@ public int getRunLevel() { @Override public void setRunLevel(int level) { - LOGGER.debug("runlevel seems unused in other hypervisors"); + logger.debug("runlevel seems unused in other hypervisors"); } /** @@ -307,7 +305,7 @@ public void setRunLevel(int level) { */ @Override public boolean configure(String name, Map params) throws ConfigurationException { - LOGGER.debug("configure " + name + " with params: " + params); + logger.debug("configure " + name + " with params: " + params); /* check if we're primary or not and if we can connect */ try { configuration = new Ovm3Configuration(params); @@ -343,7 +341,7 @@ public boolean configure(String name, Map params) throws Configu } public void setConnection(Connection con) { - LOGGER.debug("override connection: " + con.getIp()); + logger.debug("override connection: " + con.getIp()); c = con; } @@ -377,14 +375,14 @@ public synchronized StartAnswer execute(StartCommand cmd) { String domType = guesttypes.getOvm3GuestType(vmSpec.getOs()); if (domType == null || domType.isEmpty()) { domType = "default"; - LOGGER.debug("VM Virt type missing setting to: " + domType); + logger.debug("VM Virt type missing setting to: " + domType); } else { - LOGGER.debug("VM Virt type set to " + domType + " for " + vmSpec.getOs()); + logger.debug("VM Virt type set to " + domType + " for " + vmSpec.getOs()); } vm.setVmDomainType(domType); if (vmSpec.getBootloader() == BootloaderType.CD) { - LOGGER.warn("CD booting is not supported"); + logger.warn("CD booting is not supported"); } /* * officially CD boot is only supported on HVM, although there is a @@ -422,19 +420,19 @@ public synchronized StartAnswer execute(StartCommand cmd) { /* skip a beat to make sure we didn't miss start */ if (hypervisorsupport.getVmState(vmName) == null && count > 1) { String msg = "VM " + vmName + " went missing on " + configuration.getAgentHostname() + ", returning stopped"; - LOGGER.debug(msg); + logger.debug(msg); state = State.Stopped; return new StartAnswer(cmd, msg); } /* creative fix? */ try { Boolean res = cSp.domrCheckSsh(controlIp); - LOGGER.debug("connected to " + controlIp + " on attempt " + count + " result: " + res); + logger.debug("connected to " + controlIp + " on attempt " + count + " result: " + res); if (res) { break; } } catch (Exception x) { - LOGGER.trace("unable to connect to " + controlIp + " on attempt " + count + " " + x.getMessage(), x); + logger.trace("unable to connect to " + controlIp + " on attempt " + count + " " + x.getMessage(), x); } Thread.sleep(5000); } @@ -449,7 +447,7 @@ public synchronized StartAnswer execute(StartCommand cmd) { state = State.Running; return new StartAnswer(cmd); } catch (Exception e) { - LOGGER.debug("Start vm " + vmName + " failed", e); + logger.debug("Start vm " + vmName + " failed", e); state = State.Stopped; return new StartAnswer(cmd, e.getMessage()); } finally { @@ -473,7 +471,7 @@ public StopAnswer execute(StopCommand cmd) { if (vm == null) { state = State.Stopping; - LOGGER.debug("Unable to get details of vm: " + vmName + ", treating it as Stopping"); + logger.debug("Unable to get details of vm: " + vmName + ", treating it as Stopping"); return new StopAnswer(cmd, "success", true); } String repoId = ovmObject.deDash(vm.getVmRootDiskPoolId()); @@ -483,7 +481,7 @@ public StopAnswer execute(StopCommand cmd) { int tries = 30; while (vms.getRunningVmConfig(vmName) != null && tries > 0) { String msg = "Waiting for " + vmName + " to stop"; - LOGGER.debug(msg); + logger.debug(msg); tries--; Thread.sleep(10 * 1000); } @@ -492,13 +490,13 @@ public StopAnswer execute(StopCommand cmd) { if (vms.getRunningVmConfig(vmName) != null) { String msg = "Stop " + vmName + " failed "; - LOGGER.debug(msg); + logger.debug(msg); return new StopAnswer(cmd, msg, false); } state = State.Stopped; return new StopAnswer(cmd, "success", true); } catch (Exception e) { - LOGGER.debug("Stop " + vmName + " failed ", e); + logger.debug("Stop " + vmName + " failed ", e); return new StopAnswer(cmd, e.getMessage(), false); } finally { if (state != null) { @@ -524,7 +522,7 @@ public RebootAnswer execute(RebootCommand cmd) { Integer vncPort = vm.getVncPort(); return new RebootAnswer(cmd, null, vncPort); } catch (Exception e) { - LOGGER.debug("Reboot " + vmName + " failed", e); + logger.debug("Reboot " + vmName + " failed", e); return new RebootAnswer(cmd, e.getMessage(), false); } finally { hypervisorsupport.setVmState(vmName, State.Running); diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3StorageProcessor.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3StorageProcessor.java index f30df5d74443..d7c2c214f221 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3StorageProcessor.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3StorageProcessor.java @@ -41,7 +41,8 @@ import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -78,7 +79,7 @@ * Storage related bits */ public class Ovm3StorageProcessor implements StorageProcessor { - private final Logger LOGGER = Logger.getLogger(Ovm3StorageProcessor.class); + protected Logger logger = LogManager.getLogger(getClass()); private Connection c; private OvmObject ovmObject = new OvmObject(); private Ovm3StoragePool pool; @@ -92,7 +93,7 @@ public Ovm3StorageProcessor(Connection conn, Ovm3Configuration ovm3config, } public final Answer execute(final CopyCommand cmd) { - LOGGER.debug("execute: "+ cmd.getClass()); + logger.debug("execute: "+ cmd.getClass()); DataTO srcData = cmd.getSrcTO(); DataStoreTO srcStore = srcData.getDataStore(); DataTO destData = cmd.getDestTO(); @@ -111,7 +112,7 @@ public final Answer execute(final CopyCommand cmd) { return cloneVolumeFromBaseTemplate(cmd); } else { msg = "Primary to Primary doesn't match"; - LOGGER.debug(msg); + logger.debug(msg); } } else if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) && (destData.getObjectType() == DataObjectType.SNAPSHOT)) { @@ -126,38 +127,38 @@ public final Answer execute(final CopyCommand cmd) { msg = "Unable to do stuff for " + srcStore.getClass() + ":" + srcData.getObjectType() + " to " + destStore.getClass() + ":" + destData.getObjectType(); - LOGGER.debug(msg); + logger.debug(msg); } } catch (Exception e) { msg = "Catch Exception " + e.getClass().getName() + " for template due to " + e.toString(); - LOGGER.warn(msg, e); + logger.warn(msg, e); return new CopyCmdAnswer(msg); } - LOGGER.warn(msg + " " + cmd.getClass()); + logger.warn(msg + " " + cmd.getClass()); return new CopyCmdAnswer(msg); } public Answer execute(DeleteCommand cmd) { DataTO data = cmd.getData(); String msg; - LOGGER.debug("Deleting object: " + data.getObjectType()); + logger.debug("Deleting object: " + data.getObjectType()); if (data.getObjectType() == DataObjectType.VOLUME) { return deleteVolume(cmd); } else if (data.getObjectType() == DataObjectType.SNAPSHOT) { return deleteSnapshot(cmd); } else if (data.getObjectType() == DataObjectType.TEMPLATE) { msg = "Template deletion is not implemented yet."; - LOGGER.info(msg); + logger.info(msg); } else { msg = data.getObjectType() + " deletion is not implemented yet."; - LOGGER.info(msg); + logger.info(msg); } return new Answer(cmd, false, msg); } public CreateAnswer execute(CreateCommand cmd) { - LOGGER.debug("execute: "+ cmd.getClass()); + logger.debug("execute: "+ cmd.getClass()); StorageFilerTO primaryStorage = cmd.getPool(); DiskProfile disk = cmd.getDiskCharacteristics(); /* disk should have a uuid */ @@ -168,13 +169,13 @@ public CreateAnswer execute(CreateCommand cmd) { try { StoragePlugin store = new StoragePlugin(c); if (cmd.getTemplateUrl() != null) { - LOGGER.debug("CreateCommand " + cmd.getTemplateUrl() + " " + logger.debug("CreateCommand " + cmd.getTemplateUrl() + " " + dst); Linux host = new Linux(c); host.copyFile(cmd.getTemplateUrl(), dst); } else { /* this is a dup with the createVolume ? */ - LOGGER.debug("CreateCommand " + dst); + logger.debug("CreateCommand " + dst); store.storagePluginCreate(primaryStorage.getUuid(), primaryStorage.getHost(), dst, disk.getSize(), false); } @@ -186,7 +187,7 @@ public CreateAnswer execute(CreateCommand cmd) { fp.getSize(), null); return new CreateAnswer(cmd, volume); } catch (Exception e) { - LOGGER.debug("CreateCommand failed", e); + logger.debug("CreateCommand failed", e); return new CreateAnswer(cmd, e.getMessage()); } } @@ -196,7 +197,7 @@ public CreateAnswer execute(CreateCommand cmd) { */ @Override public CopyCmdAnswer copyTemplateToPrimaryStorage(CopyCommand cmd) { - LOGGER.debug("execute copyTemplateToPrimaryStorage: "+ cmd.getClass()); + logger.debug("execute copyTemplateToPrimaryStorage: "+ cmd.getClass()); DataTO srcData = cmd.getSrcTO(); DataStoreTO srcStore = srcData.getDataStore(); DataTO destData = cmd.getDestTO(); @@ -225,7 +226,7 @@ public CopyCmdAnswer copyTemplateToPrimaryStorage(CopyCommand cmd) { + "/" + destUuid + ".raw"; } String destFile = destPath + "/" + destUuid + ".raw"; - LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + logger.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile); host.copyFile(srcFile, destFile); @@ -237,7 +238,7 @@ public CopyCmdAnswer copyTemplateToPrimaryStorage(CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (Ovm3ResourceException e) { String msg = "Error while copying template to primary storage: " + e.getMessage(); - LOGGER.info(msg); + logger.info(msg); return new CopyCmdAnswer(msg); } } @@ -246,7 +247,7 @@ public CopyCmdAnswer copyTemplateToPrimaryStorage(CopyCommand cmd) { */ @Override public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) { - LOGGER.debug("execute copyVolumeFromPrimaryToSecondary: "+ cmd.getClass()); + logger.debug("execute copyVolumeFromPrimaryToSecondary: "+ cmd.getClass()); return new Answer(cmd); } /** @@ -254,7 +255,7 @@ public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) { */ @Override public CopyCmdAnswer cloneVolumeFromBaseTemplate(CopyCommand cmd) { - LOGGER.debug("execute cloneVolumeFromBaseTemplate: "+ cmd.getClass()); + logger.debug("execute cloneVolumeFromBaseTemplate: "+ cmd.getClass()); try { // src DataTO srcData = cmd.getSrcTO(); @@ -266,7 +267,7 @@ public CopyCmdAnswer cloneVolumeFromBaseTemplate(CopyCommand cmd) { VolumeObjectTO dest = (VolumeObjectTO) destData; String destFile = getVirtualDiskPath(dest.getUuid(), dest.getDataStore().getUuid()); Linux host = new Linux(c); - LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + logger.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile); host.copyFile(srcFile, destFile); @@ -278,7 +279,7 @@ public CopyCmdAnswer cloneVolumeFromBaseTemplate(CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (Ovm3ResourceException e) { String msg = "Error cloneVolumeFromBaseTemplate: " + e.getMessage(); - LOGGER.info(msg); + logger.info(msg); return new CopyCmdAnswer(msg); } } @@ -287,7 +288,7 @@ public CopyCmdAnswer cloneVolumeFromBaseTemplate(CopyCommand cmd) { */ @Override public Answer createTemplateFromVolume(CopyCommand cmd) { - LOGGER.debug("execute createTemplateFromVolume: "+ cmd.getClass()); + logger.debug("execute createTemplateFromVolume: "+ cmd.getClass()); return new Answer(cmd); } /** @@ -295,7 +296,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) { */ @Override public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) { - LOGGER.debug("execute copyVolumeFromImageCacheToPrimary: "+ cmd.getClass()); + logger.debug("execute copyVolumeFromImageCacheToPrimary: "+ cmd.getClass()); return new Answer(cmd); } /** @@ -303,7 +304,7 @@ public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) { */ @Override public Answer createTemplateFromSnapshot(CopyCommand cmd) { - LOGGER.debug("execute createTemplateFromSnapshot: "+ cmd.getClass()); + logger.debug("execute createTemplateFromSnapshot: "+ cmd.getClass()); try { // src.getPath contains the uuid of the snapshot. DataTO srcData = cmd.getSrcTO(); @@ -333,7 +334,7 @@ public Answer createTemplateFromSnapshot(CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (Ovm3ResourceException e) { String msg = "Error backupSnapshot: " + e.getMessage(); - LOGGER.info(msg); + logger.info(msg); return new CopyCmdAnswer(msg); } } @@ -344,7 +345,7 @@ public Answer createTemplateFromSnapshot(CopyCommand cmd) { */ @Override public CopyCmdAnswer backupSnapshot(CopyCommand cmd) { - LOGGER.debug("execute backupSnapshot: "+ cmd.getClass()); + logger.debug("execute backupSnapshot: "+ cmd.getClass()); try { DataTO srcData = cmd.getSrcTO(); DataTO destData = cmd.getDestTO(); @@ -366,7 +367,7 @@ public CopyCmdAnswer backupSnapshot(CopyCommand cmd) { Linux host = new Linux(c); CloudstackPlugin csp = new CloudstackPlugin(c); csp.ovsMkdirs(destDir); - LOGGER.debug("CopyFrom: " + srcData.getObjectType() + "," + logger.debug("CopyFrom: " + srcData.getObjectType() + "," + srcFile + " to " + destData.getObjectType() + "," + destFile); host.copyFile(srcFile, destFile); @@ -381,20 +382,20 @@ public CopyCmdAnswer backupSnapshot(CopyCommand cmd) { return new CopyCmdAnswer(newSnap); } catch (Ovm3ResourceException e) { String msg = "Error backupSnapshot: " + e.getMessage(); - LOGGER.info(msg); + logger.info(msg); return new CopyCmdAnswer(msg); } } public Answer execute(CreateObjectCommand cmd) { - LOGGER.debug("execute: "+ cmd.getClass()); + logger.debug("execute: "+ cmd.getClass()); DataTO data = cmd.getData(); if (data.getObjectType() == DataObjectType.VOLUME) { return createVolume(cmd); } else if (data.getObjectType() == DataObjectType.SNAPSHOT) { return createSnapshot(cmd); } else if (data.getObjectType() == DataObjectType.TEMPLATE) { - LOGGER.debug("Template object creation not supported."); + logger.debug("Template object creation not supported."); } return new CreateObjectAnswer(data.getObjectType() + " object creation not supported"); @@ -404,7 +405,7 @@ public Answer execute(CreateObjectCommand cmd) { */ @Override public AttachAnswer attachIso(AttachCommand cmd) { - LOGGER.debug("execute attachIso: "+ cmd.getClass()); + logger.debug("execute attachIso: "+ cmd.getClass()); String vmName = cmd.getVmName(); DiskTO disk = cmd.getDisk(); return attachDetach(cmd, vmName, disk, true); @@ -414,7 +415,7 @@ public AttachAnswer attachIso(AttachCommand cmd) { */ @Override public AttachAnswer dettachIso(DettachCommand cmd) { - LOGGER.debug("execute dettachIso: "+ cmd.getClass()); + logger.debug("execute dettachIso: "+ cmd.getClass()); String vmName = cmd.getVmName(); DiskTO disk = cmd.getDisk(); return attachDetach(cmd, vmName, disk, false); @@ -470,7 +471,7 @@ private AttachAnswer attachDetach(Command cmd, String vmName, DiskTO disk, boolean isAttach) { Xen xen = new Xen(c); String doThis = (isAttach) ? "Attach" : "Dettach"; - LOGGER.debug(doThis + " volume type " + disk.getType() + " " + vmName); + logger.debug(doThis + " volume type " + disk.getType() + " " + vmName); String msg = ""; String path = ""; try { @@ -478,7 +479,7 @@ private AttachAnswer attachDetach(Command cmd, String vmName, DiskTO disk, /* check running */ if (vm == null) { msg = doThis + " can't find VM " + vmName; - LOGGER.debug(msg); + logger.debug(msg); return new AttachAnswer(msg); } if (disk.getType() == Volume.Type.ISO) { @@ -488,7 +489,7 @@ private AttachAnswer attachDetach(Command cmd, String vmName, DiskTO disk, } if ("".equals(path)) { msg = doThis + " can't do anything with an empty path."; - LOGGER.debug(msg); + logger.debug(msg); return new AttachAnswer(msg); } if (isAttach) { @@ -501,7 +502,7 @@ private AttachAnswer attachDetach(Command cmd, String vmName, DiskTO disk, if (!vm.removeDisk(path)) { msg = doThis + " failed for " + vmName + disk.getType() + " was not attached " + path; - LOGGER.debug(msg); + logger.debug(msg); return new AttachAnswer(msg); } } @@ -510,7 +511,7 @@ private AttachAnswer attachDetach(Command cmd, String vmName, DiskTO disk, return new AttachAnswer(disk); } catch (Ovm3ResourceException e) { msg = doThis + " failed for " + vmName + " " + e.getMessage(); - LOGGER.warn(msg, e); + logger.warn(msg, e); return new AttachAnswer(msg); } } @@ -519,7 +520,7 @@ private AttachAnswer attachDetach(Command cmd, String vmName, DiskTO disk, */ @Override public AttachAnswer attachVolume(AttachCommand cmd) { - LOGGER.debug("execute attachVolume: "+ cmd.getClass()); + logger.debug("execute attachVolume: "+ cmd.getClass()); String vmName = cmd.getVmName(); DiskTO disk = cmd.getDisk(); return attachDetach(cmd, vmName, disk, true); @@ -529,7 +530,7 @@ public AttachAnswer attachVolume(AttachCommand cmd) { */ @Override public AttachAnswer dettachVolume(DettachCommand cmd) { - LOGGER.debug("execute dettachVolume: "+ cmd.getClass()); + logger.debug("execute dettachVolume: "+ cmd.getClass()); String vmName = cmd.getVmName(); DiskTO disk = cmd.getDisk(); return attachDetach(cmd, vmName, disk, false); @@ -540,7 +541,7 @@ public AttachAnswer dettachVolume(DettachCommand cmd) { */ @Override public Answer createVolume(CreateObjectCommand cmd) { - LOGGER.debug("execute createVolume: "+ cmd.getClass()); + logger.debug("execute createVolume: "+ cmd.getClass()); DataTO data = cmd.getData(); VolumeObjectTO volume = (VolumeObjectTO) data; try { @@ -567,7 +568,7 @@ public Answer createVolume(CreateObjectCommand cmd) { newVol.setPath(volume.getUuid()); return new CreateObjectAnswer(newVol); } catch (Ovm3ResourceException | URISyntaxException e) { - LOGGER.info("Volume creation failed: " + e.toString(), e); + logger.info("Volume creation failed: " + e.toString(), e); return new CreateObjectAnswer(e.toString()); } } @@ -586,7 +587,7 @@ public Answer createVolume(CreateObjectCommand cmd) { */ @Override public Answer createSnapshot(CreateObjectCommand cmd) { - LOGGER.debug("execute createSnapshot: "+ cmd.getClass()); + logger.debug("execute createSnapshot: "+ cmd.getClass()); DataTO data = cmd.getData(); Xen xen = new Xen(c); SnapshotObjectTO snap = (SnapshotObjectTO) data; @@ -611,7 +612,7 @@ public Answer createSnapshot(CreateObjectCommand cmd) { src = getVirtualDiskPath(vol.getUuid(),data.getDataStore().getUuid()); dest = src.replace(vol.getUuid(), uuid); } - LOGGER.debug("Snapshot " + src + " to " + dest); + logger.debug("Snapshot " + src + " to " + dest); host.copyFile(src, dest); SnapshotObjectTO nsnap = new SnapshotObjectTO(); // nsnap.setPath(dest); @@ -626,7 +627,7 @@ public Answer createSnapshot(CreateObjectCommand cmd) { @Override public Answer deleteVolume(DeleteCommand cmd) { - LOGGER.debug("execute deleteVolume: "+ cmd.getClass()); + logger.debug("execute deleteVolume: "+ cmd.getClass()); DataTO data = cmd.getData(); VolumeObjectTO volume = (VolumeObjectTO) data; try { @@ -635,9 +636,9 @@ public Answer deleteVolume(DeleteCommand cmd) { String path = getVirtualDiskPath(uuid, poolUuid); StoragePlugin sp = new StoragePlugin(c); sp.storagePluginDestroy(poolUuid, path); - LOGGER.debug("Volume deletion success: " + path); + logger.debug("Volume deletion success: " + path); } catch (Ovm3ResourceException e) { - LOGGER.info("Volume deletion failed: " + e.toString(), e); + logger.info("Volume deletion failed: " + e.toString(), e); return new CreateObjectAnswer(e.toString()); } return new Answer(cmd); @@ -648,7 +649,7 @@ public Answer deleteVolume(DeleteCommand cmd) { * bumper bowling. */ public CopyVolumeAnswer execute(CopyVolumeCommand cmd) { - LOGGER.debug("execute: "+ cmd.getClass()); + logger.debug("execute: "+ cmd.getClass()); String volumePath = cmd.getVolumePath(); /* is a repository */ String secondaryStorageURL = cmd.getSecondaryStorageURL(); @@ -662,26 +663,26 @@ public CopyVolumeAnswer execute(CopyVolumeCommand cmd) { /* to secondary storage */ if (cmd.toSecondaryStorage()) { - LOGGER.debug("Copy to secondary storage " + volumePath + logger.debug("Copy to secondary storage " + volumePath + " to " + secondaryStorageURL); host.copyFile(volumePath, secondaryStorageURL); /* from secondary storage */ } else { - LOGGER.debug("Copy from secondary storage " + logger.debug("Copy from secondary storage " + secondaryStorageURL + " to " + volumePath); host.copyFile(secondaryStorageURL, volumePath); } /* check the truth of this */ return new CopyVolumeAnswer(cmd, true, null, null, null); } catch (Ovm3ResourceException e) { - LOGGER.debug("Copy volume failed", e); + logger.debug("Copy volume failed", e); return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null); } } /* Destroy a volume (image) */ public Answer execute(DestroyCommand cmd) { - LOGGER.debug("execute: "+ cmd.getClass()); + logger.debug("execute: "+ cmd.getClass()); VolumeTO vol = cmd.getVolume(); String vmName = cmd.getVmName(); try { @@ -689,7 +690,7 @@ public Answer execute(DestroyCommand cmd) { store.storagePluginDestroy(vol.getPoolUuid(), vol.getPath()); return new Answer(cmd, true, "Success"); } catch (Ovm3ResourceException e) { - LOGGER.debug("Destroy volume " + vol.getName() + " failed for " + logger.debug("Destroy volume " + vol.getName() + " failed for " + vmName + " ", e); return new Answer(cmd, false, e.getMessage()); } @@ -698,7 +699,7 @@ public Answer execute(DestroyCommand cmd) { /* check if a VM is running should be added */ public CreatePrivateTemplateAnswer execute( final CreatePrivateTemplateFromVolumeCommand cmd) { - LOGGER.debug("execute: "+ cmd.getClass()); + logger.debug("execute: "+ cmd.getClass()); String volumePath = cmd.getVolumePath(); Long accountId = cmd.getAccountId(); Long templateId = cmd.getTemplateId(); @@ -717,7 +718,7 @@ public CreatePrivateTemplateAnswer execute( host.copyFile(volumePath, installPath); return new CreatePrivateTemplateAnswer(cmd, true, installPath); } catch (Exception e) { - LOGGER.debug("Create template failed", e); + logger.debug("Create template failed", e); return new CreatePrivateTemplateAnswer(cmd, false, e.getMessage()); } } @@ -727,7 +728,7 @@ public CreatePrivateTemplateAnswer execute( */ @Override public Answer createVolumeFromSnapshot(CopyCommand cmd) { - LOGGER.debug("execute createVolumeFromSnapshot: "+ cmd.getClass()); + logger.debug("execute createVolumeFromSnapshot: "+ cmd.getClass()); try { DataTO srcData = cmd.getSrcTO(); DataStoreTO srcStore = srcData.getDataStore(); @@ -757,7 +758,7 @@ public Answer createVolumeFromSnapshot(CopyCommand cmd) { return new CopyCmdAnswer(newVol); /* we assume the cache for templates is local */ } catch (Ovm3ResourceException e) { - LOGGER.debug("Failed to createVolumeFromSnapshot: ", e); + logger.debug("Failed to createVolumeFromSnapshot: ", e); return new CopyCmdAnswer(e.toString()); } } @@ -767,7 +768,7 @@ public Answer createVolumeFromSnapshot(CopyCommand cmd) { */ @Override public Answer deleteSnapshot(DeleteCommand cmd) { - LOGGER.debug("execute deleteSnapshot: "+ cmd.getClass()); + logger.debug("execute deleteSnapshot: "+ cmd.getClass()); DataTO data = cmd.getData(); SnapshotObjectTO snap = (SnapshotObjectTO) data; String storeUrl = data.getDataStore().getUrl(); @@ -780,10 +781,10 @@ public Answer deleteSnapshot(DeleteCommand cmd) { + snapUuid + ".raw"; StoragePlugin sp = new StoragePlugin(c); sp.storagePluginDestroy(secPoolUuid, filePath); - LOGGER.debug("Snapshot deletion success: " + filePath); + logger.debug("Snapshot deletion success: " + filePath); return new Answer(cmd, true, "Deleted Snapshot " + filePath); } catch (Ovm3ResourceException e) { - LOGGER.info("Snapshot deletion failed: " + e.toString(), e); + logger.info("Snapshot deletion failed: " + e.toString(), e); return new CreateObjectAnswer(e.toString()); } } @@ -792,7 +793,7 @@ public Answer deleteSnapshot(DeleteCommand cmd) { */ @Override public Answer introduceObject(IntroduceObjectCmd cmd) { - LOGGER.debug("execute introduceObject: "+ cmd.getClass()); + logger.debug("execute introduceObject: "+ cmd.getClass()); return new Answer(cmd, false, "not implemented yet"); } /** @@ -800,7 +801,7 @@ public Answer introduceObject(IntroduceObjectCmd cmd) { */ @Override public Answer forgetObject(ForgetObjectCmd cmd) { - LOGGER.debug("execute forgetObject: "+ cmd.getClass()); + logger.debug("execute forgetObject: "+ cmd.getClass()); return new Answer(cmd, false, "not implemented yet"); } @@ -811,14 +812,14 @@ public Answer forgetObject(ForgetObjectCmd cmd) { */ @Override public SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand cmd) { - LOGGER.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for Ovm3StorageProcessor"); + logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for Ovm3StorageProcessor"); return new SnapshotAndCopyAnswer("Not implemented"); } @Override public ResignatureAnswer resignature(final ResignatureCommand cmd) { - LOGGER.info("'ResignatureAnswer resignature(ResignatureCommand)' not currently used for Ovm3StorageProcessor"); + logger.info("'ResignatureAnswer resignature(ResignatureCommand)' not currently used for Ovm3StorageProcessor"); return new ResignatureAnswer("Not implemented"); } @@ -830,13 +831,13 @@ public Answer handleDownloadTemplateToPrimaryStorage(DirectDownloadCommand cmd) @Override public Answer checkDataStoreStoragePolicyCompliance(CheckDataStoreStoragePolicyComplainceCommand cmd) { - LOGGER.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for Ovm3StorageProcessor"); + logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for Ovm3StorageProcessor"); return new Answer(cmd,false,"Not applicable used for Ovm3StorageProcessor"); } @Override public Answer syncVolumePath(SyncVolumePathCommand cmd) { - LOGGER.info("SyncVolumePathCommand not currently applicable for Ovm3StorageProcessor"); + logger.info("SyncVolumePathCommand not currently applicable for Ovm3StorageProcessor"); return new Answer(cmd, false, "Not currently applicable for Ovm3StorageProcessor"); } @@ -851,7 +852,7 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { * @return */ public Answer execute(AttachCommand cmd) { - LOGGER.debug("execute: "+ cmd.getClass()); + logger.debug("execute: "+ cmd.getClass()); String vmName = cmd.getVmName(); DiskTO disk = cmd.getDisk(); return attachDetach(cmd, vmName, disk, true); @@ -863,7 +864,7 @@ public Answer execute(AttachCommand cmd) { * @return */ public Answer execute(DettachCommand cmd) { - LOGGER.debug("execute: "+ cmd.getClass()); + logger.debug("execute: "+ cmd.getClass()); String vmName = cmd.getVmName(); DiskTO disk = cmd.getDisk(); return attachDetach(cmd, vmName, disk, false); diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java index 0e00358e75e8..a3c4e926d085 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3VirtualRoutingResource.java @@ -17,7 +17,8 @@ package com.cloud.hypervisor.ovm3.resources; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.joda.time.Duration; import com.cloud.agent.api.SetupGuestNetworkCommand; @@ -34,8 +35,7 @@ import com.cloud.utils.ExecutionResult; public class Ovm3VirtualRoutingResource implements VirtualRouterDeployer { - private final Logger logger = Logger - .getLogger(Ovm3VirtualRoutingResource.class); + protected Logger logger = LogManager.getLogger(getClass()); private String domRCloudPath = "/opt/cloud/bin/"; private Connection c; private String agentName; diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3Configuration.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3Configuration.java index 9da760b97fb7..ff6583be3ce0 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3Configuration.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3Configuration.java @@ -25,7 +25,8 @@ import javax.naming.ConfigurationException; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.hypervisor.ovm3.objects.Network; import com.cloud.utils.NumbersUtil; @@ -33,8 +34,7 @@ /* holds config data for the Ovm3 Hypervisor */ public class Ovm3Configuration { - private static final Logger LOGGER = Logger - .getLogger(Ovm3Configuration.class); + protected Logger logger = LogManager.getLogger(getClass()); private String agentIp; private Long agentZoneId; private Long agentPodId; @@ -127,11 +127,11 @@ public Ovm3Configuration(Map params) */ private void validatePoolAndCluster() { if (agentInOvm3Cluster) { - LOGGER.debug("Clustering requires a pool, setting pool to true"); + logger.debug("Clustering requires a pool, setting pool to true"); agentInOvm3Pool = true; } if (!NetUtils.isValidIp4(ovm3PoolVip)) { - LOGGER.debug("No VIP, Setting ovm3pool and ovm3cluster to false"); + logger.debug("No VIP, Setting ovm3pool and ovm3cluster to false"); agentInOvm3Pool = false; agentInOvm3Cluster = false; ovm3PoolVip = ""; @@ -450,7 +450,7 @@ public String getTemplateDir() { private String validateParam(String name, String param) throws ConfigurationException { if (param == null) { String msg = "Unable to get " + name + " params are null"; - LOGGER.debug(msg); + logger.debug(msg); throw new ConfigurationException(msg); } return param; diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorNetwork.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorNetwork.java index 387e8bdf1547..6c2f48dbf8de 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorNetwork.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorNetwork.java @@ -21,7 +21,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckNetworkAnswer; @@ -39,8 +40,7 @@ import com.cloud.utils.net.NetUtils; public class Ovm3HypervisorNetwork { - private static final Logger LOGGER = Logger - .getLogger(Ovm3HypervisorNetwork.class); + protected Logger logger = LogManager.getLogger(getClass()); private Connection c; private Ovm3Configuration config; public Ovm3HypervisorNetwork(Connection conn, Ovm3Configuration ovm3config) { @@ -57,12 +57,12 @@ public void configureNetworking() throws ConfigurationException { String controlIface = config.getAgentControlNetworkName(); if (controlIface != null && net.getInterfaceByName(controlIface) == null) { - LOGGER.debug("starting " + controlIface); + logger.debug("starting " + controlIface); net.startOvsLocalConfig(controlIface); /* ovs replies too "fast" so the bridge can be "busy" */ int contCount = 0; while (net.getInterfaceByName(controlIface) == null) { - LOGGER.debug("waiting for " + controlIface); + logger.debug("waiting for " + controlIface); Thread.sleep(1 * 1000); if (contCount > 9) { throw new ConfigurationException("Unable to configure " @@ -72,7 +72,7 @@ public void configureNetworking() throws ConfigurationException { contCount++; } } else { - LOGGER.debug("already have " + controlIface); + logger.debug("already have " + controlIface); } /* * The bridge is remembered upon reboot, but not the IP or the @@ -85,10 +85,10 @@ public void configureNetworking() throws ConfigurationException { cSp.ovsControlInterface(controlIface, NetUtils.getLinkLocalCIDR()); } catch (InterruptedException e) { - LOGGER.error("interrupted?", e); + logger.error("interrupted?", e); } catch (Ovm3ResourceException e) { String msg = "Basic configuration failed on " + config.getAgentHostname(); - LOGGER.error(msg, e); + logger.error(msg, e); throw new ConfigurationException(msg + ", " + e.getMessage()); } } @@ -96,27 +96,27 @@ public void configureNetworking() throws ConfigurationException { /**/ private boolean isNetworkSetupByName(String nameTag) { if (nameTag != null) { - LOGGER.debug("Looking for network setup by name " + nameTag); + logger.debug("Looking for network setup by name " + nameTag); try { Network net = new Network(c); net.getInterfaceList(); if (net.getBridgeByName(nameTag) != null) { - LOGGER.debug("Found bridge with name: " + nameTag); + logger.debug("Found bridge with name: " + nameTag); return true; } } catch (Ovm3ResourceException e) { - LOGGER.debug("Unxpected error looking for name: " + nameTag, e); + logger.debug("Unxpected error looking for name: " + nameTag, e); return false; } } - LOGGER.debug("No bridge with name: " + nameTag); + logger.debug("No bridge with name: " + nameTag); return false; } /* this might have to change in the future, works for now... */ public CheckNetworkAnswer execute(CheckNetworkCommand cmd) { - LOGGER.debug("Checking if network name setup is done on " + logger.debug("Checking if network name setup is done on " + config.getAgentHostname()); List infoList = cmd @@ -141,7 +141,7 @@ public CheckNetworkAnswer execute(CheckNetworkCommand cmd) { + info.getPhysicalNetworkId() + ", Guest Network is not configured on the backend by name " + info.getGuestNetworkName(); - LOGGER.error(msg); + logger.error(msg); return new CheckNetworkAnswer(cmd, false, msg); } if (!isNetworkSetupByName(info.getPrivateNetworkName())) { @@ -149,7 +149,7 @@ public CheckNetworkAnswer execute(CheckNetworkCommand cmd) { + info.getPhysicalNetworkId() + ", Private Network is not configured on the backend by name " + info.getPrivateNetworkName(); - LOGGER.error(msg); + logger.error(msg); return new CheckNetworkAnswer(cmd, false, msg); } if (!isNetworkSetupByName(info.getPublicNetworkName())) { @@ -157,7 +157,7 @@ public CheckNetworkAnswer execute(CheckNetworkCommand cmd) { + info.getPhysicalNetworkId() + ", Public Network is not configured on the backend by name " + info.getPublicNetworkName(); - LOGGER.error(msg); + logger.error(msg); return new CheckNetworkAnswer(cmd, false, msg); } /* Storage network is optional, will revert to private otherwise */ @@ -180,7 +180,7 @@ public Answer execute(PingTestCommand cmd) { } return new Answer(cmd, true, "success"); } catch (Ovm3ResourceException e) { - LOGGER.debug("Ping " + cmd.getComputingHostIp() + " failed", e); + logger.debug("Ping " + cmd.getComputingHostIp() + " failed", e); return new Answer(cmd, false, e.getMessage()); } } @@ -190,7 +190,7 @@ private String createVlanBridge(String networkName, Integer vlanId) if (vlanId < 1 || vlanId > 4094) { String msg = "Incorrect vlan " + vlanId + ", needs to be between 1 and 4094"; - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } Network net = new Network(c); @@ -201,12 +201,12 @@ private String createVlanBridge(String networkName, Integer vlanId) if (net.getInterfaceByName(brName) == null) { net.startOvsVlanBridge(brName, physInterface, vlanId); } else { - LOGGER.debug("Interface " + brName + " already exists"); + logger.debug("Interface " + brName + " already exists"); } } catch (Ovm3ResourceException e) { String msg = "Unable to create vlan " + vlanId.toString() + " bridge for " + networkName; - LOGGER.warn(msg + ": " + e); + logger.warn(msg + ": " + e); throw new CloudRuntimeException(msg + ":" + e.getMessage()); } return brName; diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorSupport.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorSupport.java index 67a63d788f31..3deaea06db94 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorSupport.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3HypervisorSupport.java @@ -26,7 +26,8 @@ import javax.naming.ConfigurationException; import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckHealthAnswer; @@ -63,7 +64,7 @@ import com.trilead.ssh2.SCPClient; public class Ovm3HypervisorSupport { - private final Logger LOGGER = Logger.getLogger(Ovm3HypervisorSupport.class); + protected Logger logger = LogManager.getLogger(getClass()); private Connection c; private Ovm3Configuration config; @@ -162,19 +163,19 @@ public File getSystemVMKeyFile(String filename) { + filename); File keyFile = null; if (keyPath != null) { - LOGGER.debug("found SshKey " + keyPath); + logger.debug("found SshKey " + keyPath); keyFile = new File(keyPath); } if (keyFile == null || !keyFile.exists()) { String key = "client/target/generated-webapp/WEB-INF/classes/scripts/vm/systemvm/" + filename; - LOGGER.warn("findScript failed, going for generated " + key); + logger.warn("findScript failed, going for generated " + key); keyFile = new File(key); } if (keyFile == null || !keyFile.exists()) { String key = "/usr/share/cloudstack-common/scripts/vm/systemvm/" + filename; - LOGGER.warn("generated key retrieval failed " + key); + logger.warn("generated key retrieval failed " + key); keyFile = new File(key); } return keyFile; @@ -190,12 +191,12 @@ public void fillHostInfo(StartupRoutingCommand cmd) { /* get data we need from parts */ Linux host = new Linux(c); if (!host.getOvmVersion().startsWith("3.2.") && !host.getOvmVersion().startsWith("3.3.")) { - LOGGER.error("Hypervisor not supported: " + host.getOvmVersion()); + logger.error("Hypervisor not supported: " + host.getOvmVersion()); throw new CloudRuntimeException( "OVM 3.2. or 3.3. are only supported, not " + host.getOvmVersion()); } else { - LOGGER.debug("Hypervisor version: " + host.getOvmVersion()); + logger.debug("Hypervisor version: " + host.getOvmVersion()); } cmd.setName(host.getHostName()); cmd.setSpeed(host.getCpuKhz()); @@ -249,7 +250,7 @@ public void fillHostInfo(StartupRoutingCommand cmd) { d.put("isprimary", config.getAgentIsPrimary().toString()); d.put("hasprimary", config.getAgentHasPrimary().toString()); cmd.setHostDetails(d); - LOGGER.debug("Add an Ovm3 host " + config.getAgentHostname() + ":" + logger.debug("Add an Ovm3 host " + config.getAgentHostname() + ":" + cmd.getHostDetails()); } catch (Ovm3ResourceException e) { throw new CloudRuntimeException("Ovm3ResourceException: " @@ -266,7 +267,7 @@ public void fillHostInfo(StartupRoutingCommand cmd) { * @throws IOException */ public Boolean setupServer(String key) throws IOException { - LOGGER.debug("Setup all bits on agent: " + config.getAgentHostname()); + logger.debug("Setup all bits on agent: " + config.getAgentHostname()); /* version dependent patching ? */ try { com.trilead.ssh2.Connection sshConnection = SSHCmdHelper @@ -315,7 +316,7 @@ public Boolean setupServer(String key) throws IOException { config.getAgentStorageCheckTimeout(), config.getAgentStorageCheckInterval()); } catch (Exception es) { - LOGGER.error("Unexpected exception ", es); + logger.error("Unexpected exception ", es); String msg = "Unable to install module in agent"; throw new CloudRuntimeException(msg); } @@ -333,7 +334,7 @@ private Map getAllVms() throws Ovm3ResourceException { Xen vms = new Xen(c); return vms.getRunningVmConfigs(); } catch (Exception e) { - LOGGER.debug("getting VM list from " + config.getAgentHostname() + logger.debug("getting VM list from " + config.getAgentHostname() + " failed", e); throw new CloudRuntimeException("Exception on getting VMs from " + config.getAgentHostname() + ":" + e.getMessage(), e); @@ -386,7 +387,7 @@ private Map getAllVmStates(Map vmStateMap) } else { ns = State.Unknown; } - LOGGER.trace("state " + ns + " for " + vm.getVmName() + logger.trace("state " + ns + " for " + vm.getVmName() + " based on " + as); states.put(vm.getVmName(), ns); } @@ -411,7 +412,7 @@ private Map syncState(Map vmStateMap) try { newStates = getAllVmStates(vmStateMap); } catch (Ovm3ResourceException e) { - LOGGER.error("Ovm3 full sync failed: ", e); + logger.error("Ovm3 full sync failed: ", e); throw e; } synchronized (vmStateMap) { @@ -422,41 +423,41 @@ private Map syncState(Map vmStateMap) final String vmName = entry.getKey(); State newState = entry.getValue(); final State oldState = oldStates.remove(vmName); - LOGGER.trace("state for " + vmName + ", old: " + oldState + logger.trace("state for " + vmName + ", old: " + oldState + ", new: " + newState); /* eurh ? */ if (newState == State.Stopped && oldState != State.Stopping && oldState != null && oldState != State.Stopped) { - LOGGER.trace("Getting power state...."); + logger.trace("Getting power state...."); newState = State.Running; } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("VM " + vmName + ": ovm has state " + newState + if (logger.isTraceEnabled()) { + logger.trace("VM " + vmName + ": ovm has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null")); } if (newState == State.Migrating) { - LOGGER.trace(vmName + " is migrating, skipping state check"); + logger.trace(vmName + " is migrating, skipping state check"); continue; } if (oldState == null) { vmStateMap.put(vmName, newState); - LOGGER.debug("New state without old state: " + vmName); + logger.debug("New state without old state: " + vmName); changes.put(vmName, newState); } else if (oldState == State.Starting) { if (newState == State.Running) { vmStateMap.put(vmName, newState); } else if (newState == State.Stopped) { - LOGGER.debug("Ignoring vm " + vmName + logger.debug("Ignoring vm " + vmName + " because of a lag in starting the vm."); } } else if (oldState == State.Migrating) { if (newState == State.Running) { - LOGGER.debug("Detected that a migrating VM is now running: " + logger.debug("Detected that a migrating VM is now running: " + vmName); vmStateMap.put(vmName, newState); } @@ -464,7 +465,7 @@ private Map syncState(Map vmStateMap) if (newState == State.Stopped) { vmStateMap.put(vmName, newState); } else if (newState == State.Running) { - LOGGER.debug("Ignoring vm " + vmName + logger.debug("Ignoring vm " + vmName + " because of a lag in stopping the vm. "); /* should kill it hard perhaps ? */ } @@ -482,27 +483,27 @@ private Map syncState(Map vmStateMap) final State oldState = entry.getValue(); if (oldState == State.Stopping) { - LOGGER.debug("Removing VM " + vmName + logger.debug("Removing VM " + vmName + " in transition state stopping."); vmStateMap.remove(vmName); } else if (oldState == State.Starting) { - LOGGER.debug("Removing VM " + vmName + logger.debug("Removing VM " + vmName + " in transition state starting."); vmStateMap.remove(vmName); } else if (oldState == State.Stopped) { - LOGGER.debug("Stopped VM " + vmName + " removing."); + logger.debug("Stopped VM " + vmName + " removing."); vmStateMap.remove(vmName); } else if (oldState == State.Migrating) { /* * do something smarter here.. newstate should say stopping * already */ - LOGGER.debug("Ignoring VM " + vmName + logger.debug("Ignoring VM " + vmName + " in migrating state."); } else { /* if it's not there name it stopping */ State state = State.Stopping; - LOGGER.debug("VM " + vmName + logger.debug("VM " + vmName + " is now missing from ovm3 server so removing it"); changes.put(vmName, state); vmStateMap.remove(vmName); @@ -536,7 +537,7 @@ public Map hostVmStateReport() throws Ovm3ResourceException { final Map vmStates = new HashMap(); for (final Map.Entry vm : vmStateMap.entrySet()) { - LOGGER.debug("VM " + vm.getKey() + " state: " + vm.getValue() + ":" + logger.debug("VM " + vm.getKey() + " state: " + vm.getValue() + ":" + convertStateToPower(vm.getValue())); vmStates.put(vm.getKey(), new HostVmStateReportEntry( convertStateToPower(vm.getValue()), c.getIp())); @@ -558,14 +559,14 @@ public CheckHealthAnswer execute(CheckHealthCommand cmd) { try { pong = test.echo(ping); } catch (Ovm3ResourceException e) { - LOGGER.debug("CheckHealth went wrong: " + config.getAgentHostname() + logger.debug("CheckHealth went wrong: " + config.getAgentHostname() + ", " + e.getMessage(), e); return new CheckHealthAnswer(cmd, false); } if (ping.contentEquals(pong)) { return new CheckHealthAnswer(cmd, true); } - LOGGER.debug("CheckHealth did not receive " + ping + " but got " + pong + logger.debug("CheckHealth did not receive " + ping + " but got " + pong + " from " + config.getAgentHostname()); return new CheckHealthAnswer(cmd, false); } @@ -577,30 +578,30 @@ public CheckHealthAnswer execute(CheckHealthCommand cmd) { */ public boolean primaryCheck() { if ("".equals(config.getOvm3PoolVip())) { - LOGGER.debug("No cluster vip, not checking for primary"); + logger.debug("No cluster vip, not checking for primary"); return false; } try { CloudstackPlugin cSp = new CloudstackPlugin(c); if (cSp.dom0HasIp(config.getOvm3PoolVip())) { - LOGGER.debug(config.getAgentHostname() + logger.debug(config.getAgentHostname() + " is a primary, already has vip " + config.getOvm3PoolVip()); config.setAgentIsPrimary(true); } else if (cSp.ping(config.getOvm3PoolVip())) { - LOGGER.debug(config.getAgentHostname() + logger.debug(config.getAgentHostname() + " has a primary, someone has vip " + config.getOvm3PoolVip()); config.setAgentHasPrimary(true); } else { - LOGGER.debug(config.getAgentHostname() + logger.debug(config.getAgentHostname() + " becomes a primary, no one has vip " + config.getOvm3PoolVip()); config.setAgentIsPrimary(true); } } catch (Ovm3ResourceException e) { - LOGGER.debug(config.getAgentHostname() + logger.debug(config.getAgentHostname() + " can't reach primary: " + e.getMessage()); config.setAgentHasPrimary(false); } @@ -619,22 +620,22 @@ public ReadyAnswer execute(ReadyCommand cmd) { /* check pool state here */ return new ReadyAnswer(cmd); } else { - LOGGER.debug("Primary IP changes to " + logger.debug("Primary IP changes to " + pool.getPoolPrimaryVip() + ", it should be " + c.getIp()); return new ReadyAnswer(cmd, "I am not the primary server"); } } else if (host.getIsPrimary()) { - LOGGER.debug("Primary, not clustered " + logger.debug("Primary, not clustered " + config.getAgentHostname()); return new ReadyAnswer(cmd); } else { - LOGGER.debug("No primary, not clustered " + logger.debug("No primary, not clustered " + config.getAgentHostname()); return new ReadyAnswer(cmd); } } catch (CloudRuntimeException | Ovm3ResourceException e) { - LOGGER.debug("XML RPC Exception" + e.getMessage(), e); + logger.debug("XML RPC Exception" + e.getMessage(), e); throw new CloudRuntimeException("XML RPC Exception" + e.getMessage(), e); } @@ -644,19 +645,19 @@ public ReadyAnswer execute(ReadyCommand cmd) { /* check "the" virtual machine */ public CheckVirtualMachineAnswer execute( final CheckVirtualMachineCommand cmd) { - LOGGER.debug("CheckVirtualMachineCommand: " + cmd.getVmName()); + logger.debug("CheckVirtualMachineCommand: " + cmd.getVmName()); String vmName = cmd.getVmName(); try { CloudstackPlugin plug = new CloudstackPlugin(c); Integer vncPort = Integer.valueOf(plug.getVncPort(vmName)); if (vncPort == 0) { - LOGGER.warn("No VNC port for " + vmName); + logger.warn("No VNC port for " + vmName); } /* we already have the state ftw */ Map states = getAllVmStates(vmStateMap); State vmState = states.get(vmName); if (vmState == null) { - LOGGER.warn("Check state of " + vmName + logger.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand"); vmState = State.Stopped; } @@ -666,7 +667,7 @@ public CheckVirtualMachineAnswer execute( return new CheckVirtualMachineAnswer(cmd, convertStateToPower(vmState), vncPort); } catch (Ovm3ResourceException e) { - LOGGER.debug("Check migration for " + vmName + " failed", e); + logger.debug("Check migration for " + vmName + " failed", e); return new CheckVirtualMachineAnswer(cmd, convertStateToPower(State.Stopped), null); } @@ -678,13 +679,13 @@ public CheckVirtualMachineAnswer execute( * For now leave it as we're not clustering in OVM terms. */ public MaintainAnswer execute(MaintainCommand cmd) { - LOGGER.debug("MaintainCommand"); + logger.debug("MaintainCommand"); /* * try { * Network net = new Network(c); * net.stopOvsLocalConfig(config.getAgentControlNetworkName()); * } catch (Ovm3ResourceException e) { - * LOGGER.debug("unable to disable " + + * logger.debug("unable to disable " + * config.getAgentControlNetworkName(), e); * } */ @@ -706,7 +707,7 @@ public Answer execute(GetHostStatsCommand cmd) { 0, 0); return new GetHostStatsAnswer(cmd, hostStats); } catch (Exception e) { - LOGGER.debug("Unable to get host stats for: " + cmd.getHostName(), + logger.debug("Unable to get host stats for: " + cmd.getHostName(), e); return new Answer(cmd, false, e.getMessage()); } @@ -716,18 +717,18 @@ public Answer execute(GetHostStatsCommand cmd) { * We rely on storage health with CheckOnHostCommand.... */ public FenceAnswer execute(FenceCommand cmd) { - LOGGER.debug("FenceCommand"); + logger.debug("FenceCommand"); try { Boolean res = false; return new FenceAnswer(cmd, res, res.toString()); } catch (Exception e) { - LOGGER.error("Unable to fence" + cmd.getHostIp(), e); + logger.error("Unable to fence" + cmd.getHostIp(), e); return new FenceAnswer(cmd, false, e.getMessage()); } } public CheckOnHostAnswer execute(CheckOnHostCommand cmd) { - LOGGER.debug("CheckOnHostCommand"); + logger.debug("CheckOnHostCommand"); CloudstackPlugin csp = new CloudstackPlugin(c); try { Boolean alive = csp.dom0CheckStorageHealth(config.getAgentScriptsDir(), @@ -742,7 +743,7 @@ public CheckOnHostAnswer execute(CheckOnHostCommand cmd) { } else { msg = "storage dead for " + cmd.getHost().getGuid(); } - LOGGER.debug(msg); + logger.debug(msg); return new CheckOnHostAnswer(cmd, alive, msg); } catch (Ovm3ResourceException e) { return new CheckOnHostAnswer(cmd, false, "Error while checking storage for " +cmd.getHost().getGuid() +": " + e.getMessage()); diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3StoragePool.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3StoragePool.java index 7626f494bdb4..56b3777f3084 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3StoragePool.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3StoragePool.java @@ -26,7 +26,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -58,8 +59,7 @@ import com.cloud.utils.ssh.SshHelper; public class Ovm3StoragePool { - private static final Logger LOGGER = Logger - .getLogger(Ovm3StoragePool.class); + protected Logger logger = LogManager.getLogger(getClass()); private Connection c; private Ovm3Configuration config; private OvmObject ovmObject = new OvmObject(); @@ -81,7 +81,7 @@ private void setRoles(Pool pool) throws ConfigurationException { } catch (Ovm3ResourceException e) { String msg = "Failed to set server role for host " + config.getAgentHostname() + ": " + e.getMessage(); - LOGGER.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } } @@ -94,12 +94,12 @@ private void setRoles(Pool pool) throws ConfigurationException { */ private void takeOwnership(Pool pool) throws ConfigurationException { try { - LOGGER.debug("Take ownership of host " + config.getAgentHostname()); + logger.debug("Take ownership of host " + config.getAgentHostname()); pool.takeOwnership(config.getAgentOwnedByUuid(), ""); } catch (Ovm3ResourceException e) { String msg = "Failed to take ownership of host " + config.getAgentHostname(); - LOGGER.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } } @@ -113,7 +113,7 @@ private void takeOwnership(Pool pool) throws ConfigurationException { /* FIXME: Placeholders for now, implement later!!!! */ private void takeOwnership33x(Pool pool) throws ConfigurationException { try { - LOGGER.debug("Take ownership of host " + config.getAgentHostname()); + logger.debug("Take ownership of host " + config.getAgentHostname()); String event = "http://localhost:10024/event"; String stats = "http://localhost:10024/stats"; String mgrCert = "None"; @@ -126,7 +126,7 @@ private void takeOwnership33x(Pool pool) throws ConfigurationException { } catch (Ovm3ResourceException e) { String msg = "Failed to take ownership of host " + config.getAgentHostname(); - LOGGER.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } } @@ -146,7 +146,7 @@ public boolean prepareForPool() throws ConfigurationException { /* setup pool and role, needs utility to be able to do things */ if (host.getServerRoles().contentEquals( pool.getValidRoles().toString())) { - LOGGER.info("Server role for host " + config.getAgentHostname() + logger.info("Server role for host " + config.getAgentHostname() + " is ok"); } else { setRoles(pool); @@ -161,19 +161,19 @@ public boolean prepareForPool() throws ConfigurationException { if (host.getManagerUuid().equals(config.getAgentOwnedByUuid())) { String msg = "Host " + config.getAgentHostname() + " owned by us"; - LOGGER.debug(msg); + logger.debug(msg); return true; } else { String msg = "Host " + config.getAgentHostname() + " already part of a pool, and not owned by us"; - LOGGER.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } } } catch (ConfigurationException | Ovm3ResourceException es) { String msg = "Failed to prepare " + config.getAgentHostname() + " for pool: " + es.getMessage(); - LOGGER.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } return true; @@ -203,7 +203,7 @@ private Boolean setupPool(StorageFilerTO cmd) throws Ovm3ResourceException { PoolOCFS2 poolFs = new PoolOCFS2(c); if (config.getAgentIsPrimary()) { try { - LOGGER.debug("Create poolfs on " + config.getAgentHostname() + logger.debug("Create poolfs on " + config.getAgentHostname() + " for repo " + primUuid); /* double check if we're not overwritting anything here!@ */ poolFs.createPoolFs(fsType, mountPoint, clusterUuid, primUuid, @@ -270,7 +270,7 @@ private Boolean addMembers() throws Ovm3ResourceException { members.add(c.getIp()); } } else { - LOGGER.warn(c.getIp() + " noticed primary " + logger.warn(c.getIp() + " noticed primary " + config.getOvm3PoolVip() + " is not part of pool"); return false; } @@ -281,10 +281,10 @@ private Boolean addMembers() throws Ovm3ResourceException { Pool poolM = new Pool(x); if (poolM.isInAPool()) { poolM.setPoolMemberList(members); - LOGGER.debug("Added " + members + " to pool " + logger.debug("Added " + members + " to pool " + poolM.getPoolId() + " on member " + member); } else { - LOGGER.warn(member + logger.warn(member + " unable to be member of a pool it's not in"); return false; } @@ -308,7 +308,7 @@ public Answer execute(DeleteStoragePoolCommand cmd) { pool.leaveServerPool(cmd.getPool().getUuid()); /* also connect to the primary and update the pool list ? */ } catch (Ovm3ResourceException e) { - LOGGER.debug( + logger.debug( "Delete storage pool on host " + config.getAgentHostname() + " failed, however, we leave to user for cleanup and tell management server it succeeded", @@ -342,7 +342,7 @@ private boolean createRepo(StorageFilerTO cmd) throws XmlRpcException { try { repo.mountRepoFs(mountPoint, ovsRepo); } catch (Ovm3ResourceException e) { - LOGGER.debug("Unable to mount NFS repository " + mountPoint + logger.debug("Unable to mount NFS repository " + mountPoint + " on " + ovsRepo + " requested for " + config.getAgentHostname() + ": " + e.getMessage()); } @@ -350,7 +350,7 @@ private boolean createRepo(StorageFilerTO cmd) throws XmlRpcException { repo.addRepo(mountPoint, ovsRepo); repoExists = true; } catch (Ovm3ResourceException e) { - LOGGER.debug("NFS repository " + mountPoint + " on " + ovsRepo + logger.debug("NFS repository " + mountPoint + " on " + ovsRepo + " not found creating repo: " + e.getMessage()); } if (!repoExists) { @@ -364,7 +364,7 @@ private boolean createRepo(StorageFilerTO cmd) throws XmlRpcException { } catch (Ovm3ResourceException e) { msg = "NFS repository " + mountPoint + " on " + ovsRepo + " create failed!"; - LOGGER.debug(msg); + logger.debug(msg); throw new CloudRuntimeException(msg + " " + e.getMessage(), e); } @@ -375,14 +375,14 @@ private boolean createRepo(StorageFilerTO cmd) throws XmlRpcException { try { msg = "Configuring " + config.getAgentHostname() + "(" + config.getAgentIp() + ") for pool"; - LOGGER.debug(msg); + logger.debug(msg); setupPool(cmd); msg = "Configured host for pool"; /* add clustering after pooling */ if (config.getAgentInOvm3Cluster()) { msg = "Setup " + config.getAgentHostname() + "(" + config.getAgentIp() + ") for cluster"; - LOGGER.debug(msg); + logger.debug(msg); /* setup cluster */ /* * From cluster.java @@ -400,7 +400,7 @@ private boolean createRepo(StorageFilerTO cmd) throws XmlRpcException { } } else { msg = "no way dude I can't stand for this"; - LOGGER.debug(msg); + logger.debug(msg); } /* * this is to create the .generic_fs_stamp else we're not allowed to @@ -419,7 +419,7 @@ private boolean createRepo(StorageFilerTO cmd) throws XmlRpcException { } else { msg = "NFS repository " + mountPoint + " on " + ovsRepo + " create failed, was type " + cmd.getType(); - LOGGER.debug(msg); + logger.debug(msg); return false; } @@ -428,7 +428,7 @@ private boolean createRepo(StorageFilerTO cmd) throws XmlRpcException { prepareSecondaryStorageStore(ovsRepo, cmd.getUuid(), cmd.getHost()); } catch (Exception e) { msg = "systemvm.iso copy failed to " + ovsRepo; - LOGGER.debug(msg, e); + logger.debug(msg, e); return false; } return true; @@ -449,7 +449,7 @@ private void prepareSecondaryStorageStore(String storageUrl, try { /* double check */ if (config.getAgentHasPrimary() && config.getAgentInOvm3Pool()) { - LOGGER.debug("Skip systemvm iso copy, leave it to the primary"); + logger.debug("Skip systemvm iso copy, leave it to the primary"); return; } if (lock.lock(3600)) { @@ -466,12 +466,12 @@ private void prepareSecondaryStorageStore(String storageUrl, poolUuid, host, destPath + "/" + srcIso.getName()); if (fp.getSize() != srcIso.getTotalSpace()) { - LOGGER.info(" System VM patch ISO file already exists: " + logger.info(" System VM patch ISO file already exists: " + srcIso.getAbsolutePath().toString() + ", destination: " + destPath); } } catch (Exception e) { - LOGGER.info("Copy System VM patch ISO file to secondary storage. source ISO: " + logger.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + destPath); @@ -484,12 +484,12 @@ private void prepareSecondaryStorageStore(String storageUrl, destPath, srcIso.getAbsolutePath() .toString(), "0644"); } catch (Exception es) { - LOGGER.error("Unexpected exception ", es); + logger.error("Unexpected exception ", es); String msg = "Unable to copy systemvm ISO on secondary storage. src location: " + srcIso.toString() + ", dest location: " + destPath; - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, es); } } @@ -518,7 +518,7 @@ public String setupSecondaryStorage(String url) "Secondary storage host can not be empty!"); } String uuid = ovmObject.newUuid(uri.getHost() + ":" + uri.getPath()); - LOGGER.info("Secondary storage with uuid: " + uuid); + logger.info("Secondary storage with uuid: " + uuid); return setupNfsStorage(uri, uuid); } @@ -549,7 +549,7 @@ private String setupNfsStorage(URI uri, String uuid) } catch (Ovm3ResourceException ec) { msg = "Nfs storage " + uri + " mount on " + mountPoint + " FAILED " + ec.getMessage(); - LOGGER.error(msg); + logger.error(msg); throw ec; } } else { @@ -565,7 +565,7 @@ private String setupNfsStorage(URI uri, String uuid) * @return */ public GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) { - LOGGER.debug("Getting stats for: " + cmd.getStorageId()); + logger.debug("Getting stats for: " + cmd.getStorageId()); try { Linux host = new Linux(c); Linux.FileSystem fs = host.getFileSystemByUuid(cmd.getStorageId(), @@ -577,7 +577,7 @@ public GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) { || fs == null) { String msg = "Null returned when retrieving stats for " + cmd.getStorageId(); - LOGGER.error(msg); + logger.error(msg); return new GetStorageStatsAnswer(cmd, msg); } /* or is it mntUuid ish ? */ @@ -593,14 +593,14 @@ public GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) { if ("".equals(sd.getSize())) { String msg = "No size when retrieving stats for " + cmd.getStorageId(); - LOGGER.debug(msg); + logger.debug(msg); return new GetStorageStatsAnswer(cmd, msg); } long total = Long.parseLong(sd.getSize()); long used = total - Long.parseLong(sd.getFreeSize()); return new GetStorageStatsAnswer(cmd, total, used); } catch (Ovm3ResourceException e) { - LOGGER.debug("GetStorageStatsCommand for " + cmd.getStorageId() + logger.debug("GetStorageStatsCommand for " + cmd.getStorageId() + " failed", e); return new GetStorageStatsAnswer(cmd, e.getMessage()); } @@ -617,18 +617,18 @@ public File getSystemVMPatchIsoFile() { String systemVmIsoPath = Script.findScript("", "vms/" + iso); File isoFile = null; if (systemVmIsoPath != null) { - LOGGER.debug("found systemvm patch iso " + systemVmIsoPath); + logger.debug("found systemvm patch iso " + systemVmIsoPath); isoFile = new File(systemVmIsoPath); } if (isoFile == null || !isoFile.exists()) { String svm = "client/target/generated-webapp/WEB-INF/classes/vms/" + iso; - LOGGER.debug("last resort for systemvm patch iso " + svm); + logger.debug("last resort for systemvm patch iso " + svm); isoFile = new File(svm); } assert isoFile != null; if (!isoFile.exists()) { - LOGGER.error("Unable to locate " + iso + " in your setup at " + logger.error("Unable to locate " + iso + " in your setup at " + isoFile.toString()); } return isoFile; @@ -642,7 +642,7 @@ public File getSystemVMPatchIsoFile() { * @throws XmlRpcException */ private Boolean createOCFS2Sr(StorageFilerTO pool) throws XmlRpcException { - LOGGER.debug("OCFS2 Not implemented yet"); + logger.debug("OCFS2 Not implemented yet"); return false; } @@ -654,7 +654,7 @@ private Boolean createOCFS2Sr(StorageFilerTO pool) throws XmlRpcException { */ public Answer execute(ModifyStoragePoolCommand cmd) { StorageFilerTO pool = cmd.getPool(); - LOGGER.debug("modifying pool " + pool); + logger.debug("modifying pool " + pool); try { if (config.getAgentInOvm3Cluster()) { // no native ovm cluster for now, I got to break it in horrible @@ -679,7 +679,7 @@ public Answer execute(ModifyStoragePoolCommand cmd) { return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported."); } catch (Exception e) { - LOGGER.debug("ModifyStoragePoolCommand failed", e); + logger.debug("ModifyStoragePoolCommand failed", e); return new Answer(cmd, false, e.getMessage()); } } @@ -692,7 +692,7 @@ public Answer execute(ModifyStoragePoolCommand cmd) { */ public Answer execute(CreateStoragePoolCommand cmd) { StorageFilerTO pool = cmd.getPool(); - LOGGER.debug("creating pool " + pool); + logger.debug("creating pool " + pool); try { if (pool.getType() == StoragePoolType.NetworkFilesystem) { createRepo(pool); @@ -707,7 +707,7 @@ public Answer execute(CreateStoragePoolCommand cmd) { return new Answer(cmd, false, "OCFS2 is unsupported at the moment"); } else if (pool.getType() == StoragePoolType.PreSetup) { - LOGGER.warn("pre setup for pool " + pool); + logger.warn("pre setup for pool " + pool); } else { return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported."); @@ -717,7 +717,7 @@ public Answer execute(CreateStoragePoolCommand cmd) { + ", create StoragePool failed due to " + e.toString() + " on host:" + config.getAgentHostname() + " pool: " + pool.getHost() + pool.getPath(); - LOGGER.warn(msg, e); + logger.warn(msg, e); return new Answer(cmd, false, msg); } return new Answer(cmd, true, "success"); @@ -741,7 +741,7 @@ public PrimaryStorageDownloadAnswer execute( repo.importVirtualDisk(tmplturl, image, poolName); return new PrimaryStorageDownloadAnswer(image); } catch (Exception e) { - LOGGER.debug("PrimaryStorageDownloadCommand failed", e); + logger.debug("PrimaryStorageDownloadCommand failed", e); return new PrimaryStorageDownloadAnswer(e.getMessage()); } } diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VirtualRoutingSupport.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VirtualRoutingSupport.java index a9d673958779..b1547e4a20e6 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VirtualRoutingSupport.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VirtualRoutingSupport.java @@ -17,7 +17,8 @@ package com.cloud.hypervisor.ovm3.resources.helpers; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.NetworkRulesSystemVmCommand; @@ -31,8 +32,7 @@ import com.cloud.utils.ExecutionResult; public class Ovm3VirtualRoutingSupport { - private static final Logger LOGGER = Logger - .getLogger(Ovm3VirtualRoutingSupport.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String CREATE = "create"; private static final String SUCCESS = "success"; private final Connection c; @@ -49,8 +49,8 @@ public Answer execute(NetworkUsageCommand cmd) { if (cmd.isForVpc()) { return vpcNetworkUsage(cmd); } - if (LOGGER.isInfoEnabled()) { - LOGGER.info("Executing resource NetworkUsageCommand " + cmd); + if (logger.isInfoEnabled()) { + logger.info("Executing resource NetworkUsageCommand " + cmd); } if (cmd.getOption() != null && CREATE.equals(cmd.getOption())) { String result = networkUsage(cmd.getPrivateIP(), CREATE, null); @@ -101,7 +101,7 @@ private long[] getNetworkStats(String privateIP) { stats[1] += (Long.parseLong(splitResult[i++])); } } catch (Exception e) { - LOGGER.warn( + logger.warn( "Unable to parse return from script return of network usage command: " + e.toString(), e); } @@ -136,7 +136,7 @@ private NetworkUsageAnswer vpcNetworkUsage(NetworkUsageCommand cmd) { args); if (!callResult.isSuccess()) { - LOGGER.error("Unable to execute NetworkUsage command on DomR (" + logger.error("Unable to execute NetworkUsage command on DomR (" + privateIp + "), domR may not be ready yet. failure due to " + callResult.getDetails()); @@ -145,7 +145,7 @@ private NetworkUsageAnswer vpcNetworkUsage(NetworkUsageCommand cmd) { if ("get".equals(option) || "vpn".equals(option)) { String result = callResult.getDetails(); if (result == null || result.isEmpty()) { - LOGGER.error(" vpc network usage get returns empty "); + logger.error(" vpc network usage get returns empty "); } long[] stats = new long[2]; if (result != null) { @@ -182,18 +182,18 @@ public CheckSshAnswer execute(CheckSshCommand cmd) { if (!cSp.dom0CheckPort(privateIp, cmdPort, retries, interval)) { String msg = "Port " + cmdPort + " not reachable for " + vmName + ": " + config.getAgentHostname(); - LOGGER.info(msg); + logger.info(msg); return new CheckSshAnswer(cmd, msg); } } catch (Exception e) { String msg = "Can not reach port " + cmdPort + " on System vm " + vmName + ": " + config.getAgentHostname() + " due to exception: " + e; - LOGGER.error(msg); + logger.error(msg); return new CheckSshAnswer(cmd, msg); } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Ping " + cmdPort + " succeeded for vm " + vmName + if (logger.isDebugEnabled()) { + logger.debug("Ping " + cmdPort + " succeeded for vm " + vmName + ": " + config.getAgentHostname() + " " + cmd); } return new CheckSshAnswer(cmd); diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupport.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupport.java index 1d15261388d0..4dd9f013e40d 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupport.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupport.java @@ -24,7 +24,8 @@ import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -60,7 +61,7 @@ import com.cloud.vm.VirtualMachine.State; public class Ovm3VmSupport { - private final Logger LOGGER = Logger.getLogger(Ovm3VmSupport.class); + protected Logger logger = LogManager.getLogger(getClass()); private OvmObject ovmObject = new OvmObject(); private ResourceManager resourceMgr; private Connection c; @@ -89,7 +90,7 @@ public Boolean createVifs(Xen.Vm vm, VirtualMachineTO spec) NicTO[] nics = spec.getNics(); return createVifs(vm, nics); } else { - LOGGER.info("No nics for vm " + spec.getName()); + logger.info("No nics for vm " + spec.getName()); return false; } } @@ -110,18 +111,18 @@ private Boolean createVif(Xen.Vm vm, NicTO nic) try { String net = network.getNetwork(nic); if (net != null) { - LOGGER.debug("Adding vif " + nic.getDeviceId() + " " + logger.debug("Adding vif " + nic.getDeviceId() + " " + nic.getMac() + " " + net + " to " + vm.getVmName()); vm.addVif(nic.getDeviceId(), net, nic.getMac()); } else { - LOGGER.debug("Unable to add vif " + nic.getDeviceId() + logger.debug("Unable to add vif " + nic.getDeviceId() + " no network for " + vm.getVmName()); return false; } } catch (Exception e) { String msg = "Unable to add vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage(); - LOGGER.debug(msg); + logger.debug(msg); throw new Ovm3ResourceException(msg); } return true; @@ -134,18 +135,18 @@ private Boolean deleteVif(Xen.Vm vm, NicTO nic) try { String net = network.getNetwork(nic); if (net != null) { - LOGGER.debug("Removing vif " + nic.getDeviceId() + " " + " " + logger.debug("Removing vif " + nic.getDeviceId() + " " + " " + nic.getMac() + " " + net + " from " + vm.getVmName()); vm.removeVif(net, nic.getMac()); } else { - LOGGER.debug("Unable to remove vif " + nic.getDeviceId() + logger.debug("Unable to remove vif " + nic.getDeviceId() + " no network for " + vm.getVmName()); return false; } } catch (Exception e) { String msg = "Unable to remove vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage(); - LOGGER.debug(msg); + logger.debug(msg); throw new Ovm3ResourceException(msg); } return true; @@ -154,8 +155,8 @@ private Boolean deleteVif(Xen.Vm vm, NicTO nic) /* Migration should make sure both HVs are the same ? */ public PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) { VirtualMachineTO vm = cmd.getVirtualMachine(); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Preparing host for migrating " + vm.getName()); + if (logger.isDebugEnabled()) { + logger.debug("Preparing host for migrating " + vm.getName()); } NicTO[] nics = vm.getNics(); try { @@ -163,10 +164,10 @@ public PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) { network.getNetwork(nic); } hypervisor.setVmState(vm.getName(), State.Migrating); - LOGGER.debug("VM " + vm.getName() + " is in Migrating state"); + logger.debug("VM " + vm.getName() + " is in Migrating state"); return new PrepareForMigrationAnswer(cmd); } catch (Ovm3ResourceException e) { - LOGGER.error("Catch Exception " + e.getClass().getName() + logger.error("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to: " + e.getMessage()); return new PrepareForMigrationAnswer(cmd, e); } @@ -184,7 +185,7 @@ public MigrateAnswer execute(final MigrateCommand cmd) { * stop the VM. */ String msg = "Migrating " + vmName + " to " + destIp; - LOGGER.info(msg); + logger.info(msg); if (!config.getAgentInOvm3Cluster() && !config.getAgentInOvm3Pool()) { try { Xen xen = new Xen(c); @@ -193,7 +194,7 @@ public MigrateAnswer execute(final MigrateCommand cmd) { if (destHost == null) { msg = "Unable to find migration target host in DB " + destUuid + " with ip " + destIp; - LOGGER.info(msg); + logger.info(msg); return new MigrateAnswer(cmd, false, msg, null); } xen.stopVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), @@ -204,7 +205,7 @@ public MigrateAnswer execute(final MigrateCommand cmd) { } catch (Ovm3ResourceException e) { msg = "Unpooled VM Migrate of " + vmName + " to " + destUuid + " failed due to: " + e.getMessage(); - LOGGER.debug(msg, e); + logger.debug(msg, e); return new MigrateAnswer(cmd, false, msg, null); } finally { /* shouldn't we just reinitialize completely as a last resort ? */ @@ -228,7 +229,7 @@ public MigrateAnswer execute(final MigrateCommand cmd) { } catch (Ovm3ResourceException e) { msg = "Pooled VM Migrate" + ": Migration of " + vmName + " to " + destIp + " failed due to " + e.getMessage(); - LOGGER.debug(msg, e); + logger.debug(msg, e); return new MigrateAnswer(cmd, false, msg, null); } finally { hypervisor.setVmState(vmName, state); @@ -243,10 +244,10 @@ public GetVncPortAnswer execute(GetVncPortCommand cmd) { Xen host = new Xen(c); Xen.Vm vm = host.getRunningVmConfig(cmd.getName()); Integer vncPort = vm.getVncPort(); - LOGGER.debug("get vnc port for " + cmd.getName() + ": " + vncPort); + logger.debug("get vnc port for " + cmd.getName() + ": " + vncPort); return new GetVncPortAnswer(cmd, c.getIp(), vncPort); } catch (Ovm3ResourceException e) { - LOGGER.debug("get vnc port for " + cmd.getName() + " failed", e); + logger.debug("get vnc port for " + cmd.getName() + " failed", e); return new GetVncPortAnswer(cmd, e.getMessage()); } } @@ -263,11 +264,11 @@ private VmStatsEntry getVmStat(String vmName) { } newVmStats = cSp.ovsDomUStats(vmName); } catch (Ovm3ResourceException e) { - LOGGER.info("Unable to retrieve stats from " + vmName, e); + logger.info("Unable to retrieve stats from " + vmName, e); return stats; } if (oldVmStats == null) { - LOGGER.debug("No old stats retrieved stats from " + vmName); + logger.debug("No old stats retrieved stats from " + vmName); stats.setNumCPUs(1); stats.setNetworkReadKBs(0); stats.setNetworkWriteKBs(0); @@ -278,7 +279,7 @@ private VmStatsEntry getVmStat(String vmName) { stats.setCPUUtilization(0); stats.setEntityType("vm"); } else { - LOGGER.debug("Retrieved new stats from " + vmName); + logger.debug("Retrieved new stats from " + vmName); int cpus = Integer.parseInt(newVmStats.get("vcpus")); stats.setNumCPUs(cpus); stats.setNetworkReadKBs(doubleMin(newVmStats.get("rx_bytes"), oldVmStats.get("rx_bytes"))); @@ -322,14 +323,14 @@ public boolean startVm(String repoId, String vmId) throws XmlRpcException { Xen host = new Xen(c); try { if (host.getRunningVmConfig(vmId) == null) { - LOGGER.error("Create VM " + vmId + " first on " + c.getIp()); + logger.error("Create VM " + vmId + " first on " + c.getIp()); return false; } else { - LOGGER.info("VM " + vmId + " exists on " + c.getIp()); + logger.info("VM " + vmId + " exists on " + c.getIp()); } host.startVm(repoId, vmId); } catch (Exception e) { - LOGGER.error("Failed to start VM " + vmId + " on " + c.getIp() + logger.error("Failed to start VM " + vmId + " on " + c.getIp() + " " + e.getMessage()); return false; } @@ -349,7 +350,7 @@ public void cleanup(Xen.Vm vm) { try { cleanupNetwork(vm.getVmVifs()); } catch (XmlRpcException e) { - LOGGER.info("Clean up network for " + vm.getVmName() + " failed", e); + logger.info("Clean up network for " + vm.getVmName() + " failed", e); } String vmName = vm.getVmName(); /* should become a single entity */ @@ -361,7 +362,7 @@ public void cleanup(Xen.Vm vm) { */ public Boolean createVbds(Xen.Vm vm, VirtualMachineTO spec) { if (spec.getDisks() == null) { - LOGGER.info("No disks defined for " + vm.getVmName()); + logger.info("No disks defined for " + vm.getVmName()); return false; } for (DiskTO disk : spec.getDisks()) { @@ -371,7 +372,7 @@ public Boolean createVbds(Xen.Vm vm, VirtualMachineTO spec) { String diskFile = processor.getVirtualDiskPath(vol.getUuid(), vol.getDataStore().getUuid()); vm.addRootDisk(diskFile); vm.setPrimaryPoolUuid(vol.getDataStore().getUuid()); - LOGGER.debug("Adding root disk: " + diskFile); + logger.debug("Adding root disk: " + diskFile); } else if (disk.getType() == Volume.Type.ISO) { DataTO isoTO = disk.getData(); if (isoTO.getPath() != null) { @@ -389,20 +390,20 @@ public Boolean createVbds(Xen.Vm vm, VirtualMachineTO spec) { + template.getPath(); vm.addIso(isoPath); /* check if secondary storage is mounted */ - LOGGER.debug("Adding ISO: " + isoPath); + logger.debug("Adding ISO: " + isoPath); } } else if (disk.getType() == Volume.Type.DATADISK) { VolumeObjectTO vol = (VolumeObjectTO) disk.getData(); String diskFile = processor.getVirtualDiskPath(vol.getUuid(), vol.getDataStore().getUuid()); vm.addDataDisk(diskFile); - LOGGER.debug("Adding data disk: " + logger.debug("Adding data disk: " + diskFile); } else { throw new CloudRuntimeException("Unknown disk type: " + disk.getType()); } } catch (Exception e) { - LOGGER.debug("CreateVbds failed", e); + logger.debug("CreateVbds failed", e); throw new CloudRuntimeException("Exception" + e.getMessage(), e); } } @@ -439,7 +440,7 @@ private Answer plugNunplugNic(NicTO nic, String vmName, Boolean plug) { vm.getVmUuid()); } catch (Ovm3ResourceException e) { String msg = "Unable to execute command due to " + e.toString(); - LOGGER.debug(msg); + logger.debug(msg); return new Answer(null, false, msg); } return new Answer(null, true, "success"); diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/objects/ConnectionTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/objects/ConnectionTest.java index e7a94c9113ae..52215c3cffa0 100644 --- a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/objects/ConnectionTest.java +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/objects/ConnectionTest.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl; @@ -40,7 +39,6 @@ * Connection */ public class ConnectionTest extends Connection { - private final Logger LOGGER = Logger.getLogger(ConnectionTest.class); XmlTestResultTest results = new XmlTestResultTest(); String result; List multiRes = new ArrayList(); @@ -64,13 +62,13 @@ public Object callTimeoutInSec(String method, List params, int timeout, String result = null; if (getMethodResponse(method) != null) { result = getMethodResponse(method); - LOGGER.debug("methodresponse call: " + method + " - " + params); - LOGGER.trace("methodresponse reply: " + result); + logger.debug("methodresponse call: " + method + " - " + params); + logger.trace("methodresponse reply: " + result); } if (result == null && multiRes.size() >= 0) { result = getResult(); - LOGGER.debug("getresult call: " + method + " - " + params); - LOGGER.trace("getresult reply: " + result); + logger.debug("getresult call: " + method + " - " + params); + logger.trace("getresult reply: " + result); } xr.parse(new InputSource(new StringReader(result))); } catch (Exception e) { diff --git a/plugins/hypervisors/ovm3/src/test/resources/scripts/create_pool_cluster.py b/plugins/hypervisors/ovm3/src/test/resources/scripts/create_pool_cluster.py index bba41ab48e05..830dc90caede 100755 --- a/plugins/hypervisors/ovm3/src/test/resources/scripts/create_pool_cluster.py +++ b/plugins/hypervisors/ovm3/src/test/resources/scripts/create_pool_cluster.py @@ -30,7 +30,7 @@ try: if normalRepo: print "normal repo" - # this litterally throws EVERYTHING away on the repo + # this literally throws EVERYTHING away on the repo repoDom = parseString(server.discover_repository_db()) for node in repoDom.getElementsByTagName('Repository'): repoUuid = node.attributes['Uuid'] @@ -38,7 +38,7 @@ localMount = node.getElementsByTagName('Mount_point')[0].firstChild.nodeValue # there is a "strong" relation between repo's and VMs - # onfortunately there is no reference in the vm.cfg + # unfortunately there is no reference in the vm.cfg # or any known info in the configuration of the VM # in which repo it lives.... for dirname, dirnames, filenames in os.walk('%s/VirtualMachines/' % localMount): @@ -146,7 +146,7 @@ journalesize = "" # o2cb is the problem.... /etc/init.d/o2cb - # sets it's config in /etc/sysconfig/o2cb (can be removed) + # sets its config in /etc/sysconfig/o2cb (can be removed) # dmsetup requires the stopping of o2cb first, # then the removal of the config, after which dmsetup # can remove the device from /dev/mapper/ diff --git a/plugins/hypervisors/simulator/pom.xml b/plugins/hypervisors/simulator/pom.xml index fcc1727b81c4..e545f7cd658c 100644 --- a/plugins/hypervisors/simulator/pom.xml +++ b/plugins/hypervisors/simulator/pom.xml @@ -22,7 +22,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml cloud-plugin-hypervisor-simulator diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockAgentManagerImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockAgentManagerImpl.java index e7902ee99c2a..8cb2c32a1c89 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockAgentManagerImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockAgentManagerImpl.java @@ -61,7 +61,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.diagnostics.DiagnosticsAnswer; import org.apache.cloudstack.diagnostics.DiagnosticsCommand; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import javax.inject.Inject; @@ -80,7 +79,6 @@ @Component public class MockAgentManagerImpl extends ManagerBase implements MockAgentManager { - private static final Logger s_logger = Logger.getLogger(MockAgentManagerImpl.class); @Inject DataCenterDao dcDao; @Inject @@ -114,7 +112,7 @@ private Pair getPodCidr(long podId, long dcId) { DataCenterVO zone = dcDao.findById(dcId); if (DataCenter.Type.Edge.equals(zone.getType())) { String subnet = String.format("172.%d.%d.0", random.nextInt(15) + 16, random.nextInt(6) + 1); - s_logger.info(String.format("Pod belongs to an edge zone hence CIDR cannot be found, returning %s/24", subnet)); + logger.info(String.format("Pod belongs to an edge zone hence CIDR cannot be found, returning %s/24", subnet)); return new Pair<>(subnet, 24L); } HashMap> podMap = _podDao.getCurrentPodCidrSubnets(dcId, 0); @@ -123,10 +121,10 @@ private Pair getPodCidr(long podId, long dcId) { Long cidrSize = (Long)cidrPair.get(1); return new Pair(cidrAddress, cidrSize); } catch (PatternSyntaxException e) { - s_logger.error("Exception while splitting pod cidr"); + logger.error("Exception while splitting pod cidr"); return null; } catch (IndexOutOfBoundsException e) { - s_logger.error("Invalid pod cidr. Please check"); + logger.error("Invalid pod cidr. Please check"); return null; } } @@ -191,7 +189,7 @@ public Map> createServerResources(Map> createServerResources(Map params) throws Configu random = SecureRandom.getInstance("SHA1PRNG"); _executor = new ThreadPoolExecutor(1, 5, 1, TimeUnit.DAYS, new LinkedBlockingQueue(), new NamedThreadFactory("Simulator-Agent-Mgr")); } catch (NoSuchAlgorithmException e) { - s_logger.debug("Failed to initialize random:" + e.toString()); + logger.debug("Failed to initialize random:" + e.toString()); return false; } return true; @@ -311,7 +309,7 @@ private void handleSystemVMStop() { try { _resourceMgr.deleteHost(host.getId(), true, true); } catch (Exception e) { - s_logger.debug("Failed to delete host: ", e); + logger.debug("Failed to delete host: ", e); } } } @@ -376,12 +374,12 @@ public void run() { try { _resourceMgr.discoverHosts(cmd); } catch (DiscoveryException e) { - s_logger.debug("Failed to discover host: " + e.toString()); + logger.debug("Failed to discover host: " + e.toString()); CallContext.unregister(); return; } } catch (ConfigurationException e) { - s_logger.debug("Failed to load secondary storage resource: " + e.toString()); + logger.debug("Failed to load secondary storage resource: " + e.toString()); CallContext.unregister(); return; } @@ -399,7 +397,7 @@ public MockHost getHost(String guid) { if (_host != null) { return _host; } else { - s_logger.error("Host with guid " + guid + " was not found"); + logger.error("Host with guid " + guid + " was not found"); return null; } } catch (Exception ex) { @@ -526,8 +524,8 @@ public MaintainAnswer maintain(com.cloud.agent.api.MaintainCommand cmd) { @Override public Answer checkNetworkCommand(CheckNetworkCommand cmd) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Checking if network name setup is done on the resource"); + if (logger.isDebugEnabled()) { + logger.debug("Checking if network name setup is done on the resource"); } return new CheckNetworkAnswer(cmd, true, "Network Setup check by names is done"); } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockNetworkManagerImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockNetworkManagerImpl.java index a71d71f07cb1..9cc8a1c4cf3c 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockNetworkManagerImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockNetworkManagerImpl.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckS2SVpnConnectionsCommand; @@ -64,7 +63,6 @@ import com.cloud.utils.component.ManagerBase; public class MockNetworkManagerImpl extends ManagerBase implements MockNetworkManager { - private static final Logger s_logger = Logger.getLogger(MockVmManagerImpl.class); @Inject MockVMDao _mockVmDao; @@ -137,10 +135,10 @@ public Answer setupPVLAN(PvlanSetupCommand cmd) { public PlugNicAnswer plugNic(PlugNicCommand cmd) { String vmname = cmd.getVmName(); if (_mockVmDao.findByVmName(vmname) != null) { - s_logger.debug("Plugged NIC (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); + logger.debug("Plugged NIC (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); return new PlugNicAnswer(cmd, true, "success"); } - s_logger.error("Plug NIC failed for (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); + logger.error("Plug NIC failed for (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); return new PlugNicAnswer(cmd, false, "failure"); } @@ -148,10 +146,10 @@ public PlugNicAnswer plugNic(PlugNicCommand cmd) { public UnPlugNicAnswer unplugNic(UnPlugNicCommand cmd) { String vmname = cmd.getVmName(); if (_mockVmDao.findByVmName(vmname) != null) { - s_logger.debug("Unplugged NIC (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); + logger.debug("Unplugged NIC (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); return new UnPlugNicAnswer(cmd, true, "success"); } - s_logger.error("Unplug NIC failed for (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); + logger.error("Unplug NIC failed for (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); return new UnPlugNicAnswer(cmd, false, "failure"); } @@ -159,10 +157,10 @@ public UnPlugNicAnswer unplugNic(UnPlugNicCommand cmd) { public ReplugNicAnswer replugNic(ReplugNicCommand cmd) { String vmname = cmd.getVmName(); if (_mockVmDao.findByVmName(vmname) != null) { - s_logger.debug("Replugged NIC (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); + logger.debug("Replugged NIC (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); return new ReplugNicAnswer(cmd, true, "success"); } - s_logger.error("Replug NIC failed for (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); + logger.error("Replug NIC failed for (dev=" + cmd.getNic().getDeviceId() + ", " + cmd.getNic().getIp() + ") into " + cmd.getVmName()); return new ReplugNicAnswer(cmd, false, "failure"); } @@ -236,7 +234,7 @@ public Answer setUpGuestNetwork(SetupGuestNetworkCommand cmd) { return new Answer(cmd, true, "success"); } catch (Exception e) { String msg = "Creating guest network failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(cmd, false, msg); } } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManager.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManager.java index 70066dcf7ddc..a05d7d7ff8d6 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManager.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManager.java @@ -50,6 +50,7 @@ import com.cloud.agent.api.storage.ListVolumeCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; +import com.cloud.agent.api.storage.ResizeVolumeCommand; import com.cloud.utils.component.Manager; public interface MockStorageManager extends Manager { @@ -113,4 +114,6 @@ public interface MockStorageManager extends Manager { public UploadStatusAnswer getUploadStatus(UploadStatusCommand cmd); Answer handleConfigDriveIso(HandleConfigDriveIsoCommand cmd); + + Answer handleResizeVolume(ResizeVolumeCommand cmd); } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManagerImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManagerImpl.java index 27b4a716af1b..461347f47cd2 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManagerImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockStorageManagerImpl.java @@ -32,7 +32,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.storage.command.DeleteCommand; import org.apache.cloudstack.storage.command.DownloadCommand; @@ -79,6 +78,8 @@ import com.cloud.agent.api.storage.ListVolumeCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; +import com.cloud.agent.api.storage.ResizeVolumeAnswer; +import com.cloud.agent.api.storage.ResizeVolumeCommand; import com.cloud.agent.api.to.DataStoreTO; import com.cloud.agent.api.to.NfsTO; import com.cloud.agent.api.to.StorageFilerTO; @@ -108,7 +109,6 @@ @Component public class MockStorageManagerImpl extends ManagerBase implements MockStorageManager { - private static final Logger s_logger = Logger.getLogger(MockStorageManagerImpl.class); @Inject MockStoragePoolDao _mockStoragePoolDao = null; @Inject @@ -1093,7 +1093,7 @@ public Answer ComputeChecksum(ComputeChecksumCommand cmd) { MessageDigest md = MessageDigest.getInstance("md5"); md5 = String.format("%032x", new BigInteger(1, md.digest(cmd.getTemplatePath().getBytes()))); } catch (NoSuchAlgorithmException e) { - s_logger.debug("failed to gernerate md5:" + e.toString()); + logger.debug("failed to gernerate md5:" + e.toString()); } txn.commit(); return new Answer(cmd, true, md5); @@ -1309,4 +1309,32 @@ public UploadStatusAnswer getUploadStatus(UploadStatusCommand cmd) { return new Answer(cmd); } + + @Override + public Answer handleResizeVolume(ResizeVolumeCommand cmd) { + Long currentSize = cmd.getCurrentSize(); + Long newSize = cmd.getNewSize(); + MockStoragePoolVO storagePool = null; + TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB); + try { + txn.start(); + storagePool = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid()); + txn.commit(); + if (storagePool == null) { + return new ResizeVolumeAnswer(cmd, false, "Failed to find storage pool: " + cmd.getPoolUuid()); + } + } catch (Exception ex) { + txn.rollback(); + throw new CloudRuntimeException("Error when finding storage " + cmd.getPoolUuid(), ex); + } finally { + txn.close(); + txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB); + txn.close(); + } + + if (newSize >= currentSize) { + return new ResizeVolumeAnswer(cmd, true, "", newSize); + } + return new ResizeVolumeAnswer(cmd, false, "Failed to resize"); + } } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockVmManagerImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockVmManagerImpl.java index 2ae8e7e86888..953c5792a500 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockVmManagerImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/MockVmManagerImpl.java @@ -26,7 +26,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; @@ -92,7 +91,6 @@ @Component public class MockVmManagerImpl extends ManagerBase implements MockVmManager { - private static final Logger s_logger = Logger.getLogger(MockVmManagerImpl.class); @Inject MockVMDao _mockVmDao = null; @@ -240,12 +238,12 @@ public CheckRouterAnswer checkRouter(final CheckRouterCommand cmd) { final MockVm vm = _mockVmDao.findByVmName(router_name); final String args = vm.getBootargs(); if (args.indexOf("router_pr=100") > 0) { - s_logger.debug("Router priority is for PRIMARY"); + logger.debug("Router priority is for PRIMARY"); final CheckRouterAnswer ans = new CheckRouterAnswer(cmd, "Status: PRIMARY", true); ans.setState(VirtualRouter.RedundantState.PRIMARY); return ans; } else { - s_logger.debug("Router priority is for BACKUP"); + logger.debug("Router priority is for BACKUP"); final CheckRouterAnswer ans = new CheckRouterAnswer(cmd, "Status: BACKUP", true); ans.setState(VirtualRouter.RedundantState.BACKUP); return ans; @@ -438,7 +436,7 @@ public Answer scaleVm(final ScaleVmCommand cmd) { vm.setCpu(cmd.getCpus() * cmd.getMaxSpeed()); vm.setMemory(cmd.getMaxRam()); _mockVmDao.update(vm.getId(), vm); - s_logger.debug("Scaled up VM " + vmName); + logger.debug("Scaled up VM " + vmName); txn.commit(); return new ScaleVmAnswer(cmd, true, null); } catch (final Exception ex) { @@ -453,7 +451,7 @@ public Answer scaleVm(final ScaleVmCommand cmd) { @Override public Answer plugSecondaryIp(final NetworkRulesVmSecondaryIpCommand cmd) { - s_logger.debug("Plugged secondary IP to VM " + cmd.getVmName()); + logger.debug("Plugged secondary IP to VM " + cmd.getVmName()); return new Answer(cmd, true, null); } @@ -462,7 +460,7 @@ public Answer createVmSnapshot(final CreateVMSnapshotCommand cmd) { final String vmName = cmd.getVmName(); final String vmSnapshotName = cmd.getTarget().getSnapshotName(); - s_logger.debug("Created snapshot " + vmSnapshotName + " for vm " + vmName); + logger.debug("Created snapshot " + vmSnapshotName + " for vm " + vmName); return new CreateVMSnapshotAnswer(cmd, cmd.getTarget(), cmd.getVolumeTOs()); } @@ -473,7 +471,7 @@ public Answer deleteVmSnapshot(final DeleteVMSnapshotCommand cmd) { if (_mockVmDao.findByVmName(cmd.getVmName()) == null) { return new DeleteVMSnapshotAnswer(cmd, false, "No VM by name " + cmd.getVmName()); } - s_logger.debug("Removed snapshot " + snapshotName + " of VM " + vm); + logger.debug("Removed snapshot " + snapshotName + " of VM " + vm); return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs()); } @@ -485,7 +483,7 @@ public Answer revertVmSnapshot(final RevertToVMSnapshotCommand cmd) { if (vmVo == null) { return new RevertToVMSnapshotAnswer(cmd, false, "No VM by name " + cmd.getVmName()); } - s_logger.debug("Reverted to snapshot " + snapshot + " of VM " + vm); + logger.debug("Reverted to snapshot " + snapshot + " of VM " + vm); return new RevertToVMSnapshotAnswer(cmd, cmd.getVolumeTOs(), vmVo.getPowerState()); } @@ -571,40 +569,40 @@ private boolean logSecurityGroupAction(final SecurityGroupRulesCmd cmd, final Te boolean updateSeqnoAndSig = false; if (currSeqnum != null) { if (cmd.getSeqNum() > currSeqnum) { - s_logger.info("New seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum); + logger.info("New seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum); updateSeqnoAndSig = true; if (!cmd.getSignature().equals(currSig)) { - s_logger.info("New seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum + " new signature received:" + cmd.getSignature() + " curr=" + + logger.info("New seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum + " new signature received:" + cmd.getSignature() + " curr=" + currSig + ", updated iptables"); action = ", updated iptables"; reason = reason + "seqno_increased_sig_changed"; } else { - s_logger.info("New seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum + " no change in signature:" + cmd.getSignature() + ", do nothing"); + logger.info("New seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum + " no change in signature:" + cmd.getSignature() + ", do nothing"); reason = reason + "seqno_increased_sig_same"; } } else if (cmd.getSeqNum() < currSeqnum) { - s_logger.info("Older seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum + ", do nothing"); + logger.info("Older seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum + ", do nothing"); reason = reason + "seqno_decreased"; } else { if (!cmd.getSignature().equals(currSig)) { - s_logger.info("Identical seqno received: " + cmd.getSeqNum() + " new signature received:" + cmd.getSignature() + " curr=" + currSig + + logger.info("Identical seqno received: " + cmd.getSeqNum() + " new signature received:" + cmd.getSignature() + " curr=" + currSig + ", updated iptables"); action = ", updated iptables"; reason = reason + "seqno_same_sig_changed"; updateSeqnoAndSig = true; } else { - s_logger.info("Identical seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum + " no change in signature:" + cmd.getSignature() + + logger.info("Identical seqno received: " + cmd.getSeqNum() + " curr=" + currSeqnum + " no change in signature:" + cmd.getSignature() + ", do nothing"); reason = reason + "seqno_same_sig_same"; } } } else { - s_logger.info("New seqno received: " + cmd.getSeqNum() + " old=null"); + logger.info("New seqno received: " + cmd.getSeqNum() + " old=null"); updateSeqnoAndSig = true; action = ", updated iptables"; reason = ", seqno_new"; } - s_logger.info("Programmed network rules for vm " + cmd.getVmName() + " seqno=" + cmd.getSeqNum() + " signature=" + cmd.getSignature() + " guestIp=" + + logger.info("Programmed network rules for vm " + cmd.getVmName() + " seqno=" + cmd.getSeqNum() + " signature=" + cmd.getSignature() + " guestIp=" + cmd.getGuestIp() + ", numIngressRules=" + cmd.getIngressRuleSet().size() + ", numEgressRules=" + cmd.getEgressRuleSet().size() + " total cidrs=" + cmd.getTotalNumCidrs() + action + reason); return updateSeqnoAndSig; diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/SimulatorManagerImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/SimulatorManagerImpl.java index 159f22236c27..cb8d71985e34 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/SimulatorManagerImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/agent/manager/SimulatorManagerImpl.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.storage.command.DownloadProgressCommand; import org.apache.cloudstack.storage.command.StorageSubSystemCommand; import org.apache.cloudstack.storage.command.UploadStatusCommand; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; @@ -115,6 +114,7 @@ import com.cloud.agent.api.storage.ListTemplateCommand; import com.cloud.agent.api.storage.ListVolumeCommand; import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; +import com.cloud.agent.api.storage.ResizeVolumeCommand; import com.cloud.api.commands.CleanupSimulatorMockCmd; import com.cloud.api.commands.ConfigureSimulatorCmd; import com.cloud.api.commands.ConfigureSimulatorHAProviderState; @@ -141,7 +141,6 @@ @Component public class SimulatorManagerImpl extends ManagerBase implements SimulatorManager, PluggableService { - private static final Logger s_logger = Logger.getLogger(SimulatorManagerImpl.class); private static final Gson s_gson = GsonHelper.getGson(); @Inject MockVmManager _mockVmMgr; @@ -208,7 +207,7 @@ public List> getCommands() { @DB @Override public Answer simulate(final Command cmd, final String hostGuid) { - s_logger.debug("Simulate command " + cmd); + logger.debug("Simulate command " + cmd); Answer answer = null; Exception exception = null; TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB); @@ -233,7 +232,7 @@ public Answer simulate(final Command cmd, final String hostGuid) { try { info.setTimeout(Integer.valueOf(entry.getValue())); } catch (final NumberFormatException e) { - s_logger.debug("invalid timeout parameter: " + e.toString()); + logger.debug("invalid timeout parameter: " + e.toString()); } } @@ -242,9 +241,9 @@ public Answer simulate(final Command cmd, final String hostGuid) { final int wait = Integer.valueOf(entry.getValue()); Thread.sleep(wait); } catch (final NumberFormatException e) { - s_logger.debug("invalid wait parameter: " + e.toString()); + logger.debug("invalid wait parameter: " + e.toString()); } catch (final InterruptedException e) { - s_logger.debug("thread is interrupted: " + e.toString()); + logger.debug("thread is interrupted: " + e.toString()); } } @@ -442,6 +441,8 @@ public Answer simulate(final Command cmd, final String hostGuid) { answer = _mockVmMgr.fence((FenceCommand)cmd); } else if (cmd instanceof HandleConfigDriveIsoCommand) { answer = _mockStorageMgr.handleConfigDriveIso((HandleConfigDriveIsoCommand)cmd); + } else if (cmd instanceof ResizeVolumeCommand) { + answer = _mockStorageMgr.handleResizeVolume((ResizeVolumeCommand)cmd); } else if (cmd instanceof GetRouterAlertsCommand || cmd instanceof VpnUsersCfgCommand || cmd instanceof RemoteAccessVpnCfgCommand @@ -450,7 +451,7 @@ public Answer simulate(final Command cmd, final String hostGuid) { || cmd instanceof SecStorageFirewallCfgCommand) { answer = new Answer(cmd); } else { - s_logger.error("Simulator does not implement command of type " + cmd.toString()); + logger.error("Simulator does not implement command of type " + cmd.toString()); answer = Answer.createUnsupportedCommandAnswer(cmd); } } @@ -462,11 +463,11 @@ public Answer simulate(final Command cmd, final String hostGuid) { } } - s_logger.debug("Finished simulate command " + cmd); + logger.debug("Finished simulate command " + cmd); return answer; } catch (final Exception e) { - s_logger.error("Failed execute cmd: ", e); + logger.error("Failed execute cmd: ", e); txn.rollback(); return new Answer(cmd, false, e.toString()); } finally { diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/CleanupSimulatorMockCmd.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/CleanupSimulatorMockCmd.java index 3aabb41f9b9e..ad2f78a1271d 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/CleanupSimulatorMockCmd.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/CleanupSimulatorMockCmd.java @@ -30,14 +30,12 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = "cleanupSimulatorMock", description="cleanup simulator mock", responseObject=SuccessResponse.class) public class CleanupSimulatorMockCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CleanupSimulatorMockCmd.class.getName()); private static final String s_name = "cleanupsimulatormockresponse"; @Inject SimulatorManager _simMgr; diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/ConfigureSimulatorCmd.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/ConfigureSimulatorCmd.java index 2aa666a69fc8..316fef976434 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/ConfigureSimulatorCmd.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/ConfigureSimulatorCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -42,7 +41,6 @@ @APICommand(name = "configureSimulator", description = "configure simulator", responseObject = MockResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigureSimulatorCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ConfigureSimulatorCmd.class.getName()); private static final String s_name = "configuresimulatorresponse"; @Inject diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/QuerySimulatorMockCmd.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/QuerySimulatorMockCmd.java index 15ee7f723c3d..98d70b953562 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/QuerySimulatorMockCmd.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/api/commands/QuerySimulatorMockCmd.java @@ -31,14 +31,12 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = "querySimulatorMock", description="query simulator mock", responseObject=MockResponse.class) public class QuerySimulatorMockCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuerySimulatorMockCmd.class.getName()); private static final String s_name = "querysimulatormockresponse"; @Inject SimulatorManager _simMgr; diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/ha/SimulatorFencer.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/ha/SimulatorFencer.java index c776edfde353..b37960e26ab9 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/ha/SimulatorFencer.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/ha/SimulatorFencer.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.FenceAnswer; @@ -39,7 +38,6 @@ import com.cloud.vm.VirtualMachine; public class SimulatorFencer extends AdapterBase implements FenceBuilder { - private static final Logger s_logger = Logger.getLogger(SimulatorFencer.class); @Inject HostDao _hostDao; @Inject AgentManager _agentMgr; @@ -70,7 +68,7 @@ public SimulatorFencer() { @Override public Boolean fenceOff(VirtualMachine vm, Host host) { if (host.getHypervisorType() != HypervisorType.Simulator) { - s_logger.debug("Don't know how to fence non simulator hosts " + host.getHypervisorType()); + logger.debug("Don't know how to fence non simulator hosts " + host.getHypervisorType()); return null; } @@ -89,13 +87,13 @@ public Boolean fenceOff(VirtualMachine vm, Host host) { try { answer = (FenceAnswer)_agentMgr.send(h.getId(), fence); } catch (AgentUnavailableException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); + if (logger.isDebugEnabled()) { + logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); } continue; } catch (OperationTimedoutException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); + if (logger.isDebugEnabled()) { + logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); } continue; } @@ -105,8 +103,8 @@ public Boolean fenceOff(VirtualMachine vm, Host host) { } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString()); } return false; diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/ha/SimulatorInvestigator.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/ha/SimulatorInvestigator.java index 8996d5af91c4..56a5b08810be 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/ha/SimulatorInvestigator.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/ha/SimulatorInvestigator.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.ha.HAManager; import com.cloud.agent.AgentManager; @@ -42,7 +41,6 @@ import com.cloud.vm.VirtualMachine.PowerState; public class SimulatorInvestigator extends AdapterBase implements Investigator { - private final static Logger s_logger = Logger.getLogger(SimulatorInvestigator.class); @Inject AgentManager _agentMgr; @Inject @@ -77,7 +75,7 @@ public Status isAgentAlive(Host agent) { return answer.getResult() ? Status.Up : Status.Down; } } catch (Exception e) { - s_logger.debug("Failed to send command to host: " + neighbor.getId()); + logger.debug("Failed to send command to host: " + neighbor.getId()); } } @@ -93,17 +91,17 @@ public boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM { try { Answer answer = _agentMgr.send(vm.getHostId(), cmd); if (!answer.getResult()) { - s_logger.debug("Unable to get vm state on " + vm.toString()); + logger.debug("Unable to get vm state on " + vm.toString()); throw new UnknownVM(); } CheckVirtualMachineAnswer cvmAnswer = (CheckVirtualMachineAnswer)answer; - s_logger.debug("Agent responded with state " + cvmAnswer.getState().toString()); + logger.debug("Agent responded with state " + cvmAnswer.getState().toString()); return cvmAnswer.getState() == PowerState.PowerOn; } catch (AgentUnavailableException e) { - s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage()); + logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage()); throw new UnknownVM(); } catch (OperationTimedoutException e) { - s_logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage()); + logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage()); throw new UnknownVM(); } } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentResourceBase.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentResourceBase.java index cf4b40e14265..b87315b2460c 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentResourceBase.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentResourceBase.java @@ -31,7 +31,8 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -50,7 +51,7 @@ import com.cloud.utils.component.ComponentContext; public class AgentResourceBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(AgentResourceBase.class); + protected Logger logger = LogManager.getLogger(getClass()); protected String _name; private List _warnings = new LinkedList(); @@ -71,8 +72,8 @@ public class AgentResourceBase implements ServerResource { public AgentResourceBase(long instanceId, AgentType agentType, SimulatorManager simMgr, String hostGuid) { _instanceId = instanceId; - if (s_logger.isDebugEnabled()) { - s_logger.info("New Routing host instantiated with guid:" + hostGuid); + if (logger.isDebugEnabled()) { + logger.info("New Routing host instantiated with guid:" + hostGuid); } if (agentType == AgentType.Routing) { @@ -101,8 +102,8 @@ protected long getInstanceId() { } public AgentResourceBase() { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Deserializing simulated agent on reconnect"); + if (logger.isDebugEnabled()) { + logger.debug("Deserializing simulated agent on reconnect"); } } @@ -129,8 +130,8 @@ public boolean configure(String name, Map params) throws Configu } private void reconnect(MockHost host) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Reconfiguring existing simulated host w/ name: " + host.getName() + " and guid: " + host.getGuid()); + if (logger.isDebugEnabled()) { + logger.debug("Reconfiguring existing simulated host w/ name: " + host.getName() + " and guid: " + host.getGuid()); } this.agentHost = host; } @@ -230,12 +231,12 @@ public void setAgentControl(IAgentControl agentControl) { } protected String findScript(String script) { - s_logger.debug("Looking for " + script + " in the classpath"); + logger.debug("Looking for " + script + " in the classpath"); URL url = ClassLoader.getSystemResource(script); File file = null; if (url == null) { file = new File("./" + script); - s_logger.debug("Looking for " + script + " in " + file.getAbsolutePath()); + logger.debug("Looking for " + script + " in " + file.getAbsolutePath()); if (!file.exists()) { return null; } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentRoutingResource.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentRoutingResource.java index 2c8e73126320..80ced4c230db 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentRoutingResource.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentRoutingResource.java @@ -24,7 +24,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckVirtualMachineAnswer; @@ -63,7 +62,6 @@ import com.google.gson.stream.JsonReader; public class AgentRoutingResource extends AgentStorageResource { - private static final Logger s_logger = Logger.getLogger(AgentRoutingResource.class); private static final Gson s_gson = GsonHelper.getGson(); private Map> _runningVms = new HashMap>(); @@ -136,7 +134,7 @@ public PingCommand getCurrentStatus(long id) { try { clz = Class.forName(objectType); } catch (ClassNotFoundException e) { - s_logger.info("[ignored] ping returned class", e); + logger.info("[ignored] ping returned class", e); } if (clz != null) { StringReader reader = new StringReader(objectData); @@ -303,7 +301,7 @@ private Answer execute(ShutdownCommand cmd) { @Override public boolean configure(String name, Map params) throws ConfigurationException { if (!super.configure(name, params)) { - s_logger.warn("Base class was unable to configure"); + logger.warn("Base class was unable to configure"); return false; } return true; diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentStorageResource.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentStorageResource.java index c8f4701df9c1..d9bcf0b74a4e 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentStorageResource.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/AgentStorageResource.java @@ -21,7 +21,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.storage.resource.SecondaryStorageResource; @@ -40,7 +39,6 @@ import com.cloud.vm.SecondaryStorageVm; public class AgentStorageResource extends AgentResourceBase implements SecondaryStorageResource { - private static final Logger s_logger = Logger.getLogger(AgentStorageResource.class); final protected String _parent = "/mnt/SecStorage"; protected String _role; @@ -101,7 +99,7 @@ public StartupCommand[] initialize() { @Override public boolean configure(String name, Map params) throws ConfigurationException { if (!super.configure(name, params)) { - s_logger.warn("Base class was unable to configure"); + logger.warn("Base class was unable to configure"); return false; } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorDiscoverer.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorDiscoverer.java index 8f1b07f027b6..37b1ca3e4a80 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorDiscoverer.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorDiscoverer.java @@ -27,7 +27,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -53,7 +52,6 @@ import com.cloud.storage.dao.VMTemplateZoneDao; public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(SimulatorDiscoverer.class); @Inject HostDao _hostDao; @@ -92,8 +90,8 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L if (scheme.equals("http")) { if (host == null || !host.startsWith("sim")) { String msg = "uri is not of simulator type so we're not taking care of the discovery for this: " + uri; - if (s_logger.isDebugEnabled()) { - s_logger.debug(msg); + if (logger.isDebugEnabled()) { + logger.debug(msg); } return null; } @@ -119,8 +117,8 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L } } else { String msg = "uriString is not http so we're not taking care of the discovery for this: " + uri; - if (s_logger.isDebugEnabled()) { - s_logger.debug(msg); + if (logger.isDebugEnabled()) { + logger.debug(msg); } return null; } @@ -128,15 +126,15 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L String cluster = null; if (clusterId == null) { String msg = "must specify cluster Id when adding host"; - if (s_logger.isDebugEnabled()) { - s_logger.debug(msg); + if (logger.isDebugEnabled()) { + logger.debug(msg); } throw new RuntimeException(msg); } else { ClusterVO clu = _clusterDao.findById(clusterId); if (clu == null || (clu.getHypervisorType() != HypervisorType.Simulator)) { - if (s_logger.isInfoEnabled()) - s_logger.info("invalid cluster id or cluster is not for Simulator hypervisors"); + if (logger.isInfoEnabled()) + logger.info("invalid cluster id or cluster is not for Simulator hypervisors"); return null; } cluster = Long.toString(clusterId); @@ -149,8 +147,8 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L String pod; if (podId == null) { String msg = "must specify pod Id when adding host"; - if (s_logger.isDebugEnabled()) { - s_logger.debug(msg); + if (logger.isDebugEnabled()) { + logger.debug(msg); } throw new RuntimeException(msg); } else { @@ -174,17 +172,17 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L resources = createAgentResources(params); return resources; } catch (Exception ex) { - s_logger.error("Exception when discovering simulator hosts: " + ex.getMessage()); + logger.error("Exception when discovering simulator hosts: " + ex.getMessage()); } return null; } private Map> createAgentResources(Map params) { try { - s_logger.info("Creating Simulator Resources"); + logger.info("Creating Simulator Resources"); return _mockAgentMgr.createServerResources(params); } catch (Exception ex) { - s_logger.warn("Caught exception at agent resource creation: " + ex.getMessage(), ex); + logger.warn("Caught exception at agent resource creation: " + ex.getMessage(), ex); } return null; } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorSecondaryDiscoverer.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorSecondaryDiscoverer.java index e09a5a950a40..ec5ee9413994 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorSecondaryDiscoverer.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorSecondaryDiscoverer.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; import org.apache.cloudstack.storage.resource.SecondaryStorageDiscoverer; import org.apache.cloudstack.storage.resource.SecondaryStorageResource; -import org.apache.log4j.Logger; import com.cloud.agent.Listener; import com.cloud.agent.api.AgentControlAnswer; @@ -45,7 +44,6 @@ import com.cloud.storage.dao.SnapshotDao; public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer implements ResourceStateAdapter, Listener { - private static final Logger s_logger = Logger.getLogger(SimulatorSecondaryDiscoverer.class); @Inject MockStorageManager _mockStorageMgr = null; @Inject @@ -69,7 +67,7 @@ public boolean configure(String name, Map params) throws Configu public Map> find(long dcId, Long podId, Long clusterId, URI uri, String username, String password, List hostTags) { if (!uri.getScheme().equalsIgnoreCase("sim")) { - s_logger.debug("It's not NFS or file or ISO, so not a secondary storage server: " + uri.toString()); + logger.debug("It's not NFS or file or ISO, so not a secondary storage server: " + uri.toString()); return null; } List stores = imageStoreDao.listImageStores(); diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorStorageProcessor.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorStorageProcessor.java index 8c8815cc08ac..5e0ee17bb8a9 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorStorageProcessor.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/resource/SimulatorStorageProcessor.java @@ -23,7 +23,8 @@ import java.util.UUID; import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.storage.command.AttachAnswer; import org.apache.cloudstack.storage.command.AttachCommand; @@ -57,7 +58,7 @@ public class SimulatorStorageProcessor implements StorageProcessor { - private static final Logger s_logger = Logger.getLogger(SimulatorStorageProcessor.class); + protected Logger logger = LogManager.getLogger(getClass()); protected SimulatorManager hypervisorResource; public SimulatorStorageProcessor(SimulatorManager resource) { @@ -66,14 +67,14 @@ public SimulatorStorageProcessor(SimulatorManager resource) { @Override public SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand cmd) { - s_logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for SimulatorStorageProcessor"); + logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for SimulatorStorageProcessor"); return new SnapshotAndCopyAnswer(); } @Override public ResignatureAnswer resignature(ResignatureCommand cmd) { - s_logger.info("'ResignatureAnswer resignature(ResignatureCommand)' not currently used for SimulatorStorageProcessor"); + logger.info("'ResignatureAnswer resignature(ResignatureCommand)' not currently used for SimulatorStorageProcessor"); return new ResignatureAnswer(); } diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/MockStoragePoolVO.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/MockStoragePoolVO.java index 46cd0e47a7b6..385ed3273ac1 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/MockStoragePoolVO.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/MockStoragePoolVO.java @@ -17,14 +17,14 @@ package com.cloud.simulator; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import com.cloud.util.StoragePoolTypeConverter; import org.apache.cloudstack.api.InternalIdentity; import com.cloud.storage.Storage.StoragePoolType; @@ -50,7 +50,7 @@ public class MockStoragePoolVO implements InternalIdentity { private String hostGuid; @Column(name = "pool_type") - @Enumerated(value = EnumType.STRING) + @Convert(converter = StoragePoolTypeConverter.class) private StoragePoolType poolType; public MockStoragePoolVO() { diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/dao/MockConfigurationDaoImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/dao/MockConfigurationDaoImpl.java index e3c50fddcd79..f763a2aa0e5e 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/dao/MockConfigurationDaoImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/dao/MockConfigurationDaoImpl.java @@ -21,7 +21,6 @@ import java.util.Formatter; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.simulator.MockConfigurationVO; @@ -32,7 +31,6 @@ @Component public class MockConfigurationDaoImpl extends GenericDaoBase implements MockConfigurationDao { - final static Logger s_logger = Logger.getLogger(MockConfigurationDaoImpl.class); private final SearchBuilder _searchByDcIdName; private final SearchBuilder _searchByDcIDPodIdName; private final SearchBuilder _searchByDcIDPodIdClusterIdName; @@ -139,7 +137,7 @@ public MockConfigurationVO findByNameBottomUP(Long dcId, Long podId, Long cluste return toEntityBean(rs, false); } } catch (Exception e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "error while executing dynamically build search: " + e.getLocalizedMessage()); } return null; diff --git a/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/dao/MockStoragePoolDaoImpl.java b/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/dao/MockStoragePoolDaoImpl.java index ea9bcc4063cb..c656b84289d2 100644 --- a/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/dao/MockStoragePoolDaoImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/com/cloud/simulator/dao/MockStoragePoolDaoImpl.java @@ -52,7 +52,7 @@ public MockStoragePoolDaoImpl() { public MockStoragePoolVO findByHost(String hostUuid) { SearchCriteria sc = hostguidSearch.create(); sc.setParameters("hostguid", hostUuid); - sc.setParameters("type", StoragePoolType.Filesystem.toString()); + sc.setParameters("type", StoragePoolType.Filesystem); return findOneBy(sc); } diff --git a/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/ha/SimulatorHAProvider.java b/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/ha/SimulatorHAProvider.java index 7d35cfb8899c..386b32fabf08 100644 --- a/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/ha/SimulatorHAProvider.java +++ b/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/ha/SimulatorHAProvider.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.ha; import com.cloud.api.response.SimulatorHAStateResponse; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.host.Host; import com.cloud.hypervisor.Hypervisor; import com.cloud.utils.fsm.StateListener; @@ -30,7 +31,6 @@ import org.joda.time.DateTime; import javax.inject.Inject; -import java.security.InvalidParameterException; import java.util.Collections; import java.util.List; import java.util.Map; @@ -129,7 +129,7 @@ public Object getConfigValue(final HAProvider.HAProviderConfig name, final Host case RecoveryWaitTimeout: return 1L; default: - throw new InvalidParameterException("Unknown HAProviderConfig " + name.toString()); + throw new InvalidParameterValueException("Unknown HAProviderConfig " + name.toString()); } } diff --git a/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java b/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java index f50514364941..ebdef1d76d1e 100644 --- a/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java @@ -24,7 +24,6 @@ import javax.inject.Inject; import org.apache.cloudstack.storage.command.CommandResult; -import org.apache.log4j.Logger; import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; @@ -48,7 +47,6 @@ import com.cloud.storage.dao.VolumeDao; public class SimulatorImageStoreDriverImpl extends NfsImageStoreDriverImpl { - private static final Logger s_logger = Logger.getLogger(SimulatorImageStoreDriverImpl.class); @Inject TemplateDataStoreDao _templateStoreDao; @@ -114,7 +112,7 @@ public String createEntityExtractUrl(DataStore store, String installPath, Storag EndPoint ep = _epSelector.select(store); if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); return null; } // Create Symlink at ssvm diff --git a/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SimulatorImageStoreLifeCycleImpl.java b/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SimulatorImageStoreLifeCycleImpl.java index edf1e2893a72..4db2a10210d1 100644 --- a/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SimulatorImageStoreLifeCycleImpl.java +++ b/plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SimulatorImageStoreLifeCycleImpl.java @@ -26,7 +26,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -45,7 +46,7 @@ import com.cloud.utils.UriUtils; public class SimulatorImageStoreLifeCycleImpl implements ImageStoreLifeCycle { - private static final Logger s_logger = Logger.getLogger(SimulatorImageStoreLifeCycleImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject ImageStoreHelper imageStoreHelper; @@ -65,7 +66,7 @@ public DataStore initialize(Map dsInfos) { DataStoreRole role = (DataStoreRole)dsInfos.get("role"); Map details = (Map)dsInfos.get("details"); - s_logger.info("Trying to add a new data store at " + url + " to data center " + dcId); + logger.info("Trying to add a new data store at " + url + " to data center " + dcId); URI uri; try { diff --git a/plugins/hypervisors/simulator/src/main/resources/META-INF/cloudstack/simulator-discoverer/spring-simulator-discover-context.xml b/plugins/hypervisors/simulator/src/main/resources/META-INF/cloudstack/simulator-discoverer/spring-simulator-discover-context.xml index 20331bc69ac5..84f9f20471cc 100644 --- a/plugins/hypervisors/simulator/src/main/resources/META-INF/cloudstack/simulator-discoverer/spring-simulator-discover-context.xml +++ b/plugins/hypervisors/simulator/src/main/resources/META-INF/cloudstack/simulator-discoverer/spring-simulator-discover-context.xml @@ -32,5 +32,5 @@ - + diff --git a/plugins/hypervisors/ucs/pom.xml b/plugins/hypervisors/ucs/pom.xml index da2155a45547..bb9b02f4fb29 100644 --- a/plugins/hypervisors/ucs/pom.xml +++ b/plugins/hypervisors/ucs/pom.xml @@ -23,7 +23,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml cloud-plugin-hypervisor-ucs diff --git a/plugins/hypervisors/ucs/src/main/java/com/cloud/ucs/manager/UcsManagerImpl.java b/plugins/hypervisors/ucs/src/main/java/com/cloud/ucs/manager/UcsManagerImpl.java index 031d1c63c731..6127ed012f35 100644 --- a/plugins/hypervisors/ucs/src/main/java/com/cloud/ucs/manager/UcsManagerImpl.java +++ b/plugins/hypervisors/ucs/src/main/java/com/cloud/ucs/manager/UcsManagerImpl.java @@ -41,7 +41,8 @@ import org.apache.cloudstack.api.response.UcsProfileResponse; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.configuration.Config; import com.cloud.dc.ClusterDetailsDao; @@ -67,7 +68,7 @@ import com.cloud.utils.xmlobject.XmlObjectParser; public class UcsManagerImpl implements UcsManager { - public static final Logger s_logger = Logger.getLogger(UcsManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final Long COOKIE_TTL = TimeUnit.MILLISECONDS.convert(100L, TimeUnit.MINUTES); public static final Long COOKIE_REFRESH_TTL = TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES); @@ -110,7 +111,7 @@ private void discoverNewBlades(Map previous, Map previous, Map - + diff --git a/plugins/hypervisors/vmware/pom.xml b/plugins/hypervisors/vmware/pom.xml index 5dcecfae9c5a..dac359b30a28 100644 --- a/plugins/hypervisors/vmware/pom.xml +++ b/plugins/hypervisors/vmware/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java index 6d04167b748a..91a77393cc92 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteCiscoNexusVSMCmd.class.getName()); @Inject CiscoNexusVSMElementService _ciscoNexusVSMService; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java index 75850edb1c9e..8708a653b1fb 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DisableCiscoNexusVSMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableCiscoNexusVSMCmd.class.getName()); @Inject CiscoNexusVSMElementService _ciscoNexusVSMService; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java index 862f7d1e9be9..14a682a22610 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java @@ -19,7 +19,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class EnableCiscoNexusVSMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(EnableCiscoNexusVSMCmd.class.getName()); @Inject CiscoNexusVSMElementService _ciscoNexusVSMService; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java index f6604b4b9426..d73d4392ad5a 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java @@ -22,7 +22,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -56,7 +55,6 @@ public class ListCiscoNexusVSMsCmd extends BaseListCmd { * up all the clusters of type vmware in that zone, and prepare a list of VSMs * associated with those clusters. */ - public static final Logger s_logger = Logger.getLogger(ListCiscoNexusVSMsCmd.class.getName()); private static final String s_name = "listcisconexusvsmscmdresponse"; @Inject CiscoNexusVSMElementService _ciscoNexusVSMService; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java index 822fc870c67f..b8bf08cd01aa 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java @@ -30,6 +30,7 @@ import javax.inject.Inject; import com.cloud.agent.api.to.NfsTO; +import com.cloud.cpu.CPU; import com.cloud.hypervisor.vmware.mo.DatastoreMO; import com.cloud.hypervisor.vmware.mo.HostMO; import com.cloud.hypervisor.vmware.util.VmwareClient; @@ -60,7 +61,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.BackupSnapshotCommand; import com.cloud.agent.api.Command; @@ -173,7 +173,6 @@ import com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec; public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable { - private static final Logger s_logger = Logger.getLogger(VMwareGuru.class); private static final Gson GSON = GsonHelper.getGson(); @@ -229,8 +228,8 @@ protected VMwareGuru() { } @Override @DB public Pair getCommandHostDelegation(long hostId, Command cmd) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Finding delegation for command of type %s to host %d.", cmd.getClass(), hostId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Finding delegation for command of type %s to host %d.", cmd.getClass(), hostId)); } boolean needDelegation = false; @@ -286,9 +285,9 @@ protected VMwareGuru() { } } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Command of type %s is going to be executed in sequence? %b", cmd.getClass(), cmd.executeInSequence())); - s_logger.trace(String.format("Command of type %s is going to need delegation? %b", cmd.getClass(), needDelegation)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Command of type %s is going to be executed in sequence? %b", cmd.getClass(), cmd.executeInSequence())); + logger.trace(String.format("Command of type %s is going to need delegation? %b", cmd.getClass(), needDelegation)); } if (!needDelegation) { @@ -355,13 +354,13 @@ public boolean trackVmHostChange() { return true; } - private static String resolveNameInGuid(String guid) { + private String resolveNameInGuid(String guid) { String tokens[] = guid.split("@"); assert (tokens.length == 2); String vCenterIp = NetUtils.resolveToIp(tokens[1]); if (vCenterIp == null) { - s_logger.error("Fatal : unable to resolve vCenter address " + tokens[1] + ", please check your DNS configuration"); + logger.error("Fatal : unable to resolve vCenter address " + tokens[1] + ", please check your DNS configuration"); return guid; } @@ -377,7 +376,7 @@ private static String resolveNameInGuid(String guid) { for (NicVO nic : nicVOs) { NetworkVO network = networkDao.findById(nic.getNetworkId()); if (network.getBroadcastDomainType() == BroadcastDomainType.Lswitch) { - s_logger.debug("Nic " + nic.toString() + " is connected to an lswitch, cleanup required"); + logger.debug("Nic " + nic.toString() + " is connected to an lswitch, cleanup required"); NetworkVO networkVO = networkDao.findById(nic.getNetworkId()); // We need the traffic label to figure out which vSwitch has the // portgroup @@ -464,7 +463,7 @@ private DatacenterMO getDatacenterMO(long zoneId) throws Exception { ManagedObjectReference dcMor = dcMo.getMor(); if (dcMor == null) { String msg = "Error while getting Vmware datacenter " + vmwareDatacenter.getVmwareDatacenterName(); - s_logger.error(msg); + logger.error(msg); throw new InvalidParameterValueException(msg); } return dcMo; @@ -538,7 +537,7 @@ private boolean isRootDisk(VirtualDisk disk, Map disksMap private void checkBackingInfo(VirtualDeviceBackingInfo backingInfo) { if (!(backingInfo instanceof VirtualDiskFlatVer2BackingInfo)) { String errorMessage = String.format("Unsupported backing info. Expected: [%s], but received: [%s].", VirtualDiskFlatVer2BackingInfo.class.getSimpleName(), backingInfo.getClass().getSimpleName()); - s_logger.error(errorMessage); + logger.error(errorMessage); throw new CloudRuntimeException(errorMessage); } } @@ -550,18 +549,18 @@ private Long getPoolIdFromDatastoreUuid(long zoneId, String datastoreUuid) { StoragePoolVO pool = null; try { String poolUuid = UuidUtils.normalize(datastoreUuid); - s_logger.info("Trying to find pool by UUID: " + poolUuid); + logger.info("Trying to find pool by UUID: " + poolUuid); pool = _storagePoolDao.findByUuid(poolUuid); } catch (CloudRuntimeException ex) { - s_logger.warn("Unable to get pool by datastore UUID: " + ex.getMessage()); + logger.warn("Unable to get pool by datastore UUID: " + ex.getMessage()); } if (pool == null) { - s_logger.info("Trying to find pool by path: " + datastoreUuid); + logger.info("Trying to find pool by path: " + datastoreUuid); pool = _storagePoolDao.findPoolByZoneAndPath(zoneId, datastoreUuid); } if (pool == null && datastoreUuid.startsWith("-iqn") && datastoreUuid.endsWith("-0")) { String iScsiName = "/iqn" + datastoreUuid.substring(4, datastoreUuid.length() - 2) + "/0"; - s_logger.info("Trying to find volume by iScsi name: " + iScsiName); + logger.info("Trying to find volume by iScsi name: " + iScsiName); VolumeVO volumeVO = _volumeDao.findOneByIScsiName(iScsiName); if (volumeVO != null) { pool = _storagePoolDao.findById(volumeVO.getPoolId()); @@ -644,7 +643,7 @@ private Long getTemplateSize(VirtualMachineMO template, String vmInternalName, M private VMTemplateVO createVMTemplateRecord(String vmInternalName, long guestOsId, long accountId) { Long nextTemplateId = vmTemplateDao.getNextInSequence(Long.class, "id"); VMTemplateVO templateVO = new VMTemplateVO(nextTemplateId, "Imported-from-" + vmInternalName, Storage.ImageFormat.OVA, false, false, false, Storage.TemplateType.USER, null, - false, 64, accountId, null, "Template imported from VM " + vmInternalName, false, guestOsId, false, HypervisorType.VMware, null, null, false, false, false, false); + false, 64, accountId, null, "Template imported from VM " + vmInternalName, false, guestOsId, false, HypervisorType.VMware, null, null, false, false, false, false, CPU.CPUArch.amd64); return vmTemplateDao.persist(templateVO); } @@ -699,11 +698,11 @@ private Long getImportingVMTemplate(List virtualDisks, long zoneId, * If VM exists: update VM */ private VMInstanceVO getVM(String vmInternalName, long templateId, long guestOsId, long serviceOfferingId, long zoneId, long accountId, long userId, long domainId) { - s_logger.debug(String.format("Trying to get VM with specs: [vmInternalName: %s, templateId: %s, guestOsId: %s, serviceOfferingId: %s].", vmInternalName, + logger.debug(String.format("Trying to get VM with specs: [vmInternalName: %s, templateId: %s, guestOsId: %s, serviceOfferingId: %s].", vmInternalName, templateId, guestOsId, serviceOfferingId)); VMInstanceVO vm = virtualMachineDao.findVMByInstanceNameIncludingRemoved(vmInternalName); if (vm != null) { - s_logger.debug(String.format("Found an existing VM [id: %s, removed: %s] with internalName: [%s].", vm.getUuid(), vm.getRemoved() != null ? "yes" : "no", vmInternalName)); + logger.debug(String.format("Found an existing VM [id: %s, removed: %s] with internalName: [%s].", vm.getUuid(), vm.getRemoved() != null ? "yes" : "no", vmInternalName)); vm.setState(VirtualMachine.State.Stopped); vm.setPowerState(VirtualMachine.PowerState.PowerOff); virtualMachineDao.update(vm.getId(), vm); @@ -715,7 +714,7 @@ private VMInstanceVO getVM(String vmInternalName, long templateId, long guestOsI return virtualMachineDao.findById(vm.getId()); } else { long id = userVmDao.getNextInSequence(Long.class, "id"); - s_logger.debug(String.format("Can't find an existing VM with internalName: [%s]. Creating a new VM with: [id: %s, name: %s, templateId: %s, guestOsId: %s, serviceOfferingId: %s].", + logger.debug(String.format("Can't find an existing VM with internalName: [%s]. Creating a new VM with: [id: %s, name: %s, templateId: %s, guestOsId: %s, serviceOfferingId: %s].", vmInternalName, id, vmInternalName, templateId, guestOsId, serviceOfferingId)); UserVmVO vmInstanceVO = new UserVmVO(id, vmInternalName, vmInternalName, templateId, HypervisorType.VMware, guestOsId, false, false, domainId, accountId, userId, @@ -788,7 +787,7 @@ protected VolumeVO updateVolume(VirtualDisk disk, Map dis volume.setAttached(new Date()); _volumeDao.update(volume.getId(), volume); if (volume.getRemoved() != null) { - s_logger.debug(String.format("Marking volume [uuid: %s] of restored VM [%s] as non removed.", volume.getUuid(), + logger.debug(String.format("Marking volume [uuid: %s] of restored VM [%s] as non removed.", volume.getUuid(), ReflectionToStringBuilderUtils.reflectOnlySelectedFields(vm, "uuid", "instanceName"))); _volumeDao.unremove(volume.getId()); if (vm.getType() == Type.User) { @@ -823,7 +822,7 @@ private void syncVMVolumes(VMInstanceVO vmInstanceVO, List virtualD volume = createVolume(disk, vmToImport, domainId, zoneId, accountId, instanceId, poolId, templateId, backup, true); operation = "created"; } - s_logger.debug(String.format("Sync volumes to %s in backup restore operation: %s volume [id: %s].", vmInstanceVO, operation, volume.getUuid())); + logger.debug(String.format("Sync volumes to %s in backup restore operation: %s volume [id: %s].", vmInstanceVO, operation, volume.getUuid())); } } @@ -868,9 +867,9 @@ protected String createVolumeInfoFromVolumes(List vmVolumes) { return GSON.toJson(list.toArray(), Backup.VolumeInfo[].class); } catch (Exception e) { if (CollectionUtils.isEmpty(vmVolumes) || vmVolumes.get(0).getInstanceId() == null) { - s_logger.error(String.format("Failed to create VolumeInfo of VM [id: null] volumes due to: [%s].", e.getMessage()), e); + logger.error(String.format("Failed to create VolumeInfo of VM [id: null] volumes due to: [%s].", e.getMessage()), e); } else { - s_logger.error(String.format("Failed to create VolumeInfo of VM [id: %s] volumes due to: [%s].", vmVolumes.get(0).getInstanceId(), e.getMessage()), e); + logger.error(String.format("Failed to create VolumeInfo of VM [id: %s] volumes due to: [%s].", vmVolumes.get(0).getInstanceId(), e.getMessage()), e); } throw e; } @@ -921,11 +920,11 @@ private NetworkVO getGuestNetworkFromNetworkMorName(String name, long accountId, String[] tagSplit = tag.split("-"); tag = tagSplit[tagSplit.length - 1]; - s_logger.debug(String.format("Trying to find network with vlan: [%s].", vlan)); + logger.debug(String.format("Trying to find network with vlan: [%s].", vlan)); NetworkVO networkVO = networkDao.findByVlan(vlan); if (networkVO == null) { networkVO = createNetworkRecord(zoneId, tag, vlan, accountId, domainId); - s_logger.debug(String.format("Created new network record [id: %s] with details [zoneId: %s, tag: %s, vlan: %s, accountId: %s and domainId: %s].", + logger.debug(String.format("Created new network record [id: %s] with details [zoneId: %s, tag: %s, vlan: %s, accountId: %s and domainId: %s].", networkVO.getUuid(), zoneId, tag, vlan, accountId, domainId)); } return networkVO; @@ -943,7 +942,7 @@ private Map getNetworksMapping(String[] vmNetworkNames, long continue; } String vlan = broadcastUri.getHost(); - s_logger.debug(String.format("Mapping network vlan [%s] to networkVO [id: %s].", vlan, networkVO.getUuid())); + logger.debug(String.format("Mapping network vlan [%s] to networkVO [id: %s].", vlan, networkVO.getUuid())); mapping.put(vlan, networkVO); } return mapping; @@ -1011,11 +1010,11 @@ private String getVlanFromDvsPort(VmwareContext context, String dvSwitchUuid, St } VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPort.getConfig().getSetting(); VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings.getVlan(); - s_logger.debug("Found port " + dvPort.getKey() + " with vlan " + vlanId.getVlanId()); + logger.debug("Found port " + dvPort.getKey() + " with vlan " + vlanId.getVlanId()); return String.valueOf(vlanId.getVlanId()); } } catch (Exception ex) { - s_logger.error("Got exception while get vlan from DVS port: " + ex.getMessage()); + logger.error("Got exception while get vlan from DVS port: " + ex.getMessage()); } return null; } @@ -1028,17 +1027,17 @@ private void syncVMNics(VirtualDevice[] nicDevices, DatacenterMO dcMo, Map getDisksMapping(Backup backup, List getDisksMapping(Backup backup, List vmDatastores = vmMo.getAllDatastores(); if (CollectionUtils.isEmpty(vmDatastores)) { String err = String.format("Unable to fetch datastores, could not clone VM %s for migration from VMware", vmName); - s_logger.error(err); + logger.error(err); throw new CloudRuntimeException(err); } DatastoreMO datastoreMO = vmDatastores.get(0); //pick the first datastore @@ -1360,7 +1359,7 @@ private VirtualMachineMO createCloneFromSourceVM(String vmName, VirtualMachineMO VirtualMachineMO clonedVM = dataCenterMO.findVm(cloneName); if (!result || clonedVM == null) { String err = String.format("Could not clone VM %s before migration from VMware", vmName); - s_logger.error(err); + logger.error(err); throw new CloudRuntimeException(err); } @@ -1372,9 +1371,9 @@ private String createOVFTemplateOfVM(VirtualMachineMO vmMO, DataStoreTO convertL String dataStoreUrl = getDataStoreUrlForTemplate(convertLocation); String vmOvfName = UUID.randomUUID().toString(); String vmOvfCreationPath = createDirOnStorage(vmOvfName, dataStoreUrl, null); - s_logger.debug(String.format("Creating OVF %s for the VM %s at %s", vmOvfName, vmMO.getName(), vmOvfCreationPath)); + logger.debug(String.format("Creating OVF %s for the VM %s at %s", vmOvfName, vmMO.getName(), vmOvfCreationPath)); vmMO.exportVm(vmOvfCreationPath, vmOvfName, false, false, threadsCountToExportOvf); - s_logger.debug(String.format("Created OVF %s for the VM %s at %s", vmOvfName, vmMO.getName(), vmOvfCreationPath)); + logger.debug(String.format("Created OVF %s for the VM %s at %s", vmOvfName, vmMO.getName(), vmOvfCreationPath)); return vmOvfName; } @@ -1391,11 +1390,12 @@ public Pair getHypervisorVMOutOfBandAndCloneIfRequ VirtualMachineMO vmMo = dataCenterMO.findVm(vmName); if (vmMo == null) { String err = String.format("Cannot find VM with name %s on vCenter %s/%s", vmName, vcenter, datacenter); - s_logger.error(err); + logger.error(err); throw new CloudRuntimeException(err); } VirtualMachinePowerState sourceVmPowerState = vmMo.getPowerState(); + if (sourceVmPowerState == VirtualMachinePowerState.POWERED_OFF) { // Don't clone for powered off VMs, can export OVF from it UnmanagedInstanceTO instanceTO = VmwareHelper.getUnmanagedInstance(vmMo.getRunningHost(), vmMo); @@ -1406,21 +1406,21 @@ public Pair getHypervisorVMOutOfBandAndCloneIfRequ if (isWindowsVm(vmMo)) { String err = String.format("VM %s is a Windows VM and its Running, cannot be imported." + " Please gracefully shut it down before attempting the import", vmName); - s_logger.error(err); + logger.error(err); throw new CloudRuntimeException(err); } if (isVMOnStandaloneHost(vmMo)) { // or datacenter.equalsIgnoreCase("ha-datacenter")? [Note: default datacenter name on standalone host: ha-datacenter] String err = String.format("VM %s might be on standalone host and is Running, cannot be imported." + " Please shut it down before attempting the import", vmName); - s_logger.error(err); + logger.error(err); throw new CloudRuntimeException(err); } } - s_logger.debug(String.format("Cloning VM %s at VMware host %s on vCenter %s", vmName, hostIp, vcenter)); + logger.debug(String.format("Cloning VM %s at VMware host %s on vCenter %s", vmName, hostIp, vcenter)); VirtualMachineMO clonedVM = createCloneFromSourceVM(vmName, vmMo, dataCenterMO); - s_logger.debug(String.format("VM %s cloned successfully, to VM %s", vmName, clonedVM.getName())); + logger.debug(String.format("VM %s cloned successfully, to VM %s", vmName, clonedVM.getName())); UnmanagedInstanceTO clonedInstance = VmwareHelper.getUnmanagedInstance(vmMo.getRunningHost(), clonedVM); setDisksFromSourceVM(clonedInstance, vmMo); clonedInstance.setCloneSourcePowerState(sourceVmPowerState == VirtualMachinePowerState.POWERED_ON ? UnmanagedInstanceTO.PowerState.PowerOn : UnmanagedInstanceTO.PowerState.PowerOff); @@ -1429,7 +1429,7 @@ public Pair getHypervisorVMOutOfBandAndCloneIfRequ throw cre; } catch (Exception e) { String err = String.format("Error while finding or cloning VM: %s from vCenter %s: %s", vmName, vcenter, e.getMessage()); - s_logger.error(err, e); + logger.error(err, e); throw new CloudRuntimeException(err, e); } } @@ -1461,7 +1461,7 @@ public String createVMTemplateOutOfBand(String hostIp, String vmName, Map details) { - if (LOGGER.isTraceEnabled()) { + if (logger.isTraceEnabled()) { for (String key : details.keySet()) { - LOGGER.trace(String.format("Detail for VM %s: %s => %s", to.getName(), key, details.get(key))); + logger.trace(String.format("Detail for VM %s: %s => %s", to.getName(), key, details.get(key))); } } to.setDetails(details); @@ -346,8 +347,8 @@ protected void configureNestedVirtualization(Map details, Virtua Boolean globalNestedVPerVMEnabled = getGlobalNestedVPerVMEnabled(); Boolean shouldEnableNestedVirtualization = shouldEnableNestedVirtualization(globalNestedVirtualisationEnabled, globalNestedVPerVMEnabled, localNestedV); - if(LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format( + if(logger.isDebugEnabled()) { + logger.debug(String.format( "Due to '%B'(globalNestedVirtualisationEnabled) and '%B'(globalNestedVPerVMEnabled) I'm adding a flag with value %B to the vm configuration for Nested Virtualisation.", globalNestedVirtualisationEnabled, globalNestedVPerVMEnabled, @@ -410,11 +411,11 @@ private NicTO[] sortNicsByDeviceId(NicTO[] nics) { protected GuestOSHypervisorVO getGuestOsMapping(GuestOSVO guestOS , String hypervisorVersion) { GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), Hypervisor.HypervisorType.VMware.toString(), hypervisorVersion); if (guestOsMapping == null) { - LOGGER.debug(String.format("Cannot find guest os mappings for guest os \"%s\" on VMware %s", guestOS.getDisplayName(), hypervisorVersion)); + logger.debug(String.format("Cannot find guest os mappings for guest os \"%s\" on VMware %s", guestOS.getDisplayName(), hypervisorVersion)); String parentVersion = CloudStackVersion.getVMwareParentVersion(hypervisorVersion); if (parentVersion != null) { guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), Hypervisor.HypervisorType.VMware.toString(), parentVersion); - LOGGER.debug(String.format("Found guest os mappings for guest os \"%s\" on VMware %s: %s", guestOS.getDisplayName(), parentVersion, guestOsMapping)); + logger.debug(String.format("Found guest os mappings for guest os \"%s\" on VMware %s: %s", guestOS.getDisplayName(), parentVersion, guestOsMapping)); } } return guestOsMapping; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java index d3b001ae9eb1..d2c71c4ee01a 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java @@ -20,7 +20,8 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.hypervisor.vmware.manager.VmwareManager; import com.cloud.hypervisor.vmware.mo.ClusterMO; @@ -30,7 +31,7 @@ import com.cloud.hypervisor.vmware.util.VmwareContext; public class VmwareCleanupMaid { - private static final Logger s_logger = Logger.getLogger(VmwareCleanupMaid.class); + protected static Logger LOGGER = LogManager.getLogger(VmwareCleanupMaid.class); private static Map> s_leftoverDummyVMs = new HashMap>(); @@ -117,11 +118,11 @@ public synchronized static void gcLeftOverVMs(VmwareContext context) { } if (vmMo != null) { - s_logger.info("Found left over dummy VM " + cleanupMaid.getVmName() + ", destroy it"); + LOGGER.info("Found left over dummy VM " + cleanupMaid.getVmName() + ", destroy it"); vmMo.destroy(); } } catch (Throwable e) { - s_logger.warn("Unable to destroy left over dummy VM " + cleanupMaid.getVmName()); + LOGGER.warn("Unable to destroy left over dummy VM " + cleanupMaid.getVmName()); } finally { // FIXME mgr.popCleanupCheckpoint(cleanupMaid.getCheckPoint()); } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java index 1989d3d53a1d..580d44a09d61 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java @@ -29,7 +29,6 @@ import com.cloud.dc.VmwareDatacenterVO; import org.apache.cloudstack.api.ApiConstants; -import org.apache.log4j.Logger; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; @@ -79,7 +78,6 @@ import com.vmware.vim25.ManagedObjectReference; public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(VmwareServerDiscoverer.class); @Inject VmwareManager _vmwareMgr; @@ -107,27 +105,27 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer List networkElements; public VmwareServerDiscoverer() { - s_logger.info("VmwareServerDiscoverer is constructed"); + logger.info("VmwareServerDiscoverer is constructed"); } @Override public Map> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List hostTags) throws DiscoveryException { - if (s_logger.isInfoEnabled()) - s_logger.info("Discover host. dc: " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + url.getHost()); + if (logger.isInfoEnabled()) + logger.info("Discover host. dc: " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + url.getHost()); if (podId == null) { - if (s_logger.isInfoEnabled()) - s_logger.info("No pod is assigned, assuming that it is not for vmware and skip it to next discoverer"); + if (logger.isInfoEnabled()) + logger.info("No pod is assigned, assuming that it is not for vmware and skip it to next discoverer"); return null; } boolean failureInClusterDiscovery = true; String vsmIp = ""; ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null || cluster.getHypervisorType() != HypervisorType.VMware) { - if (s_logger.isInfoEnabled()) - s_logger.info("invalid cluster id or cluster is not for VMware hypervisors"); + if (logger.isInfoEnabled()) + logger.info("invalid cluster id or cluster is not for VMware hypervisors"); return null; } @@ -143,7 +141,7 @@ public VmwareServerDiscoverer() { // If either or both not provided, try to retrieve & use the credentials from database, which are provided earlier while adding VMware DC to zone. if (usernameNotProvided || passwordNotProvided) { // Retrieve credentials associated with VMware DC - s_logger.info("Username and/or Password not provided while adding cluster to cloudstack zone. " + logger.info("Username and/or Password not provided while adding cluster to cloudstack zone. " + "Hence using both username & password provided while adding VMware DC to CloudStack zone."); username = vmwareDc.getUser(); password = vmwareDc.getPassword(); @@ -179,7 +177,7 @@ public VmwareServerDiscoverer() { int maxHostsPerCluster = _hvCapabilitiesDao.getMaxHostsPerCluster(hosts.get(0).getHypervisorType(), hosts.get(0).getHypervisorVersion()); if (hosts.size() >= maxHostsPerCluster) { String msg = "VMware cluster " + cluster.getName() + " is too big to add new host, current size: " + hosts.size() + ", max. size: " + maxHostsPerCluster; - s_logger.error(msg); + logger.error(msg); throw new DiscoveredWithErrorException(msg); } } @@ -265,7 +263,7 @@ public VmwareServerDiscoverer() { "Both public traffic and guest traffic is over same physical network " + pNetworkPublic + ". And virtual switch type chosen for each traffic is different" + ". A physical network cannot be shared by different types of virtual switches."; - s_logger.error(msg); + logger.error(msg); throw new InvalidParameterValueException(msg); } } @@ -273,7 +271,7 @@ public VmwareServerDiscoverer() { privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware); if (privateTrafficLabel != null) { - s_logger.info("Detected private network label : " + privateTrafficLabel); + logger.info("Detected private network label : " + privateTrafficLabel); } Pair vsmInfo = new Pair(false, 0L); if (nexusDVS && (guestTrafficLabelObj.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) || @@ -284,13 +282,13 @@ public VmwareServerDiscoverer() { if (zoneType != NetworkType.Basic) { publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware); if (publicTrafficLabel != null) { - s_logger.info("Detected public network label : " + publicTrafficLabel); + logger.info("Detected public network label : " + publicTrafficLabel); } } // Get physical network label guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware); if (guestTrafficLabel != null) { - s_logger.info("Detected guest network label : " + guestTrafficLabel); + logger.info("Detected guest network label : " + guestTrafficLabel); } // Before proceeding with validation of Nexus 1000v VSM check if an instance of Nexus 1000v VSM is already associated with this cluster. boolean clusterHasVsm = _vmwareMgr.hasNexusVSM(clusterId); @@ -317,18 +315,18 @@ public VmwareServerDiscoverer() { if (nexusDVS) { if (vsmCredentials != null) { - s_logger.info("Stocking credentials of Nexus VSM"); + logger.info("Stocking credentials of Nexus VSM"); context.registerStockObject("vsmcredentials", vsmCredentials); } } List morHosts = _vmwareMgr.addHostToPodCluster(context, dcId, podId, clusterId, URLDecoder.decode(url.getPath(), "UTF-8")); if (morHosts == null) - s_logger.info("Found 0 hosts."); + logger.info("Found 0 hosts."); if (privateTrafficLabel != null) context.uregisterStockObject("privateTrafficLabel"); if (morHosts == null) { - s_logger.error("Unable to find host or cluster based on url: " + URLDecoder.decode(url.getPath(), "UTF-8")); + logger.error("Unable to find host or cluster based on url: " + URLDecoder.decode(url.getPath(), "UTF-8")); return null; } @@ -339,7 +337,7 @@ public VmwareServerDiscoverer() { morCluster = context.getHostMorByPath(URLDecoder.decode(uriFromCluster.getPath(), "UTF-8")); if (morCluster == null || !morCluster.getType().equalsIgnoreCase("ClusterComputeResource")) { - s_logger.warn("Cluster url does not point to a valid vSphere cluster, url: " + clusterDetails.get("url")); + logger.warn("Cluster url does not point to a valid vSphere cluster, url: " + clusterDetails.get("url")); return null; } else { ClusterMO clusterMo = new ClusterMO(context, morCluster); @@ -352,9 +350,9 @@ public VmwareServerDiscoverer() { if (!validateDiscoveredHosts(context, morCluster, morHosts)) { if (morCluster == null) - s_logger.warn("The discovered host is not standalone host, can not be added to a standalone cluster"); + logger.warn("The discovered host is not standalone host, can not be added to a standalone cluster"); else - s_logger.warn("The discovered host does not belong to the cluster"); + logger.warn("The discovered host does not belong to the cluster"); return null; } @@ -390,7 +388,7 @@ public VmwareServerDiscoverer() { resource.configure("VMware", params); } catch (ConfigurationException e) { _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + url.getHost(), "Error is " + e.getMessage()); - s_logger.warn("Unable to instantiate " + url.getHost(), e); + logger.warn("Unable to instantiate " + url.getHost(), e); } resource.start(); @@ -410,17 +408,17 @@ public VmwareServerDiscoverer() { } catch (DiscoveredWithErrorException e) { throw e; } catch (Exception e) { - s_logger.warn("Unable to connect to Vmware vSphere server. service address: " + url.getHost() + ". " + e); + logger.warn("Unable to connect to Vmware vSphere server. service address: " + url.getHost() + ". " + e); return null; } finally { if (context != null) context.close(); if (failureInClusterDiscovery && vsmInfo.first()) { try { - s_logger.debug("Deleting Nexus 1000v VSM " + vsmIp + " because cluster discovery and addition to zone has failed."); + logger.debug("Deleting Nexus 1000v VSM " + vsmIp + " because cluster discovery and addition to zone has failed."); _nexusElement.deleteCiscoNexusVSM(vsmInfo.second().longValue()); } catch (Exception e) { - s_logger.warn("Deleting Nexus 1000v VSM " + vsmIp + " failed."); + logger.warn("Deleting Nexus 1000v VSM " + vsmIp + " failed."); } } } @@ -445,7 +443,7 @@ private VmwareDatacenterVO fetchVmwareDatacenterByZone(Long dcId) throws Discove vmwareDcZone = _vmwareDcZoneMapDao.findByZoneId(dcId); if (vmwareDcZone == null) { msg = "Zone " + dcId + " is not associated with any VMware DC yet. " + "Please add VMware DC to this zone first and then try to add clusters."; - s_logger.error(msg); + logger.error(msg); throw new DiscoveryException(msg); } @@ -490,13 +488,13 @@ private String validateCluster(URI url, VmwareDatacenterVO vmwareDc) throws Disc msg = "This cluster " + clusterName + " belongs to vCenter " + url.getHost() + ". But this zone is associated with VMware DC from vCenter " + vCenterHost + ". Make sure the cluster being added belongs to vCenter " + vCenterHost + " and VMware DC " + vmwareDcNameFromDb; - s_logger.error(msg); + logger.error(msg); throw new DiscoveryException(msg); } else if (!vmwareDcNameFromDb.equalsIgnoreCase(vmwareDcNameFromApi)) { msg = "This cluster " + clusterName + " belongs to VMware DC " + vmwareDcNameFromApi + " .But this zone is associated with VMware DC " + vmwareDcNameFromDb + ". Make sure the cluster being added belongs to VMware DC " + vmwareDcNameFromDb + " in vCenter " + vCenterHost; - s_logger.error(msg); + logger.error(msg); throw new DiscoveryException(msg); } return updatedInventoryPath; @@ -543,15 +541,15 @@ public Hypervisor.HypervisorType getHypervisorType() { @Override public boolean configure(String name, Map params) throws ConfigurationException { - if (s_logger.isInfoEnabled()) - s_logger.info("Configure VmwareServerDiscoverer, discover name: " + name); + if (logger.isInfoEnabled()) + logger.info("Configure VmwareServerDiscoverer, discover name: " + name); super.configure(name, params); createVmwareToolsIso(); - if (s_logger.isInfoEnabled()) { - s_logger.info("VmwareServerDiscoverer has been successfully configured"); + if (logger.isInfoEnabled()) { + logger.info("VmwareServerDiscoverer has been successfully configured"); } _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); return true; @@ -630,7 +628,7 @@ private VmwareTrafficLabel getTrafficInfo(TrafficType trafficType, String zoneWi try { trafficLabelObj = new VmwareTrafficLabel(zoneWideTrafficLabel, trafficType, defaultVirtualSwitchType); } catch (InvalidParameterValueException e) { - s_logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); + logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); throw e; } @@ -666,7 +664,7 @@ private VmwareTrafficLabel getTrafficInfo(TrafficType trafficType, String zoneWi try { trafficLabelObj = new VmwareTrafficLabel(zoneWideTrafficLabel, trafficType, defVirtualSwitchType); } catch (InvalidParameterValueException e) { - s_logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); + logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); throw e; } @@ -741,11 +739,11 @@ public ServerResource reloadResource(HostVO host) { try { resource.configure(host.getName(), params); } catch (ConfigurationException e) { - s_logger.warn("Unable to configure resource due to " + e.getMessage()); + logger.warn("Unable to configure resource due to " + e.getMessage()); return null; } if (!resource.start()) { - s_logger.warn("Unable to start the resource"); + logger.warn("Unable to start the resource"); return null; } } @@ -755,7 +753,7 @@ public ServerResource reloadResource(HostVO host) { private void validateVswitchType(String inputVswitchType) { VirtualSwitchType vSwitchType = VirtualSwitchType.getType(inputVswitchType); if (vSwitchType == VirtualSwitchType.None) { - s_logger.error("Unable to resolve " + inputVswitchType + " to a valid virtual switch type in VMware environment."); + logger.error("Unable to resolve " + inputVswitchType + " to a valid virtual switch type in VMware environment."); throw new InvalidParameterValueException("Invalid virtual switch type : " + inputVswitchType); } } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/dao/LegacyZoneDaoImpl.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/dao/LegacyZoneDaoImpl.java index 28c98fd78311..0077a4decbc1 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/dao/LegacyZoneDaoImpl.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/dao/LegacyZoneDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.hypervisor.vmware.LegacyZoneVO; @@ -33,7 +32,6 @@ @Component @DB public class LegacyZoneDaoImpl extends GenericDaoBase implements LegacyZoneDao { - protected static final Logger s_logger = Logger.getLogger(LegacyZoneDaoImpl.class); final SearchBuilder zoneSearch; final SearchBuilder fullTableSearch; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/CleanupFullyClonedTemplatesTask.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/CleanupFullyClonedTemplatesTask.java index 1437e057b86e..fa7675906d69 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/CleanupFullyClonedTemplatesTask.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/CleanupFullyClonedTemplatesTask.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import java.util.List; @@ -41,7 +40,6 @@ */ public class CleanupFullyClonedTemplatesTask extends ManagedContextRunnable { - private static final Logger s_logger = Logger.getLogger(CleanupFullyClonedTemplatesTask.class); private PrimaryDataStoreDao primaryStorageDao; private VMTemplatePoolDao templateDataStoreDao; @@ -64,23 +62,23 @@ public class CleanupFullyClonedTemplatesTask extends ManagedContextRunnable { this.vmInstanceDao = vmInstanceDao; this.cloneSettingDao = cloneSettingDao; this.templateManager = templateManager; - if(s_logger.isDebugEnabled()) { - s_logger.debug("new task created: " + this); + if(logger.isDebugEnabled()) { + logger.debug("new task created: " + this); } } @Override public void runInContext() { mine = Thread.currentThread(); - s_logger.info("running job to mark fully cloned templates for gc in thread " + mine.getName()); + logger.info("running job to mark fully cloned templates for gc in thread " + mine.getName()); if (StorageManager.VmwareCreateCloneFull.value()) { // only run if full cloning is being used (might need to be more fine grained) try { queryAllPools(); } catch (Throwable t) { - s_logger.error("error during job to mark fully cloned templates for gc in thread " + mine.getName()); - if(s_logger.isDebugEnabled()) { - s_logger.debug("running job to mark fully cloned templates for gc in thread " + mine.getName(),t); + logger.error("error during job to mark fully cloned templates for gc in thread " + mine.getName()); + if(logger.isDebugEnabled()) { + logger.debug("running job to mark fully cloned templates for gc in thread " + mine.getName(),t); } } } @@ -97,8 +95,8 @@ private void queryAllPools() { private void queryPoolForTemplates(StoragePoolVO pool, long zoneId) { // we don't need those specific to other hypervisor types if (pool.getHypervisor() == null || Hypervisor.HypervisorType.VMware.equals(pool.getHypervisor())) { - if(s_logger.isDebugEnabled()) { - s_logger.debug(mine.getName() + " is marking fully cloned templates in pool " + pool.getName()); + if(logger.isDebugEnabled()) { + logger.debug(mine.getName() + " is marking fully cloned templates in pool " + pool.getName()); } List templatePrimaryDataStoreVOS = templateDataStoreDao.listByPoolId(pool.getId()); for (VMTemplateStoragePoolVO templateMapping : templatePrimaryDataStoreVOS) { @@ -107,16 +105,16 @@ private void queryPoolForTemplates(StoragePoolVO pool, long zoneId) { } } } else { - if(s_logger.isDebugEnabled()) { - s_logger.debug(mine.getName() + " is ignoring pool " + pool.getName() + " id == " + pool.getId()); + if(logger.isDebugEnabled()) { + logger.debug(mine.getName() + " is ignoring pool " + pool.getName() + " id == " + pool.getId()); } } } private boolean canRemoveTemplateFromZone(long zoneId, VMTemplateStoragePoolVO templateMapping) { if (!templateMapping.getMarkedForGC()) { - if(s_logger.isDebugEnabled()) { - s_logger.debug(mine.getName() + " is checking template with id " + templateMapping.getTemplateId() + " for deletion from pool with id " + templateMapping.getPoolId()); + if(logger.isDebugEnabled()) { + logger.debug(mine.getName() + " is checking template with id " + templateMapping.getTemplateId() + " for deletion from pool with id " + templateMapping.getPoolId()); } TemplateJoinVO templateJoinVO = templateDao.findByIdIncludingRemoved(templateMapping.getTemplateId()); @@ -141,14 +139,14 @@ private boolean markedForGc(VMTemplateStoragePoolVO templateMapping, long zoneId break; } } catch (Exception e) { - s_logger.error("failed to retrieve vm clone setting for vm " + vm.toString()); - if(s_logger.isDebugEnabled()) { - s_logger.debug("failed to retrieve vm clone setting for vm " + vm.toString(), e); + logger.error("failed to retrieve vm clone setting for vm " + vm.toString()); + if(logger.isDebugEnabled()) { + logger.debug("failed to retrieve vm clone setting for vm " + vm.toString(), e); } } } if (!used) { - s_logger.info(mine.getName() + " is marking template with id " + templateMapping.getTemplateId() + " for gc in pool with id " + templateMapping.getPoolId()); + logger.info(mine.getName() + " is marking template with id " + templateMapping.getTemplateId() + " for gc in pool with id " + templateMapping.getPoolId()); // else // mark it for removal from primary store templateMapping.setMarkedForGC(true); diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java index 61a949f42d3e..561034155c20 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java @@ -67,7 +67,6 @@ import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.amazonaws.util.CollectionUtils; import com.cloud.agent.AgentManager; @@ -174,7 +173,6 @@ import com.vmware.vim25.ManagedObjectReference; public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener, VmwareDatacenterService, Configurable { - private static final Logger s_logger = Logger.getLogger(VmwareManagerImpl.class); private static final long SECONDS_PER_MINUTE = 60; private static final int DEFAULT_PORTS_PER_DV_PORT_GROUP_VSPHERE4_x = 256; @@ -284,10 +282,10 @@ private boolean isSystemVmIsoCopyNeeded(File srcIso, File destIso) { String destIsoMd5 = DigestUtils.md5Hex(new FileInputStream(destIso)); copyNeeded = !StringUtils.equals(srcIsoMd5, destIsoMd5); if (copyNeeded) { - s_logger.debug(String.format("MD5 checksum: %s for source ISO: %s is different from MD5 checksum: %s from destination ISO: %s", srcIsoMd5, srcIso.getAbsolutePath(), destIsoMd5, destIso.getAbsolutePath())); + logger.debug(String.format("MD5 checksum: %s for source ISO: %s is different from MD5 checksum: %s from destination ISO: %s", srcIsoMd5, srcIso.getAbsolutePath(), destIsoMd5, destIso.getAbsolutePath())); } } catch (IOException e) { - s_logger.debug(String.format("Unable to compare MD5 checksum for systemvm.iso at source: %s and destination: %s", srcIso.getAbsolutePath(), destIso.getAbsolutePath()), e); + logger.debug(String.format("Unable to compare MD5 checksum for systemvm.iso at source: %s and destination: %s", srcIso.getAbsolutePath(), destIso.getAbsolutePath()), e); } return copyNeeded; } @@ -303,10 +301,10 @@ public ConfigKey[] getConfigKeys() { } @Override public boolean configure(String name, Map params) throws ConfigurationException { - s_logger.info("Configure VmwareManagerImpl, manager name: " + name); + logger.info("Configure VmwareManagerImpl, manager name: " + name); if (!_configDao.isPremium()) { - s_logger.error("Vmware component can only run under premium distribution"); + logger.error("Vmware component can only run under premium distribution"); throw new ConfigurationException("Vmware component can only run under premium distribution"); } @@ -314,7 +312,7 @@ public boolean configure(String name, Map params) throws Configu if (_instance == null) { _instance = "DEFAULT"; } - s_logger.info("VmwareManagerImpl config - instance.name: " + _instance); + logger.info("VmwareManagerImpl config - instance.name: " + _instance); _mountParent = _configDao.getValue(Config.MountParent.key()); if (_mountParent == null) { @@ -324,7 +322,7 @@ public boolean configure(String name, Map params) throws Configu if (_instance != null) { _mountParent = _mountParent + File.separator + _instance; } - s_logger.info("VmwareManagerImpl config - _mountParent: " + _mountParent); + logger.info("VmwareManagerImpl config - _mountParent: " + _mountParent); String value = (String)params.get("scripts.timeout"); _timeout = NumbersUtil.parseInt(value, 1440) * 1000; @@ -361,18 +359,18 @@ public boolean configure(String name, Map params) throws Configu _additionalPortRangeStart = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareAdditionalVncPortRangeStart.key()), 59000); if (_additionalPortRangeStart > 65535) { - s_logger.warn("Invalid port range start port (" + _additionalPortRangeStart + ") for additional VNC port allocation, reset it to default start port 59000"); + logger.warn("Invalid port range start port (" + _additionalPortRangeStart + ") for additional VNC port allocation, reset it to default start port 59000"); _additionalPortRangeStart = 59000; } _additionalPortRangeSize = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareAdditionalVncPortRangeSize.key()), 1000); if (_additionalPortRangeSize < 0 || _additionalPortRangeStart + _additionalPortRangeSize > 65535) { - s_logger.warn("Invalid port range size (" + _additionalPortRangeSize + " for range starts at " + _additionalPortRangeStart); + logger.warn("Invalid port range size (" + _additionalPortRangeSize + " for range starts at " + _additionalPortRangeStart); _additionalPortRangeSize = Math.min(1000, 65535 - _additionalPortRangeStart); } _vCenterSessionTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.VmwareVcenterSessionTimeout.key()), 1200) * 1000; - s_logger.info("VmwareManagerImpl config - vmware.vcenter.session.timeout: " + _vCenterSessionTimeout); + logger.info("VmwareManagerImpl config - vmware.vcenter.session.timeout: " + _vCenterSessionTimeout); _recycleHungWorker = _configDao.getValue(Config.VmwareRecycleHungWorker.key()); if (_recycleHungWorker == null || _recycleHungWorker.isEmpty()) { @@ -384,13 +382,13 @@ public boolean configure(String name, Map params) throws Configu _rootDiskController = DiskControllerType.ide.toString(); } - s_logger.info("Additional VNC port allocation range is settled at " + _additionalPortRangeStart + " to " + (_additionalPortRangeStart + _additionalPortRangeSize)); + logger.info("Additional VNC port allocation range is settled at " + _additionalPortRangeStart + " to " + (_additionalPortRangeStart + _additionalPortRangeSize)); ((VmwareStorageManagerImpl)_storageMgr).configure(params); _agentMgr.registerForHostEvents(this, true, true, true); - s_logger.info("VmwareManagerImpl has been successfully configured"); + logger.info("VmwareManagerImpl has been successfully configured"); return true; } @@ -402,13 +400,13 @@ public boolean start() { startTemplateCleanJobSchedule(); startupCleanup(_mountParent); - s_logger.info("start done"); + logger.info("start done"); return true; } @Override public boolean stop() { - s_logger.info("shutting down scheduled tasks"); + logger.info("shutting down scheduled tasks"); templateCleanupScheduler.shutdown(); shutdownCleanup(); return true; @@ -448,7 +446,7 @@ private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Excep vlanId = mgmtTrafficLabelObj.getVlanId(); vSwitchType = mgmtTrafficLabelObj.getVirtualSwitchType().toString(); - s_logger.info("Preparing network on host " + hostMo.getContext().toString() + " for " + privateTrafficLabel); + logger.info("Preparing network on host " + hostMo.getContext().toString() + " for " + privateTrafficLabel); VirtualSwitchType vsType = VirtualSwitchType.getType(vSwitchType); //The management network is probably always going to be a physical network with islation type of vlans, so assume BroadcastDomainType VLAN if (VirtualSwitchType.StandardVirtualSwitch == vsType) { @@ -464,7 +462,7 @@ private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Excep } } HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.private", hostMo, vlanId, null, null, null, 180000, - vsType, portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, null, null); + vsType, portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, null, null, null); } } @@ -527,7 +525,7 @@ public List addHostToPodCluster(VmwareContext serviceCon int maxHostsPerCluster = _hvCapabilitiesDao.getMaxHostsPerCluster(HypervisorType.VMware, version); if (hosts.size() > maxHostsPerCluster) { String msg = "Failed to add VMware cluster as size is too big, current size: " + hosts.size() + ", max. size: " + maxHostsPerCluster; - s_logger.error(msg); + logger.error(msg); throw new DiscoveredWithErrorException(msg); } } @@ -551,12 +549,12 @@ public List addHostToPodCluster(VmwareContext serviceCon returnedHostList.add(mor); return returnedHostList; } else { - s_logger.error("Unsupport host type " + mor.getType() + ":" + mor.getValue() + " from inventory path: " + hostInventoryPath); + logger.error("Unsupport host type " + mor.getType() + ":" + mor.getValue() + " from inventory path: " + hostInventoryPath); return null; } } - s_logger.error("Unable to find host from inventory path: " + hostInventoryPath); + logger.error("Unable to find host from inventory path: " + hostInventoryPath); return null; } @@ -571,13 +569,13 @@ public Pair getSecondaryStorageStoreUrlAndId(long dcId) { } if (secUrl == null) { - s_logger.info("Secondary storage is either not having free capacity or not NFS, then use cache/staging storage instead"); + logger.info("Secondary storage is either not having free capacity or not NFS, then use cache/staging storage instead"); DataStore cacheStore = _dataStoreMgr.getImageCacheStore(dcId); if (cacheStore != null) { secUrl = cacheStore.getUri(); secId = cacheStore.getId(); } else { - s_logger.warn("No cache/staging storage found when NFS secondary storage with free capacity not available or non-NFS secondary storage is used"); + logger.warn("No cache/staging storage found when NFS secondary storage with free capacity not available or non-NFS secondary storage is used"); } } @@ -597,12 +595,12 @@ public List> getSecondaryStorageStoresUrlAndIdList(long dcId) } if (urlIdList.isEmpty()) { - s_logger.info("Secondary storage is either not having free capacity or not NFS, then use cache/staging storage instead"); + logger.info("Secondary storage is either not having free capacity or not NFS, then use cache/staging storage instead"); DataStore cacheStore = _dataStoreMgr.getImageCacheStore(dcId); if (cacheStore != null) { urlIdList.add(new Pair<>(cacheStore.getUri(), cacheStore.getId())); } else { - s_logger.warn("No cache/staging storage found when NFS secondary storage with free capacity not available or non-NFS secondary storage is used"); + logger.warn("No cache/staging storage found when NFS secondary storage with free capacity not available or non-NFS secondary storage is used"); } } @@ -651,17 +649,17 @@ public void gcLeftOverVMs(VmwareContext context) { @Override public boolean needRecycle(String workerTag) { - if (s_logger.isInfoEnabled()) - s_logger.info("Check to see if a worker VM with tag " + workerTag + " needs to be recycled"); + if (logger.isInfoEnabled()) + logger.info("Check to see if a worker VM with tag " + workerTag + " needs to be recycled"); if (workerTag == null || workerTag.isEmpty()) { - s_logger.error("Invalid worker VM tag " + workerTag); + logger.error("Invalid worker VM tag " + workerTag); return false; } String tokens[] = workerTag.split("-"); if (tokens.length != 3) { - s_logger.error("Invalid worker VM tag " + workerTag); + logger.error("Invalid worker VM tag " + workerTag); return false; } @@ -670,14 +668,14 @@ public boolean needRecycle(String workerTag) { long runid = Long.parseLong(tokens[2]); if (msHostPeerDao.countStateSeenInPeers(msid, runid, ManagementServerHost.State.Down) > 0) { - if (s_logger.isInfoEnabled()) - s_logger.info("Worker VM's owner management server node has been detected down from peer nodes, recycle it"); + if (logger.isInfoEnabled()) + logger.info("Worker VM's owner management server node has been detected down from peer nodes, recycle it"); return true; } if (runid != clusterManager.getManagementRunId(msid)) { - if (s_logger.isInfoEnabled()) - s_logger.info("Worker VM's owner management server has changed runid, recycle it"); + if (logger.isInfoEnabled()) + logger.info("Worker VM's owner management server has changed runid, recycle it"); return true; } @@ -688,13 +686,13 @@ public boolean needRecycle(String workerTag) { Instant end = start.plusSeconds(2 * (AsyncJobManagerImpl.JobExpireMinutes.value() + AsyncJobManagerImpl.JobCancelThresholdMinutes.value()) * SECONDS_PER_MINUTE); Instant now = Instant.now(); if(s_vmwareCleanOldWorderVMs.value() && now.isAfter(end)) { - if(s_logger.isInfoEnabled()) { - s_logger.info("Worker VM expired, seconds elapsed: " + Duration.between(start,now).getSeconds()); + if(logger.isInfoEnabled()) { + logger.info("Worker VM expired, seconds elapsed: " + Duration.between(start,now).getSeconds()); } return true; } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Worker VM with tag '" + workerTag + "' does not need recycling, yet." + + if (logger.isTraceEnabled()) { + logger.trace("Worker VM with tag '" + workerTag + "' does not need recycling, yet." + "But in " + Duration.between(now,end).getSeconds() + " seconds, though"); } return false; @@ -713,7 +711,7 @@ public void prepareSecondaryStorageStore(String storageUrl, Long storeId) { if (!patchFolder.exists()) { if (!patchFolder.mkdirs()) { String msg = "Unable to create systemvm folder on secondary storage. location: " + patchFolder.toString(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } @@ -721,23 +719,23 @@ public void prepareSecondaryStorageStore(String storageUrl, Long storeId) { File srcIso = getSystemVMPatchIsoFile(); File destIso = new File(mountPoint + "/systemvm/" + getSystemVMIsoFileNameOnDatastore()); if (isSystemVmIsoCopyNeeded(srcIso, destIso)) { - s_logger.info("Inject SSH key pairs before copying systemvm.iso into secondary storage"); + logger.info("Inject SSH key pairs before copying systemvm.iso into secondary storage"); _configServer.updateKeyPairs(); - s_logger.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + + logger.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + destIso.getAbsolutePath()); try { FileUtil.copyfile(srcIso, destIso); } catch (IOException e) { - s_logger.error("Unexpected exception ", e); + logger.error("Unexpected exception ", e); String msg = "Unable to copy systemvm ISO on secondary storage. src location: " + srcIso.toString() + ", dest location: " + destIso; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("SystemVM ISO file " + destIso.getPath() + " already exists"); + if (logger.isTraceEnabled()) { + logger.trace("SystemVM ISO file " + destIso.getPath() + " already exists"); } } } finally { @@ -775,7 +773,7 @@ private File getSystemVMPatchIsoFile() { assert (isoFile != null); if (!isoFile.exists()) { - s_logger.error("Unable to locate systemvm.iso in your setup at " + isoFile.toString()); + logger.error("Unable to locate systemvm.iso in your setup at " + isoFile.toString()); } return isoFile; } @@ -792,7 +790,7 @@ public File getSystemVMKeyFile() { } assert (keyFile != null); if (!keyFile.exists()) { - s_logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); + logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); } return keyFile; } @@ -810,13 +808,13 @@ public String getMountPoint(String storageUrl, String nfsVersion) { try { uri = new URI(storageUrl); } catch (URISyntaxException e) { - s_logger.error("Invalid storage URL format ", e); + logger.error("Invalid storage URL format ", e); throw new CloudRuntimeException("Unable to create mount point due to invalid storage URL format " + storageUrl); } mountPoint = mount(uri.getHost() + ":" + uri.getPath(), _mountParent, nfsVersion); if (mountPoint == null) { - s_logger.error("Unable to create mount point for " + storageUrl); + logger.error("Unable to create mount point for " + storageUrl); return "/mnt/sec"; // throw new CloudRuntimeException("Unable to create mount point for " + storageUrl); } @@ -837,14 +835,14 @@ private String setupMountPoint(String parent) { break; } } - s_logger.error("Unable to create mount: " + mntPt); + logger.error("Unable to create mount: " + mntPt); } return mountPoint; } private void startupCleanup(String parent) { - s_logger.info("Cleanup mounted NFS mount points used in previous session"); + logger.info("Cleanup mounted NFS mount points used in previous session"); long mshostId = ManagementServerNode.getManagementServerId(); @@ -852,14 +850,14 @@ private void startupCleanup(String parent) { List mounts = _storage.listMountPointsByMsHost(parent, mshostId); if (mounts != null && !mounts.isEmpty()) { for (String mountPoint : mounts) { - s_logger.info("umount NFS mount from previous session: " + mountPoint); + logger.info("umount NFS mount from previous session: " + mountPoint); String result = null; - Script command = new Script(true, "umount", _timeout, s_logger); + Script command = new Script(true, "umount", _timeout, logger); command.add(mountPoint); result = command.execute(); if (result != null) { - s_logger.warn("Unable to umount " + mountPoint + " due to " + result); + logger.warn("Unable to umount " + mountPoint + " due to " + result); } File file = new File(mountPoint); if (file.exists()) { @@ -870,17 +868,17 @@ private void startupCleanup(String parent) { } private void shutdownCleanup() { - s_logger.info("Cleanup mounted NFS mount points used in current session"); + logger.info("Cleanup mounted NFS mount points used in current session"); for (String mountPoint : _storageMounts.values()) { - s_logger.info("umount NFS mount: " + mountPoint); + logger.info("umount NFS mount: " + mountPoint); String result = null; - Script command = new Script(true, "umount", _timeout, s_logger); + Script command = new Script(true, "umount", _timeout, logger); command.add(mountPoint); result = command.execute(); if (result != null) { - s_logger.warn("Unable to umount " + mountPoint + " due to " + result); + logger.warn("Unable to umount " + mountPoint + " due to " + result); } File file = new File(mountPoint); if (file.exists()) { @@ -892,13 +890,13 @@ private void shutdownCleanup() { protected String mount(String path, String parent, String nfsVersion) { String mountPoint = setupMountPoint(parent); if (mountPoint == null) { - s_logger.warn("Unable to create a mount point"); + logger.warn("Unable to create a mount point"); return null; } Script script = null; String result = null; - Script command = new Script(true, "mount", _timeout, s_logger); + Script command = new Script(true, "mount", _timeout, logger); command.add("-t", "nfs"); if (nfsVersion != null){ command.add("-o", "vers=" + nfsVersion); @@ -911,7 +909,7 @@ protected String mount(String path, String parent, String nfsVersion) { command.add(mountPoint); result = command.execute(); if (result != null) { - s_logger.warn("Unable to mount " + path + " due to " + result); + logger.warn("Unable to mount " + path + " due to " + result); File file = new File(mountPoint); if (file.exists()) { file.delete(); @@ -920,11 +918,11 @@ protected String mount(String path, String parent, String nfsVersion) { } // Change permissions for the mountpoint - script = new Script(true, "chmod", _timeout, s_logger); + script = new Script(true, "chmod", _timeout, logger); script.add("1777", mountPoint); result = script.execute(); if (result != null) { - s_logger.warn("Unable to set permissions for " + mountPoint + " due to " + result); + logger.warn("Unable to set permissions for " + mountPoint + " due to " + result); } return mountPoint; } @@ -996,8 +994,8 @@ public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) protected final static int DEFAULT_DOMR_SSHPORT = 3922; protected boolean shutdownRouterVM(DomainRouterVO router) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Try to shutdown router VM " + router.getInstanceName() + " directly."); + if (logger.isDebugEnabled()) { + logger.debug("Try to shutdown router VM " + router.getInstanceName() + " directly."); } Pair result; @@ -1005,15 +1003,15 @@ protected boolean shutdownRouterVM(DomainRouterVO router) { result = SshHelper.sshExecute(router.getPrivateIpAddress(), DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "poweroff -f"); if (!result.first()) { - s_logger.debug("Unable to shutdown " + router.getInstanceName() + " directly"); + logger.debug("Unable to shutdown " + router.getInstanceName() + " directly"); return false; } } catch (Throwable e) { - s_logger.warn("Unable to shutdown router " + router.getInstanceName() + " directly."); + logger.warn("Unable to shutdown router " + router.getInstanceName() + " directly."); return false; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Shutdown router " + router.getInstanceName() + " successful."); + if (logger.isDebugEnabled()) { + logger.debug("Shutdown router " + router.getInstanceName() + " successful."); } return true; } @@ -1070,11 +1068,11 @@ public Map getNexusVSMCredentialsByClusterId(Long clusterId) { long vsmId = 0; if (vsmMapVO != null) { vsmId = vsmMapVO.getVsmId(); - s_logger.info("vsmId is " + vsmId); + logger.info("vsmId is " + vsmId); nexusVSM = _nexusDao.findById(vsmId); - s_logger.info("Fetching nexus vsm credentials from database."); + logger.info("Fetching nexus vsm credentials from database."); } else { - s_logger.info("Found empty vsmMapVO."); + logger.info("Found empty vsmMapVO."); return null; } @@ -1083,7 +1081,7 @@ public Map getNexusVSMCredentialsByClusterId(Long clusterId) { nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr()); nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName()); nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword()); - s_logger.info("Successfully fetched the credentials of Nexus VSM."); + logger.info("Successfully fetched the credentials of Nexus VSM."); } return nexusVSMCredentials; } @@ -1161,7 +1159,7 @@ public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws Resourc Long associatedVmwareDcId = vmwareDcZoneMap.getVmwareDcId(); VmwareDatacenterVO associatedVmwareDc = vmwareDcDao.findById(associatedVmwareDcId); if (associatedVmwareDc.getVcenterHost().equalsIgnoreCase(vCenterHost) && associatedVmwareDc.getVmwareDatacenterName().equalsIgnoreCase(vmwareDcName)) { - s_logger.info("Ignoring API call addVmwareDc, because VMware DC " + vCenterHost + "/" + vmwareDcName + + logger.info("Ignoring API call addVmwareDc, because VMware DC " + vCenterHost + "/" + vmwareDcName + " is already associated with specified zone with id " + zoneId); return associatedVmwareDc; } else { @@ -1190,7 +1188,7 @@ public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws Resourc dcMor = dcMo.getMor(); if (dcMor == null) { String msg = "Unable to find VMware DC " + vmwareDcName + " in vCenter " + vCenterHost + ". "; - s_logger.error(msg); + logger.error(msg); throw new InvalidParameterValueException(msg); } @@ -1386,7 +1384,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { dcMo = new DatacenterMO(context, vmwareDcName); } catch (Throwable t) { String msg = "Unable to find DC " + vmwareDcName + " in vCenter " + vCenterHost; - s_logger.error(msg); + logger.error(msg); throw new DiscoveryException(msg); } @@ -1394,10 +1392,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) { // Reset custom field property cloud.zone over this DC dcMo.setCustomFieldValue(CustomFieldConstants.CLOUD_ZONE, "false"); - s_logger.info("Sucessfully reset custom field property cloud.zone over DC " + vmwareDcName); + logger.info("Sucessfully reset custom field property cloud.zone over DC " + vmwareDcName); } catch (Exception e) { String msg = "Unable to reset custom field property cloud.zone over DC " + vmwareDcName + " due to : " + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } finally { if (context != null) { @@ -1415,8 +1413,8 @@ private void validateZone(Long zoneId) throws InvalidParameterValueException { if (isLegacyZone(zoneId)) { throw new InvalidParameterValueException("The specified zone is legacy zone. Adding VMware datacenter to legacy zone is not supported."); } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("The specified zone is not legacy zone."); + if (logger.isTraceEnabled()) { + logger.trace("The specified zone is not legacy zone."); } } } @@ -1476,8 +1474,8 @@ private void doesZoneExist(Long zoneId) throws InvalidParameterValueException { if (zone == null) { throw new InvalidParameterValueException("Can't find zone by the id specified."); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Zone with id:[" + zoneId + "] exists."); + if (logger.isTraceEnabled()) { + logger.trace("Zone with id:[" + zoneId + "] exists."); } } @@ -1507,14 +1505,14 @@ public List importVsphereStoragePoliciesInternal String password = vmwareDatacenter.getPassword(); List storageProfiles = null; try { - s_logger.debug(String.format("Importing vSphere Storage Policies for the vmware DC %d in zone %d", vmwareDcId, zoneId)); + logger.debug(String.format("Importing vSphere Storage Policies for the vmware DC %d in zone %d", vmwareDcId, zoneId)); VmwareContext context = VmwareContextFactory.getContext(vCenterHost, userName, password); PbmProfileManagerMO profileManagerMO = new PbmProfileManagerMO(context); storageProfiles = profileManagerMO.getStorageProfiles(); - s_logger.debug(String.format("Import vSphere Storage Policies for the vmware DC %d in zone %d is successful", vmwareDcId, zoneId)); + logger.debug(String.format("Import vSphere Storage Policies for the vmware DC %d in zone %d is successful", vmwareDcId, zoneId)); } catch (Exception e) { String msg = String.format("Unable to list storage profiles from DC %s due to : %s", vmwareDcName, VmwareHelper.getExceptionMessage(e)); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -1568,7 +1566,7 @@ public List listVsphereStoragePolicyCompatibleStoragePools(ListVsph StorageFilerTO storageFilerTO = new StorageFilerTO(pool); List hostIds = storageManager.getUpHostsInPool(pool.getId()); if (CollectionUtils.isNullOrEmpty(hostIds)) { - s_logger.debug("Did not find a suitable host to verify compatibility of the pool " + pool.getName()); + logger.debug("Did not find a suitable host to verify compatibility of the pool " + pool.getName()); continue; } Collections.shuffle(hostIds); @@ -1581,7 +1579,7 @@ public List listVsphereStoragePolicyCompatibleStoragePools(ListVsph compatiblePools.add(pool); } } catch (AgentUnavailableException | OperationTimedoutException e) { - s_logger.error("Could not verify if storage policy " + storagePolicy.getName() + " is compatible with storage pool " + pool.getName()); + logger.error("Could not verify if storage policy " + storagePolicy.getName() + " is compatible with storage pool " + pool.getName()); } } return compatiblePools; @@ -1617,7 +1615,7 @@ public List listVMsInDatacenter(ListVmwareDcVmsCmd cmd) { } try { - s_logger.debug(String.format("Connecting to the VMware datacenter %s at vCenter %s to retrieve VMs", + logger.debug(String.format("Connecting to the VMware datacenter %s at vCenter %s to retrieve VMs", datacenterName, vcenter)); String serviceUrl = String.format("https://%s/sdk/vimService", vcenter); VmwareClient vimClient = new VmwareClient(vcenter); @@ -1629,7 +1627,7 @@ public List listVMsInDatacenter(ListVmwareDcVmsCmd cmd) { if (dcMor == null) { String msg = String.format("Unable to find VMware datacenter %s in vCenter %s", datacenterName, vcenter); - s_logger.error(msg); + logger.error(msg); throw new InvalidParameterValueException(msg); } List instances = dcMo.getAllVmsOnDatacenter(); @@ -1638,7 +1636,7 @@ public List listVMsInDatacenter(ListVmwareDcVmsCmd cmd) { } catch (Exception e) { String errorMsg = String.format("Error retrieving stopped VMs from the VMware VC %s datacenter %s: %s", vcenter, datacenterName, e.getMessage()); - s_logger.error(errorMsg, e); + logger.error(errorMsg, e); throw new CloudRuntimeException(errorMsg); } } @@ -1649,25 +1647,25 @@ public boolean hasNexusVSM(Long clusterId) { vsmMapVo = _vsmMapDao.findByClusterId(clusterId); if (vsmMapVo == null) { - s_logger.info("There is no instance of Nexus 1000v VSM associated with this cluster [Id:" + clusterId + "] yet."); + logger.info("There is no instance of Nexus 1000v VSM associated with this cluster [Id:" + clusterId + "] yet."); return false; } else { - s_logger.info("An instance of Nexus 1000v VSM [Id:" + vsmMapVo.getVsmId() + "] associated with this cluster [Id:" + clusterId + "]"); + logger.info("An instance of Nexus 1000v VSM [Id:" + vsmMapVo.getVsmId() + "] associated with this cluster [Id:" + clusterId + "]"); return true; } } private void startTemplateCleanJobSchedule() { - if(s_logger.isDebugEnabled()) { - s_logger.debug("checking to see if we should schedule a job to search for fully cloned templates to clean-up"); + if(logger.isDebugEnabled()) { + logger.debug("checking to see if we should schedule a job to search for fully cloned templates to clean-up"); } if(StorageManager.StorageCleanupEnabled.value() && StorageManager.TemplateCleanupEnabled.value() && templateCleanupInterval.value() > 0) { try { - if (s_logger.isInfoEnabled()) { - s_logger.info("scheduling job to search for fully cloned templates to clean-up once per " + templateCleanupInterval.value() + " minutes."); + if (logger.isInfoEnabled()) { + logger.info("scheduling job to search for fully cloned templates to clean-up once per " + templateCleanupInterval.value() + " minutes."); } // futureTemplateCleanup = Runnable task = getCleanupFullyClonedTemplatesTask(); @@ -1675,21 +1673,21 @@ private void startTemplateCleanJobSchedule() { templateCleanupInterval.value(), templateCleanupInterval.value(), TimeUnit.MINUTES); - if (s_logger.isTraceEnabled()) { - s_logger.trace("scheduled job to search for fully cloned templates to clean-up."); + if (logger.isTraceEnabled()) { + logger.trace("scheduled job to search for fully cloned templates to clean-up."); } } catch (RejectedExecutionException ree) { - s_logger.error("job to search for fully cloned templates cannot be scheduled"); - s_logger.debug("job to search for fully cloned templates cannot be scheduled;", ree); + logger.error("job to search for fully cloned templates cannot be scheduled"); + logger.debug("job to search for fully cloned templates cannot be scheduled;", ree); } catch (NullPointerException npe) { - s_logger.error("job to search for fully cloned templates is invalid"); - s_logger.debug("job to search for fully cloned templates is invalid;", npe); + logger.error("job to search for fully cloned templates is invalid"); + logger.debug("job to search for fully cloned templates is invalid;", npe); } catch (IllegalArgumentException iae) { - s_logger.error("job to search for fully cloned templates is scheduled at invalid intervals"); - s_logger.debug("job to search for fully cloned templates is scheduled at invalid intervals;", iae); + logger.error("job to search for fully cloned templates is scheduled at invalid intervals"); + logger.debug("job to search for fully cloned templates is scheduled at invalid intervals;", iae); } catch (Exception e) { - s_logger.error("job to search for fully cloned templates failed for unknown reasons"); - s_logger.debug("job to search for fully cloned templates failed for unknown reasons;", e); + logger.error("job to search for fully cloned templates failed for unknown reasons"); + logger.debug("job to search for fully cloned templates failed for unknown reasons;", e); } } } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index 7e6b8c19ad4d..6203d5b9a94c 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -32,7 +32,8 @@ import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.BackupSnapshotAnswer; @@ -125,20 +126,20 @@ public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCom @Override public void createOva(String path, String name, int archiveTimeout) { - Script commandSync = new Script(true, "sync", 0, s_logger); + Script commandSync = new Script(true, "sync", 0, logger); commandSync.execute(); - Script command = new Script(false, "tar", archiveTimeout, s_logger); + Script command = new Script(false, "tar", archiveTimeout, logger); command.setWorkDir(path); command.add("-cf", name + ".ova"); command.add(name + ".ovf"); // OVF file should be the first file in OVA archive command.add(name + "-disk0.vmdk"); - s_logger.info("Package OVA with command: " + command.toString()); + logger.info("Package OVA with command: " + command.toString()); command.execute(); } - private static final Logger s_logger = Logger.getLogger(VmwareStorageManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private final VmwareStorageMount _mountService; private final StorageLayer _storage = new JavaStorageLayer(); @@ -157,7 +158,7 @@ public VmwareStorageManagerImpl(VmwareStorageMount mountService, String nfsVersi } public void configure(Map params) { - s_logger.info("Configure VmwareStorageManagerImpl"); + logger.info("Configure VmwareStorageManagerImpl"); String value = (String)params.get("scripts.timeout"); _timeout = NumbersUtil.parseInt(value, 1440) * 1000; @@ -167,7 +168,7 @@ public void configure(Map params) { public String createOvaForTemplate(TemplateObjectTO template, int archiveTimeout) { DataStoreTO storeTO = template.getDataStore(); if (!(storeTO instanceof NfsTO)) { - s_logger.debug("Can only handle NFS storage, while creating OVA from template"); + logger.debug("Can only handle NFS storage, while creating OVA from template"); return null; } NfsTO nfsStore = (NfsTO)storeTO; @@ -179,20 +180,20 @@ public String createOvaForTemplate(TemplateObjectTO template, int archiveTimeout try { if (installFullPath.endsWith(".ova")) { if (new File(installFullPath).exists()) { - s_logger.debug("OVA file found at: " + installFullPath); + logger.debug("OVA file found at: " + installFullPath); } else { if (new File(installFullPath + ".meta").exists()) { createOVAFromMetafile(installFullPath + ".meta", archiveTimeout); } else { String msg = "Unable to find OVA or OVA MetaFile to prepare template."; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } return installPath; } } catch (Throwable e) { - s_logger.debug("Failed to create OVA: " + e.toString()); + logger.debug("Failed to create OVA: " + e.toString()); } return null; } @@ -202,7 +203,7 @@ public String createOvaForTemplate(TemplateObjectTO template, int archiveTimeout public String createOvaForVolume(VolumeObjectTO volume, int archiveTimeout) { DataStoreTO storeTO = volume.getDataStore(); if (!(storeTO instanceof NfsTO)) { - s_logger.debug("can only handle nfs storage, when create ova from volume"); + logger.debug("can only handle nfs storage, when create ova from volume"); return null; } NfsTO nfsStore = (NfsTO)storeTO; @@ -219,12 +220,12 @@ public String createOvaForVolume(VolumeObjectTO volume, int archiveTimeout) { try { if (new File(secondaryMountPoint + File.separator + volumePath).exists()) { - s_logger.debug("ova already exists:" + volumePath); + logger.debug("ova already exists:" + volumePath); return volumePath; } else { - Script commandSync = new Script(true, "sync", 0, s_logger); + Script commandSync = new Script(true, "sync", 0, logger); commandSync.execute(); - Script command = new Script(false, "tar", archiveTimeout, s_logger); + Script command = new Script(false, "tar", archiveTimeout, logger); command.setWorkDir(installFullPath); command.add("-cf", volumeUuid + ".ova"); command.add(volumeUuid + ".ovf"); // OVF file should be the first file in OVA archive @@ -237,7 +238,7 @@ public String createOvaForVolume(VolumeObjectTO volume, int archiveTimeout) { } } catch (Throwable e) { - s_logger.info("Exception for createVolumeOVA"); + logger.info("Exception for createVolumeOVA"); } return null; } @@ -284,8 +285,8 @@ public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadComma VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true); if (templateMo == null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName); + if (logger.isInfoEnabled()) { + logger.info("Template " + templateName + " is not setup yet, setup template from secondary storage with uuid name: " + templateUuidName); } ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getPoolUuid()); assert (morDs != null); @@ -293,7 +294,7 @@ public Answer execute(VmwareHostService hostService, PrimaryStorageDownloadComma copyTemplateFromSecondaryToPrimary(hyperHost, primaryStorageDatastoreMo, secondaryStorageUrl, mountPoint, templateName, templateUuidName, cmd.getNfsVersion()); } else { - s_logger.info("Template " + templateName + " has already been setup, skip the template setup process in primary storage"); + logger.info("Template " + templateName + " has already been setup, skip the template setup process in primary storage"); } return new PrimaryStorageDownloadAnswer(templateUuidName, 0); @@ -332,8 +333,8 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd) try { vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); if (vmMo == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter"); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter"); } vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getVmName()); @@ -379,7 +380,7 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd) workerVm.detachAllDisksAndDestroy(); } } catch (Throwable e) { - s_logger.warn(String.format("Failed to destroy worker VM [%s] due to: [%s].", workerVMName, e.getMessage()), e); + logger.warn(String.format("Failed to destroy worker VM [%s] due to: [%s].", workerVMName, e.getMessage()), e); } } } catch (Throwable e) { @@ -403,14 +404,14 @@ public Answer execute(VmwareHostService hostService, CreatePrivateTemplateFromVo VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName()); if (vmMo == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find the owner VM for CreatePrivateTemplateFromVolumeCommand on host " + hyperHost.getHyperHostName() + ", try within datacenter"); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find the owner VM for CreatePrivateTemplateFromVolumeCommand on host " + hyperHost.getHyperHostName() + ", try within datacenter"); } vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getVmName()); if (vmMo == null) { String msg = "Unable to find the owner VM for volume operation. vm: " + cmd.getVmName(); - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -501,7 +502,7 @@ public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCom ManagedObjectReference morPrimaryDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStorageNameLabel); if (morPrimaryDs == null) { String msg = "Unable to find datastore: " + primaryStorageNameLabel; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -523,25 +524,25 @@ public Answer execute(VmwareHostService hostService, CreateVolumeFromSnapshotCom private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl, String templatePathAtSecondaryStorage, String templateName, String templateUuid, String nfsVersion) throws Exception { - s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " + logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " + templatePathAtSecondaryStorage + ", templateName: " + templateName); String secondaryMountPoint = _mountService.getMountPoint(secondaryStorageUrl, nfsVersion); - s_logger.info("Secondary storage mount point: " + secondaryMountPoint); + logger.info("Secondary storage mount point: " + secondaryMountPoint); String srcOVAFileName = secondaryMountPoint + "/" + templatePathAtSecondaryStorage + templateName + "." + ImageFormat.OVA.getFileExtension(); String srcFileName = getOVFFilePath(srcOVAFileName); if (srcFileName == null) { - Script command = new Script("tar", 0, s_logger); + Script command = new Script("tar", 0, logger); command.add("--no-same-owner"); command.add("-xf", srcOVAFileName); command.setWorkDir(secondaryMountPoint + "/" + templatePathAtSecondaryStorage); - s_logger.info("Executing command: " + command.toString()); + logger.info("Executing command: " + command.toString()); String result = command.execute(); if (result != null) { String msg = "Unable to unpack snapshot OVA file at: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -549,7 +550,7 @@ private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, srcFileName = getOVFFilePath(srcOVAFileName); if (srcFileName == null) { String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -560,7 +561,7 @@ private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, if (vmMo == null) { String msg = "Failed to import OVA template. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " + templatePathAtSecondaryStorage + ", templateName: " + templateName + ", templateUuid: " + templateUuid; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -570,7 +571,7 @@ private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, } else { vmMo.destroy(); String msg = "Unable to create base snapshot for template, templateName: " + templateName + ", templateUuid: " + templateUuid; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -582,14 +583,14 @@ private Ternary createTemplateFromVolume(VirtualMachineMO vm String installPath = getTemplateRelativeDirInSecStorage(accountId, templateId); String installFullPath = secondaryMountPoint + "/" + installPath; synchronized (installPath.intern()) { - Script command = new Script(false, "mkdir", _timeout, s_logger); + Script command = new Script(false, "mkdir", _timeout, logger); command.add("-p"); command.add(installFullPath); String result = command.execute(); if (result != null) { String msg = "unable to prepare template directory: " + installPath + ", storage: " + secStorageUrl + ", error msg: " + result; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -599,13 +600,13 @@ private Ternary createTemplateFromVolume(VirtualMachineMO vm Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } if (!vmMo.createSnapshot(templateUniqueName, "Temporary snapshot for template creation", false, false)) { String msg = "Unable to take snapshot for creating template from volume. volume path: " + volumePath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -615,7 +616,7 @@ private Ternary createTemplateFromVolume(VirtualMachineMO vm clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName); if (clonedVm == null) { String msg = "Unable to create dummy VM to export volume. volume path: " + volumePath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -659,64 +660,64 @@ private Ternary createTemplateFromSnapshot(long accountId, l String snapshotFullVMDKName = snapshotRoot + "/" + backupSSUuid + "/"; synchronized (installPath.intern()) { - command = new Script(false, "mkdir", _timeout, s_logger); + command = new Script(false, "mkdir", _timeout, logger); command.add("-p"); command.add(installFullPath); result = command.execute(); if (result != null) { String msg = "unable to prepare template directory: " + installPath + ", storage: " + secStorageUrl + ", error msg: " + result; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } try { if (new File(snapshotFullOVAName).exists()) { - command = new Script(false, "cp", _timeout, s_logger); + command = new Script(false, "cp", _timeout, logger); command.add(snapshotFullOVAName); command.add(installFullOVAName); result = command.execute(); if (result != null) { String msg = "unable to copy snapshot " + snapshotFullOVAName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } // untar OVA file at template directory - command = new Script("tar", 0, s_logger); + command = new Script("tar", 0, logger); command.add("--no-same-owner"); command.add("-xf", installFullOVAName); command.setWorkDir(installFullPath); - s_logger.info("Executing command: " + command.toString()); + logger.info("Executing command: " + command.toString()); result = command.execute(); if (result != null) { String msg = "unable to untar snapshot " + snapshotFullOVAName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } else { // there is no ova file, only ovf originally; if (new File(snapshotFullOvfName).exists()) { - command = new Script(false, "cp", _timeout, s_logger); + command = new Script(false, "cp", _timeout, logger); command.add(snapshotFullOvfName); //command.add(installFullOvfName); command.add(installFullPath); result = command.execute(); if (result != null) { String msg = "unable to copy snapshot " + snapshotFullOvfName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } - s_logger.info("vmdkfile parent dir: " + snapshotFullVMDKName); + logger.info("vmdkfile parent dir: " + snapshotFullVMDKName); File snapshotdir = new File(snapshotFullVMDKName); // File snapshotdir = new File(snapshotRoot); File[] ssfiles = snapshotdir.listFiles(); // List filenames = new ArrayList(); for (int i = 0; i < ssfiles.length; i++) { String vmdkfile = ssfiles[i].getName(); - s_logger.info("vmdk file name: " + vmdkfile); + logger.info("vmdk file name: " + vmdkfile); if (vmdkfile.toLowerCase().startsWith(backupSSUuid) && vmdkfile.toLowerCase().endsWith(".vmdk")) { snapshotFullVMDKName += vmdkfile; templateVMDKName += vmdkfile; @@ -724,20 +725,20 @@ private Ternary createTemplateFromSnapshot(long accountId, l } } if (snapshotFullVMDKName != null) { - command = new Script(false, "cp", _timeout, s_logger); + command = new Script(false, "cp", _timeout, logger); command.add(snapshotFullVMDKName); command.add(installFullPath); result = command.execute(); - s_logger.info("Copy VMDK file: " + snapshotFullVMDKName); + logger.info("Copy VMDK file: " + snapshotFullVMDKName); if (result != null) { String msg = "unable to copy snapshot vmdk file " + snapshotFullVMDKName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } } else { String msg = "unable to find any snapshot ova/ovf files" + snapshotFullOVAName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -848,20 +849,20 @@ private void restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, Datasto if (!ovfFile.exists()) { srcOVFFileName = getOVFFilePath(srcOVAFileName); if (srcOVFFileName == null && ovafile.exists()) { // volss: ova file exists; o/w can't do tar - Script command = new Script("tar", 0, s_logger); + Script command = new Script("tar", 0, logger); command.add("--no-same-owner"); command.add("-xf", srcOVAFileName); command.setWorkDir(secondaryMountPoint + "/" + secStorageDir + "/" + snapshotDir); - s_logger.info("Executing command: " + command.toString()); + logger.info("Executing command: " + command.toString()); String result = command.execute(); if (result != null) { String msg = "Unable to unpack snapshot OVA file at: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } else { String msg = "Unable to find snapshot OVA file at: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -869,7 +870,7 @@ private void restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, Datasto } if (srcOVFFileName == null) { String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -906,14 +907,14 @@ private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volume synchronized (exportPath.intern()) { if (!new File(exportPath).exists()) { - Script command = new Script(false, "mkdir", _timeout, s_logger); + Script command = new Script(false, "mkdir", _timeout, logger); command.add("-p"); command.add(exportPath); String result = command.execute(); if (result != null) { String errorMessage = String.format("Unable to prepare snapshot backup directory: [%s] due to [%s].", exportPath, result); - s_logger.error(errorMessage); + logger.error(errorMessage); throw new Exception(errorMessage); } } @@ -925,7 +926,7 @@ private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volume Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -936,7 +937,7 @@ private void exportVolumeToSecondaryStorage(VirtualMachineMO vmMo, String volume clonedVm = vmMo.getRunningHost().findVmOnHyperHost(workerVmName); if (clonedVm == null) { String msg = String.format("Unable to create dummy VM to export volume. volume path: [%s].", volumePath); - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } clonedVm.exportVm(exportPath, exportName, false, false); //Note: volss: not to create ova. @@ -965,7 +966,7 @@ private Pair copyVolumeToSecStorage(VmwareHostService hostServic if (morDs == null) { String msg = "Unable to find volumes's storage pool for copy volume operation"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -978,7 +979,7 @@ private Pair copyVolumeToSecStorage(VmwareHostService hostServic if (workerVm == null) { String msg = "Unable to create worker VM to execute CopyVolumeCommand"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -1029,20 +1030,20 @@ private String createOVAFromMetafile(String metafileName, int archiveTimeout) th File ova_metafile = new File(metafileName); Properties props = null; String ovaFileName = ""; - s_logger.info("Creating OVA using MetaFile: " + metafileName); + logger.info("Creating OVA using MetaFile: " + metafileName); try (FileInputStream strm = new FileInputStream(ova_metafile);) { - s_logger.info("loading properties from ova meta file: " + metafileName); + logger.info("loading properties from ova meta file: " + metafileName); props = new Properties(); props.load(strm); ovaFileName = props.getProperty("ova.filename"); - s_logger.info("ovafilename: " + ovaFileName); + logger.info("ovafilename: " + ovaFileName); String ovfFileName = props.getProperty("ovf"); - s_logger.info("ovffilename: " + ovfFileName); + logger.info("ovffilename: " + ovfFileName); int diskNum = Integer.parseInt(props.getProperty("numDisks")); if (diskNum <= 0) { String msg = "VMDK disk file number is 0. Error"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } String[] disks = new String[diskNum]; @@ -1050,16 +1051,16 @@ private String createOVAFromMetafile(String metafileName, int archiveTimeout) th // String diskNameKey = "disk" + Integer.toString(i+1) + ".name"; // Fang use this String diskNameKey = "disk1.name"; disks[i] = props.getProperty(diskNameKey); - s_logger.info("diskname " + disks[i]); + logger.info("diskname " + disks[i]); } String exportDir = ova_metafile.getParent(); - s_logger.info("exportDir: " + exportDir); + logger.info("exportDir: " + exportDir); // Important! we need to sync file system before we can safely use tar to work around a linux kernel bug(or feature) - s_logger.info("Sync file system before we package OVA..., before tar "); - s_logger.info("ova: " + ovaFileName + ", ovf:" + ovfFileName + ", vmdk:" + disks[0] + "."); - Script commandSync = new Script(true, "sync", 0, s_logger); + logger.info("Sync file system before we package OVA..., before tar "); + logger.info("ova: " + ovaFileName + ", ovf:" + ovfFileName + ", vmdk:" + disks[0] + "."); + Script commandSync = new Script(true, "sync", 0, logger); commandSync.execute(); - Script command = new Script(false, "tar", archiveTimeout, s_logger); + Script command = new Script(false, "tar", archiveTimeout, logger); command.setWorkDir(exportDir); // Fang: pass this in to the method? command.add("-cf", ovaFileName); command.add(ovfFileName); // OVF file should be the first file in OVA archive @@ -1067,18 +1068,18 @@ private String createOVAFromMetafile(String metafileName, int archiveTimeout) th command.add(diskName); } command.execute(); - s_logger.info("Package OVA for template in dir: " + exportDir + "cmd: " + command.toString()); + logger.info("Package OVA for template in dir: " + exportDir + "cmd: " + command.toString()); // to be safe, physically test existence of the target OVA file if ((new File(exportDir + File.separator + ovaFileName)).exists()) { - s_logger.info("OVA file: " + ovaFileName + " is created and ready to extract."); + logger.info("OVA file: " + ovaFileName + " is created and ready to extract."); return ovaFileName; } else { String msg = exportDir + File.separator + ovaFileName + " is not created as expected"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } catch (Exception e) { - s_logger.error("Exception while creating OVA using Metafile", e); + logger.error("Exception while creating OVA using Metafile", e); throw e; } @@ -1195,7 +1196,7 @@ public CreateVMSnapshotAnswer execute(VmwareHostService hostService, CreateVMSna if (info.getEntityName().equals(cmd.getVmName()) && org.apache.commons.lang3.StringUtils.isNotBlank(info.getName()) && info.getName().equalsIgnoreCase("CreateSnapshot_Task")) { if (!(info.getState().equals(TaskInfoState.SUCCESS) || info.getState().equals(TaskInfoState.ERROR))) { - s_logger.debug("There is already a VM snapshot task running, wait for it"); + logger.debug("There is already a VM snapshot task running, wait for it"); context.getVimClient().waitForTask(taskMor); } } @@ -1209,12 +1210,12 @@ public CreateVMSnapshotAnswer execute(VmwareHostService hostService, CreateVMSna if (vmMo == null) { String msg = "Unable to find VM for CreateVMSnapshotCommand"; - s_logger.info(msg); + logger.info(msg); return new CreateVMSnapshotAnswer(cmd, false, msg); } else { if (vmMo.getSnapshotMor(vmSnapshotName) != null) { - s_logger.info("VM snapshot " + vmSnapshotName + " already exists"); + logger.info("VM snapshot " + vmSnapshotName + " already exists"); } else if (!vmMo.createSnapshot(vmSnapshotName, vmSnapshotDesc, snapshotMemory, quiescevm)) { return new CreateVMSnapshotAnswer(cmd, false, "Unable to create snapshot due to esxi internal failed"); } @@ -1225,14 +1226,14 @@ public CreateVMSnapshotAnswer execute(VmwareHostService hostService, CreateVMSna } } catch (Exception e) { String msg = e.getMessage(); - s_logger.error("failed to create snapshot for vm:" + vmName + " due to " + msg, e); + logger.error("failed to create snapshot for vm:" + vmName + " due to " + msg, e); try { if (vmMo.getSnapshotMor(vmSnapshotName) != null) { vmMo.removeSnapshot(vmSnapshotName, false); } } catch (Exception e1) { - s_logger.info("[ignored]" + "error during snapshot remove: " + e1.getLocalizedMessage()); + logger.info("[ignored]" + "error during snapshot remove: " + e1.getLocalizedMessage()); } return new CreateVMSnapshotAnswer(cmd, false, e.getMessage()); @@ -1331,7 +1332,7 @@ private ManagedObjectReference getDatastoreAsManagedObjectReference(String baseN return morDs; } } catch (Exception ex) { - s_logger.info("[ignored]" + "error getting managed object refference: " + ex.getLocalizedMessage()); + logger.info("[ignored]" + "error getting managed object refference: " + ex.getLocalizedMessage()); } // not managed storage, so use the standard way of getting a ManagedObjectReference for a datastore @@ -1356,22 +1357,22 @@ public DeleteVMSnapshotAnswer execute(VmwareHostService hostService, DeleteVMSna if (vmMo == null) { String msg = "Unable to find VM for RevertToVMSnapshotCommand"; - s_logger.debug(msg); + logger.debug(msg); return new DeleteVMSnapshotAnswer(cmd, false, msg); } else { if (vmMo.getSnapshotMor(vmSnapshotName) == null) { - s_logger.debug("can not find the snapshot " + vmSnapshotName + ", assume it is already removed"); + logger.debug("can not find the snapshot " + vmSnapshotName + ", assume it is already removed"); } else { if (!vmMo.removeSnapshot(vmSnapshotName, false)) { String msg = "delete vm snapshot " + vmSnapshotName + " due to error occurred in vmware"; - s_logger.error(msg); + logger.error(msg); return new DeleteVMSnapshotAnswer(cmd, false, msg); } } - s_logger.debug("snapshot: " + vmSnapshotName + " is removed"); + logger.debug("snapshot: " + vmSnapshotName + " is removed"); // after removed snapshot, the volumes' paths have been changed for the VM, needs to report new paths to manager @@ -1381,7 +1382,7 @@ public DeleteVMSnapshotAnswer execute(VmwareHostService hostService, DeleteVMSna } } catch (Exception e) { String msg = e.getMessage(); - s_logger.error("failed to delete vm snapshot " + vmSnapshotName + " of vm " + vmName + " due to " + msg, e); + logger.error("failed to delete vm snapshot " + vmSnapshotName + " of vm " + vmName + " due to " + msg, e); return new DeleteVMSnapshotAnswer(cmd, false, msg); } @@ -1408,7 +1409,7 @@ public RevertToVMSnapshotAnswer execute(VmwareHostService hostService, RevertToV TaskInfo info = (TaskInfo)(context.getVimClient().getDynamicProperty(taskMor, "info")); if (info.getEntityName().equals(cmd.getVmName()) && org.apache.commons.lang3.StringUtils.isNotBlank(info.getName()) && info.getName().equalsIgnoreCase("RevertToSnapshot_Task")) { - s_logger.debug("There is already a VM snapshot task running, wait for it"); + logger.debug("There is already a VM snapshot task running, wait for it"); context.getVimClient().waitForTask(taskMor); } } @@ -1422,7 +1423,7 @@ public RevertToVMSnapshotAnswer execute(VmwareHostService hostService, RevertToV if (vmMo == null) { String msg = "Unable to find VM for RevertToVMSnapshotCommand"; - s_logger.debug(msg); + logger.debug(msg); return new RevertToVMSnapshotAnswer(cmd, false, msg); } else { @@ -1454,7 +1455,7 @@ public RevertToVMSnapshotAnswer execute(VmwareHostService hostService, RevertToV } } catch (Exception e) { String msg = "revert vm " + vmName + " to snapshot " + snapshotName + " failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new RevertToVMSnapshotAnswer(cmd, false, msg); } @@ -1469,7 +1470,7 @@ private String deleteVolumeDirOnSecondaryStorage(long volumeId, String secStorag private String deleteDir(String dir) { synchronized (dir.intern()) { - Script command = new Script(false, "rm", _timeout, s_logger); + Script command = new Script(false, "rm", _timeout, logger); command.add("-rf"); command.add(dir); return command.execute(); diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java index 3ed5939aac55..9039c0f830cf 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareContextFactory.java @@ -19,7 +19,8 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.cluster.ClusterManager; @@ -31,7 +32,7 @@ @Component public class VmwareContextFactory { - private static final Logger s_logger = Logger.getLogger(VmwareContextFactory.class); + protected static Logger LOGGER = LogManager.getLogger(VmwareContextFactory.class); private static volatile int s_seq = 1; private static VmwareManager s_vmwareMgr; @@ -61,8 +62,8 @@ public static VmwareContext create(String vCenterAddress, String vCenterUserName assert (vCenterPassword != null); String serviceUrl = "https://" + vCenterAddress + "/sdk/vimService"; - if (s_logger.isDebugEnabled()) - s_logger.debug("initialize VmwareContext. url: " + serviceUrl + ", username: " + vCenterUserName + ", password: " + + if (LOGGER.isDebugEnabled()) + LOGGER.debug("initialize VmwareContext. url: " + serviceUrl + ", username: " + vCenterUserName + ", password: " + StringUtils.getMaskedPasswordForDisplay(vCenterPassword)); VmwareClient vimClient = new VmwareClient(vCenterAddress + "-" + s_seq++); @@ -88,7 +89,7 @@ public static VmwareContext getContext(String vCenterAddress, String vCenterUser } else { // Validate current context and verify if vCenter session timeout value of the context matches the timeout value set by Admin if (!context.validate() || (context.getVimClient().getVcenterSessionTimeout() != s_vmwareMgr.getVcenterSessionTimeout())) { - s_logger.info("Validation of the context failed, dispose and create a new one"); + LOGGER.info("Validation of the context failed, dispose and create a new one"); context.close(); context = create(vCenterAddress, vCenterUserName, vCenterPassword); } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 92821c7e26df..512715988bb9 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -75,8 +75,7 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; -import org.apache.log4j.NDC; +import org.apache.logging.log4j.ThreadContext; import org.joda.time.Duration; import com.cloud.agent.IAgentControl; @@ -378,7 +377,6 @@ import com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec; public class VmwareResource extends ServerResourceBase implements StoragePoolResource, ServerResource, VmwareHostService, VirtualRouterDeployer { - private static final Logger s_logger = Logger.getLogger(VmwareResource.class); public static final String VMDK_EXTENSION = ".vmdk"; private static final String EXECUTING_RESOURCE_COMMAND = "Executing resource command %s: [%s]."; public static final String BASEPATH = "/usr/share/cloudstack-common/vms/"; @@ -468,7 +466,7 @@ private String getCommandLogTitle(Command cmd) { public Answer executeRequest(Command cmd) { logCommand(cmd); Answer answer = null; - NDC.push(getCommandLogTitle(cmd)); + ThreadContext.push(getCommandLogTitle(cmd)); try { long cmdSequence = _cmdSequence++; Date startTime = DateUtil.currentGMTTime(); @@ -640,18 +638,18 @@ public Answer executeRequest(Command cmd) { JmxUtil.unregisterMBean("VMware " + _morHyperHost.getValue(), "Command " + mbeanToRemove.getProp("Sequence") + "-" + mbeanToRemove.getProp("Name")); } } catch (Exception e) { - if (s_logger.isTraceEnabled()) - s_logger.trace("Unable to register JMX monitoring due to exception " + ExceptionUtil.toString(e)); + if (logger.isTraceEnabled()) + logger.trace("Unable to register JMX monitoring due to exception " + ExceptionUtil.toString(e)); } } } finally { recycleServiceContext(); - NDC.pop(); + ThreadContext.pop(); } - if (s_logger.isTraceEnabled()) - s_logger.trace("End executeRequest(), cmd: " + cmd.getClass().getSimpleName()); + if (logger.isTraceEnabled()) + logger.trace("End executeRequest(), cmd: " + cmd.getClass().getSimpleName()); return answer; } @@ -662,12 +660,12 @@ private ExecutionResult getSystemVmVersionAndChecksum(String controlIp) { result = executeInVR(controlIp, VRScripts.VERSION, null); if (!result.isSuccess()) { String errMsg = String.format("GetSystemVMVersionCmd on %s failed, message %s", controlIp, result.getDetails()); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (final Exception e) { final String msg = "GetSystemVMVersionCmd failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg, e); } return result; @@ -697,7 +695,7 @@ private Answer execute(PatchSystemVmCommand cmd) { if (!org.apache.commons.lang3.StringUtils.isEmpty(checksum) && checksum.equals(scriptChecksum) && !cmd.isForced()) { String msg = String.format("No change in the scripts checksum, not patching systemVM %s", sysVMName); - s_logger.info(msg); + logger.info(msg); return new PatchSystemVmAnswer(cmd, msg, lines[0], lines[1]); } @@ -714,7 +712,7 @@ private Answer execute(PatchSystemVmCommand cmd) { String res = patchResult.second().replace("\n", " "); String[] output = res.split(":"); if (output.length != 2) { - s_logger.warn("Failed to get the latest script version"); + logger.warn("Failed to get the latest script version"); } else { scriptVersion = output[1].split(" ")[0]; } @@ -734,7 +732,7 @@ private Answer execute(SetupPersistentNetworkCommand cmd) { HostMO hostMO = new HostMO(context, host.getMor()); try { - prepareNetworkFromNicInfo(hostMO, cmd.getNic(), false, null); + prepareNetworkFromNicInfo(hostMO, cmd.getNic(), false, null, null); hostname = host.getHyperHostName(); } catch (Exception e) { return new SetupPersistentNetworkAnswer(cmd, false, "failed to setup port-group due to: "+ e.getLocalizedMessage()); @@ -771,9 +769,9 @@ protected void reconfigureProcessorByHandler(EnumMap vdisk = vmMo.getDiskDevice(volumePath); if (vdisk == null) { String errorMsg = String.format("Resize volume of VM [name: %s] failed because disk device [path: %s] doesn't exist.", vmMo.getVmName(), volumePath); - s_logger.error(errorMsg); + logger.error(errorMsg); throw new Exception(errorMsg); } @@ -1041,7 +1039,7 @@ private VirtualDisk getDiskAfterResizeDiskValidations(VirtualMachineMO vmMo, Str if (vdisk.second() != null && vdisk.second().toLowerCase().contains("ide")) { String errorMsg = String.format("Re-sizing a virtual disk over an IDE controller is not supported in the VMware hypervisor. " + "Please re-try when virtual disk is attached to VM [name: %s] using a SCSI controller.", vmMo.getVmName()); - s_logger.error(errorMsg); + logger.error(errorMsg); throw new Exception(errorMsg); } @@ -1049,7 +1047,7 @@ private VirtualDisk getDiskAfterResizeDiskValidations(VirtualMachineMO vmMo, Str if ((VirtualDiskFlatVer2BackingInfo) disk.getBacking() != null && ((VirtualDiskFlatVer2BackingInfo) disk.getBacking()).getParent() != null) { String errorMsg = String.format("Resize of volume in VM [name: %s] is not supported because Disk device [path: %s] has Parents: [%s].", vmMo.getVmName(), volumePath, ((VirtualDiskFlatVer2BackingInfo) disk.getBacking()).getParent().getUuid()); - s_logger.error(errorMsg); + logger.error(errorMsg); throw new Exception(errorMsg); } return disk; @@ -1065,8 +1063,8 @@ private Pair getNewPathAndChainInfoInDatastoreCluster(VirtualMac String[] diskChain = matchingExistingDisk.getDiskChain(); DatastoreFile file = new DatastoreFile(diskChain[0]); if (!file.getFileBaseName().equalsIgnoreCase(path)) { - if (s_logger.isInfoEnabled()) - s_logger.info("Detected disk-chain top file change on volume: " + path + " -> " + file.getFileBaseName()); + if (logger.isInfoEnabled()) + logger.info("Detected disk-chain top file change on volume: " + path + " -> " + file.getFileBaseName()); path = file.getFileBaseName(); chainInfo = _gson.toJson(matchingExistingDisk); return new Pair<>(path, chainInfo); @@ -1090,7 +1088,7 @@ private Pair getNewPoolUUIDAndChainInfoInDatastoreCluster(Virtua if (diskDatastoreMofromVM != null) { String actualPoolUuid = diskDatastoreMofromVM.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID); if (!actualPoolUuid.equalsIgnoreCase(poolUUID)) { - s_logger.warn(String.format("Volume %s found to be in a different storage pool %s", path, actualPoolUuid)); + logger.warn(String.format("Volume %s found to be in a different storage pool %s", path, actualPoolUuid)); poolUUID = actualPoolUuid; chainInfo = _gson.toJson(matchingExistingDisk); return new Pair<>(poolUUID, chainInfo); @@ -1152,13 +1150,13 @@ protected long[] getVPCNetworkStats(String privateIp, String publicIp, String op ExecutionResult callResult = executeInVR(privateIp, "vpc_netusage.sh", args); if (!callResult.isSuccess()) { - s_logger.error("Unable to execute NetworkUsage command on DomR (" + privateIp + "), domR may not be ready yet. failure due to " + callResult.getDetails()); + logger.error("Unable to execute NetworkUsage command on DomR (" + privateIp + "), domR may not be ready yet. failure due to " + callResult.getDetails()); } if (option.equals("get") || option.equals("vpn")) { String result = callResult.getDetails(); if (result == null || result.isEmpty()) { - s_logger.error(" vpc network usage get returns empty "); + logger.error(" vpc network usage get returns empty "); } long[] stats = new long[2]; if (result != null) { @@ -1180,10 +1178,10 @@ protected long[] getNetworkLbStats(String privateIp, String publicIp, Integer po String result = callResult.getDetails(); if (!Boolean.TRUE.equals(callResult.isSuccess())) { - s_logger.error(String.format("Unable to get network loadbalancer stats on DomR (%s), domR may not be ready yet. failure due to %s", privateIp, callResult.getDetails())); + logger.error(String.format("Unable to get network loadbalancer stats on DomR (%s), domR may not be ready yet. failure due to %s", privateIp, callResult.getDetails())); result = null; } else if (result == null || result.isEmpty()) { - s_logger.error("Get network loadbalancer stats returns empty result"); + logger.error("Get network loadbalancer stats returns empty result"); } long[] stats = new long[1]; if (result != null) { @@ -1236,7 +1234,7 @@ public ExecutionResult createFileInVR(String routerIp, String filePath, String f try { SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes("UTF-8"), fileName, null); } catch (Exception e) { - s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e); + logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e); return new ExecutionResult(false, e.getMessage()); } return new ExecutionResult(true, null); @@ -1281,7 +1279,7 @@ public ExecutionResult cleanupCommand(NetworkElementCommand cmd) { // private int findRouterEthDeviceIndex(String domrName, String routerIp, String mac) throws Exception { File keyFile = getSystemVmKeyFile(); - s_logger.info("findRouterEthDeviceIndex. mac: " + mac); + logger.info("findRouterEthDeviceIndex. mac: " + mac); ArrayList skipInterfaces = new ArrayList(Arrays.asList("all", "default", "lo")); // when we dynamically plug in a new NIC into virtual router, it may take time to show up in guest OS @@ -1298,13 +1296,13 @@ private int findRouterEthDeviceIndex(String domrName, String routerIp, String ma if (!(skipInterfaces.contains(token))) { String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token); - if (s_logger.isDebugEnabled()) - s_logger.debug("Run domr script " + cmd); + if (logger.isDebugEnabled()) + logger.debug("Run domr script " + cmd); Pair result2 = SshHelper.sshExecute(routerIp, DefaultDomRSshPort, "root", keyFile, null, // TODO need to find the dev index inside router based on IP address cmd); - if (s_logger.isDebugEnabled()) - s_logger.debug("result: " + result2.first() + ", output: " + result2.second()); + if (logger.isDebugEnabled()) + logger.debug("result: " + result2.first() + ", output: " + result2.second()); if (result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim())) { return Integer.parseInt(token.substring(3)); @@ -1315,13 +1313,13 @@ private int findRouterEthDeviceIndex(String domrName, String routerIp, String ma } } - s_logger.warn("can not find intereface associated with mac: " + mac + ", guest OS may still at loading state, retry..."); + logger.warn("can not find intereface associated with mac: " + mac + ", guest OS may still at loading state, retry..."); try { Thread.currentThread(); Thread.sleep(1000); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while trying to get mac."); + logger.debug("[ignored] interrupted while trying to get mac."); } } @@ -1350,7 +1348,7 @@ protected ExecutionResult prepareNetworkElementCommand(SetupGuestNetworkCommand nic.setDeviceId(ethDeviceNum); } catch (Exception e) { String msg = "Prepare SetupGuestNetwork failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); @@ -1369,7 +1367,7 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocVpcCommand cmd) { if (ip.isAdd()) { throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with."); } else { - s_logger.debug("VIF to deassociate IP with does not exist, return success"); + logger.debug("VIF to deassociate IP with does not exist, return success"); continue; } } @@ -1377,7 +1375,7 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocVpcCommand cmd) { ip.setNicDevId(ethDeviceNum); } } catch (Exception e) { - s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception: ", e); + logger.error("Prepare Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.toString()); } @@ -1394,7 +1392,7 @@ protected ExecutionResult prepareNetworkElementCommand(SetSourceNatCommand cmd) pubIp.setNicDevId(ethDeviceNum); } catch (Exception e) { String msg = "Prepare Ip SNAT failure due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new ExecutionResult(false, e.toString()); } return new ExecutionResult(true, null); @@ -1410,15 +1408,15 @@ private ExecutionResult prepareNetworkElementCommand(SetNetworkACLCommand cmd) { nic.setDeviceId(ethDeviceNum); } catch (Exception e) { String msg = "Prepare SetNetworkACL failed due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); } private PlugNicAnswer execute(PlugNicCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource PlugNicCommand " + _gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource PlugNicCommand " + _gson.toJson(cmd)); } try { @@ -1429,7 +1427,7 @@ private PlugNicAnswer execute(PlugNicCommand cmd) { plugNicCommandInternal(cmd.getVmName(), nicDeviceType, cmd.getNic(), cmd.getVMType()); return new PlugNicAnswer(cmd, true, "success"); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString()); } } @@ -1450,14 +1448,14 @@ private void plugNicCommandInternal(String vmName, VirtualEthernetCardType nicDe if (vmMo == null) { String msg = "Router " + vmName + " no longer exists to execute PlugNic command"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } /* if(!isVMWareToolsInstalled(vmMo)){ String errMsg = "vmware tools is not installed or not running, cannot add nic to vm " + vmName; - s_logger.debug(errMsg); + logger.debug(errMsg); return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + errMsg); } */ @@ -1476,18 +1474,18 @@ private void plugNicCommandInternal(String vmName, VirtualEthernetCardType nicDe deviceNumber++; VirtualDevice nic; - Pair networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, vmType); + Pair networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, nicTo.getNetworkSegmentName(), vmType); String dvSwitchUuid = null; if (VmwareHelper.isDvPortGroup(networkInfo.first())) { ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor); ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first()); dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor); - s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid); + logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid); nic = VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), dvSwitchUuid, nicTo.getMac(), deviceNumber + 1, true, true); } else { - s_logger.info("Preparing NIC device on network " + networkInfo.second()); + logger.info("Preparing NIC device on network " + networkInfo.second()); nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), nicTo.getMac(), deviceNumber + 1, true, true); } @@ -1513,14 +1511,14 @@ private ReplugNicAnswer execute(ReplugNicCommand cmd) { if (vmMo == null) { String msg = "Router " + vmName + " no longer exists to execute ReplugNic command"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } /* if(!isVMWareToolsInstalled(vmMo)){ String errMsg = "vmware tools is not installed or not running, cannot add nic to vm " + vmName; - s_logger.debug(errMsg); + logger.debug(errMsg); return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + errMsg); } */ @@ -1538,17 +1536,17 @@ private ReplugNicAnswer execute(ReplugNicCommand cmd) { return new ReplugNicAnswer(cmd, false, "Nic to replug not found"); } - Pair networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, cmd.getVMType()); + Pair networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, false, null, cmd.getVMType()); String dvSwitchUuid = null; if (VmwareHelper.isDvPortGroup(networkInfo.first())) { ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor); ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first()); dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor); - s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid); + logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid); VmwareHelper.updateDvNicDevice(nic, networkInfo.first(), dvSwitchUuid); } else { - s_logger.info("Preparing NIC device on network " + networkInfo.second()); + logger.info("Preparing NIC device on network " + networkInfo.second()); VmwareHelper.updateNicDevice(nic, networkInfo.first(), networkInfo.second()); } @@ -1557,7 +1555,7 @@ private ReplugNicAnswer execute(ReplugNicCommand cmd) { return new ReplugNicAnswer(cmd, true, "success"); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new ReplugNicAnswer(cmd, false, "Unable to execute ReplugNicCommand due to " + e.toString()); } } @@ -1579,14 +1577,14 @@ private UnPlugNicAnswer execute(UnPlugNicCommand cmd) { if (vmMo == null) { String msg = "VM " + vmName + " no longer exists to execute UnPlugNic command"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } /* if(!isVMWareToolsInstalled(vmMo)){ String errMsg = "vmware tools not installed or not running, cannot remove nic from vm " + vmName; - s_logger.debug(errMsg); + logger.debug(errMsg); return new UnPlugNicAnswer(cmd, false, "Unable to execute unPlugNicCommand due to " + errMsg); } */ @@ -1598,7 +1596,7 @@ private UnPlugNicAnswer execute(UnPlugNicCommand cmd) { return new UnPlugNicAnswer(cmd, true, "success"); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new UnPlugNicAnswer(cmd, false, "Unable to execute unPlugNicCommand due to " + e.toString()); } } @@ -1620,7 +1618,7 @@ private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final IpA } else { networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, ipAddressTO.getNetworkRate(), null, - _opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials, null); + _opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials, null, null); } int nicIndex = allocPublicNicIndex(vmMo); @@ -1680,7 +1678,7 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) { IpAddressTO[] ips = cmd.getIpAddresses(); String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); - String controlIp = VmwareResource.getRouterSshControlIp(cmd); + String controlIp = getRouterSshControlIp(cmd); VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName); @@ -1695,7 +1693,7 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) { if (vmMo == null) { String msg = "Router " + routerName + " no longer exists to execute IPAssoc command"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -1712,14 +1710,14 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) { String publicNetworkName = HypervisorHostHelper.getPublicNetworkNamePrefix(vlanId); Pair publicNicInfo = vmMo.getNicDeviceIndex(publicNetworkName); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Find public NIC index, public network name: " + publicNetworkName + ", index: " + publicNicInfo.first()); + if (logger.isDebugEnabled()) { + logger.debug("Find public NIC index, public network name: " + publicNetworkName + ", index: " + publicNicInfo.first()); } boolean addVif = false; if (ip.isAdd() && publicNicInfo.first() == -1) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp()); + if (logger.isDebugEnabled()) { + logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp()); } addVif = true; } @@ -1739,14 +1737,14 @@ private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) { if (publicNicInfo.first() < 0) { String msg = "Failed to find DomR VIF to associate/disassociate IP with."; - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } ip.setNicDevId(publicNicInfo.first()); ip.setNewNic(addVif); } } catch (Throwable e) { - s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); + logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); return new ExecutionResult(false, e.toString()); } return new ExecutionResult(true, null); @@ -1771,7 +1769,7 @@ private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) { if (vmMo == null) { String msg = String.format("Router %s no longer exists to execute IPAssoc command ", routerName); - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } final String lastIp = cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP); @@ -1790,7 +1788,7 @@ private ExecutionResult cleanupNetworkElementCommand(IpAssocCommand cmd) { configureNicDevice(vmMo, nicInfo.first(), VirtualDeviceConfigSpecOperation.REMOVE, "unplugNicCommand"); } } catch (Throwable e) { - s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); + logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); return new ExecutionResult(false, e.toString()); } return new ExecutionResult(true, null); @@ -1807,8 +1805,8 @@ private Pair getVirtualDevice(VirtualMachineMO vmMo, IpA String publicNetworkName = HypervisorHostHelper.getPublicNetworkNamePrefix(vlanId); Pair publicNicInfo = vmMo.getNicDeviceIndex(publicNetworkName); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Find public NIC index, public network name: %s , index: %s", publicNetworkName, publicNicInfo.first())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Find public NIC index, public network name: %s , index: %s", publicNetworkName, publicNicInfo.first())); } return new Pair<>(findVirtualNicDevice(vmMo, nicTO.getMac()), publicNicInfo.first()); @@ -1837,8 +1835,8 @@ public ExecutionResult executeInVR(String routerIP, String script, String args, Pair result; //TODO: Password should be masked, cannot output to log directly - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on VR: " + routerIP + ", script: " + script + " with args: " + args); + if (logger.isDebugEnabled()) { + logger.debug("Run command on VR: " + routerIP + ", script: " + script + " with args: " + args); } try { @@ -1846,11 +1844,11 @@ public ExecutionResult executeInVR(String routerIP, String script, String args, VRScripts.CONNECTION_TIMEOUT, VRScripts.CONNECTION_TIMEOUT, timeout); } catch (Exception e) { String msg = "Command failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg); + logger.error(msg); result = new Pair(false, msg); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(script + " execution result: " + result.first().toString()); + if (logger.isDebugEnabled()) { + logger.debug(script + " execution result: " + result.first().toString()); } return new ExecutionResult(result.first(), result.second()); } @@ -1860,29 +1858,29 @@ protected CheckSshAnswer execute(CheckSshCommand cmd) { String privateIp = cmd.getIp(); int cmdPort = cmd.getPort(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port, " + privateIp + ":" + cmdPort); } String errorMessage = "Can not ping System VM [%s], due to: [%s]."; try { String result = connect(cmd.getName(), privateIp, cmdPort); if (result != null) { - s_logger.error(String.format(errorMessage, vmName, result)); + logger.error(String.format(errorMessage, vmName, result)); return new CheckSshAnswer(cmd, String.format(errorMessage, vmName, result)); } } catch (Exception e) { - s_logger.error(String.format(errorMessage, vmName, e.getMessage()), e); + logger.error(String.format(errorMessage, vmName, e.getMessage()), e); return new CheckSshAnswer(cmd, e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port succeeded for vm " + vmName); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port succeeded for vm " + vmName); } if (VirtualMachineName.isValidRouterName(vmName)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Execute network usage setup command on " + vmName); + if (logger.isDebugEnabled()) { + logger.debug("Execute network usage setup command on " + vmName); } networkUsage(privateIp, "create", null); } @@ -1906,8 +1904,8 @@ private DiskTO[] validateDisks(DiskTO[] disks) { validatedDisks.add(vol); } } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Drop invalid disk option, volumeTO: " + _gson.toJson(vol)); + if (logger.isDebugEnabled()) { + logger.debug("Drop invalid disk option, volumeTO: " + _gson.toJson(vol)); } } } @@ -1964,7 +1962,7 @@ protected ScaleVmAnswer execute(ScaleVmCommand cmd) { throw new Exception("Unable to execute ScaleVmCommand"); } } catch (Exception e) { - s_logger.error(String.format("ScaleVmCommand failed due to: [%s].", VmwareHelper.getExceptionMessage(e)), e); + logger.error(String.format("ScaleVmCommand failed due to: [%s].", VmwareHelper.getExceptionMessage(e)), e); return new ScaleVmAnswer(cmd, false, String.format("Unable to execute ScaleVmCommand due to: [%s].", e.toString())); } return new ScaleVmAnswer(cmd, true, null); @@ -1990,7 +1988,7 @@ protected void ensureDiskControllers(VirtualMachineMO vmMo, Pair int availableBusNum = scsiControllerInfo.second() + 1; // method returned current max. bus number if (DiskControllerType.getType(scsiDiskController) != scsiControllerInfo.third()) { - s_logger.debug(String.format("Change controller type from: %s to: %s", scsiControllerInfo.third().toString(), + logger.debug(String.format("Change controller type from: %s to: %s", scsiControllerInfo.third().toString(), scsiDiskController)); vmMo.tearDownDevices(new Class[]{VirtualSCSIController.class}); vmMo.addScsiDeviceControllers(DiskControllerType.getType(scsiDiskController)); @@ -2066,7 +2064,7 @@ protected StartAnswer execute(StartCommand cmd) { if (vmInVcenter != null) { vmAlreadyExistsInVcenter = true; String msg = "VM with name: " + vmNameOnVcenter + " already exists in vCenter."; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -2079,7 +2077,7 @@ protected StartAnswer execute(StartCommand cmd) { HashMap> dataStoresDetails = inferDatastoreDetailsFromDiskInfo(hyperHost, context, disks, cmd); if ((dataStoresDetails == null) || (dataStoresDetails.isEmpty())) { String msg = "Unable to locate datastore details of the volumes to be attached"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -2093,7 +2091,7 @@ protected StartAnswer execute(StartCommand cmd) { List> diskDatastores = null; if (vmMo != null) { - s_logger.info("VM " + vmInternalCSName + " already exists, tear down devices for reconfiguration"); + logger.info("VM " + vmInternalCSName + " already exists, tear down devices for reconfiguration"); if (getVmPowerState(vmMo) != PowerState.PowerOff) vmMo.safePowerOff(_shutdownWaitMs); @@ -2112,8 +2110,8 @@ protected StartAnswer execute(StartCommand cmd) { vmMo = hyperHost.findVmOnPeerHyperHost(vmInternalCSName); if (vmMo != null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Found vm " + vmInternalCSName + " at other host, relocate to " + hyperHost.getHyperHostName()); + if (logger.isInfoEnabled()) { + logger.info("Found vm " + vmInternalCSName + " at other host, relocate to " + hyperHost.getHyperHostName()); } takeVmFromOtherHyperHost(hyperHost, vmInternalCSName); @@ -2132,7 +2130,7 @@ protected StartAnswer execute(StartCommand cmd) { // If a VM with the same name is found in a different cluster in the DC, unregister the old VM and configure a new VM (cold-migration). VirtualMachineMO existingVmInDc = dcMo.findVm(vmInternalCSName); if (existingVmInDc != null) { - s_logger.debug("Found VM: " + vmInternalCSName + " on a host in a different cluster. Unregistering the exisitng VM."); + logger.debug("Found VM: " + vmInternalCSName + " on a host in a different cluster. Unregistering the exisitng VM."); existingVmName = existingVmInDc.getName(); existingVmFileInfo = existingVmInDc.getFileInfo(); existingVmFileLayout = existingVmInDc.getFileLayout(); @@ -2143,7 +2141,7 @@ protected StartAnswer execute(StartCommand cmd) { if (deployAsIs) { vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName); if (vmMo == null) { - s_logger.info("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it"); + logger.info("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it"); vmMo = takeVmFromOtherHyperHost(hyperHost, vmInternalCSName); } } else { @@ -2158,7 +2156,7 @@ protected StartAnswer execute(StartCommand cmd) { DatastoreMO dsRootVolumeIsOn = rootDiskDataStoreDetails.second(); if (dsRootVolumeIsOn == null) { String msg = "Unable to locate datastore details of root volume"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } if (rootDisk.getDetails().get(DiskTO.PROTOCOL_TYPE) != null && rootDisk.getDetails().get(DiskTO.PROTOCOL_TYPE).equalsIgnoreCase(Storage.StoragePoolType.DatastoreCluster.toString())) { @@ -2179,8 +2177,8 @@ protected StartAnswer execute(StartCommand cmd) { registerVm(vmNameOnVcenter, dsRootVolumeIsOn); vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName); if (vmMo != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found registered vm " + vmInternalCSName + " at host " + hyperHost.getHyperHostName()); + if (logger.isDebugEnabled()) { + logger.debug("Found registered vm " + vmInternalCSName + " at host " + hyperHost.getHyperHostName()); } } tearDownVm(vmMo); @@ -2198,7 +2196,7 @@ protected StartAnswer execute(StartCommand cmd) { } } if (deployAsIs && !vmMo.hasSnapshot()) { - s_logger.info("Mapping VM disks to spec disks and tearing down datadisks (if any)"); + logger.info("Mapping VM disks to spec disks and tearing down datadisks (if any)"); mapSpecDisksToClonedDisksAndTearDownDatadisks(vmMo, vmInternalCSName, specDisks); } @@ -2247,7 +2245,7 @@ protected StartAnswer execute(StartCommand cmd) { vmConfigSpec.setMemoryHotAddEnabled(vmMo.isMemoryHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm()); String hostApiVersion = ((HostMO) hyperHost).getHostAboutInfo().getApiVersion(); if (numCoresPerSocket > 1 && hostApiVersion.compareTo("5.0") < 0) { - s_logger.warn("Dynamic scaling of CPU is not supported for Virtual Machines with multi-core vCPUs in case of ESXi hosts 4.1 and prior. Hence CpuHotAdd will not be" + logger.warn("Dynamic scaling of CPU is not supported for Virtual Machines with multi-core vCPUs in case of ESXi hosts 4.1 and prior. Hence CpuHotAdd will not be" + " enabled for Virtual Machine: " + vmInternalCSName); vmConfigSpec.setCpuHotAddEnabled(false); } else { @@ -2255,11 +2253,11 @@ protected StartAnswer execute(StartCommand cmd) { } if(!vmMo.isMemoryHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm()){ - s_logger.warn("hotadd of memory is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName); + logger.warn("hotadd of memory is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName); } if(!vmMo.isCpuHotAddSupported(guestOsId) && vmSpec.isEnableDynamicallyScaleVm()){ - s_logger.warn("hotadd of cpu is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName); + logger.warn("hotadd of cpu is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName); } configNestedHVSupport(vmMo, vmSpec, vmConfigSpec); @@ -2291,12 +2289,12 @@ protected StartAnswer execute(StartCommand cmd) { null, secDsMo.getMor(), true, true, ideUnitNumber++, i + 1); deviceConfigSpecArray[i].setDevice(isoInfo.first()); if (isoInfo.second()) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare ISO volume at new device " + _gson.toJson(isoInfo.first())); + if (logger.isDebugEnabled()) + logger.debug("Prepare ISO volume at new device " + _gson.toJson(isoInfo.first())); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD); } else { - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first())); + if (logger.isDebugEnabled()) + logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first())); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.EDIT); } i++; @@ -2314,13 +2312,13 @@ protected StartAnswer execute(StartCommand cmd) { Pair isoInfo = VmwareHelper.prepareIsoDevice(vmMo, null, null, true, true, ideUnitNumber++, i + 1); deviceConfigSpecArray[i].setDevice(isoInfo.first()); if (isoInfo.second()) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first())); + if (logger.isDebugEnabled()) + logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first())); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD); } else { - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first())); + if (logger.isDebugEnabled()) + logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first())); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.EDIT); } @@ -2409,8 +2407,8 @@ protected StartAnswer execute(StartCommand cmd) { if (diskChain != null && diskChain.length > 0) { DatastoreFile file = new DatastoreFile(diskChain[0]); if (!file.getFileBaseName().equalsIgnoreCase(volumeTO.getPath())) { - if (s_logger.isInfoEnabled()) - s_logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + file.getFileBaseName()); + if (logger.isInfoEnabled()) + logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + file.getFileBaseName()); volumeTO.setPath(file.getFileBaseName()); } } @@ -2419,8 +2417,8 @@ protected StartAnswer execute(StartCommand cmd) { String actualPoolUuid = diskDatastoreMofromVM.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID); if (actualPoolUuid != null && !actualPoolUuid.equalsIgnoreCase(primaryStore.getUuid())) { volumeDsDetails = new Pair<>(diskDatastoreMofromVM.getMor(), diskDatastoreMofromVM); - if (s_logger.isInfoEnabled()) - s_logger.info("Detected datastore uuid change on volume: " + volumeTO.getId() + " " + primaryStore.getUuid() + " -> " + actualPoolUuid); + if (logger.isInfoEnabled()) + logger.info("Detected datastore uuid change on volume: " + volumeTO.getId() + " " + primaryStore.getUuid() + " -> " + actualPoolUuid); ((PrimaryDataStoreTO)primaryStore).setUuid(actualPoolUuid); } } @@ -2440,15 +2438,15 @@ protected StartAnswer execute(StartCommand cmd) { Long maxIops = volumeTO.getIopsWriteRate() + volumeTO.getIopsReadRate(); VirtualDevice device = VmwareHelper.prepareDiskDevice(vmMo, null, controllerKey, diskChain, volumeDsDetails.first(), deviceNumber, i + 1, maxIops); - s_logger.debug(LogUtils.logGsonWithoutException("The following definitions will be used to start the VM: virtual device [%s], volume [%s].", device, volumeTO)); + logger.debug(LogUtils.logGsonWithoutException("The following definitions will be used to start the VM: virtual device [%s], volume [%s].", device, volumeTO)); diskStoragePolicyId = volumeTO.getvSphereStoragePolicyId(); if (StringUtils.isNotEmpty(diskStoragePolicyId)) { PbmProfileManagerMO profMgrMo = new PbmProfileManagerMO(context); diskProfileSpec = profMgrMo.getProfileSpec(diskStoragePolicyId); deviceConfigSpecArray[i].getProfile().add(diskProfileSpec); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Adding vSphere storage profile: %s to virtual disk [%s]", diskStoragePolicyId, _gson.toJson(device))); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Adding vSphere storage profile: %s to virtual disk [%s]", diskStoragePolicyId, _gson.toJson(device))); } } if (vol.getType() == Volume.Type.ROOT) { @@ -2459,8 +2457,8 @@ protected StartAnswer execute(StartCommand cmd) { deviceConfigSpecArray[i].setDevice(device); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD); - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare volume at new device " + _gson.toJson(device)); + if (logger.isDebugEnabled()) + logger.debug("Prepare volume at new device " + _gson.toJson(device)); i++; } else { @@ -2477,7 +2475,7 @@ protected StartAnswer execute(StartCommand cmd) { if (StringUtils.isNotBlank(guestOsId) && guestOsId.startsWith("darwin")) { //Mac OS VirtualDevice[] devices = vmMo.getMatchedDevices(new Class[]{VirtualUSBController.class}); if (devices.length == 0) { - s_logger.debug("No USB Controller device on VM Start. Add USB Controller device for Mac OS VM " + vmInternalCSName); + logger.debug("No USB Controller device on VM Start. Add USB Controller device for Mac OS VM " + vmInternalCSName); //For Mac OS X systems, the EHCI+UHCI controller is enabled by default and is required for USB mouse and keyboard access. VirtualDevice usbControllerDevice = VmwareHelper.prepareUSBControllerDevice(); @@ -2485,12 +2483,12 @@ protected StartAnswer execute(StartCommand cmd) { deviceConfigSpecArray[i].setDevice(usbControllerDevice); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD); - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare USB controller at new device " + _gson.toJson(deviceConfigSpecArray[i])); + if (logger.isDebugEnabled()) + logger.debug("Prepare USB controller at new device " + _gson.toJson(deviceConfigSpecArray[i])); i++; } else { - s_logger.debug("USB Controller device exists on VM Start for Mac OS VM " + vmInternalCSName); + logger.debug("USB Controller device exists on VM Start for Mac OS VM " + vmInternalCSName); } } @@ -2507,19 +2505,20 @@ protected StartAnswer execute(StartCommand cmd) { Map nicUuidToDvSwitchUuid = new HashMap(); for (NicTO nicTo : sortNicsByDeviceId(nics)) { - s_logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo)); + logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo)); String adapterTypeStr = deployAsIs ? mapAdapterType(deployAsIsInfo.getNicAdapterMap().get(nicTo.getDeviceId())) : vmSpec.getDetails().get(VmDetailConstants.NIC_ADAPTER); nicDeviceType = VirtualEthernetCardType.valueOf(adapterTypeStr); - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM " + vmInternalCSName + " will be started with NIC device type: " + nicDeviceType + " on NIC device " + nicTo.getDeviceId()); + if (logger.isDebugEnabled()) { + logger.debug("VM " + vmInternalCSName + " will be started with NIC device type: " + nicDeviceType + " on NIC device " + nicTo.getDeviceId()); } boolean configureVServiceInNexus = (nicTo.getType() == TrafficType.Guest) && (vmSpec.getDetails().containsKey("ConfigureVServiceInNexus")); VirtualMachine.Type vmType = cmd.getVirtualMachine().getType(); - Pair networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, configureVServiceInNexus, vmType); + Pair networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo, configureVServiceInNexus, + vmSpec.getNetworkIdToNetworkNameMap().getOrDefault(nicTo.getNetworkId(), null), vmType); if ((nicTo.getBroadcastType() != BroadcastDomainType.Lswitch) || (nicTo.getBroadcastType() == BroadcastDomainType.Lswitch && NiciraNvpApiVersion.isApiVersionLowerThan("4.2"))) { if (VmwareHelper.isDvPortGroup(networkInfo.first())) { @@ -2528,14 +2527,14 @@ protected StartAnswer execute(StartCommand cmd) { DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor); ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first()); dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor); - s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid); + logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid); nic = VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), dvSwitchUuid, nicTo.getMac(), i + 1, true, true); if (nicTo.getUuid() != null) { nicUuidToDvSwitchUuid.put(nicTo.getUuid(), dvSwitchUuid); } } else { - s_logger.info("Preparing NIC device on network " + networkInfo.second()); + logger.info("Preparing NIC device on network " + networkInfo.second()); nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), nicTo.getMac(), i + 1, true, true); } @@ -2549,8 +2548,8 @@ protected StartAnswer execute(StartCommand cmd) { deviceConfigSpecArray[i].setDevice(nic); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD); - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare NIC at new device " + _gson.toJson(deviceConfigSpecArray[i])); + if (logger.isDebugEnabled()) + logger.debug("Prepare NIC at new device " + _gson.toJson(deviceConfigSpecArray[i])); // this is really a hacking for DomR, upon DomR startup, we will reset all the NIC allocation after eth3 if (nicCount < 3) @@ -2597,8 +2596,8 @@ protected StartAnswer execute(StartCommand cmd) { if (StringUtils.isNotEmpty(vmStoragePolicyId)) { vmConfigSpec.getVmProfile().add(vmProfileSpec); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Configuring the VM %s with storage policy: %s", vmInternalCSName, vmStoragePolicyId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Configuring the VM %s with storage policy: %s", vmInternalCSName, vmStoragePolicyId)); } } // @@ -2633,7 +2632,7 @@ protected StartAnswer execute(StartCommand cmd) { // Power-on VM // if (powerOnVM(vmMo, vmInternalCSName, vmNameOnVcenter)) { - s_logger.debug(String.format("VM %s has been started successfully with hostname %s.", vmInternalCSName, vmNameOnVcenter)); + logger.debug(String.format("VM %s has been started successfully with hostname %s.", vmInternalCSName, vmNameOnVcenter)); } else { throw new Exception("Failed to start VM. vmName: " + vmInternalCSName + " with hostname " + vmNameOnVcenter); } @@ -2658,12 +2657,12 @@ protected StartAnswer execute(StartCommand cmd) { FileUtil.scpPatchFiles(controlIp, VRScripts.CONFIG_CACHE_LOCATION, DefaultDomRSshPort, pemFile, systemVmPatchFiles, BASEPATH); if (!_vrResource.isSystemVMSetup(vmInternalCSName, controlIp)) { String errMsg = "Failed to patch systemVM"; - s_logger.error(errMsg); + logger.error(errMsg); return new StartAnswer(cmd, errMsg); } } catch (Exception e) { String errMsg = "Failed to scp files to system VM. Patching of systemVM failed"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return new StartAnswer(cmd, String.format("%s due to: %s", errMsg, e.getMessage())); } } @@ -2692,14 +2691,14 @@ protected StartAnswer execute(StartCommand cmd) { } if (existingVmName != null && existingVmFileInfo != null) { - s_logger.debug(String.format("Since VM start failed, registering back an existing VM: [%s] that was unregistered.", existingVmName)); + logger.debug(String.format("Since VM start failed, registering back an existing VM: [%s] that was unregistered.", existingVmName)); try { DatastoreFile fileInDatastore = new DatastoreFile(existingVmFileInfo.getVmPathName()); DatastoreMO existingVmDsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(fileInDatastore.getDatastoreName())); registerVm(existingVmName, existingVmDsMo); } catch (Exception ex) { String message = String.format("Failed to register an existing VM: [%s] due to [%s].", existingVmName, VmwareHelper.getExceptionMessage(ex)); - s_logger.error(message, ex); + logger.error(message, ex); } } return startAnswer; @@ -2712,9 +2711,9 @@ private boolean powerOnVM(final VirtualMachineMO vmMo, final String vmInternalCS try { return vmMo.powerOn(); } catch (Exception e) { - s_logger.info(String.format("Got exception while power on VM %s with hostname %s", vmInternalCSName, vmNameOnVcenter), e); + logger.info(String.format("Got exception while power on VM %s with hostname %s", vmInternalCSName, vmNameOnVcenter), e); if (e.getMessage() != null && e.getMessage().contains("File system specific implementation of Ioctl[file] failed")) { - s_logger.debug(String.format("Failed to power on VM %s with hostname %s. Retrying", vmInternalCSName, vmNameOnVcenter)); + logger.debug(String.format("Failed to power on VM %s with hostname %s. Retrying", vmInternalCSName, vmNameOnVcenter)); } else { throw e; } @@ -2739,7 +2738,7 @@ private void configureIso(VmwareHypervisorHost hyperHost, VirtualMachineMO vmMo, if (iso.getPath() != null && !iso.getPath().isEmpty()) { DataStoreTO imageStore = iso.getDataStore(); if (!(imageStore instanceof NfsTO)) { - s_logger.debug("unsupported protocol"); + logger.debug("unsupported protocol"); throw new Exception("unsupported protocol"); } NfsTO nfsImageStore = (NfsTO) imageStore; @@ -2753,12 +2752,12 @@ private void configureIso(VmwareHypervisorHost hyperHost, VirtualMachineMO vmMo, VmwareHelper.prepareIsoDevice(vmMo, isoDatastoreInfo.first(), isoDatastoreInfo.second(), true, true, ideUnitNumber, i + 1); deviceConfigSpecArray[i].setDevice(isoInfo.first()); if (isoInfo.second()) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare ISO volume at new device " + _gson.toJson(isoInfo.first())); + if (logger.isDebugEnabled()) + logger.debug("Prepare ISO volume at new device " + _gson.toJson(isoInfo.first())); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD); } else { - if (s_logger.isDebugEnabled()) - s_logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first())); + if (logger.isDebugEnabled()) + logger.debug("Prepare ISO volume at existing device " + _gson.toJson(isoInfo.first())); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.EDIT); } } @@ -2862,7 +2861,7 @@ private void setDeployAsIsProperties(VirtualMachineMO vmMo, DeployAsIsInfoTO dep if (deployAsIsInfo != null && MapUtils.isNotEmpty(deployAsIsInfo.getProperties())) { Map properties = deployAsIsInfo.getProperties(); VmConfigInfo vAppConfig = vmMo.getConfigInfo().getVAppConfig(); - s_logger.info("Copying OVF properties to the values the user provided"); + logger.info("Copying OVF properties to the values the user provided"); setVAppPropertiesToConfigSpec(vAppConfig, properties, vmConfigSpec, hyperHost); } } @@ -2872,7 +2871,7 @@ private void setDeployAsIsProperties(VirtualMachineMO vmMo, DeployAsIsInfoTO dep */ private void mapSpecDisksToClonedDisksAndTearDownDatadisks(VirtualMachineMO vmMo, String vmInternalCSName, DiskTO[] specDisks) { try { - s_logger.debug("Mapping spec disks information to cloned VM disks for VM " + vmInternalCSName); + logger.debug("Mapping spec disks information to cloned VM disks for VM " + vmInternalCSName); if (vmMo != null && ArrayUtils.isNotEmpty(specDisks)) { List vmDisks = vmMo.getVirtualDisksOrderedByKey(); @@ -2888,7 +2887,7 @@ private void mapSpecDisksToClonedDisksAndTearDownDatadisks(VirtualMachineMO vmMo if (dataVolume instanceof VolumeObjectTO) { VolumeObjectTO volumeObjectTO = (VolumeObjectTO) dataVolume; if (!volumeObjectTO.getSize().equals(vmDisk.getCapacityInBytes())) { - s_logger.info("Mapped disk size is not the same as the cloned VM disk size: " + + logger.info("Mapped disk size is not the same as the cloned VM disk size: " + volumeObjectTO.getSize() + " - " + vmDisk.getCapacityInBytes()); } VirtualDeviceBackingInfo backingInfo = vmDisk.getBacking(); @@ -2901,29 +2900,29 @@ private void mapSpecDisksToClonedDisksAndTearDownDatadisks(VirtualMachineMO vmMo String relativePath = fileNameParts[1].split("/")[1].replace(".vmdk", ""); String vmSpecDatastoreUuid = volumeObjectTO.getDataStore().getUuid().replaceAll("-", ""); if (!datastoreUuid.equals(vmSpecDatastoreUuid)) { - s_logger.info("Mapped disk datastore UUID is not the same as the cloned VM datastore UUID: " + + logger.info("Mapped disk datastore UUID is not the same as the cloned VM datastore UUID: " + datastoreUuid + " - " + vmSpecDatastoreUuid); } volumeObjectTO.setPath(relativePath); specDisk.setPath(relativePath); rootDisks.add(vmDisk); } else { - s_logger.error("Empty backing filename for volume " + volumeObjectTO.getName()); + logger.error("Empty backing filename for volume " + volumeObjectTO.getName()); } } else { - s_logger.error("Could not get volume backing info for volume " + volumeObjectTO.getName()); + logger.error("Could not get volume backing info for volume " + volumeObjectTO.getName()); } } } vmDisks.removeAll(rootDisks); if (CollectionUtils.isNotEmpty(vmDisks)) { - s_logger.info("Tearing down datadisks for deploy-as-is VM"); + logger.info("Tearing down datadisks for deploy-as-is VM"); tearDownVMDisks(vmMo, vmDisks); } } } catch (Exception e) { String msg = "Error mapping deploy-as-is VM disks from cloned VM " + vmInternalCSName; - s_logger.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(e); } } @@ -2943,8 +2942,8 @@ private void setBootOptions(VirtualMachineTO vmSpec, String bootMode, VirtualMac if (bootOptions == null) { bootOptions = new VirtualMachineBootOptions(); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("configuring VM '%s' to enter hardware setup",vmSpec.getName())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("configuring VM '%s' to enter hardware setup",vmSpec.getName())); } bootOptions.setEnterBIOSSetup(vmSpec.isEnterHardwareSetup()); } @@ -2999,7 +2998,7 @@ protected List copyVAppConfigPropertySectionFromOVF(VmConfigIn if (ovfProperties.containsKey(info.getId())) { String value = ovfProperties.get(info.getId()); info.setValue(value); - s_logger.info("Setting OVF property ID = " + info.getId() + " VALUE = " + value); + logger.info("Setting OVF property ID = " + info.getId() + " VALUE = " + value); } spec.setInfo(info); spec.setOperation(useEdit ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD); @@ -3017,7 +3016,7 @@ protected List copyVAppConfigProductSectionFromOVF(VmConfigInfo for (VAppProductInfo info : productFromOvf) { VAppProductSpec spec = new VAppProductSpec(); spec.setInfo(info); - s_logger.info("Procuct info KEY " + info.getKey()); + logger.info("Procuct info KEY " + info.getKey()); spec.setOperation(useEdit ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD); specs.add(spec); } @@ -3073,7 +3072,7 @@ private void resizeRootDiskOnVMStart(VirtualMachineMO vmMo, DiskTO rootDiskTO, V final String[] diskChain = diskInfo.getDiskChain(); if (diskChain != null && diskChain.length > 1) { - s_logger.warn("Disk chain length for the VM is greater than one, this is not supported"); + logger.warn("Disk chain length for the VM is greater than one, this is not supported"); throw new CloudRuntimeException("Unsupported VM disk chain length: " + diskChain.length); } @@ -3083,7 +3082,7 @@ private void resizeRootDiskOnVMStart(VirtualMachineMO vmMo, DiskTO rootDiskTO, V resizingSupported = true; } if (!resizingSupported) { - s_logger.warn("Resizing of root disk is only support for scsi device/bus, the provide VM's disk device bus name is " + diskInfo.getDiskDeviceBusName()); + logger.warn("Resizing of root disk is only support for scsi device/bus, the provide VM's disk device bus name is " + diskInfo.getDiskDeviceBusName()); throw new CloudRuntimeException("Unsupported VM root disk device bus: " + diskInfo.getDiskDeviceBusName()); } @@ -3147,7 +3146,7 @@ protected void configureVideoCard(VirtualMachineMO vmMo, VirtualMachineTO vmSpec long svgaVmramSize = Long.parseLong(value); setNewVRamSizeVmVideoCard(vmMo, svgaVmramSize, vmConfigSpec); } catch (NumberFormatException e) { - s_logger.error("Unexpected value, cannot parse " + value + " to long due to: " + e.getMessage()); + logger.error("Unexpected value, cannot parse " + value + " to long due to: " + e.getMessage()); } } } @@ -3178,7 +3177,7 @@ protected void setNewVRamSizeVmVideoCard(VirtualMachineMO vmMo, long svgaVmramSi */ protected void modifyVmVideoCardVRamSize(VirtualMachineVideoCard videoCard, VirtualMachineMO vmMo, long svgaVmramSize, VirtualMachineConfigSpec vmConfigSpec) { if (videoCard.getVideoRamSizeInKB().longValue() != svgaVmramSize) { - s_logger.info("Video card memory was set " + toHumanReadableSize(videoCard.getVideoRamSizeInKB().longValue()) + " instead of " + toHumanReadableSize(svgaVmramSize)); + logger.info("Video card memory was set " + toHumanReadableSize(videoCard.getVideoRamSizeInKB().longValue()) + " instead of " + toHumanReadableSize(svgaVmramSize)); configureSpecVideoCardNewVRamSize(videoCard, svgaVmramSize, vmConfigSpec); } } @@ -3262,7 +3261,7 @@ private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, DiskTO for (int i = 0; i < disks.length; i++) { DatastoreFile file = new DatastoreFile(disks[i]); if (!isManaged && file.getDir() != null && file.getDir().isEmpty()) { - s_logger.info("Perform run-time datastore folder upgrade. sync " + disks[i] + " to VM folder"); + logger.info("Perform run-time datastore folder upgrade. sync " + disks[i] + " to VM folder"); disks[i] = VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmMo.getName(), dsMo, file.getFileBaseName(), VmwareManager.s_vmwareSearchExcludeFolder.value()); } } @@ -3290,7 +3289,7 @@ private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, DiskTO } } if (!dsMo.fileExists(datastoreDiskPath)) { - s_logger.warn("Volume " + volumeTO.getId() + " does not seem to exist on datastore, out of sync? path: " + datastoreDiskPath); + logger.warn("Volume " + volumeTO.getId() + " does not seem to exist on datastore, out of sync? path: " + datastoreDiskPath); } return new String[]{datastoreDiskPath}; @@ -3316,8 +3315,8 @@ protected void configNestedHVSupport(VirtualMachineMO vmMo, VirtualMachineTO vmS VmwareContext context = vmMo.getContext(); if ("true".equals(vmSpec.getDetails().get(VmDetailConstants.NESTED_VIRTUALIZATION_FLAG))) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability"); + if (logger.isDebugEnabled()) + logger.debug("Nested Virtualization enabled in configuration, checking hypervisor capability"); ManagedObjectReference hostMor = vmMo.getRunningHost().getMor(); ManagedObjectReference computeMor = context.getVimClient().getMoRefProp(hostMor, "parent"); @@ -3326,12 +3325,12 @@ protected void configNestedHVSupport(VirtualMachineMO vmMo, VirtualMachineTO vmS Boolean nestedHvSupported = hostCapability.isNestedHVSupported(); if (nestedHvSupported == null) { // nestedHvEnabled property is supported only since VMware 5.1. It's not defined for earlier versions. - s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " + vmSpec.getName()); + logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " + vmSpec.getName()); } else if (nestedHvSupported.booleanValue()) { - s_logger.debug("Hypervisor supports nested virtualization, enabling for VM " + vmSpec.getName()); + logger.debug("Hypervisor supports nested virtualization, enabling for VM " + vmSpec.getName()); vmConfigSpec.setNestedHVEnabled(true); } else { - s_logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " + vmSpec.getName()); + logger.warn("Hypervisor doesn't support nested virtualization, unable to set config for VM " + vmSpec.getName()); vmConfigSpec.setNestedHVEnabled(false); } } @@ -3388,7 +3387,7 @@ private static void configCustomExtraOption(List extraOptions, Virt } } - private static void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec) throws Exception { + private void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec) throws Exception { /** * We need to configure the port on the DV switch after the host is * connected. So make this happen between the configure and start of @@ -3398,7 +3397,7 @@ private static void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachi for (NicTO nicTo : sortNicsByDeviceId(vmSpec.getNics())) { if (nicTo.getBroadcastType() == BroadcastDomainType.Lswitch) { // We need to create a port with a unique vlan and pass the key to the nic device - s_logger.trace("Nic " + nicTo.toString() + " is connected to an NVP logicalswitch"); + logger.trace("Nic " + nicTo.toString() + " is connected to an NVP logicalswitch"); VirtualDevice nicVirtualDevice = vmMo.getNicDeviceByIndex(nicIndex); if (nicVirtualDevice == null) { throw new Exception("Failed to find a VirtualDevice for nic " + nicIndex); //FIXME Generic exceptions are bad @@ -3412,7 +3411,7 @@ private static void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachi String portGroupKey = port.getPortgroupKey(); String dvSwitchUuid = port.getSwitchUuid(); - s_logger.debug("NIC " + nicTo.toString() + " is connected to dvSwitch " + dvSwitchUuid + " pg " + portGroupKey + " port " + portKey); + logger.debug("NIC " + nicTo.toString() + " is connected to dvSwitch " + dvSwitchUuid + " pg " + portGroupKey + " port " + portKey); ManagedObjectReference dvSwitchManager = vmMo.getContext().getVimClient().getServiceContent().getDvSwitchManager(); ManagedObjectReference dvSwitch = vmMo.getContext().getVimClient().getService().queryDvsByUuid(dvSwitchManager, dvSwitchUuid); @@ -3432,7 +3431,7 @@ private static void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachi } VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPort.getConfig().getSetting(); VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings.getVlan(); - s_logger.trace("Found port " + dvPort.getKey() + " with vlan " + vlanId.getVlanId()); + logger.trace("Found port " + dvPort.getKey() + " with vlan " + vlanId.getVlanId()); if (vlanId.getVlanId() > 0 && vlanId.getVlanId() < 4095) { usedVlans.add(vlanId.getVlanId()); } @@ -3448,7 +3447,7 @@ private static void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachi VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings.getVlan(); BoolPolicy blocked = settings.getBlocked(); if (blocked.isValue() == Boolean.TRUE) { - s_logger.trace("Port is blocked, set a vlanid and unblock"); + logger.trace("Port is blocked, set a vlanid and unblock"); DVPortConfigSpec dvPortConfigSpec = new DVPortConfigSpec(); VMwareDVSPortSetting edittedSettings = new VMwareDVSPortSetting(); // Unblock @@ -3475,9 +3474,9 @@ private static void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachi if (!vmMo.getContext().getVimClient().waitForTask(task)) { throw new Exception("Failed to configure the dvSwitch port for nic " + nicTo.toString()); } - s_logger.debug("NIC " + nicTo.toString() + " connected to vlan " + i); + logger.debug("NIC " + nicTo.toString() + " connected to vlan " + i); } else { - s_logger.trace("Port already configured and set to vlan " + vlanId.getVlanId()); + logger.trace("Port already configured and set to vlan " + vlanId.getVlanId()); } } else if (backing instanceof VirtualEthernetCardNetworkBackingInfo) { // This NIC is connected to a Virtual Switch @@ -3486,7 +3485,7 @@ private static void postNvpConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachi //if NSX API VERSION >= 4.2, connect to br-int (nsx.network), do not create portgroup else previous behaviour //OK, connected to OpaqueNetwork } else { - s_logger.error("nic device backing is of type " + backing.getClass().getName()); + logger.error("nic device backing is of type " + backing.getClass().getName()); throw new Exception("Incompatible backing for a VirtualDevice for nic " + nicIndex); //FIXME Generic exceptions are bad } } @@ -3503,7 +3502,7 @@ private VirtualMachineDiskInfo getMatchingExistingDiskWithVolumeDetails(VirtualM VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(diskBackingFileBaseName, dsName); if (diskInfo != null) { - s_logger.info("Found existing disk info from volume path: " + volumePath); + logger.info("Found existing disk info from volume path: " + volumePath); return diskInfo; } else { if (chainInfo != null) { @@ -3515,7 +3514,7 @@ private VirtualMachineDiskInfo getMatchingExistingDiskWithVolumeDetails(VirtualM DatastoreFile file = new DatastoreFile(diskPath); diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName); if (diskInfo != null) { - s_logger.info("Found existing disk from chain info: " + diskPath); + logger.info("Found existing disk from chain info: " + diskPath); return diskInfo; } } @@ -3524,7 +3523,7 @@ private VirtualMachineDiskInfo getMatchingExistingDiskWithVolumeDetails(VirtualM if (diskInfo == null) { diskInfo = diskInfoBuilder.getDiskInfoByDeviceBusName(infoInChain.getDiskDeviceBusName()); if (diskInfo != null) { - s_logger.info("Found existing disk from chain device bus information: " + infoInChain.getDiskDeviceBusName()); + logger.info("Found existing disk from chain device bus information: " + infoInChain.getDiskDeviceBusName()); return diskInfo; } } @@ -3574,7 +3573,7 @@ private String getDiskController(VirtualMachineMO vmMo, VirtualMachineDiskInfo m if (deployAsIs && matchingExistingDisk != null) { String currentBusName = matchingExistingDisk.getDiskDeviceBusName(); if (currentBusName != null) { - s_logger.info("Chose disk controller based on existing information: " + currentBusName); + logger.info("Chose disk controller based on existing information: " + currentBusName); if (currentBusName.startsWith("ide")) { controllerType = DiskControllerType.ide; } else if (currentBusName.startsWith("scsi")) { @@ -3620,13 +3619,13 @@ private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO v DatastoreFile originalFile = new DatastoreFile(volumeTO.getPath()); if (!file.getFileBaseName().equalsIgnoreCase(originalFile.getFileBaseName())) { - if (s_logger.isInfoEnabled()) - s_logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + diskChain[0]); + if (logger.isInfoEnabled()) + logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + diskChain[0]); } } else { if (!file.getFileBaseName().equalsIgnoreCase(volumeTO.getPath())) { - if (s_logger.isInfoEnabled()) - s_logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + file.getFileBaseName()); + if (logger.isInfoEnabled()) + logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumeTO.getPath() + " -> " + file.getFileBaseName()); } } @@ -3659,13 +3658,13 @@ private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO v private void checkAndDeleteDatastoreFile(String filePath, List skipDatastores, DatastoreMO dsMo, DatacenterMO dcMo) throws Exception { if (dsMo != null && dcMo != null && (skipDatastores == null || !skipDatastores.contains(dsMo.getName()))) { - s_logger.debug("Deleting file: " + filePath); + logger.debug("Deleting file: " + filePath); dsMo.deleteFile(filePath, dcMo.getMor(), true); } } private void deleteUnregisteredVmFiles(VirtualMachineFileLayoutEx vmFileLayout, DatacenterMO dcMo, boolean deleteDisks, List skipDatastores) throws Exception { - s_logger.debug("Deleting files associated with an existing VM that was unregistered"); + logger.debug("Deleting files associated with an existing VM that was unregistered"); DatastoreFile vmFolder = null; try { List fileInfo = vmFileLayout.getFile(); @@ -3694,7 +3693,7 @@ else if (file.getType().equals("config")) } } catch (Exception e) { String message = "Failed to delete files associated with an existing VM that was unregistered due to " + VmwareHelper.getExceptionMessage(e); - s_logger.warn(message, e); + logger.warn(message, e); } } @@ -3796,7 +3795,7 @@ private DatastoreMO getDataStoreWhereDiskExists(VmwareHypervisorHost hyperHost, VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(diskBackingFileBaseName, dsName); if (diskInfo != null) { - s_logger.info("Found existing disk info from volume path: " + volume.getPath()); + logger.info("Found existing disk info from volume path: " + volume.getPath()); return dsMo; } else { String chainInfo = volume.getChainInfo(); @@ -3809,7 +3808,7 @@ private DatastoreMO getDataStoreWhereDiskExists(VmwareHypervisorHost hyperHost, DatastoreFile file = new DatastoreFile(diskPath); diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName); if (diskInfo != null) { - s_logger.info("Found existing disk from chain info: " + diskPath); + logger.info("Found existing disk from chain info: " + diskPath); return dsMo; } } @@ -3879,7 +3878,7 @@ private HashMap> inferDatastor if (morDatastore == null) { String msg = "Failed to get the mounted datastore for the volume's pool " + poolUuid; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -3935,7 +3934,7 @@ private String getVlanInfo(NicTO nicTo, String defaultVlan) { // TODO consider the spread of functionality between BroadcastDomainType and NetUtils return NetUtils.getPrimaryPvlanFromUri(nicTo.getBroadcastUri()); } else { - s_logger.warn("BroadcastType is not claimed as VLAN or PVLAN, but without vlan info in broadcast URI. Use vlan info from labeling: " + defaultVlan); + logger.warn("BroadcastType is not claimed as VLAN or PVLAN, but without vlan info in broadcast URI. Use vlan info from labeling: " + defaultVlan); return defaultVlan; } } else if (nicTo.getBroadcastType() == BroadcastDomainType.Lswitch) { @@ -3945,16 +3944,16 @@ private String getVlanInfo(NicTO nicTo, String defaultVlan) { URI broadcastUri = nicTo.getBroadcastUri(); if (broadcastUri != null) { String vlanId = BroadcastDomainType.getValue(broadcastUri); - s_logger.debug("Using VLAN [" + vlanId + "] from broadcast uri [" + broadcastUri + "]"); + logger.debug("Using VLAN [" + vlanId + "] from broadcast uri [" + broadcastUri + "]"); return vlanId; } } - s_logger.warn("Unrecognized broadcast type in VmwareResource, type: " + nicTo.getBroadcastType().toString() + ". Use vlan info from labeling: " + defaultVlan); + logger.warn("Unrecognized broadcast type in VmwareResource, type: " + nicTo.getBroadcastType().toString() + ". Use vlan info from labeling: " + defaultVlan); return defaultVlan; } - private Pair prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo, boolean configureVServiceInNexus, VirtualMachine.Type vmType) + private Pair prepareNetworkFromNicInfo(HostMO hostMo, NicTO nicTo, boolean configureVServiceInNexus, String networkName, VirtualMachine.Type vmType) throws Exception { Ternary switchDetails = getTargetSwitch(nicTo); @@ -3965,7 +3964,7 @@ private Pair prepareNetworkFromNicInfo(HostMO ho String namePrefix = getNetworkNamePrefix(nicTo); Pair networkInfo = null; - s_logger.info("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix); + logger.info("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix); if (VirtualSwitchType.StandardVirtualSwitch == switchType) { networkInfo = HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, @@ -3984,7 +3983,7 @@ private Pair prepareNetworkFromNicInfo(HostMO ho } networkInfo = HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, vlanId, svlanId, nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _opsTimeout, switchType, - _portsPerDvPortGroup, nicTo.getGateway(), configureVServiceInNexus, nicTo.getBroadcastType(), _vsmCredentials, nicTo.getDetails()); + _portsPerDvPortGroup, nicTo.getGateway(), configureVServiceInNexus, nicTo.getBroadcastType(), _vsmCredentials, nicTo.getDetails(), networkName); } return networkInfo; @@ -4073,13 +4072,13 @@ private VirtualMachineMO takeVmFromOtherHyperHost(VmwareHypervisorHost hyperHost ManagedObjectReference morTargetPhysicalHost = hyperHost.findMigrationTarget(vmMo); if (morTargetPhysicalHost == null) { String msg = "VM " + vmName + " is on other host and we have no resource available to migrate and start it here"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } if (!vmMo.relocate(morTargetPhysicalHost)) { String msg = "VM " + vmName + " is on other host and we failed to relocate it here"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -4134,7 +4133,7 @@ protected Answer execute(ReadyCommand cmd) { return new ReadyAnswer(cmd, "Host is not in connect state"); } } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new ReadyAnswer(cmd, VmwareHelper.getExceptionMessage(e)); } } @@ -4148,16 +4147,16 @@ protected Answer execute(GetHostStatsCommand cmd) { try { HostStatsEntry entry = getHyperHostStats(hyperHost); if (entry != null) { - s_logger.debug(String.format("Host stats response from hypervisor is: [%s].", _gson.toJson(entry))); + logger.debug(String.format("Host stats response from hypervisor is: [%s].", _gson.toJson(entry))); entry.setHostId(cmd.getHostId()); answer = new GetHostStatsAnswer(cmd, entry); } } catch (Exception e) { - s_logger.error(createLogMessageException(e, cmd), e); + logger.error(createLogMessageException(e, cmd), e); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("GetHostStats Answer: " + _gson.toJson(answer)); + if (logger.isTraceEnabled()) { + logger.trace("GetHostStats Answer: " + _gson.toJson(answer)); } return answer; @@ -4188,7 +4187,7 @@ protected Answer execute(GetVmStatsCommand cmd) { createLogMessageException(e, cmd); } - s_logger.debug(String.format("VM Stats Map is: [%s].", _gson.toJson(vmStatsMap))); + logger.debug(String.format("VM Stats Map is: [%s].", _gson.toJson(vmStatsMap))); return new GetVmStatsAnswer(cmd, vmStatsMap); } @@ -4296,7 +4295,7 @@ protected Answer execute(GetVmDiskStatsCommand cmd) { } } } catch (Exception e) { - s_logger.error(String.format("Unable to execute PerfQuerySpec due to: [%s]. The window interval is enabled in vCenter?", VmwareHelper.getExceptionMessage(e)), e); + logger.error(String.format("Unable to execute PerfQuerySpec due to: [%s]. The window interval is enabled in vCenter?", VmwareHelper.getExceptionMessage(e)), e); } } @@ -4307,12 +4306,12 @@ protected Answer execute(GetVmDiskStatsCommand cmd) { } } - s_logger.debug(String.format("VM Disks Maps is: [%s].", _gson.toJson(vmStatsMap))); + logger.debug(String.format("VM Disks Maps is: [%s].", _gson.toJson(vmStatsMap))); if (MapUtils.isNotEmpty(vmStatsMap)) { return new GetVmDiskStatsAnswer(cmd, "", cmd.getHostName(), vmStatsMap); } } catch (Exception e) { - s_logger.error(String.format("Unable to execute GetVmDiskStatsCommand due to [%s].", VmwareHelper.getExceptionMessage(e)), e); + logger.error(String.format("Unable to execute GetVmDiskStatsCommand due to [%s].", VmwareHelper.getExceptionMessage(e)), e); } return new GetVmDiskStatsAnswer(cmd, null, null, null); } @@ -4358,10 +4357,10 @@ protected GetVolumeStatsAnswer execute(GetVolumeStatsCommand cmd) { } } } - s_logger.debug(String.format("Volume Stats Entry is: [%s].", _gson.toJson(statEntry))); + logger.debug(String.format("Volume Stats Entry is: [%s].", _gson.toJson(statEntry))); return new GetVolumeStatsAnswer(cmd, "", statEntry); } catch (Exception e) { - s_logger.error(String.format("VOLSTAT GetVolumeStatsCommand failed due to [%s].", VmwareHelper.getExceptionMessage(e)), e); + logger.error(String.format("VOLSTAT GetVolumeStatsCommand failed due to [%s].", VmwareHelper.getExceptionMessage(e)), e); } return new GetVolumeStatsAnswer(cmd, "", null); @@ -4390,11 +4389,11 @@ protected Answer execute(StopCommand cmd) { if (cmd.checkBeforeCleanup()) { if (getVmPowerState(vmMo) != PowerState.PowerOff) { String msg = "StopCommand is sent for cleanup and VM " + cmd.getVmName() + " is current running. ignore it."; - s_logger.warn(msg); + logger.warn(msg); return new StopAnswer(cmd, msg, false); } else { String msg = "StopCommand is sent for cleanup and VM " + cmd.getVmName() + " is indeed stopped already."; - s_logger.info(msg); + logger.info(msg); return new StopAnswer(cmd, msg, true); } } @@ -4413,7 +4412,7 @@ protected Answer execute(StopCommand cmd) { } if (!success) { msg = "Have problem in powering off VM " + cmd.getVmName() + ", let the process continue"; - s_logger.warn(msg); + logger.warn(msg); } disconnectConfigDriveIsoIfExists(vmMo); @@ -4421,13 +4420,13 @@ protected Answer execute(StopCommand cmd) { } String msg = "VM " + cmd.getVmName() + " is already in stopped state"; - s_logger.info(msg); + logger.info(msg); return new StopAnswer(cmd, msg, true); } finally { } } else { String msg = "VM " + cmd.getVmName() + " is no longer on the expected host in vSphere"; - s_logger.info(msg); + logger.info(msg); return new StopAnswer(cmd, msg, true); } } catch (Exception e) { @@ -4450,12 +4449,12 @@ private void disconnectConfigDriveIsoIfExists(VirtualMachineMO vmMo) { if (!isoFilePath.contains(ConfigDrive.CONFIGDRIVEDIR)) { continue; } - s_logger.info(String.format("Disconnecting config drive at location: %s", isoFilePath)); + logger.info(String.format("Disconnecting config drive at location: %s", isoFilePath)); vmMo.detachIso(isoFilePath, true); return; } } catch (Exception e) { - s_logger.warn(String.format("Couldn't check/disconnect config drive, error: %s", e.getMessage()), e); + logger.warn(String.format("Couldn't check/disconnect config drive, error: %s", e.getMessage()), e); } } @@ -4484,7 +4483,7 @@ protected Answer execute(RebootCommand cmd) { if (vmMo != null) { if (vmMo.isToolsInstallerMounted()) { toolsInstallerMounted = true; - s_logger.trace("Detected mounted vmware tools installer for :[" + cmd.getVmName() + "]"); + logger.trace("Detected mounted vmware tools installer for :[" + cmd.getVmName() + "]"); } try { if (canSetEnableSetupConfig(vmMo,cmd.getVirtualMachine())) { @@ -4494,9 +4493,9 @@ protected Answer execute(RebootCommand cmd) { return new RebootAnswer(cmd, "Failed to configure VM to boot into hardware setup menu: " + vmMo.getName(), false); } } catch (ToolsUnavailableFaultMsg e) { - s_logger.warn("VMware tools is not installed at guest OS, we will perform hard reset for reboot"); + logger.warn("VMware tools is not installed at guest OS, we will perform hard reset for reboot"); } catch (Exception e) { - s_logger.warn("We are not able to perform gracefull guest reboot due to " + VmwareHelper.getExceptionMessage(e)); + logger.warn("We are not able to perform gracefull guest reboot due to " + VmwareHelper.getExceptionMessage(e)); } // continue to try with hard-reset @@ -4505,11 +4504,11 @@ protected Answer execute(RebootCommand cmd) { } String msg = "Reboot failed in vSphere. vm: " + cmd.getVmName(); - s_logger.warn(msg); + logger.warn(msg); return new RebootAnswer(cmd, msg, false); } else { String msg = "Unable to find the VM in vSphere to reboot. vm: " + cmd.getVmName(); - s_logger.warn(msg); + logger.warn(msg); return new RebootAnswer(cmd, msg, false); } } catch (Exception e) { @@ -4518,9 +4517,9 @@ protected Answer execute(RebootCommand cmd) { if (toolsInstallerMounted) { try { vmMo.mountToolsInstaller(); - s_logger.debug(String.format("Successfully re-mounted vmware tools installer for :[%s].", cmd.getVmName())); + logger.debug(String.format("Successfully re-mounted vmware tools installer for :[%s].", cmd.getVmName())); } catch (Exception e) { - s_logger.error(String.format("Unabled to re-mount vmware tools installer for: [%s].", cmd.getVmName()), e); + logger.error(String.format("Unabled to re-mount vmware tools installer for: [%s].", cmd.getVmName()), e); } } } @@ -4536,8 +4535,8 @@ private boolean canSetEnableSetupConfig(VirtualMachineMO vmMo, VirtualMachineTO if (virtualMachine.isEnterHardwareSetup()) { VirtualMachineBootOptions bootOptions = new VirtualMachineBootOptions(); VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("configuring VM '%s' to reboot into hardware setup menu.",virtualMachine.getName())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("configuring VM '%s' to reboot into hardware setup menu.",virtualMachine.getName())); } bootOptions.setEnterBIOSSetup(virtualMachine.isEnterHardwareSetup()); vmConfigSpec.setBootOptions(bootOptions); @@ -4546,7 +4545,7 @@ private boolean canSetEnableSetupConfig(VirtualMachineMO vmMo, VirtualMachineTO return false; } } catch (Exception e) { - s_logger.error(String.format("failed to reconfigure VM '%s' to boot into hardware setup menu",virtualMachine.getName()),e); + logger.error(String.format("failed to reconfigure VM '%s' to boot into hardware setup menu",virtualMachine.getName()),e); return false; } } @@ -4567,7 +4566,7 @@ protected Answer execute(CheckVirtualMachineCommand cmd) { powerState = getVmPowerState(vmMo); return new CheckVirtualMachineAnswer(cmd, powerState, vncPort); } else { - s_logger.warn("Can not find vm " + vmName + " to execute CheckVirtualMachineCommand"); + logger.warn("Can not find vm " + vmName + " to execute CheckVirtualMachineCommand"); return new CheckVirtualMachineAnswer(cmd, powerState, vncPort); } @@ -4587,13 +4586,13 @@ protected Answer execute(PrepareForMigrationCommand cmd) { // find VM through datacenter (VM is not at the target host yet) VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName); if (vmMo == null) { - s_logger.info("VM " + vmName + " was not found in the cluster of host " + hyperHost.getHyperHostName() + ". Looking for the VM in datacenter."); + logger.info("VM " + vmName + " was not found in the cluster of host " + hyperHost.getHyperHostName() + ". Looking for the VM in datacenter."); ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), dcMor); vmMo = dcMo.findVm(vmName); if (vmMo == null) { String msg = "VM " + vmName + " does not exist in VMware datacenter"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -4601,7 +4600,8 @@ protected Answer execute(PrepareForMigrationCommand cmd) { NicTO[] nics = vm.getNics(); for (NicTO nic : nics) { // prepare network on the host - prepareNetworkFromNicInfo(new HostMO(getServiceContext(), _morHyperHost), nic, false, cmd.getVirtualMachine().getType()); + prepareNetworkFromNicInfo(new HostMO(getServiceContext(), _morHyperHost), nic, false, + vm.getNetworkIdToNetworkNameMap().getOrDefault(nic.getNetworkId(), null), cmd.getVirtualMachine().getType()); } List> secStoreUrlAndIdList = mgr.getSecondaryStorageStoresUrlAndIdList(Long.parseLong(_dcId)); @@ -4632,13 +4632,13 @@ protected Answer execute(MigrateVmToPoolCommand cmd) { try { VirtualMachineMO vmMo = getVirtualMachineMO(vmName, hyperHost); if (vmMo == null) { - s_logger.info("VM " + vmName + " was not found in the cluster of host " + hyperHost.getHyperHostName() + ". Looking for the VM in datacenter."); + logger.info("VM " + vmName + " was not found in the cluster of host " + hyperHost.getHyperHostName() + ". Looking for the VM in datacenter."); ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), dcMor); vmMo = dcMo.findVm(vmName); if (vmMo == null) { String msg = "VM " + vmName + " does not exist in VMware datacenter"; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } @@ -4647,10 +4647,10 @@ protected Answer execute(MigrateVmToPoolCommand cmd) { if (e instanceof Exception) { return new Answer(cmd, (Exception) e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("problem", e); + if (logger.isDebugEnabled()) { + logger.debug("problem", e); } - s_logger.error(e.getLocalizedMessage()); + logger.error(e.getLocalizedMessage()); return new Answer(cmd, false, "unknown problem: " + e.getLocalizedMessage()); } } @@ -4674,9 +4674,9 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy if (cmd instanceof MigrateVolumeCommand) { // Else device keys will be found in relocateVirtualMachine MigrateVolumeCommand mcmd = (MigrateVolumeCommand) cmd; addVolumeDiskmapping(vmMo, volumeDeviceKey, mcmd.getVolumePath(), mcmd.getVolumeId()); - if (s_logger.isTraceEnabled()) { + if (logger.isTraceEnabled()) { for (Integer diskId: volumeDeviceKey.keySet()) { - s_logger.trace(String.format("Disk to migrate has disk id %d and volumeId %d", diskId, volumeDeviceKey.get(diskId))); + logger.trace(String.format("Disk to migrate has disk id %d and volumeId %d", diskId, volumeDeviceKey.get(diskId))); } } } @@ -4684,7 +4684,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy return createAnswerForCmd(vmMo, volumeToList, cmd, volumeDeviceKey); } catch (Exception e) { String msg = "Change data store for VM " + vmMo.getVmName() + " failed"; - s_logger.error(msg + ": " + e.getLocalizedMessage()); + logger.error(msg + ": " + e.getLocalizedMessage()); throw new CloudRuntimeException(msg, e); } } @@ -4694,8 +4694,8 @@ Answer createAnswerForCmd(VirtualMachineMO vmMo, List volumeObje VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder(); VirtualDisk[] disks = vmMo.getAllDiskDevice(); Answer answer; - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("creating answer for %s", cmd.getClass().getSimpleName())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("creating answer for %s", cmd.getClass().getSimpleName())); } if (cmd instanceof MigrateVolumeCommand) { if (disks.length == 1) { @@ -4711,8 +4711,8 @@ Answer createAnswerForCmd(VirtualMachineMO vmMo, List volumeObje } private void addVolumeDiskmapping(VirtualMachineMO vmMo, Map volumeDeviceKey, String volumePath, long volumeId) throws Exception { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("locating disk for volume (%d) using path %s", volumeId, volumePath)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("locating disk for volume (%d) using path %s", volumeId, volumePath)); } Pair diskInfo = getVirtualDiskInfo(vmMo, volumePath + VMDK_EXTENSION); String vmdkAbsFile = VmwareHelper.getAbsoluteVmdkFile(diskInfo.first()); @@ -4727,13 +4727,13 @@ private ManagedObjectReference getTargetDatastoreMOReference(String destinationP VmwareHypervisorHost hyperHost) { ManagedObjectReference morDs; try { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("finding datastore %s", destinationPool)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("finding datastore %s", destinationPool)); } morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, destinationPool); } catch (Exception e) { String msg = "exception while finding data store " + destinationPool; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg + ": " + e.getLocalizedMessage()); } return morDs; @@ -4745,7 +4745,7 @@ private ManagedObjectReference getDataCenterMOReference(String vmName, VmwareHyp morDc = hyperHost.getHyperHostDatacenter(); } catch (Exception e) { String msg = "exception while finding VMware datacenter to search for VM " + vmName; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg + ": " + e.getLocalizedMessage()); } return morDc; @@ -4758,7 +4758,7 @@ private VirtualMachineMO getVirtualMachineMO(String vmName, VmwareHypervisorHost vmMo = hyperHost.findVmOnPeerHyperHost(vmName); } catch (Exception e) { String msg = "exception while searching for VM " + vmName + " in VMware datacenter"; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg + ": " + e.getLocalizedMessage()); } return vmMo; @@ -4780,7 +4780,7 @@ protected Answer execute(MigrateCommand cmd) { VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName); if (vmMo == null) { String msg = "VM " + vmName + " does not exist in VMware datacenter"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -4800,7 +4800,7 @@ protected Answer execute(MigrateCommand cmd) { return new MigrateAnswer(cmd, true, "migration succeeded", null); } catch (Exception e) { - s_logger.info(String.format("migrate command for %s failed due to %s", vmName, e.getLocalizedMessage())); + logger.info(String.format("migrate command for %s failed due to %s", vmName, e.getLocalizedMessage())); return new MigrateAnswer(cmd, false, createLogMessageException(e, cmd), null); } } @@ -4815,7 +4815,7 @@ protected Answer execute(MigrateWithStorageCommand cmd) { return new MigrateWithStorageAnswer(cmd, volumeToList); } catch (Throwable e) { String msg = "MigrateWithStorageCommand failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.warn(msg, e); + logger.warn(msg, e); return new MigrateWithStorageAnswer(cmd, (Exception)e); } } @@ -4847,7 +4847,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) { morDestinationDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(dsHost, targetDsName); if(morDestinationDS == null) { String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost.getHyperHostName(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } destinationDsMo = new DatastoreMO(hyperHost.getContext(), morDestinationDS); @@ -4863,7 +4863,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) { // OfflineVmwareMigration: more robust would be to find the store given the volume as it might have been moved out of band or due to error // example: DatastoreMO existingVmDsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(fileInDatastore.getDatastoreName())); - s_logger.info("Create worker VM " + vmName); + logger.info("Create worker VM " + vmName); // OfflineVmwareMigration: 2. create the worker with access to the data(store) vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, sourceDsMo, vmName, HypervisorHostHelper.getMinimumHostHardwareVersion(hyperHost, hyperHostInTargetCluster)); @@ -4877,14 +4877,14 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) { String vmdkFileName = path + VMDK_EXTENSION; vmdkDataStorePath = VmwareStorageLayoutHelper.getLegacyDatastorePathFromVmdkFileName(sourceDsMo, vmdkFileName); if (!sourceDsMo.fileExists(vmdkDataStorePath)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("path not found (%s), trying under '%s'", vmdkFileName, path)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("path not found (%s), trying under '%s'", vmdkFileName, path)); } vmdkDataStorePath = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(sourceDsMo, path, vmdkFileName); } if (!sourceDsMo.folderExists(String.format("[%s]", sourceDsMo.getName()), path) || !sourceDsMo.fileExists(vmdkDataStorePath)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("path not found (%s), trying under '%s'", vmdkFileName, vmName)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("path not found (%s), trying under '%s'", vmdkFileName, vmName)); } vmdkDataStorePath = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(sourceDsMo, vmName, vmdkFileName); } @@ -4892,8 +4892,8 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) { vmdkDataStorePath = sourceDsMo.searchFileInSubFolders(vmdkFileName, true, null); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("attaching %s to %s for migration", vmdkDataStorePath, vmMo.getVmName())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("attaching %s to %s for migration", vmdkDataStorePath, vmMo.getVmName())); } vmMo.attachDisk(new String[]{vmdkDataStorePath}, morSourceDS); } @@ -4903,23 +4903,23 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) { vmMo = hyperHost.findVmOnPeerHyperHost(vmName); if (vmMo == null) { String msg = "VM " + vmName + " does not exist in VMware datacenter"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } - if (s_logger.isTraceEnabled()) { + if (logger.isTraceEnabled()) { VirtualDisk[] disks = vmMo.getAllDiskDevice(); String format = "disk %d is attached as %s"; for (VirtualDisk disk : disks) { - s_logger.trace(String.format(format, disk.getKey(), vmMo.getVmdkFileBaseName(disk))); + logger.trace(String.format(format, disk.getKey(), vmMo.getVmdkFileBaseName(disk))); } } // OfflineVmwareMigration: 5. create a relocate spec and perform Pair vdisk = vmMo.getDiskDevice(path); if (vdisk == null) { - if (s_logger.isTraceEnabled()) - s_logger.trace("migrate volume done (failed)"); + if (logger.isTraceEnabled()) + logger.trace("migrate volume done (failed)"); throw new CloudRuntimeException("No such disk device: " + path); } @@ -4933,26 +4933,26 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) { answer = migrateAndAnswer(vmMo, cmd.getTargetPool().getUuid(), hyperHost, cmd); } catch (Exception e) { String msg = String.format("Migration of volume '%s' failed due to %s", cmd.getVolumePath(), e.getLocalizedMessage()); - s_logger.error(msg, e); + logger.error(msg, e); answer = new Answer(cmd, false, msg); } finally { try { // OfflineVmwareMigration: worker *may* have been renamed vmName = vmMo.getVmName(); - s_logger.info("Dettaching disks before destroying worker VM '" + vmName + "' after volume migration"); + logger.info("Dettaching disks before destroying worker VM '" + vmName + "' after volume migration"); VirtualDisk[] disks = vmMo.getAllDiskDevice(); String format = "disk %d was migrated to %s"; for (VirtualDisk disk : disks) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format(format, disk.getKey(), vmMo.getVmdkFileBaseName(disk))); + if (logger.isTraceEnabled()) { + logger.trace(String.format(format, disk.getKey(), vmMo.getVmdkFileBaseName(disk))); } vmdkDataStorePath = VmwareStorageLayoutHelper.getLegacyDatastorePathFromVmdkFileName(destinationDsMo, vmMo.getVmdkFileBaseName(disk) + VMDK_EXTENSION); vmMo.detachDisk(vmdkDataStorePath, false); } - s_logger.info("Destroy worker VM '" + vmName + "' after volume migration"); + logger.info("Destroy worker VM '" + vmName + "' after volume migration"); vmMo.destroy(); } catch (Throwable e) { - s_logger.info("Failed to destroy worker VM: " + vmName); + logger.info("Failed to destroy worker VM: " + vmName); } } if (answer instanceof MigrateVolumeAnswer) { @@ -4965,12 +4965,12 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) { if (!destinationDsMo.fileExists(vmdkDataStorePath)) { String msg = String.format("Migration of volume '%s' failed; file (%s) not found as path '%s'", cmd.getVolumePath(), vmdkFileName, vmdkDataStorePath); - s_logger.error(msg); + logger.error(msg); answer = new Answer(cmd, false, msg); } } catch (Exception e) { String msg = String.format("Migration of volume '%s' failed due to %s", cmd.getVolumePath(), e.getLocalizedMessage()); - s_logger.error(msg, e); + logger.error(msg, e); answer = new Answer(cmd, false, msg); } } @@ -5013,7 +5013,7 @@ private Answer execute(MigrateVolumeCommand cmd) { if (vmMo == null) { String msg = "VM " + vmName + " does not exist in VMware datacenter " + morDc.getValue(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } vmName = vmMo.getName(); @@ -5021,7 +5021,7 @@ private Answer execute(MigrateVolumeCommand cmd) { if (morDs == null) { String msg = "Unable to find the mounted datastore with name: " + tgtDsName + " on source host: " + srcHyperHost.getHyperHostName() + " to execute MigrateVolumeCommand"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -5035,8 +5035,8 @@ private Answer execute(MigrateVolumeCommand cmd) { String[] diskChain = matchingExistingDisk.getDiskChain(); DatastoreFile file = new DatastoreFile(diskChain[0]); if (!file.getFileBaseName().equalsIgnoreCase(volumePath)) { - if (s_logger.isInfoEnabled()) - s_logger.info("Detected disk-chain top file change on volume: " + volumePath + " -> " + file.getFileBaseName()); + if (logger.isInfoEnabled()) + logger.info("Detected disk-chain top file change on volume: " + volumePath + " -> " + file.getFileBaseName()); volumePath = file.getFileBaseName(); } } @@ -5075,16 +5075,16 @@ private Answer execute(MigrateVolumeCommand cmd) { if (!vmMo.changeDatastore(relocateSpec)) { throw new Exception("Change datastore operation failed during volume migration"); } else { - s_logger.debug("Successfully migrated volume " + volumePath + " to target datastore " + tgtDsName); + logger.debug("Successfully migrated volume " + volumePath + " to target datastore " + tgtDsName); } // Consolidate VM disks. // In case of a linked clone VM, if VM's disks are not consolidated, // further volume operations on the ROOT volume such as volume snapshot etc. will result in DB inconsistencies. if (!vmMo.consolidateVmDisks()) { - s_logger.warn("VM disk consolidation failed after storage migration."); + logger.warn("VM disk consolidation failed after storage migration."); } else { - s_logger.debug("Successfully consolidated disks of VM " + vmName + "."); + logger.debug("Successfully consolidated disks of VM " + vmName + "."); } // Update and return volume path and chain info because that could have changed after migration @@ -5102,7 +5102,7 @@ private Answer execute(MigrateVolumeCommand cmd) { return answer; } catch (Exception e) { String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new MigrateVolumeAnswer(cmd, false, msg, null); } } @@ -5168,7 +5168,7 @@ protected Answer execute(ModifyTargetsCommand cmd) { hostMOs.add(hostMO); } } catch (Exception ex) { - s_logger.error(ex.getMessage(), ex); + logger.error(ex.getMessage(), ex); throw new CloudRuntimeException(ex.getMessage(), ex); } @@ -5314,7 +5314,7 @@ private void handleTargets(boolean add, ModifyTargetsCommand.TargetTypeToRemove try { _storageProcessor.handleTargets(add, targetTypeToRemove, isRemoveAsync, targets, hosts); } catch (Exception ex) { - s_logger.warn(ex.getMessage()); + logger.warn(ex.getMessage()); } } } @@ -5338,14 +5338,14 @@ protected Answer execute(DeleteStoragePoolCommand cmd) { } } catch (Throwable e) { if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); invalidateServiceContext(); } StorageFilerTO pool = cmd.getPool(); String msg = String.format("DeleteStoragePoolCommand (pool: [%s], path: [%s]) failed due to [%s].", pool.getHost(), pool.getPath(), VmwareHelper.getExceptionMessage(e)); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -5365,7 +5365,7 @@ protected AttachIsoAnswer execute(AttachIsoCommand cmd) { VirtualMachineMO vmMo = HypervisorHostHelper.findVmOnHypervisorHostOrPeer(hyperHost, cmd.getVmName()); if (vmMo == null) { String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + cmd.getVmName(); - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -5373,7 +5373,7 @@ protected AttachIsoAnswer execute(AttachIsoCommand cmd) { if (storeUrl == null) { if (!cmd.getIsoPath().equalsIgnoreCase(TemplateManager.VMWARE_TOOLS_ISO)) { String msg = "ISO store root url is not found in AttachIsoCommand"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } else { if (cmd.isAttach()) { @@ -5398,7 +5398,7 @@ protected AttachIsoAnswer execute(AttachIsoCommand cmd) { if (!isoPath.startsWith(storeUrl)) { assert (false); String msg = "ISO path does not start with the secondary storage root"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -5423,12 +5423,12 @@ protected AttachIsoAnswer execute(AttachIsoCommand cmd) { } catch (Throwable e) { if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); invalidateServiceContext(); } String message = String.format("AttachIsoCommand(%s) failed due to [%s].", cmd.isAttach()? "attach" : "detach", VmwareHelper.getExceptionMessage(e)); - s_logger.error(message, e); + logger.error(message, e); return new AttachIsoAnswer(cmd, false, message); } } @@ -5458,12 +5458,12 @@ public synchronized ManagedObjectReference prepareSecondaryDatastoreOnSpecificHo return morDatastore; } - private static String getSecondaryDatastoreUUID(String storeUrl) { + private String getSecondaryDatastoreUUID(String storeUrl) { String uuid = null; try { uuid = UUID.nameUUIDFromBytes(storeUrl.getBytes("UTF-8")).toString(); } catch (UnsupportedEncodingException e) { - s_logger.warn("Failed to create UUID from string " + storeUrl + ". Bad storeUrl or UTF-8 encoding error."); + logger.warn("Failed to create UUID from string " + storeUrl + ". Bad storeUrl or UTF-8 encoding error."); } return uuid; } @@ -5616,11 +5616,11 @@ protected Answer execute(GetStorageStatsCommand cmd) { long used = capacity - free; - s_logger.debug(String.format("Datastore summary info: [storageId: %s, ], localPath: %s, poolType: %s, capacity: %s, free: %s, used: %s].", cmd.getStorageId(), + logger.debug(String.format("Datastore summary info: [storageId: %s, ], localPath: %s, poolType: %s, capacity: %s, free: %s, used: %s].", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype(), toHumanReadableSize(capacity), toHumanReadableSize(free), toHumanReadableSize(used))); if (capacity <= 0) { - s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help"); + logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help"); } return new GetStorageStatsAnswer(cmd, capacity, used); @@ -5628,17 +5628,17 @@ protected Answer execute(GetStorageStatsCommand cmd) { String msg = String.format("Could not find datastore for GetStorageStatsCommand: [storageId: %s, localPath: %s, poolType: %s].", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype()); - s_logger.error(msg); + logger.error(msg); return new GetStorageStatsAnswer(cmd, msg); } } catch (Throwable e) { if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); invalidateServiceContext(); } String msg = String.format("Unable to execute GetStorageStatsCommand(storageId : [%s], localPath: [%s], poolType: [%s]) due to [%s]", cmd.getStorageId(), cmd.getLocalPath(), cmd.getPooltype(), VmwareHelper.getExceptionMessage(e)); - s_logger.error(msg, e); + logger.error(msg, e); return new GetStorageStatsAnswer(cmd, msg); } } @@ -5652,8 +5652,8 @@ protected Answer execute(GetVncPortCommand cmd) { VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getName()); if (vmMo == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find the owner VM for GetVncPortCommand on host " + hyperHost.getHyperHostName() + ", try within datacenter"); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find the owner VM for GetVncPortCommand on host " + hyperHost.getHyperHostName() + ", try within datacenter"); } vmMo = hyperHost.findVmOnPeerHyperHost(cmd.getName()); @@ -5665,8 +5665,8 @@ protected Answer execute(GetVncPortCommand cmd) { Pair portInfo = vmMo.getVncPort(mgr.getManagementPortGroupByHost((HostMO) hyperHost)); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Found vnc port info. vm: " + cmd.getName() + " host: " + portInfo.first() + ", vnc port: " + portInfo.second()); + if (logger.isTraceEnabled()) { + logger.trace("Found vnc port info. vm: " + cmd.getName() + " host: " + portInfo.first() + ", vnc port: " + portInfo.second()); } return new GetVncPortAnswer(cmd, portInfo.first(), portInfo.second()); } catch (Throwable e) { @@ -5679,7 +5679,7 @@ protected Answer execute(SetupCommand cmd) { } protected Answer execute(MaintainCommand cmd) { - return new MaintainAnswer(cmd, "Put host in maintaince"); + return new MaintainAnswer(cmd, "Put host in maintenance"); } protected Answer execute(PingTestCommand cmd) { @@ -5691,7 +5691,7 @@ protected Answer execute(PingTestCommand cmd) { if (result.first()) return new Answer(cmd); } catch (Exception e) { - s_logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + VmwareHelper.getExceptionMessage(e), e); + logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + VmwareHelper.getExceptionMessage(e), e); } return new Answer(cmd, false, "PingTestCommand failed"); } else { @@ -5715,7 +5715,7 @@ protected Answer execute(PingTestCommand cmd) { } } } catch (Exception e) { - s_logger.error("Unable to execute ping command on host (" + cmd.getComputingHostIp() + "). failure due to " + VmwareHelper.getExceptionMessage(e), e); + logger.error("Unable to execute ping command on host (" + cmd.getComputingHostIp() + "). failure due to " + VmwareHelper.getExceptionMessage(e), e); } return new Answer(cmd, false, "PingTestCommand failed"); @@ -5727,7 +5727,7 @@ protected Answer execute(CheckOnHostCommand cmd) { } protected Answer execute(ModifySshKeysCommand cmd) { - s_logger.debug(String.format("Executing resource command %s.", cmd.getClass().getSimpleName())); + logger.debug(String.format("Executing resource command %s.", cmd.getClass().getSimpleName())); return new Answer(cmd); } @@ -5762,17 +5762,17 @@ protected Answer execute(GetVmIpAddressCommand cmd) { } } else { details += "VM " + vmName + " no longer exists on vSphere host: " + hyperHost.getHyperHostName(); - s_logger.info(details); + logger.info(details); } } catch (Throwable e) { createLogMessageException(e, cmd); details = String.format("%s. Encountered exception: [%s].", details, VmwareHelper.getExceptionMessage(e)); - s_logger.error(details); + logger.error(details); } answer = new Answer(cmd, result, details); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Returning GetVmIpAddressAnswer: " + _gson.toJson(answer)); + if (logger.isTraceEnabled()) { + logger.trace("Returning GetVmIpAddressAnswer: " + _gson.toJson(answer)); } return answer; } @@ -5811,15 +5811,15 @@ protected Answer execute(UnregisterVMCommand cmd) { } return new Answer(cmd, true, "unregister succeeded"); } catch (Exception e) { - s_logger.warn("We are not able to unregister VM " + VmwareHelper.getExceptionMessage(e)); + logger.warn("We are not able to unregister VM " + VmwareHelper.getExceptionMessage(e)); } String msg = "Expunge failed in vSphere. vm: " + cmd.getVmName(); - s_logger.warn(msg); + logger.warn(msg); return new Answer(cmd, false, msg); } else { String msg = "Unable to find the VM in vSphere to unregister, assume it is already removed. VM: " + cmd.getVmName(); - s_logger.warn(msg); + logger.warn(msg); return new Answer(cmd, true, msg); } } catch (Exception e) { @@ -5848,7 +5848,7 @@ protected Answer execute(UnregisterNicCommand cmd) { return new Answer(cmd, true, "Nothing to do"); } - s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch " + _guestTrafficInfo.getVirtualSwitchName()); + logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch " + _guestTrafficInfo.getVirtualSwitchName()); VmwareContext context = getServiceContext(); VmwareHypervisorHost host = getHyperHost(context); ManagedObjectReference clusterMO = host.getHyperHostCluster(); @@ -5863,7 +5863,7 @@ protected Answer execute(UnregisterNicCommand cmd) { for (ManagedObjectReference hostMOR : hosts) { HostMO hostMo = new HostMO(context, hostMOR); hostMo.deletePortGroup(cmd.getNicUuid().toString()); - s_logger.debug("Removed portgroup " + cmd.getNicUuid() + " from host " + hostMo.getHostName()); + logger.debug("Removed portgroup " + cmd.getNicUuid() + " from host " + hostMo.getHostName()); } return new Answer(cmd, true, "Unregistered resources for NIC " + cmd.getNicUuid()); } catch (Exception e) { @@ -5883,13 +5883,13 @@ public void cleanupNetwork(DatacenterMO dcMO, NetworkDetails netDetails) { } } } catch(Throwable e) { - s_logger.warn("Unable to cleanup network due to exception: " + e.getMessage(), e); + logger.warn("Unable to cleanup network due to exception: " + e.getMessage(), e); } } private void cleanupPortGroup(DatacenterMO dcMO, String portGroupName) throws Exception { if (StringUtils.isBlank(portGroupName)) { - s_logger.debug("Unspecified network port group, couldn't cleanup"); + logger.debug("Unspecified network port group, couldn't cleanup"); return; } @@ -5912,7 +5912,7 @@ private boolean areVMsOnNetwork(DatacenterMO dcMO, NetworkDetails netDetails) th NetworkMO networkMo = new NetworkMO(host.getContext(), netDetails.getNetworkMor()); List vms = networkMo.getVMsOnNetwork(); if (!CollectionUtils.isEmpty(vms)) { - s_logger.debug("Network port group: " + netDetails.getName() + " is in use"); + logger.debug("Network port group: " + netDetails.getName() + " is in use"); return true; } } @@ -5952,7 +5952,7 @@ public PingCommand getCurrentStatus(long id) { return null; } } catch (Exception e) { - s_logger.error("Unexpected exception", e); + logger.error("Unexpected exception", e); return null; } return new PingRoutingCommand(getType(), id, syncHostVmStates()); @@ -5971,7 +5971,7 @@ private void gcAndKillHungWorkerVMs() { if (hyperHost.isHyperHostConnected()) { mgr.gcLeftOverVMs(context); - s_logger.info("Scan hung worker VM to recycle"); + logger.info("Scan hung worker VM to recycle"); int workerKey = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_WORKER); int workerTagKey = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_WORKER_TAG); @@ -6007,7 +6007,7 @@ private void gcAndKillHungWorkerVMs() { recycle = mgr.needRecycle(workerTag); if (recycle) { - s_logger.info("Recycle pending worker VM: " + vmMo.getName()); + logger.info("Recycle pending worker VM: " + vmMo.getName()); vmMo.cancelPendingTasks(); vmMo.powerOff(); @@ -6018,12 +6018,12 @@ private void gcAndKillHungWorkerVMs() { } } } else { - s_logger.error("Host is no longer connected."); + logger.error("Host is no longer connected."); } } catch (Throwable e) { if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); invalidateServiceContext(); } } @@ -6043,7 +6043,7 @@ public StartupCommand[] initialize() { VmwareHypervisorHost hyperHost = getHyperHost(context); assert (hyperHost instanceof HostMO); if (!((HostMO) hyperHost).isHyperHostConnected()) { - s_logger.info("Host " + hyperHost.getHyperHostName() + " is not in connected state"); + logger.info("Host " + hyperHost.getHyperHostName() + " is not in connected state"); return null; } @@ -6054,7 +6054,7 @@ public StartupCommand[] initialize() { } catch (Exception e) { String msg = "VmwareResource intialize() failed due to : " + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg); + logger.error(msg); invalidateServiceContext(); return null; } @@ -6112,16 +6112,16 @@ private List initializeLocalStorage() { cmd.setPod(_pod); cmd.setCluster(_cluster); - s_logger.info("Add local storage startup command: " + _gson.toJson(cmd)); + logger.info("Add local storage startup command: " + _gson.toJson(cmd)); storageCmds.add(cmd); } } else { - s_logger.info("Cluster host does not support local storage, skip it"); + logger.info("Cluster host does not support local storage, skip it"); } } catch (Exception e) { String msg = "initializing local storage failed due to : " + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg); + logger.error(msg); invalidateServiceContext(); throw new CloudRuntimeException(msg); } @@ -6141,14 +6141,14 @@ protected void fillHostInfo(StartupRoutingCommand cmd) { fillHostNetworkInfo(serviceContext, cmd); fillHostDetailsInfo(serviceContext, details); } catch (RuntimeFaultFaultMsg e) { - s_logger.error("RuntimeFault while retrieving host info: " + e.toString(), e); + logger.error("RuntimeFault while retrieving host info: " + e.toString(), e); throw new CloudRuntimeException("RuntimeFault while retrieving host info"); } catch (RemoteException e) { - s_logger.error("RemoteException while retrieving host info: " + e.toString(), e); + logger.error("RemoteException while retrieving host info: " + e.toString(), e); invalidateServiceContext(); throw new CloudRuntimeException("RemoteException while retrieving host info"); } catch (Exception e) { - s_logger.error("Exception while retrieving host info: " + e.toString(), e); + logger.error("Exception while retrieving host info: " + e.toString(), e); invalidateServiceContext(); throw new CloudRuntimeException("Exception while retrieving host info: " + e.toString()); } @@ -6182,7 +6182,7 @@ private String getIqn() { } } } catch (Exception ex) { - s_logger.info("Could not locate an IQN for this host."); + logger.info("Could not locate an IQN for this host."); } return null; @@ -6193,8 +6193,8 @@ private void fillHostHardwareInfo(VmwareContext serviceContext, StartupRoutingCo VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); VmwareHypervisorHostResourceSummary summary = hyperHost.getHyperHostResourceSummary(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Startup report on host hardware info. " + _gson.toJson(summary)); + if (logger.isInfoEnabled()) { + logger.info("Startup report on host hardware info. " + _gson.toJson(summary)); } cmd.setCaps("hvm"); @@ -6218,8 +6218,8 @@ private void fillHostNetworkInfo(VmwareContext serviceContext, StartupRoutingCom throw new Exception("No ESX(i) host found"); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Startup report on host network info. " + _gson.toJson(summary)); + if (logger.isInfoEnabled()) { + logger.info("Startup report on host network info. " + _gson.toJson(summary)); } cmd.setPrivateIpAddress(summary.getHostIp()); @@ -6232,7 +6232,7 @@ private void fillHostNetworkInfo(VmwareContext serviceContext, StartupRoutingCom } catch (Throwable e) { String msg = "querying host network info failed due to " + VmwareHelper.getExceptionMessage(e); - s_logger.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg); } } @@ -6291,7 +6291,7 @@ protected OptionValue[] configureVnc(OptionValue[] optionsToMerge, VmwareHypervi } while (val != startVal); if (vncPort == 0) { - s_logger.info("we've run out of range for ports between 5900-5964 for the cluster, we will try port range at 59000-60000"); + logger.info("we've run out of range for ports between 5900-5964 for the cluster, we will try port range at 59000-60000"); Pair additionalRange = mgr.getAddiionalVncPortRange(); maxVncPorts = additionalRange.second(); @@ -6311,8 +6311,8 @@ protected OptionValue[] configureVnc(OptionValue[] optionsToMerge, VmwareHypervi throw new Exception("Unable to find an available VNC port on host"); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Configure VNC port for VM " + vmName + ", port: " + vncPort + ", host: " + vmOwnerHost.getHyperHostName()); + if (logger.isInfoEnabled()) { + logger.info("Configure VNC port for VM " + vmName + ", port: " + vncPort + ", host: " + vmOwnerHost.getHyperHostName()); } return VmwareHelper.composeVncOptions(optionsToMerge, true, vncPassword, vncPort, keyboardLayout); @@ -6321,29 +6321,29 @@ protected OptionValue[] configureVnc(OptionValue[] optionsToMerge, VmwareHypervi mgr.endExclusiveOperation(); } catch (Throwable e) { assert (false); - s_logger.error("Unexpected exception ", e); + logger.error("Unexpected exception ", e); } } } private VirtualMachineGuestOsIdentifier translateGuestOsIdentifier(String cpuArchitecture, String guestOs, String cloudGuestOs) { if (cpuArchitecture == null) { - s_logger.warn("CPU arch is not set, default to i386. guest os: " + guestOs); + logger.warn("CPU arch is not set, default to i386. guest os: " + guestOs); cpuArchitecture = "i386"; } if (cloudGuestOs == null) { - s_logger.warn("Guest OS mapping name is not set for guest os: " + guestOs); + logger.warn("Guest OS mapping name is not set for guest os: " + guestOs); } VirtualMachineGuestOsIdentifier identifier = null; try { if (cloudGuestOs != null) { identifier = VirtualMachineGuestOsIdentifier.fromValue(cloudGuestOs); - s_logger.debug("Using mapping name : " + identifier.toString()); + logger.debug("Using mapping name : " + identifier.toString()); } } catch (IllegalArgumentException e) { - s_logger.warn("Unable to find Guest OS Identifier in VMware for mapping name: " + cloudGuestOs + ". Continuing with defaults."); + logger.warn("Unable to find Guest OS Identifier in VMware for mapping name: " + cloudGuestOs + ". Continuing with defaults."); } if (identifier != null) { return identifier; @@ -6360,7 +6360,7 @@ private HashMap getHostVmStateReport() throws Ex int key = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); if (key == 0) { - s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); + logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); } String instanceNameCustomField = "value[" + key + "]"; @@ -6412,7 +6412,7 @@ private HashMap getVmStates() throws Exception { int key = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); if (key == 0) { - s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); + logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); } String instanceNameCustomField = "value[" + key + "]"; @@ -6504,7 +6504,7 @@ private HashMap getVmStats(List vmNames) throws Ex int key = ((HostMO) hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME); if (key == 0) { - s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); + logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!"); } String instanceNameCustomField = "value[" + key + "]"; @@ -6640,7 +6640,7 @@ private HashMap getVmStats(List vmNames) throws Ex } } } catch (Exception e) { - s_logger.error(String.format("Unable to execute PerfQuerySpec due to: [%s]. The window interval is enabled in vCenter?", VmwareHelper.getExceptionMessage(e)), e); + logger.error(String.format("Unable to execute PerfQuerySpec due to: [%s]. The window interval is enabled in vCenter?", VmwareHelper.getExceptionMessage(e)), e); } } @@ -6701,7 +6701,7 @@ protected long[] getNetworkStats(String privateIP, String publicIp) { stats[1] += Long.parseLong(splitResult[i++]); } } catch (Throwable e) { - s_logger.warn("Unable to parse return from script return of network usage command: " + e.toString(), e); + logger.warn("Unable to parse return from script return of network usage command: " + e.toString(), e); } } return stats; @@ -6715,7 +6715,7 @@ protected String connect(final String vmName, final String ipAddress, final int // VM patching/rebooting time that may need int retry = _retry; while (System.currentTimeMillis() - startTick <= _opsTimeout || --retry > 0) { - s_logger.info("Trying to connect to " + ipAddress); + logger.info("Trying to connect to " + ipAddress); try (SocketChannel sch = SocketChannel.open();) { sch.configureBlocking(true); sch.socket().setSoTimeout(5000); @@ -6724,7 +6724,7 @@ protected String connect(final String vmName, final String ipAddress, final int sch.connect(addr); return null; } catch (IOException e) { - s_logger.info("Could not connect to " + ipAddress + " due to " + e.toString()); + logger.info("Could not connect to " + ipAddress + " due to " + e.toString()); if (e instanceof ConnectException) { // if connection is refused because of VM is being started, // we give it more sleep time @@ -6732,7 +6732,7 @@ protected String connect(final String vmName, final String ipAddress, final int try { Thread.sleep(5000); } catch (InterruptedException ex) { - s_logger.debug("[ignored] interrupted while waiting to retry connect after failure.", e); + logger.debug("[ignored] interrupted while waiting to retry connect after failure.", e); } } } @@ -6740,11 +6740,11 @@ protected String connect(final String vmName, final String ipAddress, final int try { Thread.sleep(1000); } catch (InterruptedException ex) { - s_logger.debug("[ignored] interrupted while waiting to retry connect."); + logger.debug("[ignored] interrupted while waiting to retry connect."); } } - s_logger.info("Unable to logon to " + ipAddress); + logger.info("Unable to logon to " + ipAddress); return "Unable to connect"; } @@ -6783,10 +6783,10 @@ private static HostStatsEntry getHyperHostStats(VmwareHypervisorHost hyperHost) return entry; } - private static String getRouterSshControlIp(NetworkElementCommand cmd) { + private String getRouterSshControlIp(NetworkElementCommand cmd) { String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); - if (s_logger.isDebugEnabled()) - s_logger.debug("Use router's private IP for SSH control. IP : " + routerIp); + if (logger.isDebugEnabled()) + logger.debug("Use router's private IP for SSH control. IP : " + routerIp); return routerIp; } @@ -6867,7 +6867,7 @@ else if (value != null && value.equalsIgnoreCase("ide")) if (intObj != null) _portsPerDvPortGroup = intObj.intValue(); - s_logger.info("VmwareResource network configuration info." + " private traffic over vSwitch: " + _privateNetworkVSwitchName + ", public traffic over " + logger.info("VmwareResource network configuration info." + " private traffic over vSwitch: " + _privateNetworkVSwitchName + ", public traffic over " + _publicTrafficInfo.getVirtualSwitchType() + " : " + _publicTrafficInfo.getVirtualSwitchName() + ", guest traffic over " + _guestTrafficInfo.getVirtualSwitchType() + " : " + _guestTrafficInfo.getVirtualSwitchName()); @@ -6898,12 +6898,12 @@ else if (value != null && value.equalsIgnoreCase("ide")) throw new ConfigurationException("Unable to configure VirtualRoutingResource"); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Successfully configured VmwareResource."); + if (logger.isTraceEnabled()) { + logger.trace("Successfully configured VmwareResource."); } return true; } catch (Exception e) { - s_logger.error("Unexpected Exception ", e); + logger.error("Unexpected Exception ", e); throw new ConfigurationException("Failed to configure VmwareResource due to unexpect exception."); } finally { recycleServiceContext(); @@ -6951,24 +6951,24 @@ public VmwareContext getServiceContext(Command cmd) { // Before re-using the thread local context, ensure it corresponds to the right vCenter API session and that it is valid to make calls. if (context.getPoolKey().equals(poolKey)) { if (context.validate()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("ThreadLocal context is still valid, just reuse"); + if (logger.isTraceEnabled()) { + logger.trace("ThreadLocal context is still valid, just reuse"); } return context; } else { - s_logger.info("Validation of the context failed, dispose and use a new one"); + logger.info("Validation of the context failed, dispose and use a new one"); invalidateServiceContext(context); } } else { // Exisitng ThreadLocal context corresponds to a different vCenter API session. Why has it not been recycled? - s_logger.warn("ThreadLocal VMware context: " + poolKey + " doesn't correspond to the right vCenter. Expected VMware context: " + context.getPoolKey()); + logger.warn("ThreadLocal VMware context: " + poolKey + " doesn't correspond to the right vCenter. Expected VMware context: " + context.getPoolKey()); } } try { context = VmwareContextFactory.getContext(_vCenterAddress, _username, _password); s_serviceContext.set(context); } catch (Exception e) { - s_logger.error("Unable to connect to vSphere server: " + _vCenterAddress, e); + logger.error("Unable to connect to vSphere server: " + _vCenterAddress, e); throw new CloudRuntimeException("Unable to connect to vSphere server: " + _vCenterAddress); } return context; @@ -6983,17 +6983,17 @@ public void invalidateServiceContext(VmwareContext context) { context.close(); } - private static void recycleServiceContext() { + private void recycleServiceContext() { VmwareContext context = s_serviceContext.get(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Reset threadlocal context to null"); + if (logger.isTraceEnabled()) { + logger.trace("Reset threadlocal context to null"); } s_serviceContext.set(null); if (context != null) { assert (context.getPool() != null); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Recycling threadlocal context to pool"); + if (logger.isTraceEnabled()) { + logger.trace("Recycling threadlocal context to pool"); } context.getPool().registerContext(context); } @@ -7061,16 +7061,16 @@ public Answer execute(DestroyCommand cmd) { VirtualMachineMO vmMo = findVmOnDatacenter(context, hyperHost, vol); if (vmMo != null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Destroy template volume " + vol.getPath()); + if (logger.isInfoEnabled()) { + logger.info("Destroy template volume " + vol.getPath()); } if (vmMo.isTemplate()) { vmMo.markAsVirtualMachine(hyperHost.getHyperHostOwnerResourcePool(), hyperHost.getMor()); } vmMo.destroy(); } else { - if (s_logger.isInfoEnabled()) { - s_logger.info("Template volume " + vol.getPath() + " is not found, no need to delete."); + if (logger.isInfoEnabled()) { + logger.info("Template volume " + vol.getPath() + " is not found, no need to delete."); } } return new Answer(cmd, true, "Success"); @@ -7095,7 +7095,7 @@ protected VirtualMachineMO findVmOnDatacenter(VmwareContext context, VmwareHyper DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter()); if (dcMo.getMor() == null) { String msg = "Unable to find VMware DC"; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } return dcMo.findVm(vol.getPath()); @@ -7108,7 +7108,7 @@ protected File getSystemVmKeyFile() { return s_systemVmKeyFile; } - private static void syncFetchSystemVmKeyFile() { + private void syncFetchSystemVmKeyFile() { synchronized (s_syncLockObjectFetchKeyFile) { if (s_systemVmKeyFile == null) { s_systemVmKeyFile = fetchSystemVmKeyFile(); @@ -7116,9 +7116,9 @@ private static void syncFetchSystemVmKeyFile() { } } - private static File fetchSystemVmKeyFile() { + private File fetchSystemVmKeyFile() { String filePath = s_relativePathSystemVmKeyFileInstallDir; - s_logger.debug("Looking for file [" + filePath + "] in the classpath."); + logger.debug("Looking for file [" + filePath + "] in the classpath."); URL url = Script.class.getClassLoader().getResource(filePath); File keyFile = null; if (url != null) { @@ -7127,10 +7127,10 @@ private static File fetchSystemVmKeyFile() { if (keyFile == null || !keyFile.exists()) { filePath = s_defaultPathSystemVmKeyFile; keyFile = new File(filePath); - s_logger.debug("Looking for file [" + filePath + "] in the classpath."); + logger.debug("Looking for file [" + filePath + "] in the classpath."); } if (!keyFile.exists()) { - s_logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); + logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); } return keyFile; } @@ -7171,7 +7171,7 @@ private Answer execute(GetUnmanagedInstancesCommand cmd) { } } } catch (Exception e) { - s_logger.info("GetUnmanagedInstancesCommand failed due to " + VmwareHelper.getExceptionMessage(e)); + logger.info("GetUnmanagedInstancesCommand failed due to " + VmwareHelper.getExceptionMessage(e)); } return new GetUnmanagedInstancesAnswer(cmd, "", unmanagedInstances); } @@ -7182,7 +7182,7 @@ private Answer execute(PrepareUnmanageVMInstanceCommand cmd) { String instanceName = cmd.getInstanceName(); try { - s_logger.debug(String.format("Verify if VMware instance: [%s] is available before unmanaging VM.", cmd.getInstanceName())); + logger.debug(String.format("Verify if VMware instance: [%s] is available before unmanaging VM.", cmd.getInstanceName())); ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); DatacenterMO dataCenterMo = new DatacenterMO(getServiceContext(), dcMor); @@ -7191,7 +7191,7 @@ private Answer execute(PrepareUnmanageVMInstanceCommand cmd) { return new PrepareUnmanageVMInstanceAnswer(cmd, false, String.format("Cannot find VM with name [%s] in datacenter [%s].", instanceName, dataCenterMo.getName())); } } catch (Exception e) { - s_logger.error("Error trying to verify if VM to unmanage exists", e); + logger.error("Error trying to verify if VM to unmanage exists", e); return new PrepareUnmanageVMInstanceAnswer(cmd, false, "Error: " + e.getMessage()); } @@ -7242,12 +7242,12 @@ private List relocateVirtualMachine(final VmwareHypervisorHost h vmMo = sourceHyperHost.findVmOnHyperHost(vmName); if (vmMo == null) { String msg = String.format("VM: %s does not exist on host: %s", vmName, sourceHyperHost.getHyperHostName()); - s_logger.warn(msg); + logger.warn(msg); // find VM through source host (VM is not at the target host yet) vmMo = dcMo.findVm(vmName); if (vmMo == null) { msg = String.format("VM: %s does not exist on datacenter: %s", vmName, dcMo.getName()); - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } // VM host has changed @@ -7263,7 +7263,7 @@ private List relocateVirtualMachine(final VmwareHypervisorHost h morDatastore = getTargetDatastoreMOReference(poolUuid, dsHost); if (morDatastore == null) { String msg = String.format("Unable to find the target datastore: %s on host: %s to execute migration", poolUuid, dsHost.getHyperHostName()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } relocateSpec.setDatastore(morDatastore); @@ -7273,13 +7273,13 @@ private List relocateVirtualMachine(final VmwareHypervisorHost h for (Pair entry : volToFiler) { VolumeTO volume = entry.first(); StorageFilerTO filerTo = entry.second(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Preparing spec for volume: %s to migrate it to datastore: %s", volume.getName(), filerTo.getUuid())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Preparing spec for volume: %s to migrate it to datastore: %s", volume.getName(), filerTo.getUuid())); } ManagedObjectReference morVolumeDatastore = getTargetDatastoreMOReference(filerTo.getUuid(), dsHost); if (morVolumeDatastore == null) { String msg = String.format("Unable to find the target datastore: %s in datacenter: %s to execute migration", filerTo.getUuid(), dcMo.getName()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -7325,7 +7325,8 @@ private List relocateVirtualMachine(final VmwareHypervisorHost h NicTO[] nics = vmTo.getNics(); for (NicTO nic : nics) { // prepare network on the host - prepareNetworkFromNicInfo((HostMO)targetHyperHost, nic, false, vmTo.getType()); + prepareNetworkFromNicInfo((HostMO)targetHyperHost, nic, false, + vmTo.getNetworkIdToNetworkNameMap().get(nic.getNetworkId()), vmTo.getType()); } if (targetHyperHost == null) { @@ -7352,7 +7353,7 @@ private List relocateVirtualMachine(final VmwareHypervisorHost h if (!vmMo.changeDatastore(relocateSpec)) { throw new Exception("Change datastore operation failed during storage migration"); } else { - s_logger.debug(String.format("Successfully migrated storage of VM: %s to target datastore(s)", vmName)); + logger.debug(String.format("Successfully migrated storage of VM: %s to target datastore(s)", vmName)); } // Migrate VM to target host. if (targetHyperHost != null) { @@ -7360,7 +7361,7 @@ private List relocateVirtualMachine(final VmwareHypervisorHost h if (!vmMo.migrate(morPool, targetHyperHost.getMor())) { throw new Exception("VM migration to target host failed during storage migration"); } else { - s_logger.debug(String.format("Successfully migrated VM: %s from host %s to %s", vmName , sourceHyperHost.getHyperHostName(), targetHyperHost.getHyperHostName())); + logger.debug(String.format("Successfully migrated VM: %s from host %s to %s", vmName , sourceHyperHost.getHyperHostName(), targetHyperHost.getHyperHostName())); } } } else { @@ -7376,16 +7377,16 @@ private List relocateVirtualMachine(final VmwareHypervisorHost h if (targetHyperHost != null) { msg = String.format("%s from host %s to %s", msg, sourceHyperHost.getHyperHostName(), targetHyperHost.getHyperHostName()); } - s_logger.debug(msg); + logger.debug(msg); } } // Consolidate VM disks. // In case of a linked clone VM, if VM's disks are not consolidated, further VM operations such as volume snapshot, VM snapshot etc. will result in DB inconsistencies. if (!vmMo.consolidateVmDisks()) { - s_logger.warn("VM disk consolidation failed after storage migration. Yet proceeding with VM migration."); + logger.warn("VM disk consolidation failed after storage migration. Yet proceeding with VM migration."); } else { - s_logger.debug(String.format("Successfully consolidated disks of VM: %s", vmName)); + logger.debug(String.format("Successfully consolidated disks of VM: %s", vmName)); } if (MapUtils.isNotEmpty(volumeDeviceKey)) { @@ -7414,21 +7415,21 @@ private List relocateVirtualMachine(final VmwareHypervisorHost h } } catch (Throwable e) { if (e instanceof RemoteException) { - s_logger.warn("Encountered remote exception at vCenter, invalidating VMware session context"); + logger.warn("Encountered remote exception at vCenter, invalidating VMware session context"); invalidateServiceContext(); } throw e; } finally { // Cleanup datastores mounted on source host for (String mountedDatastore : mountedDatastoresAtSource) { - s_logger.debug("Attempting to unmount datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName()); + logger.debug("Attempting to unmount datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName()); try { sourceHyperHost.unmountDatastore(mountedDatastore); } catch (Exception unmountEx) { - s_logger.warn("Failed to unmount datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName() + ". Seems the datastore is still being used by " + sourceHyperHost.getHyperHostName() + + logger.warn("Failed to unmount datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName() + ". Seems the datastore is still being used by " + sourceHyperHost.getHyperHostName() + ". Please unmount manually to cleanup."); } - s_logger.debug("Successfully unmounted datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName()); + logger.debug("Successfully unmounted datastore " + mountedDatastore + " at " + sourceHyperHost.getHyperHostName()); } } @@ -7441,7 +7442,7 @@ private String getMountedDatastoreName(VmwareHypervisorHost sourceHyperHost, Str // If host version is below 5.1 then simultaneous change of VM's datastore and host is not supported. // So since only the datastore will be changed first, ensure the target datastore is mounted on source host. if (sourceHostApiVersion.compareTo("5.1") < 0) { - s_logger.debug(String.format("Host: %s version is %s, vMotion without shared storage cannot be done. Check source host has target datastore mounted or can be mounted", sourceHyperHost.getHyperHostName(), sourceHostApiVersion)); + logger.debug(String.format("Host: %s version is %s, vMotion without shared storage cannot be done. Check source host has target datastore mounted or can be mounted", sourceHyperHost.getHyperHostName(), sourceHostApiVersion)); ManagedObjectReference morVolumeDatastoreAtSource = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(sourceHyperHost, filerTo.getUuid()); String volumeDatastoreName = filerTo.getUuid().replace("-", ""); String volumeDatastoreHost = filerTo.getHost(); @@ -7456,20 +7457,20 @@ private String getMountedDatastoreName(VmwareHypervisorHost sourceHyperHost, Str throw new Exception("Unable to mount NFS datastore " + volumeDatastoreHost + ":/" + volumeDatastorePath + " on host: " + sourceHyperHost.getHyperHostName()); } mountedDatastoreName = volumeDatastoreName; - s_logger.debug("Mounted NFS datastore " + volumeDatastoreHost + ":/" + volumeDatastorePath + " on host: " + sourceHyperHost.getHyperHostName()); + logger.debug("Mounted NFS datastore " + volumeDatastoreHost + ":/" + volumeDatastorePath + " on host: " + sourceHyperHost.getHyperHostName()); } } // If datastore is VMFS and target datastore is not mounted or accessible to source host then fail migration. if (filerTo.getType().equals(StoragePoolType.VMFS)) { if (morVolumeDatastoreAtSource == null) { - s_logger.warn("Host: " + sourceHyperHost.getHyperHostName() + " version is below 5.1, target VMFS datastore(s) need to be manually mounted on host for successful storage migration."); + logger.warn("Host: " + sourceHyperHost.getHyperHostName() + " version is below 5.1, target VMFS datastore(s) need to be manually mounted on host for successful storage migration."); throw new Exception("Target VMFS datastore: " + volumeDatastorePath + " is not mounted on host: " + sourceHyperHost.getHyperHostName()); } DatastoreMO dsAtSourceMo = new DatastoreMO(getServiceContext(), morVolumeDatastoreAtSource); String srcHostValue = sourceHyperHost.getMor().getValue(); if (!dsAtSourceMo.isAccessibleToHost(srcHostValue)) { - s_logger.warn("Host " + sourceHyperHost.getHyperHostName() + " version is below 5.1, target VMFS datastore(s) need to be accessible to host for a successful storage migration."); + logger.warn("Host " + sourceHyperHost.getHyperHostName() + " version is below 5.1, target VMFS datastore(s) need to be accessible to host for a successful storage migration."); throw new Exception("Target VMFS datastore: " + volumeDatastorePath + " is not accessible on host: " + sourceHyperHost.getHyperHostName()); } } @@ -7498,13 +7499,13 @@ public String acquireVirtualMachineVncTicket(String vmInternalCSName) throws Exc private GetVmVncTicketAnswer execute(GetVmVncTicketCommand cmd) { String vmInternalName = cmd.getVmInternalName(); - s_logger.info("Getting VNC ticket for VM " + vmInternalName); + logger.info("Getting VNC ticket for VM " + vmInternalName); try { String ticket = acquireVirtualMachineVncTicket(vmInternalName); boolean result = StringUtils.isNotBlank(ticket); return new GetVmVncTicketAnswer(ticket, result, result ? "" : "Empty ticket obtained"); } catch (Exception e) { - s_logger.error("Error getting VNC ticket for VM " + vmInternalName, e); + logger.error("Error getting VNC ticket for VM " + vmInternalName, e); return new GetVmVncTicketAnswer(null, false, e.getLocalizedMessage()); } } @@ -7512,7 +7513,7 @@ private GetVmVncTicketAnswer execute(GetVmVncTicketCommand cmd) { protected CheckGuestOsMappingAnswer execute(CheckGuestOsMappingCommand cmd) { String guestOsName = cmd.getGuestOsName(); String guestOsMappingName = cmd.getGuestOsHypervisorMappingName(); - s_logger.info("Checking guest os mapping name: " + guestOsMappingName + " for the guest os: " + guestOsName + " in the hypervisor"); + logger.info("Checking guest os mapping name: " + guestOsMappingName + " for the guest os: " + guestOsName + " in the hypervisor"); try { VmwareContext context = getServiceContext(); VmwareHypervisorHost hyperHost = getHyperHost(context); @@ -7520,14 +7521,14 @@ protected CheckGuestOsMappingAnswer execute(CheckGuestOsMappingCommand cmd) { if (guestOsDescriptor == null) { return new CheckGuestOsMappingAnswer(cmd, "Guest os mapping name: " + guestOsMappingName + " not found in the hypervisor"); } - s_logger.debug("Matching hypervisor guest os - id: " + guestOsDescriptor.getId() + ", full name: " + guestOsDescriptor.getFullName() + ", family: " + guestOsDescriptor.getFamily()); + logger.debug("Matching hypervisor guest os - id: " + guestOsDescriptor.getId() + ", full name: " + guestOsDescriptor.getFullName() + ", family: " + guestOsDescriptor.getFamily()); if (guestOsDescriptor.getFullName().equalsIgnoreCase(guestOsName)) { - s_logger.debug("Hypervisor guest os name in the descriptor matches with os name: " + guestOsName); + logger.debug("Hypervisor guest os name in the descriptor matches with os name: " + guestOsName); } - s_logger.info("Hypervisor guest os name in the descriptor matches with os mapping: " + guestOsMappingName + " from user"); + logger.info("Hypervisor guest os name in the descriptor matches with os mapping: " + guestOsMappingName + " from user"); return new CheckGuestOsMappingAnswer(cmd); } catch (Exception e) { - s_logger.error("Failed to check the hypervisor guest os mapping name: " + guestOsMappingName, e); + logger.error("Failed to check the hypervisor guest os mapping name: " + guestOsMappingName, e); return new CheckGuestOsMappingAnswer(cmd, e.getLocalizedMessage()); } } @@ -7595,7 +7596,7 @@ protected ListDataStoreObjectsAnswer execute(ListDataStoreObjectsCommand cmd) { return new ListDataStoreObjectsAnswer(false, count, names, paths, absPaths, isDirs, sizes, modifiedList); } String errorMsg = String.format("Failed to list files at path [%s] due to: [%s].", path, e.getMessage()); - s_logger.error(errorMsg, e); + logger.error(errorMsg, e); } return null; @@ -7603,7 +7604,7 @@ protected ListDataStoreObjectsAnswer execute(ListDataStoreObjectsCommand cmd) { protected GetHypervisorGuestOsNamesAnswer execute(GetHypervisorGuestOsNamesCommand cmd) { String keyword = cmd.getKeyword(); - s_logger.info("Getting guest os names in the hypervisor"); + logger.info("Getting guest os names in the hypervisor"); try { VmwareContext context = getServiceContext(); VmwareHypervisorHost hyperHost = getHyperHost(context); @@ -7627,7 +7628,7 @@ protected GetHypervisorGuestOsNamesAnswer execute(GetHypervisorGuestOsNamesComma } return new GetHypervisorGuestOsNamesAnswer(cmd, hypervisorGuestOsNames); } catch (Exception e) { - s_logger.error("Failed to get the hypervisor guest names due to: " + e.getLocalizedMessage(), e); + logger.error("Failed to get the hypervisor guest names due to: " + e.getLocalizedMessage(), e); return new GetHypervisorGuestOsNamesAnswer(cmd, e.getLocalizedMessage()); } } @@ -7648,7 +7649,7 @@ private Answer execute(PrepareForBackupRestorationCommand command) { if (vmMo == null) { String msg = "VM " + vmName + " no longer exists to execute PrepareForBackupRestorationCommand command"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -7656,7 +7657,7 @@ private Answer execute(PrepareForBackupRestorationCommand command) { return new Answer(command, true, "success"); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new Answer(command, false, "Unable to execute PrepareForBackupRestorationCommand due to " + e.toString()); } } @@ -7664,7 +7665,7 @@ private Answer execute(PrepareForBackupRestorationCommand command) { private Integer getVmwareWindowTimeInterval() { Integer windowInterval = VmwareManager.VMWARE_STATS_TIME_WINDOW.value(); if (windowInterval == null || windowInterval < 20) { - s_logger.error(String.format("The window interval can't be [%s]. Therefore we will use the default value of [%s] seconds.", windowInterval, VmwareManager.VMWARE_STATS_TIME_WINDOW.defaultValue())); + logger.error(String.format("The window interval can't be [%s]. Therefore we will use the default value of [%s] seconds.", windowInterval, VmwareManager.VMWARE_STATS_TIME_WINDOW.defaultValue())); windowInterval = Integer.valueOf(VmwareManager.VMWARE_STATS_TIME_WINDOW.defaultValue()); } return windowInterval; @@ -7673,21 +7674,21 @@ private Integer getVmwareWindowTimeInterval() { @Override public String createLogMessageException(Throwable e, Command command) { if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context."); + logger.warn("Encounter remote exception to vCenter, invalidate VMware session context."); invalidateServiceContext(); } String message = String.format("%s failed due to [%s].", command.getClass().getSimpleName(), VmwareHelper.getExceptionMessage(e)); - s_logger.error(message, e); + logger.error(message, e); return message; } private void logCommand(Command cmd) { try { - s_logger.debug(String.format(EXECUTING_RESOURCE_COMMAND, cmd.getClass().getSimpleName(), _gson.toJson(cmd))); + logger.debug(String.format(EXECUTING_RESOURCE_COMMAND, cmd.getClass().getSimpleName(), _gson.toJson(cmd))); } catch (Exception e) { - s_logger.error(String.format("Failed to log command %s due to: [%s].", cmd.getClass().getSimpleName(), e.getMessage()), e); + logger.error(String.format("Failed to log command %s due to: [%s].", cmd.getClass().getSimpleName(), e.getMessage()), e); } } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java index 136e44261b50..beac489acdb3 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java @@ -20,7 +20,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.agent.api.StartupCommand; import com.cloud.dc.ClusterDetailsDao; @@ -65,7 +64,6 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { @Inject PortProfileDao _ppDao; - private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalLoadBalancerDeviceManagerImpl.class); @DB //public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, ServerResource resource, String vsmName) { @@ -107,7 +105,7 @@ CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String netconfClient = new NetconfHelper(ipaddress, username, password); } catch (CloudRuntimeException e) { String msg = "Failed to connect to Nexus VSM " + ipaddress + " with credentials of user " + username; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -203,7 +201,7 @@ public boolean deleteCiscoNexusVSM(final long vsmId) throws ResourceInUseExcepti if (hosts != null && hosts.size() > 0) { for (Host host : hosts) { if (host.getType() == Host.Type.Routing) { - s_logger.info("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first"); + logger.info("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first"); throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first"); } @@ -267,7 +265,7 @@ public CiscoNexusVSMDeviceVO getCiscoVSMbyVSMId(long vsmId) { public CiscoNexusVSMDeviceVO getCiscoVSMbyClusId(long clusterId) { ClusterVSMMapVO mapVO = _clusterVSMDao.findByClusterId(clusterId); if (mapVO == null) { - s_logger.info("Couldn't find a VSM associated with the specified cluster Id"); + logger.info("Couldn't find a VSM associated with the specified cluster Id"); return null; } // Else, pull out the VSM associated with the VSM id in mapVO. diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java index 4fff02247831..2e7e41534301 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.CiscoNexusVSMDeviceVO; @@ -32,7 +31,6 @@ @Component @DB public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase implements CiscoNexusVSMDeviceDao { - protected static final Logger s_logger = Logger.getLogger(CiscoNexusVSMDeviceDaoImpl.class); final SearchBuilder mgmtVlanIdSearch; final SearchBuilder domainIdSearch; final SearchBuilder nameSearch; diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/network/element/CiscoNexusVSMElement.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/network/element/CiscoNexusVSMElement.java index f67b2e73bd16..2503e0ac7fde 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/network/element/CiscoNexusVSMElement.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/network/element/CiscoNexusVSMElement.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.api.commands.DeleteCiscoNexusVSMCmd; import com.cloud.api.commands.DisableCiscoNexusVSMCmd; @@ -69,7 +68,6 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl implements CiscoNexusVSMElementService, NetworkElement, Manager { - private static final Logger s_logger = Logger.getLogger(CiscoNexusVSMElement.class); @Inject CiscoNexusVSMDeviceDao _vsmDao; @@ -146,7 +144,7 @@ public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) { try { result = deleteCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId()); } catch (ResourceInUseException e) { - s_logger.info("VSM could not be deleted"); + logger.info("VSM could not be deleted"); // TODO: Throw a better exception here. throw new CloudRuntimeException("Failed to delete specified VSM"); } @@ -265,7 +263,7 @@ public Pair validateAndAddVsm(final String vsmIp, final String vs netconfClient.disconnect(); } catch (CloudRuntimeException e) { String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp; - s_logger.error(msg); + logger.error(msg); _clusterDao.remove(clusterId); throw new CloudRuntimeException(msg); } @@ -275,7 +273,7 @@ public Pair validateAndAddVsm(final String vsmIp, final String vs if (vsm != null) { List clusterList = _clusterVSMDao.listByVSMId(vsm.getId()); if (clusterList != null && !clusterList.isEmpty()) { - s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster"); + logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster"); ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id"); // get clusterUuid to report error @@ -320,7 +318,7 @@ public CiscoNexusVSMDeviceVO doInTransaction(TransactionStatus status) { msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. "; } } - s_logger.error(msg); + logger.error(msg); // Cleaning up the cluster record as addCluster operation failed because of invalid credentials of Nexus dvSwitch. _clusterDao.remove(clusterId); throw new CloudRuntimeException(msg); diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/PremiumSecondaryStorageResource.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/PremiumSecondaryStorageResource.java index e2aff4ce932e..f5344119dede 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/PremiumSecondaryStorageResource.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/PremiumSecondaryStorageResource.java @@ -21,7 +21,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource; import org.apache.cloudstack.storage.resource.SecondaryStorageResourceHandler; @@ -32,7 +31,6 @@ public class PremiumSecondaryStorageResource extends NfsSecondaryStorageResource { - private static final Logger s_logger = Logger.getLogger(PremiumSecondaryStorageResource.class); private Map _handlers = new HashMap(); @@ -44,13 +42,13 @@ public Answer executeRequest(Command cmd) { if (hypervisor != null) { Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor); if (hypervisorType == null) { - s_logger.error("Unsupported hypervisor type in command context, hypervisor: " + hypervisor); + logger.error("Unsupported hypervisor type in command context, hypervisor: " + hypervisor); return defaultAction(cmd); } SecondaryStorageResourceHandler handler = getHandler(hypervisorType); if (handler == null) { - s_logger.error("No handler can be found for hypervisor type in command context, hypervisor: " + hypervisor); + logger.error("No handler can be found for hypervisor type in command context, hypervisor: " + hypervisor); return defaultAction(cmd); } @@ -66,8 +64,8 @@ public Answer defaultAction(Command cmd) { public void ensureOutgoingRuleForAddress(String address) { if (address == null || address.isEmpty() || address.startsWith("0.0.0.0")) { - if (s_logger.isInfoEnabled()) - s_logger.info("Drop invalid dynamic route/firewall entry " + address); + if (logger.isInfoEnabled()) + logger.info("Drop invalid dynamic route/firewall entry " + address); return; } @@ -80,8 +78,8 @@ public void ensureOutgoingRuleForAddress(String address) { } if (needToSetRule) { - if (s_logger.isInfoEnabled()) - s_logger.info("Add dynamic route/firewall entry for " + address); + if (logger.isInfoEnabled()) + logger.info("Add dynamic route/firewall entry for " + address); allowOutgoingOnPrivate(address); } } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java index 6e19ba67bf50..2fa3ccc568e9 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java @@ -16,14 +16,15 @@ // under the License. package com.cloud.storage.resource; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.hypervisor.vmware.util.VmwareClient; import com.cloud.hypervisor.vmware.util.VmwareContext; import com.cloud.hypervisor.vmware.util.VmwareContextPool; public class VmwareSecondaryStorageContextFactory { - private static final Logger s_logger = Logger.getLogger(VmwareSecondaryStorageContextFactory.class); + protected static Logger LOGGER = LogManager.getLogger(VmwareSecondaryStorageContextFactory.class); private static volatile int s_seq = 1; @@ -60,7 +61,7 @@ public static VmwareContext getContext(String vCenterAddress, String vCenterUser } else { // Validate current context and verify if vCenter session timeout value of the context matches the timeout value set by Admin if (!context.validate() || (context.getVimClient().getVcenterSessionTimeout() != s_vCenterSessionTimeout)) { - s_logger.info("Validation of the context faild. dispose and create a new one"); + LOGGER.info("Validation of the context faild. dispose and create a new one"); context.close(); context = create(vCenterAddress, vCenterUserName, vCenterPassword); } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java index 68947ef69042..ece6176547c0 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java @@ -20,8 +20,8 @@ import org.apache.cloudstack.storage.command.StorageSubSystemCommand; import org.apache.cloudstack.storage.resource.SecondaryStorageResourceHandler; -import org.apache.log4j.Logger; -import org.apache.log4j.NDC; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.BackupSnapshotCommand; @@ -50,9 +50,10 @@ import com.cloud.utils.StringUtils; import com.google.gson.Gson; import com.vmware.vim25.ManagedObjectReference; +import org.apache.logging.log4j.ThreadContext; public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageResourceHandler, VmwareHostService, VmwareStorageMount { - private static final Logger s_logger = Logger.getLogger(VmwareSecondaryStorageResourceHandler.class); + protected Logger logger = LogManager.getLogger(getClass()); private final PremiumSecondaryStorageResource _resource; private final VmwareStorageManager _storageMgr; @@ -94,7 +95,7 @@ public Answer executeRequest(Command cmd) { try { Answer answer; - NDC.push(getCommandLogTitle(cmd)); + ThreadContext.push(getCommandLogTitle(cmd)); logCommand(cmd); if (cmd instanceof PrimaryStorageDownloadCommand) { @@ -130,23 +131,23 @@ public Answer executeRequest(Command cmd) { answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2")); } - if (s_logger.isDebugEnabled()) - s_logger.debug("Command execution answer: " + _gson.toJson(answer)); + if (logger.isDebugEnabled()) + logger.debug("Command execution answer: " + _gson.toJson(answer)); return answer; } finally { - if (s_logger.isDebugEnabled()) - s_logger.debug("Done executing " + _gson.toJson(cmd)); + if (logger.isDebugEnabled()) + logger.debug("Done executing " + _gson.toJson(cmd)); recycleServiceContext(); - NDC.pop(); + ThreadContext.pop(); } } private void logCommand(Command cmd) { try { - s_logger.debug(String.format("Executing command: [%s].", _gson.toJson(cmd))); + logger.debug(String.format("Executing command: [%s].", _gson.toJson(cmd))); } catch (Exception e) { - s_logger.debug(String.format("Executing command: [%s].", cmd.getClass().getSimpleName())); + logger.debug(String.format("Executing command: [%s].", cmd.getClass().getSimpleName())); } } @@ -186,13 +187,13 @@ private Answer execute(CreateVolumeFromSnapshotCommand cmd) { public VmwareContext getServiceContext(Command cmd) { String guid = cmd.getContextParam("guid"); if (guid == null || guid.isEmpty()) { - s_logger.error("Invalid command context parameter guid"); + logger.error("Invalid command context parameter guid"); return null; } String username = cmd.getContextParam("username"); if (username == null || username.isEmpty()) { - s_logger.error("Invalid command context parameter username"); + logger.error("Invalid command context parameter username"); return null; } @@ -201,14 +202,14 @@ public VmwareContext getServiceContext(Command cmd) { // validate command guid parameter String[] tokens = guid.split("@"); if (tokens == null || tokens.length != 2) { - s_logger.error("Invalid content in command context parameter guid"); + logger.error("Invalid content in command context parameter guid"); return null; } String vCenterAddress = tokens[1]; String[] hostTokens = tokens[0].split(":"); if (hostTokens == null || hostTokens.length != 2) { - s_logger.error("Invalid content in command context parameter guid"); + logger.error("Invalid content in command context parameter guid"); return null; } @@ -223,7 +224,7 @@ public VmwareContext getServiceContext(Command cmd) { context = null; } if (context == null) { - s_logger.info("Open new VmwareContext. vCenter: " + vCenterAddress + ", user: " + username + ", password: " + StringUtils.getMaskedPasswordForDisplay(password)); + logger.info("Open new VmwareContext. vCenter: " + vCenterAddress + ", user: " + username + ", password: " + StringUtils.getMaskedPasswordForDisplay(password)); VmwareSecondaryStorageContextFactory.setVcenterSessionTimeout(vCenterSessionTimeout); context = VmwareSecondaryStorageContextFactory.getContext(vCenterAddress, username, password); } @@ -235,7 +236,7 @@ public VmwareContext getServiceContext(Command cmd) { currentContext.set(context); return context; } catch (Exception e) { - s_logger.error("Unexpected exception " + e.toString(), e); + logger.error("Unexpected exception " + e.toString(), e); return null; } } @@ -266,7 +267,7 @@ public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) { ManagedObjectReference morHyperHost = new ManagedObjectReference(); String[] hostTokens = tokens[0].split(":"); if (hostTokens == null || hostTokens.length != 2) { - s_logger.error("Invalid content in command context parameter guid"); + logger.error("Invalid content in command context parameter guid"); return null; } @@ -289,10 +290,10 @@ public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) { : cmd.getContextParam("serviceconsole")); _resource.ensureOutgoingRuleForAddress(netSummary.getHostIp()); - s_logger.info("Setup firewall rule for host: " + netSummary.getHostIp()); + logger.info("Setup firewall rule for host: " + netSummary.getHostIp()); } } catch (Throwable e) { - s_logger.warn("Unable to retrive host network information due to exception " + e.toString() + ", host: " + hostTokens[0] + "-" + hostTokens[1]); + logger.warn("Unable to retrive host network information due to exception " + e.toString() + ", host: " + hostTokens[0] + "-" + hostTokens[1]); } return hostMo; @@ -320,7 +321,7 @@ public String getMountPoint(String storageUrl, String nfsVersion) { @Override public String createLogMessageException(Throwable e, Command command) { String message = String.format("%s failed due to [%s].", command.getClass().getSimpleName(), VmwareHelper.getExceptionMessage(e)); - s_logger.error(message, e); + logger.error(message, e); return message; } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageLayoutHelper.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageLayoutHelper.java index b6b92f67ec59..ab9754a7c9e0 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageLayoutHelper.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageLayoutHelper.java @@ -22,7 +22,8 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.hypervisor.vmware.mo.DatacenterMO; import com.cloud.hypervisor.vmware.mo.DatastoreFile; @@ -37,7 +38,7 @@ * */ public class VmwareStorageLayoutHelper implements Configurable { - private static final Logger s_logger = Logger.getLogger(VmwareStorageLayoutHelper.class); + protected static Logger LOGGER = LogManager.getLogger(VmwareStorageLayoutHelper.class); static final ConfigKey VsphereLinkedCloneExtensions = new ConfigKey("Hidden", String.class, "vsphere.linked.clone.extensions", "delta.vmdk,sesparse.vmdk", @@ -169,7 +170,7 @@ public static String syncVolumeToVmDefaultFolder(DatacenterMO dcMo, String vmNam assert (ds != null); if (!ds.folderExists(String.format("[%s]", ds.getName()), vmName)) { - s_logger.info("VM folder does not exist on target datastore, we will create one. vm: " + vmName + ", datastore: " + ds.getName()); + LOGGER.info("VM folder does not exist on target datastore, we will create one. vm: " + vmName + ", datastore: " + ds.getName()); ds.makeDirectory(String.format("[%s] %s", ds.getName(), vmName), dcMo.getMor()); } @@ -190,7 +191,7 @@ public static String syncVolumeToVmDefaultFolder(DatacenterMO dcMo, String vmNam for (int i=1; i" + vmdkFullCloneModePair[i]); + LOGGER.info("sync " + vmdkFullCloneModeLegacyPair[i] + "->" + vmdkFullCloneModePair[i]); ds.moveDatastoreFile(vmdkFullCloneModeLegacyPair[i], dcMo.getMor(), ds.getMor(), vmdkFullCloneModePair[i], dcMo.getMor(), true); } @@ -198,14 +199,14 @@ public static String syncVolumeToVmDefaultFolder(DatacenterMO dcMo, String vmNam for (int i=1; i" + vmdkLinkedCloneModePair[i]); + LOGGER.info("sync " + vmdkLinkedCloneModeLegacyPair[i] + "->" + vmdkLinkedCloneModePair[i]); ds.moveDatastoreFile(vmdkLinkedCloneModeLegacyPair[i], dcMo.getMor(), ds.getMor(), vmdkLinkedCloneModePair[i], dcMo.getMor(), true); } } if (ds.fileExists(vmdkLinkedCloneModeLegacyPair[0])) { - s_logger.info("sync " + vmdkLinkedCloneModeLegacyPair[0] + "->" + vmdkLinkedCloneModePair[0]); + LOGGER.info("sync " + vmdkLinkedCloneModeLegacyPair[0] + "->" + vmdkLinkedCloneModePair[0]); ds.moveDatastoreFile(vmdkLinkedCloneModeLegacyPair[0], dcMo.getMor(), ds.getMor(), vmdkLinkedCloneModePair[0], dcMo.getMor(), true); } @@ -240,14 +241,14 @@ public static void syncVolumeToRootFolder(DatacenterMO dcMo, DatastoreMO ds, Str if (ds.fileExists(companionFilePath)) { String targetPath = getDatastorePathBaseFolderFromVmdkFileName(ds, String.format("%s-%s",vmdkName, linkedCloneExtension)); - s_logger.info("Fixup folder-synchronization. move " + companionFilePath + " -> " + targetPath); + LOGGER.info("Fixup folder-synchronization. move " + companionFilePath + " -> " + targetPath); ds.moveDatastoreFile(companionFilePath, dcMo.getMor(), ds.getMor(), targetPath, dcMo.getMor(), true); } } // move the identity VMDK file the last String targetPath = getDatastorePathBaseFolderFromVmdkFileName(ds, vmdkName + ".vmdk"); - s_logger.info("Fixup folder-synchronization. move " + fileDsFullPath + " -> " + targetPath); + LOGGER.info("Fixup folder-synchronization. move " + fileDsFullPath + " -> " + targetPath); ds.moveDatastoreFile(fileDsFullPath, dcMo.getMor(), ds.getMor(), targetPath, dcMo.getMor(), true); try { @@ -266,9 +267,9 @@ public static void syncVolumeToRootFolder(DatacenterMO dcMo, DatastoreMO ds, Str + "in specific versions of VMWare. Users using VMFS or VMWare versions greater than 6.7 have not reported this error. If the operation performed is a volume detach, " + "it was successful. If you want to know why this error occurs in VMWare, please contact VMWare's technical support.", vmName, e.getMessage(), link); - s_logger.warn(message, e); + LOGGER.warn(message, e); } else { - s_logger.error(String.format("Failed to sync volume [%s] of VM [%s] due to: [%s].", vmdkName, vmName, e.getMessage()), e); + LOGGER.error(String.format("Failed to sync volume [%s] of VM [%s] due to: [%s].", vmdkName, vmName, e.getMessage()), e); throw e; } } @@ -279,13 +280,13 @@ public static void moveVolumeToRootFolder(DatacenterMO dcMo, List detach for (String fileFullDsPath : detachedDisks) { DatastoreFile file = new DatastoreFile(fileFullDsPath); - s_logger.info("Check if we need to move " + fileFullDsPath + " to its root location"); + LOGGER.info("Check if we need to move " + fileFullDsPath + " to its root location"); DatastoreMO dsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(file.getDatastoreName())); if (dsMo.getMor() != null && !dsMo.getDatastoreType().equalsIgnoreCase("VVOL")) { HypervisorHostHelper.createBaseFolderInDatastore(dsMo, dsMo.getDataCenterMor()); DatastoreFile targetFile = new DatastoreFile(file.getDatastoreName(), HypervisorHostHelper.VSPHERE_DATASTORE_BASE_FOLDER, file.getFileName()); if (!targetFile.getPath().equalsIgnoreCase(file.getPath())) { - s_logger.info("Move " + file.getPath() + " -> " + targetFile.getPath()); + LOGGER.info("Move " + file.getPath() + " -> " + targetFile.getPath()); dsMo.moveDatastoreFile(file.getPath(), dcMo.getMor(), dsMo.getMor(), targetFile.getPath(), dcMo.getMor(), true); List vSphereFileExtensions = new ArrayList<>(Arrays.asList(VsphereLinkedCloneExtensions.value().trim().split("\\s*,\\s*"))); @@ -295,13 +296,13 @@ public static void moveVolumeToRootFolder(DatacenterMO dcMo, List detach String pairSrcFilePath = file.getCompanionPath(String.format("%s-%s", file.getFileBaseName(), linkedCloneExtension)); String pairTargetFilePath = targetFile.getCompanionPath(String.format("%s-%s", file.getFileBaseName(), linkedCloneExtension)); if (dsMo.fileExists(pairSrcFilePath)) { - s_logger.info("Move " + pairSrcFilePath + " -> " + pairTargetFilePath); + LOGGER.info("Move " + pairSrcFilePath + " -> " + pairTargetFilePath); dsMo.moveDatastoreFile(pairSrcFilePath, dcMo.getMor(), dsMo.getMor(), pairTargetFilePath, dcMo.getMor(), true); } } } } else { - s_logger.warn("Datastore for " + fileFullDsPath + " no longer exists, we have to skip"); + LOGGER.warn("Datastore for " + fileFullDsPath + " no longer exists, we have to skip"); } } } @@ -371,7 +372,7 @@ public static void deleteVolumeVmdkFiles(DatastoreMO dsMo, String volumeName, Da if (fileFullPath != null) { dsMo.deleteFile(fileFullPath, dcMo.getMor(), true, excludeFolders); } else { - s_logger.warn("Unable to locate VMDK file: " + fileName); + LOGGER.warn("Unable to locate VMDK file: " + fileName); } List vSphereFileExtensions = new ArrayList<>(Arrays.asList(VsphereLinkedCloneExtensions.value().trim().split("\\s*,\\s*"))); @@ -383,7 +384,7 @@ public static void deleteVolumeVmdkFiles(DatastoreMO dsMo, String volumeName, Da if (fileFullPath != null) { dsMo.deleteFile(fileFullPath, dcMo.getMor(), true, excludeFolders); } else { - s_logger.warn("Unable to locate VMDK file: " + String.format("%s-%s", volumeName, linkedCloneExtension)); + LOGGER.warn("Unable to locate VMDK file: " + String.format("%s-%s", volumeName, linkedCloneExtension)); } } } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java index 40ebc4cb02ad..1e260b4f99b5 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -58,7 +58,8 @@ import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -151,7 +152,7 @@ public String getName() { } } - private static final Logger s_logger = Logger.getLogger(VmwareStorageProcessor.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int DEFAULT_NFS_PORT = 2049; private static final int SECONDS_TO_WAIT_FOR_DATASTORE = 120; @@ -181,7 +182,7 @@ public VmwareStorageProcessor(VmwareHostService hostService, boolean fullCloneFl @Override public SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand cmd) { - s_logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for VmwareStorageProcessor"); + logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for VmwareStorageProcessor"); return new SnapshotAndCopyAnswer(); } @@ -303,7 +304,7 @@ public ResignatureAnswer resignature(ResignatureCommand cmd) { return answer; } catch (Exception ex) { - s_logger.error(String.format("Command %s failed due to: [%s].", cmd.getClass().getSimpleName(), ex.getMessage()), ex); + logger.error(String.format("Command %s failed due to: [%s].", cmd.getClass().getSimpleName(), ex.getMessage()), ex); throw new CloudRuntimeException(ex.getMessage()); } @@ -314,7 +315,7 @@ private List getExtentsMatching(List details) throws Exception { - s_logger.debug(String.format("Executing clean up in DataStore: [%s].", dsMo.getName())); + logger.debug(String.format("Executing clean up in DataStore: [%s].", dsMo.getName())); boolean expandDatastore = Boolean.parseBoolean(details.get(DiskTO.EXPAND_DATASTORE)); // A volume on the storage system holding a template uses a minimum hypervisor snapshot reserve value. @@ -492,7 +493,7 @@ private Pair copyTemplateFromSecondaryToPrimary(VmwareHy boolean createSnapshot, String nfsVersion, String configuration) throws Exception { String secondaryMountPoint = mountService.getMountPoint(secondaryStorageUrl, nfsVersion); - s_logger.info(String.format("Init copy of template [name: %s, path in secondary storage: %s, configuration: %s] in secondary storage [url: %s, mount point: %s] to primary storage.", + logger.info(String.format("Init copy of template [name: %s, path in secondary storage: %s, configuration: %s] in secondary storage [url: %s, mount point: %s] to primary storage.", templateName, templatePathAtSecondaryStorage, configuration, secondaryStorageUrl, secondaryMountPoint)); String srcOVAFileName = @@ -501,15 +502,15 @@ private Pair copyTemplateFromSecondaryToPrimary(VmwareHy String srcFileName = getOVFFilePath(srcOVAFileName); if (srcFileName == null) { - Script command = new Script("tar", 0, s_logger); + Script command = new Script("tar", 0, logger); command.add("--no-same-owner"); command.add("-xf", srcOVAFileName); command.setWorkDir(secondaryMountPoint + "/" + templatePathAtSecondaryStorage); - s_logger.info("Executing command: " + command.toString()); + logger.info("Executing command: " + command.toString()); String result = command.execute(); if (result != null) { String msg = "Unable to unpack snapshot OVA file at: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -517,7 +518,7 @@ private Pair copyTemplateFromSecondaryToPrimary(VmwareHy srcFileName = getOVFFilePath(srcOVAFileName); if (srcFileName == null) { String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -526,19 +527,19 @@ private Pair copyTemplateFromSecondaryToPrimary(VmwareHy } VmConfigInfo vAppConfig; - s_logger.debug(String.format("Deploying OVF template %s with configuration %s.", templateName, configuration)); + logger.debug(String.format("Deploying OVF template %s with configuration %s.", templateName, configuration)); hyperHost.importVmFromOVF(srcFileName, templateUuid, datastoreMo, "thin", configuration); VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(templateUuid); if (vmMo == null) { String msg = "Failed to import OVA template. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " + templatePathAtSecondaryStorage + ", templateName: " + templateName + ", templateUuid: " + templateUuid; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } else { vAppConfig = vmMo.getConfigInfo().getVAppConfig(); if (vAppConfig != null) { - s_logger.info("Found vApp configuration"); + logger.info("Found vApp configuration"); } } @@ -561,7 +562,7 @@ private Pair copyTemplateFromSecondaryToPrimary(VmwareHy String msg = "Unable to create base snapshot for template, templateName: " + templateName + ", templateUuid: " + templateUuid; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -665,8 +666,8 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) { dsMo = new DatastoreMO(context, morDs); if (templateMo == null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Template " + templateInfo.second() + " is not setup yet. Set up template from secondary storage with uuid name: " + templateUuidName); + if (logger.isInfoEnabled()) { + logger.info("Template " + templateInfo.second() + " is not setup yet. Set up template from secondary storage with uuid name: " + templateUuidName); } if (managed) { @@ -694,7 +695,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) { templateUuidName, true, _nfsVersion, configurationId); } } else { - s_logger.info("Template " + templateInfo.second() + " has already been setup, skip the template setup process in primary storage"); + logger.info("Template " + templateInfo.second() + " has already been setup, skip the template setup process in primary storage"); } TemplateObjectTO newTemplate = new TemplateObjectTO(); @@ -727,7 +728,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) { removeVmfsDatastore(cmd, hyperHost, VmwareResource.getDatastoreName(managedStoragePoolName), storageHost, storagePort, trimIqn(managedStoragePoolName)); } catch (Exception ex) { - s_logger.error("Unable to remove the following datastore: " + VmwareResource.getDatastoreName(managedStoragePoolName), ex); + logger.error("Unable to remove the following datastore: " + VmwareResource.getDatastoreName(managedStoragePoolName), ex); } } } @@ -747,17 +748,17 @@ private boolean createVMLinkedClone(VirtualMachineMO vmTemplate, DatacenterMO dc if (morBaseSnapshot == null) { String msg = "Unable to find template base snapshot, invalid template"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } - s_logger.info("creating linked clone from template"); + logger.info("creating linked clone from template"); if (!vmTemplate.createLinkedClone(vmdkName, morBaseSnapshot, dcMo.getVmFolder(), morPool, morDatastore)) { String msg = "Unable to clone from the template"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -767,12 +768,12 @@ private boolean createVMLinkedClone(VirtualMachineMO vmTemplate, DatacenterMO dc private boolean createVMFullClone(VirtualMachineMO vmTemplate, DatacenterMO dcMo, DatastoreMO dsMo, String vmdkName, ManagedObjectReference morDatastore, ManagedObjectReference morPool, ProvisioningType diskProvisioningType) throws Exception { - s_logger.info("creating full clone from template"); + logger.info("creating full clone from template"); if (!vmTemplate.createFullClone(vmdkName, dcMo.getVmFolder(), morPool, morDatastore, diskProvisioningType)) { String msg = "Unable to create full clone from the template"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -809,13 +810,13 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) { VirtualMachineMO existingVm = dcMo.findVm(vmName); if (volume.getDeviceId().equals(0L)) { if (existingVm != null) { - s_logger.info(String.format("Found existing VM wth name [%s] before cloning from template, destroying it", vmName)); + logger.info(String.format("Found existing VM wth name [%s] before cloning from template, destroying it", vmName)); existingVm.detachAllDisksAndDestroy(); } - s_logger.info("ROOT Volume from deploy-as-is template, cloning template"); + logger.info("ROOT Volume from deploy-as-is template, cloning template"); cloneVMFromTemplate(hyperHost, template.getPath(), vmName, primaryStore.getUuid()); } else { - s_logger.info("ROOT Volume from deploy-as-is template, volume already created at this point"); + logger.info("ROOT Volume from deploy-as-is template, volume already created at this point"); } } else { if (srcStore == null) { @@ -833,15 +834,15 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) { String vmdkFilePair[] = VmwareStorageLayoutHelper.getVmdkFilePairDatastorePath(dsMo, null, vmdkFileBaseName, VmwareStorageLayoutType.CLOUDSTACK_LEGACY, true); String volumeDatastorePath = vmdkFilePair[0]; synchronized (this) { - s_logger.info("Delete file if exists in datastore to clear the way for creating the volume. file: " + volumeDatastorePath); + logger.info("Delete file if exists in datastore to clear the way for creating the volume. file: " + volumeDatastorePath); VmwareStorageLayoutHelper.deleteVolumeVmdkFiles(dsMo, vmdkName, dcMo, searchExcludedFolders); vmMo.createDisk(volumeDatastorePath, (long)(volume.getSize() / (1024L * 1024L)), morDatastore, -1, null); vmMo.detachDisk(volumeDatastorePath, false); } } finally { - s_logger.info("Destroy dummy VM after volume creation"); + logger.info("Destroy dummy VM after volume creation"); if (vmMo != null) { - s_logger.warn("Unable to destroy a null VM ManagedObjectReference"); + logger.warn("Unable to destroy a null VM ManagedObjectReference"); vmMo.detachAllDisksAndDestroy(); } } @@ -849,7 +850,7 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) { String templatePath = template.getPath(); VirtualMachineMO vmTemplate = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templatePath), true); if (vmTemplate == null) { - s_logger.warn("Template host in vSphere is not in connected state, request template reload"); + logger.warn("Template host in vSphere is not in connected state, request template reload"); return new CopyCmdAnswer("Template host in vSphere is not in connected state, request template reload"); } if (dsMo.getDatastoreType().equalsIgnoreCase("VVOL")) { @@ -909,7 +910,7 @@ private String cloneVMforVvols(VmwareContext context, VmwareHypervisorHost hyper assert (vmMo != null); String vmdkFileBaseName = vmMo.getVmdkFileBaseNames().get(0); if (volume.getVolumeType() == Volume.Type.DATADISK) { - s_logger.info("detach disks from volume-wrapper VM " + vmName); + logger.info("detach disks from volume-wrapper VM " + vmName); vmMo.detachAllDisksAndDestroy(); } return vmdkFileBaseName; @@ -939,7 +940,7 @@ private String createVMAndFolderWithVMName(VmwareContext context, VmwareHypervis assert (vmMo != null); String vmdkFileBaseName = vmMo.getVmdkFileBaseNames().get(0); - s_logger.info("Move volume out of volume-wrapper VM " + vmdkFileBaseName); + logger.info("Move volume out of volume-wrapper VM " + vmdkFileBaseName); String[] vmwareLayoutFilePair = VmwareStorageLayoutHelper.getVmdkFilePairDatastorePath(dsMo, vmdkName, vmdkFileBaseName, VmwareStorageLayoutType.VMWARE, !_fullCloneFlag); String[] legacyCloudStackLayoutFilePair = VmwareStorageLayoutHelper.getVmdkFilePairDatastorePath(dsMo, vmdkName, vmdkFileBaseName, VmwareStorageLayoutType.CLOUDSTACK_LEGACY, !_fullCloneFlag); @@ -947,7 +948,7 @@ private String createVMAndFolderWithVMName(VmwareContext context, VmwareHypervis dsMo.moveDatastoreFile(vmwareLayoutFilePair[i], dcMo.getMor(), dsMo.getMor(), legacyCloudStackLayoutFilePair[i], dcMo.getMor(), true); } - s_logger.info("detach disks from volume-wrapper VM and destroy" + vmdkName); + logger.info("detach disks from volume-wrapper VM and destroy {}", vmdkName); vmMo.detachAllDisksAndDestroy(); String srcFile = dsMo.getDatastorePath(vmdkName, true); @@ -1021,7 +1022,7 @@ private String deleteVolumeDirOnSecondaryStorage(String volumeDir, String secSto private String deleteDir(String dir) { synchronized (dir.intern()) { - Script command = new Script(false, "rm", _timeout, s_logger); + Script command = new Script(false, "rm", _timeout, logger); command.add("-rf"); command.add(dir); return command.execute(); @@ -1081,7 +1082,7 @@ private Pair copyVolumeToSecStorage(VmwareHostService hostServic if (morDs == null) { String msg = "Unable to find volumes's storage pool for copy volume operation"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -1094,7 +1095,7 @@ private Pair copyVolumeToSecStorage(VmwareHostService hostServic if (workerVm == null) { String msg = "Unable to create worker VM to execute CopyVolumeCommand"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -1188,14 +1189,14 @@ private Ternary createTemplateFromVolume(VmwareContext conte String secondaryMountPoint = mountService.getMountPoint(secStorageUrl, nfsVersion); String installFullPath = secondaryMountPoint + "/" + installPath; synchronized (installPath.intern()) { - Script command = new Script(false, "mkdir", _timeout, s_logger); + Script command = new Script(false, "mkdir", _timeout, logger); command.add("-p"); command.add(installFullPath); String result = command.execute(); if (result != null) { String msg = "unable to prepare template directory: " + installPath + ", storage: " + secStorageUrl + ", error msg: " + result; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -1205,7 +1206,7 @@ private Ternary createTemplateFromVolume(VmwareContext conte Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -1245,7 +1246,7 @@ private Ternary createTemplateFromVolume(VmwareContext conte } finally { if (clonedVm != null) { - s_logger.debug(String.format("Destroying cloned VM: %s with its disks", clonedVm.getName())); + logger.debug(String.format("Destroying cloned VM: %s with its disks", clonedVm.getName())); clonedVm.destroy(); } } @@ -1283,8 +1284,8 @@ public Answer createTemplateFromVolume(CopyCommand cmd) { } else { vmMo = hyperHost.findVmOnHyperHost(volume.getVmName()); if (vmMo == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find the owner VM for CreatePrivateTemplateFromVolumeCommand on host " + hyperHost.getHyperHostName() + + if (logger.isDebugEnabled()) { + logger.debug("Unable to find the owner VM for CreatePrivateTemplateFromVolumeCommand on host " + hyperHost.getHyperHostName() + ", try within datacenter"); } vmMo = hyperHost.findVmOnPeerHyperHost(volume.getVmName()); @@ -1299,7 +1300,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) { if (vmMo == null) { String msg = "Unable to find the owner VM for volume operation. vm: " + volume.getVmName(); - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -1323,7 +1324,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) { workerVmMo.detachAllDisksAndDestroy(); } } catch (Throwable e) { - s_logger.error("Failed to destroy worker VM created for detached volume"); + logger.error("Failed to destroy worker VM created for detached volume"); } } } @@ -1380,68 +1381,68 @@ private Ternary createTemplateFromSnapshot(String installPat String snapshotFullVMDKName = snapshotRoot + "/" + backupSSUuid + "/"; synchronized (installPath.intern()) { - command = new Script(false, "mkdir", _timeout, s_logger); + command = new Script(false, "mkdir", _timeout, logger); command.add("-p"); command.add(installFullPath); result = command.execute(); if (result != null) { String msg = "unable to prepare template directory: " + installPath + ", storage: " + secStorageUrl + ", error msg: " + result; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } try { if (new File(snapshotFullOVAName).exists()) { - command = new Script(false, "cp", wait, s_logger); + command = new Script(false, "cp", wait, logger); command.add(snapshotFullOVAName); command.add(installFullOVAName); result = command.execute(); if (result != null) { String msg = "unable to copy snapshot " + snapshotFullOVAName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } // untar OVA file at template directory - command = new Script("tar", wait, s_logger); + command = new Script("tar", wait, logger); command.add("--no-same-owner"); command.add("-xf", installFullOVAName); command.setWorkDir(installFullPath); - s_logger.info("Executing command: " + command.toString()); + logger.info("Executing command: " + command.toString()); result = command.execute(); if (result != null) { String msg = "unable to untar snapshot " + snapshotFullOVAName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } else { // there is no ova file, only ovf originally; if (new File(snapshotFullOvfName).exists()) { - command = new Script(false, "cp", wait, s_logger); + command = new Script(false, "cp", wait, logger); command.add(snapshotFullOvfName); //command.add(installFullOvfName); command.add(installFullPath); result = command.execute(); if (result != null) { String msg = "unable to copy snapshot " + snapshotFullOvfName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } - s_logger.info("vmdkfile parent dir: " + snapshotRoot); + logger.info("vmdkfile parent dir: " + snapshotRoot); File snapshotdir = new File(snapshotRoot); File[] ssfiles = snapshotdir.listFiles(); if (ssfiles == null) { String msg = "unable to find snapshot vmdk files in " + snapshotRoot; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } // List filenames = new ArrayList(); for (int i = 0; i < ssfiles.length; i++) { String vmdkfile = ssfiles[i].getName(); - s_logger.info("vmdk file name: " + vmdkfile); + logger.info("vmdk file name: " + vmdkfile); if (vmdkfile.toLowerCase().startsWith(backupSSUuid) && vmdkfile.toLowerCase().endsWith(".vmdk")) { snapshotFullVMDKName = snapshotRoot + File.separator + vmdkfile; templateVMDKName += vmdkfile; @@ -1449,20 +1450,20 @@ private Ternary createTemplateFromSnapshot(String installPat } } if (snapshotFullVMDKName != null) { - command = new Script(false, "cp", wait, s_logger); + command = new Script(false, "cp", wait, logger); command.add(snapshotFullVMDKName); command.add(installFullPath); result = command.execute(); - s_logger.info("Copy VMDK file: " + snapshotFullVMDKName); + logger.info("Copy VMDK file: " + snapshotFullVMDKName); if (result != null) { String msg = "unable to copy snapshot vmdk file " + snapshotFullVMDKName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } } else { String msg = "unable to find any snapshot ova/ovf files" + snapshotFullOVAName + " to " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } @@ -1592,7 +1593,7 @@ private void takeDownManagedStorageCopyTemplateFromSnapshot(CopyCommand cmd) thr private void createTemplateFolder(String installPath, String installFullPath, NfsTO nfsSvr) { synchronized (installPath.intern()) { - Script command = new Script(false, "mkdir", _timeout, s_logger); + Script command = new Script(false, "mkdir", _timeout, logger); command.add("-p"); command.add(installFullPath); @@ -1603,7 +1604,7 @@ private void createTemplateFolder(String installPath, String installFullPath, Nf String secStorageUrl = nfsSvr.getUrl(); String msg = "unable to prepare template directory: " + installPath + "; storage: " + secStorageUrl + "; error msg: " + result; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -1640,7 +1641,7 @@ private String getTemplateVmdkName(String installFullPath, String exportName) { if (templateFiles == null) { String msg = "Unable to find template files in " + installFullPath; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -1693,7 +1694,7 @@ private Answer handleManagedStorageCreateTemplateFromSnapshot(CopyCommand cmd, T catch (Exception ex) { String errMsg = "Problem creating a template from a snapshot for managed storage: " + ex.getMessage(); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg, ex); } @@ -1702,7 +1703,7 @@ private Answer handleManagedStorageCreateTemplateFromSnapshot(CopyCommand cmd, T takeDownManagedStorageCopyTemplateFromSnapshot(cmd); } catch (Exception ex) { - s_logger.warn("Unable to remove one or more static targets"); + logger.warn("Unable to remove one or more static targets"); } } } @@ -1757,13 +1758,13 @@ private Pair exportVolumeToSecondaryStorage(VmwareContext cont synchronized (exportPath.intern()) { if (!new File(exportPath).exists()) { - Script command = new Script(false, "mkdir", _timeout, s_logger); + Script command = new Script(false, "mkdir", _timeout, logger); command.add("-p"); command.add(exportPath); String result = command.execute(); if (result != null) { String errorMessage = String.format("Unable to prepare snapshot backup directory: [%s] due to [%s].", exportPath, result); - s_logger.error(errorMessage); + logger.error(errorMessage); throw new Exception(errorMessage); } } @@ -1775,7 +1776,7 @@ private Pair exportVolumeToSecondaryStorage(VmwareContext cont Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath); if (volumeDeviceInfo == null) { String msg = "Unable to find related disk device for volume. volume path: " + volumePath; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -1799,7 +1800,7 @@ private Pair exportVolumeToSecondaryStorage(VmwareContext cont return new Pair<>(diskDevice, disks); } finally { if (clonedVm != null) { - s_logger.debug(String.format("Destroying cloned VM: %s with its disks", clonedVm.getName())); + logger.debug(String.format("Destroying cloned VM: %s with its disks", clonedVm.getName())); clonedVm.destroy(); } } @@ -1858,8 +1859,8 @@ public Answer backupSnapshot(CopyCommand cmd) { if(vmName != null) { vmMo = hyperHost.findVmOnHyperHost(vmName); if (vmMo == null) { - if(s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter"); + if(logger.isDebugEnabled()) { + logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter"); } vmMo = hyperHost.findVmOnPeerHyperHost(vmName); } @@ -1876,11 +1877,11 @@ public Answer backupSnapshot(CopyCommand cmd) { String datastoreVolumePath = VmwareStorageLayoutHelper.getLegacyDatastorePathFromVmdkFileName(dsMo, volumePath + ".vmdk"); vmMo.attachDisk(new String[] { datastoreVolumePath }, morDs); } else { - s_logger.info("Using owner VM " + vmName + " for snapshot operation"); + logger.info("Using owner VM " + vmName + " for snapshot operation"); hasOwnerVm = true; } - s_logger.debug(String.format("Executing backup snapshot with UUID [%s] to secondary storage.", snapshotUuid)); + logger.debug(String.format("Executing backup snapshot with UUID [%s] to secondary storage.", snapshotUuid)); backupResult = backupSnapshotToSecondaryStorage(context, vmMo, hyperHost, destSnapshot.getPath(), srcSnapshot.getVolume().getPath(), snapshotUuid, secondaryStorageUrl, prevSnapshotUuid, prevBackupUuid, hostService.getWorkerName(context, cmd, 1, null), _nfsVersion); @@ -1925,18 +1926,18 @@ public Answer backupSnapshot(CopyCommand cmd) { // TODO: this post operation fixup is not atomic and not safe when management server stops // in the middle if (backupResult != null && hasOwnerVm) { - s_logger.info("Check if we have disk consolidation after snapshot operation"); + logger.info("Check if we have disk consolidation after snapshot operation"); boolean chainConsolidated = false; for (String vmdkDsFilePath : backupResult.third()) { - s_logger.info("Validate disk chain file:" + vmdkDsFilePath); + logger.info("Validate disk chain file:" + vmdkDsFilePath); if (vmMo.getDiskDevice(vmdkDsFilePath) == null) { - s_logger.info("" + vmdkDsFilePath + " no longer exists, consolidation detected"); + logger.info("" + vmdkDsFilePath + " no longer exists, consolidation detected"); chainConsolidated = true; break; } else { - s_logger.info("" + vmdkDsFilePath + " is found still in chain"); + logger.info("" + vmdkDsFilePath + " is found still in chain"); } } @@ -1945,10 +1946,10 @@ public Answer backupSnapshot(CopyCommand cmd) { try { topVmdkFilePath = vmMo.getDiskCurrentTopBackingFileInChain(backupResult.second()); } catch (Exception e) { - s_logger.error("Unexpected exception", e); + logger.error("Unexpected exception", e); } - s_logger.info("Disk has been consolidated, top VMDK is now: " + topVmdkFilePath); + logger.info("Disk has been consolidated, top VMDK is now: " + topVmdkFilePath); if (topVmdkFilePath != null) { DatastoreFile file = new DatastoreFile(topVmdkFilePath); @@ -1958,12 +1959,12 @@ public Answer backupSnapshot(CopyCommand cmd) { vol.setPath(file.getFileBaseName()); snapshotInfo.setVolume(vol); } else { - s_logger.error("Disk has been consolidated, but top VMDK is not found ?!"); + logger.error("Disk has been consolidated, but top VMDK is not found ?!"); } } } } else { - s_logger.info("No snapshots created to be deleted!"); + logger.info("No snapshots created to be deleted!"); } } @@ -1972,7 +1973,7 @@ public Answer backupSnapshot(CopyCommand cmd) { workerVm.detachAllDisksAndDestroy(); } } catch (Throwable e) { - s_logger.warn(String.format("Failed to destroy worker VM [%s] due to: [%s]", workerVMName, e.getMessage()), e); + logger.warn(String.format("Failed to destroy worker VM [%s] due to: [%s]", workerVMName, e.getMessage()), e); } } @@ -2018,7 +2019,7 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean if (vmMo == null) { String msg = "Unable to find the VM to execute AttachCommand, vmName: " + vmName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -2047,7 +2048,7 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean if (morDs == null) { String msg = "Unable to find the mounted datastore to execute AttachCommand, vmName: " + vmName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -2149,7 +2150,7 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean return answer; } catch (Throwable e) { String msg = String.format("Failed to %s volume!", isAttach? "attach" : "detach"); - s_logger.error(msg, e); + logger.error(msg, e); hostService.createLogMessageException(e, cmd); // Sending empty error message - too many duplicate errors in UI return new AttachAnswer(""); @@ -2171,7 +2172,7 @@ private VirtualMachineDiskInfo getMatchingExistingDisk(VmwareHypervisorHost hype VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(diskBackingFileBaseName, dsName); if (diskInfo != null) { - s_logger.info("Found existing disk info from volume path: " + volume.getPath()); + logger.info("Found existing disk info from volume path: " + volume.getPath()); return diskInfo; } else { String chainInfo = volume.getChainInfo(); @@ -2184,7 +2185,7 @@ private VirtualMachineDiskInfo getMatchingExistingDisk(VmwareHypervisorHost hype DatastoreFile file = new DatastoreFile(diskPath); diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName); if (diskInfo != null) { - s_logger.info("Found existing disk from chain info: " + diskPath); + logger.info("Found existing disk from chain info: " + diskPath); return diskInfo; } } @@ -2193,7 +2194,7 @@ private VirtualMachineDiskInfo getMatchingExistingDisk(VmwareHypervisorHost hype if (diskInfo == null) { diskInfo = diskInfoBuilder.getDiskInfoByDeviceBusName(infoInChain.getDiskDeviceBusName()); if (diskInfo != null) { - s_logger.info("Found existing disk from chain device bus information: " + infoInChain.getDiskDeviceBusName()); + logger.info("Found existing disk from chain device bus information: " + infoInChain.getDiskDeviceBusName()); return diskInfo; } } @@ -2216,7 +2217,7 @@ private DatastoreMO getDiskDatastoreMofromVM(VmwareHypervisorHost hyperHost, Vmw VirtualMachineDiskInfo diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(diskBackingFileBaseName, dsName); if (diskInfo != null) { - s_logger.info("Found existing disk info from volume path: " + volume.getPath()); + logger.info("Found existing disk info from volume path: " + volume.getPath()); return dsMo; } else { String chainInfo = volume.getChainInfo(); @@ -2229,7 +2230,7 @@ private DatastoreMO getDiskDatastoreMofromVM(VmwareHypervisorHost hyperHost, Vmw DatastoreFile file = new DatastoreFile(diskPath); diskInfo = diskInfoBuilder.getDiskInfoByBackingFileBaseName(file.getFileBaseName(), dsName); if (diskInfo != null) { - s_logger.info("Found existing disk from chain info: " + diskPath); + logger.info("Found existing disk from chain info: " + diskPath); return dsMo; } } @@ -2282,12 +2283,12 @@ private boolean expandVirtualDisk(VirtualMachineMO vmMo, String datastoreVolumeP return false; } - private static String getSecondaryDatastoreUUID(String storeUrl) { + private String getSecondaryDatastoreUUID(String storeUrl) { String uuid = null; try{ uuid=UUID.nameUUIDFromBytes(storeUrl.getBytes("UTF-8")).toString(); }catch(UnsupportedEncodingException e){ - s_logger.warn("Failed to create UUID from string " + storeUrl + ". Bad storeUrl or UTF-8 encoding error." ); + logger.warn("Failed to create UUID from string " + storeUrl + ". Bad storeUrl or UTF-8 encoding error." ); } return uuid; } @@ -2313,7 +2314,7 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName, boolean f VirtualMachineMO vmMo = HypervisorHostHelper.findVmOnHypervisorHostOrPeer(hyperHost, vmName); if (vmMo == null) { String msg = "Unable to find VM in vSphere to execute AttachIsoCommand, vmName: " + vmName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } TemplateObjectTO iso = (TemplateObjectTO)disk.getData(); @@ -2325,7 +2326,7 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName, boolean f if (storeUrl == null) { if (!iso.getName().equalsIgnoreCase(TemplateManager.VMWARE_TOOLS_ISO)) { String msg = "ISO store root url is not found in AttachIsoCommand"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } else { if (isAttach) { @@ -2349,7 +2350,7 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName, boolean f if (!isoPath.startsWith(storeUrl)) { assert (false); String msg = "ISO path does not start with the secondary storage root"; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -2372,12 +2373,12 @@ private Answer attachIso(DiskTO disk, boolean isAttach, String vmName, boolean f return new AttachAnswer(disk); } catch (Throwable e) { if (e instanceof RemoteException) { - s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); + logger.warn("Encounter remote exception to vCenter, invalidate VMware session context"); hostService.invalidateServiceContext(null); } String message = String.format("AttachIsoCommand(%s) failed due to: [%s]. Also check if your guest os is a supported version", isAttach? "attach" : "detach", VmwareHelper.getExceptionMessage(e)); - s_logger.error(message, e); + logger.error(message, e); return new AttachAnswer(message); } } @@ -2394,7 +2395,7 @@ public Answer dettachVolume(DettachCommand cmd) { @Override public Answer createVolume(CreateObjectCommand cmd) { - s_logger.debug(LogUtils.logGsonWithoutException("Executing CreateObjectCommand cmd: [%s].", cmd)); + logger.debug(LogUtils.logGsonWithoutException("Executing CreateObjectCommand cmd: [%s].", cmd)); VolumeObjectTO volume = (VolumeObjectTO)cmd.getData(); DataStoreTO primaryStore = volume.getDataStore(); String vSphereStoragePolicyId = volume.getvSphereStoragePolicyId(); @@ -2424,10 +2425,10 @@ public Answer createVolume(CreateObjectCommand cmd) { newVol.setPath(file.getFileBaseName()); newVol.setSize(volume.getSize()); } catch (Exception e) { - s_logger.error(String.format("Create disk using vStorageObject manager failed due to [%s], retrying using worker VM.", e.getMessage()), e); + logger.error(String.format("Create disk using vStorageObject manager failed due to [%s], retrying using worker VM.", e.getMessage()), e); String dummyVmName = hostService.getWorkerName(context, cmd, 0, dsMo); try { - s_logger.info(String.format("Creating worker VM [%s].", dummyVmName)); + logger.info(String.format("Creating worker VM [%s].", dummyVmName)); vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, dummyVmName, null); if (vmMo == null) { throw new CloudRuntimeException("Unable to create a dummy VM for volume creation."); @@ -2439,7 +2440,7 @@ public Answer createVolume(CreateObjectCommand cmd) { vmMo.detachDisk(volumeDatastorePath, false); } catch (Exception e1) { - s_logger.error(String.format("Deleting file [%s] due to [%s].", volumeDatastorePath, e1.getMessage()), e1); + logger.error(String.format("Deleting file [%s] due to [%s].", volumeDatastorePath, e1.getMessage()), e1); VmwareStorageLayoutHelper.deleteVolumeVmdkFiles(dsMo, volumeUuid, dcMo, VmwareManager.s_vmwareSearchExcludeFolder.value()); throw new CloudRuntimeException(String.format("Unable to create volume due to [%s].", e1.getMessage())); } @@ -2450,7 +2451,7 @@ public Answer createVolume(CreateObjectCommand cmd) { newVol.setSize(volume.getSize()); return new CreateObjectAnswer(newVol); } finally { - s_logger.info("Destroying dummy VM after volume creation."); + logger.info("Destroying dummy VM after volume creation."); if (vmMo != null) { vmMo.detachAllDisksAndDestroy(); } @@ -2505,7 +2506,7 @@ public Answer deleteVolume(DeleteCommand cmd) { if (morDs == null) { String msg = "Unable to find datastore based on volume mount point " + store.getUuid(); - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -2531,11 +2532,11 @@ public Answer deleteVolume(DeleteCommand cmd) { boolean deployAsIs = vol.isDeployAsIs(); if (vmMo != null) { - if (s_logger.isInfoEnabled()) { + if (logger.isInfoEnabled()) { if (deployAsIs) { - s_logger.info("Destroying root volume " + vol.getPath() + " of deploy-as-is VM " + vmName); + logger.info("Destroying root volume " + vol.getPath() + " of deploy-as-is VM " + vmName); } else { - s_logger.info("Destroy root volume and VM itself. vmName " + vmName); + logger.info("Destroy root volume and VM itself. vmName " + vmName); } } @@ -2583,15 +2584,15 @@ public Answer deleteVolume(DeleteCommand cmd) { } } } else if (deployAsIs) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Destroying root volume " + vol.getPath() + " of already removed deploy-as-is VM " + vmName); + if (logger.isInfoEnabled()) { + logger.info("Destroying root volume " + vol.getPath() + " of already removed deploy-as-is VM " + vmName); } // The disks of the deploy-as-is VM have been detached from the VM and moved to root folder String deployAsIsRootDiskPath = dsMo.searchFileInSubFolders(vol.getPath() + VmwareResource.VMDK_EXTENSION, true, null); if (StringUtils.isNotBlank(deployAsIsRootDiskPath)) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Removing disk " + deployAsIsRootDiskPath); + if (logger.isInfoEnabled()) { + logger.info("Removing disk " + deployAsIsRootDiskPath); } dsMo.deleteFile(deployAsIsRootDiskPath, morDc, true); String deltaFilePath = dsMo.searchFileInSubFolders(vol.getPath() + "-delta" + VmwareResource.VMDK_EXTENSION, @@ -2603,8 +2604,8 @@ public Answer deleteVolume(DeleteCommand cmd) { } /* - if (s_logger.isInfoEnabled()) { - s_logger.info("Destroy volume by original name: " + vol.getPath() + ".vmdk"); + if (logger.isInfoEnabled()) { + logger.info("Destroy volume by original name: " + vol.getPath() + ".vmdk"); } VmwareStorageLayoutHelper.deleteVolumeVmdkFiles(dsMo, vol.getPath(), new DatacenterMO(context, morDc)); @@ -2613,8 +2614,8 @@ public Answer deleteVolume(DeleteCommand cmd) { return new Answer(cmd, true, ""); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Destroy root volume directly from datastore"); + if (logger.isInfoEnabled()) { + logger.info("Destroy root volume directly from datastore"); } } @@ -2637,7 +2638,7 @@ private ManagedObjectReference prepareManagedDatastore(VmwareContext context, Vm String storageHost, int storagePort, String chapInitiatorUsername, String chapInitiatorSecret, String chapTargetUsername, String chapTargetSecret) throws Exception { if (storagePort == DEFAULT_NFS_PORT) { - s_logger.info("creating the NFS datastore with the following configuration - storageHost: " + storageHost + ", storagePort: " + storagePort + + logger.info("creating the NFS datastore with the following configuration - storageHost: " + storageHost + ", storagePort: " + storagePort + ", exportpath: " + iScsiName + "and diskUuid : " + diskUuid); ManagedObjectReference morCluster = hyperHost.getHyperHostCluster(); ClusterMO cluster = new ClusterMO(context, morCluster); @@ -3024,13 +3025,13 @@ private void mountVmfsDatastore2(DatastoreMO dsMO, List hosts) throws Ex hostStorageSystemMO.mountVmfsVolume(getDatastoreUuid(dsMO, hostMO)); } catch (InvalidStateFaultMsg ex) { - s_logger.trace("'" + ex.getClass().getName() + "' exception thrown: " + ex.getMessage()); + logger.trace("'" + ex.getClass().getName() + "' exception thrown: " + ex.getMessage()); List currentHosts = new ArrayList<>(1); currentHosts.add(hostMO); - s_logger.trace("Waiting for host " + hostMO.getHostName() + " to mount datastore " + dsMO.getName()); + logger.trace("Waiting for host " + hostMO.getHostName() + " to mount datastore " + dsMO.getName()); waitForAllHostsToMountDatastore2(currentHosts, dsMO); } @@ -3204,7 +3205,7 @@ public void handleTargets(boolean add, ModifyTargetsCommand.TargetTypeToRemove t } } catch (Exception ex) { - s_logger.warn(ex.getMessage()); + logger.warn(ex.getMessage()); } })); } @@ -3288,7 +3289,7 @@ private void handleRemove(List targetsToRemove, rescanAllHosts(hosts, true, false); } catch (Exception ex) { - s_logger.warn(ex.getMessage()); + logger.warn(ex.getMessage()); } } @@ -3425,13 +3426,13 @@ private void rescanAllHosts(List lstHosts, boolean rescanHba, boolean re } } - private static String trimIqn(String iqn) { + private String trimIqn(String iqn) { String[] tmp = iqn.split("/"); if (tmp.length != 3) { String msg = "Wrong format for iSCSI path: " + iqn + ". It should be formatted as '/targetIQN/LUN'."; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -3548,7 +3549,7 @@ private void removeManagedTargetsFromCluster(List managedDatastoreNames) rescanAllHosts(context, hosts, true, false); } catch (Exception ex) { - s_logger.warn(ex.getMessage()); + logger.warn(ex.getMessage()); } })); } @@ -3617,27 +3618,27 @@ private Long restoreVolumeFromSecStorage(VmwareHypervisorHost hyperHost, Datasto if (!ovfFile.exists()) { srcOVFFileName = getOVFFilePath(srcOVAFileName); if (srcOVFFileName == null && ovafile.exists()) { // volss: ova file exists; o/w can't do tar - Script command = new Script("tar", wait, s_logger); + Script command = new Script("tar", wait, logger); command.add("--no-same-owner"); command.add("-xf", srcOVAFileName); command.setWorkDir(secondaryMountPoint + "/" + secStorageDir + "/" + snapshotDir); - s_logger.info("Executing command: " + command.toString()); + logger.info("Executing command: " + command.toString()); String result = command.execute(); if (result != null) { String msg = "Unable to unpack snapshot OVA file at: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } srcOVFFileName = getOVFFilePath(srcOVAFileName); } else if (srcOVFFileName == null) { String msg = "Unable to find snapshot OVA file at: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } if (srcOVFFileName == null) { String msg = "Unable to locate OVF file in template package directory: " + srcOVAFileName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -3691,7 +3692,7 @@ public Answer createVolumeFromSnapshot(CopyCommand cmd) { ManagedObjectReference morPrimaryDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStorageNameLabel); if (morPrimaryDs == null) { String msg = "Unable to find datastore: " + primaryStorageNameLabel; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -3736,12 +3737,12 @@ public Answer forgetObject(ForgetObjectCmd cmd) { return new Answer(cmd, false, "not implememented yet"); } - private static String deriveTemplateUuidOnHost(VmwareHypervisorHost hyperHost, String storeIdentifier, String templateName) { + private String deriveTemplateUuidOnHost(VmwareHypervisorHost hyperHost, String storeIdentifier, String templateName) { String templateUuid; try { templateUuid = UUID.nameUUIDFromBytes((templateName + "@" + storeIdentifier + "-" + hyperHost.getMor().getValue()).getBytes("UTF-8")).toString(); } catch(UnsupportedEncodingException e){ - s_logger.warn("unexpected encoding error, using default Charset: " + e.getLocalizedMessage()); + logger.warn("unexpected encoding error, using default Charset: " + e.getLocalizedMessage()); templateUuid = UUID.nameUUIDFromBytes((templateName + "@" + storeIdentifier + "-" + hyperHost.getMor().getValue()).getBytes(Charset.defaultCharset())) .toString(); } @@ -3755,17 +3756,17 @@ private String getLegacyVmDataDiskController() throws Exception { void setNfsVersion(String nfsVersion){ this._nfsVersion = nfsVersion; - s_logger.debug("VmwareProcessor instance now using NFS version: " + nfsVersion); + logger.debug("VmwareProcessor instance now using NFS version: " + nfsVersion); } void setFullCloneFlag(boolean value){ this._fullCloneFlag = value; - s_logger.debug("VmwareProcessor instance - create full clone = " + (value ? "TRUE" : "FALSE")); + logger.debug("VmwareProcessor instance - create full clone = " + (value ? "TRUE" : "FALSE")); } void setDiskProvisioningStrictness(boolean value){ this._diskProvisioningStrictness = value; - s_logger.debug("VmwareProcessor instance - diskProvisioningStrictness = " + (value ? "TRUE" : "FALSE")); + logger.debug("VmwareProcessor instance - diskProvisioningStrictness = " + (value ? "TRUE" : "FALSE")); } @Override @@ -3783,7 +3784,7 @@ public Answer checkDataStoreStoragePolicyCompliance(CheckDataStoreStoragePolicyC ManagedObjectReference morPrimaryDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStorageNameLabel); if (morPrimaryDs == null) { String msg = "Unable to find datastore: " + primaryStorageNameLabel; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } @@ -3824,7 +3825,7 @@ public VirtualMachineMO cloneVMFromTemplate(VmwareHypervisorHost hyperHost, Stri if (morDatastore == null) { throw new CloudRuntimeException("Unable to find datastore in vSphere"); } - s_logger.info("Cloning VM " + cloneName + " from template " + templateName + " into datastore " + templatePrimaryStoreUuid); + logger.info("Cloning VM " + cloneName + " from template " + templateName + " into datastore " + templatePrimaryStoreUuid); if (!_fullCloneFlag) { createVMLinkedClone(templateMo, dcMo, cloneName, morDatastore, morPool, null); } else { @@ -3837,7 +3838,7 @@ public VirtualMachineMO cloneVMFromTemplate(VmwareHypervisorHost hyperHost, Stri return vm; } catch (Throwable e) { String msg = "Error cloning VM from template in primary storage: %s" + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg, e); } } @@ -3857,8 +3858,8 @@ public Pair getSyncedVolume(VirtualMachineMO vmMo, VmwareConte DatastoreFile file = new DatastoreFile(diskChain[0]); String volumePath = volumeTO.getPath(); if (!file.getFileBaseName().equalsIgnoreCase(volumePath)) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumePath + " -> " + file.getFileBaseName()); + if (logger.isInfoEnabled()) { + logger.info("Detected disk-chain top file change on volume: " + volumeTO.getId() + " " + volumePath + " -> " + file.getFileBaseName()); } volumePathChangeObserved = true; volumePath = file.getFileBaseName(); @@ -3870,7 +3871,7 @@ public Pair getSyncedVolume(VirtualMachineMO vmMo, VmwareConte if (diskDatastoreMoFromVM != null) { String actualPoolUuid = diskDatastoreMoFromVM.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID); if (!actualPoolUuid.equalsIgnoreCase(primaryStore.getUuid())) { - s_logger.warn(String.format("Volume %s found to be in a different storage pool %s", volumePath, actualPoolUuid)); + logger.warn(String.format("Volume %s found to be in a different storage pool %s", volumePath, actualPoolUuid)); datastoreChangeObserved = true; volumeTO.setDataStoreUuid(actualPoolUuid); volumeTO.setChainInfo(_gson.toJson(matchingExistingDisk)); @@ -3894,7 +3895,7 @@ public Answer syncVolumePath(SyncVolumePathCommand cmd) { vmMo = hyperHost.findVmOnPeerHyperHost(vmName); if (vmMo == null) { String msg = "Unable to find the VM to execute SyncVolumePathCommand, vmName: " + vmName; - s_logger.error(msg); + logger.error(msg); throw new Exception(msg); } } diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java index e56f41ea8212..0067508cb000 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataObjectType; @@ -54,7 +53,6 @@ public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemCommandHandlerBase { - private static final Logger s_logger = Logger.getLogger(VmwareStorageSubsystemCommandHandler.class); private VmwareStorageManager storageManager; private PremiumSecondaryStorageResource storageResource; private String _nfsVersion; @@ -98,7 +96,7 @@ public boolean reconfigureStorageProcessor(EnumMap getHostIdForVmAndHostGuidInTargetCluster(VirtualMachi @Override public StrategyPriority canHandle(Map volumeMap, Host srcHost, Host destHost) { if (srcHost.getHypervisorType() == HypervisorType.VMware && destHost.getHypervisorType() == HypervisorType.VMware) { - s_logger.debug(this.getClass() + " can handle the request because the hosts have VMware hypervisor"); + logger.debug(this.getClass() + " can handle the request because the hosts have VMware hypervisor"); return StrategyPriority.HYPERVISOR; } return StrategyPriority.CANT_HANDLE; @@ -230,7 +231,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As , srcData.toString() , destData.toString() ); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } // OfflineVmwareMigration: extract the destination pool from destData and construct a migrateVolume command @@ -300,9 +301,9 @@ private void updateVolumeAfterMigration(Answer answer, DataObject srcData, DataO throw new CloudRuntimeException("unexpected answer from hypervisor agent: " + answer.getDetails()); } MigrateVolumeAnswer ans = (MigrateVolumeAnswer) answer; - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { String format = "retrieved '%s' as new path for volume(%d)"; - s_logger.debug(String.format(format, ans.getVolumePath(), destData.getId())); + logger.debug(String.format(format, ans.getVolumePath(), destData.getId())); } // OfflineVmwareMigration: update the volume with new pool/volume path destinationVO.setPoolId(destData.getDataStore().getId()); @@ -326,7 +327,7 @@ public void copyAsync(Map volumeMap, VirtualMachineTO vmT throw new CloudRuntimeException("Unsupported operation requested for moving data."); } } catch (Exception e) { - s_logger.error("copy failed", e); + logger.error("copy failed", e); errMsg = e.toString(); } @@ -355,20 +356,20 @@ private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachine MigrateWithStorageCommand migrateWithStorageCmd = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid()); MigrateWithStorageAnswer migrateWithStorageAnswer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), migrateWithStorageCmd); if (migrateWithStorageAnswer == null) { - s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed."); + logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed."); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else if (!migrateWithStorageAnswer.getResult()) { - s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + migrateWithStorageAnswer.getDetails()); + logger.error("Migration with storage of vm " + vm + " failed. Details: " + migrateWithStorageAnswer.getDetails()); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + migrateWithStorageAnswer.getDetails()); } else { // Update the volume details after migration. updateVolumesAfterMigration(volumeToPool, migrateWithStorageAnswer.getVolumeTos()); } - s_logger.debug("Storage migration of VM " + vm.getInstanceName() + " completed successfully. Migrated to host " + destHost.getName()); + logger.debug("Storage migration of VM " + vm.getInstanceName() + " completed successfully. Migrated to host " + destHost.getName()); return migrateWithStorageAnswer; } catch (OperationTimedoutException e) { - s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e); + logger.error("Error while migrating vm " + vm + " to host " + destHost, e); throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId()); } } @@ -389,10 +390,10 @@ private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachine MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid()); MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), command); if (answer == null) { - s_logger.error("Migration with storage of vm " + vm + " failed."); + logger.error("Migration with storage of vm " + vm + " failed."); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else if (!answer.getResult()) { - s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails()); + logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails()); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails()); } else { // Update the volume details after migration. @@ -401,7 +402,7 @@ private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachine return answer; } catch (OperationTimedoutException e) { - s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e); + logger.error("Error while migrating vm " + vm + " to host " + destHost, e); throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId()); } } @@ -429,7 +430,7 @@ private void updateVolumesAfterMigration(Map volumeToPool } } if (!updated) { - s_logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated."); + logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated."); } } } diff --git a/plugins/hypervisors/vmware/src/main/resources/META-INF/cloudstack/vmware-compute/spring-vmware-compute-context.xml b/plugins/hypervisors/vmware/src/main/resources/META-INF/cloudstack/vmware-compute/spring-vmware-compute-context.xml index ec1031d18a0b..65a7a4cde1d1 100644 --- a/plugins/hypervisors/vmware/src/main/resources/META-INF/cloudstack/vmware-compute/spring-vmware-compute-context.xml +++ b/plugins/hypervisors/vmware/src/main/resources/META-INF/cloudstack/vmware-compute/spring-vmware-compute-context.xml @@ -41,5 +41,5 @@ - + diff --git a/plugins/hypervisors/vmware/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/hypervisors/vmware/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/hypervisors/vmware/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/hypervisors/xenserver/pom.xml b/plugins/hypervisors/xenserver/pom.xml index 57c4a8d8b35e..ab70f893488c 100644 --- a/plugins/hypervisors/xenserver/pom.xml +++ b/plugins/hypervisors/xenserver/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/ha/XenServerFencer.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/ha/XenServerFencer.java index 72ec375fa271..a29ac2aee76b 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/ha/XenServerFencer.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/ha/XenServerFencer.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -40,7 +39,6 @@ import com.cloud.vm.VirtualMachine; public class XenServerFencer extends AdapterBase implements FenceBuilder { - private static final Logger s_logger = Logger.getLogger(XenServerFencer.class); @Inject HostDao _hostDao; @@ -52,7 +50,7 @@ public class XenServerFencer extends AdapterBase implements FenceBuilder { @Override public Boolean fenceOff(VirtualMachine vm, Host host) { if (host.getHypervisorType() != HypervisorType.XenServer) { - s_logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType()); + logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType()); return null; } @@ -71,18 +69,18 @@ public Boolean fenceOff(VirtualMachine vm, Host host) { try { Answer ans = _agentMgr.send(h.getId(), fence); if (!(ans instanceof FenceAnswer)) { - s_logger.debug("Answer is not fenceanswer. Result = " + ans.getResult() + "; Details = " + ans.getDetails()); + logger.debug("Answer is not fenceanswer. Result = " + ans.getResult() + "; Details = " + ans.getDetails()); continue; } answer = (FenceAnswer)ans; } catch (AgentUnavailableException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); + if (logger.isDebugEnabled()) { + logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); } continue; } catch (OperationTimedoutException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); + if (logger.isDebugEnabled()) { + logger.debug("Moving on to the next host because " + h.toString() + " is unavailable", e); } continue; } @@ -92,8 +90,8 @@ public Boolean fenceOff(VirtualMachine vm, Host host) { } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString()); } return false; diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java index 9de6ba8ab4f7..af10ded2e22f 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/XenServerGuru.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Command; import com.cloud.agent.api.to.DataObjectType; @@ -59,7 +58,6 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable { - private Logger logger = Logger.getLogger(getClass()); @Inject private GuestOSDao guestOsDao; @@ -184,8 +182,8 @@ public Pair getCommandHostDelegation(long hostId, Command cmd) { } // only now can we decide, now we now we're only deciding for ourselves if (cmd instanceof StorageSubSystemCommand) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("XenServer StrorageSubSystemCommand re always executed in sequence (command of type %s to host %l).", cmd.getClass(), hostId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("XenServer StrorageSubSystemCommand re always executed in sequence (command of type %s to host %l).", cmd.getClass(), hostId)); } StorageSubSystemCommand c = (StorageSubSystemCommand)cmd; c.setExecuteInSequence(true); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscoverer.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscoverer.java index 095ba8108417..8a5e59e4373c 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscoverer.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscoverer.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.maven.artifact.versioning.ComparableVersion; import org.apache.xmlrpc.XmlRpcException; @@ -105,7 +104,6 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(XcpServerDiscoverer.class); private int _wait; private XenServerConnectionPool _connPool; private boolean _checkHvm; @@ -171,16 +169,16 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui for(HostPatch patch : patches) { PoolPatch pp = patch.getPoolPatch(conn); if (pp != null && pp.equals(poolPatch) && patch.getApplied(conn)) { - s_logger.debug("host " + hostIp + " does have " + hotFixUuid +" Hotfix."); + logger.debug("host " + hostIp + " does have " + hotFixUuid +" Hotfix."); return true; } } } return false; } catch (UuidInvalid e) { - s_logger.debug("host " + hostIp + " doesn't have " + hotFixUuid + " Hotfix"); + logger.debug("host " + hostIp + " doesn't have " + hotFixUuid + " Hotfix"); } catch (Exception e) { - s_logger.debug("can't get patches information, consider it doesn't have " + hotFixUuid + " Hotfix"); + logger.debug("can't get patches information, consider it doesn't have " + hotFixUuid + " Hotfix"); } return false; } @@ -194,25 +192,25 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui Connection conn = null; if (!url.getScheme().equals("http")) { String msg = "urlString is not http so we're not taking care of the discovery for this: " + url; - s_logger.debug(msg); + logger.debug(msg); return null; } if (clusterId == null) { String msg = "must specify cluster Id when add host"; - s_logger.debug(msg); + logger.debug(msg); throw new RuntimeException(msg); } if (podId == null) { String msg = "must specify pod Id when add host"; - s_logger.debug(msg); + logger.debug(msg); throw new RuntimeException(msg); } ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null || cluster.getHypervisorType() != HypervisorType.XenServer) { - if (s_logger.isInfoEnabled()) { - s_logger.info("invalid cluster id or cluster is not for XenServer hypervisors"); + if (logger.isInfoEnabled()) { + logger.info("invalid cluster id or cluster is not for XenServer hypervisors"); } return null; } @@ -226,7 +224,7 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui conn = _connPool.getConnect(hostIp, username, pass); if (conn == null) { String msg = "Unable to get a connection to " + url; - s_logger.debug(msg); + logger.debug(msg); throw new DiscoveryException(msg); } @@ -252,7 +250,7 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui if (!clu.getGuid().equals(poolUuid)) { String msg = "Please join the host " + hostIp + " to XS pool " + clu.getGuid() + " through XC/XS before adding it through CS UI"; - s_logger.warn(msg); + logger.warn(msg); throw new DiscoveryException(msg); } } else { @@ -264,7 +262,7 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui try { Session.logout(conn); } catch (Exception e) { - s_logger.debug("Caught exception during logout", e); + logger.debug("Caught exception during logout", e); } conn.dispose(); conn = null; @@ -287,7 +285,7 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui if (!support_hvm) { String msg = "Unable to add host " + record.address + " because it doesn't support hvm"; _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, msg, msg); - s_logger.debug(msg); + logger.debug(msg); throw new RuntimeException(msg); } } @@ -308,12 +306,12 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui String hostKernelVer = record.softwareVersion.get("linux"); if (_resourceMgr.findHostByGuid(record.uuid) != null) { - s_logger.debug("Skipping " + record.address + " because " + record.uuid + " is already in the database."); + logger.debug("Skipping " + record.address + " because " + record.uuid + " is already in the database."); continue; } CitrixResourceBase resource = createServerResource(dcId, podId, record, latestHotFix); - s_logger.info("Found host " + record.hostname + " ip=" + record.address + " product version=" + prodVersion); + logger.info("Found host " + record.hostname + " ip=" + record.address + " product version=" + prodVersion); Map details = new HashMap(); Map params = new HashMap(); @@ -348,7 +346,7 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui } DataCenterVO zone = _dcDao.findById(dcId); - boolean securityGroupEnabled = zone.isSecurityGroupEnabled(); + boolean securityGroupEnabled = zone.isSecurityGroupEnabled() || _networkMgr.isSecurityGroupSupportedForZone(zone.getId()); params.put("securitygroupenabled", Boolean.toString(securityGroupEnabled)); params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString())); @@ -364,7 +362,7 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui resource.configure("XenServer", params); } catch (ConfigurationException e) { _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + record.address, "Error is " + e.getMessage()); - s_logger.warn("Unable to instantiate " + record.address, e); + logger.warn("Unable to instantiate " + record.address, e); continue; } resource.start(); @@ -373,16 +371,16 @@ protected boolean poolHasHotFix(Connection conn, String hostIp, String hotFixUui } catch (SessionAuthenticationFailed e) { throw new DiscoveredWithErrorException("Authentication error"); } catch (XenAPIException e) { - s_logger.warn("XenAPI exception", e); + logger.warn("XenAPI exception", e); return null; } catch (XmlRpcException e) { - s_logger.warn("Xml Rpc Exception", e); + logger.warn("Xml Rpc Exception", e); return null; } catch (UnknownHostException e) { - s_logger.warn("Unable to resolve the host name", e); + logger.warn("Unable to resolve the host name", e); return null; } catch (Exception e) { - s_logger.warn("other exceptions: " + e.toString(), e); + logger.warn("other exceptions: " + e.toString(), e); return null; } return resources; @@ -440,7 +438,7 @@ else if (prodBrand.equals("XenServer") && prodVersion.equals("5.6.0")) { final String[] items = prodVersion.split("\\."); if ((Integer.parseInt(items[0]) > 6) || (Integer.parseInt(items[0]) == 6 && Integer.parseInt(items[1]) >= 4)) { - s_logger.warn("defaulting to xenserver650 resource for product brand: " + prodBrand + " with product " + + logger.warn("defaulting to xenserver650 resource for product brand: " + prodBrand + " with product " + "version: " + prodVersion); //default to xenserver650 resource. return new XenServer650Resource(); @@ -449,7 +447,7 @@ else if (prodBrand.equals("XenServer") && prodVersion.equals("5.6.0")) { String msg = "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, XenServer 5.6 FP1, XenServer 5.6 SP2, Xenserver 6.0, 6.0.2, 6.1.0, 6.2.0, >6.4.0, Citrix Hypervisor > 8.0.0 but this one is " + prodBrand + " " + prodVersion; - s_logger.warn(msg); + logger.warn(msg); throw new RuntimeException(msg); } @@ -566,7 +564,7 @@ public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolea StartupRoutingCommand startup = (StartupRoutingCommand)cmd; if (startup.getHypervisorType() != HypervisorType.XenServer) { - s_logger.debug("Not XenServer so moving on."); + logger.debug("Not XenServer so moving on."); return; } @@ -578,7 +576,7 @@ public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolea _clusterDao.update(cluster.getId(), cluster); } else if (!cluster.getGuid().equals(startup.getPool())) { String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool(); - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -592,15 +590,15 @@ public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolea if (!resource.equals(host.getResource())) { String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource; - s_logger.debug(msg); + logger.debug(msg); host.setResource(resource); host.setSetup(false); _hostDao.update(agentId, host); throw new HypervisorVersionChangedException(msg); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Setting up host " + agentId); + if (logger.isDebugEnabled()) { + logger.debug("Setting up host " + agentId); } HostEnvironment env = new HostEnvironment(); @@ -624,12 +622,12 @@ public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolea } return; } else { - s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null")); + logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null")); } } catch (AgentUnavailableException e) { - s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e); + logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e); } catch (OperationTimedoutException e) { - s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e); + logger.warn("Unable to setup agent " + agentId + " because it timed out", e); } throw new ConnectionException(true, "Reinitialize agent after setup."); } @@ -677,7 +675,7 @@ public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] st HostPodVO pod = _podDao.findById(host.getPodId()); DataCenterVO dc = _dcDao.findById(host.getDataCenterId()); - s_logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.XenServer + ". Checking CIDR..."); + logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.XenServer + ". Checking CIDR..."); _resourceMgr.checkCIDR(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPrivateNetmask()); return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.XenServer, details, hostTags); } @@ -697,7 +695,7 @@ protected HashMap buildConfigParams(HostVO host) { HashMap params = super.buildConfigParams(host); DataCenterVO zone = _dcDao.findById(host.getDataCenterId()); if (zone != null) { - boolean securityGroupEnabled = zone.isSecurityGroupEnabled(); + boolean securityGroupEnabled = zone.isSecurityGroupEnabled() || _networkMgr.isSecurityGroupSupportedForZone(zone.getId()); params.put("securitygroupenabled", Boolean.toString(securityGroupEnabled)); } return params; diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index f53a70de7228..e06268cd6ab6 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -71,7 +71,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import org.joda.time.Duration; import org.w3c.dom.Document; @@ -233,7 +232,6 @@ public String toString() { private static final long mem_128m = 134217728L; static final Random Rand = new Random(System.currentTimeMillis()); - private static final Logger s_logger = Logger.getLogger(CitrixResourceBase.class); protected static final HashMap s_powerStatesTable; public static final String XS_TOOLS_ISO_AFTER_70 = "guest-tools.iso"; @@ -366,21 +364,21 @@ public String callHostPlugin(final Connection conn, final String plugin, final S args.put(params[i], params[i + 1]); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); + if (logger.isTraceEnabled()) { + logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); } final Host host = Host.getByUuid(conn, _host.getUuid()); final String result = host.callPlugin(conn, plugin, cmd, args); - if (s_logger.isTraceEnabled()) { - s_logger.trace("callHostPlugin Result: " + result); + if (logger.isTraceEnabled()) { + logger.trace("callHostPlugin Result: " + result); } return result.replace("\n", ""); } catch (final XenAPIException e) { msg = "callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(); - s_logger.warn(msg); + logger.warn(msg); } catch (final XmlRpcException e) { msg = "callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(); - s_logger.debug(msg); + logger.debug(msg); } throw new CloudRuntimeException(msg); } @@ -393,8 +391,8 @@ protected String callHostPluginAsync(final Connection conn, final String plugin, for (final Map.Entry entry : params.entrySet()) { args.put(entry.getKey(), entry.getValue()); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); + if (logger.isTraceEnabled()) { + logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); } final Host host = Host.getByUuid(conn, _host.getUuid()); task = host.callPluginAsync(conn, plugin, cmd, args); @@ -402,20 +400,20 @@ protected String callHostPluginAsync(final Connection conn, final String plugin, waitForTask(conn, task, 1000, timeout); checkForSuccess(conn, task); final String result = task.getResult(conn); - if (s_logger.isTraceEnabled()) { - s_logger.trace("callHostPlugin Result: " + result); + if (logger.isTraceEnabled()) { + logger.trace("callHostPlugin Result: " + result); } return result.replace("", "").replace("", "").replace("\n", ""); } catch (final Types.HandleInvalid e) { - s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle); + logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle); } catch (final Exception e) { - s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e); + logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e); } finally { if (task != null) { try { task.destroy(conn); } catch (final Exception e1) { - s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); + logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); } } } @@ -430,8 +428,8 @@ protected String callHostPluginAsync(final Connection conn, final String plugin, for (int i = 0; i < params.length; i += 2) { args.put(params[i], params[i + 1]); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); + if (logger.isTraceEnabled()) { + logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); } final Host host = Host.getByUuid(conn, _host.getUuid()); task = host.callPluginAsync(conn, plugin, cmd, args); @@ -439,22 +437,22 @@ protected String callHostPluginAsync(final Connection conn, final String plugin, waitForTask(conn, task, 1000, timeout); checkForSuccess(conn, task); final String result = task.getResult(conn); - if (s_logger.isTraceEnabled()) { - s_logger.trace("callHostPlugin Result: " + result); + if (logger.isTraceEnabled()) { + logger.trace("callHostPlugin Result: " + result); } return result.replace("", "").replace("", "").replace("\n", ""); } catch (final Types.HandleInvalid e) { - s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle); + logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle); } catch (final XenAPIException e) { - s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e); + logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e); } catch (final Exception e) { - s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e); + logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e); } finally { if (task != null) { try { task.destroy(conn); } catch (final Exception e1) { - s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); + logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); } } } @@ -478,20 +476,20 @@ protected String callHostPluginThroughMaster(final Connection conn, final String args.put(params[i], params[i + 1]); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); + if (logger.isTraceEnabled()) { + logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args)); } final String result = master.callPlugin(conn, plugin, cmd, args); - if (s_logger.isTraceEnabled()) { - s_logger.trace("callHostPlugin Result: " + result); + if (logger.isTraceEnabled()) { + logger.trace("callHostPlugin Result: " + result); } return result.replace("\n", ""); } catch (final Types.HandleInvalid e) { - s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle); + logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle); } catch (final XenAPIException e) { - s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e); + logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e); } catch (final XmlRpcException e) { - s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e); + logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e); } return null; } @@ -506,13 +504,13 @@ public boolean canBridgeFirewall(final Connection conn) { public void checkForSuccess(final Connection c, final Task task) throws XenAPIException, XmlRpcException { if (task.getStatus(c) == Types.TaskStatusType.SUCCESS) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Task " + task.getNameLabel(c) + " (" + task.getUuid(c) + ") completed"); + if (logger.isTraceEnabled()) { + logger.trace("Task " + task.getNameLabel(c) + " (" + task.getUuid(c) + ") completed"); } return; } else { final String msg = "Task failed! Task record: " + task.getRecord(c); - s_logger.warn(msg); + logger.warn(msg); task.cancel(c); task.destroy(c); throw new Types.BadAsyncResult(msg); @@ -525,11 +523,11 @@ protected boolean checkSR(final Connection conn, final SR sr) { final Set pbds = sr.getPBDs(conn); if (pbds.size() == 0) { final String msg = "There is no PBDs for this SR: " + srr.nameLabel + " on host:" + _host.getUuid(); - s_logger.warn(msg); + logger.warn(msg); return false; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Checking " + srr.nameLabel + " or SR " + srr.uuid + " on " + _host); + if (logger.isDebugEnabled()) { + logger.debug("Checking " + srr.nameLabel + " or SR " + srr.uuid + " on " + _host); } if (srr.shared) { if (SRType.NFS.equals(srr.type)) { @@ -570,7 +568,7 @@ protected boolean checkSR(final Connection conn, final SR sr) { } catch (final Exception e) { final String msg = "checkSR failed host:" + _host + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return false; } return true; @@ -594,7 +592,7 @@ private void CheckXenHostInfo() throws ConfigurationException { } if (!hostRec.address.equals(_host.getIp())) { final String msg = "Host " + _host.getIp() + " seems be reinstalled, please remove this host and readd"; - s_logger.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } } finally { @@ -629,7 +627,7 @@ public boolean cleanupHaltedVms(final Connection conn) throws XenAPIException, X try { vm.destroy(conn); } catch (final Exception e) { - s_logger.warn("Catch Exception " + e.getClass().getName() + ": unable to destroy VM " + vmRec.nameLabel + " due to ", e); + logger.warn("Catch Exception " + e.getClass().getName() + ": unable to destroy VM " + vmRec.nameLabel + " due to ", e); success = false; } } @@ -704,7 +702,7 @@ protected ExecutionResult cleanupNetworkElementCommand(final IpAssocCommand cmd) } } } catch (final Exception e) { - s_logger.debug("Ip Assoc failure on applying one ip due to exception: ", e); + logger.debug("Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.getMessage()); } return new ExecutionResult(true, null); @@ -716,7 +714,7 @@ public void cleanupTemplateSR(final Connection conn) { final Host host = Host.getByUuid(conn, _host.getUuid()); pbds = host.getPBDs(conn); } catch (final XenAPIException e) { - s_logger.warn("Unable to get the SRs " + e.toString(), e); + logger.warn("Unable to get the SRs " + e.toString(), e); throw new CloudRuntimeException("Unable to get SRs " + e.toString(), e); } catch (final Exception e) { throw new CloudRuntimeException("Unable to get SRs " + e.getMessage(), e); @@ -728,7 +726,7 @@ public void cleanupTemplateSR(final Connection conn) { sr = pbd.getSR(conn); srRec = sr.getRecord(conn); } catch (final Exception e) { - s_logger.warn("pbd.getSR get Exception due to ", e); + logger.warn("pbd.getSR get Exception due to ", e); continue; } final String type = srRec.type; @@ -741,7 +739,7 @@ public void cleanupTemplateSR(final Connection conn) { pbd.destroy(conn); sr.forget(conn); } catch (final Exception e) { - s_logger.warn("forget SR catch Exception due to ", e); + logger.warn("forget SR catch Exception due to ", e); } } } @@ -761,12 +759,12 @@ public void cleanUpTmpDomVif(final Connection conn, final Network nw) throws Xen final Map config = vifr.otherConfig; vifName = config.get("nameLabel"); } - s_logger.debug("A VIF in dom0 for the network is found - so destroy the vif"); + logger.debug("A VIF in dom0 for the network is found - so destroy the vif"); v.destroy(conn); - s_logger.debug("Destroy temp dom0 vif" + vifName + " success"); + logger.debug("Destroy temp dom0 vif" + vifName + " success"); } } catch (final Exception e) { - s_logger.warn("Destroy temp dom0 vif " + vifName + "failed", e); + logger.warn("Destroy temp dom0 vif " + vifName + "failed", e); } } } @@ -788,7 +786,7 @@ protected VDI cloudVDIcopy(final Connection conn, final VDI vdi, final SR sr, in try { task.destroy(conn); } catch (final Exception e) { - s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e.toString()); + logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e.toString()); } } } @@ -812,7 +810,7 @@ public HashMap clusterVMMetaDataSync(final Connection conn) { } } catch (final Throwable e) { final String msg = "Unable to get vms through host " + _host.getUuid() + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg); } return vmMetaDatum; @@ -918,7 +916,7 @@ public synchronized Network configureTunnelNetwork(final Connection conn, final } return nw; } catch (final Exception e) { - s_logger.warn("createandConfigureTunnelNetwork failed", e); + logger.warn("createandConfigureTunnelNetwork failed", e); return null; } } @@ -937,16 +935,16 @@ public String connect(final Connection conn, final String vmName, final String i final Set vms = VM.getByNameLabel(conn, vmName); if (vms.size() < 1) { final String msg = "VM " + vmName + " is not running"; - s_logger.warn(msg); + logger.warn(msg); return msg; } } catch (final Exception e) { final String msg = "VM.getByNameLabel " + vmName + " failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return msg; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Trying to connect to " + ipAddress + " attempt " + i + " of " + _retry); + if (logger.isDebugEnabled()) { + logger.debug("Trying to connect to " + ipAddress + " attempt " + i + " of " + _retry); } if (pingdomr(conn, ipAddress, Integer.toString(port))) { return null; @@ -957,7 +955,7 @@ public String connect(final Connection conn, final String vmName, final String i } } final String msg = "Timeout, Unable to logon to " + ipAddress; - s_logger.debug(msg); + logger.debug(msg); return msg; } @@ -981,7 +979,7 @@ public String copyVhdFromSecondaryStorage(final Connection conn, final String mo if (killCopyProcess(conn, source)) { destroyVDIbyNameLabel(conn, nameLabel); } - s_logger.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -990,15 +988,15 @@ public ExecutionResult createFileInVR(final String routerIp, final String path, final Connection conn = getConnection(); final String hostPath = "/tmp/"; - s_logger.debug("Copying VR with ip " + routerIp + " config file into host " + _host.getIp()); + logger.debug("Copying VR with ip " + routerIp + " config file into host " + _host.getIp()); try { SshHelper.scpTo(_host.getIp(), 22, _username, null, _password.peek(), hostPath, content.getBytes(Charset.defaultCharset()), filename, null); } catch (final Exception e) { - s_logger.warn("scp VR config file into host " + _host.getIp() + " failed with exception " + e.getMessage().toString()); + logger.warn("scp VR config file into host " + _host.getIp() + " failed with exception " + e.getMessage().toString()); } final String rc = callHostPlugin(conn, "vmops", "createFileInDomr", "domrip", routerIp, "srcfilepath", hostPath + filename, "dstfilepath", path, "cleanup", "true"); - s_logger.debug("VR Config file " + filename + " got created in VR, IP: " + routerIp + " with content \n" + content); + logger.debug("VR Config file " + filename + " got created in VR, IP: " + routerIp + " with content \n" + content); return new ExecutionResult(rc.startsWith("succ#"), rc.substring(5)); } @@ -1010,12 +1008,12 @@ public ExecutionResult copyPatchFilesToVR(final String routerIp, final String pa for (String file: systemVmPatchFiles) { rc = callHostPlugin(conn, "vmops", "createFileInDomr", "domrip", routerIp, "srcfilepath", hostPath.concat(file), "dstfilepath", path, "cleanup", "false"); if (rc.startsWith("fail#")) { - s_logger.error(String.format("Failed to scp file %s required for patching the systemVM", file)); + logger.error(String.format("Failed to scp file %s required for patching the systemVM", file)); break; } } - s_logger.debug("VR Config files at " + hostPath + " got created in VR, IP: " + routerIp); + logger.debug("VR Config files at " + hostPath + " got created in VR, IP: " + routerIp); return new ExecutionResult(rc.startsWith("succ#"), rc.substring(5)); } @@ -1036,19 +1034,19 @@ protected SR createIsoSRbyURI(final Connection conn, final URI uri, final String return sr; } catch (final XenAPIException e) { final String msg = "createIsoSRbyURI failed! mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } catch (final Exception e) { final String msg = "createIsoSRbyURI failed! mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } } protected SR createNfsSRbyURI(final Connection conn, final URI uri, final boolean shared) { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating a " + (shared ? "shared SR for " : "not shared SR for ") + uri); + if (logger.isDebugEnabled()) { + logger.debug("Creating a " + (shared ? "shared SR for " : "not shared SR for ") + uri); } final Map deviceConfig = new HashMap(); @@ -1075,18 +1073,18 @@ protected SR createNfsSRbyURI(final Connection conn, final URI uri, final boolea if (!checkSR(conn, sr)) { throw new Exception("no attached PBD"); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(logX(sr, "Created a SR; UUID is " + sr.getUuid(conn) + " device config is " + deviceConfig)); + if (logger.isDebugEnabled()) { + logger.debug(logX(sr, "Created a SR; UUID is " + sr.getUuid(conn) + " device config is " + deviceConfig)); } sr.scan(conn); return sr; } catch (final XenAPIException e) { final String msg = "Can not create second storage SR mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } catch (final Exception e) { final String msg = "Can not create second storage SR mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } } @@ -1094,11 +1092,11 @@ protected SR createNfsSRbyURI(final Connection conn, final URI uri, final boolea public SR findPatchIsoSR(final Connection conn) throws XmlRpcException, XenAPIException { Set srs = SR.getByNameLabel(conn, "XenServer Tools"); if (srs.size() != 1) { - s_logger.debug("Failed to find SR by name 'XenServer Tools', will try to find 'XCP-ng Tools' SR"); + logger.debug("Failed to find SR by name 'XenServer Tools', will try to find 'XCP-ng Tools' SR"); srs = SR.getByNameLabel(conn, "XCP-ng Tools"); } if (srs.size() != 1) { - s_logger.debug("Failed to find SR by name 'XenServer Tools' or 'XCP-ng Tools', will try to find 'Citrix Hypervisor' SR"); + logger.debug("Failed to find SR by name 'XenServer Tools' or 'XCP-ng Tools', will try to find 'Citrix Hypervisor' SR"); srs = SR.getByNameLabel(conn, "Citrix Hypervisor Tools"); } if (srs.size() != 1) { @@ -1169,7 +1167,7 @@ String createTemplateFromSnapshot(final Connection conn, final String templatePa } final String source = "cloud_mount/" + tmpltLocalDir; killCopyProcess(conn, source); - s_logger.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -1222,8 +1220,8 @@ public VBD createVbd(final Connection conn, final DiskTO volume, final String vm } final VBD vbd = VBD.create(conn, vbdr); - if (s_logger.isDebugEnabled()) { - s_logger.debug("VBD " + vbd.getUuid(conn) + " created for " + volume); + if (logger.isDebugEnabled()) { + logger.debug("VBD " + vbd.getUuid(conn) + " created for " + volume); } return vbd; @@ -1257,8 +1255,8 @@ public void createVGPU(final Connection conn, final StartCommand cmd, final VM v public VIF createVif(final Connection conn, final String vmName, final VM vm, final VirtualMachineTO vmSpec, final NicTO nic) throws XmlRpcException, XenAPIException { assert nic.getUuid() != null : "Nic should have a uuid value"; - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating VIF for " + vmName + " on nic " + nic); + if (logger.isDebugEnabled()) { + logger.debug("Creating VIF for " + vmName + " on nic " + nic); } VIF.Record vifr = new VIF.Record(); vifr.VM = vm; @@ -1290,10 +1288,10 @@ public VIF createVif(final Connection conn, final String vmName, final VM vm, fi vifr.lockingMode = Types.VifLockingMode.NETWORK_DEFAULT; final VIF vif = VIF.create(conn, vifr); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { vifr = vif.getRecord(conn); if (vifr != null) { - s_logger.debug("Created a vif " + vifr.uuid + " on " + nic.getDeviceId()); + logger.debug("Created a vif " + vifr.uuid + " on " + nic.getDeviceId()); } } @@ -1355,7 +1353,7 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS } else { // scaling disallowed, set static memory target if (vmSpec.isEnableDynamicallyScaleVm() && !isDmcEnabled(conn, host)) { - s_logger.warn("Host " + host.getHostname(conn) + " does not support dynamic scaling, so the vm " + vmSpec.getName() + " is not dynamically scalable"); + logger.warn("Host " + host.getHostname(conn) + " does not support dynamic scaling, so the vm " + vmSpec.getName() + " is not dynamically scalable"); } vmr.memoryStaticMin = vmSpec.getMinRam(); vmr.memoryStaticMax = vmSpec.getMaxRam(); @@ -1381,7 +1379,7 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS } final VM vm = VM.create(conn, vmr); - s_logger.debug("Created VM " + vm.getUuid(conn) + " for " + vmSpec.getName()); + logger.debug("Created VM " + vm.getUuid(conn) + " for " + vmSpec.getName()); final Map vcpuParams = new HashMap(); @@ -1417,14 +1415,14 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS String pvargs = vm.getPVArgs(conn); pvargs = pvargs + vmSpec.getBootArgs().replaceAll(" ", "%"); vm.setPVArgs(conn, pvargs); - s_logger.debug("PV args are " + pvargs); + logger.debug("PV args are " + pvargs); // send boot args into xenstore-data for HVM instances Map xenstoreData = new HashMap<>(); xenstoreData.put(XENSTORE_DATA_CS_INIT, bootArgs); vm.setXenstoreData(conn, xenstoreData); - s_logger.debug("HVM args are " + bootArgs); + logger.debug("HVM args are " + bootArgs); } if (!(guestOsTypeName.startsWith("Windows") || guestOsTypeName.startsWith("Citrix") || guestOsTypeName.startsWith("Other"))) { @@ -1477,7 +1475,7 @@ public VM createWorkingVM(final Connection conn, final String vmName, final Stri final String guestOsTypeName = platformEmulator; if (guestOsTypeName == null) { final String msg = " Hypervisor " + this.getClass().getName() + " doesn't support guest OS type " + guestOSType + ". you can choose 'Other install media' to run it as HVM"; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } final VM template = getVM(conn, guestOsTypeName); @@ -1490,7 +1488,7 @@ public VM createWorkingVM(final Connection conn, final String vmName, final Stri final VDI vdi = VDI.getByUuid(conn, vdiUuid); vdiMap.put(vdi, volume); } catch (final Types.UuidInvalid e) { - s_logger.warn("Unable to find vdi by uuid: " + vdiUuid + ", skip it"); + logger.warn("Unable to find vdi by uuid: " + vdiUuid + ", skip it"); } } for (final Map.Entry entry : vdiMap.entrySet()) { @@ -1553,12 +1551,12 @@ public void destroyPatchVbd(final Connection conn, final Set vms) throws Xml vbd.eject(conn); } } catch (Exception e) { - s_logger.debug("Cannot eject CD-ROM device for VM " + vmName + " due to " + e.toString(), e); + logger.debug("Cannot eject CD-ROM device for VM " + vmName + " due to " + e.toString(), e); } try { vbd.destroy(conn); } catch (Exception e) { - s_logger.debug("Cannot destroy CD-ROM device for VM " + vmName + " due to " + e.toString(), e); + logger.debug("Cannot destroy CD-ROM device for VM " + vmName + " due to " + e.toString(), e); } break; } @@ -1576,7 +1574,7 @@ public synchronized void destroyTunnelNetwork(final Connection conn, final Netwo } return; } catch (final Exception e) { - s_logger.warn("destroyTunnelNetwork failed:", e); + logger.warn("destroyTunnelNetwork failed:", e); return; } } @@ -1585,7 +1583,7 @@ void destroyVDIbyNameLabel(final Connection conn, final String nameLabel) { try { final Set vdis = VDI.getByNameLabel(conn, nameLabel); if (vdis.size() != 1) { - s_logger.warn("destroyVDIbyNameLabel failed due to there are " + vdis.size() + " VDIs with name " + nameLabel); + logger.warn("destroyVDIbyNameLabel failed due to there are " + vdis.size() + " VDIs with name " + nameLabel); return; } for (final VDI vdi : vdis) { @@ -1593,14 +1591,14 @@ void destroyVDIbyNameLabel(final Connection conn, final String nameLabel) { vdi.destroy(conn); } catch (final Exception e) { final String msg = "Failed to destroy VDI : " + nameLabel + "due to " + e.toString() + "\n Force deleting VDI using system 'rm' command"; - s_logger.warn(msg); + logger.warn(msg); try { final String srUUID = vdi.getSR(conn).getUuid(conn); final String vdiUUID = vdi.getUuid(conn); final String vdifile = "/var/run/sr-mount/" + srUUID + "/" + vdiUUID + ".vhd"; callHostPluginAsync(conn, "vmopspremium", "remove_corrupt_vdi", 10, "vdifile", vdifile); } catch (final Exception e2) { - s_logger.warn(e2); + logger.warn(e2); } } } @@ -1629,7 +1627,7 @@ public boolean doPingTest(final Connection conn, final String computingHostIp) { } return true; } catch (final Exception e) { - s_logger.warn("Catch exception " + e.toString(), e); + logger.warn("Catch exception " + e.toString(), e); return false; } finally { sshConnection.close(); @@ -1698,18 +1696,18 @@ protected Network enableVlanNetwork(final Connection conn, final long tag, final final String newName = "VLAN-" + network.getNetworkRecord(conn).uuid + "-" + tag; XsLocalNetwork vlanNic = getNetworkByName(conn, newName); if (vlanNic == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Couldn't find vlan network with the new name so trying old name: " + oldName); + if (logger.isDebugEnabled()) { + logger.debug("Couldn't find vlan network with the new name so trying old name: " + oldName); } vlanNic = getNetworkByName(conn, oldName); if (vlanNic != null) { - s_logger.info("Renaming VLAN with old name " + oldName + " to " + newName); + logger.info("Renaming VLAN with old name " + oldName + " to " + newName); vlanNic.getNetwork().setNameLabel(conn, newName); } } if (vlanNic == null) { // Can't find it, then create it. - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating VLAN network for " + tag + " on host " + _host.getIp()); + if (logger.isDebugEnabled()) { + logger.debug("Creating VLAN network for " + tag + " on host " + _host.getIp()); } final Network.Record nwr = new Network.Record(); nwr.nameLabel = newName; @@ -1732,15 +1730,15 @@ protected Network enableVlanNetwork(final Connection conn, final long tag, final return vlanNetwork; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating VLAN " + tag + " on host " + _host.getIp() + " on device " + nPifr.device); + if (logger.isDebugEnabled()) { + logger.debug("Creating VLAN " + tag + " on host " + _host.getIp() + " on device " + nPifr.device); } final VLAN vlan = VLAN.create(conn, nPif, tag, vlanNetwork); if (vlan != null) { final VLAN.Record vlanr = vlan.getRecord(conn); if (vlanr != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VLAN is created for " + tag + ". The uuid is " + vlanr.uuid); + if (logger.isDebugEnabled()) { + logger.debug("VLAN is created for " + tag + ". The uuid is " + vlanr.uuid); } } } @@ -1778,7 +1776,7 @@ public ExecutionResult executeInVR(final String routerIP, final String script, f // semicolon need to be escape for bash cmdline = cmdline.replaceAll(";", "\\\\;"); try { - s_logger.debug("Executing command in VR: " + cmdline); + logger.debug("Executing command in VR: " + cmdline); result = SshHelper.sshExecute(_host.getIp(), 22, _username, null, _password.peek(), cmdline, VRScripts.CONNECTION_TIMEOUT, VRScripts.CONNECTION_TIMEOUT, timeout); } catch (final Exception e) { return new ExecutionResult(false, e.getMessage()); @@ -1860,8 +1858,8 @@ protected void fillHostInfo(final Connection conn, final StartupRoutingCommand c cmd.setMemory(ram); cmd.setDom0MinMemory(dom0Ram); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Total Ram: " + toHumanReadableSize(ram) + " dom0 Ram: " + toHumanReadableSize(dom0Ram)); + if (logger.isDebugEnabled()) { + logger.debug("Total Ram: " + toHumanReadableSize(ram) + " dom0 Ram: " + toHumanReadableSize(dom0Ram)); } PIF pif = PIF.getByUuid(conn, _host.getPrivatePif()); @@ -1921,7 +1919,7 @@ protected void fillHostInfo(final Connection conn, final StartupRoutingCommand c cmd.setSupportsClonedVolumes(supportsClonedVolumes); } catch (NumberFormatException ex) { - s_logger.warn("Issue sending 'xe sm-list' via SSH to XenServer host: " + ex.getMessage()); + logger.warn("Issue sending 'xe sm-list' via SSH to XenServer host: " + ex.getMessage()); } } catch (final XmlRpcException e) { throw new CloudRuntimeException("XML RPC Exception: " + e.getMessage(), e); @@ -1937,7 +1935,7 @@ protected void syncPlatformAndCoresPerSocketSettings(String coresPerSocket, Map< return; } if (platform.containsKey(PLATFORM_CORES_PER_SOCKET_KEY)) { - s_logger.debug("Updating the cores per socket value from: " + platform.get(PLATFORM_CORES_PER_SOCKET_KEY) + " to " + coresPerSocket); + logger.debug("Updating the cores per socket value from: " + platform.get(PLATFORM_CORES_PER_SOCKET_KEY) + " to " + coresPerSocket); } platform.put(PLATFORM_CORES_PER_SOCKET_KEY, coresPerSocket); } @@ -1978,14 +1976,14 @@ protected void finalizeVmMetaData(final VM vm, final VM.Record vmr, final Connec // Add configuration settings VM record for User VM instances before creating VM Map extraConfig = vmSpec.getExtraConfig(); if (vmSpec.getType().equals(VirtualMachine.Type.User) && MapUtils.isNotEmpty(extraConfig)) { - s_logger.info("Appending user extra configuration settings to VM"); + logger.info("Appending user extra configuration settings [{}] to [{}].", extraConfig, vmSpec); ExtraConfigurationUtility.setExtraConfigurationToVm(conn,vmr, vm, extraConfig); } } protected void setVmBootDetails(final VM vm, final Connection conn, String bootType, String bootMode) throws XenAPIException, XmlRpcException { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Setting boottype=%s and bootmode=%s for VM: %s", bootType, bootMode, vm.getUuid(conn))); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Setting boottype=%s and bootmode=%s for VM: %s", bootType, bootMode, vm.getUuid(conn))); } Boolean isSecure = bootType.equals(ApiConstants.BootType.UEFI.toString()) && ApiConstants.BootMode.SECURE.toString().equals(bootMode); @@ -2021,14 +2019,14 @@ public synchronized Network findOrCreateTunnelNetwork(final Connection conn, fin otherConfig.put("assume_network_is_shared", "true"); rec.otherConfig = otherConfig; nw = Network.create(conn, rec); - s_logger.debug("### XenServer network for tunnels created:" + nwName); + logger.debug("### XenServer network for tunnels created:" + nwName); } else { nw = networks.iterator().next(); - s_logger.debug("XenServer network for tunnels found:" + nwName); + logger.debug("XenServer network for tunnels found:" + nwName); } return nw; } catch (final Exception e) { - s_logger.warn("createTunnelNetwork failed", e); + logger.warn("createTunnelNetwork failed", e); return null; } } @@ -2041,7 +2039,7 @@ void forceShutdownVM(final Connection conn, final VM vm) { vm.destroy(conn); } catch (final Exception e) { final String msg = "forceShutdown failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg); } } @@ -2127,7 +2125,7 @@ public PingCommand getCurrentStatus(final long id) { if (!pingXAPI()) { Thread.sleep(1000); if (!pingXAPI()) { - s_logger.warn("can not ping xenserver " + _host.getUuid()); + logger.warn("can not ping xenserver " + _host.getUuid()); return null; } } @@ -2142,7 +2140,7 @@ public PingCommand getCurrentStatus(final long id) { return new PingRoutingWithNwGroupsCommand(getType(), id, getHostVmStateReport(conn), nwGrpStates); } } catch (final Exception e) { - s_logger.warn("Unable to get current status", e); + logger.warn("Unable to get current status", e); return null; } } @@ -2164,14 +2162,14 @@ protected double getDataAverage(final Node dataNode, final int col, final int nu if (!Double.isInfinite(value) && !Double.isNaN(value)) { return value; } else { - s_logger.warn("Found an invalid value (infinity/NaN) in getDataAverage(), numRows=0"); + logger.warn("Found an invalid value (infinity/NaN) in getDataAverage(), numRows=0"); return dummy; } } else { if (!Double.isInfinite(value / numRowsUsed) && !Double.isNaN(value / numRowsUsed)) { return value / numRowsUsed; } else { - s_logger.warn("Found an invalid value (infinity/NaN) in getDataAverage(), numRows>0"); + logger.warn("Found an invalid value (infinity/NaN) in getDataAverage(), numRows>0"); return dummy; } } @@ -2184,7 +2182,7 @@ public HashMap> getGPUGroupDetails(final protected String getGuestOsType(String platformEmulator) { if (StringUtils.isBlank(platformEmulator)) { - s_logger.debug("no guest OS type, start it as HVM guest"); + logger.debug("no guest OS type, start it as HVM guest"); platformEmulator = "Other install media"; } return platformEmulator; @@ -2242,7 +2240,7 @@ protected boolean getHostInfo(final Connection conn) throws IllegalArgumentExcep if (_guestNetworkName != null && !_guestNetworkName.equals(_privateNetworkName)) { guestNic = getNetworkByName(conn, _guestNetworkName); if (guestNic == null) { - s_logger.warn("Unable to find guest network " + _guestNetworkName); + logger.warn("Unable to find guest network " + _guestNetworkName); throw new IllegalArgumentException("Unable to find guest network " + _guestNetworkName + " for host " + _host.getIp()); } } else { @@ -2256,7 +2254,7 @@ protected boolean getHostInfo(final Connection conn) throws IllegalArgumentExcep if (_publicNetworkName != null && !_publicNetworkName.equals(_guestNetworkName)) { publicNic = getNetworkByName(conn, _publicNetworkName); if (publicNic == null) { - s_logger.warn("Unable to find public network " + _publicNetworkName + " for host " + _host.getIp()); + logger.warn("Unable to find public network " + _publicNetworkName + " for host " + _host.getIp()); throw new IllegalArgumentException("Unable to find public network " + _publicNetworkName + " for host " + _host.getIp()); } } else { @@ -2271,7 +2269,7 @@ protected boolean getHostInfo(final Connection conn) throws IllegalArgumentExcep XsLocalNetwork storageNic1 = null; storageNic1 = getNetworkByName(conn, _storageNetworkName1); if (storageNic1 == null) { - s_logger.warn("Unable to find storage network " + _storageNetworkName1 + " for host " + _host.getIp()); + logger.warn("Unable to find storage network " + _storageNetworkName1 + " for host " + _host.getIp()); throw new IllegalArgumentException("Unable to find storage network " + _storageNetworkName1 + " for host " + _host.getIp()); } else { _host.setStorageNetwork1(storageNic1.getNetworkRecord(conn).uuid); @@ -2286,17 +2284,17 @@ protected boolean getHostInfo(final Connection conn) throws IllegalArgumentExcep } } - s_logger.info("XenServer Version is " + _host.getProductVersion() + " for host " + _host.getIp()); - s_logger.info("Private Network is " + _privateNetworkName + " for host " + _host.getIp()); - s_logger.info("Guest Network is " + _guestNetworkName + " for host " + _host.getIp()); - s_logger.info("Public Network is " + _publicNetworkName + " for host " + _host.getIp()); + logger.info("XenServer Version is " + _host.getProductVersion() + " for host " + _host.getIp()); + logger.info("Private Network is " + _privateNetworkName + " for host " + _host.getIp()); + logger.info("Guest Network is " + _guestNetworkName + " for host " + _host.getIp()); + logger.info("Public Network is " + _publicNetworkName + " for host " + _host.getIp()); return true; } catch (final XenAPIException e) { - s_logger.warn("Unable to get host information for " + _host.getIp(), e); + logger.warn("Unable to get host information for " + _host.getIp(), e); return false; } catch (final Exception e) { - s_logger.warn("Unable to get host information for " + _host.getIp(), e); + logger.warn("Unable to get host information for " + _host.getIp(), e); return false; } } @@ -2365,7 +2363,7 @@ public HostStatsEntry getHostStats(final Connection conn, final GetHostStatsComm /* * if (hostStats.getNumCpus() != 0) { * hostStats.setCpuUtilization(hostStats.getCpuUtilization() / - * hostStats.getNumCpus()); s_logger.debug("Host cpu utilization " + + * hostStats.getNumCpus()); logger.debug("Host cpu utilization " + * hostStats.getCpuUtilization()); } */ @@ -2380,7 +2378,7 @@ protected HashMap getHostVmStateReport(final Con vm_map = VM.getAllRecords(conn); break; } catch (final Throwable e) { - s_logger.warn("Unable to get vms", e); + logger.warn("Unable to get vms", e); } try { Thread.sleep(1000); @@ -2404,11 +2402,11 @@ protected HashMap getHostVmStateReport(final Con try { host_uuid = host.getUuid(conn); } catch (final BadServerResponse e) { - s_logger.error("Failed to get host uuid for host " + host.toWireString(), e); + logger.error("Failed to get host uuid for host " + host.toWireString(), e); } catch (final XenAPIException e) { - s_logger.error("Failed to get host uuid for host " + host.toWireString(), e); + logger.error("Failed to get host uuid for host " + host.toWireString(), e); } catch (final XmlRpcException e) { - s_logger.error("Failed to get host uuid for host " + host.toWireString(), e); + logger.error("Failed to get host uuid for host " + host.toWireString(), e); } if (host_uuid.equalsIgnoreCase(_host.getUuid())) { @@ -2444,7 +2442,7 @@ public SR getIscsiSR(final Connection conn, final String srNameLabel, final Stri final String tmp[] = path.split("/"); if (tmp.length != 3) { final String msg = "Wrong iscsi path " + path + " it should be /targetIQN/LUN"; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } final String targetiqn = tmp[1].trim(); @@ -2498,11 +2496,11 @@ public SR getIscsiSR(final Connection conn, final String srNameLabel, final Stri } catch (final XenAPIException e) { final String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } catch (final Exception e) { final String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } } @@ -2526,7 +2524,7 @@ private SR introduceAndPlugIscsiSr(Connection conn, String pooluuid, String srNa if (setHosts == null) { final String msg = "Unable to create iSCSI SR " + deviceConfig + " due to hosts not available."; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -2640,12 +2638,12 @@ private String probeScisiId(Connection conn, Host host, Map devi } if (!found) { final String msg = "can not find LUN " + lunid + " in " + errmsg; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } } else { final String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } } @@ -2662,14 +2660,14 @@ public SR getISOSRbyVmName(final Connection conn, final String vmName, boolean i return srs.iterator().next(); } else { final String msg = "getIsoSRbyVmName failed due to there are more than 1 SR having same Label"; - s_logger.warn(msg); + logger.warn(msg); } } catch (final XenAPIException e) { final String msg = "getIsoSRbyVmName failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } catch (final Exception e) { final String msg = "getIsoSRbyVmName failed due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); } return null; } @@ -2771,28 +2769,28 @@ public String getLowestAvailableVIFDeviceNum(final Connection conn, final VM vm) if (vm.getIsControlDomain(conn) || vif.getCurrentlyAttached(conn)) { usedDeviceNums.add(Integer.valueOf(deviceId)); } else { - s_logger.debug("Found unplugged VIF " + deviceId + " in VM " + vmName + " destroy it"); + logger.debug("Found unplugged VIF " + deviceId + " in VM " + vmName + " destroy it"); vif.destroy(conn); } } catch (final NumberFormatException e) { final String msg = "Obtained an invalid value for an allocated VIF device number for VM: " + vmName; - s_logger.debug(msg, e); + logger.debug(msg, e); throw new CloudRuntimeException(msg); } } for (Integer i = 0; i < _maxNics; i++) { if (!usedDeviceNums.contains(i)) { - s_logger.debug("Lowest available Vif device number: " + i + " for VM: " + vmName); + logger.debug("Lowest available Vif device number: " + i + " for VM: " + vmName); return i.toString(); } } } catch (final XmlRpcException e) { final String msg = "Caught XmlRpcException: " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); } catch (final XenAPIException e) { final String msg = "Caught XenAPIException: " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } throw new CloudRuntimeException("Could not find available VIF slot in VM with name: " + vmName); @@ -2809,11 +2807,11 @@ protected XsLocalNetwork getManagementNetwork(final Connection conn) throws XmlR if (rec.VLAN != null && rec.VLAN != -1) { final String msg = new StringBuilder("Unsupported configuration. Management network is on a VLAN. host=").append(_host.getUuid()).append("; pif=").append(rec.uuid) .append("; vlan=").append(rec.VLAN).toString(); - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Management network is on pif=" + rec.uuid); + if (logger.isDebugEnabled()) { + logger.debug("Management network is on pif=" + rec.uuid); } mgmtPif = pif; mgmtPifRec = rec; @@ -2822,14 +2820,14 @@ protected XsLocalNetwork getManagementNetwork(final Connection conn) throws XmlR } if (mgmtPif == null) { final String msg = "Unable to find management network for " + _host.getUuid(); - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } final Bond bond = mgmtPifRec.bondSlaveOf; if (!isRefNull(bond)) { final String msg = "Management interface is on slave(" + mgmtPifRec.uuid + ") of bond(" + bond.getUuid(conn) + ") on host(" + _host.getUuid() + "), please move management interface to bond!"; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } final Network nk = mgmtPifRec.network; @@ -2844,8 +2842,8 @@ public String getName() { public XsLocalNetwork getNativeNetworkForTraffic(final Connection conn, final TrafficType type, final String name) throws XenAPIException, XmlRpcException { if (name != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Looking for network named " + name); + if (logger.isDebugEnabled()) { + logger.debug("Looking for network named " + name); } return getNetworkByName(conn, name); } @@ -2874,7 +2872,7 @@ public Network getNetwork(final Connection conn, final NicTO nic) throws XenAPIE final String name = nic.getName(); final XsLocalNetwork network = getNativeNetworkForTraffic(conn, nic.getType(), name); if (network == null) { - s_logger.error("Network is not configured on the backend for nic " + nic.toString()); + logger.error("Network is not configured on the backend for nic " + nic.toString()); throw new CloudRuntimeException("Network for the backend is not configured correctly for network broadcast domain: " + nic.getBroadcastUri()); } final URI uri = nic.getBroadcastUri(); @@ -2965,8 +2963,8 @@ public XsLocalNetwork getNetworkByName(final Connection conn, final String name) return null; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found more than one network with the name " + name); + if (logger.isDebugEnabled()) { + logger.debug("Found more than one network with the name " + name); } Network earliestNetwork = null; Network.Record earliestNetworkRecord = null; @@ -3035,7 +3033,7 @@ public long[] getNetworkLbStats(final String privateIp, final String publicIp, f ExecutionResult callResult = executeInVR(privateIp, "get_haproxy_stats.sh", args); String detail = callResult.getDetails(); if (detail == null || detail.isEmpty()) { - s_logger.error("Get network loadbalancer stats returns empty result"); + logger.error("Get network loadbalancer stats returns empty result"); } final long[] stats = new long[1]; if (detail != null) { @@ -3133,7 +3131,7 @@ public String getPerfMon(final Connection conn, final Map params return result; } } catch (final Exception e) { - s_logger.error("Can not get performance monitor for AS due to ", e); + logger.error("Can not get performance monitor for AS due to ", e); } return null; } @@ -3149,7 +3147,7 @@ protected Object[] getRRDData(final Connection conn, final int flag) { try { doc = getStatsRawXML(conn, flag == 1 ? true : false); } catch (final Exception e1) { - s_logger.warn("Error whilst collecting raw stats from plugin: ", e1); + logger.warn("Error whilst collecting raw stats from plugin: ", e1); return null; } @@ -3208,7 +3206,7 @@ protected SR getSRByNameLabelandHost(final Connection conn, final String name) t private long getStaticMax(final String os, final boolean b, final long dynamicMinRam, final long dynamicMaxRam, final long recommendedValue) { if (recommendedValue == 0) { - s_logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal"); + logger.warn("No recommended value found for dynamic max, setting static max and dynamic max equal"); return dynamicMaxRam; } final long staticMax = Math.min(recommendedValue, 4L * dynamicMinRam); // XS @@ -3217,7 +3215,7 @@ private long getStaticMax(final String os, final boolean b, final long dynamicMi // stability if (dynamicMaxRam > staticMax) { // XS constraint that dynamic max <= // static max - s_logger.warn("dynamic max " + toHumanReadableSize(dynamicMaxRam) + " can't be greater than static max " + toHumanReadableSize(staticMax) + ", this can lead to stability issues. Setting static max as much as dynamic max "); + logger.warn("dynamic max " + toHumanReadableSize(dynamicMaxRam) + " can't be greater than static max " + toHumanReadableSize(staticMax) + ", this can lead to stability issues. Setting static max as much as dynamic max "); return dynamicMaxRam; } return staticMax; @@ -3225,13 +3223,13 @@ private long getStaticMax(final String os, final boolean b, final long dynamicMi private long getStaticMin(final String os, final boolean b, final long dynamicMinRam, final long dynamicMaxRam, final long recommendedValue) { if (recommendedValue == 0) { - s_logger.warn("No recommended value found for dynamic min"); + logger.warn("No recommended value found for dynamic min"); return dynamicMinRam; } if (dynamicMinRam < recommendedValue) { // XS constraint that dynamic min // > static min - s_logger.warn("Vm ram is set to dynamic min " + toHumanReadableSize(dynamicMinRam) + " and is less than the recommended static min " + toHumanReadableSize(recommendedValue) + ", this could lead to stability issues"); + logger.warn("Vm ram is set to dynamic min " + toHumanReadableSize(dynamicMinRam) + " and is less than the recommended static min " + toHumanReadableSize(recommendedValue) + ", this could lead to stability issues"); } return dynamicMinRam; } @@ -3255,23 +3253,23 @@ protected Document getStatsRawXML(final Connection conn, final boolean host) { final InputSource statsSource = new InputSource(in); return ParserUtils.getSaferDocumentBuilderFactory().newDocumentBuilder().parse(statsSource); } catch (final MalformedURLException e) { - s_logger.warn("Malformed URL? come on...." + urlStr); + logger.warn("Malformed URL? come on...." + urlStr); return null; } catch (final IOException e) { - s_logger.warn("Problems getting stats using " + urlStr, e); + logger.warn("Problems getting stats using " + urlStr, e); return null; } catch (final SAXException e) { - s_logger.warn("Problems getting stats using " + urlStr, e); + logger.warn("Problems getting stats using " + urlStr, e); return null; } catch (final ParserConfigurationException e) { - s_logger.warn("Problems getting stats using " + urlStr, e); + logger.warn("Problems getting stats using " + urlStr, e); return null; } finally { if (in != null) { try { in.close(); } catch (final IOException e) { - s_logger.warn("Unable to close the buffer ", e); + logger.warn("Unable to close the buffer ", e); } } } @@ -3291,8 +3289,8 @@ public SR getStorageRepository(final Connection conn, final String srNameLabel) throw new CloudRuntimeException("More than one storage repository was found for pool with uuid: " + srNameLabel); } else if (srs.size() == 1) { final SR sr = srs.iterator().next(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("SR retrieved for " + srNameLabel); + if (logger.isDebugEnabled()) { + logger.debug("SR retrieved for " + srNameLabel); } if (checkSR(conn, sr)) { @@ -3323,15 +3321,15 @@ protected VDI getVDIbyLocationandSR(final Connection conn, final String loc, fin } final String msg = "can not getVDIbyLocationandSR " + loc; - s_logger.warn(msg); + logger.warn(msg); return null; } catch (final XenAPIException e) { final String msg = "getVDIbyLocationandSR exception " + loc + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } catch (final Exception e) { final String msg = "getVDIbyLocationandSR exception " + loc + " due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } @@ -3348,7 +3346,7 @@ public VDI getVDIbyUuid(final Connection conn, final String uuid, final boolean if (throwExceptionIfNotFound) { final String msg = "Catch Exception " + e.getClass().getName() + " :VDI getByUuid for uuid: " + uuid + " failed due to " + e.toString(); - s_logger.debug(msg); + logger.debug(msg); throw new CloudRuntimeException(msg, e); } @@ -3361,7 +3359,7 @@ public String getVhdParent(final Connection conn, final String primaryStorageSRU final String parentUuid = callHostPlugin(conn, "vmopsSnapshot", "getVhdParent", "primaryStorageSRUuid", primaryStorageSRUuid, "snapshotUuid", snapshotUuid, "isISCSI", isISCSI.toString()); if (parentUuid == null || parentUuid.isEmpty() || parentUuid.equalsIgnoreCase("None")) { - s_logger.debug("Unable to get parent of VHD " + snapshotUuid + " in SR " + primaryStorageSRUuid); + logger.debug("Unable to get parent of VHD " + snapshotUuid + " in SR " + primaryStorageSRUuid); // errString is already logged. return null; } @@ -3402,7 +3400,7 @@ public VM getVM(final Connection conn, final String vmName) { // If there is more than one VM, print a warning if (vms.size() > 1) { - s_logger.warn("Found " + vms.size() + " VMs with name: " + vmName); + logger.warn("Found " + vms.size() + " VMs with name: " + vmName); } // Return the first VM in the set @@ -3440,7 +3438,7 @@ public long getVMSnapshotChainSize(final Connection conn, final VolumeObjectTO v } } } catch (final Exception e) { - s_logger.debug("Exception occurs when calculate snapshot capacity for volumes: due to " + e.toString()); + logger.debug("Exception occurs when calculate snapshot capacity for volumes: due to " + e.toString()); continue; } } @@ -3452,23 +3450,23 @@ public long getVMSnapshotChainSize(final Connection conn, final VolumeObjectTO v for (VM vmsnap : vmSnapshots) { try { final String vmSnapName = vmsnap.getNameLabel(conn); - s_logger.debug("snapname " + vmSnapName); + logger.debug("snapname " + vmSnapName); if (vmSnapName != null && vmSnapName.contains(vmSnapshotName) && vmsnap.getIsASnapshot(conn)) { - s_logger.debug("snapname " + vmSnapName + "isASnapshot"); + logger.debug("snapname " + vmSnapName + "isASnapshot"); VDI memoryVDI = vmsnap.getSuspendVDI(conn); if (!isRefNull(memoryVDI)) { size = size + memoryVDI.getPhysicalUtilisation(conn); - s_logger.debug("memoryVDI size :" + toHumanReadableSize(size)); + logger.debug("memoryVDI size :" + toHumanReadableSize(size)); String parentUuid = memoryVDI.getSmConfig(conn).get("vhd-parent"); VDI pMemoryVDI = VDI.getByUuid(conn, parentUuid); if (!isRefNull(pMemoryVDI)) { size = size + pMemoryVDI.getPhysicalUtilisation(conn); } - s_logger.debug("memoryVDI size+parent :" + toHumanReadableSize(size)); + logger.debug("memoryVDI size+parent :" + toHumanReadableSize(size)); } } } catch (Exception e) { - s_logger.debug("Exception occurs when calculate snapshot capacity for memory: due to " + e.toString()); + logger.debug("Exception occurs when calculate snapshot capacity for memory: due to " + e.toString()); continue; } @@ -3501,7 +3499,7 @@ public PowerState getVmState(final Connection conn, final String vmName) { // com.xensource.xenapi.Types$BadServerResponse // [HANDLE_INVALID, VM, // 3dde93f9-c1df-55a7-2cde-55e1dce431ab] - s_logger.info("Unable to get a vm PowerState due to " + e.toString() + ". We are retrying. Count: " + retry); + logger.info("Unable to get a vm PowerState due to " + e.toString() + ". We are retrying. Count: " + retry); try { Thread.sleep(3000); } catch (final InterruptedException ex) { @@ -3509,11 +3507,11 @@ public PowerState getVmState(final Connection conn, final String vmName) { } } catch (final XenAPIException e) { final String msg = "Unable to get a vm PowerState due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); break; } catch (final XmlRpcException e) { final String msg = "Unable to get a vm PowerState due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); break; } } @@ -3598,8 +3596,8 @@ public HashMap getVmStats(final Connection conn, final Get } vmStatsAnswer.setCPUUtilization(vmStatsAnswer.getCPUUtilization() * 100); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Vm cpu utilization " + vmStatsAnswer.getCPUUtilization()); + if (logger.isDebugEnabled()) { + logger.debug("Vm cpu utilization " + vmStatsAnswer.getCPUUtilization()); } } @@ -3614,7 +3612,7 @@ record = vm.getRecord(conn); final Set consoles = record.consoles; if (consoles.isEmpty()) { - s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription); + logger.warn("There are no Consoles available to the vm : " + record.nameDescription); return null; } final Iterator i = consoles.iterator(); @@ -3626,11 +3624,11 @@ record = vm.getRecord(conn); } } catch (final XenAPIException e) { final String msg = "Unable to get console url due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return null; } catch (final XmlRpcException e) { final String msg = "Unable to get console url due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); return null; } return null; @@ -3654,13 +3652,13 @@ protected void destroyUnattachedVBD(Connection conn, VM vm) { } } } catch (final Exception e) { - s_logger.debug("Failed to destroy unattached VBD due to ", e); + logger.debug("Failed to destroy unattached VBD due to ", e); } } public String handleVmStartFailure(final Connection conn, final String vmName, final VM vm, final String message, final Throwable th) { final String msg = "Unable to start " + vmName + " due to " + message; - s_logger.warn(msg, th); + logger.warn(msg, th); if (vm == null) { return msg; @@ -3675,24 +3673,24 @@ public String handleVmStartFailure(final Connection conn, final String vmName, f if (rec != null) { networks.add(rec.network); } else { - s_logger.warn("Unable to cleanup VIF: " + vif.toWireString() + " As vif record is null"); + logger.warn("Unable to cleanup VIF: " + vif.toWireString() + " As vif record is null"); } } catch (final Exception e) { - s_logger.warn("Unable to cleanup VIF", e); + logger.warn("Unable to cleanup VIF", e); } } if (vmr.powerState == VmPowerState.RUNNING) { try { vm.hardShutdown(conn); } catch (final Exception e) { - s_logger.warn("VM hardshutdown failed due to ", e); + logger.warn("VM hardshutdown failed due to ", e); } } if (vm.getPowerState(conn) == VmPowerState.HALTED) { try { vm.destroy(conn); } catch (final Exception e) { - s_logger.warn("VM destroy failed due to ", e); + logger.warn("VM destroy failed due to ", e); } } for (final VBD vbd : vmr.VBDs) { @@ -3700,7 +3698,7 @@ public String handleVmStartFailure(final Connection conn, final String vmName, f vbd.unplug(conn); vbd.destroy(conn); } catch (final Exception e) { - s_logger.warn("Unable to clean up VBD due to ", e); + logger.warn("Unable to clean up VBD due to ", e); } } for (final VIF vif : vmr.VIFs) { @@ -3708,7 +3706,7 @@ public String handleVmStartFailure(final Connection conn, final String vmName, f vif.unplug(conn); vif.destroy(conn); } catch (final Exception e) { - s_logger.warn("Unable to cleanup VIF", e); + logger.warn("Unable to cleanup VIF", e); } } for (final Network network : networks) { @@ -3717,7 +3715,7 @@ public String handleVmStartFailure(final Connection conn, final String vmName, f } } } catch (final Exception e) { - s_logger.warn("VM getRecord failed due to ", e); + logger.warn("VM getRecord failed due to ", e); } return msg; @@ -3727,7 +3725,7 @@ public String handleVmStartFailure(final Connection conn, final String vmName, f public StartupCommand[] initialize() throws IllegalArgumentException { final Connection conn = getConnection(); if (!getHostInfo(conn)) { - s_logger.warn("Unable to get host information for " + _host.getIp()); + logger.warn("Unable to get host information for " + _host.getIp()); return null; } final StartupRoutingCommand cmd = new StartupRoutingCommand(); @@ -3741,13 +3739,13 @@ public StartupCommand[] initialize() throws IllegalArgumentException { final Pool.Record poolr = pool.getRecord(conn); poolr.master.getRecord(conn); } catch (final Throwable e) { - s_logger.warn("Check for master failed, failing the FULL Cluster sync command"); + logger.warn("Check for master failed, failing the FULL Cluster sync command"); } List startUpLocalStorageCommands = null; try { startUpLocalStorageCommands = initializeLocalSrs(conn); } catch (XenAPIException | XmlRpcException e) { - s_logger.warn("Could not initialize local SRs on host: " + _host.getUuid(), e); + logger.warn("Could not initialize local SRs on host: " + _host.getUuid(), e); } if (CollectionUtils.isEmpty(startUpLocalStorageCommands)) { return new StartupCommand[] {cmd}; @@ -3798,17 +3796,17 @@ protected List getAllLocalSrForType(Connection conn, SRType srType) throws X Host host = pbd.getHost(conn); if (!isRefNull(host) && StringUtils.equals(host.getUuid(conn), _host.getUuid())) { if (!pbd.getCurrentlyAttached(conn)) { - s_logger.debug(String.format("PBD [%s] of local SR [%s] was unplugged, pluggin it now", pbd.getUuid(conn), srRec.uuid)); + logger.debug(String.format("PBD [%s] of local SR [%s] was unplugged, pluggin it now", pbd.getUuid(conn), srRec.uuid)); pbd.plug(conn); } - s_logger.debug("Scanning local SR: " + srRec.uuid); + logger.debug("Scanning local SR: " + srRec.uuid); SR sr = entry.getKey(); sr.scan(conn); localSrs.add(sr); } } } - s_logger.debug(String.format("Found %d local storage of type [%s] for host [%s]", localSrs.size(), srType.toString(), _host.getUuid())); + logger.debug(String.format("Found %d local storage of type [%s] for host [%s]", localSrs.size(), srType.toString(), _host.getUuid())); return localSrs; } @@ -3895,10 +3893,10 @@ public boolean isDeviceUsed(final Connection conn, final VM vm, final Long devic return true; } catch (final XmlRpcException e) { msg = "Catch XmlRpcException due to: " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); } catch (final XenAPIException e) { msg = "Catch XenAPIException due to: " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } throw new CloudRuntimeException("When check deviceId " + msg); } @@ -3920,8 +3918,8 @@ public boolean IsISCSI(final String type) { public boolean isNetworkSetupByName(final String nameTag) throws XenAPIException, XmlRpcException { if (nameTag != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Looking for network setup by name " + nameTag); + if (logger.isDebugEnabled()) { + logger.debug("Looking for network setup by name " + nameTag); } final Connection conn = getConnection(); final XsLocalNetwork network = getNetworkByName(conn, nameTag); @@ -3958,7 +3956,7 @@ boolean killCopyProcess(final Connection conn, final String nameLabel) { String errMsg = null; if (results == null || results.equals("false")) { errMsg = "kill_copy_process failed"; - s_logger.warn(errMsg); + logger.warn(errMsg); return false; } else { return true; @@ -3968,7 +3966,7 @@ boolean killCopyProcess(final Connection conn, final String nameLabel) { public boolean launchHeartBeat(final Connection conn) { final String result = callHostPluginPremium(conn, "heartbeat", "host", _host.getUuid(), "timeout", Integer.toString(_heartbeatTimeout), "interval", Integer.toString(_heartbeatInterval)); if (result == null || !result.contains("> DONE <")) { - s_logger.warn("Unable to launch the heartbeat process on " + _host.getIp()); + logger.warn("Unable to launch the heartbeat process on " + _host.getIp()); return false; } return true; @@ -3998,14 +3996,14 @@ public void migrateVM(final Connection conn, final Host destHost, final VM vm, f } } catch (final XenAPIException e) { final String msg = "Unable to migrate VM(" + vmName + ") from host(" + _host.getUuid() + ")"; - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg); } finally { if (task != null) { try { task.destroy(conn); } catch (final Exception e1) { - s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); + logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); } } } @@ -4094,7 +4092,7 @@ private List> ovsFullSyncStates() { for (final String log : logs) { final String[] info = log.split(","); if (info.length != 5) { - s_logger.warn("Wrong element number in ovs log(" + log + ")"); + logger.warn("Wrong element number in ovs log(" + log + ")"); continue; } @@ -4131,11 +4129,11 @@ public HashMap parseDefaultOvsRuleCommand(final String str) { protected Pair parseTimestamp(final String timeStampStr) { final String[] tokens = timeStampStr.split("-"); if (tokens.length != 3) { - s_logger.debug("timeStamp in network has wrong pattern: " + timeStampStr); + logger.debug("timeStamp in network has wrong pattern: " + timeStampStr); return null; } if (!tokens[0].equals("CsCreateTime")) { - s_logger.debug("timeStamp in network doesn't start with CsCreateTime: " + timeStampStr); + logger.debug("timeStamp in network doesn't start with CsCreateTime: " + timeStampStr); return null; } return new Pair(Long.parseLong(tokens[1]), Integer.parseInt(tokens[2])); @@ -4143,13 +4141,13 @@ protected Pair parseTimestamp(final String timeStampStr) { private void pbdPlug(final Connection conn, final PBD pbd, final String uuid) { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Plugging in PBD " + uuid + " for " + _host); + if (logger.isDebugEnabled()) { + logger.debug("Plugging in PBD " + uuid + " for " + _host); } pbd.plug(conn); } catch (final Exception e) { final String msg = "PBD " + uuid + " is not attached! and PBD plug failed due to " + e.toString() + ". Please check this PBD in " + _host; - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg); } } @@ -4171,17 +4169,17 @@ public boolean pingXAPI() { try { final Host host = Host.getByUuid(conn, _host.getUuid()); if (!host.getEnabled(conn)) { - s_logger.debug("Host " + _host.getIp() + " is not enabled!"); + logger.debug("Host " + _host.getIp() + " is not enabled!"); return false; } } catch (final Exception e) { - s_logger.debug("cannot get host enabled status, host " + _host.getIp() + " due to " + e.toString(), e); + logger.debug("cannot get host enabled status, host " + _host.getIp() + " due to " + e.toString(), e); return false; } try { callHostPlugin(conn, "echo", "main"); } catch (final Exception e) { - s_logger.debug("cannot ping host " + _host.getIp() + " due to " + e.toString(), e); + logger.debug("cannot ping host " + _host.getIp() + " due to " + e.toString(), e); return false; } return true; @@ -4212,10 +4210,10 @@ protected boolean postCreatePrivateTemplate(final Connection conn, final String // Else, command threw an exception which has already been logged. if (result.equalsIgnoreCase("1")) { - s_logger.debug("Successfully created template.properties file on secondary storage for " + tmpltFilename); + logger.debug("Successfully created template.properties file on secondary storage for " + tmpltFilename); success = true; } else { - s_logger.warn("Could not create template.properties file on secondary storage for " + tmpltFilename + " for templateId: " + templateId); + logger.warn("Could not create template.properties file on secondary storage for " + tmpltFilename + " for templateId: " + templateId); } } @@ -4344,17 +4342,17 @@ protected VDI prepareManagedStorage(final Connection conn, final Map vdis = sr.getVDIs(conn); @@ -4605,10 +4603,10 @@ protected void skipOrRemoveSR(Connection conn, SR sr) { removeSR(conn, sr); return; } catch (XenAPIException | XmlRpcException e) { - s_logger.warn(logX(sr, "Unable to get current operations " + e.toString()), e); + logger.warn(logX(sr, "Unable to get current operations " + e.toString()), e); } String msg = "Remove SR failed"; - s_logger.warn(msg); + logger.warn(msg); } public void removeSR(final Connection conn, final SR sr) { @@ -4616,8 +4614,8 @@ public void removeSR(final Connection conn, final SR sr) { return; } - if (s_logger.isDebugEnabled()) { - s_logger.debug(logX(sr, "Removing SR")); + if (logger.isDebugEnabled()) { + logger.debug(logX(sr, "Removing SR")); } for (int i = 0; i < 2; i++) { @@ -4629,8 +4627,8 @@ public void removeSR(final Connection conn, final SR sr) { Set pbds = sr.getPBDs(conn); for (final PBD pbd : pbds) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(logX(pbd, "Unplugging pbd")); + if (logger.isDebugEnabled()) { + logger.debug(logX(pbd, "Unplugging pbd")); } // if (pbd.getCurrentlyAttached(conn)) { @@ -4643,8 +4641,8 @@ public void removeSR(final Connection conn, final SR sr) { pbds = sr.getPBDs(conn); if (pbds.size() == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(logX(sr, "Forgetting")); + if (logger.isDebugEnabled()) { + logger.debug(logX(sr, "Forgetting")); } sr.forget(conn); @@ -4652,31 +4650,31 @@ public void removeSR(final Connection conn, final SR sr) { return; } - if (s_logger.isDebugEnabled()) { - s_logger.debug(logX(sr, "There is still one or more PBDs attached.")); + if (logger.isDebugEnabled()) { + logger.debug(logX(sr, "There is still one or more PBDs attached.")); - if (s_logger.isTraceEnabled()) { + if (logger.isTraceEnabled()) { for (final PBD pbd : pbds) { - s_logger.trace(logX(pbd, " Still attached")); + logger.trace(logX(pbd, " Still attached")); } } } } catch (final XenAPIException e) { - s_logger.debug(logX(sr, "Catch XenAPIException: " + e.toString())); + logger.debug(logX(sr, "Catch XenAPIException: " + e.toString())); } catch (final XmlRpcException e) { - s_logger.debug(logX(sr, "Catch Exception: " + e.getMessage())); + logger.debug(logX(sr, "Catch Exception: " + e.getMessage())); } } - s_logger.warn(logX(sr, "Unable to remove SR")); + logger.warn(logX(sr, "Unable to remove SR")); } protected String removeSRSync(final Connection conn, final SR sr) { if (sr == null) { return null; } - if (s_logger.isDebugEnabled()) { - s_logger.debug(logX(sr, "Removing SR")); + if (logger.isDebugEnabled()) { + logger.debug(logX(sr, "Removing SR")); } long waittime = 0; try { @@ -4688,7 +4686,7 @@ protected String removeSRSync(final Connection conn, final SR sr) { } if (waittime >= 1800000) { final String msg = "This template is being used, try late time"; - s_logger.warn(msg); + logger.warn(msg); return msg; } waittime += 30000; @@ -4700,12 +4698,12 @@ protected String removeSRSync(final Connection conn, final SR sr) { removeSR(conn, sr); return null; } catch (final XenAPIException e) { - s_logger.warn(logX(sr, "Unable to get current operations " + e.toString()), e); + logger.warn(logX(sr, "Unable to get current operations " + e.toString()), e); } catch (final XmlRpcException e) { - s_logger.warn(logX(sr, "Unable to get current operations " + e.getMessage()), e); + logger.warn(logX(sr, "Unable to get current operations " + e.getMessage()), e); } final String msg = "Remove SR failed"; - s_logger.warn(msg); + logger.warn(msg); return msg; } @@ -4725,7 +4723,7 @@ public String revertToSnapshot(final Connection conn, final VM vmSnapshot, final errMsg = "revert_memory_snapshot exception"; } } - s_logger.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -4820,7 +4818,7 @@ protected void setNicDevIdIfCorrectVifIsNotNull(final Connection conn, final IpA if (ip.isAdd()) { throw new InternalErrorException("Failed to find DomR VIF to associate IP with."); } else { - s_logger.debug("VIF to deassociate IP with does not exist, return success"); + logger.debug("VIF to deassociate IP with does not exist, return success"); } } else { ip.setNicDevId(Integer.valueOf(correctVif.getDevice(conn))); @@ -4841,8 +4839,8 @@ public String setupHeartbeatSr(final Connection conn, final SR sr, final boolean final Host host = Host.getByUuid(conn, _host.getUuid()); final Set tags = host.getTags(conn); if (force || !tags.contains("cloud-heartbeat-" + srUuid)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Setting up the heartbeat sr for host " + _host.getIp() + " and sr " + srUuid); + if (logger.isDebugEnabled()) { + logger.debug("Setting up the heartbeat sr for host " + _host.getIp() + " and sr " + srUuid); } final Set pbds = sr.getPBDs(conn); for (final PBD pbd : pbds) { @@ -4911,12 +4909,12 @@ public void setupLinkLocalNetwork(final Connection conn) { /* create temp VIF0 */ if (dom0vif == null) { - s_logger.debug("Can't find a vif on dom0 for link local, creating a new one"); + logger.debug("Can't find a vif on dom0 for link local, creating a new one"); final VIF.Record vifr = new VIF.Record(); vifr.VM = dom0; vifr.device = getLowestAvailableVIFDeviceNum(conn, dom0); if (vifr.device == null) { - s_logger.debug("Failed to create link local network, no vif available"); + logger.debug("Failed to create link local network, no vif available"); return; } final Map config = new HashMap(); @@ -4928,7 +4926,7 @@ public void setupLinkLocalNetwork(final Connection conn) { dom0vif = VIF.create(conn, vifr); plugDom0Vif(conn, dom0vif); } else { - s_logger.debug("already have a vif on dom0 for link local network"); + logger.debug("already have a vif on dom0 for link local network"); if (!dom0vif.getCurrentlyAttached(conn)) { plugDom0Vif(conn, dom0vif); } @@ -4939,10 +4937,10 @@ public void setupLinkLocalNetwork(final Connection conn) { _host.setLinkLocalNetwork(linkLocal.getUuid(conn)); } catch (final XenAPIException e) { - s_logger.warn("Unable to create local link network", e); + logger.warn("Unable to create local link network", e); throw new CloudRuntimeException("Unable to create local link network due to " + e.toString(), e); } catch (final XmlRpcException e) { - s_logger.warn("Unable to create local link network", e); + logger.warn("Unable to create local link network", e); throw new CloudRuntimeException("Unable to create local link network due to " + e.toString(), e); } } @@ -4962,7 +4960,7 @@ public boolean setupServer(final Connection conn, final Host host) { final String tag = it.next(); if (tag.startsWith("vmops-version-")) { if (tag.contains(version)) { - s_logger.info(logX(host, "Host " + hr.address + " is already setup.")); + logger.info(logX(host, "Host " + hr.address + " is already setup.")); return false; } else { it.remove(); @@ -5024,22 +5022,22 @@ public boolean setupServer(final Connection conn, final Host host) { } if (!new File(f).exists()) { - s_logger.warn("We cannot locate " + f); + logger.warn("We cannot locate " + f); continue; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Copying " + f + " to " + directoryPath + " on " + hr.address + " with permission " + permissions); + if (logger.isDebugEnabled()) { + logger.debug("Copying " + f + " to " + directoryPath + " on " + hr.address + " with permission " + permissions); } if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "mkdir -m 700 -p " + directoryPath)) { - s_logger.debug("Unable to create destination path: " + directoryPath + " on " + hr.address + "."); + logger.debug("Unable to create destination path: " + directoryPath + " on " + hr.address + "."); } try { scp.put(f, directoryPath, permissions); } catch (final IOException e) { final String msg = "Unable to copy file " + f + " to path " + directoryPath + " with permissions " + permissions; - s_logger.debug(msg); + logger.debug(msg); throw new CloudRuntimeException("Unable to setup the server: " + msg, e); } } @@ -5055,11 +5053,11 @@ public boolean setupServer(final Connection conn, final Host host) { return true; } catch (final XenAPIException e) { final String msg = "XenServer setup failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException("Unable to get host information " + e.toString(), e); } catch (final XmlRpcException e) { final String msg = "XenServer setup failed due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException("Unable to get host information ", e); } } @@ -5083,11 +5081,11 @@ public synchronized Network setupvSwitchNetwork(final Connection conn) { } return _host.getVswitchNetwork(); } catch (final BadServerResponse e) { - s_logger.error("Failed to setup vswitch network", e); + logger.error("Failed to setup vswitch network", e); } catch (final XenAPIException e) { - s_logger.error("Failed to setup vswitch network", e); + logger.error("Failed to setup vswitch network", e); } catch (final XmlRpcException e) { - s_logger.error("Failed to setup vswitch network", e); + logger.error("Failed to setup vswitch network", e); } return null; @@ -5114,14 +5112,14 @@ public void shutdownVM(final Connection conn, final VM vm, final String vmName, throw new CloudRuntimeException("Shutdown VM catch HandleInvalid and VM is not in HALTED state"); } } catch (final XenAPIException e) { - s_logger.debug("Unable to shutdown VM(" + vmName + ") with force=" + forcedStop + " on host(" + _host.getUuid() + ") due to " + e.toString()); + logger.debug("Unable to shutdown VM(" + vmName + ") with force=" + forcedStop + " on host(" + _host.getUuid() + ") due to " + e.toString()); try { VmPowerState state = vm.getPowerState(conn); if (state == VmPowerState.RUNNING) { try { vm.hardShutdown(conn); } catch (final Exception e1) { - s_logger.debug("Unable to hardShutdown VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString()); + logger.debug("Unable to hardShutdown VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString()); state = vm.getPowerState(conn); if (state == VmPowerState.RUNNING) { forceShutdownVM(conn, vm); @@ -5132,12 +5130,12 @@ public void shutdownVM(final Connection conn, final VM vm, final String vmName, return; } else { final String msg = "After cleanShutdown the VM status is " + state.toString() + ", that is not expected"; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } } catch (final Exception e1) { final String msg = "Unable to hardShutdown VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString(); - s_logger.warn(msg, e1); + logger.warn(msg, e1); throw new CloudRuntimeException(msg); } } finally { @@ -5145,7 +5143,7 @@ public void shutdownVM(final Connection conn, final VM vm, final String vmName, try { task.destroy(conn); } catch (final Exception e1) { - s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); + logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); } } } @@ -5166,14 +5164,14 @@ public void startVM(final Connection conn, final Host host, final VM vm, final S checkForSuccess(conn, task); } catch (final Types.HandleInvalid e) { if (vm.getPowerState(conn) == VmPowerState.RUNNING) { - s_logger.debug("VM " + vmName + " is in Running status", e); + logger.debug("VM " + vmName + " is in Running status", e); task = null; return; } throw new CloudRuntimeException("Start VM " + vmName + " catch HandleInvalid and VM is not in RUNNING state"); } catch (final TimeoutException e) { if (vm.getPowerState(conn) == VmPowerState.RUNNING) { - s_logger.debug("VM " + vmName + " is in Running status", e); + logger.debug("VM " + vmName + " is in Running status", e); task = null; return; } @@ -5181,14 +5179,14 @@ public void startVM(final Connection conn, final Host host, final VM vm, final S } } catch (final XenAPIException e) { final String msg = "Unable to start VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg); } finally { if (task != null) { try { task.destroy(conn); } catch (final Exception e1) { - s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); + logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString()); } } } @@ -5203,7 +5201,7 @@ protected void startvmfailhandle(final Connection conn, final VM vm, final List< vm.hardShutdown(conn); } catch (final Exception e) { final String msg = "VM hardshutdown failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } } if (vm.getPowerState(conn) == VmPowerState.HALTED) { @@ -5211,12 +5209,12 @@ protected void startvmfailhandle(final Connection conn, final VM vm, final List< vm.destroy(conn); } catch (final Exception e) { final String msg = "VM destroy failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } } } catch (final Exception e) { final String msg = "VM getPowerState failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } } if (mounts != null) { @@ -5227,7 +5225,7 @@ protected void startvmfailhandle(final Connection conn, final VM vm, final List< vbds = vdi.getVBDs(conn); } catch (final Exception e) { final String msg = "VDI getVBDS failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); continue; } for (final VBD vbd : vbds) { @@ -5236,7 +5234,7 @@ protected void startvmfailhandle(final Connection conn, final VM vm, final List< vbd.destroy(conn); } catch (final Exception e) { final String msg = "VBD destroy failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } } } @@ -5253,7 +5251,7 @@ private HashMap> syncNetworkGroups(final Connection con final HashMap> states = new HashMap>(); final String result = callHostPlugin(conn, "vmops", "get_rule_logs_for_vms", "host_uuid", _host.getUuid()); - s_logger.trace("syncNetworkGroups: id=" + id + " got: " + result); + logger.trace("syncNetworkGroups: id=" + id + " got: " + result); final String[] rulelogs = result != null ? result.split(";") : new String[0]; for (final String rulesforvm : rulelogs) { final String[] log = rulesforvm.split(","); @@ -5284,16 +5282,16 @@ public boolean transferManagementNetwork(final Connection conn, final Host host, } ++count; } catch (final XmlRpcException e) { - s_logger.debug("Waiting for host to come back: " + e.getMessage()); + logger.debug("Waiting for host to come back: " + e.getMessage()); } catch (final XenAPIException e) { - s_logger.debug("Waiting for host to come back: " + e.getMessage()); + logger.debug("Waiting for host to come back: " + e.getMessage()); } catch (final InterruptedException e) { - s_logger.debug("Gotta run"); + logger.debug("Gotta run"); return false; } } if (hostUuid == null) { - s_logger.warn("Unable to transfer the management network from " + spr.uuid); + logger.warn("Unable to transfer the management network from " + spr.uuid); return false; } @@ -5309,7 +5307,7 @@ public void umountSnapshotDir(final Connection conn, final Long dcId) { try { callHostPlugin(conn, "vmopsSnapshot", "unmountSnapshotsDir", "dcId", dcId.toString()); } catch (final Exception e) { - s_logger.debug("Failed to umount snapshot dir", e); + logger.debug("Failed to umount snapshot dir", e); } } @@ -5318,7 +5316,7 @@ public String upgradeSnapshot(final Connection conn, final String templatePath, if (results == null || results.isEmpty()) { final String msg = "upgrade_snapshot return null"; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } final String[] tmp = results.split("#"); @@ -5326,27 +5324,27 @@ public String upgradeSnapshot(final Connection conn, final String templatePath, if (status.equals("0")) { return results; } else { - s_logger.warn(results); + logger.warn(results); throw new CloudRuntimeException(results); } } public void waitForTask(final Connection c, final Task task, final long pollInterval, final long timeout) throws XenAPIException, XmlRpcException, TimeoutException { final long beginTime = System.currentTimeMillis(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Task " + task.getNameLabel(c) + " (" + task.getUuid(c) + ") sent to " + c.getSessionReference() + " is pending completion with a " + timeout + "ms timeout"); + if (logger.isTraceEnabled()) { + logger.trace("Task " + task.getNameLabel(c) + " (" + task.getUuid(c) + ") sent to " + c.getSessionReference() + " is pending completion with a " + timeout + "ms timeout"); } while (task.getStatus(c) == Types.TaskStatusType.PENDING) { try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Task " + task.getNameLabel(c) + " (" + task.getUuid(c) + ") is pending, sleeping for " + pollInterval + "ms"); + if (logger.isTraceEnabled()) { + logger.trace("Task " + task.getNameLabel(c) + " (" + task.getUuid(c) + ") is pending, sleeping for " + pollInterval + "ms"); } Thread.sleep(pollInterval); } catch (final InterruptedException e) { } if (System.currentTimeMillis() - beginTime > timeout) { final String msg = "Async " + timeout / 1000 + " seconds timeout for task " + task.toString(); - s_logger.warn(msg); + logger.warn(msg); task.cancel(c); task.destroy(c); throw new TimeoutException(msg); @@ -5361,14 +5359,14 @@ public boolean createAndAttachConfigDriveIsoForVM(final Connection conn, final V // create SR final SR sr = createLocalIsoSR(conn, _configDriveSRName + _host.getIp()); if (sr == null) { - s_logger.debug("Failed to create local SR for the config drive"); + logger.debug("Failed to create local SR for the config drive"); return false; } - s_logger.debug("Creating vm data files in config drive for vm " + vmName); + logger.debug("Creating vm data files in config drive for vm " + vmName); // 1. create vm data files if (!createVmdataFiles(vmName, vmDataList, configDriveLabel)) { - s_logger.debug("Failed to create vm data files in config drive for vm " + vmName); + logger.debug("Failed to create vm data files in config drive for vm " + vmName); return false; } @@ -5397,9 +5395,9 @@ public boolean createVmdataFiles(final String vmName, final List vmDat try { deleteLocalFolder("/tmp/" + isoPath); } catch (final IOException e) { - s_logger.debug("Failed to delete the exiting config drive for vm " + vmName + " " + e.getMessage()); + logger.debug("Failed to delete the exiting config drive for vm " + vmName + " " + e.getMessage()); } catch (final Exception e) { - s_logger.debug("Failed to delete the exiting config drive for vm " + vmName + " " + e.getMessage()); + logger.debug("Failed to delete the exiting config drive for vm " + vmName + " " + e.getMessage()); } if (vmDataList != null) { @@ -5422,7 +5420,7 @@ public boolean createVmdataFiles(final String vmName, final List vmDat dir.mkdirs(); } } catch (final SecurityException ex) { - s_logger.debug("Failed to create dir " + ex.getMessage()); + logger.debug("Failed to create dir " + ex.getMessage()); return false; } @@ -5431,16 +5429,16 @@ public boolean createVmdataFiles(final String vmName, final List vmDat try (OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(file.getAbsoluteFile()), "UTF-8"); BufferedWriter bw = new BufferedWriter(fw);) { bw.write(content); - s_logger.debug("created file: " + file + " in folder:" + folder); + logger.debug("created file: " + file + " in folder:" + folder); } catch (final IOException ex) { - s_logger.debug("Failed to create file " + ex.getMessage()); + logger.debug("Failed to create file " + ex.getMessage()); return false; } } } } } - s_logger.debug("Created the vm data in " + isoPath); + logger.debug("Created the vm data in " + isoPath); } String s = null; @@ -5455,16 +5453,16 @@ public boolean createVmdataFiles(final String vmName, final List vmDat // read the output from the command while ((s = stdInput.readLine()) != null) { - s_logger.debug(s); + logger.debug(s); } // read any errors from the attempted command while ((s = stdError.readLine()) != null) { - s_logger.debug(s); + logger.debug(s); } - s_logger.debug(" Created config drive ISO using the command " + cmd + " in the host " + _host.getIp()); + logger.debug(" Created config drive ISO using the command " + cmd + " in the host " + _host.getIp()); } catch (final IOException e) { - s_logger.debug(e.getMessage()); + logger.debug(e.getMessage()); return false; } @@ -5483,18 +5481,18 @@ public boolean copyConfigDriveIsoToHost(final Connection conn, final SR sr, fina throw new CloudRuntimeException("Unable to authenticate"); } - s_logger.debug("scp config drive iso file " + vmIso + " to host " + _host.getIp() + " path " + _configDriveIsopath); + logger.debug("scp config drive iso file " + vmIso + " to host " + _host.getIp() + " path " + _configDriveIsopath); final SCPClient scp = new SCPClient(sshConnection); final String p = "0755"; scp.put(vmIso, _configDriveIsopath, p); sr.scan(conn); - s_logger.debug("copied config drive iso to host " + _host); + logger.debug("copied config drive iso to host " + _host); } catch (final IOException e) { - s_logger.debug("failed to copy configdrive iso " + vmIso + " to host " + _host, e); + logger.debug("failed to copy configdrive iso " + vmIso + " to host " + _host, e); return false; } catch (final XmlRpcException e) { - s_logger.debug("Failed to scan config drive iso SR " + _configDriveSRName + _host.getIp() + " in host " + _host, e); + logger.debug("Failed to scan config drive iso SR " + _configDriveSRName + _host.getIp() + " in host " + _host, e); return false; } finally { sshConnection.close(); @@ -5503,9 +5501,9 @@ public boolean copyConfigDriveIsoToHost(final Connection conn, final SR sr, fina final String configDir = "/tmp/" + vmName; try { deleteLocalFolder(configDir); - s_logger.debug("Successfully cleaned up config drive directory " + configDir + " after copying it to host "); + logger.debug("Successfully cleaned up config drive directory " + configDir + " after copying it to host "); } catch (final Exception e) { - s_logger.debug("Failed to delete config drive folder :" + configDir + " for VM " + vmName + " " + e.getMessage()); + logger.debug("Failed to delete config drive folder :" + configDir + " for VM " + vmName + " " + e.getMessage()); } } @@ -5530,10 +5528,10 @@ public boolean attachConfigDriveIsoToVm(final Connection conn, final VM vm) thro srVdi = vdis.iterator().next(); } catch (final XenAPIException e) { - s_logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString()); + logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString()); return false; } catch (final Exception e) { - s_logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString()); + logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString()); return false; } @@ -5565,7 +5563,7 @@ public boolean attachConfigDriveIsoToVm(final Connection conn, final VM vm) thro final VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr); isoVBD = cfgDriveVBD; - s_logger.debug("Created CD-ROM VBD for VM: " + vm); + logger.debug("Created CD-ROM VBD for VM: " + vm); } if (isoVBD != null) { @@ -5577,9 +5575,9 @@ public boolean attachConfigDriveIsoToVm(final Connection conn, final VM vm) thro try { // Insert the new ISO isoVBD.insert(conn, srVdi); - s_logger.debug("Attached config drive iso to vm " + vmName); + logger.debug("Attached config drive iso to vm " + vmName); } catch (final XmlRpcException ex) { - s_logger.debug("Failed to attach config drive iso to vm " + vmName); + logger.debug("Failed to attach config drive iso to vm " + vmName); return false; } } @@ -5593,7 +5591,7 @@ public SR createLocalIsoSR(final Connection conn, final String srName) throws Xe SR sr = getSRByNameLabelandHost(conn, srName); if (sr != null) { - s_logger.debug("Config drive SR already exist, returing it"); + logger.debug("Config drive SR already exist, returing it"); return sr; } @@ -5616,7 +5614,7 @@ public SR createLocalIsoSR(final Connection conn, final String srName) throws Xe } finally { sshConnection.close(); } - s_logger.debug("Created the config drive SR " + srName + " folder path " + _configDriveIsopath); + logger.debug("Created the config drive SR " + srName + " folder path " + _configDriveIsopath); deviceConfig.put("location", _configDriveIsopath); deviceConfig.put("legacy_mode", "true"); @@ -5628,15 +5626,15 @@ public SR createLocalIsoSR(final Connection conn, final String srName) throws Xe sr.setNameDescription(conn, deviceConfig.get("location")); sr.scan(conn); - s_logger.debug("Config drive ISO SR at the path " + _configDriveIsopath + " got created in host " + _host); + logger.debug("Config drive ISO SR at the path " + _configDriveIsopath + " got created in host " + _host); return sr; } catch (final XenAPIException e) { final String msg = "createLocalIsoSR failed! mountpoint " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } catch (final Exception e) { final String msg = "createLocalIsoSR failed! mountpoint: due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } @@ -5645,7 +5643,7 @@ public SR createLocalIsoSR(final Connection conn, final String srName) throws Xe public void deleteLocalFolder(final String directory) throws Exception { if (directory == null || directory.isEmpty()) { final String msg = "Invalid directory path (null/empty) detected. Cannot delete specified directory."; - s_logger.debug(msg); + logger.debug(msg); throw new Exception(msg); } @@ -5680,7 +5678,7 @@ public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, Str // attach the config drive in destination host try { - s_logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr); + logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr); Set vms = VM.getByNameLabel(conn, vmName); SR sr = getSRByNameLabel(conn, vmName + VM_NAME_CONFIGDRIVE_ISO_SUFFIX); @@ -5688,7 +5686,7 @@ public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, Str //one is from source host and second from dest host Set vdis = VDI.getByNameLabel(conn, vmName + VM_FILE_ISO_SUFFIX); if (vdis.isEmpty()) { - s_logger.debug("Could not find config drive ISO: " + vmName); + logger.debug("Could not find config drive ISO: " + vmName); return false; } @@ -5698,16 +5696,16 @@ public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, Str if (vdiSr.getUuid(conn).equals(sr.getUuid(conn))) { //get this vdi to attach to vbd configdriveVdi = vdi; - s_logger.debug("VDI for the config drive ISO " + vdi); + logger.debug("VDI for the config drive ISO " + vdi); } else { // delete the vdi in source host so that the .iso file is get removed - s_logger.debug("Removing the source host VDI for the config drive ISO " + vdi); + logger.debug("Removing the source host VDI for the config drive ISO " + vdi); vdi.destroy(conn); } } if (configdriveVdi == null) { - s_logger.debug("Config drive ISO VDI is not found "); + logger.debug("Config drive ISO VDI is not found "); return false; } @@ -5724,7 +5722,7 @@ public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, Str VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr); - s_logger.debug("Inserting vbd " + configdriveVdi); + logger.debug("Inserting vbd " + configdriveVdi); cfgDriveVBD.insert(conn, configdriveVdi); break; @@ -5733,13 +5731,13 @@ public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, Str return true; } catch (BadServerResponse e) { - s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a bad server response.", e); + logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a bad server response.", e); return false; } catch (XenAPIException e) { - s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a xapi problem.", e); + logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a xapi problem.", e); return false; } catch (XmlRpcException e) { - s_logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a problem in a remote call.", e); + logger.warn("Failed to attach config drive ISO to the VM " + vmName + " In host " + ipAddr + " due to a problem in a remote call.", e); return false; } @@ -5850,7 +5848,7 @@ public Answer copyDiagnosticsFileToSecondaryStorage(Connection conn, CopyToSecon return answer; } catch (Exception e) { String msg = "Exception caught zip file copy to secondary storage URI: " + secondaryStorageUrl + "Exception : " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new CopyToSecondaryStorageAnswer(cmd, false, msg); } finally { if (localDir != null) umountNfs(conn, secondaryStorageMountPath, localDir); @@ -5872,7 +5870,7 @@ private void umountNfs(Connection conn, String remoteDir, String localDir) { String result = callHostPlugin(conn, "cloud-plugin-storage", "umountNfsSecondaryStorage", "localDir", localDir, "remoteDir", remoteDir); if (StringUtils.isBlank(result)) { String errMsg = "Could not umount secondary storage " + remoteDir + " on host " + localDir; - s_logger.warn(errMsg); + logger.warn(errMsg); } } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XcpServerResource.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XcpServerResource.java index 9de2b2996bc8..29312a3d764d 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XcpServerResource.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XcpServerResource.java @@ -17,7 +17,6 @@ package com.cloud.hypervisor.xenserver.resource; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.xensource.xenapi.Connection; @@ -29,7 +28,6 @@ public class XcpServerResource extends CitrixResourceBase { - private final static Logger s_logger = Logger.getLogger(XcpServerResource.class); private final static long mem_32m = 33554432L; @Override @@ -89,8 +87,8 @@ host memory (taking into account various memory overheads). @Override protected void setMemory(final Connection conn, final VM vm, final long minMemsize, final long maxMemsize) throws XmlRpcException, XenAPIException { //setMemoryLimits(staticMin, staticMax, dynamicMin, dynamicMax) - if (s_logger.isDebugEnabled()) { - s_logger.debug("Memory Limits for VM [" + vm.getNameLabel(conn) + "[staticMin:" + toHumanReadableSize(mem_32m) + ", staticMax:" + toHumanReadableSize(maxMemsize) + ", dynamicMin: " + toHumanReadableSize(minMemsize) + + if (logger.isDebugEnabled()) { + logger.debug("Memory Limits for VM [" + vm.getNameLabel(conn) + "[staticMin:" + toHumanReadableSize(mem_32m) + ", staticMax:" + toHumanReadableSize(maxMemsize) + ", dynamicMin: " + toHumanReadableSize(minMemsize) + ", dynamicMax:" + toHumanReadableSize(maxMemsize) + "]]"); } vm.setMemoryLimits(conn, mem_32m, maxMemsize, minMemsize, maxMemsize); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java index 9ae8bcf49c6d..92e812d8d780 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java @@ -17,7 +17,6 @@ package com.cloud.hypervisor.xenserver.resource; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.StartupCommand; import com.cloud.utils.exception.CloudRuntimeException; @@ -30,7 +29,6 @@ import com.xensource.xenapi.VLAN; public class XenServer56Resource extends CitrixResourceBase { - private final static Logger s_logger = Logger.getLogger(XenServer56Resource.class); @Override protected String getPatchFilePath() { @@ -67,7 +65,7 @@ public void disableVlanNetwork(final Connection conn, final Network network, boo host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx"); host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx"); } catch (final XenAPIException e) { - s_logger.trace("Catch " + e.getClass().getName() + ": failed to destroy VLAN " + device + " on host " + _host.getUuid() + " due to " + e.toString()); + logger.trace("Catch " + e.getClass().getName() + ": failed to destroy VLAN " + device + " on host " + _host.getUuid() + " due to " + e.toString()); } } return; @@ -75,10 +73,10 @@ public void disableVlanNetwork(final Connection conn, final Network network, boo } } catch (final XenAPIException e) { final String msg = "Unable to disable VLAN network due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } catch (final Exception e) { final String msg = "Unable to disable VLAN network due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); } } @@ -115,13 +113,13 @@ public Boolean checkHeartbeat(final String hostuuid) { final String shcmd = "/opt/cloud/bin/check_heartbeat.sh " + hostuuid + " " + Integer.toString(_heartbeatInterval * 2); if (!SSHCmdHelper.sshExecuteCmd(sshConnection, shcmd)) { - s_logger.debug("Heart beat is gone so dead."); + logger.debug("Heart beat is gone so dead."); return false; } - s_logger.debug("Heart beat is still going"); + logger.debug("Heart beat is still going"); return true; } catch (final Exception e) { - s_logger.debug("health check failed due to catch exception " + e.toString()); + logger.debug("health check failed due to catch exception " + e.toString()); return null; } finally { sshConnection.close(); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java index 7066d6205df2..77f1e7936f2e 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer610Resource.java @@ -23,7 +23,6 @@ import java.util.Set; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.to.DiskTO; @@ -39,7 +38,6 @@ public class XenServer610Resource extends XenServer600Resource { - private static final Logger s_logger = Logger.getLogger(XenServer610Resource.class); public List getUpdatedVolumePathsOfMigratedVm(final Connection connection, final VM migratedVm, final DiskTO[] volumes) throws CloudRuntimeException { final List volumeToList = new ArrayList(); @@ -69,7 +67,7 @@ public List getUpdatedVolumePathsOfMigratedVm(final Connection c } } } catch (final Exception e) { - s_logger.error("Unable to get the updated VDI paths of the migrated vm " + e.toString(), e); + logger.error("Unable to get the updated VDI paths of the migrated vm " + e.toString(), e); throw new CloudRuntimeException("Unable to get the updated VDI paths of the migrated vm " + e.toString(), e); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer620Resource.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer620Resource.java index affccc695a5a..dd0767aa595c 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer620Resource.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer620Resource.java @@ -19,7 +19,6 @@ import java.util.Set; import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs; -import org.apache.log4j.Logger; import com.cloud.agent.api.StartupRoutingCommand; import com.xensource.xenapi.Connection; @@ -29,7 +28,6 @@ public class XenServer620Resource extends XenServer610Resource { - private static final Logger s_logger = Logger.getLogger(XenServer620Resource.class); protected boolean hostHasHotFix(final Connection conn, final String hotFixUuid) { try { @@ -44,7 +42,7 @@ protected boolean hostHasHotFix(final Connection conn, final String hotFixUuid) } } } catch (final Exception e) { - s_logger.debug("can't get patches information for hotFix: " + hotFixUuid); + logger.debug("can't get patches information for hotFix: " + hotFixUuid); } return false; } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java index 5997b490e588..e9c19b8b9954 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer620SP1Resource.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.Set; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.StartCommand; @@ -42,7 +41,6 @@ public class XenServer620SP1Resource extends XenServer620Resource { - private static final Logger s_logger = Logger.getLogger(XenServer620SP1Resource.class); @Override protected void fillHostInfo(final Connection conn, final StartupRoutingCommand cmd) { @@ -54,8 +52,8 @@ protected void fillHostInfo(final Connection conn, final StartupRoutingCommand c cmd.setHostTags("GPU"); } } catch (final Exception e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Error while getting GPU device info from host " + cmd.getName(), e); + if (logger.isDebugEnabled()) { + logger.debug("Error while getting GPU device info from host " + cmd.getName(), e); } } } @@ -104,8 +102,8 @@ public HashMap> getGPUGroupDetails(final @Override public void createVGPU(final Connection conn, final StartCommand cmd, final VM vm, final GPUDeviceTO gpuDevice) throws XenAPIException, XmlRpcException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating VGPU of VGPU type [ " + gpuDevice.getVgpuType() + " ] in gpu group" + gpuDevice.getGpuGroup() + if (logger.isDebugEnabled()) { + logger.debug("Creating VGPU of VGPU type [ " + gpuDevice.getVgpuType() + " ] in gpu group" + gpuDevice.getGpuGroup() + " for VM " + cmd.getVirtualMachine().getName()); } @@ -126,8 +124,8 @@ public void createVGPU(final Connection conn, final StartCommand cmd, final VM v final Map other_config = new HashMap(); VGPU.create(conn, vm, gpuGroup, device, other_config, vgpuType); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Created VGPU of VGPU type [ " + gpuDevice.getVgpuType() + " ] for VM " + cmd.getVirtualMachine().getName()); + if (logger.isDebugEnabled()) { + logger.debug("Created VGPU of VGPU type [ " + gpuDevice.getVgpuType() + " ] for VM " + cmd.getVirtualMachine().getName()); } // Calculate and set remaining GPU capacity in the host. cmd.getVirtualMachine().getGpuDevice().setGroupDetails(getGPUGroupDetails(conn)); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java index 2f27b1376fdb..87b869ba3c6a 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerConnectionPool.java @@ -29,7 +29,8 @@ import com.xensource.xenapi.Types.XenAPIException; import org.apache.cloudstack.utils.security.SSLUtils; import org.apache.cloudstack.utils.security.SecureSSLSocketFactory; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.XmlRpcClientException; @@ -48,7 +49,7 @@ import java.util.Queue; public class XenServerConnectionPool { - private static final Logger s_logger = Logger.getLogger(XenServerConnectionPool.class); + protected static Logger LOGGER = LogManager.getLogger(XenServerConnectionPool.class); protected HashMap _conns = new HashMap(); protected int _retries; protected int _interval; @@ -57,7 +58,7 @@ public class XenServerConnectionPool { static { File file = PropertiesUtil.findConfigFile("environment.properties"); if (file == null) { - s_logger.debug("Unable to find environment.properties"); + LOGGER.debug("Unable to find environment.properties"); } else { try { final Properties props = PropertiesUtil.loadFromFile(file); @@ -65,11 +66,11 @@ public class XenServerConnectionPool { if (search != null) { s_sleepOnError = NumbersUtil.parseInterval(search, 10) * 1000; } - s_logger.info("XenServer Connection Pool Configs: sleep.interval.on.error=" + s_sleepOnError); + LOGGER.info("XenServer Connection Pool Configs: sleep.interval.on.error=" + s_sleepOnError); } catch (FileNotFoundException e) { - s_logger.debug("File is not found", e); + LOGGER.debug("File is not found", e); } catch (IOException e) { - s_logger.debug("IO Exception while reading file", e); + LOGGER.debug("IO Exception while reading file", e); } } try { @@ -89,7 +90,7 @@ public boolean verify(String hostName, SSLSession session) { } catch (NoSuchAlgorithmException e) { //ignore this } catch (KeyManagementException e) { - s_logger.debug("Init SSLContext failed ", e); + LOGGER.debug("Init SSLContext failed ", e); } } @@ -101,8 +102,8 @@ protected XenServerConnectionPool() { private void addConnect(String poolUuid, XenServerConnection conn) { if (poolUuid == null) return; - if (s_logger.isDebugEnabled()) { - s_logger.debug("Add master connection through " + conn.getIp() + " for pool(" + conn.getPoolUuid() + ")"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Add master connection through " + conn.getIp() + " for pool(" + conn.getPoolUuid() + ")"); } synchronized (_conns) { _conns.put(poolUuid, conn); @@ -126,8 +127,8 @@ private void removeConnect(String poolUuid) { conn = _conns.remove(poolUuid); } if (conn != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Remove master connection through " + conn.getIp() + " for pool(" + conn.getPoolUuid() + ")"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Remove master connection through " + conn.getIp() + " for pool(" + conn.getPoolUuid() + ")"); } } @@ -159,12 +160,12 @@ public Connection getConnect(String ip, String username, Queue password) loginWithPassword(conn, username, password, APIVersion.latest().toString()); } catch (Exception e1) { String msg = "Unable to create master connection to host(" + maddress +") , due to " + e1.toString(); - s_logger.debug(msg); + LOGGER.debug(msg); throw new CloudRuntimeException(msg, e1); } } catch (Exception e) { String msg = "Unable to create master connection to host(" + ip +") , due to " + e.toString(); - s_logger.debug(msg); + LOGGER.debug(msg); throw new CloudRuntimeException(msg, e); } return conn; @@ -175,8 +176,8 @@ public URL getURL(String ip) { return new URL("https://" + ip); } catch (Exception e) { String msg = "Unable to convert IP " + ip + " to URL due to " + e.toString(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(msg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(msg); } throw new CloudRuntimeException(msg, e); } @@ -188,7 +189,7 @@ public Connection connect(String hostUuid, String poolUuid, String ipAddress, if (hostUuid == null || poolUuid == null || ipAddress == null || username == null || password == null) { String msg = "Connect some parameter are null hostUuid:" + hostUuid + " ,poolUuid:" + poolUuid + " ,ipAddress:" + ipAddress; - s_logger.debug(msg); + LOGGER.debug(msg); throw new CloudRuntimeException(msg); } synchronized (poolUuid.intern()) { @@ -198,7 +199,7 @@ public Connection connect(String hostUuid, String poolUuid, String ipAddress, Host host = Host.getByUuid(mConn, hostUuid); if (!host.getEnabled(mConn)) { String msg = "Cannot connect this host " + ipAddress + " due to the host is not enabled"; - s_logger.debug(msg); + LOGGER.debug(msg); if (mConn.getIp().equalsIgnoreCase(ipAddress)) { removeConnect(poolUuid); mConn = null; @@ -209,9 +210,9 @@ public Connection connect(String hostUuid, String poolUuid, String ipAddress, } catch (CloudRuntimeException e) { throw e; } catch (Exception e) { - if (s_logger.isDebugEnabled()) { + if (LOGGER.isDebugEnabled()) { String ip = mConn != null ? mConn.getIp() : null; - s_logger.debug("connect through IP(" + ip + ") for pool(" + poolUuid + ") is broken due to " + e.toString()); + LOGGER.debug("connect through IP(" + ip + ") for pool(" + poolUuid + ") is broken due to " + e.toString()); } removeConnect(poolUuid); mConn = null; @@ -228,13 +229,13 @@ public Connection connect(String hostUuid, String poolUuid, String ipAddress, try{ Session.logout(conn); } catch (Exception e) { - s_logger.debug("Caught exception during logout", e); + LOGGER.debug("Caught exception during logout", e); } conn.dispose(); } if (!hostenabled) { String msg = "Unable to create master connection, due to master Host " + ipAddress + " is not enabled"; - s_logger.debug(msg); + LOGGER.debug(msg); throw new CloudRuntimeException(msg); } mConn = new XenServerConnection(getURL(ipAddress), ipAddress, username, password, _retries, _interval, wait, _connWait); @@ -247,12 +248,12 @@ public Connection connect(String hostUuid, String poolUuid, String ipAddress, Host host = session.getThisHost(mConn); if (!host.getEnabled(mConn)) { String msg = "Unable to create master connection, due to master Host " + maddress + " is not enabled"; - s_logger.debug(msg); + LOGGER.debug(msg); throw new CloudRuntimeException(msg); } } catch (Exception e1) { String msg = "Unable to create master connection to host(" + maddress +") , due to " + e1.toString(); - s_logger.debug(msg); + LOGGER.debug(msg); throw new CloudRuntimeException(msg, e1); } @@ -260,7 +261,7 @@ public Connection connect(String hostUuid, String poolUuid, String ipAddress, throw e; } catch (Exception e) { String msg = "Unable to create master connection to host(" + ipAddress +") , due to " + e.toString(); - s_logger.debug(msg); + LOGGER.debug(msg); throw new CloudRuntimeException(msg, e); } addConnect(poolUuid, mConn); @@ -457,19 +458,19 @@ protected Map dispatch(String methodcall, Object[] methodparams) throws XmlRpcE try { return super.dispatch(methodcall, methodparams); } catch (Types.SessionInvalid e) { - s_logger.debug("Session is invalid for method: " + methodcall + " due to " + e.toString()); + LOGGER.debug("Session is invalid for method: " + methodcall + " due to " + e.toString()); removeConnect(_poolUuid); throw e; } catch (XmlRpcClientException e) { - s_logger.debug("XmlRpcClientException for method: " + methodcall + " due to " + e.toString()); + LOGGER.debug("XmlRpcClientException for method: " + methodcall + " due to " + e.toString()); removeConnect(_poolUuid); throw e; } catch (XmlRpcException e) { - s_logger.debug("XmlRpcException for method: " + methodcall + " due to " + e.toString()); + LOGGER.debug("XmlRpcException for method: " + methodcall + " due to " + e.toString()); removeConnect(_poolUuid); throw e; } catch (Types.HostIsSlave e) { - s_logger.debug("HostIsSlave Exception for method: " + methodcall + " due to " + e.toString()); + LOGGER.debug("HostIsSlave Exception for method: " + methodcall + " due to " + e.toString()); removeConnect(_poolUuid); throw e; } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java index cb226ed7d9bf..4298c9a72189 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServerStorageProcessor.java @@ -56,7 +56,8 @@ import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -89,7 +90,7 @@ import com.xensource.xenapi.VM; public class XenServerStorageProcessor implements StorageProcessor { - private static final Logger s_logger = Logger.getLogger(XenServerStorageProcessor.class); + protected Logger logger = LogManager.getLogger(getClass()); protected CitrixResourceBase hypervisorResource; protected String BaseMountPointOnHost = "/var/run/cloud_mount"; @@ -156,7 +157,7 @@ public SnapshotAndCopyAnswer snapshotAndCopy(final SnapshotAndCopyCommand cmd) { return snapshotAndCopyAnswer; } catch (final Exception ex) { - s_logger.warn("Failed to take and copy snapshot: " + ex.toString(), ex); + logger.warn("Failed to take and copy snapshot: " + ex.toString(), ex); return new SnapshotAndCopyAnswer(ex.getMessage()); } @@ -195,7 +196,7 @@ public ResignatureAnswer resignature(final ResignatureCommand cmd) { return resignatureAnswer; } catch (final Exception ex) { - s_logger.warn("Failed to resignature: " + ex.toString(), ex); + logger.warn("Failed to resignature: " + ex.toString(), ex); return new ResignatureAnswer(ex.getMessage()); } @@ -219,13 +220,13 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) { @Override public Answer checkDataStoreStoragePolicyCompliance(CheckDataStoreStoragePolicyComplainceCommand cmd) { - s_logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for XenServerStorageProcessor"); + logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for XenServerStorageProcessor"); return new Answer(cmd,false,"Not applicable used for XenServerStorageProcessor"); } @Override public Answer syncVolumePath(SyncVolumePathCommand cmd) { - s_logger.info("SyncVolumePathCommand not currently applicable for XenServerStorageProcessor"); + logger.info("SyncVolumePathCommand not currently applicable for XenServerStorageProcessor"); return new Answer(cmd, false, "Not currently applicable for XenServerStorageProcessor"); } @@ -241,7 +242,7 @@ public AttachAnswer attachIso(final AttachCommand cmd) { isoURL = iso.getName(); } else { if (!(store instanceof NfsTO)) { - s_logger.debug("Can't attach a iso which is not created on nfs: "); + logger.debug("Can't attach a iso which is not created on nfs: "); return new AttachAnswer("Can't attach a iso which is not created on nfs: "); } final NfsTO nfsStore = (NfsTO) store; @@ -286,10 +287,10 @@ public AttachAnswer attachIso(final AttachCommand cmd) { return new AttachAnswer(disk); } catch (final XenAPIException e) { - s_logger.warn("Failed to attach iso" + ": " + e.toString(), e); + logger.warn("Failed to attach iso" + ": " + e.toString(), e); return new AttachAnswer(e.toString()); } catch (final Exception e) { - s_logger.warn("Failed to attach iso" + ": " + e.toString(), e); + logger.warn("Failed to attach iso" + ": " + e.toString(), e); return new AttachAnswer(e.toString()); } } @@ -377,7 +378,7 @@ public AttachAnswer attachVolume(final AttachCommand cmd) { } catch (final Exception e) { final String msg = "Failed to attach volume for uuid: " + data.getPath() + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new AttachAnswer(msg); } @@ -395,7 +396,7 @@ public Answer dettachIso(final DettachCommand cmd) { isoURL = iso.getName(); } else { if (!(store instanceof NfsTO)) { - s_logger.debug("Can't detach a iso which is not created on nfs: "); + logger.debug("Can't detach a iso which is not created on nfs: "); return new AttachAnswer("Can't detach a iso which is not created on nfs: "); } final NfsTO nfsStore = (NfsTO) store; @@ -438,11 +439,11 @@ public Answer dettachIso(final DettachCommand cmd) { return new DettachAnswer(disk); } catch (final XenAPIException e) { final String msg = "Failed to detach volume" + " for uuid: " + data.getPath() + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new DettachAnswer(msg); } catch (final Exception e) { final String msg = "Failed to detach volume" + " for uuid: " + data.getPath() + " due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new DettachAnswer(msg); } } @@ -501,7 +502,7 @@ public Answer dettachVolume(final DettachCommand cmd) { return new DettachAnswer(disk); } catch (final Exception e) { - s_logger.warn("Failed dettach volume: " + data.getPath()); + logger.warn("Failed dettach volume: " + data.getPath()); return new DettachAnswer("Failed dettach volume: " + data.getPath() + ", due to " + e.toString()); } } @@ -558,7 +559,7 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { snapshotUUID = preSnapshotUUID; } } catch (final Exception e) { - s_logger.debug("Failed to get parent snapshot", e); + logger.debug("Failed to get parent snapshot", e); } } final SnapshotObjectTO newSnapshot = new SnapshotObjectTO(); @@ -566,10 +567,10 @@ public Answer createSnapshot(final CreateObjectCommand cmd) { return new CreateObjectAnswer(newSnapshot); } catch (final XenAPIException e) { details += ", reason: " + e.toString(); - s_logger.warn(details, e); + logger.warn(details, e); } catch (final Exception e) { details += ", reason: " + e.toString(); - s_logger.warn(details, e); + logger.warn(details, e); } return new CreateObjectAnswer(details); @@ -588,13 +589,13 @@ public Answer deleteVolume(final DeleteCommand cmd) { deleteVDI(conn, vdi); return new Answer(null); } catch (final BadServerResponse e) { - s_logger.debug("Failed to delete volume", e); + logger.debug("Failed to delete volume", e); errorMsg = e.toString(); } catch (final XenAPIException e) { - s_logger.debug("Failed to delete volume", e); + logger.debug("Failed to delete volume", e); errorMsg = e.toString(); } catch (final XmlRpcException e) { - s_logger.debug("Failed to delete volume", e); + logger.debug("Failed to delete volume", e); errorMsg = e.toString(); } return new Answer(null, false, errorMsg); @@ -625,7 +626,7 @@ private String copy_vhd_from_secondarystorage(final Connection conn, final Strin if (hypervisorResource.killCopyProcess(conn, source)) { destroyVDIbyNameLabel(conn, nameLabel); } - s_logger.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -633,7 +634,7 @@ private void destroyVDIbyNameLabel(final Connection conn, final String nameLabel try { final Set vdis = VDI.getByNameLabel(conn, nameLabel); if (vdis.size() != 1) { - s_logger.warn("destroyVDIbyNameLabel failed due to there are " + vdis.size() + " VDIs with name " + nameLabel); + logger.warn("destroyVDIbyNameLabel failed due to there are " + vdis.size() + " VDIs with name " + nameLabel); return; } for (final VDI vdi : vdis) { @@ -651,7 +652,7 @@ protected VDI getVDIbyUuid(final Connection conn, final String uuid) { return VDI.getByUuid(conn, uuid); } catch (final Exception e) { final String msg = "Catch Exception " + e.getClass().getName() + " :VDI getByUuid for uuid: " + uuid + " failed due to " + e.toString(); - s_logger.debug(msg); + logger.debug(msg); throw new CloudRuntimeException(msg, e); } } @@ -662,7 +663,7 @@ protected String getVhdParent(final Connection conn, final String primaryStorage "isISCSI", isISCSI.toString()); if (parentUuid == null || parentUuid.isEmpty() || parentUuid.equalsIgnoreCase("None")) { - s_logger.debug("Unable to get parent of VHD " + snapshotUuid + " in SR " + primaryStorageSRUuid); + logger.debug("Unable to get parent of VHD " + snapshotUuid + " in SR " + primaryStorageSRUuid); // errString is already logged. return null; } @@ -733,7 +734,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { if (srs.size() != 1) { final String msg = "There are " + srs.size() + " SRs with same name: " + srName; - s_logger.warn(msg); + logger.warn(msg); return new CopyCmdAnswer(msg); } else { @@ -785,7 +786,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { } catch (final Exception e) { final String msg = "Catch Exception " + e.getClass().getName() + " for template + " + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new CopyCmdAnswer(msg); } @@ -825,7 +826,7 @@ public Answer createVolume(final CreateObjectCommand cmd) { return new CreateObjectAnswer(newVol); } catch (final Exception e) { - s_logger.debug("create volume failed: " + e.toString()); + logger.debug("create volume failed: " + e.toString()); return new CreateObjectAnswer(e.toString()); } } @@ -844,16 +845,16 @@ public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { vdi = tmpltvdi.createClone(conn, new HashMap()); Long virtualSize = vdi.getVirtualSize(conn); if (volume.getSize() > virtualSize) { - s_logger.debug("Overriding provided template's size with new size " + toHumanReadableSize(volume.getSize()) + " for volume: " + volume.getName()); + logger.debug("Overriding provided template's size with new size " + toHumanReadableSize(volume.getSize()) + " for volume: " + volume.getName()); vdi.resize(conn, volume.getSize()); } else { - s_logger.debug("Using templates disk size of " + toHumanReadableSize(virtualSize) + " for volume: " + volume.getName() + " since size passed was " + toHumanReadableSize(volume.getSize())); + logger.debug("Using templates disk size of " + toHumanReadableSize(virtualSize) + " for volume: " + volume.getName() + " since size passed was " + toHumanReadableSize(volume.getSize())); } vdi.setNameLabel(conn, volume.getName()); VDI.Record vdir; vdir = vdi.getRecord(conn); - s_logger.debug("Successfully created VDI: Uuid = " + vdir.uuid); + logger.debug("Successfully created VDI: Uuid = " + vdir.uuid); final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setName(vdir.nameLabel); @@ -862,7 +863,7 @@ public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (final Exception e) { - s_logger.warn("Unable to create volume; Pool=" + destData + "; Disk: ", e); + logger.warn("Unable to create volume; Pool=" + destData + "; Disk: ", e); return new CopyCmdAnswer(e.toString()); } } @@ -894,12 +895,12 @@ public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (final Exception e) { final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new CopyCmdAnswer(e.toString()); } } - s_logger.debug("unsupported protocol"); + logger.debug("unsupported protocol"); return new CopyCmdAnswer("unsupported protocol"); } @@ -935,7 +936,7 @@ public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) { newVol.setSize(srcVolume.getSize()); return new CopyCmdAnswer(newVol); } catch (final Exception e) { - s_logger.debug("Failed to copy volume to secondary: " + e.toString()); + logger.debug("Failed to copy volume to secondary: " + e.toString()); return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString()); } finally { hypervisorResource.removeSR(conn, secondaryStorage); @@ -953,7 +954,7 @@ private boolean swiftUpload(final Connection conn, final SwiftTO swift, final St String result = hypervisorResource.callHostPluginAsync(conn, "swiftxenserver", "swift", wait, params.toArray(new String[params.size()])); return BooleanUtils.toBoolean(result); } catch (final Exception e) { - s_logger.warn("swift upload failed due to " + e.toString(), e); + logger.warn("swift upload failed due to " + e.toString(), e); } return false; } @@ -1043,7 +1044,7 @@ protected String backupSnapshotToS3(final Connection connection, final S3TO s3, return null; } catch (final Exception e) { - s_logger.error(String.format("S3 upload failed of snapshot %1$s due to %2$s.", snapshotUuid, e.toString()), e); + logger.error(String.format("S3 upload failed of snapshot %1$s due to %2$s.", snapshotUuid, e.toString()), e); } return null; @@ -1089,7 +1090,7 @@ private String backupSnapshot(final Connection conn, final String primaryStorage // So we don't rely on status value but return backupSnapshotUuid as an // indicator of success. if (status != null && status.equalsIgnoreCase("1") && backupSnapshotUuid != null) { - s_logger.debug("Successfully copied backupUuid: " + backupSnapshotUuid + " to secondary storage"); + logger.debug("Successfully copied backupUuid: " + backupSnapshotUuid + " to secondary storage"); return results; } else { errMsg = @@ -1099,7 +1100,7 @@ private String backupSnapshot(final Connection conn, final String primaryStorage } final String source = backupUuid + ".vhd"; hypervisorResource.killCopyProcess(conn, source); - s_logger.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -1122,17 +1123,17 @@ protected boolean destroySnapshotOnPrimaryStorageExceptThis(final Connection con } } catch (final Exception e) { final String msg = "Destroying snapshot: " + snapshot + " on primary storage failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } } - s_logger.debug("Successfully destroyed snapshot on volume: " + volumeUuid + " execept this current snapshot " + avoidSnapshotUuid); + logger.debug("Successfully destroyed snapshot on volume: " + volumeUuid + " execept this current snapshot " + avoidSnapshotUuid); return true; } catch (final XenAPIException e) { final String msg = "Destroying snapshot on volume: " + volumeUuid + " execept this current snapshot " + avoidSnapshotUuid + " failed due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); } catch (final Exception e) { final String msg = "Destroying snapshot on volume: " + volumeUuid + " execept this current snapshot " + avoidSnapshotUuid + " failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } return false; @@ -1143,17 +1144,17 @@ protected boolean destroySnapshotOnPrimaryStorage(final Connection conn, final S final VDI snapshot = getVDIbyUuid(conn, lastSnapshotUuid); if (snapshot == null) { // since this is just used to cleanup leftover bad snapshots, no need to throw exception - s_logger.warn("Could not destroy snapshot " + lastSnapshotUuid + " due to can not find it"); + logger.warn("Could not destroy snapshot " + lastSnapshotUuid + " due to can not find it"); return false; } snapshot.destroy(conn); return true; } catch (final XenAPIException e) { final String msg = "Destroying snapshot: " + lastSnapshotUuid + " failed due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); } catch (final Exception e) { final String msg = "Destroying snapshot: " + lastSnapshotUuid + " failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); } return false; } @@ -1222,7 +1223,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { } } } catch (final Exception e) { - s_logger.debug("Failed to get parent snapshots, take full snapshot", e); + logger.debug("Failed to get parent snapshots, take full snapshot", e); fullbackup = true; } } @@ -1239,7 +1240,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, folder, nfsVersion)) { details = " Filed to create folder " + folder + " in secondary storage"; - s_logger.warn(details); + logger.warn(details); return new CopyCmdAnswer(details); } final String snapshotMountpoint = secondaryStorageUrl + "/" + folder; @@ -1261,7 +1262,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { try { deleteSnapshotBackup(conn, localMountPoint, folder, secondaryStorageMountPath, snapshotBackupUuid); } catch (final Exception e) { - s_logger.debug("Failed to delete snapshot on cache storages", e); + logger.debug("Failed to delete snapshot on cache storages", e); } } @@ -1275,7 +1276,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { try { deleteSnapshotBackup(conn, localMountPoint, folder, secondaryStorageMountPath, snapshotBackupUuid); } catch (final Exception e) { - s_logger.debug("Failed to delete snapshot on cache storages", e); + logger.debug("Failed to delete snapshot on cache storages", e); } } // finalPath = folder + File.separator + snapshotBackupUuid; @@ -1326,17 +1327,17 @@ public Answer backupSnapshot(final CopyCommand cmd) { return new CopyCmdAnswer(newSnapshot); } catch (final XenAPIException e) { details = "BackupSnapshot Failed due to " + e.toString(); - s_logger.warn(details, e); + logger.warn(details, e); } catch (final Exception e) { details = "BackupSnapshot Failed due to " + e.getMessage(); - s_logger.warn(details, e); + logger.warn(details, e); } finally { if (!result) { // remove last bad primary snapshot when exception happens try { destroySnapshotOnPrimaryStorage(conn, snapshotUuid); } catch (final Exception e) { - s_logger.debug("clean up snapshot failed", e); + logger.debug("clean up snapshot failed", e); } } } @@ -1369,7 +1370,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) { installPath = template.getPath(); if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath, nfsVersion)) { details = " Filed to create folder " + installPath + " in secondary storage"; - s_logger.warn(details); + logger.warn(details); return new CopyCmdAnswer(details); } @@ -1417,7 +1418,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) { hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath, nfsVersion); } details = "Creating template from volume " + volumeUUID + " failed due to " + e.toString(); - s_logger.error(details, e); + logger.error(details, e); } return new CopyCmdAnswer(details); } @@ -1443,7 +1444,7 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) { destUri = new URI(destStore.getUrl()); } catch (final Exception ex) { - s_logger.debug("Invalid URI", ex); + logger.debug("Invalid URI", ex); return new CopyCmdAnswer("Invalid URI: " + ex.toString()); } @@ -1472,7 +1473,7 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) { if (!hypervisorResource.createSecondaryStorageFolder(conn, destNfsPath, destDir, destNfsVersion)) { final String details = " Failed to create folder " + destDir + " in secondary storage"; - s_logger.warn(details); + logger.warn(details); return new CopyCmdAnswer(details); } @@ -1523,7 +1524,7 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) { return new CopyCmdAnswer(newTemplate); } catch (final Exception ex) { - s_logger.error("Failed to create a template from a snapshot", ex); + logger.error("Failed to create a template from a snapshot", ex); return new CopyCmdAnswer("Failed to create a template from a snapshot: " + ex.toString()); } finally { @@ -1532,7 +1533,7 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) { try { destVdi.destroy(conn); } catch (final Exception e) { - s_logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e); + logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e); } } } @@ -1648,16 +1649,16 @@ public Answer createVolumeFromSnapshot(final CopyCommand cmd) { } catch (final XenAPIException e) { details = "Exception due to " + e.toString(); - s_logger.warn(details, e); + logger.warn(details, e); } catch (final Exception e) { details = "Exception due to " + e.getMessage(); - s_logger.warn(details, e); + logger.warn(details, e); } if (!result) { // Is this logged at a higher level? - s_logger.error(details); + logger.error(details); } // In all cases return something. @@ -1703,7 +1704,7 @@ Answer createManagedVolumeFromManagedSnapshot(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (final Exception ex) { - s_logger.warn("Failed to copy snapshot to volume: " + ex.toString(), ex); + logger.warn("Failed to copy snapshot to volume: " + ex.toString(), ex); return new CopyCmdAnswer(ex.getMessage()); } @@ -1743,7 +1744,7 @@ Answer createNonManagedVolumeFromManagedSnapshot(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (Exception ex) { - s_logger.warn("Failed to copy snapshot to volume: " + ex.toString(), ex); + logger.warn("Failed to copy snapshot to volume: " + ex.toString(), ex); return new CopyCmdAnswer(ex.getMessage()); } @@ -1768,13 +1769,13 @@ public Answer deleteSnapshot(final DeleteCommand cmd) { try { deleteVDI(conn, snapshotVdi); } catch (final BadServerResponse e) { - s_logger.debug("delete snapshot failed:" + e.toString()); + logger.debug("delete snapshot failed:" + e.toString()); errMsg = e.toString(); } catch (final XenAPIException e) { - s_logger.debug("delete snapshot failed:" + e.toString()); + logger.debug("delete snapshot failed:" + e.toString()); errMsg = e.toString(); } catch (final XmlRpcException e) { - s_logger.debug("delete snapshot failed:" + e.toString()); + logger.debug("delete snapshot failed:" + e.toString()); errMsg = e.toString(); } return new Answer(cmd, false, errMsg); @@ -1791,7 +1792,7 @@ public Answer introduceObject(final IntroduceObjectCmd cmd) { poolSr.scan(conn); return new IntroduceObjectAnswer(cmd.getDataTO()); } catch (final Exception e) { - s_logger.debug("Failed to introduce object", e); + logger.debug("Failed to introduce object", e); return new Answer(cmd, false, e.toString()); } } @@ -1805,7 +1806,7 @@ public Answer forgetObject(final ForgetObjectCmd cmd) { vdi.forget(conn); return new IntroduceObjectAnswer(cmd.getDataTO()); } catch (final Exception e) { - s_logger.debug("Failed to forget object", e); + logger.debug("Failed to forget object", e); return new Answer(cmd, false, e.toString()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625Resource.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625Resource.java index 407beb774ee8..65c9e604100d 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625Resource.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625Resource.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource; import org.apache.cloudstack.hypervisor.xenserver.XenServerResourceNewBase; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.storage.resource.StorageSubsystemCommandHandler; @@ -33,7 +32,6 @@ public class Xenserver625Resource extends XenServerResourceNewBase { - private static final Logger s_logger = Logger.getLogger(Xenserver625Resource.class); @Override protected String getPatchFilePath() { @@ -70,7 +68,7 @@ public boolean setupServer(final Connection conn,final Host host) { SSHCmdHelper.sshExecuteCmd(sshConnection, cmd); } catch (final Exception e) { - s_logger.debug("Catch exception " + e.toString(), e); + logger.debug("Catch exception " + e.toString(), e); } finally { sshConnection.close(); } @@ -96,7 +94,7 @@ public String revertToSnapshot(final Connection conn, final VM vmSnapshot, errMsg = "revert_memory_snapshot exception"; } } - s_logger.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java index 68236f92ac44..773b443a57e8 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java @@ -38,7 +38,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -67,7 +66,6 @@ import static com.cloud.utils.NumbersUtil.toHumanReadableSize; public class Xenserver625StorageProcessor extends XenServerStorageProcessor { - private static final Logger s_logger = Logger.getLogger(XenServerStorageProcessor.class); public Xenserver625StorageProcessor(final CitrixResourceBase resource) { super(resource); @@ -80,7 +78,7 @@ private void mountNfs(Connection conn, String remoteDir, String localDir, String String result = hypervisorResource.callHostPluginAsync(conn, "cloud-plugin-storage", "mountNfsSecondaryStorage", 100 * 1000, "localDir", localDir, "remoteDir", remoteDir, "nfsVersion", nfsVersion); if (StringUtils.isBlank(result)) { String errMsg = "Could not mount secondary storage " + remoteDir + " on host " + localDir; - s_logger.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } } @@ -118,7 +116,7 @@ protected SR createFileSR(Connection conn, String path) { */ protected SR createNewFileSr(Connection conn, String srPath) { String hostUuid = hypervisorResource.getHost().getUuid(); - s_logger.debug(String.format("Creating file SR for path [%s] on host [%s]", srPath, this.hypervisorResource._host.getUuid())); + logger.debug(String.format("Creating file SR for path [%s] on host [%s]", srPath, this.hypervisorResource._host.getUuid())); SR sr = null; PBD pbd = null; try { @@ -143,14 +141,14 @@ protected SR createNewFileSr(Connection conn, String srPath) { Types.InternalError internalErrorException = (Types.InternalError)e; if (StringUtils.contains(internalErrorException.message, expectedDuplicatedFileSrErrorMessage)) { - s_logger.debug(String.format( + logger.debug(String.format( "It seems that we have hit a race condition case here while creating file SR for [%s]. Instead of creating one, we will reuse the one that already exist in the XenServer pool.", srPath)); return retrieveAlreadyConfiguredSrWithoutException(conn, srPath); } } removeSrAndPbdIfPossible(conn, sr, pbd); - s_logger.debug(String.format("Could not create file SR [%s] on host [%s].", srPath, hostUuid), e); + logger.debug(String.format("Could not create file SR [%s] on host [%s].", srPath, hostUuid), e); return null; } } @@ -187,7 +185,7 @@ protected SR retrieveAlreadyConfiguredSrWithoutException(Connection conn, String protected SR retrieveAlreadyConfiguredSr(Connection conn, String path) throws XenAPIException, XmlRpcException { Set srs = SR.getByNameLabel(conn, path); if (CollectionUtils.isEmpty(srs)) { - s_logger.debug("No file SR found for path: " + path); + logger.debug("No file SR found for path: " + path); return null; } if (srs.size() > 1) { @@ -195,19 +193,19 @@ protected SR retrieveAlreadyConfiguredSr(Connection conn, String path) throws Xe } SR sr = srs.iterator().next(); String srUuid = sr.getUuid(conn); - s_logger.debug(String.format("SR [%s] was already introduced in XenServer. Checking if we can reuse it.", srUuid)); + logger.debug(String.format("SR [%s] was already introduced in XenServer. Checking if we can reuse it.", srUuid)); Map currentOperations = sr.getCurrentOperations(conn); if (MapUtils.isEmpty(currentOperations)) { - s_logger.debug(String.format("There are no current operation in SR [%s]. It looks like an unusual condition. We will check if it is usable before returning it.", srUuid)); + logger.debug(String.format("There are no current operation in SR [%s]. It looks like an unusual condition. We will check if it is usable before returning it.", srUuid)); } try { sr.scan(conn); } catch (XenAPIException | XmlRpcException e) { - s_logger.debug(String.format("Problems while checking if cached temporary SR [%s] is working properly (we executed sr-scan). We will not reuse it.", srUuid)); + logger.debug(String.format("Problems while checking if cached temporary SR [%s] is working properly (we executed sr-scan). We will not reuse it.", srUuid)); forgetSr(conn, sr); return null; } - s_logger.debug(String.format("Cached temporary SR [%s] is working properly. We will reuse it.", srUuid)); + logger.debug(String.format("Cached temporary SR [%s] is working properly. We will reuse it.", srUuid)); return sr; } @@ -221,10 +219,10 @@ protected void forgetSr(Connection conn, SR sr) { srUuid = sr.getUuid(conn); Set pbDs = sr.getPBDs(conn); for (PBD pbd : pbDs) { - s_logger.debug(String.format("Unpluging PBD [%s] of SR [%s] as it is not working properly.", pbd.getUuid(conn), srUuid)); + logger.debug(String.format("Unpluging PBD [%s] of SR [%s] as it is not working properly.", pbd.getUuid(conn), srUuid)); unplugPbd(conn, pbd); } - s_logger.debug(String.format("Forgetting SR [%s] as it is not working properly.", srUuid)); + logger.debug(String.format("Forgetting SR [%s] as it is not working properly.", srUuid)); sr.forget(conn); } catch (XenAPIException | XmlRpcException e) { throw new CloudRuntimeException("Exception while forgeting SR: " + srUuid, e); @@ -336,7 +334,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { if (srs.size() != 1) { final String msg = "There are " + srs.size() + " SRs with same name: " + srName; - s_logger.warn(msg); + logger.warn(msg); return new CopyCmdAnswer(msg); } else { @@ -392,7 +390,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { } catch (final Exception e) { final String msg = "Catch Exception " + e.getClass().getName() + " for template due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new CopyCmdAnswer(msg); } finally { @@ -400,7 +398,7 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) { try { task.destroy(conn); } catch (final Exception e) { - s_logger.debug("unable to destroy task (" + task.toWireString() + ") due to " + e.toString()); + logger.debug("unable to destroy task (" + task.toWireString() + ") due to " + e.toString()); } } @@ -454,7 +452,7 @@ protected String backupSnapshot(final Connection conn, final String primaryStora try { task.destroy(conn); } catch (final Exception e) { - s_logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString()); + logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString()); } } } @@ -462,7 +460,7 @@ protected String backupSnapshot(final Connection conn, final String primaryStora return result; } catch (final Exception e) { final String msg = "Exception in backupsnapshot stage due to " + e.toString(); - s_logger.debug(msg); + logger.debug(msg); throw new CloudRuntimeException(msg, e); } finally { try { @@ -470,7 +468,7 @@ protected String backupSnapshot(final Connection conn, final String primaryStora hypervisorResource.removeSR(conn, ssSR); } } catch (final Exception e) { - s_logger.debug("Exception in backupsnapshot cleanup stage due to " + e.toString()); + logger.debug("Exception in backupsnapshot cleanup stage due to " + e.toString()); } } } @@ -481,7 +479,7 @@ protected String getVhdParent(final Connection conn, final String primaryStorage isISCSI.toString()); if (parentUuid == null || parentUuid.isEmpty() || parentUuid.equalsIgnoreCase("None")) { - s_logger.debug("Unable to get parent of VHD " + snapshotUuid + " in SR " + primaryStorageSRUuid); + logger.debug("Unable to get parent of VHD " + snapshotUuid + " in SR " + primaryStorageSRUuid); // errString is already logged. return null; } @@ -575,7 +573,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { final boolean result = makeDirectory(conn, localDir + "/" + folder); if (!result) { details = " Failed to create folder " + folder + " in secondary storage"; - s_logger.warn(details); + logger.warn(details); return new CopyCmdAnswer(details); } @@ -600,7 +598,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { try { deleteSnapshotBackup(conn, localMountPoint, folder, secondaryStorageMountPath, snapshotBackupUuid); } catch (final Exception e) { - s_logger.debug("Failed to delete snapshot on cache storages", e); + logger.debug("Failed to delete snapshot on cache storages", e); } } @@ -614,7 +612,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { try { deleteSnapshotBackup(conn, localMountPoint, folder, secondaryStorageMountPath, snapshotBackupUuid); } catch (final Exception e) { - s_logger.debug("Failed to delete snapshot on cache storages", e); + logger.debug("Failed to delete snapshot on cache storages", e); } } // finalPath = folder + File.separator + @@ -628,7 +626,7 @@ public Answer backupSnapshot(final CopyCommand cmd) { try { task.destroy(conn); } catch (final Exception e) { - s_logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString()); + logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString()); } } if (snapshotSr != null) { @@ -671,14 +669,14 @@ public Answer backupSnapshot(final CopyCommand cmd) { } else { newSnapshot.setParentSnapshotPath(prevBackupUuid); } - s_logger.info("New snapshot details: " + newSnapshot.toString()); - s_logger.info("New snapshot physical utilization: " + toHumanReadableSize(physicalSize)); + logger.info("New snapshot details: " + newSnapshot.toString()); + logger.info("New snapshot physical utilization: " + toHumanReadableSize(physicalSize)); return new CopyCmdAnswer(newSnapshot); } catch (final Exception e) { final String reason = e instanceof Types.XenAPIException ? e.toString() : e.getMessage(); details = "BackupSnapshot Failed due to " + reason; - s_logger.warn(details, e); + logger.warn(details, e); // remove last bad primary snapshot when exception happens destroySnapshotOnPrimaryStorage(conn, snapshotUuid); @@ -713,7 +711,7 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) { installPath = template.getPath(); if (!hypervisorResource.createSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath, nfsVersion)) { details = " Filed to create folder " + installPath + " in secondary storage"; - s_logger.warn(details); + logger.warn(details); return new CopyCmdAnswer(details); } @@ -762,13 +760,13 @@ public Answer createTemplateFromVolume(final CopyCommand cmd) { hypervisorResource.deleteSecondaryStorageFolder(conn, secondaryStorageMountPath, installPath, nfsVersion); } details = "Creating template from volume " + volumeUUID + " failed due to " + e.toString(); - s_logger.error(details, e); + logger.error(details, e); } finally { if (task != null) { try { task.destroy(conn); } catch (final Exception e) { - s_logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString()); + logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString()); } } } @@ -889,10 +887,10 @@ public Answer createVolumeFromSnapshot(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (final Types.XenAPIException e) { details += " due to " + e.toString(); - s_logger.warn(details, e); + logger.warn(details, e); } catch (final Exception e) { details += " due to " + e.getMessage(); - s_logger.warn(details, e); + logger.warn(details, e); } finally { if (srcSr != null) { hypervisorResource.skipOrRemoveSR(conn, srcSr); @@ -906,13 +904,13 @@ public Answer createVolumeFromSnapshot(final CopyCommand cmd) { try { destVdi.destroy(conn); } catch (final Exception e) { - s_logger.debug("destroy dest vdi failed", e); + logger.debug("destroy dest vdi failed", e); } } } if (!result) { // Is this logged at a higher level? - s_logger.error(details); + logger.error(details); } // In all cases return something. @@ -921,13 +919,13 @@ public Answer createVolumeFromSnapshot(final CopyCommand cmd) { @Override public Answer checkDataStoreStoragePolicyCompliance(CheckDataStoreStoragePolicyComplainceCommand cmd) { - s_logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for XenServerStorageProcessor"); + logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not applicable used for XenServerStorageProcessor"); return new Answer(cmd,false,"Not applicable used for XenServerStorageProcessor"); } @Override public Answer syncVolumePath(SyncVolumePathCommand cmd) { - s_logger.info("SyncVolumePathCommand not currently applicable for XenServerStorageProcessor"); + logger.info("SyncVolumePathCommand not currently applicable for XenServerStorageProcessor"); return new Answer(cmd, false, "Not currently applicable for XenServerStorageProcessor"); } @@ -968,14 +966,14 @@ public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) { newVol.setSize(srcVolume.getSize()); return new CopyCmdAnswer(newVol); } catch (final Exception e) { - s_logger.debug("Failed to copy volume to secondary: " + e.toString()); + logger.debug("Failed to copy volume to secondary: " + e.toString()); return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString()); } finally { if (task != null) { try { task.destroy(conn); } catch (final Exception e) { - s_logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString()); + logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString()); } } hypervisorResource.removeSR(conn, secondaryStorage); @@ -1031,14 +1029,14 @@ public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { return new CopyCmdAnswer(newVol); } catch (final Exception e) { final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new CopyCmdAnswer(e.toString()); } finally { if (task != null) { try { task.destroy(conn); } catch (final Exception e) { - s_logger.warn("unable to destroy task(" + task.toString() + ") due to " + e.toString()); + logger.warn("unable to destroy task(" + task.toString() + ") due to " + e.toString()); } } if (srcSr != null) { @@ -1047,7 +1045,7 @@ public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { } } - s_logger.debug("unsupported protocol"); + logger.debug("unsupported protocol"); return new CopyCmdAnswer("unsupported protocol"); } @@ -1077,7 +1075,7 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) { srcUri = new URI(srcStore.getUrl()); destUri = new URI(destStore.getUrl()); } catch (final Exception e) { - s_logger.debug("incorrect url", e); + logger.debug("incorrect url", e); return new CopyCmdAnswer("incorrect url" + e.toString()); } @@ -1174,7 +1172,7 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) { return new CopyCmdAnswer(newTemplate); } catch (final Exception e) { - s_logger.error("Failed create template from snapshot", e); + logger.error("Failed create template from snapshot", e); return new CopyCmdAnswer("Failed create template from snapshot " + e.toString()); } finally { @@ -1183,7 +1181,7 @@ public Answer createTemplateFromSnapshot(final CopyCommand cmd) { try { destVdi.destroy(conn); } catch (final Exception e) { - s_logger.debug("Clean up left over on dest storage failed: ", e); + logger.debug("Clean up left over on dest storage failed: ", e); } } } @@ -1215,7 +1213,7 @@ private Answer createTemplateFromSnapshot2(final CopyCommand cmd) { destStore = (NfsTO)templateObjTO.getDataStore(); destUri = new URI(destStore.getUrl()); } catch (final Exception ex) { - s_logger.debug("Invalid URI", ex); + logger.debug("Invalid URI", ex); return new CopyCmdAnswer("Invalid URI: " + ex.toString()); } @@ -1291,15 +1289,15 @@ private Answer createTemplateFromSnapshot2(final CopyCommand cmd) { return new CopyCmdAnswer(newTemplate); } catch (final BadServerResponse e) { - s_logger.error("Failed to create a template from a snapshot due to incomprehensible server response", e); + logger.error("Failed to create a template from a snapshot due to incomprehensible server response", e); return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString()); } catch (final XenAPIException e) { - s_logger.error("Failed to create a template from a snapshot due to xenapi error", e); + logger.error("Failed to create a template from a snapshot due to xenapi error", e); return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString()); } catch (final XmlRpcException e) { - s_logger.error("Failed to create a template from a snapshot due to rpc error", e); + logger.error("Failed to create a template from a snapshot due to rpc error", e); return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString()); } finally { @@ -1308,7 +1306,7 @@ private Answer createTemplateFromSnapshot2(final CopyCommand cmd) { try { destVdi.destroy(conn); } catch (final Exception e) { - s_logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e); + logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e); } } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XsLocalNetwork.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XsLocalNetwork.java index e03a5895a5b4..c8ec2b106ab8 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XsLocalNetwork.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XsLocalNetwork.java @@ -16,7 +16,8 @@ // under the License. package com.cloud.hypervisor.xenserver.resource; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import com.xensource.xenapi.Connection; @@ -29,7 +30,7 @@ */ public class XsLocalNetwork { - private static final Logger s_logger = Logger.getLogger(XsLocalNetwork.class); + protected Logger logger = LogManager.getLogger(getClass()); private final CitrixResourceBase _citrixResourceBase; private final Network _n; @@ -67,8 +68,8 @@ public PIF getPif(final Connection conn) throws XenAPIException, XmlRpcException for (final PIF pif : nr.PIFs) { final PIF.Record pr = pif.getRecord(conn); if (_citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found a network called " + nr.nameLabel + " on host=" + _citrixResourceBase.getHost().getIp() + "; Network=" + nr.uuid + "; pif=" + pr.uuid); + if (logger.isDebugEnabled()) { + logger.debug("Found a network called " + nr.nameLabel + " on host=" + _citrixResourceBase.getHost().getIp() + "; Network=" + nr.uuid + "; pif=" + pr.uuid); } _p = pif; _pr = pr; diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerGetAutoScaleMetricsCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerGetAutoScaleMetricsCommandWrapper.java index 74d5a8ed0a45..1bf1c5070696 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerGetAutoScaleMetricsCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerGetAutoScaleMetricsCommandWrapper.java @@ -20,7 +20,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xcp; import com.cloud.hypervisor.xenserver.resource.XcpServerResource; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = GetAutoScaleMetricsCommand.class) public final class XcpServerGetAutoScaleMetricsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XcpServerGetAutoScaleMetricsCommandWrapper.class); @Override public Answer execute(final GetAutoScaleMetricsCommand command, final XcpServerResource xcpServer) { @@ -77,7 +75,7 @@ public Answer execute(final GetAutoScaleMetricsCommand command, final XcpServerR return new GetAutoScaleMetricsAnswer(command, true, values); } catch (final Exception ex) { - s_logger.warn("Failed to get autoscale metrics due to ", ex); + logger.warn("Failed to get autoscale metrics due to ", ex); return new GetAutoScaleMetricsAnswer(command, false); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerNetworkUsageCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerNetworkUsageCommandWrapper.java index 0f5aaa1fb134..cc37c8373fb1 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerNetworkUsageCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerNetworkUsageCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xcp; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.NetworkUsageAnswer; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = NetworkUsageCommand.class) public final class XcpServerNetworkUsageCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XcpServerNetworkUsageCommandWrapper.class); @Override public Answer execute(final NetworkUsageCommand command, final XcpServerResource xcpServerResource) { @@ -47,7 +45,7 @@ public Answer execute(final NetworkUsageCommand command, final XcpServerResource final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]); return answer; } catch (final Exception ex) { - s_logger.warn("Failed to get network usage stats due to ", ex); + logger.warn("Failed to get network usage stats due to ", ex); return new NetworkUsageAnswer(command, ex); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56CheckOnHostCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56CheckOnHostCommandWrapper.java index 49445163f379..d59ef1f5a0da 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56CheckOnHostCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56CheckOnHostCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xen56; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckOnHostAnswer; @@ -31,7 +30,6 @@ @ResourceWrapper(handles = CheckOnHostCommand.class) public final class XenServer56CheckOnHostCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer56CheckOnHostCommandWrapper.class); @Override public Answer execute(final CheckOnHostCommand command, final XenServer56Resource xenServer56) { @@ -44,7 +42,7 @@ public Answer execute(final CheckOnHostCommand command, final XenServer56Resourc } else { msg = "Heart beat is gone so dead."; } - s_logger.debug(msg); + logger.debug(msg); return new CheckOnHostAnswer(command, alive, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56FenceCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56FenceCommandWrapper.java index 3cebbd9a342e..c76059640b32 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56FenceCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56FenceCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Set; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = FenceCommand.class) public final class XenServer56FenceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer56FenceCommandWrapper.class); @Override public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) { @@ -45,28 +43,28 @@ public Answer execute(final FenceCommand command, final XenServer56Resource xenS try { final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid()); if (alive == null) { - s_logger.debug("Failed to check heartbeat, so unable to fence"); + logger.debug("Failed to check heartbeat, so unable to fence"); return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence"); } if (alive) { - s_logger.debug("Heart beat is still going so unable to fence"); + logger.debug("Heart beat is still going so unable to fence"); return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence"); } final Set vms = VM.getByNameLabel(conn, command.getVmName()); for (final VM vm : vms) { - s_logger.info("Fence command for VM " + command.getVmName()); + logger.info("Fence command for VM " + command.getVmName()); vm.powerStateReset(conn); vm.destroy(conn); } return new FenceAnswer(command); } catch (final XmlRpcException e) { - s_logger.warn("Unable to fence", e); + logger.warn("Unable to fence", e); return new FenceAnswer(command, false, e.getMessage()); } catch (final XenAPIException e) { - s_logger.warn("Unable to fence", e); + logger.warn("Unable to fence", e); return new FenceAnswer(command, false, e.getMessage()); } catch (final Exception e) { - s_logger.warn("Unable to fence", e); + logger.warn("Unable to fence", e); return new FenceAnswer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56GetAutoScaleMetricsCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56GetAutoScaleMetricsCommandWrapper.java index 8cd11345fca1..3da752dd4e8e 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56GetAutoScaleMetricsCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56GetAutoScaleMetricsCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xen56; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.routing.GetAutoScaleMetricsAnswer; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = GetAutoScaleMetricsCommand.class) public final class XenServer56GetAutoScaleMetricsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer56GetAutoScaleMetricsCommandWrapper.class); @Override public Answer execute(final GetAutoScaleMetricsCommand command, final XenServer56Resource xenServer56) { @@ -77,7 +75,7 @@ public Answer execute(final GetAutoScaleMetricsCommand command, final XenServer5 return new GetAutoScaleMetricsAnswer(command, true, values); } catch (final Exception ex) { - s_logger.warn("Failed to get autoscale metrics due to ", ex); + logger.warn("Failed to get autoscale metrics due to ", ex); return new GetAutoScaleMetricsAnswer(command, false); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56NetworkUsageCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56NetworkUsageCommandWrapper.java index 4f3209e6d6f9..43233cc657cf 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56NetworkUsageCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56/XenServer56NetworkUsageCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xen56; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.NetworkUsageAnswer; @@ -33,7 +32,6 @@ @ResourceWrapper(handles = NetworkUsageCommand.class) public final class XenServer56NetworkUsageCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer56NetworkUsageCommandWrapper.class); @Override public Answer execute(final NetworkUsageCommand command, final XenServer56Resource xenServer56) { @@ -51,7 +49,7 @@ public Answer execute(final NetworkUsageCommand command, final XenServer56Resour final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]); return answer; } catch (final Exception ex) { - s_logger.warn("Failed to get network usage stats due to ", ex); + logger.warn("Failed to get network usage stats due to ", ex); return new NetworkUsageAnswer(command, ex); } } @@ -97,7 +95,7 @@ protected NetworkUsageAnswer executeNetworkUsage(final NetworkUsageCommand comma } return new NetworkUsageAnswer(command, "success", 0L, 0L); } catch (final Exception ex) { - s_logger.warn("Failed to get network usage stats due to ", ex); + logger.warn("Failed to get network usage stats due to ", ex); return new NetworkUsageAnswer(command, ex); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56p1/XenServer56FP1FenceCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56p1/XenServer56FP1FenceCommandWrapper.java index bc7a4434bd06..84fe14ecee86 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56p1/XenServer56FP1FenceCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen56p1/XenServer56FP1FenceCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.Set; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -41,7 +40,6 @@ @ResourceWrapper(handles = FenceCommand.class) public final class XenServer56FP1FenceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer56FP1FenceCommandWrapper.class); @Override public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) { @@ -49,11 +47,11 @@ public Answer execute(final FenceCommand command, final XenServer56Resource xenS try { final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid()); if ( alive == null ) { - s_logger.debug("Failed to check heartbeat, so unable to fence"); + logger.debug("Failed to check heartbeat, so unable to fence"); return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence"); } if ( alive ) { - s_logger.debug("Heart beat is still going so unable to fence"); + logger.debug("Heart beat is still going so unable to fence"); return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence"); } final Set vms = VM.getByNameLabel(conn, command.getVmName()); @@ -66,7 +64,7 @@ public Answer execute(final FenceCommand command, final XenServer56Resource xenS vdis.add(vdi); } } - s_logger.info("Fence command for VM " + command.getVmName()); + logger.info("Fence command for VM " + command.getVmName()); vm.powerStateReset(conn); vm.destroy(conn); for (final VDI vdi : vdis) { @@ -81,13 +79,13 @@ public Answer execute(final FenceCommand command, final XenServer56Resource xenS } return new FenceAnswer(command); } catch (final XmlRpcException e) { - s_logger.warn("Unable to fence", e); + logger.warn("Unable to fence", e); return new FenceAnswer(command, false, e.getMessage()); } catch (final XenAPIException e) { - s_logger.warn("Unable to fence", e); + logger.warn("Unable to fence", e); return new FenceAnswer(command, false, e.getMessage()); } catch (final Exception e) { - s_logger.warn("Unable to fence", e); + logger.warn("Unable to fence", e); return new FenceAnswer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateVolumeCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateVolumeCommandWrapper.java index e35bfb045727..aac0af723baf 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateVolumeCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateVolumeCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.MigrateVolumeAnswer; @@ -41,7 +40,6 @@ @ResourceWrapper(handles = MigrateVolumeCommand.class) public final class XenServer610MigrateVolumeCommandWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(XenServer610MigrateVolumeCommandWrapper.class); @Override public Answer execute(final MigrateVolumeCommand command, final XenServer610Resource xenServer610Resource) { @@ -89,7 +87,7 @@ public Answer execute(final MigrateVolumeCommand command, final XenServer610Reso String msg = "Caught exception " + ex.getClass().getName() + " due to the following: " + ex.toString(); - LOGGER.error(msg, ex); + logger.error(msg, ex); return new MigrateVolumeAnswer(command, false, msg, null); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java index f22b4f1bf78c..e46b930b07a7 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java @@ -25,7 +25,6 @@ import java.util.Set; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.MigrateWithStorageAnswer; @@ -56,7 +55,6 @@ @ResourceWrapper(handles = MigrateWithStorageCommand.class) public final class XenServer610MigrateWithStorageCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageCommandWrapper.class); @Override public Answer execute(final MigrateWithStorageCommand command, final XenServer610Resource xenServer610Resource) { @@ -108,7 +106,7 @@ public Answer execute(final MigrateWithStorageCommand command, final XenServer61 xenServer610Resource.waitForTask(connection, task, 1000, timeout); xenServer610Resource.checkForSuccess(connection, task); } catch (final Types.HandleInvalid e) { - s_logger.error("Error while checking if vm " + vmName + " can be migrated to the destination host " + host, e); + logger.error("Error while checking if vm " + vmName + " can be migrated to the destination host " + host, e); throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated to the " + "destination host " + host, e); } @@ -120,7 +118,7 @@ public Answer execute(final MigrateWithStorageCommand command, final XenServer61 xenServer610Resource.waitForTask(connection, task, 1000, timeout); xenServer610Resource.checkForSuccess(connection, task); } catch (final Types.HandleInvalid e) { - s_logger.error("Error while migrating vm " + vmName + " to the destination host " + host, e); + logger.error("Error while migrating vm " + vmName + " to the destination host " + host, e); throw new CloudRuntimeException("Error while migrating vm " + vmName + " to the destination host " + host, e); } @@ -129,14 +127,14 @@ public Answer execute(final MigrateWithStorageCommand command, final XenServer61 vmToMigrate.setAffinity(connection, host); return new MigrateWithStorageAnswer(command, volumeToList); } catch (final Exception e) { - s_logger.warn("Catch Exception " + e.getClass().getName() + ". Storage motion failed due to " + e.toString(), e); + logger.warn("Catch Exception " + e.getClass().getName() + ". Storage motion failed due to " + e.toString(), e); return new MigrateWithStorageAnswer(command, e); } finally { if (task != null) { try { task.destroy(connection); } catch (final Exception e) { - s_logger.debug("Unable to destroy task " + task.toString() + " on host " + uuid + " due to " + e.toString()); + logger.debug("Unable to destroy task " + task.toString() + " on host " + uuid + " due to " + e.toString()); } } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCompleteCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCompleteCommandWrapper.java index bf649aab5118..1aaa4011f093 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCompleteCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCompleteCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.Set; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.MigrateWithStorageCompleteAnswer; @@ -41,7 +40,6 @@ @ResourceWrapper(handles = MigrateWithStorageCompleteCommand.class) public final class XenServer610MigrateWithStorageCompleteCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageCompleteCommandWrapper.class); @Override public Answer execute(final MigrateWithStorageCompleteCommand command, final XenServer610Resource xenServer610Resource) { @@ -73,10 +71,10 @@ public Answer execute(final MigrateWithStorageCompleteCommand command, final Xen return new MigrateWithStorageCompleteAnswer(command, volumeToSet); } catch (final CloudRuntimeException e) { - s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e); + logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e); return new MigrateWithStorageCompleteAnswer(command, e); } catch (final Exception e) { - s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e); + logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e); return new MigrateWithStorageCompleteAnswer(command, e); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageReceiveCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageReceiveCommandWrapper.java index 6bb01965632b..422c0a9cfc77 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageReceiveCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageReceiveCommandWrapper.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.MigrateWithStorageReceiveAnswer; @@ -48,7 +47,6 @@ @ResourceWrapper(handles = MigrateWithStorageReceiveCommand.class) public final class XenServer610MigrateWithStorageReceiveCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageReceiveCommandWrapper.class); @Override public Answer execute(final MigrateWithStorageReceiveCommand command, final XenServer610Resource xenServer610Resource) { @@ -94,10 +92,10 @@ public Answer execute(final MigrateWithStorageReceiveCommand command, final XenS return new MigrateWithStorageReceiveAnswer(command, volumeToSr, nicToNetwork, token); } catch (final CloudRuntimeException e) { - s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e); + logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e); return new MigrateWithStorageReceiveAnswer(command, e); } catch (final Exception e) { - s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e); + logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e); return new MigrateWithStorageReceiveAnswer(command, e); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageSendCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageSendCommandWrapper.java index 7b1e4c85397a..59abe5303cd6 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageSendCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageSendCommandWrapper.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.MigrateWithStorageSendAnswer; @@ -49,7 +48,6 @@ @ResourceWrapper(handles = MigrateWithStorageSendCommand.class) public final class XenServer610MigrateWithStorageSendCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageSendCommandWrapper.class); @Override public Answer execute(final MigrateWithStorageSendCommand command, final XenServer610Resource xenServer610Resource) { @@ -114,7 +112,7 @@ public Answer execute(final MigrateWithStorageSendCommand command, final XenServ xenServer610Resource.waitForTask(connection, task, 1000, timeout); xenServer610Resource.checkForSuccess(connection, task); } catch (final Types.HandleInvalid e) { - s_logger.error("Error while checking if vm " + vmName + " can be migrated.", e); + logger.error("Error while checking if vm " + vmName + " can be migrated.", e); throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated.", e); } @@ -126,24 +124,24 @@ public Answer execute(final MigrateWithStorageSendCommand command, final XenServ xenServer610Resource.waitForTask(connection, task, 1000, timeout); xenServer610Resource.checkForSuccess(connection, task); } catch (final Types.HandleInvalid e) { - s_logger.error("Error while migrating vm " + vmName, e); + logger.error("Error while migrating vm " + vmName, e); throw new CloudRuntimeException("Error while migrating vm " + vmName, e); } final Set volumeToSet = null; return new MigrateWithStorageSendAnswer(command, volumeToSet); } catch (final CloudRuntimeException e) { - s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e); + logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e); return new MigrateWithStorageSendAnswer(command, e); } catch (final Exception e) { - s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e); + logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e); return new MigrateWithStorageSendAnswer(command, e); } finally { if (task != null) { try { task.destroy(connection); } catch (final Exception e) { - s_logger.debug("Unable to destroy task " + task.toString() + " on host " + xenServer610Resource.getHost().getUuid() + " due to " + e.toString()); + logger.debug("Unable to destroy task " + task.toString() + " on host " + xenServer610Resource.getHost().getUuid() + " due to " + e.toString()); } } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen620sp1/XenServer620SP1GetGPUStatsCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen620sp1/XenServer620SP1GetGPUStatsCommandWrapper.java index 8fbe663ce180..1370effb8bf1 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen620sp1/XenServer620SP1GetGPUStatsCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xen620sp1/XenServer620SP1GetGPUStatsCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.HashMap; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetGPUStatsAnswer; @@ -35,7 +34,6 @@ @ResourceWrapper(handles = GetGPUStatsCommand.class) public final class XenServer620SP1GetGPUStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(XenServer620SP1GetGPUStatsCommandWrapper.class); @Override public Answer execute(final GetGPUStatsCommand command, final XenServer620SP1Resource xenServer620SP1Resource) { @@ -45,7 +43,7 @@ public Answer execute(final GetGPUStatsCommand command, final XenServer620SP1Res groupDetails = xenServer620SP1Resource.getGPUGroupDetails(conn); } catch (final Exception e) { final String msg = "Unable to get GPU stats" + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new GetGPUStatsAnswer(command, false, msg); } return new GetGPUStatsAnswer(command, groupDetails); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachIsoCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachIsoCommandWrapper.java index 120c7f62c713..30fd0642174f 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachIsoCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachIsoCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = AttachIsoCommand.class) public final class CitrixAttachIsoCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixAttachIsoCommandWrapper.class); @Override public Answer execute(final AttachIsoCommand command, final CitrixResourceBase citrixResourceBase) { @@ -126,10 +124,10 @@ public Answer execute(final AttachIsoCommand command, final CitrixResourceBase c return new Answer(command); } } catch (final XenAPIException e) { - s_logger.warn(errorMsg + ": " + e.toString(), e); + logger.warn(errorMsg + ": " + e.toString(), e); return new Answer(command, false, e.toString()); } catch (final Exception e) { - s_logger.warn(errorMsg + ": " + e.toString(), e); + logger.warn(errorMsg + ": " + e.toString(), e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachOrDettachConfigDriveCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachOrDettachConfigDriveCommandWrapper.java index 08da7ae07cce..dcdc6013d2ec 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachOrDettachConfigDriveCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachOrDettachConfigDriveCommandWrapper.java @@ -29,7 +29,6 @@ import com.xensource.xenapi.VDI; import com.xensource.xenapi.VM; import com.xensource.xenapi.Types; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; @@ -39,7 +38,6 @@ @ResourceWrapper(handles = AttachOrDettachConfigDriveCommand.class) public final class CitrixAttachOrDettachConfigDriveCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixAttachOrDettachConfigDriveCommandWrapper.class); @Override public Answer execute(final AttachOrDettachConfigDriveCommand command, final CitrixResourceBase citrixResourceBase) { @@ -55,13 +53,13 @@ public Answer execute(final AttachOrDettachConfigDriveCommand command, final Cit for (VM vm : vms) { if (isAttach) { if (!citrixResourceBase.createAndAttachConfigDriveIsoForVM(conn, vm, vmData, label)) { - s_logger.debug("Failed to attach config drive iso to VM " + vmName); + logger.debug("Failed to attach config drive iso to VM " + vmName); } } else { // delete the config drive iso attached to VM Set vdis = VDI.getByNameLabel(conn, vmName+".iso"); if (vdis != null && !vdis.isEmpty()) { - s_logger.debug("Deleting config drive for the VM " + vmName); + logger.debug("Deleting config drive for the VM " + vmName); VDI vdi = vdis.iterator().next(); // Find the VM's CD-ROM VBD Set vbds = vdi.getVBDs(conn); @@ -79,13 +77,13 @@ public Answer execute(final AttachOrDettachConfigDriveCommand command, final Cit vdi.destroy(conn); } - s_logger.debug("Successfully dettached config drive iso from the VM " + vmName); + logger.debug("Successfully dettached config drive iso from the VM " + vmName); } } }catch (Types.XenAPIException ex) { - s_logger.debug("Failed to attach config drive iso to VM " + vmName + " " + ex.getMessage() ); + logger.debug("Failed to attach config drive iso to VM " + vmName + " " + ex.getMessage() ); }catch (XmlRpcException ex) { - s_logger.debug("Failed to attach config drive iso to VM " + vmName + " "+ex.getMessage()); + logger.debug("Failed to attach config drive iso to VM " + vmName + " "+ex.getMessage()); } return new Answer(command, true, "success"); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckGuestOsMappingCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckGuestOsMappingCommandWrapper.java index 68403d76ca4b..927e2b3fbe38 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckGuestOsMappingCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckGuestOsMappingCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.Set; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckGuestOsMappingAnswer; @@ -36,15 +35,13 @@ @ResourceWrapper(handles = CheckGuestOsMappingCommand.class) public final class CitrixCheckGuestOsMappingCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCheckGuestOsMappingCommandWrapper.class); - @Override public Answer execute(final CheckGuestOsMappingCommand command, final CitrixResourceBase citrixResourceBase) { final Connection conn = citrixResourceBase.getConnection(); String guestOsName = command.getGuestOsName(); String guestOsMappingName = command.getGuestOsHypervisorMappingName(); try { - s_logger.info("Checking guest os mapping name: " + guestOsMappingName + " for the guest os: " + guestOsName + " in the hypervisor"); + logger.info("Checking guest os mapping name: " + guestOsMappingName + " for the guest os: " + guestOsName + " in the hypervisor"); final Set vms = VM.getAll(conn); if (CollectionUtils.isEmpty(vms)) { return new CheckGuestOsMappingAnswer(command, "Unable to match guest os mapping name: " + guestOsMappingName + " in the hypervisor"); @@ -52,15 +49,15 @@ public Answer execute(final CheckGuestOsMappingCommand command, final CitrixReso for (VM vm : vms) { if (vm != null && vm.getIsATemplate(conn) && guestOsMappingName.equalsIgnoreCase(vm.getNameLabel(conn))) { if (guestOsName.equalsIgnoreCase(vm.getNameLabel(conn))) { - s_logger.debug("Hypervisor guest os name label matches with os name: " + guestOsName); + logger.debug("Hypervisor guest os name label matches with os name: " + guestOsName); } - s_logger.info("Hypervisor guest os name label matches with os mapping: " + guestOsMappingName + " from user"); + logger.info("Hypervisor guest os name label matches with os mapping: " + guestOsMappingName + " from user"); return new CheckGuestOsMappingAnswer(command); } } return new CheckGuestOsMappingAnswer(command, "Guest os mapping name: " + guestOsMappingName + " not found in the hypervisor"); } catch (final Exception e) { - s_logger.error("Failed to find the hypervisor guest os mapping name: " + guestOsMappingName, e); + logger.error("Failed to find the hypervisor guest os mapping name: " + guestOsMappingName, e); return new CheckGuestOsMappingAnswer(command, e.getLocalizedMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckNetworkCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckNetworkCommandWrapper.java index 2825d751bbba..600c8e2625d8 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckNetworkCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckNetworkCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckNetworkAnswer; @@ -35,12 +34,11 @@ @ResourceWrapper(handles = CheckNetworkCommand.class) public final class CitrixCheckNetworkCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCheckNetworkCommandWrapper.class); @Override public Answer execute(final CheckNetworkCommand command, final CitrixResourceBase citrixResourceBase) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Checking if network name setup is done on the resource"); + if (logger.isDebugEnabled()) { + logger.debug("Checking if network name setup is done on the resource"); } final List infoList = command.getPhysicalNetworkInfoList(); @@ -77,7 +75,7 @@ public Answer execute(final CheckNetworkCommand command, final CitrixResourceBas }*/ } if (errorout) { - s_logger.error(msg); + logger.error(msg); return new CheckNetworkAnswer(command, false, msg); } else { return new CheckNetworkAnswer(command, true, "Network Setup check by names is done"); @@ -85,11 +83,11 @@ public Answer execute(final CheckNetworkCommand command, final CitrixResourceBas } catch (final XenAPIException e) { final String msg = "CheckNetworkCommand failed with XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new CheckNetworkAnswer(command, false, msg); } catch (final Exception e) { final String msg = "CheckNetworkCommand failed with Exception:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new CheckNetworkAnswer(command, false, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java index 2c318935c43d..2873040ae22b 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckSshCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.check.CheckSshAnswer; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = CheckSshCommand.class) public final class CitrixCheckSshCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCheckSshCommandWrapper.class); @Override public Answer execute(final CheckSshCommand command, final CitrixResourceBase citrixResourceBase) { @@ -41,8 +39,8 @@ public Answer execute(final CheckSshCommand command, final CitrixResourceBase ci final String privateIp = command.getIp(); final int cmdPort = command.getPort(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port, " + privateIp + ":" + cmdPort); } try { @@ -56,8 +54,8 @@ public Answer execute(final CheckSshCommand command, final CitrixResourceBase ci return new CheckSshAnswer(command, e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port succeeded for vm " + vmName); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port succeeded for vm " + vmName); } return new CheckSshAnswer(command); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckVirtualMachineCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckVirtualMachineCommandWrapper.java index c3e75d490155..87bb7fd4e489 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckVirtualMachineCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCheckVirtualMachineCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckVirtualMachineAnswer; @@ -33,7 +32,6 @@ @ResourceWrapper(handles = CheckVirtualMachineCommand.class) public final class CitrixCheckVirtualMachineCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCheckVirtualMachineCommandWrapper.class); @Override public Answer execute(final CheckVirtualMachineCommand command, final CitrixResourceBase citrixResourceBase) { @@ -42,7 +40,7 @@ public Answer execute(final CheckVirtualMachineCommand command, final CitrixReso final PowerState powerState = citrixResourceBase.getVmState(conn, vmName); final Integer vncPort = null; if (powerState == PowerState.PowerOn) { - s_logger.debug("3. The VM " + vmName + " is in Running state"); + logger.debug("3. The VM " + vmName + " is in Running state"); } return new CheckVirtualMachineAnswer(command, powerState, vncPort); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCleanupNetworkRulesCmdWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCleanupNetworkRulesCmdWrapper.java index 74c23d830213..a367a67019bf 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCleanupNetworkRulesCmdWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCleanupNetworkRulesCmdWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CleanupNetworkRulesCmd; @@ -31,7 +30,6 @@ @ResourceWrapper(handles = CleanupNetworkRulesCmd.class) public final class CitrixCleanupNetworkRulesCmdWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCleanupNetworkRulesCmdWrapper.class); @Override public Answer execute(final CleanupNetworkRulesCmd command, final CitrixResourceBase citrixResourceBase) { @@ -44,12 +42,12 @@ public Answer execute(final CleanupNetworkRulesCmd command, final CitrixResource final int numCleaned = Integer.parseInt(result); if (result == null || result.isEmpty() || numCleaned < 0) { - s_logger.warn("Failed to cleanup rules for host " + citrixResourceBase.getHost().getIp()); + logger.warn("Failed to cleanup rules for host " + citrixResourceBase.getHost().getIp()); return new Answer(command, false, result); } if (numCleaned > 0) { - s_logger.info("Cleaned up rules for " + result + " vms on host " + citrixResourceBase.getHost().getIp()); + logger.info("Cleaned up rules for " + result + " vms on host " + citrixResourceBase.getHost().getIp()); } return new Answer(command, true, result); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCleanupPersistentNetworkResourceCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCleanupPersistentNetworkResourceCommandWrapper.java index 3be321cf6b8b..43329eb3df51 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCleanupPersistentNetworkResourceCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCleanupPersistentNetworkResourceCommandWrapper.java @@ -17,7 +17,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CleanupPersistentNetworkResourceAnswer; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = CleanupPersistentNetworkResourceCommand.class) public class CitrixCleanupPersistentNetworkResourceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCleanupPersistentNetworkResourceCommandWrapper.class); @Override public Answer execute(CleanupPersistentNetworkResourceCommand command, CitrixResourceBase citrixResourceBase) { @@ -48,7 +46,7 @@ public Answer execute(CleanupPersistentNetworkResourceCommand command, CitrixRes return new CleanupPersistentNetworkResourceAnswer(command, true, "Successfully deleted network VLAN on host: "+ host.getIp()); } catch (final Exception e) { final String msg = " Failed to cleanup network VLAN on host: " + host.getIp() + " due to: " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new CleanupPersistentNetworkResourceAnswer(command, false, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixClusterVMMetaDataSyncCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixClusterVMMetaDataSyncCommandWrapper.java index a85fb4491538..e02fc7060ca9 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixClusterVMMetaDataSyncCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixClusterVMMetaDataSyncCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.HashMap; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ClusterVMMetaDataSyncAnswer; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = ClusterVMMetaDataSyncCommand.class) public final class CitrixClusterVMMetaDataSyncCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixClusterVMMetaDataSyncCommandWrapper.class); @Override public Answer execute(final ClusterVMMetaDataSyncCommand command, final CitrixResourceBase citrixResourceBase) { @@ -50,7 +48,7 @@ public Answer execute(final ClusterVMMetaDataSyncCommand command, final CitrixRe return new ClusterVMMetaDataSyncAnswer(command.getClusterId(), null); } } catch (final Throwable e) { - s_logger.warn("Check for master failed, failing the Cluster sync VMMetaData command"); + logger.warn("Check for master failed, failing the Cluster sync VMMetaData command"); return new ClusterVMMetaDataSyncAnswer(command.getClusterId(), null); } final HashMap vmMetadatum = citrixResourceBase.clusterVMMetaDataSync(conn); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixConsoleProxyLoadCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixConsoleProxyLoadCommandWrapper.java index 70334580b7c1..740dedec6c82 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixConsoleProxyLoadCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixConsoleProxyLoadCommandWrapper.java @@ -26,7 +26,6 @@ import java.net.URL; import java.net.URLConnection; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -36,7 +35,6 @@ public abstract class CitrixConsoleProxyLoadCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixConsoleProxyLoadCommandWrapper.class); protected Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, final String proxyVmName, final String proxyManagementIp, final int cmdPort) { String result = null; @@ -68,12 +66,12 @@ protected Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, f try { is.close(); } catch (final IOException e) { - s_logger.warn("Exception when closing , console proxy address : " + proxyManagementIp); + logger.warn("Exception when closing , console proxy address : " + proxyManagementIp); success = false; } } } catch (final IOException e) { - s_logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp); + logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp); success = false; } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCoppyToSecondaryStorageCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCoppyToSecondaryStorageCommandWrapper.java index 45bbf4a631c2..2ca389478b00 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCoppyToSecondaryStorageCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCoppyToSecondaryStorageCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageCommand; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; @@ -30,13 +29,12 @@ @ResourceWrapper(handles = CopyToSecondaryStorageCommand.class) public class CitrixCoppyToSecondaryStorageCommandWrapper extends CommandWrapper { - public static final Logger LOGGER = Logger.getLogger(CitrixCoppyToSecondaryStorageCommandWrapper.class); @Override public Answer execute(CopyToSecondaryStorageCommand cmd, CitrixResourceBase citrixResourceBase) { final Connection conn = citrixResourceBase.getConnection(); String msg = String.format("Copying diagnostics zip file %s from system vm %s to secondary storage %s", cmd.getFileName(), cmd.getSystemVmIp(), cmd.getSecondaryStorageUrl()); - LOGGER.debug(msg); + logger.debug(msg); // Allow the hypervisor host to copy file from system VM to mounted secondary storage return citrixResourceBase.copyDiagnosticsFileToSecondaryStorage(conn, cmd); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateCommandWrapper.java index 928c8f04a9dd..75bdd63bd88a 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.HashMap; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.CreateAnswer; @@ -41,7 +40,6 @@ @ResourceWrapper(handles = CreateCommand.class) public final class CitrixCreateCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCreateCommandWrapper.class); @Override public Answer execute(final CreateCommand command, final CitrixResourceBase citrixResourceBase) { @@ -72,14 +70,14 @@ public Answer execute(final CreateCommand command, final CitrixResourceBase citr VDI.Record vdir; vdir = vdi.getRecord(conn); - s_logger.debug("Successfully created VDI for " + command + ". Uuid = " + vdir.uuid); + logger.debug("Successfully created VDI for " + command + ". Uuid = " + vdir.uuid); final VolumeTO vol = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), vdir.nameLabel, pool.getPath(), vdir.uuid, vdir.virtualSize, null); return new CreateAnswer(command, vol); } catch (final Exception e) { - s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e); + logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e); return new CreateAnswer(command, e); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateStoragePoolCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateStoragePoolCommandWrapper.java index dd4290c89f72..7aef00601bef 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateStoragePoolCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateStoragePoolCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CreateStoragePoolCommand; @@ -35,7 +34,6 @@ @ResourceWrapper(handles = CreateStoragePoolCommand.class) public final class CitrixCreateStoragePoolCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCreateStoragePoolCommandWrapper.class); @Override public Answer execute(final CreateStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) { @@ -68,7 +66,7 @@ public Answer execute(final CreateStoragePoolCommand command, final CitrixResour final String msg = "Catch Exception " + e.getClass().getName() + ", create StoragePool failed due to " + e.toString() + " on host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(command, false, msg); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateVMSnapshotCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateVMSnapshotCommandWrapper.java index 68c295717c3e..85cfa5d8aa8f 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateVMSnapshotCommandWrapper.java @@ -25,7 +25,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CreateVMSnapshotAnswer; @@ -47,7 +46,6 @@ @ResourceWrapper(handles = CreateVMSnapshotCommand.class) public final class CitrixCreateVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixCreateVMSnapshotCommandWrapper.class); @Override public Answer execute(final CreateVMSnapshotCommand command, final CitrixResourceBase citrixResourceBase) { @@ -163,13 +161,13 @@ public Answer execute(final CreateVMSnapshotCommand command, final CitrixResourc } else { msg = e.toString(); } - s_logger.warn("Creating VM Snapshot " + command.getTarget().getSnapshotName() + " failed due to: " + msg, e); + logger.warn("Creating VM Snapshot " + command.getTarget().getSnapshotName() + " failed due to: " + msg, e); return new CreateVMSnapshotAnswer(command, false, msg); } finally { try { if (!success) { if (vmSnapshot != null) { - s_logger.debug("Delete existing VM Snapshot " + vmSnapshotName + " after making VolumeTO failed"); + logger.debug("Delete existing VM Snapshot " + vmSnapshotName + " after making VolumeTO failed"); final Set vbds = vmSnapshot.getVBDs(conn); for (final VBD vbd : vbds) { final VBD.Record vbdr = vbd.getRecord(conn); @@ -187,7 +185,7 @@ public Answer execute(final CreateVMSnapshotCommand command, final CitrixResourc } } } catch (final Exception e2) { - s_logger.error("delete snapshot error due to " + e2.getMessage()); + logger.error("delete snapshot error due to " + e2.getMessage()); } } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteStoragePoolCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteStoragePoolCommandWrapper.java index d3cfc2514746..bdf63414a596 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteStoragePoolCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteStoragePoolCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.DeleteStoragePoolCommand; @@ -35,7 +34,6 @@ @ResourceWrapper(handles = DeleteStoragePoolCommand.class) public final class CitrixDeleteStoragePoolCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixDeleteStoragePoolCommandWrapper.class); @Override public Answer execute(final DeleteStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) { @@ -67,7 +65,7 @@ public Answer execute(final DeleteStoragePoolCommand command, final CitrixResour final String msg = "DeleteStoragePoolCommand XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + poolTO.getHost() + poolTO.getPath(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(command, false, msg); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteVMSnapshotCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteVMSnapshotCommandWrapper.java index b74111e8441c..5e7ca01ea1dd 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteVMSnapshotCommandWrapper.java @@ -25,7 +25,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.DeleteVMSnapshotAnswer; @@ -43,7 +42,6 @@ @ResourceWrapper(handles = DeleteVMSnapshotCommand.class) public final class CitrixDeleteVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixDeleteVMSnapshotCommandWrapper.class); @Override public Answer execute(final DeleteVMSnapshotCommand command, final CitrixResourceBase citrixResourceBase) { @@ -54,7 +52,7 @@ public Answer execute(final DeleteVMSnapshotCommand command, final CitrixResourc final List vdiList = new ArrayList(); final Set snapshots = VM.getByNameLabel(conn, snapshotName); if (snapshots == null || snapshots.size() == 0) { - s_logger.warn("VM snapshot with name " + snapshotName + " does not exist, assume it is already deleted"); + logger.warn("VM snapshot with name " + snapshotName + " does not exist, assume it is already deleted"); return new DeleteVMSnapshotAnswer(command, command.getVolumeTOs()); } final VM snapshot = snapshots.iterator().next(); @@ -90,7 +88,7 @@ public Answer execute(final DeleteVMSnapshotCommand command, final CitrixResourc return new DeleteVMSnapshotAnswer(command, command.getVolumeTOs()); } catch (final Exception e) { - s_logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e); + logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e); return new DeleteVMSnapshotAnswer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDestroyCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDestroyCommandWrapper.java index d2cf3d0bdd62..0c5c32d7779a 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDestroyCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDestroyCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.DestroyCommand; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = DestroyCommand.class) public final class CitrixDestroyCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixDestroyCommandWrapper.class); @Override public Answer execute(final DestroyCommand command, final CitrixResourceBase citrixResourceBase) { @@ -55,7 +53,7 @@ public Answer execute(final DestroyCommand command, final CitrixResourceBase cit vbds = vdi.getVBDs(conn); } catch (final Exception e) { final String msg = "VDI getVBDS for " + volumeUUID + " failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(command, false, msg); } for (final VBD vbd : vbds) { @@ -64,7 +62,7 @@ public Answer execute(final DestroyCommand command, final CitrixResourceBase cit vbd.destroy(conn); } catch (final Exception e) { final String msg = "VM destroy for " + volumeUUID + " failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(command, false, msg); } } @@ -76,7 +74,7 @@ public Answer execute(final DestroyCommand command, final CitrixResourceBase cit vdi.destroy(conn); } catch (final Exception e) { final String msg = "VDI destroy for " + volumeUUID + " failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(command, false, msg); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetHostStatsCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetHostStatsCommandWrapper.java index 256d862ba25b..ff9d2afd6f33 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetHostStatsCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetHostStatsCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetHostStatsAnswer; @@ -33,7 +32,6 @@ @ResourceWrapper(handles = GetHostStatsCommand.class) public final class CitrixGetHostStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixGetHostStatsCommandWrapper.class); @Override public Answer execute(final GetHostStatsCommand command, final CitrixResourceBase citrixResourceBase) { @@ -43,7 +41,7 @@ public Answer execute(final GetHostStatsCommand command, final CitrixResourceBas return new GetHostStatsAnswer(command, hostStats); } catch (final Exception e) { final String msg = "Unable to get Host stats" + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new GetHostStatsAnswer(command, null); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetHypervisorGuestOsNamesCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetHypervisorGuestOsNamesCommandWrapper.java index 0be3e5a5746b..72ae6fb132d9 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetHypervisorGuestOsNamesCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetHypervisorGuestOsNamesCommandWrapper.java @@ -25,7 +25,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetHypervisorGuestOsNamesAnswer; @@ -40,14 +39,12 @@ @ResourceWrapper(handles = GetHypervisorGuestOsNamesCommand.class) public final class CitrixGetHypervisorGuestOsNamesCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixGetHypervisorGuestOsNamesCommandWrapper.class); - @Override public Answer execute(final GetHypervisorGuestOsNamesCommand command, final CitrixResourceBase citrixResourceBase) { final Connection conn = citrixResourceBase.getConnection(); String keyword = command.getKeyword(); try { - s_logger.info("Getting guest os names in the hypervisor"); + logger.info("Getting guest os names in the hypervisor"); final Set vms = VM.getAll(conn); if (CollectionUtils.isEmpty(vms)) { return new GetHypervisorGuestOsNamesAnswer(command, "Guest os names not found in the hypervisor"); @@ -69,7 +66,7 @@ public Answer execute(final GetHypervisorGuestOsNamesCommand command, final Citr } return new GetHypervisorGuestOsNamesAnswer(command, hypervisorGuestOsNames); } catch (final Exception e) { - s_logger.error("Failed to fetch hypervisor guest os names due to: " + e.getLocalizedMessage(), e); + logger.error("Failed to fetch hypervisor guest os names due to: " + e.getLocalizedMessage(), e); return new GetHypervisorGuestOsNamesAnswer(command, e.getLocalizedMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetStorageStatsCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetStorageStatsCommandWrapper.java index c99d90e0608a..d6dd6c5fcacd 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetStorageStatsCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetStorageStatsCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Set; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = GetStorageStatsCommand.class) public final class CitrixGetStorageStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixGetStorageStatsCommandWrapper.class); @Override public Answer execute(final GetStorageStatsCommand command, final CitrixResourceBase citrixResourceBase) { @@ -46,7 +44,7 @@ public Answer execute(final GetStorageStatsCommand command, final CitrixResource final Set srs = SR.getByNameLabel(conn, command.getStorageId()); if (srs.size() != 1) { final String msg = "There are " + srs.size() + " storageid: " + command.getStorageId(); - s_logger.warn(msg); + logger.warn(msg); return new GetStorageStatsAnswer(command, msg); } final SR sr = srs.iterator().next(); @@ -56,15 +54,15 @@ public Answer execute(final GetStorageStatsCommand command, final CitrixResource return new GetStorageStatsAnswer(command, capacity, used); } catch (final XenAPIException e) { final String msg = "GetStorageStats Exception:" + e.toString() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId(); - s_logger.warn(msg); + logger.warn(msg); return new GetStorageStatsAnswer(command, msg); } catch (final XmlRpcException e) { final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId(); - s_logger.warn(msg); + logger.warn(msg); return new GetStorageStatsAnswer(command, msg); } catch (final Exception e) { final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId(); - s_logger.warn(msg); + logger.warn(msg); return new GetStorageStatsAnswer(command, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVmIpAddressCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVmIpAddressCommandWrapper.java index b67ef0850baf..a324ec1bdada 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVmIpAddressCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVmIpAddressCommandWrapper.java @@ -27,7 +27,6 @@ import com.xensource.xenapi.VM; import com.xensource.xenapi.VMGuestMetrics; import com.xensource.xenapi.Types; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = GetVmIpAddressCommand.class) public final class CitrixGetVmIpAddressCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixGetVmIpAddressCommandWrapper.class); @Override public Answer execute(final GetVmIpAddressCommand command, final CitrixResourceBase citrixResourceBase) { @@ -63,16 +61,16 @@ public Answer execute(final GetVmIpAddressCommand command, final CitrixResourceB } if (vmIp != null) { - s_logger.debug("VM " +vmName + " ip address got retrieved "+vmIp); + logger.debug("VM " +vmName + " ip address got retrieved "+vmIp); result = true; return new Answer(command, result, vmIp); } }catch (Types.XenAPIException e) { - s_logger.debug("Got exception in GetVmIpAddressCommand "+ e.getMessage()); + logger.debug("Got exception in GetVmIpAddressCommand "+ e.getMessage()); errorMsg = "Failed to retrived vm ip addr, exception: "+e.getMessage(); }catch (XmlRpcException e) { - s_logger.debug("Got exception in GetVmIpAddressCommand "+ e.getMessage()); + logger.debug("Got exception in GetVmIpAddressCommand "+ e.getMessage()); errorMsg = "Failed to retrived vm ip addr, exception: "+e.getMessage(); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVmStatsCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVmStatsCommandWrapper.java index 329ce4977b44..b2c06c0365bd 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVmStatsCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVmStatsCommandWrapper.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -41,7 +40,6 @@ @ResourceWrapper(handles = GetVmStatsCommand.class) public final class CitrixGetVmStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixGetVmStatsCommandWrapper.class); @Override public Answer execute(final GetVmStatsCommand command, final CitrixResourceBase citrixResourceBase) { @@ -73,11 +71,11 @@ public Answer execute(final GetVmStatsCommand command, final CitrixResourceBase return new GetVmStatsAnswer(command, vmStatsNameMap); } catch (final XenAPIException e) { final String msg = "Unable to get VM stats" + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new GetVmStatsAnswer(command, vmStatsNameMap); } catch (final XmlRpcException e) { final String msg = "Unable to get VM stats" + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new GetVmStatsAnswer(command, vmStatsNameMap); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVncPortCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVncPortCommandWrapper.java index e95430aeebb4..362b6b02b2b2 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVncPortCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVncPortCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetVncPortAnswer; @@ -35,7 +34,6 @@ @ResourceWrapper(handles = GetVncPortCommand.class) public final class CitrixGetVncPortCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixGetVncPortCommandWrapper.class); @Override public Answer execute(final GetVncPortCommand command, final CitrixResourceBase citrixResourceBase) { @@ -51,7 +49,7 @@ public Answer execute(final GetVncPortCommand command, final CitrixResourceBase } } catch (final Exception e) { final String msg = "Unable to get vnc port due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new GetVncPortAnswer(command, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVolumeStatsCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVolumeStatsCommandWrapper.java index bb959621a43c..f516d2545f94 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVolumeStatsCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixGetVolumeStatsCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.HashMap; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetVolumeStatsAnswer; @@ -35,7 +34,6 @@ @ResourceWrapper(handles = GetVolumeStatsCommand.class) public final class CitrixGetVolumeStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixGetVolumeStatsCommandWrapper.class); @Override public Answer execute(final GetVolumeStatsCommand cmd, final CitrixResourceBase citrixResourceBase) { @@ -48,11 +46,11 @@ public Answer execute(final GetVolumeStatsCommand cmd, final CitrixResourceBase VolumeStatsEntry vse = new VolumeStatsEntry(volumeUuid, vdi.getPhysicalUtilisation(conn), vdi.getVirtualSize(conn)); statEntry.put(volumeUuid, vse); } catch (Exception e) { - s_logger.warn("Unable to get volume stats", e); + logger.warn("Unable to get volume stats", e); statEntry.put(volumeUuid, new VolumeStatsEntry(volumeUuid, -1, -1)); } } else { - s_logger.warn("VDI not found for path " + volumeUuid); + logger.warn("VDI not found for path " + volumeUuid); statEntry.put(volumeUuid, new VolumeStatsEntry(volumeUuid, -1L, -1L)); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixListDataStoreObjectsCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixListDataStoreObjectsCommandWrapper.java index 1be7879d602e..2367f6d608bf 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixListDataStoreObjectsCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixListDataStoreObjectsCommandWrapper.java @@ -25,25 +25,22 @@ import com.cloud.resource.ResourceWrapper; import com.xensource.xenapi.Types.XenAPIException; import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsCommand; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; @ResourceWrapper(handles = ListDataStoreObjectsCommand.class) public final class CitrixListDataStoreObjectsCommandWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(CitrixListDataStoreObjectsCommandWrapper.class); - @Override public Answer execute(final ListDataStoreObjectsCommand command, final CitrixResourceBase citrixResourceBase) { try { return citrixResourceBase.listFilesAtPath(command); } catch (XenAPIException e) { - LOGGER.warn("XenAPI exception", e); + logger.warn("XenAPI exception", e); } catch (XmlRpcException e) { - LOGGER.warn("Xml Rpc Exception", e); + logger.warn("Xml Rpc Exception", e); } catch (Exception e) { - LOGGER.warn("Caught exception", e); + logger.warn("Caught exception", e); } return null; } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMaintainCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMaintainCommandWrapper.java index 84c043ab1719..065fd9fe0ab4 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMaintainCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMaintainCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Iterator; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -38,7 +37,6 @@ @ResourceWrapper(handles = MaintainCommand.class) public final class CitrixMaintainCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixMaintainCommandWrapper.class); @Override public Answer execute(final MaintainCommand command, final CitrixResourceBase citrixResourceBase) { @@ -53,7 +51,7 @@ public Answer execute(final MaintainCommand command, final CitrixResourceBase ci // Adding this check because could not get the mock to work. Will push the code and fix it afterwards. if (hr == null) { - s_logger.warn("Host.Record is null."); + logger.warn("Host.Record is null."); return new MaintainAnswer(command, false, "Host.Record is null"); } @@ -67,10 +65,10 @@ public Answer execute(final MaintainCommand command, final CitrixResourceBase ci host.setTags(conn, hr.tags); return new MaintainAnswer(command); } catch (final XenAPIException e) { - s_logger.warn("Unable to put server in maintainence mode", e); + logger.warn("Unable to put server in maintainence mode", e); return new MaintainAnswer(command, false, e.getMessage()); } catch (final XmlRpcException e) { - s_logger.warn("Unable to put server in maintainence mode", e); + logger.warn("Unable to put server in maintainence mode", e); return new MaintainAnswer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapper.java index 68ee19a8058c..269eb5ceb8bf 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.Set; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -42,7 +41,6 @@ @ResourceWrapper(handles = MigrateCommand.class) public class CitrixMigrateCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixMigrateCommandWrapper.class); @Override public Answer execute(final MigrateCommand command, final CitrixResourceBase citrixResourceBase) { @@ -65,7 +63,7 @@ public Answer execute(final MigrateCommand command, final CitrixResourceBase cit } if (dsthost == null) { final String msg = "Migration failed due to unable to find host " + dstHostIpAddr + " in XenServer pool " + citrixResourceBase.getHost().getPool(); - s_logger.warn(msg); + logger.warn(msg); return new MigrateAnswer(command, false, msg, null); } for (final VM vm : vms) { @@ -93,12 +91,12 @@ public Answer execute(final MigrateCommand command, final CitrixResourceBase cit // Attach the config drive iso device to VM VM vm = vms.iterator().next(); if (!citrixResourceBase.attachConfigDriveIsoToVm(conn, vm)) { - s_logger.debug("Config drive ISO attach failed after migration for vm "+vmName); + logger.debug("Config drive ISO attach failed after migration for vm "+vmName); } return new MigrateAnswer(command, true, "migration succeeded", null); } catch (final Exception e) { - s_logger.warn(e.getMessage(), e); + logger.warn(e.getMessage(), e); return new MigrateAnswer(command, false, e.getMessage(), null); } } @@ -111,9 +109,9 @@ protected void destroyMigratedVmNetworkRulesOnSourceHost(final MigrateCommand co if (citrixResourceBase.canBridgeFirewall()) { final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "destroy_network_rules_for_vm", "vmName", command.getVmName()); if (BooleanUtils.toBoolean(result)) { - s_logger.debug(String.format("Removed network rules from source host [%s] for migrated vm [%s]", dsthost.getHostname(conn), command.getVmName())); + logger.debug(String.format("Removed network rules from source host [%s] for migrated vm [%s]", dsthost.getHostname(conn), command.getVmName())); } else { - s_logger.warn(String.format("Failed to remove network rules from source host [%s] for migrated vm [%s]", dsthost.getHostname(conn), command.getVmName())); + logger.warn(String.format("Failed to remove network rules from source host [%s] for migrated vm [%s]", dsthost.getHostname(conn), command.getVmName())); } } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixModifyStoragePoolCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixModifyStoragePoolCommandWrapper.java index 07fe32a4a803..63cb675c6143 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixModifyStoragePoolCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixModifyStoragePoolCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ModifyStoragePoolAnswer; @@ -41,7 +40,6 @@ @ResourceWrapper(handles = ModifyStoragePoolCommand.class) public final class CitrixModifyStoragePoolCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixModifyStoragePoolCommandWrapper.class); @Override public Answer execute(final ModifyStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) { @@ -60,7 +58,7 @@ public Answer execute(final ModifyStoragePoolCommand command, final CitrixResour final long available = capacity - sr.getPhysicalUtilisation(conn); if (capacity == -1) { final String msg = "Pool capacity is -1! pool: " + pool.getHost() + pool.getPath(); - s_logger.warn(msg); + logger.warn(msg); return new Answer(command, false, msg); } final Map tInfo = new HashMap(); @@ -69,12 +67,12 @@ public Answer execute(final ModifyStoragePoolCommand command, final CitrixResour } catch (final XenAPIException e) { final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(command, false, msg); } catch (final Exception e) { final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(command, false, msg); } } else { @@ -91,12 +89,12 @@ public Answer execute(final ModifyStoragePoolCommand command, final CitrixResour } catch (final XenAPIException e) { final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(command, false, msg); } catch (final Exception e) { final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new Answer(command, false, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixNetworkElementCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixNetworkElementCommandWrapper.java index 184187a051c8..2efe38417754 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixNetworkElementCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixNetworkElementCommandWrapper.java @@ -25,11 +25,9 @@ import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; -import org.apache.log4j.Logger; @ResourceWrapper(handles = NetworkElementCommand.class) public final class CitrixNetworkElementCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixNetworkElementCommandWrapper.class); @Override public Answer execute(final NetworkElementCommand command, final CitrixResourceBase citrixResourceBase) { final VirtualRoutingResource routingResource = citrixResourceBase.getVirtualRoutingResource(); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsCreateGreTunnelCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsCreateGreTunnelCommandWrapper.java index 45ddda278150..2e87f03c7e93 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsCreateGreTunnelCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsCreateGreTunnelCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = OvsCreateGreTunnelCommand.class) public final class CitrixOvsCreateGreTunnelCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsCreateGreTunnelCommandWrapper.class); @Override public Answer execute(final OvsCreateGreTunnelCommand command, final CitrixResourceBase citrixResourceBase) { @@ -57,11 +55,11 @@ public Answer execute(final OvsCreateGreTunnelCommand command, final CitrixResou return new OvsCreateGreTunnelAnswer(command, true, result, citrixResourceBase.getHost().getIp(), bridge, Integer.parseInt(res[1])); } } catch (final BadServerResponse e) { - s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e); + logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e); } catch (final XenAPIException e) { - s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e); + logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e); } catch (final XmlRpcException e) { - s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e); + logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e); } return new OvsCreateGreTunnelAnswer(command, false, "EXCEPTION", citrixResourceBase.getHost().getIp(), bridge); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsCreateTunnelCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsCreateTunnelCommandWrapper.java index f051b5cc1d4d..98888c248e1a 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsCreateTunnelCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsCreateTunnelCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsCreateTunnelAnswer; @@ -33,7 +32,6 @@ @ResourceWrapper(handles = OvsCreateTunnelCommand.class) public final class CitrixOvsCreateTunnelCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsCreateTunnelCommandWrapper.class); @Override public Answer execute(final OvsCreateTunnelCommand command, final CitrixResourceBase citrixResourceBase) { @@ -42,7 +40,7 @@ public Answer execute(final OvsCreateTunnelCommand command, final CitrixResource try { final Network nw = citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getNetworkName()); if (nw == null) { - s_logger.debug("Error during bridge setup"); + logger.debug("Error during bridge setup"); return new OvsCreateTunnelAnswer(command, false, "Cannot create network", bridge); } @@ -61,8 +59,8 @@ public Answer execute(final OvsCreateTunnelCommand command, final CitrixResource return new OvsCreateTunnelAnswer(command, false, result, bridge); } } catch (final Exception e) { - s_logger.debug("Error during tunnel setup"); - s_logger.warn("Caught execption when creating ovs tunnel", e); + logger.debug("Error during tunnel setup"); + logger.warn("Caught execption when creating ovs tunnel", e); return new OvsCreateTunnelAnswer(command, false, e.getMessage(), bridge); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDeleteFlowCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDeleteFlowCommandWrapper.java index 511b870ffba6..bcf7170e908a 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDeleteFlowCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDeleteFlowCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -35,7 +34,6 @@ @ResourceWrapper(handles = OvsDeleteFlowCommand.class) public final class CitrixOvsDeleteFlowCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsDeleteFlowCommandWrapper.class); @Override public Answer execute(final OvsDeleteFlowCommand command, final CitrixResourceBase citrixResourceBase) { @@ -53,11 +51,11 @@ public Answer execute(final OvsDeleteFlowCommand command, final CitrixResourceBa return new Answer(command, false, result); } } catch (final BadServerResponse e) { - s_logger.error("Failed to delete flow", e); + logger.error("Failed to delete flow", e); } catch (final XenAPIException e) { - s_logger.error("Failed to delete flow", e); + logger.error("Failed to delete flow", e); } catch (final XmlRpcException e) { - s_logger.error("Failed to delete flow", e); + logger.error("Failed to delete flow", e); } return new Answer(command, false, "failed to delete flow for " + command.getVmName()); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDestroyBridgeCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDestroyBridgeCommandWrapper.java index 4aaa9c845de6..ceac995b5588 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDestroyBridgeCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDestroyBridgeCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsDestroyBridgeCommand; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = OvsDestroyBridgeCommand.class) public final class CitrixOvsDestroyBridgeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsDestroyBridgeCommandWrapper.class); @Override public Answer execute(final OvsDestroyBridgeCommand command, final CitrixResourceBase citrixResourceBase) { @@ -44,11 +42,11 @@ public Answer execute(final OvsDestroyBridgeCommand command, final CitrixResourc citrixResourceBase.destroyTunnelNetwork(conn, nw, command.getHostId()); - s_logger.debug("OVS Bridge destroyed"); + logger.debug("OVS Bridge destroyed"); return new Answer(command, true, null); } catch (final Exception e) { - s_logger.warn("caught execption when destroying ovs bridge", e); + logger.warn("caught execption when destroying ovs bridge", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDestroyTunnelCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDestroyTunnelCommandWrapper.java index dffeeda91e65..c54c27db4bf5 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDestroyTunnelCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsDestroyTunnelCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsDestroyTunnelCommand; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = OvsDestroyTunnelCommand.class) public final class CitrixOvsDestroyTunnelCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsDestroyTunnelCommandWrapper.class); @Override public Answer execute(final OvsDestroyTunnelCommand command, final CitrixResourceBase citrixResourceBase) { @@ -40,7 +38,7 @@ public Answer execute(final OvsDestroyTunnelCommand command, final CitrixResourc try { final Network nw = citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getBridgeName()); if (nw == null) { - s_logger.warn("Unable to find tunnel network for GRE key:" + command.getBridgeName()); + logger.warn("Unable to find tunnel network for GRE key:" + command.getBridgeName()); return new Answer(command, false, "No network found"); } @@ -53,7 +51,7 @@ public Answer execute(final OvsDestroyTunnelCommand command, final CitrixResourc return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught execption when destroy ovs tunnel", e); + logger.warn("caught execption when destroy ovs tunnel", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsFetchInterfaceCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsFetchInterfaceCommandWrapper.java index 4a03acfc1a7e..3a1f3971d32e 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsFetchInterfaceCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsFetchInterfaceCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -38,7 +37,6 @@ @ResourceWrapper(handles = OvsFetchInterfaceCommand.class) public final class CitrixOvsFetchInterfaceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsFetchInterfaceCommandWrapper.class); @Override public Answer execute(final OvsFetchInterfaceCommand command, final CitrixResourceBase citrixResourceBase) { @@ -47,26 +45,26 @@ public Answer execute(final OvsFetchInterfaceCommand command, final CitrixResour if (citrixResourceBase.isXcp()) { label = citrixResourceBase.getLabel(); } - s_logger.debug("Will look for network with name-label:" + label + " on host " + citrixResourceBase.getHost().getIp()); + logger.debug("Will look for network with name-label:" + label + " on host " + citrixResourceBase.getHost().getIp()); final Connection conn = citrixResourceBase.getConnection(); try { final XsLocalNetwork nw = citrixResourceBase.getNetworkByName(conn, label); if(nw == null) { throw new CloudRuntimeException("Unable to locate the network with name-label: " + label + " on host: " + citrixResourceBase.getHost().getIp()); } - s_logger.debug("Network object:" + nw.getNetwork().getUuid(conn)); + logger.debug("Network object:" + nw.getNetwork().getUuid(conn)); final PIF pif = nw.getPif(conn); final PIF.Record pifRec = pif.getRecord(conn); - s_logger.debug("PIF object:" + pifRec.uuid + "(" + pifRec.device + ")"); + logger.debug("PIF object:" + pifRec.uuid + "(" + pifRec.device + ")"); return new OvsFetchInterfaceAnswer(command, true, "Interface " + pifRec.device + " retrieved successfully", pifRec.IP, pifRec.netmask, pifRec.MAC); } catch (final BadServerResponse e) { - s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); + logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage()); } catch (final XenAPIException e) { - s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); + logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage()); } catch (final XmlRpcException e) { - s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); + logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e); return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsSetTagAndFlowCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsSetTagAndFlowCommandWrapper.java index 14e43f301dcb..d389056f2aa0 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsSetTagAndFlowCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsSetTagAndFlowCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = OvsSetTagAndFlowCommand.class) public final class CitrixOvsSetTagAndFlowCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsSetTagAndFlowCommandWrapper.class); @Override public Answer execute(final OvsSetTagAndFlowCommand command, final CitrixResourceBase citrixResourceBase) { @@ -54,7 +52,7 @@ public Answer execute(final OvsSetTagAndFlowCommand command, final CitrixResourc */ final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_set_tag_and_flow", "bridge", bridge, "vmName", command.getVmName(), "tag", command.getTag(), "vlans", command.getVlans(), "seqno", command.getSeqNo()); - s_logger.debug("set flow for " + command.getVmName() + " " + result); + logger.debug("set flow for " + command.getVmName() + " " + result); if (result != null && result.equalsIgnoreCase("SUCCESS")) { return new OvsSetTagAndFlowAnswer(command, true, result); @@ -62,11 +60,11 @@ public Answer execute(final OvsSetTagAndFlowCommand command, final CitrixResourc return new OvsSetTagAndFlowAnswer(command, false, result); } } catch (final BadServerResponse e) { - s_logger.error("Failed to set tag and flow", e); + logger.error("Failed to set tag and flow", e); } catch (final XenAPIException e) { - s_logger.error("Failed to set tag and flow", e); + logger.error("Failed to set tag and flow", e); } catch (final XmlRpcException e) { - s_logger.error("Failed to set tag and flow", e); + logger.error("Failed to set tag and flow", e); } return new OvsSetTagAndFlowAnswer(command, false, "EXCEPTION"); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsSetupBridgeCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsSetupBridgeCommandWrapper.java index c3a54a0ceed9..0eb57c4f7e71 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsSetupBridgeCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsSetupBridgeCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsSetupBridgeCommand; @@ -31,7 +30,6 @@ @ResourceWrapper(handles = OvsSetupBridgeCommand.class) public final class CitrixOvsSetupBridgeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsSetupBridgeCommandWrapper.class); @Override public Answer execute(final OvsSetupBridgeCommand command, final CitrixResourceBase citrixResourceBase) { @@ -40,7 +38,7 @@ public Answer execute(final OvsSetupBridgeCommand command, final CitrixResourceB citrixResourceBase.findOrCreateTunnelNetwork(conn, command.getBridgeName()); citrixResourceBase.configureTunnelNetwork(conn, command.getNetworkId(), command.getHostId(), command.getBridgeName()); - s_logger.debug("OVS Bridge configured"); + logger.debug("OVS Bridge configured"); return new Answer(command, true, null); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsVpcPhysicalTopologyConfigCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsVpcPhysicalTopologyConfigCommandWrapper.java index d95a1fd5891f..034d35087300 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsVpcPhysicalTopologyConfigCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsVpcPhysicalTopologyConfigCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = OvsVpcPhysicalTopologyConfigCommand.class) public final class CitrixOvsVpcPhysicalTopologyConfigCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsVpcPhysicalTopologyConfigCommandWrapper.class); @Override public Answer execute(final OvsVpcPhysicalTopologyConfigCommand command, final CitrixResourceBase citrixResourceBase) { @@ -52,7 +50,7 @@ public Answer execute(final OvsVpcPhysicalTopologyConfigCommand command, final C return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught exception while updating host with latest VPC topology", e); + logger.warn("caught exception while updating host with latest VPC topology", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsVpcRoutingPolicyConfigCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsVpcRoutingPolicyConfigCommandWrapper.java index 9193e029e14c..da6c7bef5554 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsVpcRoutingPolicyConfigCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixOvsVpcRoutingPolicyConfigCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand; @@ -32,7 +31,6 @@ @ResourceWrapper(handles = OvsVpcRoutingPolicyConfigCommand.class) public final class CitrixOvsVpcRoutingPolicyConfigCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final OvsVpcRoutingPolicyConfigCommand command, final CitrixResourceBase citrixResourceBase) { @@ -52,7 +50,7 @@ public Answer execute(final OvsVpcRoutingPolicyConfigCommand command, final Citr return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught exception while updating host with latest routing policies", e); + logger.warn("caught exception while updating host with latest routing policies", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPatchSystemVmCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPatchSystemVmCommandWrapper.java index 0f37bea15cb8..02f332654adb 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPatchSystemVmCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPatchSystemVmCommandWrapper.java @@ -29,13 +29,11 @@ import com.cloud.utils.validation.ChecksumUtil; import com.xensource.xenapi.Connection; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; @ResourceWrapper(handles = PatchSystemVmCommand.class) public class CitrixPatchSystemVmCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixPatchSystemVmCommandWrapper.class); private static int sshPort = CitrixResourceBase.DEFAULTDOMRSSHPORT; private static File pemFile = new File(CitrixResourceBase.SSHPRVKEYPATH); @@ -62,7 +60,7 @@ public Answer execute(PatchSystemVmCommand command, CitrixResourceBase serverRes String checksum = ChecksumUtil.calculateCurrentChecksum(sysVMName, "vms/cloud-scripts.tgz").trim(); if (!StringUtils.isEmpty(checksum) && checksum.equals(scriptChecksum) && !command.isForced()) { String msg = String.format("No change in the scripts checksum, not patching systemVM %s", sysVMName); - s_logger.info(msg); + logger.info(msg); return new PatchSystemVmAnswer(command, msg, lines[0], lines[1]); } @@ -79,7 +77,7 @@ public Answer execute(PatchSystemVmCommand command, CitrixResourceBase serverRes String res = patchResult.replace("\n", " "); String[] output = res.split(":"); if (output.length != 2) { - s_logger.warn("Failed to get the latest script version"); + logger.warn("Failed to get the latest script version"); } else { scriptVersion = output[1].split(" ")[0]; } @@ -96,12 +94,12 @@ private ExecutionResult getSystemVmVersionAndChecksum(CitrixResourceBase serverR result = serverResource.executeInVR(controlIp, VRScripts.VERSION, null); if (!result.isSuccess()) { String errMsg = String.format("GetSystemVMVersionCmd on %s failed, message %s", controlIp, result.getDetails()); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (final Exception e) { final String msg = "GetSystemVMVersionCmd failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg, e); } return result; diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPlugNicCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPlugNicCommandWrapper.java index 6e954be805f5..2fc3aa517d8d 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPlugNicCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPlugNicCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.PlugNicAnswer; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = PlugNicCommand.class) public final class CitrixPlugNicCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixPlugNicCommandWrapper.class); @Override public Answer execute(final PlugNicCommand command, final CitrixResourceBase citrixResourceBase) { @@ -67,7 +65,7 @@ public Answer execute(final PlugNicCommand command, final CitrixResourceBase cit // redundant. if (counter > 2) { final String msg = " Plug Nic failed due to a VIF with the same mac " + nic.getMac() + " exists in more than 2 routers."; - s_logger.error(msg); + logger.error(msg); return new PlugNicAnswer(command, false, msg); } @@ -75,7 +73,7 @@ public Answer execute(final PlugNicCommand command, final CitrixResourceBase cit // VIF vif = getVifByMac(conn, vm, nic.getMac()); // if (vif != null) { // final String msg = " Plug Nic failed due to a VIF with the same mac " + nic.getMac() + " exists"; - // s_logger.warn(msg); + // logger.warn(msg); // return new PlugNicAnswer(cmd, false, msg); // } @@ -87,7 +85,7 @@ public Answer execute(final PlugNicCommand command, final CitrixResourceBase cit return new PlugNicAnswer(command, true, "success"); } catch (final Exception e) { final String msg = " Plug Nic failed due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new PlugNicAnswer(command, false, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPrepareForMigrationCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPrepareForMigrationCommandWrapper.java index 8a8ebb418058..806016a21d9f 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPrepareForMigrationCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPrepareForMigrationCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.PrepareForMigrationAnswer; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = PrepareForMigrationCommand.class) public final class CitrixPrepareForMigrationCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixPrepareForMigrationCommandWrapper.class); @Override public Answer execute(final PrepareForMigrationCommand command, final CitrixResourceBase citrixResourceBase) { @@ -50,8 +48,8 @@ public Answer execute(final PrepareForMigrationCommand command, final CitrixReso configDriveLabel = "config-2"; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Preparing host for migrating " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Preparing host for migrating " + vm); } final NicTO[] nics = vm.getNics(); @@ -61,11 +59,11 @@ public Answer execute(final PrepareForMigrationCommand command, final CitrixReso for (final NicTO nic : nics) { citrixResourceBase.getNetwork(conn, nic); } - s_logger.debug("4. The VM " + vm.getName() + " is in Migrating state"); + logger.debug("4. The VM " + vm.getName() + " is in Migrating state"); return new PrepareForMigrationAnswer(command); } catch (final Exception e) { - s_logger.warn("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to " + e.toString(), e); + logger.warn("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to " + e.toString(), e); return new PrepareForMigrationAnswer(command, e); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPrimaryStorageDownloadCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPrimaryStorageDownloadCommandWrapper.java index 23be5eb1dcdb..b5a145a9ecab 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPrimaryStorageDownloadCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPrimaryStorageDownloadCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer; @@ -38,7 +37,6 @@ @ResourceWrapper(handles = PrimaryStorageDownloadCommand.class) public final class CitrixPrimaryStorageDownloadCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixPrimaryStorageDownloadCommandWrapper.class); @Override public Answer execute(final PrimaryStorageDownloadCommand command, final CitrixResourceBase citrixResourceBase) { @@ -53,7 +51,7 @@ public Answer execute(final PrimaryStorageDownloadCommand command, final CitrixR final Set srs = SR.getByNameLabel(conn, poolName); if (srs.size() != 1) { final String msg = "There are " + srs.size() + " SRs with same name: " + poolName; - s_logger.warn(msg); + logger.warn(msg); return new PrimaryStorageDownloadAnswer(msg); } else { poolsr = srs.iterator().next(); @@ -78,7 +76,7 @@ public Answer execute(final PrimaryStorageDownloadCommand command, final CitrixR } catch (final Exception e) { final String msg = "Catch Exception " + e.getClass().getName() + " on host:" + citrixResourceBase.getHost().getUuid() + " for template: " + tmplturl + " due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new PrimaryStorageDownloadAnswer(msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPvlanSetupCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPvlanSetupCommandWrapper.java index 313cb4e34e4a..2873f3f99a84 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPvlanSetupCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixPvlanSetupCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = PvlanSetupCommand.class) public final class CitrixPvlanSetupCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixPvlanSetupCommandWrapper.class); @Override public Answer execute(final PvlanSetupCommand command, final CitrixResourceBase citrixResourceBase) { @@ -55,15 +53,15 @@ public Answer execute(final PvlanSetupCommand command, final CitrixResourceBase try { final XsLocalNetwork nw = citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag); if (nw == null) { - s_logger.error("Network is not configured on the backend for pvlan " + primaryPvlan); + logger.error("Network is not configured on the backend for pvlan " + primaryPvlan); throw new CloudRuntimeException("Network for the backend is not configured correctly for pvlan primary: " + primaryPvlan); } nwNameLabel = nw.getNetwork().getNameLabel(conn); } catch (final XenAPIException e) { - s_logger.warn("Fail to get network", e); + logger.warn("Fail to get network", e); return new Answer(command, false, e.toString()); } catch (final XmlRpcException e) { - s_logger.warn("Fail to get network", e); + logger.warn("Fail to get network", e); return new Answer(command, false, e.toString()); } @@ -73,20 +71,20 @@ public Answer execute(final PvlanSetupCommand command, final CitrixResourceBase isolatedPvlan, "dhcp-name", dhcpName, "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac); if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { - s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac); + logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac); return new Answer(command, false, result); } else { - s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac); + logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac); } } else if (command.getType() == PvlanSetupCommand.Type.VM) { result = citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", nwNameLabel, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac); if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { - s_logger.warn("Failed to program pvlan for vm with mac " + vmMac); + logger.warn("Failed to program pvlan for vm with mac " + vmMac); return new Answer(command, false, result); } else { - s_logger.info("Programmed pvlan for vm with mac " + vmMac); + logger.info("Programmed pvlan for vm with mac " + vmMac); } } return new Answer(command, true, result); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixReadyCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixReadyCommandWrapper.java index c276aff5fc2e..e7f7e00e6ae7 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixReadyCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixReadyCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.Set; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import static com.cloud.hypervisor.xenserver.discoverer.XcpServerDiscoverer.isUefiSupported; @@ -43,7 +42,6 @@ @ResourceWrapper(handles = ReadyCommand.class) public final class CitrixReadyCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixReadyCommandWrapper.class); @Override public Answer execute(final ReadyCommand command, final CitrixResourceBase citrixResourceBase) { @@ -74,10 +72,10 @@ public Answer execute(final ReadyCommand command, final CitrixResourceBase citri return new ReadyAnswer(command, "Unable to cleanup halted vms"); } } catch (final XenAPIException e) { - s_logger.warn("Unable to cleanup halted vms", e); + logger.warn("Unable to cleanup halted vms", e); return new ReadyAnswer(command, "Unable to cleanup halted vms"); } catch (final XmlRpcException e) { - s_logger.warn("Unable to cleanup halted vms", e); + logger.warn("Unable to cleanup halted vms", e); return new ReadyAnswer(command, "Unable to cleanup halted vms"); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRebootCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRebootCommandWrapper.java index 6d5b9f7992d1..3ea832cadf7c 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRebootCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRebootCommandWrapper.java @@ -21,7 +21,6 @@ import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.RebootAnswer; @@ -36,21 +35,20 @@ @ResourceWrapper(handles = RebootCommand.class) public final class CitrixRebootCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixRebootCommandWrapper.class); @Override public Answer execute(final RebootCommand command, final CitrixResourceBase citrixResourceBase) { final Connection conn = citrixResourceBase.getConnection(); - s_logger.debug("7. The VM " + command.getVmName() + " is in Starting state"); + logger.debug("7. The VM " + command.getVmName() + " is in Starting state"); try { Set vms = null; try { vms = VM.getByNameLabel(conn, command.getVmName()); } catch (final XenAPIException e0) { - s_logger.debug("getByNameLabel failed " + e0.toString()); + logger.debug("getByNameLabel failed " + e0.toString()); return new RebootAnswer(command, "getByNameLabel failed " + e0.toString(), false); } catch (final Exception e0) { - s_logger.debug("getByNameLabel failed " + e0.getMessage()); + logger.debug("getByNameLabel failed " + e0.getMessage()); return new RebootAnswer(command, "getByNameLabel failed", false); } for (final VM vm : vms) { @@ -58,13 +56,13 @@ public Answer execute(final RebootCommand command, final CitrixResourceBase citr citrixResourceBase.rebootVM(conn, vm, vm.getNameLabel(conn)); } catch (final Exception e) { final String msg = e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new RebootAnswer(command, msg, false); } } return new RebootAnswer(command, "reboot succeeded", true); } finally { - s_logger.debug("8. The VM " + command.getVmName() + " is in Running state"); + logger.debug("8. The VM " + command.getVmName() + " is in Running state"); } } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java index e7505cc2f34e..2ddf1bd18511 100755 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.ResizeVolumeAnswer; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = ResizeVolumeCommand.class) public final class CitrixResizeVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixResizeVolumeCommandWrapper.class); @Override public Answer execute(final ResizeVolumeCommand command, final CitrixResourceBase citrixResourceBase) { @@ -52,7 +50,7 @@ public Answer execute(final ResizeVolumeCommand command, final CitrixResourceBas try { if (command.getCurrentSize() >= newSize) { - s_logger.info("No need to resize volume: " + volId +", current size " + toHumanReadableSize(command.getCurrentSize()) + " is same as new size " + toHumanReadableSize(newSize)); + logger.info("No need to resize volume: " + volId +", current size " + toHumanReadableSize(command.getCurrentSize()) + " is same as new size " + toHumanReadableSize(newSize)); return new ResizeVolumeAnswer(command, true, "success", newSize); } if (command.isManaged()) { @@ -65,7 +63,7 @@ public Answer execute(final ResizeVolumeCommand command, final CitrixResourceBas return new ResizeVolumeAnswer(command, true, "success", newSize); } catch (Exception ex) { - s_logger.warn("Unable to resize volume", ex); + logger.warn("Unable to resize volume", ex); String error = "Failed to resize volume: " + ex; @@ -91,7 +89,7 @@ private void resizeSr(Connection conn, ResizeVolumeCommand command) { Set pbds = sr.getPBDs(conn); if (pbds.size() <= 0) { - s_logger.debug("No PBDs found for the following SR: " + sr.getNameLabel(conn)); + logger.debug("No PBDs found for the following SR: " + sr.getNameLabel(conn)); } allPbds.addAll(pbds); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRevertToVMSnapshotCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRevertToVMSnapshotCommandWrapper.java index f8bb1b892420..be5139390c9e 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRevertToVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRevertToVMSnapshotCommandWrapper.java @@ -25,7 +25,6 @@ import java.util.Set; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.RevertToVMSnapshotAnswer; @@ -44,7 +43,6 @@ @ResourceWrapper(handles = RevertToVMSnapshotCommand.class) public final class CitrixRevertToVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixRevertToVMSnapshotCommandWrapper.class); @Override public Answer execute(final RevertToVMSnapshotCommand command, final CitrixResourceBase citrixResourceBase) { @@ -105,7 +103,7 @@ public Answer execute(final RevertToVMSnapshotCommand command, final CitrixResou return new RevertToVMSnapshotAnswer(command, listVolumeTo, vmState); } catch (final Exception e) { - s_logger.error("revert vm " + vmName + " to snapshot " + command.getTarget().getSnapshotName() + " failed due to " + e.getMessage()); + logger.error("revert vm " + vmName + " to snapshot " + command.getTarget().getSnapshotName() + " failed due to " + e.getMessage()); return new RevertToVMSnapshotAnswer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixScaleVmCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixScaleVmCommandWrapper.java index 8aa77277c786..d1ca2ee437b5 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixScaleVmCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixScaleVmCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.Iterator; import java.util.Set; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -42,7 +41,6 @@ @ResourceWrapper(handles = ScaleVmCommand.class) public final class CitrixScaleVmCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixScaleVmCommandWrapper.class); @Override public Answer execute(final ScaleVmCommand command, final CitrixResourceBase citrixResourceBase) { @@ -60,7 +58,7 @@ public Answer execute(final ScaleVmCommand command, final CitrixResourceBase cit } if (vms == null || vms.size() == 0) { - s_logger.info("No running VM " + vmName + " exists on XenServer" + citrixResourceBase.getHost().getUuid()); + logger.info("No running VM " + vmName + " exists on XenServer" + citrixResourceBase.getHost().getUuid()); return new ScaleVmAnswer(command, false, "VM does not exist"); } @@ -82,26 +80,26 @@ public Answer execute(final ScaleVmCommand command, final CitrixResourceBase cit citrixResourceBase.scaleVM(conn, vm, vmSpec, host); } catch (final Exception e) { final String msg = "Catch exception " + e.getClass().getName() + " when scaling VM:" + vmName + " due to " + e.toString(); - s_logger.debug(msg); + logger.debug(msg); return new ScaleVmAnswer(command, false, msg); } } final String msg = "scaling VM " + vmName + " is successful on host " + host; - s_logger.debug(msg); + logger.debug(msg); return new ScaleVmAnswer(command, true, msg); } catch (final XenAPIException e) { final String msg = "Upgrade Vm " + vmName + " fail due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new ScaleVmAnswer(command, false, msg); } catch (final XmlRpcException e) { final String msg = "Upgrade Vm " + vmName + " fail due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new ScaleVmAnswer(command, false, msg); } catch (final Exception e) { final String msg = "Unable to upgrade " + vmName + " due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new ScaleVmAnswer(command, false, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSecurityGroupRulesCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSecurityGroupRulesCommandWrapper.java index 00974d75b72f..816d9703b98d 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSecurityGroupRulesCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSecurityGroupRulesCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.SecurityGroupRuleAnswer; @@ -32,17 +31,16 @@ @ResourceWrapper(handles = SecurityGroupRulesCmd.class) public final class CitrixSecurityGroupRulesCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixSecurityGroupRulesCommandWrapper.class); @Override public Answer execute(final SecurityGroupRulesCmd command, final CitrixResourceBase citrixResourceBase) { final Connection conn = citrixResourceBase.getConnection(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Sending network rules command to " + citrixResourceBase.getHost().getIp()); + if (logger.isTraceEnabled()) { + logger.trace("Sending network rules command to " + citrixResourceBase.getHost().getIp()); } if (!citrixResourceBase.canBridgeFirewall()) { - s_logger.warn("Host " + citrixResourceBase.getHost().getIp() + " cannot do bridge firewalling"); + logger.warn("Host " + citrixResourceBase.getHost().getIp() + " cannot do bridge firewalling"); return new SecurityGroupRuleAnswer(command, false, "Host " + citrixResourceBase.getHost().getIp() + " cannot do bridge firewalling", SecurityGroupRuleAnswer.FailureReason.CANNOT_BRIDGE_FIREWALL); } @@ -52,10 +50,10 @@ public Answer execute(final SecurityGroupRulesCmd command, final CitrixResourceB "true", "rules", command.compressStringifiedRules(), "secIps", command.getSecIpsString()); if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { - s_logger.warn("Failed to program network rules for vm " + command.getVmName()); + logger.warn("Failed to program network rules for vm " + command.getVmName()); return new SecurityGroupRuleAnswer(command, false, "programming network rules failed"); } else { - s_logger.info("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp() + ", ingress numrules=" + logger.info("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp() + ", ingress numrules=" + command.getIngressRuleSet().size() + ", egress numrules=" + command.getEgressRuleSet().size()); return new SecurityGroupRuleAnswer(command); } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupCommandWrapper.java index 263dade328eb..57daba4da41d 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupCommandWrapper.java @@ -22,7 +22,6 @@ import java.util.Map; import java.util.Set; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -45,7 +44,6 @@ @ResourceWrapper(handles = SetupCommand.class) public final class CitrixSetupCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixSetupCommandWrapper.class); @Override public Answer execute(final SetupCommand command, final CitrixResourceBase citrixResourceBase) { @@ -61,7 +59,7 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri citrixResourceBase.setupServer(conn, host); if (!citrixResourceBase.setIptables(conn)) { - s_logger.warn("set xenserver Iptable failed"); + logger.warn("set xenserver Iptable failed"); return null; } @@ -70,8 +68,8 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri citrixResourceBase.setCanBridgeFirewall(canBridgeFirewall); if (!canBridgeFirewall) { final String msg = "Failed to configure bridge firewall"; - s_logger.warn(msg); - s_logger.warn("Check host " + citrixResourceBase.getHost().getIp() +" for CSP is installed or not and check network mode for bridge"); + logger.warn(msg); + logger.warn("Check host " + citrixResourceBase.getHost().getIp() +" for CSP is installed or not and check network mode for bridge"); return new SetupAnswer(command, msg); } @@ -90,14 +88,14 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri } } catch (final Types.MapDuplicateKey e) { - s_logger.debug("multipath is already set"); + logger.debug("multipath is already set"); } if (command.needSetup() ) { final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "setup_iscsi", "uuid", citrixResourceBase.getHost().getUuid()); if (!result.contains("> DONE <")) { - s_logger.warn("Unable to setup iscsi: " + result); + logger.warn("Unable to setup iscsi: " + result); return new SetupAnswer(command, result); } @@ -114,11 +112,11 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri .append("; vlan=") .append(rec.VLAN) .toString(); - s_logger.warn(msg); + logger.warn(msg); return new SetupAnswer(command, msg); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Management network is on pif=" + rec.uuid); + if (logger.isDebugEnabled()) { + logger.debug("Management network is on pif=" + rec.uuid); } mgmtPif = new Pair(pif, rec); break; @@ -127,14 +125,14 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri if (mgmtPif == null) { final String msg = "Unable to find management network for " + citrixResourceBase.getHost().getUuid(); - s_logger.warn(msg); + logger.warn(msg); return new SetupAnswer(command, msg); } final Map networks = Network.getAllRecords(conn); if(networks == null) { final String msg = "Unable to setup as there are no networks in the host: " + citrixResourceBase.getHost().getUuid(); - s_logger.warn(msg); + logger.warn(msg); return new SetupAnswer(command, msg); } for (final Network.Record network : networks.values()) { @@ -142,8 +140,8 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri for (final PIF pif : network.PIFs) { final PIF.Record pr = pif.getRecord(conn); if (citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found a network called cloud-private. host=" + citrixResourceBase.getHost().getUuid() + "; Network=" + network.uuid + "; pif=" + pr.uuid); + if (logger.isDebugEnabled()) { + logger.debug("Found a network called cloud-private. host=" + citrixResourceBase.getHost().getUuid() + "; Network=" + network.uuid + "; pif=" + pr.uuid); } if (pr.VLAN != null && pr.VLAN != -1) { final String msg = @@ -151,7 +149,7 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri .append(" ; pif=") .append(pr.uuid) .toString(); - s_logger.warn(msg); + logger.warn(msg); return new SetupAnswer(command, msg); } if (!pr.management && pr.bondMasterOf != null && pr.bondMasterOf.size() > 0) { @@ -161,7 +159,7 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri .append("; pif=") .append(pr.uuid) .toString(); - s_logger.warn(msg); + logger.warn(msg); return new SetupAnswer(command, msg); } final Bond bond = pr.bondMasterOf.iterator().next(); @@ -173,7 +171,7 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri final String msg = new StringBuilder("Unable to transfer management network. slave=" + spr.uuid + "; master=" + pr.uuid + "; host=" + citrixResourceBase.getHost().getUuid()).toString(); - s_logger.warn(msg); + logger.warn(msg); return new SetupAnswer(command, msg); } break; @@ -188,13 +186,13 @@ public Answer execute(final SetupCommand command, final CitrixResourceBase citri return new SetupAnswer(command, false); } catch (final XmlRpcException e) { - s_logger.warn("Unable to setup", e); + logger.warn("Unable to setup", e); return new SetupAnswer(command, e.getMessage()); } catch (final XenAPIException e) { - s_logger.warn("Unable to setup", e); + logger.warn("Unable to setup", e); return new SetupAnswer(command, e.getMessage()); } catch (final Exception e) { - s_logger.warn("Unable to setup", e); + logger.warn("Unable to setup", e); return new SetupAnswer(command, e.getMessage()); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupPersistentNetworkCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupPersistentNetworkCommandWrapper.java index cab5a080949c..7c84d44c49f8 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupPersistentNetworkCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixSetupPersistentNetworkCommandWrapper.java @@ -18,7 +18,6 @@ package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.SetupPersistentNetworkAnswer; @@ -33,7 +32,6 @@ @ResourceWrapper(handles = SetupPersistentNetworkCommand.class) public class CitrixSetupPersistentNetworkCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixSetupPersistentNetworkCommandWrapper.class); @Override public Answer execute(SetupPersistentNetworkCommand command, CitrixResourceBase citrixResourceBase) { @@ -47,7 +45,7 @@ public Answer execute(SetupPersistentNetworkCommand command, CitrixResourceBase return new SetupPersistentNetworkAnswer(command, true, "Successfully setup network on host: "+ host.getIp()); } catch (final Exception e) { final String msg = " Failed to setup network on host: " + host.getIp() + " due to: " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new SetupPersistentNetworkAnswer(command, false, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStartCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStartCommandWrapper.java index ad76b7f4541a..33d4eaf6e777 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStartCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStartCommandWrapper.java @@ -28,7 +28,6 @@ import com.cloud.agent.resource.virtualnetwork.VRScripts; import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsSetTagAndFlowAnswer; @@ -57,7 +56,6 @@ @ResourceWrapper(handles = StartCommand.class) public final class CitrixStartCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixStartCommandWrapper.class); @Override public Answer execute(final StartCommand command, final CitrixResourceBase citrixResourceBase) { @@ -79,22 +77,22 @@ public Answer execute(final StartCommand command, final CitrixResourceBase citri } else if (vRec.powerState == VmPowerState.RUNNING) { final String host = vRec.residentOn.getUuid(conn); final String msg = "VM " + vmName + " is runing on host " + host; - s_logger.debug(msg); + logger.debug(msg); return new StartAnswer(command, msg, host); } else { final String msg = "There is already a VM having the same name " + vmName + " vm record " + vRec.toString(); - s_logger.warn(msg); + logger.warn(msg); return new StartAnswer(command, msg); } } } - s_logger.debug("1. The VM " + vmName + " is in Starting state."); + logger.debug("1. The VM " + vmName + " is in Starting state."); final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid()); vm = citrixResourceBase.createVmFromTemplate(conn, vmSpec, host); final GPUDeviceTO gpuDevice = vmSpec.getGpuDevice(); if (gpuDevice != null) { - s_logger.debug("Creating VGPU for of VGPU type: " + gpuDevice.getVgpuType() + " in GPU group " + gpuDevice.getGpuGroup() + " for VM " + vmName); + logger.debug("Creating VGPU for of VGPU type: " + gpuDevice.getVgpuType() + " in GPU group " + gpuDevice.getGpuGroup() + " for VM " + vmName); citrixResourceBase.createVGPU(conn, command, vm, gpuDevice); } @@ -123,9 +121,9 @@ public Answer execute(final StartCommand command, final CitrixResourceBase citri final OvsSetTagAndFlowAnswer r = (OvsSetTagAndFlowAnswer) citrixRequestWrapper.execute(flowCmd, citrixResourceBase); if (!r.getResult()) { - s_logger.warn("Failed to set flow for VM " + r.getVmId()); + logger.warn("Failed to set flow for VM " + r.getVmId()); } else { - s_logger.info("Success to set flow for VM " + r.getVmId()); + logger.info("Success to set flow for VM " + r.getVmId()); } } } @@ -145,9 +143,9 @@ public Answer execute(final StartCommand command, final CitrixResourceBase citri if (secGrpEnabled) { result = citrixResourceBase.callHostPlugin(conn, "vmops", "default_network_rules_systemvm", "vmName", vmName); if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { - s_logger.warn("Failed to program default network rules for " + vmName); + logger.warn("Failed to program default network rules for " + vmName); } else { - s_logger.info("Programmed default network rules for " + vmName); + logger.info("Programmed default network rules for " + vmName); } } @@ -172,9 +170,9 @@ public Answer execute(final StartCommand command, final CitrixResourceBase citri "vmID", Long.toString(vmSpec.getId()), "secIps", secIpsStr); if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { - s_logger.warn("Failed to program default network rules for " + vmName + " on nic with ip:" + nic.getIp() + " mac:" + nic.getMac()); + logger.warn("Failed to program default network rules for " + vmName + " on nic with ip:" + nic.getIp() + " mac:" + nic.getMac()); } else { - s_logger.info("Programmed default network rules for " + vmName + " on nic with ip:" + nic.getIp() + " mac:" + nic.getMac()); + logger.info("Programmed default network rules for " + vmName + " on nic with ip:" + nic.getIp() + " mac:" + nic.getMac()); } } } @@ -194,7 +192,7 @@ public Answer execute(final StartCommand command, final CitrixResourceBase citri String result2 = citrixResourceBase.connect(conn, vmName, controlIp, 1000); if (StringUtils.isEmpty(result2)) { - s_logger.info(String.format("Connected to SystemVM: %s", vmName)); + logger.info(String.format("Connected to SystemVM: %s", vmName)); } try { @@ -202,12 +200,12 @@ public Answer execute(final StartCommand command, final CitrixResourceBase citri VirtualRoutingResource vrResource = citrixResourceBase.getVirtualRoutingResource(); if (!vrResource.isSystemVMSetup(vmName, controlIp)) { String errMsg = "Failed to patch systemVM"; - s_logger.error(errMsg); + logger.error(errMsg); return new StartAnswer(command, errMsg); } } catch (Exception e) { String errMsg = "Failed to scp files to system VM. Patching of systemVM failed"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return new StartAnswer(command, String.format("%s due to: %s", errMsg, e.getMessage())); } } @@ -218,7 +216,7 @@ public Answer execute(final StartCommand command, final CitrixResourceBase citri return startAnswer; } catch (final Exception e) { - s_logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e); + logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e); final String msg = citrixResourceBase.handleVmStartFailure(conn, vmName, vm, "", e); final StartAnswer startAnswer = new StartAnswer(command, msg); @@ -228,9 +226,9 @@ public Answer execute(final StartCommand command, final CitrixResourceBase citri return startAnswer; } finally { if (state != VmPowerState.HALTED) { - s_logger.debug("2. The VM " + vmName + " is in " + state + " state."); + logger.debug("2. The VM " + vmName + " is in " + state + " state."); } else { - s_logger.debug("The VM is in stopped state, detected problem during startup : " + vmName); + logger.debug("The VM is in stopped state, detected problem during startup : " + vmName); } } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStopCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStopCommandWrapper.java index 8e7eb4caec29..955c3c347230 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStopCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStopCommandWrapper.java @@ -27,7 +27,6 @@ import java.util.Set; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.StopAnswer; @@ -50,7 +49,6 @@ @ResourceWrapper(handles = StopCommand.class) public final class CitrixStopCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixStopCommandWrapper.class); @Override public Answer execute(final StopCommand command, final CitrixResourceBase citrixResourceBase) { @@ -85,23 +83,23 @@ public Answer execute(final StopCommand command, final CitrixResourceBase citrix platformstring = StringUtils.mapToString(vmr.platform); if (vmr.isControlDomain) { final String msg = "Tring to Shutdown control domain"; - s_logger.warn(msg); + logger.warn(msg); return new StopAnswer(command, msg, false); } if (vmr.powerState == VmPowerState.RUNNING && !citrixResourceBase.isRefNull(vmr.residentOn) && !vmr.residentOn.getUuid(conn).equals(citrixResourceBase.getHost().getUuid())) { final String msg = "Stop Vm " + vmName + " failed due to this vm is not running on this host: " + citrixResourceBase.getHost().getUuid() + " but host:" + vmr.residentOn.getUuid(conn); - s_logger.warn(msg); + logger.warn(msg); return new StopAnswer(command, msg, platformstring, false); } if (command.checkBeforeCleanup() && vmr.powerState == VmPowerState.RUNNING) { final String msg = "Vm " + vmName + " is running on host and checkBeforeCleanup flag is set, so bailing out"; - s_logger.debug(msg); + logger.debug(msg); return new StopAnswer(command, msg, false); } - s_logger.debug("9. The VM " + vmName + " is in Stopping state"); + logger.debug("9. The VM " + vmName + " is in Stopping state"); try { if (vmr.powerState == VmPowerState.RUNNING) { @@ -111,16 +109,16 @@ public Answer execute(final StopCommand command, final CitrixResourceBase citrix if (citrixResourceBase.canBridgeFirewall()) { final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "destroy_network_rules_for_vm", "vmName", command.getVmName()); if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) { - s_logger.warn("Failed to remove network rules for vm " + command.getVmName()); + logger.warn("Failed to remove network rules for vm " + command.getVmName()); } else { - s_logger.info("Removed network rules for vm " + command.getVmName()); + logger.info("Removed network rules for vm " + command.getVmName()); } } citrixResourceBase.shutdownVM(conn, vm, vmName, command.isForceStop()); } } catch (final Exception e) { final String msg = "Catch exception " + e.getClass().getName() + " when stop VM:" + command.getVmName() + " due to " + e.toString(); - s_logger.debug(msg); + logger.debug(msg); return new StopAnswer(command, msg, platformstring, false); } finally { @@ -131,7 +129,7 @@ public Answer execute(final StopCommand command, final CitrixResourceBase citrix try { vGPUs = vm.getVGPUs(conn); } catch (final XenAPIException e2) { - s_logger.debug("VM " + vmName + " does not have GPU support."); + logger.debug("VM " + vmName + " does not have GPU support."); } if (vGPUs != null && !vGPUs.isEmpty()) { final HashMap> groupDetails = citrixResourceBase.getGPUGroupDetails(conn); @@ -164,16 +162,16 @@ public Answer execute(final StopCommand command, final CitrixResourceBase citrix } } catch (final Exception e) { final String msg = "VM destroy failed in Stop " + vmName + " Command due to " + e.getMessage(); - s_logger.warn(msg, e); + logger.warn(msg, e); } finally { - s_logger.debug("10. The VM " + vmName + " is in Stopped state"); + logger.debug("10. The VM " + vmName + " is in Stopped state"); } } } } catch (final Exception e) { final String msg = "Stop Vm " + vmName + " fail due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new StopAnswer(command, msg, platformstring, false); } return new StopAnswer(command, "Stop VM failed", platformstring, false); diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUnPlugNicCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUnPlugNicCommandWrapper.java index 28981413a723..0e7a0629ed01 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUnPlugNicCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUnPlugNicCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.Set; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; @@ -42,7 +41,6 @@ @ResourceWrapper(handles = UnPlugNicCommand.class) public final class CitrixUnPlugNicCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixUnPlugNicCommandWrapper.class); @Override public Answer execute(final UnPlugNicCommand command, final CitrixResourceBase citrixResourceBase) { @@ -73,7 +71,7 @@ public Answer execute(final UnPlugNicCommand command, final CitrixResourceBase c return new UnPlugNicAnswer(command, true, "success"); } catch (final Exception e) { final String msg = " UnPlug Nic failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new UnPlugNicAnswer(command, false, msg); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java index 39110b12a25d..1acc292b450b 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpdateHostPasswordCommandWrapper.java @@ -21,7 +21,6 @@ import static com.cloud.hypervisor.xenserver.resource.wrapper.xenbase.XenServerUtilitiesHelper.SCRIPT_CMD_PATH; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.UpdateHostPasswordCommand; @@ -34,7 +33,6 @@ @ResourceWrapper(handles = UpdateHostPasswordCommand.class) public final class CitrixUpdateHostPasswordCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixUpdateHostPasswordCommandWrapper.class); @Override public Answer execute(final UpdateHostPasswordCommand command, final CitrixResourceBase citrixResourceBase) { @@ -47,7 +45,7 @@ public Answer execute(final UpdateHostPasswordCommand command, final CitrixResou Pair result; try { - s_logger.debug("Executing command in Host: " + cmdLine); + logger.debug("Executing command in Host: " + cmdLine); final String hostPassword = citrixResourceBase.getPwdFromQueue(); result = xenServerUtilitiesHelper.executeSshWrapper(hostIp, 22, username, null, hostPassword, cmdLine.toString()); } catch (final Exception e) { diff --git a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpgradeSnapshotCommandWrapper.java b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpgradeSnapshotCommandWrapper.java index c5feef042162..9022e51ef6ba 100644 --- a/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpgradeSnapshotCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixUpgradeSnapshotCommandWrapper.java @@ -21,7 +21,6 @@ import java.net.URI; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.UpgradeSnapshotCommand; @@ -33,7 +32,6 @@ @ResourceWrapper(handles = UpgradeSnapshotCommand.class) public final class CitrixUpgradeSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(CitrixUpgradeSnapshotCommandWrapper.class); @Override public Answer execute(final UpgradeSnapshotCommand command, final CitrixResourceBase citrixResourceBase) { @@ -58,7 +56,7 @@ public Answer execute(final UpgradeSnapshotCommand command, final CitrixResource return new Answer(command, true, "success"); } catch (final Exception e) { final String details = "upgrading snapshot " + backedUpSnapshotUuid + " failed due to " + e.toString(); - s_logger.error(details, e); + logger.error(details, e); } return new Answer(command, false, "failure"); diff --git a/plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/hypervisor/xenserver/ExtraConfigurationUtility.java b/plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/hypervisor/xenserver/ExtraConfigurationUtility.java index a0a51b121c7a..97efbea02dff 100644 --- a/plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/hypervisor/xenserver/ExtraConfigurationUtility.java +++ b/plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/hypervisor/xenserver/ExtraConfigurationUtility.java @@ -18,7 +18,8 @@ import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xmlrpc.XmlRpcException; import com.cloud.exception.InvalidParameterValueException; @@ -29,7 +30,7 @@ import com.xensource.xenapi.VM; public class ExtraConfigurationUtility { - private static final Logger LOG = Logger.getLogger(ExtraConfigurationUtility.class); + protected static Logger LOGGER = LogManager.getLogger(ExtraConfigurationUtility.class); public static void setExtraConfigurationToVm(Connection conn, VM.Record vmr, VM vm, Map extraConfig) { Map recordMap = vmr.toMap(); @@ -38,7 +39,7 @@ public static void setExtraConfigurationToVm(Connection conn, VM.Record vmr, VM // cfg is either param=value or map-param:key=value Pair configParam = prepareKeyValuePair(cfg); if (configParam == null) { - LOG.warn("Invalid extra config passed: " + cfg); + LOGGER.warn("Invalid extra config passed: " + cfg); continue; } @@ -46,6 +47,8 @@ public static void setExtraConfigurationToVm(Connection conn, VM.Record vmr, VM String paramKey = configParam.first(); String paramValue = configParam.second(); + //Map params + LOGGER.debug("Applying [{}] configuration as [{}].", paramKey, paramValue); if (paramKey.contains(":")) { // Map params - paramKey is map-param:key applyConfigWithNestedKeyValue(conn, vm, recordMap, paramKey, paramValue); @@ -60,6 +63,11 @@ private static boolean isValidOperation(Map recordMap, String ac return recordMap.containsKey(actualParam); } + private static Map putInMap(Map map, String key, String value) { + map.put(key, value); + return map; + } + /** * Nested keys contain ":" between the paramKey and need to split into operation param and key * */ @@ -70,7 +78,7 @@ private static void applyConfigWithNestedKeyValue(Connection conn, VM vm, Map recordMap, String paramKey, String paramValue) { if (!isValidOperation(recordMap, paramKey)) { - LOG.error("Unsupported extra configuration has been passed: " + paramKey); + LOGGER.error("Unsupported extra configuration has been passed: " + paramKey); throw new InvalidParameterValueException("Unsupported extra configuration parameter key has been passed: " + paramKey); } @@ -170,10 +179,10 @@ private static void applyConfigWithKeyValue(Connection conn, VM vm, Map classes = new HashSet(); @@ -112,14 +110,14 @@ protected void waitForTask2(final Connection c, final Task task, final long poll Set events = map.events; if (events.size() == 0) { final String msg = "No event for task " + task.toWireString(); - s_logger.warn(msg); + logger.warn(msg); task.cancel(c); throw new TimeoutException(msg); } for (final Event.Record rec : events) { if (!(rec.snapshot instanceof Task.Record)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Skipping over " + rec); + if (logger.isDebugEnabled()) { + logger.debug("Skipping over " + rec); } continue; } @@ -127,20 +125,20 @@ protected void waitForTask2(final Connection c, final Task task, final long poll final Task.Record taskRecord = (Task.Record)rec.snapshot; if (taskRecord.status != Types.TaskStatusType.PENDING) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Task, ref:" + task.toWireString() + ", UUID:" + taskRecord.uuid + " is done " + taskRecord.status); + if (logger.isDebugEnabled()) { + logger.debug("Task, ref:" + task.toWireString() + ", UUID:" + taskRecord.uuid + " is done " + taskRecord.status); } return; } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Task: ref:" + task.toWireString() + ", UUID:" + taskRecord.uuid + " progress: " + taskRecord.progress); + if (logger.isDebugEnabled()) { + logger.debug("Task: ref:" + task.toWireString() + ", UUID:" + taskRecord.uuid + " progress: " + taskRecord.progress); } } } if (System.currentTimeMillis() - beginTime > timeout) { final String msg = "Async " + timeout / 1000 + " seconds timeout for task " + task.toString(); - s_logger.warn(msg); + logger.warn(msg); task.cancel(c); throw new TimeoutException(msg); } @@ -171,7 +169,7 @@ public void run() { try { results = Event.from(conn, _classes, _token, new Double(30)); } catch (final Exception e) { - s_logger.error("Retrying the waiting on VM events due to: ", e); + logger.error("Retrying the waiting on VM events due to: ", e); continue; } @@ -182,8 +180,8 @@ public void run() { for (final Event.Record event : events) { try { if (!(event.snapshot instanceof VM.Record)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("The snapshot is not a VM: " + event); + if (logger.isDebugEnabled()) { + logger.debug("The snapshot is not a VM: " + event); } continue; } @@ -195,11 +193,11 @@ public void run() { } recordChanges(conn, vm, hostUuid); } catch (final Exception e) { - s_logger.error("Skipping over " + event, e); + logger.error("Skipping over " + event, e); } } } catch (final Throwable th) { - s_logger.error("Exception caught in eventlistener thread: ", th); + logger.error("Exception caught in eventlistener thread: ", th); } } } @@ -217,11 +215,11 @@ public void start() { try { results = Event.from(conn, _classes, _token, new Double(30)); } catch (final Exception e) { - s_logger.error("Retrying the waiting on VM events due to: ", e); + logger.error("Retrying the waiting on VM events due to: ", e); throw new CloudRuntimeException("Unable to start a listener thread to listen to VM events", e); } _token = results.token; - s_logger.debug("Starting the event listener thread for " + _host.getUuid()); + logger.debug("Starting the event listener thread for " + _host.getUuid()); super.start(); } } diff --git a/plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java b/plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java index dbfcfe987fc5..caf28e849a0e 100644 --- a/plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java +++ b/plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java @@ -37,7 +37,8 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -75,7 +76,7 @@ @Component public class XenServerStorageMotionStrategy implements DataMotionStrategy { - private static final Logger s_logger = Logger.getLogger(XenServerStorageMotionStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AgentManager agentMgr; @Inject @@ -126,7 +127,7 @@ public void copyAsync(Map volumeMap, VirtualMachineTO vmT throw new CloudRuntimeException("Unsupported operation requested for moving data."); } } catch (Exception e) { - s_logger.error("copy failed", e); + logger.error("copy failed", e); errMsg = e.toString(); } @@ -198,7 +199,7 @@ private String handleManagedVolumePreMigration(VolumeInfo volumeInfo, StoragePoo String errMsg = "Error interacting with host (related to CreateStoragePoolCommand)" + (StringUtils.isNotBlank(answer.getDetails()) ? ": " + answer.getDetails() : ""); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -240,7 +241,7 @@ private void handleManagedVolumePostMigration(VolumeInfo volumeInfo, Host srcHos String errMsg = "Error interacting with host (related to DeleteStoragePoolCommand)" + (StringUtils.isNotBlank(answer.getDetails()) ? ": " + answer.getDetails() : ""); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -283,7 +284,7 @@ private void handleManagedVolumesAfterFailedMigration(Map String errMsg = "Error interacting with host (related to handleManagedVolumesAfterFailedMigration)" + (StringUtils.isNotBlank(answer.getDetails()) ? ": " + answer.getDetails() : ""); - s_logger.error(errMsg); + logger.error(errMsg); // no need to throw an exception here as the calling code is responsible for doing so // regardless of the success or lack thereof concerning this method @@ -342,10 +343,10 @@ private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachine MigrateWithStorageReceiveAnswer receiveAnswer = (MigrateWithStorageReceiveAnswer)agentMgr.send(destHost.getId(), receiveCmd); if (receiveAnswer == null) { - s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed."); + logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed."); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else if (!receiveAnswer.getResult()) { - s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + receiveAnswer.getDetails()); + logger.error("Migration with storage of vm " + vm + " failed. Details: " + receiveAnswer.getDetails()); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } @@ -356,12 +357,12 @@ private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachine if (sendAnswer == null) { handleManagedVolumesAfterFailedMigration(volumeToPool, destHost); - s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed."); + logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed."); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else if (!sendAnswer.getResult()) { handleManagedVolumesAfterFailedMigration(volumeToPool, destHost); - s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + sendAnswer.getDetails()); + logger.error("Migration with storage of vm " + vm + " failed. Details: " + sendAnswer.getDetails()); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } @@ -369,10 +370,10 @@ private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachine MigrateWithStorageCompleteAnswer answer = (MigrateWithStorageCompleteAnswer)agentMgr.send(destHost.getId(), command); if (answer == null) { - s_logger.error("Migration with storage of vm " + vm + " failed."); + logger.error("Migration with storage of vm " + vm + " failed."); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else if (!answer.getResult()) { - s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails()); + logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails()); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else { // Update the volume details after migration. @@ -381,7 +382,7 @@ private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachine return answer; } catch (OperationTimedoutException e) { - s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e); + logger.error("Error while migrating vm " + vm + " to host " + destHost, e); throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId()); } } @@ -402,10 +403,10 @@ private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachine MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto); MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer)agentMgr.send(destHost.getId(), command); if (answer == null) { - s_logger.error("Migration with storage of vm " + vm + " failed."); + logger.error("Migration with storage of vm " + vm + " failed."); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else if (!answer.getResult()) { - s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails()); + logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails()); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails()); } else { // Update the volume details after migration. @@ -414,7 +415,7 @@ private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachine return answer; } catch (OperationTimedoutException e) { - s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e); + logger.error("Error while migrating vm " + vm + " to host " + destHost, e); throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId()); } } @@ -451,7 +452,7 @@ private void updateVolumePathsAfterMigration(Map volumeTo } if (!updated) { - s_logger.error("The volume path wasn't updated for volume '" + volumeInfo + "' after it was migrated."); + logger.error("The volume path wasn't updated for volume '" + volumeInfo + "' after it was migrated."); } } } diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/XenServerGuruTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/XenServerGuruTest.java index f5169ae5dde8..b7e39ab89277 100644 --- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/XenServerGuruTest.java +++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/XenServerGuruTest.java @@ -28,7 +28,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.api.Command; import com.cloud.agent.api.to.DataObjectType; diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java index 26c2e6da625c..325843099796 100644 --- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java +++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/discoverer/XcpServerDiscovererTest.java @@ -25,7 +25,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.VMTemplateVO; diff --git a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapperTest.java b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapperTest.java index 95fb5aeb5c7d..9790222f0277 100644 --- a/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapperTest.java +++ b/plugins/hypervisors/xenserver/src/test/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixMigrateCommandWrapperTest.java @@ -24,7 +24,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.api.MigrateCommand; import com.cloud.agent.api.to.VirtualMachineTO; diff --git a/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/hypervisors/xenserver/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/integrations/cloudian/pom.xml b/plugins/integrations/cloudian/pom.xml index 2ed0e1a9f808..5529abe01542 100644 --- a/plugins/integrations/cloudian/pom.xml +++ b/plugins/integrations/cloudian/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/CloudianConnectorImpl.java b/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/CloudianConnectorImpl.java index cfb23da28462..3c1f161dd202 100644 --- a/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/CloudianConnectorImpl.java +++ b/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/CloudianConnectorImpl.java @@ -41,7 +41,6 @@ import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.messagebus.MessageBus; import org.apache.cloudstack.framework.messagebus.MessageSubscriber; -import org.apache.log4j.Logger; import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; @@ -56,7 +55,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class CloudianConnectorImpl extends ComponentLifecycleBase implements CloudianConnector, Configurable { - private static final Logger LOG = Logger.getLogger(CloudianConnectorImpl.class); @Inject private UserDao userDao; @@ -80,7 +78,7 @@ private CloudianClient getClient() { CloudianAdminUser.value(), CloudianAdminPassword.value(), CloudianValidateSSLSecurity.value(), CloudianAdminApiRequestTimeout.value()); } catch (final KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { - LOG.error("Failed to create Cloudian API client due to: ", e); + logger.error("Failed to create Cloudian API client due to: ", e); } throw new CloudRuntimeException("Failed to create and return Cloudian API client instance"); } @@ -104,17 +102,17 @@ private boolean removeGroup(final Domain domain) { final CloudianClient client = getClient(); for (final CloudianUser user: client.listUsers(domain.getUuid())) { if (client.removeUser(user.getUserId(), domain.getUuid())) { - LOG.error(String.format("Failed to remove Cloudian user id=%s, while removing Cloudian group id=%s", user.getUserId(), domain.getUuid())); + logger.error(String.format("Failed to remove Cloudian user id=%s, while removing Cloudian group id=%s", user.getUserId(), domain.getUuid())); } } for (int retry = 0; retry < 3; retry++) { if (client.removeGroup(domain.getUuid())) { return true; } else { - LOG.warn("Failed to remove Cloudian group id=" + domain.getUuid() + ", retrying count=" + retry+1); + logger.warn("Failed to remove Cloudian group id=" + domain.getUuid() + ", retrying count=" + retry+1); } } - LOG.warn("Failed to remove Cloudian group id=" + domain.getUuid() + ", please remove manually"); + logger.warn("Failed to remove Cloudian group id=" + domain.getUuid() + ", please remove manually"); return false; } @@ -164,10 +162,10 @@ private boolean removeUserAccount(final Account account) { if (client.removeUser(account.getUuid(), domain.getUuid())) { return true; } else { - LOG.warn("Failed to remove Cloudian user id=" + account.getUuid() + " in group id=" + domain.getUuid() + ", retrying count=" + retry+1); + logger.warn("Failed to remove Cloudian user id=" + account.getUuid() + " in group id=" + domain.getUuid() + ", retrying count=" + retry+1); } } - LOG.warn("Failed to remove Cloudian user id=" + account.getUuid() + " in group id=" + domain.getUuid() + ", please remove manually"); + logger.warn("Failed to remove Cloudian user id=" + account.getUuid() + " in group id=" + domain.getUuid() + ", please remove manually"); return false; } @@ -199,21 +197,21 @@ public String generateSsoUrl() { group = "0"; } - LOG.debug(String.format("Attempting Cloudian SSO with user id=%s, group id=%s", user, group)); + logger.debug(String.format("Attempting Cloudian SSO with user id=%s, group id=%s", user, group)); final CloudianUser ssoUser = getClient().listUser(user, group); if (ssoUser == null || !ssoUser.getActive()) { - LOG.debug(String.format("Failed to find existing Cloudian user id=%s in group id=%s", user, group)); + logger.debug(String.format("Failed to find existing Cloudian user id=%s in group id=%s", user, group)); final CloudianGroup ssoGroup = getClient().listGroup(group); if (ssoGroup == null) { - LOG.debug(String.format("Failed to find existing Cloudian group id=%s, trying to add it", group)); + logger.debug(String.format("Failed to find existing Cloudian group id=%s, trying to add it", group)); if (!addGroup(domain)) { - LOG.error("Failed to add missing Cloudian group id=" + group); + logger.error("Failed to add missing Cloudian group id=" + group); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Aborting Cloudian SSO, failed to add group to Cloudian."); } } if (!addUserAccount(caller, domain)) { - LOG.error("Failed to add missing Cloudian group id=" + group); + logger.error("Failed to add missing Cloudian group id=" + group); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Aborting Cloudian SSO, failed to add user to Cloudian."); } final CloudianUser addedSsoUser = getClient().listUser(user, group); @@ -224,7 +222,7 @@ public String generateSsoUrl() { updateUserAccount(caller, domain, ssoUser); } - LOG.debug(String.format("Validated Cloudian SSO for Cloudian user id=%s, group id=%s", user, group)); + logger.debug(String.format("Validated Cloudian SSO for Cloudian user id=%s, group id=%s", user, group)); return CloudianUtils.generateSSOUrl(getCmcUrl(), user, group, CloudianSsoKey.value()); } @@ -237,11 +235,11 @@ public boolean configure(String name, Map params) throws Configu super.configure(name, params); if (!isEnabled()) { - LOG.debug("Cloudian connector is disabled, skipping configuration"); + logger.debug("Cloudian connector is disabled, skipping configuration"); return true; } - LOG.debug(String.format("Cloudian connector is enabled, completed configuration, integration is ready. " + + logger.debug(String.format("Cloudian connector is enabled, completed configuration, integration is ready. " + "Cloudian admin host:%s, port:%s, user:%s", CloudianAdminHost.value(), CloudianAdminPort.value(), CloudianAdminUser.value())); @@ -255,10 +253,10 @@ public void onPublishMessage(String senderAddress, String subject, Object args) final Domain domain = domainDao.findById(account.getDomainId()); if (!addUserAccount(account, domain)) { - LOG.warn(String.format("Failed to add account in Cloudian while adding CloudStack account=%s in domain=%s", account.getAccountName(), domain.getPath())); + logger.warn(String.format("Failed to add account in Cloudian while adding CloudStack account=%s in domain=%s", account.getAccountName(), domain.getPath())); } } catch (final Exception e) { - LOG.error("Caught exception while adding account in Cloudian: ", e); + logger.error("Caught exception while adding account in Cloudian: ", e); } } }); @@ -269,10 +267,10 @@ public void onPublishMessage(String senderAddress, String subject, Object args) try { final Account account = accountDao.findByIdIncludingRemoved((Long) args); if(!removeUserAccount(account)) { - LOG.warn(String.format("Failed to remove account to Cloudian while removing CloudStack account=%s, id=%s", account.getAccountName(), account.getId())); + logger.warn(String.format("Failed to remove account to Cloudian while removing CloudStack account=%s, id=%s", account.getAccountName(), account.getId())); } } catch (final Exception e) { - LOG.error("Caught exception while removing account in Cloudian: ", e); + logger.error("Caught exception while removing account in Cloudian: ", e); } } }); @@ -283,10 +281,10 @@ public void onPublishMessage(String senderAddress, String subject, Object args) try { final Domain domain = domainDao.findById((Long) args); if (!addGroup(domain)) { - LOG.warn(String.format("Failed to add group in Cloudian while adding CloudStack domain=%s id=%s", domain.getPath(), domain.getId())); + logger.warn(String.format("Failed to add group in Cloudian while adding CloudStack domain=%s id=%s", domain.getPath(), domain.getId())); } } catch (final Exception e) { - LOG.error("Caught exception adding domain/group in Cloudian: ", e); + logger.error("Caught exception adding domain/group in Cloudian: ", e); } } }); @@ -297,10 +295,10 @@ public void onPublishMessage(String senderAddress, String subject, Object args) try { final DomainVO domain = (DomainVO) args; if (!removeGroup(domain)) { - LOG.warn(String.format("Failed to remove group in Cloudian while removing CloudStack domain=%s id=%s", domain.getPath(), domain.getId())); + logger.warn(String.format("Failed to remove group in Cloudian while removing CloudStack domain=%s id=%s", domain.getPath(), domain.getId())); } } catch (final Exception e) { - LOG.error("Caught exception while removing domain/group in Cloudian: ", e); + logger.error("Caught exception while removing domain/group in Cloudian: ", e); } } }); diff --git a/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianClient.java b/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianClient.java index 644a3c68a01c..9deddbe38a34 100644 --- a/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianClient.java +++ b/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianClient.java @@ -56,14 +56,15 @@ import org.apache.http.impl.client.BasicAuthCache; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.nio.TrustAllManager; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; public class CloudianClient { - private static final Logger LOG = Logger.getLogger(CloudianClient.class); + protected Logger logger = LogManager.getLogger(getClass()); private final HttpClient httpClient; private final HttpClientContext httpContext; @@ -107,14 +108,14 @@ public CloudianClient(final String host, final Integer port, final String scheme private void checkAuthFailure(final HttpResponse response) { if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { final Credentials credentials = httpContext.getCredentialsProvider().getCredentials(AuthScope.ANY); - LOG.error("Cloudian admin API authentication failed, please check Cloudian configuration. Admin auth principal=" + credentials.getUserPrincipal() + ", password=" + credentials.getPassword() + ", API url=" + adminApiUrl); + logger.error("Cloudian admin API authentication failed, please check Cloudian configuration. Admin auth principal=" + credentials.getUserPrincipal() + ", password=" + credentials.getPassword() + ", API url=" + adminApiUrl); throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, "Cloudian backend API call unauthorized, please ask your administrator to fix integration issues."); } } private void checkResponseOK(final HttpResponse response) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) { - LOG.debug("Requested Cloudian resource does not exist"); + logger.debug("Requested Cloudian resource does not exist"); return; } if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK && response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { @@ -178,12 +179,12 @@ public boolean addUser(final CloudianUser user) { if (user == null) { return false; } - LOG.debug("Adding Cloudian user: " + user); + logger.debug("Adding Cloudian user: " + user); try { final HttpResponse response = put("/user", user); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (final IOException e) { - LOG.error("Failed to add Cloudian user due to:", e); + logger.error("Failed to add Cloudian user due to:", e); checkResponseTimeOut(e); } return false; @@ -193,7 +194,7 @@ public CloudianUser listUser(final String userId, final String groupId) { if (StringUtils.isAnyEmpty(userId, groupId)) { return null; } - LOG.debug("Trying to find Cloudian user with id=" + userId + " and group id=" + groupId); + logger.debug("Trying to find Cloudian user with id=" + userId + " and group id=" + groupId); try { final HttpResponse response = get(String.format("/user?userId=%s&groupId=%s", userId, groupId)); checkResponseOK(response); @@ -203,7 +204,7 @@ public CloudianUser listUser(final String userId, final String groupId) { final ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(response.getEntity().getContent(), CloudianUser.class); } catch (final IOException e) { - LOG.error("Failed to list Cloudian user due to:", e); + logger.error("Failed to list Cloudian user due to:", e); checkResponseTimeOut(e); } return null; @@ -213,7 +214,7 @@ public List listUsers(final String groupId) { if (StringUtils.isEmpty(groupId)) { return new ArrayList<>(); } - LOG.debug("Trying to list Cloudian users in group id=" + groupId); + logger.debug("Trying to list Cloudian users in group id=" + groupId); try { final HttpResponse response = get(String.format("/user/list?groupId=%s&userType=all&userStatus=active", groupId)); checkResponseOK(response); @@ -223,7 +224,7 @@ public List listUsers(final String groupId) { final ObjectMapper mapper = new ObjectMapper(); return Arrays.asList(mapper.readValue(response.getEntity().getContent(), CloudianUser[].class)); } catch (final IOException e) { - LOG.error("Failed to list Cloudian users due to:", e); + logger.error("Failed to list Cloudian users due to:", e); checkResponseTimeOut(e); } return new ArrayList<>(); @@ -233,12 +234,12 @@ public boolean updateUser(final CloudianUser user) { if (user == null) { return false; } - LOG.debug("Updating Cloudian user: " + user); + logger.debug("Updating Cloudian user: " + user); try { final HttpResponse response = post("/user", user); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (final IOException e) { - LOG.error("Failed to update Cloudian user due to:", e); + logger.error("Failed to update Cloudian user due to:", e); checkResponseTimeOut(e); } return false; @@ -248,12 +249,12 @@ public boolean removeUser(final String userId, final String groupId) { if (StringUtils.isAnyEmpty(userId, groupId)) { return false; } - LOG.debug("Removing Cloudian user with user id=" + userId + " in group id=" + groupId); + logger.debug("Removing Cloudian user with user id=" + userId + " in group id=" + groupId); try { final HttpResponse response = delete(String.format("/user?userId=%s&groupId=%s", userId, groupId)); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (final IOException e) { - LOG.error("Failed to remove Cloudian user due to:", e); + logger.error("Failed to remove Cloudian user due to:", e); checkResponseTimeOut(e); } return false; @@ -267,12 +268,12 @@ public boolean addGroup(final CloudianGroup group) { if (group == null) { return false; } - LOG.debug("Adding Cloudian group: " + group); + logger.debug("Adding Cloudian group: " + group); try { final HttpResponse response = put("/group", group); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (final IOException e) { - LOG.error("Failed to add Cloudian group due to:", e); + logger.error("Failed to add Cloudian group due to:", e); checkResponseTimeOut(e); } return false; @@ -282,7 +283,7 @@ public CloudianGroup listGroup(final String groupId) { if (StringUtils.isEmpty(groupId)) { return null; } - LOG.debug("Trying to find Cloudian group with id=" + groupId); + logger.debug("Trying to find Cloudian group with id=" + groupId); try { final HttpResponse response = get(String.format("/group?groupId=%s", groupId)); checkResponseOK(response); @@ -292,14 +293,14 @@ public CloudianGroup listGroup(final String groupId) { final ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(response.getEntity().getContent(), CloudianGroup.class); } catch (final IOException e) { - LOG.error("Failed to list Cloudian group due to:", e); + logger.error("Failed to list Cloudian group due to:", e); checkResponseTimeOut(e); } return null; } public List listGroups() { - LOG.debug("Trying to list Cloudian groups"); + logger.debug("Trying to list Cloudian groups"); try { final HttpResponse response = get("/group/list"); checkResponseOK(response); @@ -309,7 +310,7 @@ public List listGroups() { final ObjectMapper mapper = new ObjectMapper(); return Arrays.asList(mapper.readValue(response.getEntity().getContent(), CloudianGroup[].class)); } catch (final IOException e) { - LOG.error("Failed to list Cloudian groups due to:", e); + logger.error("Failed to list Cloudian groups due to:", e); checkResponseTimeOut(e); } return new ArrayList<>(); @@ -319,12 +320,12 @@ public boolean updateGroup(final CloudianGroup group) { if (group == null) { return false; } - LOG.debug("Updating Cloudian group: " + group); + logger.debug("Updating Cloudian group: " + group); try { final HttpResponse response = post("/group", group); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (final IOException e) { - LOG.error("Failed to update group due to:", e); + logger.error("Failed to update group due to:", e); checkResponseTimeOut(e); } return false; @@ -334,12 +335,12 @@ public boolean removeGroup(final String groupId) { if (StringUtils.isEmpty(groupId)) { return false; } - LOG.debug("Removing Cloudian group id=" + groupId); + logger.debug("Removing Cloudian group id=" + groupId); try { final HttpResponse response = delete(String.format("/group?groupId=%s", groupId)); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (final IOException e) { - LOG.error("Failed to remove group due to:", e); + logger.error("Failed to remove group due to:", e); checkResponseTimeOut(e); } return false; diff --git a/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianUtils.java b/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianUtils.java index 0ef0fc9b5e02..6d70e785d0a4 100644 --- a/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianUtils.java +++ b/plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianUtils.java @@ -24,14 +24,15 @@ import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.HttpUtils; import org.apache.commons.lang3.StringUtils; public class CloudianUtils { - private static final Logger LOG = Logger.getLogger(CloudianUtils.class); + protected static Logger LOGGER = LogManager.getLogger(CloudianUtils.class); private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1"; /** @@ -51,7 +52,7 @@ public static String generateHMACSignature(final String data, final String key) byte[] rawHmac = mac.doFinal(data.getBytes()); return Base64.encodeBase64String(rawHmac); } catch (final Exception e) { - LOG.error("Failed to generate HMAC signature from provided data and key, due to: ", e); + LOGGER.error("Failed to generate HMAC signature from provided data and key, due to: ", e); } return null; } @@ -80,12 +81,8 @@ public static String generateSSOUrl(final String cmcUrlPath, final String user, return null; } - stringBuilder.append("&redirect="); - if (group.equals("0")) { - stringBuilder.append("admin.htm"); - } else { - stringBuilder.append("explorer.htm"); - } + // Redirects to dashboard for admin users or the bucket browser for regular users + stringBuilder.append("&redirect=/"); return cmcUrlPath + "ssosecurelogin.htm?" + stringBuilder.toString(); } diff --git a/plugins/integrations/cloudian/src/test/java/org/apache/cloudstack/cloudian/CloudianUtilsTest.java b/plugins/integrations/cloudian/src/test/java/org/apache/cloudstack/cloudian/CloudianUtilsTest.java new file mode 100644 index 000000000000..4bc9ce1fe284 --- /dev/null +++ b/plugins/integrations/cloudian/src/test/java/org/apache/cloudstack/cloudian/CloudianUtilsTest.java @@ -0,0 +1,87 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.cloudian; + +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLDecoder; +import java.util.HashMap; +import org.apache.cloudstack.cloudian.client.CloudianUtils; +import org.junit.Assert; +import org.junit.Test; + +public class CloudianUtilsTest { + + @Test + public void testGenerateSSOUrl() { + final String cmcUrlPath = "https://cmc.cloudian.com:8443/Cloudian/"; + final String user = "abc-def-ghi"; + final String group = "uvw-xyz"; + final String ssoKey = "randomkey"; + + // test expectations + final String expPath = "/Cloudian/ssosecurelogin.htm"; + HashMap expected = new HashMap(); + expected.put("user", user); + expected.put("group", group); + expected.put("timestamp", null); // null value will not be checked by this test + expected.put("signature", null); // null value will not be checked by this test + expected.put("redirect", "/"); + + // Generated URL will be something like this + // https://cmc.cloudian.com:8443/Cloudian/ssosecurelogin.htm?user=abc-def-ghi&group=uvw-xyz×tamp=1725937474949&signature=Wu1hjafeyE82mGwd1MIwrp5hPt4%3D&redirect=/ + String output = CloudianUtils.generateSSOUrl(cmcUrlPath, user, group, ssoKey); + Assert.assertNotNull(output); + + // Check main parts of the output URL + URL url = null; + try { + url = new URL(output); + } catch (MalformedURLException e) { + Assert.fail("failed to parse URL: " + output); + } + String path = url.getPath(); + Assert.assertEquals(expPath, path); + + // No easy way to check Query parameters in Java still? + // Just do a rudementary check as we are in charge of the URL + String query = url.getQuery(); + String[] nameValues = query.split("&"); + int matchedCount = 0; + for(String nameValue : nameValues) { + String[] nameValuePair = nameValue.split("=", 2); + Assert.assertEquals(nameValue, 2, nameValuePair.length); + String name = null; + String value = null; + try { + name = URLDecoder.decode(nameValuePair[0], "UTF-8"); + value = URLDecoder.decode(nameValuePair[1], "UTF-8"); + } catch (UnsupportedEncodingException e) { + Assert.fail("not expecting UTF-8 to fail"); + } + Assert.assertTrue(expected.containsKey(name)); + matchedCount++; + String expValue = expected.get(name); + if (expValue != null) { + Assert.assertEquals("Parameter " + name, expValue, value); + } + } + Assert.assertEquals("Should be 5 query parameters", 5, matchedCount); + } +} diff --git a/plugins/integrations/kubernetes-service/pom.xml b/plugins/integrations/kubernetes-service/pom.xml index 41ef1b07083e..397a3b43b31d 100644 --- a/plugins/integrations/kubernetes-service/pom.xml +++ b/plugins/integrations/kubernetes-service/pom.xml @@ -26,7 +26,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -86,9 +86,12 @@ ${cs.guava.version} - ch.qos.reload4j - reload4j - ${cs.reload4j.version} + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api org.springframework diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java index bf5a3ef60c30..71be8b1a475d 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java @@ -40,6 +40,8 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.uservm.UserVm; +import com.cloud.vm.UserVmService; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.SecurityChecker; import org.apache.cloudstack.annotation.AnnotationService; @@ -69,11 +71,10 @@ import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.managed.context.ManagedContextRunnable; +import org.apache.cloudstack.network.RoutedIpv4Manager; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; import com.cloud.api.ApiDBUtils; import com.cloud.api.query.dao.NetworkOfferingJoinDao; @@ -159,7 +160,6 @@ import com.cloud.user.UserVO; import com.cloud.user.dao.SSHKeyPairDao; import com.cloud.user.dao.UserDao; -import com.cloud.uservm.UserVm; import com.cloud.utils.Pair; import com.cloud.utils.Ternary; import com.cloud.utils.component.ComponentContext; @@ -177,15 +177,19 @@ import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.fsm.StateMachine2; import com.cloud.utils.net.NetUtils; -import com.cloud.vm.UserVmService; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.dao.VMInstanceDao; +import org.apache.logging.log4j.Level; public class KubernetesClusterManagerImpl extends ManagerBase implements KubernetesClusterService { - private static final Logger LOGGER = Logger.getLogger(KubernetesClusterManagerImpl.class); private static final String DEFAULT_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_NAME = "DefaultNetworkOfferingforKubernetesService"; + private static final String DEFAULT_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_DISPLAY_TEXT = "Network Offering used for CloudStack Kubernetes service"; + private static final String DEFAULT_NSX_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_NAME = "DefaultNSXNetworkOfferingforKubernetesService"; + private static final String DEFAULT_NSX_VPC_TIER_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_NAME = "DefaultNSXVPCNetworkOfferingforKubernetesService"; + private static final String DEFAULT_NSX_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_DISPLAY_TEXT = "Network Offering for NSX CloudStack Kubernetes Service"; + private static final String DEFAULT_NSX_VPC_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_DISPLAY_TEXT = "Network Offering for NSX CloudStack Kubernetes service on VPC"; protected StateMachine2 _stateMachine = KubernetesCluster.State.getStateMachine(); @@ -261,19 +265,21 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne @Inject private UserVmService userVmService; + @Inject + RoutedIpv4Manager routedIpv4Manager; private void logMessage(final Level logLevel, final String message, final Exception e) { if (logLevel == Level.WARN) { if (e != null) { - LOGGER.warn(message, e); + logger.warn(message, e); } else { - LOGGER.warn(message); + logger.warn(message); } } else { if (e != null) { - LOGGER.error(message, e); + logger.error(message, e); } else { - LOGGER.error(message); + logger.error(message); } } } @@ -301,25 +307,25 @@ private boolean isKubernetesServiceNetworkOfferingConfigured(DataCenter zone) { // Check network offering String networkOfferingName = KubernetesClusterNetworkOffering.value(); if (networkOfferingName == null || networkOfferingName.isEmpty()) { - LOGGER.warn(String.format("Global setting %s is empty. Admin has not yet specified the network offering to be used for provisioning isolated network for the cluster", KubernetesClusterNetworkOffering.key())); + logger.warn(String.format("Global setting %s is empty. Admin has not yet specified the network offering to be used for provisioning isolated network for the cluster", KubernetesClusterNetworkOffering.key())); return false; } NetworkOfferingVO networkOffering = networkOfferingDao.findByUniqueName(networkOfferingName); if (networkOffering == null) { - LOGGER.warn(String.format("Unable to find the network offering %s to be used for provisioning Kubernetes cluster", networkOfferingName)); + logger.warn(String.format("Unable to find the network offering %s to be used for provisioning Kubernetes cluster", networkOfferingName)); return false; } if (networkOffering.getState() == NetworkOffering.State.Disabled) { - LOGGER.warn(String.format("Network offering ID: %s is not enabled", networkOffering.getUuid())); + logger.warn(String.format("Network offering ID: %s is not enabled", networkOffering.getUuid())); return false; } List services = networkOfferingServiceMapDao.listServicesForNetworkOffering(networkOffering.getId()); if (services == null || services.isEmpty() || !services.contains("SourceNat")) { - LOGGER.warn(String.format("Network offering ID: %s does not have necessary services to provision Kubernetes cluster", networkOffering.getUuid())); + logger.warn(String.format("Network offering ID: %s does not have necessary services to provision Kubernetes cluster", networkOffering.getUuid())); return false; } if (!networkOffering.isEgressDefaultPolicy()) { - LOGGER.warn(String.format("Network offering ID: %s has egress default policy turned off should be on to provision Kubernetes cluster", networkOffering.getUuid())); + logger.warn(String.format("Network offering ID: %s has egress default policy turned off should be on to provision Kubernetes cluster", networkOffering.getUuid())); return false; } boolean offeringAvailableForZone = false; @@ -331,13 +337,13 @@ private boolean isKubernetesServiceNetworkOfferingConfigured(DataCenter zone) { } } if (!offeringAvailableForZone) { - LOGGER.warn(String.format("Network offering ID: %s is not available for zone ID: %s", networkOffering.getUuid(), zone.getUuid())); + logger.warn(String.format("Network offering ID: %s is not available for zone ID: %s", networkOffering.getUuid(), zone.getUuid())); return false; } long physicalNetworkId = networkModel.findPhysicalNetworkId(zone.getId(), networkOffering.getTags(), networkOffering.getTrafficType()); PhysicalNetwork physicalNetwork = physicalNetworkDao.findById(physicalNetworkId); if (physicalNetwork == null) { - LOGGER.warn(String.format("Unable to find physical network with tag: %s", networkOffering.getTags())); + logger.warn(String.format("Unable to find physical network with tag: %s", networkOffering.getTags())); return false; } return true; @@ -366,7 +372,7 @@ private IpAddress getSourceNatIp(Network network) { public VMTemplateVO getKubernetesServiceTemplate(DataCenter dataCenter, Hypervisor.HypervisorType hypervisorType) { VMTemplateVO template = templateDao.findSystemVMReadyTemplate(dataCenter.getId(), hypervisorType); if (DataCenter.Type.Edge.equals(dataCenter.getType()) && template != null && !template.isDirectDownload()) { - LOGGER.debug(String.format("Template %s can not be used for edge zone %s", template, dataCenter)); + logger.debug(String.format("Template %s can not be used for edge zone %s", template, dataCenter)); template = templateDao.findRoutingTemplate(hypervisorType, networkHelper.getHypervisorRouterTemplateConfigMap().get(hypervisorType).valueIn(dataCenter.getId())); } if (template == null) { @@ -380,8 +386,8 @@ protected void validateIsolatedNetworkIpRules(long ipId, FirewallRule.Purpose pu for (FirewallRuleVO rule : rules) { Integer startPort = rule.getSourcePortStart(); Integer endPort = rule.getSourcePortEnd(); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Validating rule with purpose: %s for network: %s with ports: %d-%d", purpose.toString(), network.getUuid(), startPort, endPort)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Validating rule with purpose: %s for network: %s with ports: %d-%d", purpose.toString(), network.getUuid(), startPort, endPort)); } if (startPort <= KubernetesClusterActionWorker.CLUSTER_API_PORT && KubernetesClusterActionWorker.CLUSTER_API_PORT <= endPort) { throw new InvalidParameterValueException(String.format("Network ID: %s has conflicting %s rules to provision Kubernetes cluster for API access", network.getUuid(), purpose.toString().toLowerCase())); @@ -426,6 +432,13 @@ private void validateNetwork(Network network, int clusterTotalNodeCount) { if (!networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData)) { throw new InvalidParameterValueException(String.format("Network ID: %s does not support userdata that is required for Kubernetes cluster", network.getUuid())); } + if (!networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)) { + throw new InvalidParameterValueException(String.format("Network ID: %s does not support DHCP that is required for Kubernetes cluster", network.getUuid())); + } + if (routedIpv4Manager.isRoutedNetwork(network)) { + logger.debug("No need to add firewall and port forwarding rules for ROUTED network. Assume the VMs are reachable."); + return; + } Long vpcId = network.getVpcId(); if (vpcId == null && !networkModel.areServicesSupportedInNetwork(network.getId(), Service.Firewall)) { throw new InvalidParameterValueException(String.format("Network ID: %s does not support firewall that is required for Kubernetes cluster", network.getUuid())); @@ -433,9 +446,6 @@ private void validateNetwork(Network network, int clusterTotalNodeCount) { if (!networkModel.areServicesSupportedInNetwork(network.getId(), Service.PortForwarding)) { throw new InvalidParameterValueException(String.format("Network ID: %s does not support port forwarding that is required for Kubernetes cluster", network.getUuid())); } - if (!networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)) { - throw new InvalidParameterValueException(String.format("Network ID: %s does not support DHCP that is required for Kubernetes cluster", network.getUuid())); - } if (network.getVpcId() != null) { validateVpcTier(network); return; @@ -510,13 +520,11 @@ private DeployDestination plan(final long nodesCount, final DataCenter zone, fin ClusterDetailsVO cluster_detail_ram = clusterDetailsDao.findDetail(cluster.getId(), "memoryOvercommitRatio"); Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue()); Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue()); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Checking host ID: %s for capacity already reserved %d", hostVO.getUuid(), reserved)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Checking host ID: %s for capacity already reserved %d", hostVO.getUuid(), reserved)); } if (capacityManager.checkIfHostHasCapacity(hostVO.getId(), cpu_requested * reserved, ram_requested * reserved, false, cpuOvercommitRatio, memoryOvercommitRatio, true)) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Found host ID: %s for with enough capacity, CPU=%d RAM=%s", hostVO.getUuid(), cpu_requested * reserved, toHumanReadableSize(ram_requested * reserved))); - } + logger.debug("Found host ID == '{}' to have enough capacity, CPU={} RAM={}", hostVO.getUuid(), cpu_requested * reserved, toHumanReadableSize(ram_requested * reserved)); hostEntry.setValue(new Pair(hostVO, reserved)); suitable_host_found = true; planCluster = cluster; @@ -524,21 +532,21 @@ private DeployDestination plan(final long nodesCount, final DataCenter zone, fin } } if (!suitable_host_found) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Suitable hosts not found in datacenter ID: %s for node %d with offering ID: %s", zone.getUuid(), i, offering.getUuid())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Suitable hosts not found in datacenter ID: %s for node %d with offering ID: %s", zone.getUuid(), i, offering.getUuid())); } break; } } if (suitable_host_found) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Suitable hosts found in datacenter ID: %s, creating deployment destination", zone.getUuid())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Suitable hosts found in datacenter ID: %s, creating deployment destination", zone.getUuid())); } return new DeployDestination(zone, null, planCluster, null); } String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%d memory=%s) with offering ID: %s", cpu_requested * nodesCount, toHumanReadableSize(ram_requested * nodesCount), offering.getUuid()); - LOGGER.warn(msg); + logger.warn(msg); throw new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId()); } @@ -591,7 +599,7 @@ public KubernetesClusterResponse createKubernetesClusterResponse(long kubernetes if (ntwk != null) { response.setNetworkId(ntwk.getUuid()); response.setAssociatedNetworkName(ntwk.getName()); - if (ntwk.getGuestType() == Network.GuestType.Isolated) { + if (!isDirectAccess(ntwk)) { List ipAddresses = ipAddressDao.listByAssociatedNetwork(ntwk.getId(), true); if (ipAddresses != null && ipAddresses.size() == 1) { response.setIpAddress(ipAddresses.get(0).getAddress().addr()); @@ -828,8 +836,8 @@ private void validateManagedKubernetesClusterCreateParameters(final CreateKubern if (network == null) { throw new InvalidParameterValueException(String.format("%s parameter must be specified along with %s parameter", ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, ApiConstants.NETWORK_ID)); } - if (!Network.GuestType.Shared.equals(network.getGuestType())) { - throw new InvalidParameterValueException(String.format("%s parameter must be specified along with %s type of network", ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, Network.GuestType.Shared.toString())); + if (!Network.GuestType.Shared.equals(network.getGuestType()) || routedIpv4Manager.isRoutedNetwork(network)) { + throw new InvalidParameterValueException(String.format("%s parameter must be specified when network type is not %s or is %s network", ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, Network.GuestType.Shared, NetworkOffering.NetworkMode.ROUTED)); } } @@ -850,7 +858,8 @@ private Network getKubernetesClusterNetworkIfMissing(final String clusterName, f } else { throw new InvalidParameterValueException(String.format("Network ID: %s is already under use by another Kubernetes cluster", network.getUuid())); } - } else if (Network.GuestType.Shared.equals(network.getGuestType())) { + } + if (isDirectAccess(network)) { if (controlNodesCount > 1 && StringUtils.isEmpty(externalLoadBalancerIpAddress)) { throw new InvalidParameterValueException(String.format("Multi-control nodes, HA Kubernetes cluster with %s network ID: %s needs an external load balancer IP address. %s parameter can be used", network.getGuestType().toString(), network.getUuid(), ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS)); @@ -862,8 +871,8 @@ private Network getKubernetesClusterNetworkIfMissing(final String clusterName, f long physicalNetworkId = networkModel.findPhysicalNetworkId(zone.getId(), networkOffering.getTags(), networkOffering.getTrafficType()); PhysicalNetwork physicalNetwork = physicalNetworkDao.findById(physicalNetworkId); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Creating network for account ID: %s from the network offering ID: %s as part of Kubernetes cluster: %s deployment process", owner.getUuid(), networkOffering.getUuid(), clusterName)); + if (logger.isInfoEnabled()) { + logger.info(String.format("Creating network for account ID: %s from the network offering ID: %s as part of Kubernetes cluster: %s deployment process", owner.getUuid(), networkOffering.getUuid(), clusterName)); } CallContext networkContext = CallContext.register(CallContext.current(), ApiCommandResourceType.Network); @@ -892,7 +901,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { List details = new ArrayList<>(); long kubernetesClusterId = kubernetesCluster.getId(); - if ((network != null && Network.GuestType.Shared.equals(network.getGuestType())) || kubernetesCluster.getClusterType() == KubernetesCluster.ClusterType.ExternalManaged) { + if ((network != null && isDirectAccess(network)) || kubernetesCluster.getClusterType() == KubernetesCluster.ClusterType.ExternalManaged) { addKubernetesClusterDetailIfIsNotEmpty(details, kubernetesClusterId, ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, externalLoadBalancerIpAddress, true); } @@ -1137,7 +1146,7 @@ protected boolean stateTransitTo(long kubernetesClusterId, KubernetesCluster.Eve try { return _stateMachine.transitTo(kubernetesCluster, e, null, kubernetesClusterDao); } catch (NoTransitionException nte) { - LOGGER.warn(String.format("Failed to transition state of the Kubernetes cluster : %s in state %s on event %s", kubernetesCluster.getName(), kubernetesCluster.getState().toString(), e.toString()), nte); + logger.warn(String.format("Failed to transition state of the Kubernetes cluster : %s in state %s on event %s", kubernetesCluster.getName(), kubernetesCluster.getState().toString(), e.toString()), nte); return false; } } @@ -1188,8 +1197,8 @@ public KubernetesClusterVO doInTransaction(TransactionStatus status) { addKubernetesClusterDetails(cluster, network, cmd); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Kubernetes cluster with name: %s and ID: %s has been created", cluster.getName(), cluster.getUuid())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Kubernetes cluster with name: %s and ID: %s has been created", cluster.getName(), cluster.getUuid())); } CallContext.current().putContextParameter(KubernetesCluster.class, cluster.getUuid()); return cluster; @@ -1251,8 +1260,8 @@ public KubernetesClusterVO doInTransaction(TransactionStatus status) { addKubernetesClusterDetails(cluster, defaultNetwork, cmd); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Kubernetes cluster name: %s and ID: %s has been created", cluster.getName(), cluster.getUuid())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Kubernetes cluster name: %s and ID: %s has been created", cluster.getName(), cluster.getUuid())); } CallContext.current().putContextParameter(KubernetesCluster.class, cluster.getUuid()); return cluster; @@ -1342,14 +1351,14 @@ public boolean startKubernetesCluster(KubernetesClusterVO kubernetesCluster, boo } accountManager.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.OperateEntry, false, kubernetesCluster); if (kubernetesCluster.getState().equals(KubernetesCluster.State.Running)) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Kubernetes cluster : %s is in running state", kubernetesCluster.getName())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Kubernetes cluster : %s is in running state", kubernetesCluster.getName())); } return true; } if (kubernetesCluster.getState().equals(KubernetesCluster.State.Starting)) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Kubernetes cluster : %s is already in starting state", kubernetesCluster.getName())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Kubernetes cluster : %s is already in starting state", kubernetesCluster.getName())); } return true; } @@ -1415,14 +1424,14 @@ public boolean stopKubernetesCluster(StopKubernetesClusterCmd cmd) throws CloudR } accountManager.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.OperateEntry, false, kubernetesCluster); if (kubernetesCluster.getState().equals(KubernetesCluster.State.Stopped)) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Kubernetes cluster : %s is already stopped", kubernetesCluster.getName())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Kubernetes cluster : %s is already stopped", kubernetesCluster.getName())); } return true; } if (kubernetesCluster.getState().equals(KubernetesCluster.State.Stopping)) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Kubernetes cluster : %s is getting stopped", kubernetesCluster.getName())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Kubernetes cluster : %s is getting stopped", kubernetesCluster.getName())); } return true; } @@ -1777,26 +1786,26 @@ public void reallyRun() { try { List kubernetesClusters = kubernetesClusterDao.findKubernetesClustersToGarbageCollect(); for (KubernetesCluster kubernetesCluster : kubernetesClusters) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Running Kubernetes cluster garbage collector on Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Running Kubernetes cluster garbage collector on Kubernetes cluster : %s", kubernetesCluster.getName())); } try { KubernetesClusterDestroyWorker destroyWorker = new KubernetesClusterDestroyWorker(kubernetesCluster, KubernetesClusterManagerImpl.this); destroyWorker = ComponentContext.inject(destroyWorker); if (destroyWorker.destroy()) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Garbage collection complete for Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Garbage collection complete for Kubernetes cluster : %s", kubernetesCluster.getName())); } } else { - LOGGER.warn(String.format("Garbage collection failed for Kubernetes cluster : %s, it will be attempted to garbage collected in next run", kubernetesCluster.getName())); + logger.warn(String.format("Garbage collection failed for Kubernetes cluster : %s, it will be attempted to garbage collected in next run", kubernetesCluster.getName())); } } catch (CloudRuntimeException e) { - LOGGER.warn(String.format("Failed to destroy Kubernetes cluster : %s during GC", kubernetesCluster.getName()), e); + logger.warn(String.format("Failed to destroy Kubernetes cluster : %s during GC", kubernetesCluster.getName()), e); // proceed further with rest of the Kubernetes cluster garbage collection } } } catch (Exception e) { - LOGGER.warn("Caught exception while running Kubernetes cluster gc: ", e); + logger.warn("Caught exception while running Kubernetes cluster gc: ", e); } } } @@ -1834,38 +1843,38 @@ public void reallyRun() { // run through Kubernetes clusters in 'Running' state and ensure all the VM's are Running in the cluster List runningKubernetesClusters = kubernetesClusterDao.findManagedKubernetesClustersInState(KubernetesCluster.State.Running); for (KubernetesCluster kubernetesCluster : runningKubernetesClusters) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s", kubernetesCluster.getName())); } try { if (!isClusterVMsInDesiredState(kubernetesCluster, VirtualMachine.State.Running)) { stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.FaultsDetected); } } catch (Exception e) { - LOGGER.warn(String.format("Failed to run Kubernetes cluster Running state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); + logger.warn(String.format("Failed to run Kubernetes cluster Running state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); } } // run through Kubernetes clusters in 'Stopped' state and ensure all the VM's are Stopped in the cluster List stoppedKubernetesClusters = kubernetesClusterDao.findManagedKubernetesClustersInState(KubernetesCluster.State.Stopped); for (KubernetesCluster kubernetesCluster : stoppedKubernetesClusters) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s for state: %s", kubernetesCluster.getName(), KubernetesCluster.State.Stopped.toString())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s for state: %s", kubernetesCluster.getName(), KubernetesCluster.State.Stopped.toString())); } try { if (!isClusterVMsInDesiredState(kubernetesCluster, VirtualMachine.State.Stopped)) { stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.FaultsDetected); } } catch (Exception e) { - LOGGER.warn(String.format("Failed to run Kubernetes cluster Stopped state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); + logger.warn(String.format("Failed to run Kubernetes cluster Stopped state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); } } // run through Kubernetes clusters in 'Alert' state and reconcile state as 'Running' if the VM's are running or 'Stopped' if VM's are stopped List alertKubernetesClusters = kubernetesClusterDao.findManagedKubernetesClustersInState(KubernetesCluster.State.Alert); for (KubernetesClusterVO kubernetesCluster : alertKubernetesClusters) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s for state: %s", kubernetesCluster.getName(), KubernetesCluster.State.Alert.toString())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s for state: %s", kubernetesCluster.getName(), KubernetesCluster.State.Alert.toString())); } try { if (isClusterVMsInDesiredState(kubernetesCluster, VirtualMachine.State.Running)) { @@ -1878,7 +1887,7 @@ public void reallyRun() { stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.OperationSucceeded); } } catch (Exception e) { - LOGGER.warn(String.format("Failed to run Kubernetes cluster Alert state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); + logger.warn(String.format("Failed to run Kubernetes cluster Alert state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); } } @@ -1890,8 +1899,8 @@ public void reallyRun() { if ((new Date()).getTime() - kubernetesCluster.getCreated().getTime() < 10*60*1000) { continue; } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s for state: %s", kubernetesCluster.getName(), KubernetesCluster.State.Starting.toString())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s for state: %s", kubernetesCluster.getName(), KubernetesCluster.State.Starting.toString())); } try { if (isClusterVMsInDesiredState(kubernetesCluster, VirtualMachine.State.Running)) { @@ -1900,25 +1909,25 @@ public void reallyRun() { stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed); } } catch (Exception e) { - LOGGER.warn(String.format("Failed to run Kubernetes cluster Starting state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); + logger.warn(String.format("Failed to run Kubernetes cluster Starting state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); } } List destroyingKubernetesClusters = kubernetesClusterDao.findManagedKubernetesClustersInState(KubernetesCluster.State.Destroying); for (KubernetesCluster kubernetesCluster : destroyingKubernetesClusters) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s for state: %s", kubernetesCluster.getName(), KubernetesCluster.State.Destroying.toString())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Running Kubernetes cluster state scanner on Kubernetes cluster : %s for state: %s", kubernetesCluster.getName(), KubernetesCluster.State.Destroying.toString())); } try { KubernetesClusterDestroyWorker destroyWorker = new KubernetesClusterDestroyWorker(kubernetesCluster, KubernetesClusterManagerImpl.this); destroyWorker = ComponentContext.inject(destroyWorker); destroyWorker.destroy(); } catch (Exception e) { - LOGGER.warn(String.format("Failed to run Kubernetes cluster Destroying state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); + logger.warn(String.format("Failed to run Kubernetes cluster Destroying state scanner on Kubernetes cluster : %s status scanner", kubernetesCluster.getName()), e); } } } } catch (Exception e) { - LOGGER.warn("Caught exception while running Kubernetes cluster state scanner", e); + logger.warn("Caught exception while running Kubernetes cluster state scanner", e); } firstRun = false; } @@ -1930,8 +1939,8 @@ boolean isClusterVMsInDesiredState(KubernetesCluster kubernetesCluster, VirtualM // check cluster is running at desired capacity include control nodes as well if (clusterVMs.size() < kubernetesCluster.getTotalNodeCount()) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Found only %d VMs in the Kubernetes cluster %s while expected %d VMs to be in state: %s", + if (logger.isDebugEnabled()) { + logger.debug(String.format("Found only %d VMs in the Kubernetes cluster %s while expected %d VMs to be in state: %s", clusterVMs.size(), kubernetesCluster.getName(), kubernetesCluster.getTotalNodeCount(), state.toString())); } return false; @@ -1940,8 +1949,8 @@ boolean isClusterVMsInDesiredState(KubernetesCluster kubernetesCluster, VirtualM for (KubernetesClusterVmMapVO clusterVm : clusterVMs) { VMInstanceVO vm = vmInstanceDao.findByIdIncludingRemoved(clusterVm.getVmId()); if (vm.getState() != state) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Found VM : %s in the Kubernetes cluster : %s in state: %s while expected to be in state: %s. So moving the cluster to Alert state for reconciliation", + if (logger.isDebugEnabled()) { + logger.debug(String.format("Found VM : %s in the Kubernetes cluster : %s in state: %s while expected to be in state: %s. So moving the cluster to Alert state for reconciliation", vm.getUuid(), kubernetesCluster.getName(), vm.getState().toString(), state.toString())); } return false; @@ -1953,26 +1962,54 @@ boolean isClusterVMsInDesiredState(KubernetesCluster kubernetesCluster, VirtualM @Override public boolean start() { + createNetworkOfferingForKubernetes(DEFAULT_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_NAME, + DEFAULT_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_DISPLAY_TEXT, false, false); + + createNetworkOfferingForKubernetes(DEFAULT_NSX_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_NAME, + DEFAULT_NSX_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_DISPLAY_TEXT, true, false); + + createNetworkOfferingForKubernetes(DEFAULT_NSX_VPC_TIER_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_NAME, + DEFAULT_NSX_VPC_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_DISPLAY_TEXT , true, true); + + _gcExecutor.scheduleWithFixedDelay(new KubernetesClusterGarbageCollector(), 300, 300, TimeUnit.SECONDS); + _stateScanner.scheduleWithFixedDelay(new KubernetesClusterStatusScanner(), 300, 30, TimeUnit.SECONDS); + + return true; + } + + private void createNetworkOfferingForKubernetes(String offeringName, String offeringDesc, boolean forNsx, boolean forVpc) { final Map defaultKubernetesServiceNetworkOfferingProviders = new HashMap(); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.Dhcp, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.Dns, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.UserData, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.Firewall, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.Gateway, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.Lb, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.SourceNat, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.StaticNat, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.PortForwarding, Network.Provider.VirtualRouter); - defaultKubernetesServiceNetworkOfferingProviders.put(Service.Vpn, Network.Provider.VirtualRouter); + Network.Provider provider = forVpc ? Network.Provider.VPCVirtualRouter : Network.Provider.VirtualRouter; + defaultKubernetesServiceNetworkOfferingProviders.put(Service.Dhcp, provider); + defaultKubernetesServiceNetworkOfferingProviders.put(Service.Dns, provider); + defaultKubernetesServiceNetworkOfferingProviders.put(Service.UserData, provider); + if (forVpc) { + defaultKubernetesServiceNetworkOfferingProviders.put(Service.NetworkACL, forNsx ? Network.Provider.Nsx : provider); + } else { + defaultKubernetesServiceNetworkOfferingProviders.put(Service.Firewall, forNsx ? Network.Provider.Nsx : provider); + } + defaultKubernetesServiceNetworkOfferingProviders.put(Service.Lb, forNsx ? Network.Provider.Nsx : provider); + defaultKubernetesServiceNetworkOfferingProviders.put(Service.SourceNat, forNsx ? Network.Provider.Nsx : provider); + defaultKubernetesServiceNetworkOfferingProviders.put(Service.StaticNat, forNsx ? Network.Provider.Nsx : provider); + defaultKubernetesServiceNetworkOfferingProviders.put(Service.PortForwarding, forNsx ? Network.Provider.Nsx : provider); + + if (!forNsx) { + defaultKubernetesServiceNetworkOfferingProviders.put(Service.Gateway, Network.Provider.VirtualRouter); + defaultKubernetesServiceNetworkOfferingProviders.put(Service.Vpn, Network.Provider.VirtualRouter); + } NetworkOfferingVO defaultKubernetesServiceNetworkOffering = - new NetworkOfferingVO(DEFAULT_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_NAME, - "Network Offering used for CloudStack Kubernetes service", Networks.TrafficType.Guest, + new NetworkOfferingVO(offeringName, + offeringDesc, Networks.TrafficType.Guest, false, false, null, null, true, NetworkOffering.Availability.Required, null, Network.GuestType.Isolated, true, true, false, false, false, false, false, false, false, true, true, false, - false, true, false, false); + forVpc, true, false, false); + if (forNsx) { + defaultKubernetesServiceNetworkOffering.setNetworkMode(NetworkOffering.NetworkMode.NATTED); + defaultKubernetesServiceNetworkOffering.setForNsx(true); + } defaultKubernetesServiceNetworkOffering.setSupportsVmAutoScaling(true); defaultKubernetesServiceNetworkOffering.setState(NetworkOffering.State.Enabled); defaultKubernetesServiceNetworkOffering = networkOfferingDao.persistDefaultNetworkOffering(defaultKubernetesServiceNetworkOffering); @@ -1982,13 +2019,13 @@ public boolean start() { new NetworkOfferingServiceMapVO(defaultKubernetesServiceNetworkOffering.getId(), service, defaultKubernetesServiceNetworkOfferingProviders.get(service)); networkOfferingServiceMapDao.persist(offService); - LOGGER.trace("Added service for the network offering: " + offService); + logger.trace("Added service for the network offering: " + offService); } + } - _gcExecutor.scheduleWithFixedDelay(new KubernetesClusterGarbageCollector(), 300, 300, TimeUnit.SECONDS); - _stateScanner.scheduleWithFixedDelay(new KubernetesClusterStatusScanner(), 300, 30, TimeUnit.SECONDS); - - return true; + @Override + public boolean isDirectAccess(Network network) { + return Network.GuestType.Shared.equals(network.getGuestType()) || routedIpv4Manager.isRoutedNetwork(network); } @Override diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterService.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterService.java index 6acc876493ef..9d86c564de48 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterService.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterService.java @@ -33,6 +33,7 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; +import com.cloud.network.Network; import com.cloud.utils.component.PluggableService; import com.cloud.utils.exception.CloudRuntimeException; @@ -122,4 +123,6 @@ public interface KubernetesClusterService extends PluggableService, Configurable boolean addVmsToCluster(AddVirtualMachinesToKubernetesClusterCmd cmd); List removeVmsFromCluster(RemoveVirtualMachinesFromKubernetesClusterCmd cmd); + + boolean isDirectAccess(Network network); } diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelperImpl.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelperImpl.java index 9551142d24e4..efaec61b052e 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelperImpl.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelperImpl.java @@ -18,6 +18,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.Objects; import javax.inject.Inject; @@ -25,9 +26,6 @@ import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.event.EventTypes; import com.cloud.kubernetes.cluster.dao.KubernetesClusterDao; @@ -39,9 +37,14 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.UserVmManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.stereotype.Component; + @Component public class KubernetesServiceHelperImpl extends AdapterBase implements KubernetesServiceHelper, Configurable { - private static final Logger logger = Logger.getLogger(KubernetesServiceHelperImpl.class); + private static final Logger logger = LogManager.getLogger(KubernetesServiceHelperImpl.class); @Inject private KubernetesClusterDao kubernetesClusterDao; @@ -71,6 +74,15 @@ public ControlledEntity findByUuid(String uuid) { return kubernetesClusterDao.findByUuid(uuid); } + @Override + public ControlledEntity findByVmId(long vmId) { + KubernetesClusterVmMapVO clusterVmMapVO = kubernetesClusterVmMapDao.getClusterMapFromVmId(vmId); + if (Objects.isNull(clusterVmMapVO)) { + return null; + } + return kubernetesClusterDao.findById(clusterVmMapVO.getClusterId()); + } + @Override public void checkVmCanBeDestroyed(UserVm userVm) { if (!UserVmManager.CKS_NODE.equals(userVm.getUserVmType())) { diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java index 199f6da90d29..743962a1f00b 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java @@ -31,6 +31,9 @@ import javax.inject.Inject; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.ca.CAManager; @@ -41,8 +44,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.DataCenterDao; @@ -64,7 +65,6 @@ import com.cloud.network.IpAddress; import com.cloud.network.IpAddressManager; import com.cloud.network.Network; -import com.cloud.network.Network.GuestType; import com.cloud.network.NetworkModel; import com.cloud.network.NetworkService; import com.cloud.network.dao.IPAddressDao; @@ -110,7 +110,7 @@ public class KubernetesClusterActionWorker { public static final String CKS_CLUSTER_SECURITY_GROUP_NAME = "CKSSecurityGroup"; public static final String CKS_SECURITY_GROUP_DESCRIPTION = "Security group for CKS nodes"; - protected static final Logger LOGGER = Logger.getLogger(KubernetesClusterActionWorker.class); + protected Logger logger = LogManager.getLogger(getClass()); protected StateMachine2 _stateMachine = KubernetesCluster.State.getStateMachine(); @@ -227,32 +227,32 @@ protected String getControlNodeLoginUser() { protected void logMessage(final Level logLevel, final String message, final Exception e) { if (logLevel == Level.INFO) { - if (LOGGER.isInfoEnabled()) { + if (logger.isInfoEnabled()) { if (e != null) { - LOGGER.info(message, e); + logger.info(message, e); } else { - LOGGER.info(message); + logger.info(message); } } } else if (logLevel == Level.DEBUG) { - if (LOGGER.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (e != null) { - LOGGER.debug(message, e); + logger.debug(message, e); } else { - LOGGER.debug(message); + logger.debug(message); } } } else if (logLevel == Level.WARN) { if (e != null) { - LOGGER.warn(message, e); + logger.warn(message, e); } else { - LOGGER.warn(message); + logger.warn(message); } } else { if (e != null) { - LOGGER.error(message, e); + logger.error(message, e); } else { - LOGGER.error(message); + logger.error(message); } } } @@ -270,7 +270,7 @@ protected void logTransitStateDetachIsoAndThrow(final Level logLevel, final Stri protected void deleteTemplateLaunchPermission() { if (clusterTemplate != null && owner != null) { - LOGGER.info("Revoking launch permission for systemVM template"); + logger.info("Revoking launch permission for systemVM template"); launchPermissionDao.removePermissions(clusterTemplate.getId(), Collections.singletonList(owner.getId())); } } @@ -325,7 +325,7 @@ private UserVm fetchControlVmIfMissing(final UserVm controlVm) { } List clusterVMs = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId()); if (CollectionUtils.isEmpty(clusterVMs)) { - LOGGER.warn(String.format("Unable to retrieve VMs for Kubernetes cluster : %s", kubernetesCluster.getName())); + logger.warn(String.format("Unable to retrieve VMs for Kubernetes cluster : %s", kubernetesCluster.getName())); return null; } List vmIds = new ArrayList<>(); @@ -350,7 +350,7 @@ protected IpAddress getNetworkSourceNatIp(Network network) { if (CollectionUtils.isNotEmpty(addresses)) { return addresses.get(0); } - LOGGER.warn(String.format("No public IP addresses found for network : %s, Kubernetes cluster : %s", network.getName(), kubernetesCluster.getName())); + logger.warn(String.format("No public IP addresses found for network : %s, Kubernetes cluster : %s", network.getName(), kubernetesCluster.getName())); return null; } @@ -360,8 +360,8 @@ protected IpAddress getVpcTierKubernetesPublicIp(Network network) { return null; } IpAddress address = ipAddressDao.findByUuid(detailsVO.getValue()); - if (address == null || network.getVpcId() != address.getVpcId()) { - LOGGER.warn(String.format("Public IP with ID: %s linked to the Kubernetes cluster: %s is not usable", detailsVO.getValue(), kubernetesCluster.getName())); + if (address == null || !Objects.equals(network.getVpcId(), address.getVpcId())) { + logger.warn(String.format("Public IP with ID: %s linked to the Kubernetes cluster: %s is not usable", detailsVO.getValue(), kubernetesCluster.getName())); return null; } return address; @@ -392,7 +392,7 @@ protected Pair getKubernetesClusterServerIpSshPortForSharedNetw int port = DEFAULT_SSH_PORT; controlVm = fetchControlVmIfMissing(controlVm); if (controlVm == null) { - LOGGER.warn(String.format("Unable to retrieve control VM for Kubernetes cluster : %s", kubernetesCluster.getName())); + logger.warn(String.format("Unable to retrieve control VM for Kubernetes cluster : %s", kubernetesCluster.getName())); return new Pair<>(null, port); } return new Pair<>(controlVm.getPrivateIpAddress(), port); @@ -412,7 +412,7 @@ protected Pair getKubernetesClusterServerIpSshPortForVpcTier(Ne return new Pair<>(address.getAddress().addr(), port); } } - LOGGER.warn(String.format("No public IP found for the VPC tier: %s, Kubernetes cluster : %s", network, kubernetesCluster.getName())); + logger.warn(String.format("No public IP found for the VPC tier: %s, Kubernetes cluster : %s", network, kubernetesCluster.getName())); return new Pair<>(null, port); } @@ -425,18 +425,19 @@ protected Pair getKubernetesClusterServerIpSshPort(UserVm contr } Network network = networkDao.findById(kubernetesCluster.getNetworkId()); if (network == null) { - LOGGER.warn(String.format("Network for Kubernetes cluster : %s cannot be found", kubernetesCluster.getName())); + logger.warn(String.format("Network for Kubernetes cluster : %s cannot be found", kubernetesCluster.getName())); return new Pair<>(null, port); } + if (manager.isDirectAccess(network)) { + return getKubernetesClusterServerIpSshPortForSharedNetwork(controlVm); + } if (network.getVpcId() != null) { return getKubernetesClusterServerIpSshPortForVpcTier(network, acquireNewPublicIpForVpcTierIfNeeded); } if (Network.GuestType.Isolated.equals(network.getGuestType())) { return getKubernetesClusterServerIpSshPortForIsolatedNetwork(network); - } else if (Network.GuestType.Shared.equals(network.getGuestType())) { - return getKubernetesClusterServerIpSshPortForSharedNetwork(controlVm); } - LOGGER.warn(String.format("Unable to retrieve server IP address for Kubernetes cluster : %s", kubernetesCluster.getName())); + logger.warn(String.format("Unable to retrieve server IP address for Kubernetes cluster : %s", kubernetesCluster.getName())); return new Pair<>(null, port); } @@ -444,7 +445,7 @@ protected Pair getKubernetesClusterServerIpSshPort(UserVm contr try { return getKubernetesClusterServerIpSshPort(controlVm, false); } catch (InsufficientAddressCapacityException | ResourceAllocationException | ResourceUnavailableException e) { - LOGGER.debug("This exception should not have occurred", e); + logger.debug("This exception should not have occurred", e); } return new Pair<>(null, CLUSTER_NODES_DEFAULT_START_SSH_PORT); } @@ -478,8 +479,8 @@ protected void attachIsoKubernetesVMs(List clusterVMs, final KubernetesS vmContext.putContextParameter(VirtualMachine.class, vm.getUuid()); try { templateService.attachIso(iso.getId(), vm.getId(), true); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Attached binaries ISO for VM : %s in cluster: %s", vm.getDisplayName(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Attached binaries ISO for VM : %s in cluster: %s", vm.getDisplayName(), kubernetesCluster.getName())); } } catch (CloudRuntimeException ex) { logTransitStateAndThrow(Level.ERROR, String.format("Failed to attach binaries ISO for VM : %s in the Kubernetes cluster name: %s", vm.getDisplayName(), kubernetesCluster.getName()), kubernetesCluster.getId(), failedEvent, ex); @@ -501,17 +502,17 @@ protected void detachIsoKubernetesVMs(List clusterVMs) { try { result = templateService.detachIso(vm.getId(), true); } catch (CloudRuntimeException ex) { - LOGGER.warn(String.format("Failed to detach binaries ISO from VM : %s in the Kubernetes cluster : %s ", vm.getDisplayName(), kubernetesCluster.getName()), ex); + logger.warn(String.format("Failed to detach binaries ISO from VM : %s in the Kubernetes cluster : %s ", vm.getDisplayName(), kubernetesCluster.getName()), ex); } finally { CallContext.unregister(); } if (result) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Detached Kubernetes binaries from VM : %s in the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Detached Kubernetes binaries from VM : %s in the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName())); } continue; } - LOGGER.warn(String.format("Failed to detach binaries ISO from VM : %s in the Kubernetes cluster : %s ", vm.getDisplayName(), kubernetesCluster.getName())); + logger.warn(String.format("Failed to detach binaries ISO from VM : %s in the Kubernetes cluster : %s ", vm.getDisplayName(), kubernetesCluster.getName())); } } @@ -554,7 +555,7 @@ protected boolean stateTransitTo(long kubernetesClusterId, KubernetesCluster.Eve try { return _stateMachine.transitTo(kubernetesCluster, e, null, kubernetesClusterDao); } catch (NoTransitionException nte) { - LOGGER.warn(String.format("Failed to transition state of the Kubernetes cluster : %s in state %s on event %s", + logger.warn(String.format("Failed to transition state of the Kubernetes cluster : %s in state %s on event %s", kubernetesCluster.getName(), kubernetesCluster.getState().toString(), e.toString()), nte); return false; } @@ -579,7 +580,7 @@ protected boolean createCloudStackSecret(String[] keys) { return result.first(); } catch (Exception e) { String msg = String.format("Failed to add cloudstack-secret to Kubernetes cluster: %s", kubernetesCluster.getName()); - LOGGER.warn(msg, e); + logger.warn(msg, e); } return false; } @@ -653,7 +654,7 @@ protected boolean taintControlNodes() { protected boolean deployProvider() { Network network = networkDao.findById(kubernetesCluster.getNetworkId()); // Since the provider creates IP addresses, don't deploy it unless the underlying network supports it - if (network.getGuestType() != GuestType.Isolated) { + if (manager.isDirectAccess(network)) { logMessage(Level.INFO, String.format("Skipping adding the provider as %s is not on an isolated network", kubernetesCluster.getName()), null); return true; diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterDestroyWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterDestroyWorker.java index d42f31ec2d3b..50d7fb14085a 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterDestroyWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterDestroyWorker.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.context.CallContext; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Level; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientAddressCapacityException; @@ -56,6 +55,7 @@ import com.cloud.vm.UserVmVO; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; +import org.apache.logging.log4j.Level; public class KubernetesClusterDestroyWorker extends KubernetesClusterResourceModifierActionWorker { @@ -78,7 +78,7 @@ private void validateClusterSate() { || kubernetesCluster.getState().equals(KubernetesCluster.State.Destroying))) { String msg = String.format("Cannot perform delete operation on cluster : %s in state: %s", kubernetesCluster.getName(), kubernetesCluster.getState()); - LOGGER.warn(msg); + logger.warn(msg); throw new PermissionDeniedException(msg); } } @@ -100,15 +100,15 @@ private boolean destroyClusterVMs() { try { UserVm vm = userVmService.destroyVm(vmID, true); if (!userVmManager.expunge(userVM)) { - LOGGER.warn(String.format("Unable to expunge VM %s : %s, destroying Kubernetes cluster will probably fail", + logger.warn(String.format("Unable to expunge VM %s : %s, destroying Kubernetes cluster will probably fail", vm.getInstanceName() , vm.getUuid())); } kubernetesClusterVmMapDao.expunge(clusterVM.getId()); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Destroyed VM : %s as part of Kubernetes cluster : %s cleanup", vm.getDisplayName(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Destroyed VM : %s as part of Kubernetes cluster : %s cleanup", vm.getDisplayName(), kubernetesCluster.getName())); } } catch (ResourceUnavailableException | ConcurrentOperationException e) { - LOGGER.warn(String.format("Failed to destroy VM : %s part of the Kubernetes cluster : %s cleanup. Moving on with destroying remaining resources provisioned for the Kubernetes cluster", userVM.getDisplayName(), kubernetesCluster.getName()), e); + logger.warn(String.format("Failed to destroy VM : %s part of the Kubernetes cluster : %s cleanup. Moving on with destroying remaining resources provisioned for the Kubernetes cluster", userVM.getDisplayName(), kubernetesCluster.getName()), e); return false; } finally { CallContext.unregister(); @@ -133,11 +133,11 @@ private void destroyKubernetesClusterNetwork() throws ManagementServerException boolean networkDestroyed = networkMgr.destroyNetwork(kubernetesCluster.getNetworkId(), context, true); if (!networkDestroyed) { String msg = String.format("Failed to destroy network : %s as part of Kubernetes cluster : %s cleanup", network.getName(), kubernetesCluster.getName()); - LOGGER.warn(msg); + logger.warn(msg); throw new ManagementServerException(msg); } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Destroyed network : %s as part of Kubernetes cluster : %s cleanup", + if (logger.isInfoEnabled()) { + logger.info(String.format("Destroyed network : %s as part of Kubernetes cluster : %s cleanup", network.getName(), kubernetesCluster.getName())); } } @@ -223,7 +223,7 @@ private void validateClusterVMsDestroyed() { private void checkForRulesToDelete() throws ManagementServerException { NetworkVO kubernetesClusterNetwork = networkDao.findById(kubernetesCluster.getNetworkId()); - if (kubernetesClusterNetwork != null && kubernetesClusterNetwork.getGuestType() != Network.GuestType.Shared) { + if (kubernetesClusterNetwork != null && !manager.isDirectAccess(kubernetesClusterNetwork)) { deleteKubernetesClusterNetworkRules(); } } @@ -270,11 +270,11 @@ public boolean destroy() throws CloudRuntimeException { } } } else { - LOGGER.error(String.format("Failed to find network for Kubernetes cluster : %s", kubernetesCluster.getName())); + logger.error(String.format("Failed to find network for Kubernetes cluster : %s", kubernetesCluster.getName())); } } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Destroying Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Destroying Kubernetes cluster : %s", kubernetesCluster.getName())); } stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.DestroyRequested); boolean vmsDestroyed = destroyClusterVMs(); @@ -286,7 +286,7 @@ public boolean destroy() throws CloudRuntimeException { destroyKubernetesClusterNetwork(); } catch (ManagementServerException e) { String msg = String.format("Failed to destroy network of Kubernetes cluster : %s cleanup", kubernetesCluster.getName()); - LOGGER.warn(msg, e); + logger.warn(msg, e); updateKubernetesClusterEntryForGC(); throw new CloudRuntimeException(msg, e); } @@ -295,7 +295,7 @@ public boolean destroy() throws CloudRuntimeException { checkForRulesToDelete(); } catch (ManagementServerException e) { String msg = String.format("Failed to remove network rules of Kubernetes cluster : %s", kubernetesCluster.getName()); - LOGGER.warn(msg, e); + logger.warn(msg, e); updateKubernetesClusterEntryForGC(); throw new CloudRuntimeException(msg, e); } @@ -303,14 +303,14 @@ public boolean destroy() throws CloudRuntimeException { releaseVpcTierPublicIpIfNeeded(); } catch (InsufficientAddressCapacityException e) { String msg = String.format("Failed to release public IP for VPC tier used by Kubernetes cluster : %s", kubernetesCluster.getName()); - LOGGER.warn(msg, e); + logger.warn(msg, e); updateKubernetesClusterEntryForGC(); throw new CloudRuntimeException(msg, e); } } } else { String msg = String.format("Failed to destroy one or more VMs as part of Kubernetes cluster : %s cleanup", kubernetesCluster.getName()); - LOGGER.warn(msg); + logger.warn(msg); updateKubernetesClusterEntryForGC(); throw new CloudRuntimeException(msg); } @@ -323,8 +323,8 @@ public boolean destroy() throws CloudRuntimeException { updateKubernetesClusterEntryForGC(); return false; } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Kubernetes cluster : %s is successfully deleted", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Kubernetes cluster : %s is successfully deleted", kubernetesCluster.getName())); } return true; } diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java index d721db4b6b47..2a001c4aa94e 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterResourceModifierActionWorker.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -31,17 +30,17 @@ import javax.inject.Inject; -import org.apache.cloudstack.api.ApiCommandResourceType; +import com.cloud.network.rules.FirewallManager; +import com.cloud.offering.NetworkOffering; +import com.cloud.offerings.dao.NetworkOfferingDao; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.command.user.firewall.CreateFirewallRuleCmd; import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd; import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd; -import org.apache.cloudstack.context.CallContext; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Level; import com.cloud.capacity.CapacityManager; import com.cloud.dc.ClusterDetailsDao; @@ -58,6 +57,7 @@ import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.Host; import com.cloud.host.HostVO; @@ -101,7 +101,6 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.db.TransactionCallback; import com.cloud.utils.db.TransactionCallbackWithException; -import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; @@ -111,6 +110,9 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VmDetailConstants; import com.cloud.vm.dao.VMInstanceDao; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.context.CallContext; +import org.apache.logging.log4j.Level; public class KubernetesClusterResourceModifierActionWorker extends KubernetesClusterActionWorker { @@ -135,6 +137,8 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu @Inject protected RulesService rulesService; @Inject + protected FirewallManager firewallManager; + @Inject protected PortForwardingRulesDao portForwardingRulesDao; @Inject protected ResourceManager resourceManager; @@ -150,6 +154,8 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu protected VolumeApiService volumeService; @Inject protected VolumeDao volumeDao; + @Inject + protected NetworkOfferingDao networkOfferingDao; protected String kubernetesClusterNodeNamePrefix; @@ -168,6 +174,7 @@ private String getKubernetesNodeConfig(final String joinIp, final boolean ejectI final String joinIpKey = "{{ k8s_control_node.join_ip }}"; final String clusterTokenKey = "{{ k8s_control_node.cluster.token }}"; final String ejectIsoKey = "{{ k8s.eject.iso }}"; + String pubKey = "- \"" + configurationDao.getValue("ssh.publickey") + "\""; String sshKeyPair = kubernetesCluster.getKeyPair(); if (StringUtils.isNotEmpty(sshKeyPair)) { @@ -180,7 +187,6 @@ private String getKubernetesNodeConfig(final String joinIp, final boolean ejectI k8sNodeConfig = k8sNodeConfig.replace(joinIpKey, joinIp); k8sNodeConfig = k8sNodeConfig.replace(clusterTokenKey, KubernetesClusterUtil.generateClusterToken(kubernetesCluster)); k8sNodeConfig = k8sNodeConfig.replace(ejectIsoKey, String.valueOf(ejectIso)); - k8sNodeConfig = updateKubeConfigWithRegistryDetails(k8sNodeConfig); return k8sNodeConfig; @@ -256,44 +262,42 @@ protected DeployDestination plan(final long nodesCount, final DataCenter zone, f ClusterDetailsVO cluster_detail_ram = clusterDetailsDao.findDetail(cluster.getId(), "memoryOvercommitRatio"); Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue()); Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue()); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Checking host : %s for capacity already reserved %d", h.getName(), reserved)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Checking host : %s for capacity already reserved %d", h.getName(), reserved)); } if (capacityManager.checkIfHostHasCapacity(h.getId(), cpu_requested * reserved, ram_requested * reserved, false, cpuOvercommitRatio, memoryOvercommitRatio, true)) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Found host : %s for with enough capacity, CPU=%d RAM=%s", h.getName(), cpu_requested * reserved, toHumanReadableSize(ram_requested * reserved))); - } + logger.debug("Found host {} with enough capacity: CPU={} RAM={}", h.getName(), cpu_requested * reserved, toHumanReadableSize(ram_requested * reserved)); hostEntry.setValue(new Pair(h, reserved)); suitable_host_found = true; break; } } if (!suitable_host_found) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Suitable hosts not found in datacenter : %s for node %d, with offering : %s and hypervisor: %s", + if (logger.isInfoEnabled()) { + logger.info(String.format("Suitable hosts not found in datacenter : %s for node %d, with offering : %s and hypervisor: %s", zone.getName(), i, offering.getName(), clusterTemplate.getHypervisorType().toString())); } break; } } if (suitable_host_found) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Suitable hosts found in datacenter : %s, creating deployment destination", zone.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Suitable hosts found in datacenter : %s, creating deployment destination", zone.getName())); } return new DeployDestination(zone, null, null, null); } String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%d memory=%s) with offering : %s and hypervisor: %s", cpu_requested * nodesCount, toHumanReadableSize(ram_requested * nodesCount), offering.getName(), clusterTemplate.getHypervisorType().toString()); - LOGGER.warn(msg); + logger.warn(msg); throw new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId()); } protected DeployDestination plan() throws InsufficientServerCapacityException { ServiceOffering offering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId()); DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId()); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Checking deployment destination for Kubernetes cluster : %s in zone : %s", kubernetesCluster.getName(), zone.getName())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Checking deployment destination for Kubernetes cluster : %s in zone : %s", kubernetesCluster.getName(), zone.getName())); } return plan(kubernetesCluster.getTotalNodeCount(), zone, offering); } @@ -306,17 +310,14 @@ protected void resizeNodeVolume(final UserVm vm) throws ManagementServerExceptio if (volumeVO.getVolumeType() == Volume.Type.ROOT) { ResizeVolumeCmd resizeVolumeCmd = new ResizeVolumeCmd(); resizeVolumeCmd = ComponentContext.inject(resizeVolumeCmd); - Field f = resizeVolumeCmd.getClass().getDeclaredField("size"); - Field f1 = resizeVolumeCmd.getClass().getDeclaredField("id"); - f.setAccessible(true); - f1.setAccessible(true); - f1.set(resizeVolumeCmd, volumeVO.getId()); - f.set(resizeVolumeCmd, kubernetesCluster.getNodeRootDiskSize()); + resizeVolumeCmd.setSize(kubernetesCluster.getNodeRootDiskSize()); + resizeVolumeCmd.setId(volumeVO.getId()); + volumeService.resizeVolume(resizeVolumeCmd); } } } - } catch (IllegalAccessException | NoSuchFieldException e) { + } catch (ResourceAllocationException e) { throw new ManagementServerException(String.format("Failed to resize volume of VM in the Kubernetes cluster : %s", kubernetesCluster.getName()), e); } } @@ -361,9 +362,7 @@ protected List provisionKubernetesClusterNodeVms(final long nodeCount, f throw new ManagementServerException(String.format("Failed to provision worker VM for Kubernetes cluster : %s", kubernetesCluster.getName())); } nodes.add(vm); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Provisioned node VM : %s in to the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName())); - } + logger.info("Provisioned node VM : {} in to the Kubernetes cluster : {}", vm.getDisplayName(), kubernetesCluster.getName()); } finally { CallContext.unregister(); } @@ -407,7 +406,7 @@ protected UserVm createKubernetesNode(String joinIp) throws ManagementServerExce if (StringUtils.isNotBlank(kubernetesCluster.getKeyPair())) { keypairs.add(kubernetesCluster.getKeyPair()); } - if (zone.isSecurityGroupEnabled()) { + if (kubernetesCluster.getSecurityGroupId() != null && networkModel.checkSecurityGroupSupportForNetwork(owner, zone, networkIds, List.of(kubernetesCluster.getSecurityGroupId()))) { List securityGroupIds = new ArrayList<>(); securityGroupIds.add(kubernetesCluster.getSecurityGroupId()); nodeVm = userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, clusterTemplate, networkIds, securityGroupIds, owner, @@ -420,8 +419,8 @@ protected UserVm createKubernetesNode(String joinIp) throws ManagementServerExce Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, base64UserData, null, null, keypairs, null, addrs, null, null, null, customParameterMap, null, null, null, null, true, UserVmManager.CKS_NODE, null); } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Created node VM : %s, %s in the Kubernetes cluster : %s", hostName, nodeVm.getUuid(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Created node VM : %s, %s in the Kubernetes cluster : %s", hostName, nodeVm.getUuid(), kubernetesCluster.getName())); } return nodeVm; } @@ -431,30 +430,20 @@ protected void provisionFirewallRules(final IpAddress publicIp, final Account ac List sourceCidrList = new ArrayList(); sourceCidrList.add("0.0.0.0/0"); - CreateFirewallRuleCmd rule = new CreateFirewallRuleCmd(); - rule = ComponentContext.inject(rule); + CreateFirewallRuleCmd firewallRule = new CreateFirewallRuleCmd(); + firewallRule = ComponentContext.inject(firewallRule); - Field addressField = rule.getClass().getDeclaredField("ipAddressId"); - addressField.setAccessible(true); - addressField.set(rule, publicIp.getId()); + firewallRule.setIpAddressId(publicIp.getId()); - Field protocolField = rule.getClass().getDeclaredField("protocol"); - protocolField.setAccessible(true); - protocolField.set(rule, "TCP"); + firewallRule.setProtocol("TCP"); - Field startPortField = rule.getClass().getDeclaredField("publicStartPort"); - startPortField.setAccessible(true); - startPortField.set(rule, startPort); + firewallRule.setPublicStartPort(startPort); - Field endPortField = rule.getClass().getDeclaredField("publicEndPort"); - endPortField.setAccessible(true); - endPortField.set(rule, endPort); + firewallRule.setPublicEndPort(endPort); - Field cidrField = rule.getClass().getDeclaredField("cidrlist"); - cidrField.setAccessible(true); - cidrField.set(rule, sourceCidrList); + firewallRule.setSourceCidrList(sourceCidrList); - firewallService.createIngressFirewallRule(rule); + firewallService.createIngressFirewallRule(firewallRule); firewallService.applyIngressFwRules(publicIp.getId(), account); } @@ -479,8 +468,8 @@ protected void provisionPublicIpPortForwardingRule(IpAddress publicIp, Network n return newRule; }); rulesService.applyPortForwardingRules(publicIp.getId(), account); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Provisioned SSH port forwarding rule: %s from port %d to %d on %s to the VM IP : %s in Kubernetes cluster : %s", pfRule.getUuid(), sourcePort, destPort, publicIp.getAddress().addr(), vmIp.toString(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Provisioned SSH port forwarding rule: %s from port %d to %d on %s to the VM IP : %s in Kubernetes cluster : %s", pfRule.getUuid(), sourcePort, destPort, publicIp.getAddress().addr(), vmIp.toString(), kubernetesCluster.getName())); } } @@ -515,6 +504,7 @@ protected FirewallRule removeApiFirewallRule(final IpAddress publicIp) { firewallRule.getSourcePortEnd() == CLUSTER_API_PORT) { rule = firewallRule; firewallService.revokeIngressFwRule(firewallRule.getId(), true); + logger.debug("The API firewall rule [%s] with the id [%s] was revoked",firewallRule.getName(),firewallRule.getId()); break; } } @@ -528,6 +518,7 @@ protected FirewallRule removeSshFirewallRule(final IpAddress publicIp) { if (firewallRule.getSourcePortStart() == CLUSTER_NODES_DEFAULT_START_SSH_PORT) { rule = firewallRule; firewallService.revokeIngressFwRule(firewallRule.getId(), true); + logger.debug("The SSH firewall rule [%s] with the id [%s] was revoked",firewallRule.getName(),firewallRule.getId()); break; } } @@ -536,16 +527,22 @@ protected FirewallRule removeSshFirewallRule(final IpAddress publicIp) { protected void removePortForwardingRules(final IpAddress publicIp, final Network network, final Account account, final List removedVMIds) throws ResourceUnavailableException { if (!CollectionUtils.isEmpty(removedVMIds)) { + List pfRules = new ArrayList<>(); + List revokedRules = new ArrayList<>(); for (Long vmId : removedVMIds) { - List pfRules = portForwardingRulesDao.listByNetwork(network.getId()); + pfRules.addAll(portForwardingRulesDao.listByNetwork(network.getId())); for (PortForwardingRuleVO pfRule : pfRules) { if (pfRule.getVirtualMachineId() == vmId) { portForwardingRulesDao.remove(pfRule.getId()); + logger.trace("Marking PF rule {} with Revoke state", pfRule); + pfRule.setState(FirewallRule.State.Revoke); + revokedRules.add(pfRule); + logger.debug("The Port forwarding rule [%s] with the id [%s] was removed.", pfRule.getName(), pfRule.getId()); break; } } } - rulesService.applyPortForwardingRules(publicIp.getId(), account); + firewallManager.applyRules(revokedRules, false, true); } } @@ -555,46 +552,45 @@ protected void removePortForwardingRules(final IpAddress publicIp, final Network for (PortForwardingRuleVO pfRule : pfRules) { if (startPort <= pfRule.getSourcePortStart() && pfRule.getSourcePortStart() <= endPort) { portForwardingRulesDao.remove(pfRule.getId()); + logger.debug("The Port forwarding rule [{}] with the id [{}] was mark as revoked.", pfRule.getName(), pfRule.getId()); + pfRule.setState(FirewallRule.State.Revoke); } } - rulesService.applyPortForwardingRules(publicIp.getId(), account); + firewallManager.applyRules(pfRules, false, true); } protected void removeLoadBalancingRule(final IpAddress publicIp, final Network network, final Account account) throws ResourceUnavailableException { - List rules = loadBalancerDao.listByIpAddress(publicIp.getId()); - for (LoadBalancerVO rule : rules) { - if (rule.getNetworkId() == network.getId() && - rule.getAccountId() == account.getId() && - rule.getSourcePortStart() == CLUSTER_API_PORT && - rule.getSourcePortEnd() == CLUSTER_API_PORT) { - lbService.deleteLoadBalancerRule(rule.getId(), true); - break; - } - } + List loadBalancerRules = loadBalancerDao.listByIpAddress(publicIp.getId()); + loadBalancerRules.stream().filter(lbRules -> lbRules.getNetworkId() == network.getId() && lbRules.getAccountId() == account.getId() && lbRules.getSourcePortStart() == CLUSTER_API_PORT + && lbRules.getSourcePortEnd() == CLUSTER_API_PORT).forEach(lbRule -> { + lbService.deleteLoadBalancerRule(lbRule.getId(), true); + logger.debug("The load balancing rule with the Id: {} was removed",lbRule.getId()); + }); } protected void provisionVpcTierAllowPortACLRule(final Network network, int startPort, int endPorts) throws NoSuchFieldException, IllegalAccessException, ResourceUnavailableException { List aclItems = networkACLItemDao.listByACL(network.getNetworkACLId()); - aclItems = aclItems.stream().filter(x -> !NetworkACLItem.State.Revoke.equals(x.getState())).collect(Collectors.toList()); - CreateNetworkACLCmd rule = new CreateNetworkACLCmd(); - rule = ComponentContext.inject(rule); - Map fieldValues = Map.of( - "protocol", "TCP", - "publicStartPort", startPort, - "publicEndPort", endPorts, - "trafficType", NetworkACLItem.TrafficType.Ingress.toString(), - "networkId", network.getId(), - "aclId", network.getNetworkACLId(), - "action", NetworkACLItem.Action.Allow.toString() - ); - for (Map.Entry entry : fieldValues.entrySet()) { - Field field = rule.getClass().getDeclaredField(entry.getKey()); - field.setAccessible(true); - field.set(rule, entry.getValue()); - } - NetworkACLItem aclRule = networkACLService.createNetworkACLItem(rule); + aclItems = aclItems.stream().filter(networkACLItem -> !NetworkACLItem.State.Revoke.equals(networkACLItem.getState())).collect(Collectors.toList()); + CreateNetworkACLCmd networkACLRule = new CreateNetworkACLCmd(); + networkACLRule = ComponentContext.inject(networkACLRule); + + networkACLRule.setProtocol("TCP"); + + networkACLRule.setPublicStartPort(startPort); + + networkACLRule.setPublicEndPort(endPorts); + + networkACLRule.setTrafficType(NetworkACLItem.TrafficType.Ingress.toString()); + + networkACLRule.setNetworkId(network.getId()); + + networkACLRule.setAclId(network.getNetworkACLId()); + + networkACLRule.setAction(NetworkACLItem.Action.Allow.toString()); + + NetworkACLItem aclRule = networkACLService.createNetworkACLItem(networkACLRule); networkACLService.moveRuleToTheTopInACLList(aclRule); networkACLService.applyNetworkACL(aclRule.getAclId()); } @@ -602,13 +598,13 @@ protected void provisionVpcTierAllowPortACLRule(final Network network, int start protected void removeVpcTierAllowPortACLRule(final Network network, int startPort, int endPort) throws NoSuchFieldException, IllegalAccessException, ResourceUnavailableException { List aclItems = networkACLItemDao.listByACL(network.getNetworkACLId()); - aclItems = aclItems.stream().filter(x -> (x.getProtocol() != null && - x.getProtocol().equals("TCP") && - x.getSourcePortStart() != null && - x.getSourcePortStart().equals(startPort) && - x.getSourcePortEnd() != null && - x.getSourcePortEnd().equals(endPort) && - x.getAction().equals(NetworkACLItem.Action.Allow))) + aclItems = aclItems.stream().filter(networkACLItem -> (networkACLItem.getProtocol() != null && + networkACLItem.getProtocol().equals("TCP") && + networkACLItem.getSourcePortStart() != null && + networkACLItem.getSourcePortStart().equals(startPort) && + networkACLItem.getSourcePortEnd() != null && + networkACLItem.getSourcePortEnd().equals(endPort) && + networkACLItem.getAction().equals(NetworkACLItem.Action.Allow))) .collect(Collectors.toList()); for (NetworkACLItemVO aclItem : aclItems) { @@ -640,8 +636,8 @@ protected void createFirewallRules(IpAddress publicIp, List clusterVMIds, try { int endPort = CLUSTER_NODES_DEFAULT_START_SSH_PORT + clusterVMIds.size() - 1; provisionFirewallRules(publicIp, owner, CLUSTER_NODES_DEFAULT_START_SSH_PORT, endPort); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Provisioned firewall rule to open up port %d to %d on %s for Kubernetes cluster : %s", CLUSTER_NODES_DEFAULT_START_SSH_PORT, endPort, publicIp.getAddress().addr(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Provisioned firewall rule to open up port %d to %d on %s for Kubernetes cluster : %s", CLUSTER_NODES_DEFAULT_START_SSH_PORT, endPort, publicIp.getAddress().addr(), kubernetesCluster.getName())); } } catch (NoSuchFieldException | IllegalAccessException | ResourceUnavailableException | NetworkRuleConflictException e) { throw new ManagementServerException(String.format("Failed to provision firewall rules for SSH access for the Kubernetes cluster : %s", kubernetesCluster.getName()), e); @@ -655,8 +651,8 @@ protected void createFirewallRules(IpAddress publicIp, List clusterVMIds, CallContext.register(CallContext.current(), null); try { provisionFirewallRules(publicIp, owner, CLUSTER_API_PORT, CLUSTER_API_PORT); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Provisioned firewall rule to open up port %d on %s for Kubernetes cluster %s", + if (logger.isInfoEnabled()) { + logger.info(String.format("Provisioned firewall rule to open up port %d on %s for Kubernetes cluster %s", CLUSTER_API_PORT, publicIp.getAddress().addr(), kubernetesCluster.getName())); } } catch (NoSuchFieldException | IllegalAccessException | ResourceUnavailableException | NetworkRuleConflictException e) { @@ -706,8 +702,8 @@ protected void createVpcTierAclRules(Network network) throws ManagementServerExc CallContext.register(CallContext.current(), null); try { provisionVpcTierAllowPortACLRule(network, CLUSTER_API_PORT, CLUSTER_API_PORT); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Provisioned ACL rule to open up port %d on %s for Kubernetes cluster %s", + if (logger.isInfoEnabled()) { + logger.info(String.format("Provisioned ACL rule to open up port %d on %s for Kubernetes cluster %s", CLUSTER_API_PORT, publicIpAddress, kubernetesCluster.getName())); } } catch (NoSuchFieldException | IllegalAccessException | ResourceUnavailableException | InvalidParameterValueException | PermissionDeniedException e) { @@ -718,8 +714,8 @@ protected void createVpcTierAclRules(Network network) throws ManagementServerExc CallContext.register(CallContext.current(), null); try { provisionVpcTierAllowPortACLRule(network, DEFAULT_SSH_PORT, DEFAULT_SSH_PORT); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Provisioned ACL rule to open up port %d on %s for Kubernetes cluster %s", + if (logger.isInfoEnabled()) { + logger.info(String.format("Provisioned ACL rule to open up port %d on %s for Kubernetes cluster %s", DEFAULT_SSH_PORT, publicIpAddress, kubernetesCluster.getName())); } } catch (NoSuchFieldException | IllegalAccessException | ResourceUnavailableException | InvalidParameterValueException | PermissionDeniedException e) { @@ -736,8 +732,8 @@ protected void removeVpcTierAclRules(Network network) throws ManagementServerExc // ACL rule for API access for control node VMs try { removeVpcTierAllowPortACLRule(network, CLUSTER_API_PORT, CLUSTER_API_PORT); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Removed network ACL rule to open up port %d on %s for Kubernetes cluster %s", + if (logger.isInfoEnabled()) { + logger.info(String.format("Removed network ACL rule to open up port %d on %s for Kubernetes cluster %s", CLUSTER_API_PORT, publicIpAddress, kubernetesCluster.getName())); } } catch (NoSuchFieldException | IllegalAccessException | ResourceUnavailableException e) { @@ -746,8 +742,8 @@ protected void removeVpcTierAclRules(Network network) throws ManagementServerExc // ACL rule for SSH access for all node VMs try { removeVpcTierAllowPortACLRule(network, DEFAULT_SSH_PORT, DEFAULT_SSH_PORT); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Removed network ACL rule to open up port %d on %s for Kubernetes cluster %s", + if (logger.isInfoEnabled()) { + logger.info(String.format("Removed network ACL rule to open up port %d on %s for Kubernetes cluster %s", DEFAULT_SSH_PORT, publicIpAddress, kubernetesCluster.getName())); } } catch (NoSuchFieldException | IllegalAccessException | ResourceUnavailableException e) { @@ -758,12 +754,24 @@ protected void removeVpcTierAclRules(Network network) throws ManagementServerExc protected void setupKubernetesClusterVpcTierRules(IpAddress publicIp, Network network, List clusterVMIds) throws ManagementServerException { // Create ACL rules createVpcTierAclRules(network); - // Add port forwarding for API access - try { - provisionPublicIpPortForwardingRule(publicIp, network, owner, clusterVMIds.get(0), CLUSTER_API_PORT, CLUSTER_API_PORT); - } catch (ResourceUnavailableException | NetworkRuleConflictException e) { - throw new ManagementServerException(String.format("Failed to activate API port forwarding rules for the Kubernetes cluster : %s", kubernetesCluster.getName()), e); + + NetworkOffering offering = networkOfferingDao.findById(network.getNetworkOfferingId()); + if (offering.isConserveMode()) { + // Add load balancing for API access + try { + provisionLoadBalancerRule(publicIp, network, owner, clusterVMIds, CLUSTER_API_PORT); + } catch (InsufficientAddressCapacityException e) { + throw new ManagementServerException(String.format("Failed to activate API load balancing rules for the Kubernetes cluster : %s", kubernetesCluster.getName()), e); + } + } else { + // Add port forwarding for API access + try { + provisionPublicIpPortForwardingRule(publicIp, network, owner, clusterVMIds.get(0), CLUSTER_API_PORT, CLUSTER_API_PORT); + } catch (ResourceUnavailableException | NetworkRuleConflictException e) { + throw new ManagementServerException(String.format("Failed to activate API port forwarding rules for the Kubernetes cluster : %s", kubernetesCluster.getName()), e); + } } + // Add port forwarding rule for SSH access on each node VM try { provisionSshPortForwardingRules(publicIp, network, owner, clusterVMIds); @@ -789,29 +797,27 @@ protected String getKubernetesClusterNodeNamePrefix() { protected KubernetesClusterVO updateKubernetesClusterEntry(final Long cores, final Long memory, final Long size, final Long serviceOfferingId, final Boolean autoscaleEnabled, final Long minSize, final Long maxSize) { - return Transaction.execute(new TransactionCallback() { - @Override - public KubernetesClusterVO doInTransaction(TransactionStatus status) { - KubernetesClusterVO updatedCluster = kubernetesClusterDao.findById(kubernetesCluster.getId()); - if (cores != null) { - updatedCluster.setCores(cores); - } - if (memory != null) { - updatedCluster.setMemory(memory); - } - if (size != null) { - updatedCluster.setNodeCount(size); - } - if (serviceOfferingId != null) { - updatedCluster.setServiceOfferingId(serviceOfferingId); - } - if (autoscaleEnabled != null) { - updatedCluster.setAutoscalingEnabled(autoscaleEnabled.booleanValue()); - } - updatedCluster.setMinSize(minSize); - updatedCluster.setMaxSize(maxSize); - return kubernetesClusterDao.persist(updatedCluster); + return Transaction.execute((TransactionCallback) status -> { + KubernetesClusterVO updatedCluster = kubernetesClusterDao.createForUpdate(kubernetesCluster.getId()); + + if (cores != null) { + updatedCluster.setCores(cores); + } + if (memory != null) { + updatedCluster.setMemory(memory); + } + if (size != null) { + updatedCluster.setNodeCount(size); + } + if (serviceOfferingId != null) { + updatedCluster.setServiceOfferingId(serviceOfferingId); + } + if (autoscaleEnabled != null) { + updatedCluster.setAutoscalingEnabled(autoscaleEnabled.booleanValue()); } + updatedCluster.setMinSize(minSize); + updatedCluster.setMaxSize(maxSize); + return kubernetesClusterDao.persist(updatedCluster); }); } diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterScaleWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterScaleWorker.java index 5b496509eebc..aa500de91902 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterScaleWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterScaleWorker.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Level; import com.cloud.dc.DataCenter; import com.cloud.exception.InsufficientCapacityException; @@ -59,6 +58,7 @@ import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.dao.VMInstanceDao; +import org.apache.logging.log4j.Level; public class KubernetesClusterScaleWorker extends KubernetesClusterResourceModifierActionWorker { @@ -163,9 +163,9 @@ private void scaleKubernetesClusterVpcTierRules(final List clusterVMIds) t * @throws ManagementServerException */ private void scaleKubernetesClusterNetworkRules(final List clusterVMIds) throws ManagementServerException { - if (!Network.GuestType.Isolated.equals(network.getGuestType())) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Network : %s for Kubernetes cluster : %s is not an isolated network, therefore, no need for network rules", network.getName(), kubernetesCluster.getName())); + if (manager.isDirectAccess(network)) { + if (logger.isDebugEnabled()) { + logger.debug(String.format("Network : %s for Kubernetes cluster : %s is not an isolated network or ROUTED network, therefore, no need for network rules", network.getName(), kubernetesCluster.getName())); } return; } @@ -206,7 +206,7 @@ private boolean removeKubernetesClusterNode(final String ipAddress, final int po pkFile, null, String.format("sudo /opt/bin/kubectl drain %s --ignore-daemonsets --delete-local-data", hostName), 10000, 10000, 60000); if (!result.first()) { - LOGGER.warn(String.format("Draining node: %s on VM : %s in Kubernetes cluster : %s unsuccessful", hostName, userVm.getDisplayName(), kubernetesCluster.getName())); + logger.warn(String.format("Draining node: %s on VM : %s in Kubernetes cluster : %s unsuccessful", hostName, userVm.getDisplayName(), kubernetesCluster.getName())); } else { result = SshHelper.sshExecute(ipAddress, port, getControlNodeLoginUser(), pkFile, null, String.format("sudo /opt/bin/kubectl delete node %s", hostName), @@ -214,18 +214,18 @@ private boolean removeKubernetesClusterNode(final String ipAddress, final int po if (result.first()) { return true; } else { - LOGGER.warn(String.format("Deleting node: %s on VM : %s in Kubernetes cluster : %s unsuccessful", hostName, userVm.getDisplayName(), kubernetesCluster.getName())); + logger.warn(String.format("Deleting node: %s on VM : %s in Kubernetes cluster : %s unsuccessful", hostName, userVm.getDisplayName(), kubernetesCluster.getName())); } } break; } catch (Exception e) { String msg = String.format("Failed to remove Kubernetes cluster : %s node: %s on VM : %s", kubernetesCluster.getName(), hostName, userVm.getDisplayName()); - LOGGER.warn(msg, e); + logger.warn(msg, e); } try { Thread.sleep(waitDuration); } catch (InterruptedException ie) { - LOGGER.error(String.format("Error while waiting for Kubernetes cluster : %s node: %s on VM : %s removal", kubernetesCluster.getName(), hostName, userVm.getDisplayName()), ie); + logger.error(String.format("Error while waiting for Kubernetes cluster : %s node: %s on VM : %s removal", kubernetesCluster.getName(), hostName, userVm.getDisplayName()), ie); } retryCounter++; } @@ -316,7 +316,7 @@ private void scaleKubernetesClusterOffering() throws CloudRuntimeException { private void removeNodesFromCluster(List vmMaps) throws CloudRuntimeException { for (KubernetesClusterVmMapVO vmMapVO : vmMaps) { UserVmVO userVM = userVmDao.findById(vmMapVO.getVmId()); - LOGGER.info(String.format("Removing vm : %s from cluster %s", userVM.getDisplayName(), kubernetesCluster.getName())); + logger.info(String.format("Removing vm : %s from cluster %s", userVM.getDisplayName(), kubernetesCluster.getName())); if (!removeKubernetesClusterNode(publicIpAddress, sshPort, userVM, 3, 30000)) { logTransitStateAndThrow(Level.ERROR, String.format("Scaling failed for Kubernetes cluster : %s, failed to remove Kubernetes node: %s running on VM : %s", kubernetesCluster.getName(), userVM.getHostName(), userVM.getDisplayName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed); } @@ -436,8 +436,8 @@ private boolean isAutoscalingChanged() { public boolean scaleCluster() throws CloudRuntimeException { init(); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Scaling Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Scaling Kubernetes cluster : %s", kubernetesCluster.getName())); } scaleTimeoutTime = System.currentTimeMillis() + KubernetesClusterService.KubernetesClusterScaleTimeout.value() * 1000; final long originalClusterSize = kubernetesCluster.getNodeCount(); diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStartWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStartWorker.java index 84ad9bdc0a68..028ea1c79925 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStartWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStartWorker.java @@ -36,7 +36,6 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Level; import com.cloud.dc.DataCenter; import com.cloud.dc.Vlan; @@ -74,6 +73,7 @@ import com.cloud.vm.UserVmManager; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VmDetailConstants; +import org.apache.logging.log4j.Level; public class KubernetesClusterStartWorker extends KubernetesClusterResourceModifierActionWorker { @@ -122,7 +122,7 @@ private boolean isKubernetesVersionSupportsHA() { haSupported = true; } } catch (IllegalArgumentException e) { - LOGGER.error(String.format("Unable to compare Kubernetes version for cluster version : %s with %s", version.getName(), KubernetesClusterService.MIN_KUBERNETES_VERSION_HA_SUPPORT), e); + logger.error(String.format("Unable to compare Kubernetes version for cluster version : %s with %s", version.getName(), KubernetesClusterService.MIN_KUBERNETES_VERSION_HA_SUPPORT), e); } } return haSupported; @@ -139,6 +139,7 @@ private String getKubernetesControlNodeConfig(final String controlNodeIp, final final String clusterToken = "{{ k8s_control_node.cluster.token }}"; final String clusterInitArgsKey = "{{ k8s_control_node.cluster.initargs }}"; final String ejectIsoKey = "{{ k8s.eject.iso }}"; + final List addresses = new ArrayList<>(); addresses.add(controlNodeIp); if (!serverIp.equals(controlNodeIp)) { @@ -189,7 +190,7 @@ private UserVm createKubernetesControlNode(final Network network, String serverI Pair> ipAddresses = getKubernetesControlNodeIpAddresses(zone, network, owner); String controlNodeIp = ipAddresses.first(); Map requestedIps = ipAddresses.second(); - if (Network.GuestType.Shared.equals(network.getGuestType()) && StringUtils.isEmpty(serverIp)) { + if (StringUtils.isEmpty(serverIp) && manager.isDirectAccess(network)) { serverIp = controlNodeIp; } Network.IpAddresses addrs = new Network.IpAddresses(controlNodeIp, null); @@ -215,7 +216,9 @@ private UserVm createKubernetesControlNode(final Network network, String serverI if (StringUtils.isNotBlank(kubernetesCluster.getKeyPair())) { keypairs.add(kubernetesCluster.getKeyPair()); } - if (zone.isSecurityGroupEnabled()) { + if (kubernetesCluster.getSecurityGroupId() != null && + networkModel.checkSecurityGroupSupportForNetwork(owner, zone, networkIds, + List.of(kubernetesCluster.getSecurityGroupId()))) { List securityGroupIds = new ArrayList<>(); securityGroupIds.add(kubernetesCluster.getSecurityGroupId()); controlVm = userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, clusterTemplate, networkIds, securityGroupIds, owner, @@ -228,8 +231,8 @@ private UserVm createKubernetesControlNode(final Network network, String serverI Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, base64UserData, null, null, keypairs, requestedIps, addrs, null, null, null, customParameterMap, null, null, null, null, true, UserVmManager.CKS_NODE, null); } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Created control VM ID: %s, %s in the Kubernetes cluster : %s", controlVm.getUuid(), hostName, kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Created control VM ID: %s, %s in the Kubernetes cluster : %s", controlVm.getUuid(), hostName, kubernetesCluster.getName())); } return controlVm; } @@ -241,6 +244,7 @@ private String getKubernetesAdditionalControlNodeConfig(final String joinIp, fin final String sshPubKey = "{{ k8s.ssh.pub.key }}"; final String clusterHACertificateKey = "{{ k8s_control_node.cluster.ha.certificate.key }}"; final String ejectIsoKey = "{{ k8s.eject.iso }}"; + String pubKey = "- \"" + configurationDao.getValue("ssh.publickey") + "\""; String sshKeyPair = kubernetesCluster.getKeyPair(); if (StringUtils.isNotEmpty(sshKeyPair)) { @@ -289,7 +293,9 @@ private UserVm createKubernetesAdditionalControlNode(final String joinIp, final if (StringUtils.isNotBlank(kubernetesCluster.getKeyPair())) { keypairs.add(kubernetesCluster.getKeyPair()); } - if (zone.isSecurityGroupEnabled()) { + if (kubernetesCluster.getSecurityGroupId() != null && + networkModel.checkSecurityGroupSupportForNetwork(owner, zone, networkIds, + List.of(kubernetesCluster.getSecurityGroupId()))) { List securityGroupIds = new ArrayList<>(); securityGroupIds.add(kubernetesCluster.getSecurityGroupId()); additionalControlVm = userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, clusterTemplate, networkIds, securityGroupIds, owner, @@ -303,8 +309,8 @@ private UserVm createKubernetesAdditionalControlNode(final String joinIp, final null, addrs, null, null, null, customParameterMap, null, null, null, null, true, UserVmManager.CKS_NODE, null); } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Created control VM ID : %s, %s in the Kubernetes cluster : %s", additionalControlVm.getUuid(), hostName, kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Created control VM ID : %s, %s in the Kubernetes cluster : %s", additionalControlVm.getUuid(), hostName, kubernetesCluster.getName())); } return additionalControlVm; } @@ -322,8 +328,8 @@ private UserVm provisionKubernetesClusterControlVm(final Network network, final if (k8sControlVM == null) { throw new ManagementServerException(String.format("Failed to provision control VM for Kubernetes cluster : %s" , kubernetesCluster.getName())); } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Provisioned the control VM : %s in to the Kubernetes cluster : %s", k8sControlVM.getDisplayName(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Provisioned the control VM : %s in to the Kubernetes cluster : %s", k8sControlVM.getDisplayName(), kubernetesCluster.getName())); } return k8sControlVM; } @@ -345,8 +351,8 @@ private List provisionKubernetesClusterAdditionalControlVms(final String throw new ManagementServerException(String.format("Failed to provision additional control VM for Kubernetes cluster : %s" , kubernetesCluster.getName())); } additionalControlVms.add(vm); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Provisioned additional control VM : %s in to the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Provisioned additional control VM : %s in to the Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName())); } } } @@ -358,18 +364,18 @@ private Network startKubernetesClusterNetwork(final DeployDestination destinatio Network network = networkDao.findById(kubernetesCluster.getNetworkId()); if (network == null) { String msg = String.format("Network for Kubernetes cluster : %s not found", kubernetesCluster.getName()); - LOGGER.warn(msg); + logger.warn(msg); stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed); throw new ManagementServerException(msg); } try { networkMgr.startNetwork(network.getId(), destination, context); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Network : %s is started for the Kubernetes cluster : %s", network.getName(), kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Network : %s is started for the Kubernetes cluster : %s", network.getName(), kubernetesCluster.getName())); } } catch (ConcurrentOperationException | ResourceUnavailableException |InsufficientCapacityException e) { String msg = String.format("Failed to start Kubernetes cluster : %s as unable to start associated network : %s" , kubernetesCluster.getName(), network.getName()); - LOGGER.error(msg, e); + logger.error(msg, e); stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed); throw new ManagementServerException(msg, e); } @@ -377,9 +383,9 @@ private Network startKubernetesClusterNetwork(final DeployDestination destinatio } protected void setupKubernetesClusterNetworkRules(Network network, List clusterVMs) throws ManagementServerException { - if (!Network.GuestType.Isolated.equals(network.getGuestType())) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Network : %s for Kubernetes cluster : %s is not an isolated network, therefore, no need for network rules", network.getName(), kubernetesCluster.getName())); + if (manager.isDirectAccess(network)) { + if (logger.isDebugEnabled()) { + logger.debug(String.format("Network : %s for Kubernetes cluster : %s is not an isolated network or ROUTED network, therefore, no need for network rules", network.getName(), kubernetesCluster.getName())); } return; } @@ -410,7 +416,7 @@ private void startKubernetesClusterVMs() { resizeNodeVolume(vm); startKubernetesVM(vm); } catch (ManagementServerException ex) { - LOGGER.warn(String.format("Failed to start VM : %s in Kubernetes cluster : %s due to ", vm.getDisplayName(), kubernetesCluster.getName()) + ex); + logger.warn(String.format("Failed to start VM : %s in Kubernetes cluster : %s due to ", vm.getDisplayName(), kubernetesCluster.getName()) + ex); // don't bail out here. proceed further to stop the reset of the VM's } } @@ -464,8 +470,8 @@ private void updateKubernetesClusterEntryEndpoint() { public boolean startKubernetesClusterOnCreate() { init(); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Starting Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Starting Kubernetes cluster : %s", kubernetesCluster.getName())); } final long startTimeoutTime = System.currentTimeMillis() + KubernetesClusterService.KubernetesClusterStartTimeout.value() * 1000; stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.StartRequested); @@ -489,7 +495,7 @@ public boolean startKubernetesClusterOnCreate() { } publicIpAddress = publicIpSshPort.first(); if (StringUtils.isEmpty(publicIpAddress) && - (Network.GuestType.Isolated.equals(network.getGuestType()) || kubernetesCluster.getControlNodeCount() > 1)) { // Shared network, single-control node cluster won't have an IP yet + (!manager.isDirectAccess(network) || kubernetesCluster.getControlNodeCount() > 1)) { // Shared network, single-control node cluster won't have an IP yet logTransitStateAndThrow(Level.ERROR, String.format("Failed to start Kubernetes cluster : %s as no public IP found for the cluster" , kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed); } // Allow account creating the kubernetes cluster to access systemVM template @@ -523,8 +529,8 @@ public boolean startKubernetesClusterOnCreate() { } catch (CloudRuntimeException | ManagementServerException | ResourceUnavailableException | InsufficientCapacityException e) { logTransitStateAndThrow(Level.ERROR, String.format("Provisioning node VM failed in the Kubernetes cluster : %s", kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed, e); } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Kubernetes cluster : %s VMs successfully provisioned", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Kubernetes cluster : %s VMs successfully provisioned", kubernetesCluster.getName())); } try { setupKubernetesClusterNetworkRules(network, clusterVMs); @@ -533,8 +539,8 @@ public boolean startKubernetesClusterOnCreate() { } attachIsoKubernetesVMs(clusterVMs); if (!KubernetesClusterUtil.isKubernetesClusterControlVmRunning(kubernetesCluster, publicIpAddress, publicIpSshPort.second(), startTimeoutTime)) { - String msg = String.format("Failed to setup Kubernetes cluster : %s in usable state as unable to access control node VMs of the cluster", kubernetesCluster.getName()); - if (kubernetesCluster.getControlNodeCount() > 1 && Network.GuestType.Shared.equals(network.getGuestType())) { + String msg = String.format("Failed to setup Kubernetes cluster : %s is not in usable state as the system is unable to access control node VMs of the cluster", kubernetesCluster.getName()); + if (kubernetesCluster.getControlNodeCount() > 1 && manager.isDirectAccess(network)) { msg = String.format("%s. Make sure external load-balancer has port forwarding rules for SSH access on ports %d-%d and API access on port %d", msg, CLUSTER_NODES_DEFAULT_START_SSH_PORT, @@ -570,8 +576,8 @@ public boolean startKubernetesClusterOnCreate() { public boolean startStoppedKubernetesCluster() throws CloudRuntimeException { init(); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Starting Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Starting Kubernetes cluster : %s", kubernetesCluster.getName())); } final long startTimeoutTime = System.currentTimeMillis() + KubernetesClusterService.KubernetesClusterStartTimeout.value() * 1000; stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.StartRequested); @@ -597,8 +603,8 @@ public boolean startStoppedKubernetesCluster() throws CloudRuntimeException { logTransitStateAndThrow(Level.ERROR, String.format("Failed to start Kubernetes cluster : %s in usable state as unable to get Dashboard service running for the cluster", kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed); } stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.OperationSucceeded); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Kubernetes cluster : %s successfully started", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Kubernetes cluster : %s successfully started", kubernetesCluster.getName())); } return true; } diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStopWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStopWorker.java index 74bbfa7f6f0b..60802d12e729 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStopWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterStopWorker.java @@ -19,9 +19,9 @@ import java.util.List; +import org.apache.logging.log4j.Level; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Level; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.cluster.KubernetesCluster; @@ -37,8 +37,8 @@ public KubernetesClusterStopWorker(final KubernetesCluster kubernetesCluster, fi public boolean stop() throws CloudRuntimeException { init(); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Stopping Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Stopping Kubernetes cluster : %s", kubernetesCluster.getName())); } stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.StopRequested); List clusterVMs = getKubernetesClusterVMs(); @@ -51,7 +51,7 @@ public boolean stop() throws CloudRuntimeException { try { userVmService.stopVirtualMachine(vm.getId(), false); } catch (ConcurrentOperationException ex) { - LOGGER.warn(String.format("Failed to stop VM : %s in Kubernetes cluster : %s", + logger.warn(String.format("Failed to stop VM : %s in Kubernetes cluster : %s", vm.getDisplayName(), kubernetesCluster.getName()), ex); } finally { CallContext.unregister(); diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterUpgradeWorker.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterUpgradeWorker.java index d418e20f58f7..4fefa54a6d98 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterUpgradeWorker.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterUpgradeWorker.java @@ -23,7 +23,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Level; +import org.apache.logging.log4j.Level; import com.cloud.hypervisor.Hypervisor; import com.cloud.kubernetes.cluster.KubernetesCluster; @@ -84,8 +84,8 @@ private void upgradeKubernetesClusterNodes() { hostName = hostName.toLowerCase(); } Pair result; - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Upgrading node on VM %s in Kubernetes cluster %s with Kubernetes version(%s) ID: %s", + if (logger.isInfoEnabled()) { + logger.info(String.format("Upgrading node on VM %s in Kubernetes cluster %s with Kubernetes version(%s) ID: %s", vm.getDisplayName(), kubernetesCluster.getName(), upgradeVersion.getSemanticVersion(), upgradeVersion.getUuid())); } String errorMessage = String.format("Failed to upgrade Kubernetes cluster : %s, unable to drain Kubernetes node on VM : %s", kubernetesCluster.getName(), vm.getDisplayName()); @@ -98,13 +98,13 @@ private void upgradeKubernetesClusterNodes() { break; } if (retry > 0) { - LOGGER.error(String.format("%s, retries left: %s", errorMessage, retry)); + logger.error(String.format("%s, retries left: %s", errorMessage, retry)); } else { logTransitStateDetachIsoAndThrow(Level.ERROR, errorMessage, kubernetesCluster, clusterVMs, KubernetesCluster.Event.OperationFailed, null); } } catch (Exception e) { if (retry > 0) { - LOGGER.error(String.format("%s due to %s, retries left: %s", errorMessage, e, retry)); + logger.error(String.format("%s due to %s, retries left: %s", errorMessage, e, retry)); } else { logTransitStateDetachIsoAndThrow(Level.ERROR, errorMessage, kubernetesCluster, clusterVMs, KubernetesCluster.Event.OperationFailed, e); } @@ -122,13 +122,13 @@ private void upgradeKubernetesClusterNodes() { break; } if (retry > 0) { - LOGGER.error(String.format("%s, retries left: %s", errorMessage, retry)); + logger.error(String.format("%s, retries left: %s", errorMessage, retry)); } else { logTransitStateDetachIsoAndThrow(Level.ERROR, errorMessage, kubernetesCluster, clusterVMs, KubernetesCluster.Event.OperationFailed, null); } } catch (Exception e) { if (retry > 0) { - LOGGER.error(String.format("%s due to %s, retries left: %s", errorMessage, e, retry)); + logger.error(String.format("%s due to %s, retries left: %s", errorMessage, e, retry)); } else { logTransitStateDetachIsoAndThrow(Level.ERROR, errorMessage, kubernetesCluster, clusterVMs, KubernetesCluster.Event.OperationFailed, e); } @@ -148,8 +148,8 @@ private void upgradeKubernetesClusterNodes() { if (!KubernetesClusterUtil.clusterNodeVersionMatches(upgradeVersion.getSemanticVersion(), publicIpAddress, sshPort, getControlNodeLoginUser(), getManagementServerSshPublicKeyFile(), hostName, upgradeTimeoutTime, 15000)) { logTransitStateDetachIsoAndThrow(Level.ERROR, String.format("Failed to upgrade Kubernetes cluster : %s, unable to get Kubernetes node on VM : %s upgraded to version %s", kubernetesCluster.getName(), vm.getDisplayName(), upgradeVersion.getSemanticVersion()), kubernetesCluster, clusterVMs, KubernetesCluster.Event.OperationFailed, null); } - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Successfully upgraded node on VM %s in Kubernetes cluster %s with Kubernetes version(%s) ID: %s", + if (logger.isInfoEnabled()) { + logger.info(String.format("Successfully upgraded node on VM %s in Kubernetes cluster %s with Kubernetes version(%s) ID: %s", vm.getDisplayName(), kubernetesCluster.getName(), upgradeVersion.getSemanticVersion(), upgradeVersion.getUuid())); } } @@ -157,8 +157,8 @@ private void upgradeKubernetesClusterNodes() { public boolean upgradeCluster() throws CloudRuntimeException { init(); - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Upgrading Kubernetes cluster : %s", kubernetesCluster.getName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Upgrading Kubernetes cluster : %s", kubernetesCluster.getName())); } upgradeTimeoutTime = System.currentTimeMillis() + KubernetesClusterService.KubernetesClusterUpgradeTimeout.value() * 1000; Pair publicIpSshPort = getKubernetesClusterServerIpSshPort(null); diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/dao/KubernetesClusterVmMapDao.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/dao/KubernetesClusterVmMapDao.java index abb7c3b5d011..eaeccd09f801 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/dao/KubernetesClusterVmMapDao.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/dao/KubernetesClusterVmMapDao.java @@ -23,6 +23,8 @@ public interface KubernetesClusterVmMapDao extends GenericDao { public List listByClusterId(long clusterId); + + public KubernetesClusterVmMapVO getClusterMapFromVmId(long vmId); public List listByClusterIdAndVmIdsIn(long clusterId, List vmIds); int removeByClusterIdAndVmIdsIn(long clusterId, List vmIds); diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/dao/KubernetesClusterVmMapDaoImpl.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/dao/KubernetesClusterVmMapDaoImpl.java index 3625873d0293..5e465848e1c1 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/dao/KubernetesClusterVmMapDaoImpl.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/dao/KubernetesClusterVmMapDaoImpl.java @@ -31,12 +31,17 @@ public class KubernetesClusterVmMapDaoImpl extends GenericDaoBase implements KubernetesClusterVmMapDao { private final SearchBuilder clusterIdSearch; + private final SearchBuilder vmIdSearch; public KubernetesClusterVmMapDaoImpl() { clusterIdSearch = createSearchBuilder(); clusterIdSearch.and("clusterId", clusterIdSearch.entity().getClusterId(), SearchCriteria.Op.EQ); clusterIdSearch.and("vmIdsIN", clusterIdSearch.entity().getVmId(), SearchCriteria.Op.IN); clusterIdSearch.done(); + + vmIdSearch = createSearchBuilder(); + vmIdSearch.and("vmId", vmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ); + vmIdSearch.done(); } @Override @@ -47,6 +52,13 @@ public List listByClusterId(long clusterId) { return listBy(sc, filter); } + @Override + public KubernetesClusterVmMapVO getClusterMapFromVmId(long vmId) { + SearchCriteria sc = vmIdSearch.create(); + sc.setParameters("vmId", vmId); + return findOneBy(sc); + } + @Override public List listByClusterIdAndVmIdsIn(long clusterId, List vmIds) { SearchCriteria sc = clusterIdSearch.create(); diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/utils/KubernetesClusterUtil.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/utils/KubernetesClusterUtil.java index e1210a607e67..7a3268014fdb 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/utils/KubernetesClusterUtil.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/utils/KubernetesClusterUtil.java @@ -33,7 +33,8 @@ import org.apache.cloudstack.utils.security.SSLUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.kubernetes.cluster.KubernetesCluster; import com.cloud.uservm.UserVm; @@ -43,7 +44,7 @@ public class KubernetesClusterUtil { - protected static final Logger LOGGER = Logger.getLogger(KubernetesClusterUtil.class); + protected static Logger LOGGER = LogManager.getLogger(KubernetesClusterUtil.class); public static final String CLUSTER_NODE_READY_COMMAND = "sudo /opt/bin/kubectl get nodes | awk '{if ($1 == \"%s\" && $2 == \"Ready\") print $1}'"; public static final String CLUSTER_NODE_VERSION_COMMAND = "sudo /opt/bin/kubectl get nodes | awk '{if ($1 == \"%s\") print $5}'"; @@ -265,13 +266,11 @@ public static boolean isKubernetesClusterControlVmRunning(final KubernetesCluste socket.connect(new InetSocketAddress(ipAddress, port), 10000); controlVmRunning = true; } catch (IOException e) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(String.format("Waiting for Kubernetes cluster : %s control node VMs to be accessible", kubernetesCluster.getName())); - } + LOGGER.info("Waiting for Kubernetes cluster : {} control node VMs to be accessible", kubernetesCluster.getName()); try { Thread.sleep(10000); } catch (InterruptedException ex) { - LOGGER.warn(String.format("Error while waiting for Kubernetes cluster : %s control node VMs to be accessible", kubernetesCluster.getName()), ex); + LOGGER.warn("Error while waiting for Kubernetes cluster : {} control node VMs to be accessible", kubernetesCluster.getName(), ex); } } } diff --git a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java index efdbebc1ab9d..93e1ae2810a6 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java +++ b/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java @@ -22,6 +22,7 @@ import javax.inject.Inject; +import com.cloud.cpu.CPU; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.command.admin.kubernetes.version.AddKubernetesSupportedVersionCmd; @@ -34,7 +35,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.api.query.dao.TemplateJoinDao; import com.cloud.api.query.vo.TemplateJoinVO; @@ -63,7 +63,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class KubernetesVersionManagerImpl extends ManagerBase implements KubernetesVersionService { - public static final Logger LOGGER = Logger.getLogger(KubernetesVersionManagerImpl.class.getName()); @Inject private KubernetesSupportedVersionDao kubernetesSupportedVersionDao; @@ -153,7 +152,7 @@ private List filterKubernetesSupportedVersions(Li versions.remove(i); } } catch (IllegalArgumentException e) { - LOGGER.warn(String.format("Unable to compare Kubernetes version for supported version ID: %s with %s", version.getUuid(), minimumSemanticVersion)); + logger.warn(String.format("Unable to compare Kubernetes version for supported version ID: %s with %s", version.getUuid(), minimumSemanticVersion)); versions.remove(i); } } @@ -161,7 +160,7 @@ private List filterKubernetesSupportedVersions(Li return versions; } - private VirtualMachineTemplate registerKubernetesVersionIso(final Long zoneId, final String versionName, final String isoUrl, final String isoChecksum, final boolean directDownload) throws IllegalAccessException, NoSuchFieldException, + private VirtualMachineTemplate registerKubernetesVersionIso(final Long zoneId, final String versionName, final String isoUrl, final String isoChecksum, final boolean directDownload, CPU.CPUArch arch) throws IllegalAccessException, NoSuchFieldException, IllegalArgumentException, ResourceAllocationException { CallContext.register(CallContext.current(), ApiCommandResourceType.Iso); String isoName = String.format("%s-Kubernetes-Binaries-ISO", versionName); @@ -179,6 +178,7 @@ private VirtualMachineTemplate registerKubernetesVersionIso(final Long zoneId, f registerIsoCmd.setChecksum(isoChecksum); } registerIsoCmd.setDirectDownload(directDownload); + registerIsoCmd.setArch(arch.getType()); registerIsoCmd.setAccountName(accountManager.getSystemAccount().getAccountName()); registerIsoCmd.setDomainId(accountManager.getSystemAccount().getDomainId()); try { @@ -318,6 +318,8 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad final Integer minimumCpu = cmd.getMinimumCpu(); final Integer minimumRamSize = cmd.getMinimumRamSize(); final boolean isDirectDownload = cmd.isDirectDownload(); + CPU.CPUArch arch = cmd.getArch(); + if (minimumCpu == null || minimumCpu < KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU) { throw new InvalidParameterValueException(String.format("Invalid value for %s parameter. Minimum %d vCPUs required.", ApiConstants.MIN_CPU_NUMBER, KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU)); } @@ -348,10 +350,10 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad VMTemplateVO template = null; try { - VirtualMachineTemplate vmTemplate = registerKubernetesVersionIso(zoneId, name, isoUrl, isoChecksum, isDirectDownload); + VirtualMachineTemplate vmTemplate = registerKubernetesVersionIso(zoneId, name, isoUrl, isoChecksum, isDirectDownload, arch); template = templateDao.findById(vmTemplate.getId()); } catch (IllegalAccessException | NoSuchFieldException | IllegalArgumentException | ResourceAllocationException ex) { - LOGGER.error(String.format("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s", name, isoUrl), ex); + logger.error(String.format("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s", name, isoUrl), ex); throw new CloudRuntimeException(String.format("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s", name, isoUrl)); } @@ -381,13 +383,13 @@ public boolean deleteKubernetesSupportedVersion(final DeleteKubernetesSupportedV VMTemplateVO template = templateDao.findByIdIncludingRemoved(version.getIsoId()); if (template == null) { - LOGGER.warn(String.format("Unable to find ISO associated with supported Kubernetes version ID: %s", version.getUuid())); + logger.warn(String.format("Unable to find ISO associated with supported Kubernetes version ID: %s", version.getUuid())); } if (template != null && template.getRemoved() == null) { // Delete ISO try { deleteKubernetesVersionIso(template.getId()); } catch (IllegalAccessException | NoSuchFieldException | IllegalArgumentException ex) { - LOGGER.error(String.format("Unable to delete binaries ISO ID: %s associated with supported kubernetes version ID: %s", template.getUuid(), version.getUuid()), ex); + logger.error(String.format("Unable to delete binaries ISO ID: %s associated with supported kubernetes version ID: %s", template.getUuid(), version.getUuid()), ex); throw new CloudRuntimeException(String.format("Unable to delete binaries ISO ID: %s associated with supported kubernetes version ID: %s", template.getUuid(), version.getUuid())); } } diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/AddKubernetesSupportedVersionCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/AddKubernetesSupportedVersionCmd.java index 1cff833d9cff..592ca6b0c259 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/AddKubernetesSupportedVersionCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/AddKubernetesSupportedVersionCmd.java @@ -19,6 +19,7 @@ import javax.inject.Inject; +import com.cloud.cpu.CPU; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -33,7 +34,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InvalidParameterValueException; @@ -48,7 +48,6 @@ entityType = {KubernetesSupportedVersion.class}, authorized = {RoleType.Admin}) public class AddKubernetesSupportedVersionCmd extends BaseCmd implements AdminCmd { - public static final Logger LOGGER = Logger.getLogger(AddKubernetesSupportedVersionCmd.class.getName()); @Inject private KubernetesVersionService kubernetesVersionService; @@ -89,6 +88,11 @@ public class AddKubernetesSupportedVersionCmd extends BaseCmd implements AdminCm description = "If set to true the Kubernetes supported version ISO will bypass Secondary Storage and be downloaded to Primary Storage on deployment. Default is false") private Boolean directDownload; + @Parameter(name = ApiConstants.ARCH, type = CommandType.STRING, + description = "the CPU arch of the Kubernetes ISO. Valid options are: x86_64, aarch64", + since = "4.20") + private String arch; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -132,6 +136,10 @@ public boolean isDirectDownload() { return (directDownload != null) ? directDownload : false; } + public CPU.CPUArch getArch() { + return CPU.CPUArch.fromType(arch); + } + @Override public long getEntityOwnerId() { return CallContext.current().getCallingAccountId(); diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/DeleteKubernetesSupportedVersionCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/DeleteKubernetesSupportedVersionCmd.java index b709637bf8b5..a7799a33f188 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/DeleteKubernetesSupportedVersionCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/DeleteKubernetesSupportedVersionCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.version.KubernetesSupportedVersion; @@ -45,7 +44,6 @@ entityType = {KubernetesSupportedVersion.class}, authorized = {RoleType.Admin}) public class DeleteKubernetesSupportedVersionCmd extends BaseAsyncCmd implements AdminCmd { - public static final Logger LOGGER = Logger.getLogger(DeleteKubernetesSupportedVersionCmd.class.getName()); @Inject private KubernetesVersionService kubernetesVersionService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/UpdateKubernetesSupportedVersionCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/UpdateKubernetesSupportedVersionCmd.java index 9950a06dc84c..990b6a936b70 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/UpdateKubernetesSupportedVersionCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/UpdateKubernetesSupportedVersionCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.command.admin.AdminCmd; import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.version.KubernetesSupportedVersion; @@ -45,7 +44,6 @@ entityType = {KubernetesSupportedVersion.class}, authorized = {RoleType.Admin}) public class UpdateKubernetesSupportedVersionCmd extends BaseCmd implements AdminCmd { - public static final Logger LOGGER = Logger.getLogger(UpdateKubernetesSupportedVersionCmd.class.getName()); @Inject private KubernetesVersionService kubernetesVersionService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/AddVirtualMachinesToKubernetesClusterCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/AddVirtualMachinesToKubernetesClusterCmd.java index a7134f501bc2..bd35794a3a5a 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/AddVirtualMachinesToKubernetesClusterCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/AddVirtualMachinesToKubernetesClusterCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; @@ -40,7 +39,6 @@ since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class AddVirtualMachinesToKubernetesClusterCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(AddVirtualMachinesToKubernetesClusterCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/CreateKubernetesClusterCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/CreateKubernetesClusterCmd.java index 529088254306..721cb47867b0 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/CreateKubernetesClusterCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/CreateKubernetesClusterCmd.java @@ -16,8 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.kubernetes.cluster; -import java.security.InvalidParameterException; - import javax.inject.Inject; import com.cloud.exception.InvalidParameterValueException; @@ -41,7 +39,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.kubernetes.cluster.KubernetesCluster; import com.cloud.kubernetes.cluster.KubernetesClusterEventTypes; @@ -57,7 +54,6 @@ responseHasSensitiveInfo = true, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateKubernetesClusterCmd extends BaseAsyncCreateCmd { - public static final Logger LOGGER = Logger.getLogger(CreateKubernetesClusterCmd.class.getName()); private static final Long DEFAULT_NODE_ROOT_DISK_SIZE = 8L; @Inject @@ -229,7 +225,7 @@ public String getDockerRegistryUrl() { public Long getNodeRootDiskSize() { if (nodeRootDiskSize != null) { if (nodeRootDiskSize < DEFAULT_NODE_ROOT_DISK_SIZE) { - throw new InvalidParameterException("Provided node root disk size is lesser than default size of " + DEFAULT_NODE_ROOT_DISK_SIZE +"GB"); + throw new InvalidParameterValueException("Provided node root disk size is lesser than default size of " + DEFAULT_NODE_ROOT_DISK_SIZE +"GB"); } return nodeRootDiskSize; } else { diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/DeleteKubernetesClusterCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/DeleteKubernetesClusterCmd.java index 9ea48b0e9d74..2ce8151c0631 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/DeleteKubernetesClusterCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/DeleteKubernetesClusterCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.KubernetesClusterResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.cluster.KubernetesCluster; @@ -43,7 +42,6 @@ entityType = {KubernetesCluster.class}, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeleteKubernetesClusterCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(DeleteKubernetesClusterCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/GetKubernetesClusterConfigCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/GetKubernetesClusterConfigCmd.java index 789e460ee809..42305245d506 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/GetKubernetesClusterConfigCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/GetKubernetesClusterConfigCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.KubernetesClusterConfigResponse; import org.apache.cloudstack.api.response.KubernetesClusterResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.kubernetes.cluster.KubernetesClusterService; import com.cloud.user.Account; @@ -44,7 +43,6 @@ responseHasSensitiveInfo = true, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class GetKubernetesClusterConfigCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(GetKubernetesClusterConfigCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ListKubernetesClustersCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ListKubernetesClustersCmd.java index 33eab2cbb651..7ee663bd4c38 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ListKubernetesClustersCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ListKubernetesClustersCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.KubernetesClusterResponse; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import com.cloud.kubernetes.cluster.KubernetesClusterService; import com.cloud.utils.exception.CloudRuntimeException; @@ -41,7 +40,6 @@ responseHasSensitiveInfo = true, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListKubernetesClustersCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger LOGGER = Logger.getLogger(ListKubernetesClustersCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/RemoveVirtualMachinesFromKubernetesClusterCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/RemoveVirtualMachinesFromKubernetesClusterCmd.java index 61096be24c8e..5c87f01862f3 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/RemoveVirtualMachinesFromKubernetesClusterCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/RemoveVirtualMachinesFromKubernetesClusterCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.RemoveVirtualMachinesFromKubernetesClusterResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; @@ -43,7 +42,6 @@ since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class RemoveVirtualMachinesFromKubernetesClusterCmd extends BaseListCmd { - public static final Logger LOGGER = Logger.getLogger(RemoveVirtualMachinesFromKubernetesClusterCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ScaleKubernetesClusterCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ScaleKubernetesClusterCmd.java index 49017e937ca3..ee3566564e41 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ScaleKubernetesClusterCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/ScaleKubernetesClusterCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.cluster.KubernetesCluster; @@ -52,7 +51,6 @@ responseHasSensitiveInfo = true, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ScaleKubernetesClusterCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(ScaleKubernetesClusterCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StartKubernetesClusterCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StartKubernetesClusterCmd.java index a15c76469675..bfe00ca27b28 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StartKubernetesClusterCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StartKubernetesClusterCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.KubernetesClusterResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.cluster.KubernetesCluster; @@ -45,7 +44,6 @@ responseHasSensitiveInfo = true, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class StartKubernetesClusterCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(StartKubernetesClusterCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StopKubernetesClusterCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StopKubernetesClusterCmd.java index 7cefef0b947e..23d6878cf729 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StopKubernetesClusterCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StopKubernetesClusterCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.KubernetesClusterResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.cluster.KubernetesCluster; @@ -46,7 +45,6 @@ responseHasSensitiveInfo = true, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class StopKubernetesClusterCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(StopKubernetesClusterCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/UpgradeKubernetesClusterCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/UpgradeKubernetesClusterCmd.java index faba8a930cac..a3f2e0576459 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/UpgradeKubernetesClusterCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/UpgradeKubernetesClusterCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.KubernetesClusterResponse; import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.cluster.KubernetesCluster; @@ -47,7 +46,6 @@ responseHasSensitiveInfo = true, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class UpgradeKubernetesClusterCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(UpgradeKubernetesClusterCmd.class.getName()); @Inject public KubernetesClusterService kubernetesClusterService; diff --git a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/version/ListKubernetesSupportedVersionsCmd.java b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/version/ListKubernetesSupportedVersionsCmd.java index 15f83252c8af..f718d873842d 100644 --- a/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/version/ListKubernetesSupportedVersionsCmd.java +++ b/plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/version/ListKubernetesSupportedVersionsCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.kubernetes.version.KubernetesVersionService; @@ -41,7 +40,6 @@ responseView = ResponseObject.ResponseView.Restricted, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListKubernetesSupportedVersionsCmd extends BaseListCmd { - public static final Logger LOGGER = Logger.getLogger(ListKubernetesSupportedVersionsCmd.class.getName()); @Inject private KubernetesVersionService kubernetesVersionService; diff --git a/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node-add.yml b/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node-add.yml index 429e2eff0985..6819723b3f04 100644 --- a/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node-add.yml +++ b/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node-add.yml @@ -66,7 +66,7 @@ write_files: break fi set +e - output=`blkid -o device -t TYPE=iso9660` + output=`blkid -o device -t LABEL=CDROM` set -e if [ "$output" != "" ]; then while read -r line; do diff --git a/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node.yml b/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node.yml index 4bc2c2c6d3ed..90be8957d440 100644 --- a/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node.yml +++ b/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node.yml @@ -86,7 +86,7 @@ write_files: break fi set +e - output=`blkid -o device -t TYPE=iso9660` + output=`blkid -o device -t LABEL=CDROM` set -e if [ "$output" != "" ]; then while read -r line; do diff --git a/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-node.yml b/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-node.yml index ad5bb9d19a6f..ac80e8576ffe 100644 --- a/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-node.yml +++ b/plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-node.yml @@ -66,7 +66,7 @@ write_files: break fi set +e - output=`blkid -o device -t TYPE=iso9660` + output=`blkid -o device -t LABEL=CDROM` set -e if [ "$output" != "" ]; then while read -r line; do diff --git a/plugins/integrations/kubernetes-service/src/main/resources/script/upgrade-kubernetes.sh b/plugins/integrations/kubernetes-service/src/main/resources/script/upgrade-kubernetes.sh index c092f53359d6..480b002ef179 100755 --- a/plugins/integrations/kubernetes-service/src/main/resources/script/upgrade-kubernetes.sh +++ b/plugins/integrations/kubernetes-service/src/main/resources/script/upgrade-kubernetes.sh @@ -54,7 +54,7 @@ while true; do break fi set +e - output=`blkid -o device -t TYPE=iso9660` + output=`blkid -o device -t LABEL=CDROM` set -e if [ "$output" != "" ]; then while read -r line; do diff --git a/plugins/integrations/kubernetes-service/src/test/java/com/cloud/kubernetes/version/KubernetesVersionServiceTest.java b/plugins/integrations/kubernetes-service/src/test/java/com/cloud/kubernetes/version/KubernetesVersionServiceTest.java index f7e816596c26..e6d25df10efa 100644 --- a/plugins/integrations/kubernetes-service/src/test/java/com/cloud/kubernetes/version/KubernetesVersionServiceTest.java +++ b/plugins/integrations/kubernetes-service/src/test/java/com/cloud/kubernetes/version/KubernetesVersionServiceTest.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.UUID; +import com.cloud.cpu.CPU; import org.apache.cloudstack.api.command.admin.kubernetes.version.AddKubernetesSupportedVersionCmd; import org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd; import org.apache.cloudstack.api.command.admin.kubernetes.version.UpdateKubernetesSupportedVersionCmd; @@ -213,6 +214,7 @@ public void addKubernetesSupportedVersionIsoUrlTest() throws ResourceAllocationE when(cmd.getChecksum()).thenReturn(null); when(cmd.getMinimumCpu()).thenReturn(KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU); when(cmd.getMinimumRamSize()).thenReturn(KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_RAM_SIZE); + when(cmd.getArch()).thenReturn(CPU.CPUArch.amd64); Account systemAccount = new AccountVO("system", 1L, "", Account.Type.ADMIN, "uuid"); when(accountManager.getSystemAccount()).thenReturn(systemAccount); CallContext callContext = Mockito.mock(CallContext.class); diff --git a/plugins/integrations/kubernetes-service/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/integrations/kubernetes-service/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/integrations/kubernetes-service/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/integrations/prometheus/pom.xml b/plugins/integrations/prometheus/pom.xml index 6086a024de1a..52c4a7ef2da4 100644 --- a/plugins/integrations/prometheus/pom.xml +++ b/plugins/integrations/prometheus/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java index 17fbd48181ad..a84b1a6e2dea 100644 --- a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java +++ b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java @@ -25,16 +25,9 @@ import javax.inject.Inject; -import com.cloud.configuration.dao.ResourceCountDao; -import com.cloud.dc.DedicatedResourceVO; -import com.cloud.dc.dao.DedicatedResourceDao; -import com.cloud.host.HostStats; -import com.cloud.host.HostTagVO; -import com.cloud.user.Account; -import com.cloud.user.dao.AccountDao; import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.StringUtils; import com.cloud.alert.AlertManager; import com.cloud.api.ApiDBUtils; @@ -44,16 +37,21 @@ import com.cloud.api.query.vo.StoragePoolJoinVO; import com.cloud.capacity.Capacity; import com.cloud.capacity.CapacityManager; -import com.cloud.capacity.CapacityVO; import com.cloud.capacity.CapacityState; +import com.cloud.capacity.CapacityVO; import com.cloud.capacity.dao.CapacityDao; import com.cloud.capacity.dao.CapacityDaoImpl; import com.cloud.configuration.Resource; +import com.cloud.configuration.dao.ResourceCountDao; import com.cloud.dc.DataCenterVO; +import com.cloud.dc.DedicatedResourceVO; import com.cloud.dc.Vlan; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterIpAddressDao; +import com.cloud.dc.dao.DedicatedResourceDao; import com.cloud.host.Host; +import com.cloud.host.HostStats; +import com.cloud.host.HostTagVO; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; @@ -64,7 +62,8 @@ import com.cloud.storage.Volume; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.VolumeDao; -import org.apache.commons.lang3.StringUtils; +import com.cloud.user.Account; +import com.cloud.user.dao.AccountDao; import com.cloud.utils.Ternary; import com.cloud.utils.component.Manager; import com.cloud.utils.component.ManagerBase; @@ -73,7 +72,6 @@ import com.cloud.vm.dao.VMInstanceDao; public class PrometheusExporterImpl extends ManagerBase implements PrometheusExporter, Manager { - private static final Logger LOG = Logger.getLogger(PrometheusExporterImpl.class); private static final String USED = "used"; private static final String ALLOCATED = "allocated"; @@ -440,13 +438,13 @@ private void addDomainResourceCount(final List metricsList) { } long memoryUsed = _resourceCountDao.getResourceCount(domain.getId(), Resource.ResourceOwnerType.Domain, - Resource.ResourceType.memory); + Resource.ResourceType.memory, null); long cpuUsed = _resourceCountDao.getResourceCount(domain.getId(), Resource.ResourceOwnerType.Domain, - Resource.ResourceType.cpu); + Resource.ResourceType.cpu, null); long primaryStorageUsed = _resourceCountDao.getResourceCount(domain.getId(), Resource.ResourceOwnerType.Domain, - Resource.ResourceType.primary_storage); + Resource.ResourceType.primary_storage, null); long secondaryStorageUsed = _resourceCountDao.getResourceCount(domain.getId(), Resource.ResourceOwnerType.Domain, - Resource.ResourceType.secondary_storage); + Resource.ResourceType.secondary_storage, null); metricsList.add(new ItemPerDomainResourceCount(memoryUsed, domain.getPath(), Resource.ResourceType.memory.getName())); metricsList.add(new ItemPerDomainResourceCount(cpuUsed, domain.getPath(), Resource.ResourceType.cpu.getName())); @@ -493,7 +491,7 @@ public void updateMetrics() { addDomainLimits(latestMetricsItems); addDomainResourceCount(latestMetricsItems); } catch (Exception e) { - LOG.warn("Getting metrics failed ", e); + logger.warn("Getting metrics failed ", e); } metricsItems = latestMetricsItems; } diff --git a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterServerImpl.java b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterServerImpl.java index cc3b7d556538..d9f25d2f5772 100644 --- a/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterServerImpl.java +++ b/plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterServerImpl.java @@ -22,7 +22,6 @@ import com.sun.net.httpserver.HttpServer; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.io.IOException; @@ -32,14 +31,13 @@ import java.util.Arrays; public class PrometheusExporterServerImpl extends ManagerBase implements PrometheusExporterServer, Configurable { - private static final Logger LOG = Logger.getLogger(PrometheusExporterServerImpl.class); private static HttpServer httpServer; @Inject private PrometheusExporter prometheusExporter; - private final static class ExporterHandler implements HttpHandler { + private final class ExporterHandler implements HttpHandler { private PrometheusExporter prometheusExporter; ExporterHandler(final PrometheusExporter prometheusExporter) { @@ -50,7 +48,7 @@ private final static class ExporterHandler implements HttpHandler { @Override public void handle(final HttpExchange httpExchange) throws IOException { final String remoteClientAddress = httpExchange.getRemoteAddress().getAddress().toString().replace("/", ""); - LOG.debug("Prometheus exporter received client request from: " + remoteClientAddress); + logger.debug("Prometheus exporter received client request from: " + remoteClientAddress); String response = "Forbidden"; int responseCode = 403; if (Arrays.asList(PrometheusExporterAllowedAddresses.value().split(",")).contains(remoteClientAddress)) { @@ -65,9 +63,9 @@ public void handle(final HttpExchange httpExchange) throws IOException { try { os.write(bytesToOutput); } catch (IOException e) { - LOG.error(String.format("could not export Prometheus data due to %s", e.getLocalizedMessage())); - if (LOG.isDebugEnabled()) { - LOG.debug("Error during Prometheus export: ", e); + logger.error(String.format("could not export Prometheus data due to %s", e.getLocalizedMessage())); + if (logger.isDebugEnabled()) { + logger.debug("Error during Prometheus export: ", e); } os.write("The system could not export Prometheus due to an internal error. Contact your operator to learn about the reason.".getBytes()); } finally { @@ -96,9 +94,9 @@ public void handle(HttpExchange httpExchange) throws IOException { } }); httpServer.start(); - LOG.debug("Started prometheus exporter http server"); + logger.debug("Started prometheus exporter http server"); } catch (final IOException e) { - LOG.info("Failed to start prometheus exporter http server due to: ", e); + logger.info("Failed to start prometheus exporter http server due to: ", e); } } return true; @@ -108,7 +106,7 @@ public void handle(HttpExchange httpExchange) throws IOException { public boolean stop() { if (httpServer != null) { httpServer.stop(0); - LOG.debug("Stopped Prometheus exporter http server"); + logger.debug("Stopped Prometheus exporter http server"); } return true; } diff --git a/plugins/metrics/pom.xml b/plugins/metrics/pom.xml index bd3235da8b92..8621dc3c71d9 100644 --- a/plugins/metrics/pom.xml +++ b/plugins/metrics/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/plugins/metrics/src/main/java/org/apache/cloudstack/api/MetricConstants.java b/plugins/metrics/src/main/java/org/apache/cloudstack/api/MetricConstants.java index 19a1cd405630..8c93f2e1f446 100644 --- a/plugins/metrics/src/main/java/org/apache/cloudstack/api/MetricConstants.java +++ b/plugins/metrics/src/main/java/org/apache/cloudstack/api/MetricConstants.java @@ -29,7 +29,7 @@ public interface MetricConstants { String HEAP_MEMORY_TOTAL = "heapmemorytotal"; String LAST_HEARTBEAT = "lastheartbeat"; String LAST_SUCCESSFUL_JOB = "lastsuccessfuljob"; - String LOG_INFO = "loginfo"; + String logger_INFO = "loginfo"; String REPLICAS = "replicas"; String SESSIONS = "sessions"; String SYSTEM = "system"; diff --git a/plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java b/plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java index 86bf2e3e351a..6025a41d69cb 100644 --- a/plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java +++ b/plugins/metrics/src/main/java/org/apache/cloudstack/metrics/MetricsServiceImpl.java @@ -84,7 +84,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.log4j.Logger; import com.cloud.agent.api.VmDiskStatsEntry; import com.cloud.agent.api.VmStatsEntryBase; @@ -143,7 +142,6 @@ import com.google.gson.Gson; public class MetricsServiceImpl extends MutualExclusiveIdsManagerBase implements MetricsService { - private static final Logger LOGGER = Logger.getLogger(MetricsServiceImpl.class); @Inject private DataCenterDao dataCenterDao; @@ -789,7 +787,7 @@ public List listClusterMetrics(Pair listManagementServerMetrics(List managementServerResponses) { final List metricsResponses = new ArrayList<>(); - if(LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Getting metrics for %d MS hosts.", managementServerResponses.size())); + if(logger.isDebugEnabled()) { + logger.debug(String.format("Getting metrics for %d MS hosts.", managementServerResponses.size())); } for (final ManagementServerResponse managementServerResponse: managementServerResponses) { - if(LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("Processing metrics for MS hosts %s.", managementServerResponse.getId())); + if(logger.isDebugEnabled()) { + logger.debug(String.format("Processing metrics for MS hosts %s.", managementServerResponse.getId())); } ManagementServerMetricsResponse metricsResponse = new ManagementServerMetricsResponse(); try { BeanUtils.copyProperties(metricsResponse, managementServerResponse); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Bean copy result %s.", new ReflectionToStringBuilder(metricsResponse, ToStringStyle.SIMPLE_STYLE).toString())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Bean copy result %s.", new ReflectionToStringBuilder(metricsResponse, ToStringStyle.SIMPLE_STYLE).toString())); } } catch (IllegalAccessException | InvocationTargetException e) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate zone metrics response."); @@ -877,15 +875,15 @@ public List listManagementServerMetrics(List 0) { copyManagementServerStatusToResponse(metricsResponse, status); @@ -1020,8 +1018,8 @@ public DbMetricsResponse listDbMetrics() { getQueryHistory(response); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(new ReflectionToStringBuilder(response)); + if (logger.isTraceEnabled()) { + logger.trace(new ReflectionToStringBuilder(response)); } response.setObjectName("dbMetrics"); @@ -1079,8 +1077,8 @@ protected boolean isUsageRunning() { boolean local = false; String usageStatus = Script.runSimpleBashScript("systemctl status cloudstack-usage | grep \" Active:\""); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("The current usage status is: %s.", usageStatus)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("The current usage status is: %s.", usageStatus)); } if (StringUtils.isNotBlank(usageStatus)) { diff --git a/plugins/metrics/src/main/java/org/apache/cloudstack/response/ManagementServerMetricsResponse.java b/plugins/metrics/src/main/java/org/apache/cloudstack/response/ManagementServerMetricsResponse.java index ae0f57b967b8..95c3fd09c072 100644 --- a/plugins/metrics/src/main/java/org/apache/cloudstack/response/ManagementServerMetricsResponse.java +++ b/plugins/metrics/src/main/java/org/apache/cloudstack/response/ManagementServerMetricsResponse.java @@ -85,7 +85,7 @@ public class ManagementServerMetricsResponse extends ManagementServerResponse { @Param(description = "Virtual size of the fully loaded process") private String systemMemoryVirtualSize; - @SerializedName(MetricConstants.LOG_INFO) + @SerializedName(MetricConstants.logger_INFO) @Param(description = "the log files and their usage on disk") private String logInfo; diff --git a/plugins/metrics/src/main/java/org/apache/cloudstack/response/VolumeMetricsResponse.java b/plugins/metrics/src/main/java/org/apache/cloudstack/response/VolumeMetricsResponse.java index c2004817dd25..a9919d7cce62 100644 --- a/plugins/metrics/src/main/java/org/apache/cloudstack/response/VolumeMetricsResponse.java +++ b/plugins/metrics/src/main/java/org/apache/cloudstack/response/VolumeMetricsResponse.java @@ -25,7 +25,7 @@ import com.google.gson.annotations.SerializedName; public class VolumeMetricsResponse extends VolumeResponse { - @SerializedName("sizegb") + @SerializedName(ApiConstants.SIZEGB) @Param(description = "disk size in GiB") private String diskSizeGB; diff --git a/plugins/metrics/src/test/java/org/apache/cloudstack/metrics/MetricsServiceImplTest.java b/plugins/metrics/src/test/java/org/apache/cloudstack/metrics/MetricsServiceImplTest.java index ec4add4141db..b37be68b3e43 100644 --- a/plugins/metrics/src/test/java/org/apache/cloudstack/metrics/MetricsServiceImplTest.java +++ b/plugins/metrics/src/test/java/org/apache/cloudstack/metrics/MetricsServiceImplTest.java @@ -128,7 +128,7 @@ public void searchForUserVmsInternalTestWithOnlyOneId() { Mockito.verify(scMock).setParameters(stringCaptor1.capture(), objectArrayCaptor.capture()); Assert.assertEquals("idIN", stringCaptor1.getValue()); - Assert.assertEquals(Arrays.asList(fakeVmId1), objectArrayCaptor.getAllValues()); + Assert.assertEquals(fakeVmId1, objectArrayCaptor.getAllValues().get(0)[0]); Assert.assertEquals(expectedVmListAndCounter, result); } @@ -146,7 +146,7 @@ public void searchForUserVmsInternalTestWithAListOfIds() { Mockito.verify(scMock).setParameters(stringCaptor1.capture(), objectArrayCaptor.capture()); Assert.assertEquals("idIN", stringCaptor1.getValue()); - Assert.assertEquals(expected, objectArrayCaptor.getAllValues()); + Assert.assertArrayEquals(expected.toArray(), objectArrayCaptor.getAllValues().get(0)); Assert.assertEquals(expectedVmListAndCounter, result); } @@ -163,7 +163,7 @@ public void searchForUserVmsInternalTestWithName() { Mockito.verify(scMock).setParameters(stringCaptor1.capture(), objectArrayCaptor.capture()); Assert.assertEquals("displayName", stringCaptor1.getValue()); - Assert.assertEquals("%fakeName%", objectArrayCaptor.getValue()); + Assert.assertEquals("%fakeName%", objectArrayCaptor.getValue()[0]); Assert.assertEquals(expectedVmListAndCounter, result); } @@ -184,8 +184,8 @@ public void searchForUserVmsInternalTestWithKeyword() { List params = objectArrayCaptor.getAllValues(); Assert.assertEquals("displayName", conditions.get(0)); Assert.assertEquals("state", conditions.get(1)); - Assert.assertEquals("%fakeKeyword%", params.get(0)); - Assert.assertEquals("fakeKeyword", params.get(1)); + Assert.assertEquals("%fakeKeyword%", params.get(0)[0]); + Assert.assertEquals("fakeKeyword", params.get(1)[0]); Assert.assertEquals(expectedVmListAndCounter, result); } diff --git a/plugins/metrics/src/test/java/org/apache/cloudstack/response/HostMetricsResponseTest.java b/plugins/metrics/src/test/java/org/apache/cloudstack/response/HostMetricsResponseTest.java index 98c8cd3d97f9..d81d6f6dadbf 100644 --- a/plugins/metrics/src/test/java/org/apache/cloudstack/response/HostMetricsResponseTest.java +++ b/plugins/metrics/src/test/java/org/apache/cloudstack/response/HostMetricsResponseTest.java @@ -56,4 +56,27 @@ public void testSetCpuAllocatedWithValidCpu() { Assert.assertEquals(expected, hostResponse.getCpuAllocatedGhz()); } + @Test + public void testSetCpuAllocatedWithNullCpu() { + String expected = null; + final HostMetricsResponse hostResponse = new HostMetricsResponse(); + hostResponse.setCpuAllocated(null, 10, 1000L); + Assert.assertEquals(expected, hostResponse.getCpuAllocatedGhz()); + } + + @Test + public void testSetCpuAllocatedWithNullCpuNumber() { + String expected = null; + final HostMetricsResponse hostResponse = new HostMetricsResponse(); + hostResponse.setCpuAllocated(String.format("50%s25%%", decimalSeparator), null, 1000L); + Assert.assertEquals(expected, hostResponse.getCpuAllocatedGhz()); + } + + @Test + public void testSetCpuAllocatedWithNullCpuSpeed() { + String expected = null; + final HostMetricsResponse hostResponse = new HostMetricsResponse(); + hostResponse.setCpuAllocated(String.format("50%s25%%", decimalSeparator), 10, null); + Assert.assertEquals(expected, hostResponse.getCpuAllocatedGhz()); + } } diff --git a/plugins/network-elements/bigswitch/pom.xml b/plugins/network-elements/bigswitch/pom.xml index 26cae620eb2c..18d069978789 100644 --- a/plugins/network-elements/bigswitch/pom.xml +++ b/plugins/network-elements/bigswitch/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/bigswitch/src/main/java/com/cloud/api/commands/ListBigSwitchBcfDevicesCmd.java b/plugins/network-elements/bigswitch/src/main/java/com/cloud/api/commands/ListBigSwitchBcfDevicesCmd.java index 3e25848804de..f009f3bbc7f5 100644 --- a/plugins/network-elements/bigswitch/src/main/java/com/cloud/api/commands/ListBigSwitchBcfDevicesCmd.java +++ b/plugins/network-elements/bigswitch/src/main/java/com/cloud/api/commands/ListBigSwitchBcfDevicesCmd.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -48,7 +47,6 @@ @APICommand(name = "listBigSwitchBcfDevices", responseObject = BigSwitchBcfDeviceResponse.class, description = "Lists BigSwitch BCF Controller devices", since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListBigSwitchBcfDevicesCmd extends BaseListCmd { - public static final Logger S_LOGGER = Logger.getLogger(ListBigSwitchBcfDevicesCmd.class.getName()); private static final String S_NAME = "listbigswitchbcfdeviceresponse"; @Inject private BigSwitchBcfElementService bigswitchBcfElementService; diff --git a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/bigswitch/BigSwitchBcfApi.java b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/bigswitch/BigSwitchBcfApi.java index a7f0f05e7628..ba81b76022d8 100644 --- a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/bigswitch/BigSwitchBcfApi.java +++ b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/bigswitch/BigSwitchBcfApi.java @@ -48,13 +48,14 @@ import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; public class BigSwitchBcfApi { - private static final Logger S_LOGGER = Logger.getLogger(BigSwitchBcfApi.class); + protected Logger logger = LogManager.getLogger(getClass()); private final static String S_PROTOCOL = "https"; private final static String S_NS_BASE_URL = "/networkService/v1.1"; private final static String CONTENT_TYPE = "content-type"; @@ -94,7 +95,7 @@ protected HttpMethod createMethod(final String type, final String uri, final int try { url = new URL(S_PROTOCOL, host, port, uri).toString(); } catch (MalformedURLException e) { - S_LOGGER.error("Unable to build Big Switch API URL", e); + logger.error("Unable to build Big Switch API URL", e); throw new BigSwitchBcfApiException("Unable to build Big Switch API URL", e); } @@ -119,7 +120,7 @@ public BigSwitchBcfApi() { // Cast to ProtocolSocketFactory to avoid the deprecated constructor with the SecureProtocolSocketFactory parameter Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), _port)); } catch (IOException e) { - S_LOGGER.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e); + logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e); } } @@ -289,7 +290,7 @@ private String checkResponse(final HttpMethodBase m, final String errorMessageBa } String errorMessage = responseToErrorMessage(m); m.releaseConnection(); - S_LOGGER.error(errorMessageBase + errorMessage); + logger.error(errorMessageBase + errorMessage); throw new BigSwitchBcfApiException(errorMessageBase + errorMessage + customErrorMsg); } @@ -395,7 +396,7 @@ protected T executeRetrieveObject(final Type returnObjectType, // CAUTIOUS: Safety margin of 2048 characters - extend if needed. returnValue = (T)gson.fromJson(gm.getResponseBodyAsString(2048), returnObjectType); } catch (IOException e) { - S_LOGGER.error("IOException while retrieving response body", e); + logger.error("IOException while retrieving response body", e); throw new BigSwitchBcfApiException(e); } finally { gm.releaseConnection(); @@ -419,11 +420,11 @@ protected void executeMethod(final HttpMethodBase method) throws BigSwitchBcfApi method.releaseConnection(); } } catch (HttpException e) { - S_LOGGER.error("HttpException caught while trying to connect to the BigSwitch Controller", e); + logger.error("HttpException caught while trying to connect to the BigSwitch Controller", e); method.releaseConnection(); throw new BigSwitchBcfApiException("API call to BigSwitch Controller Failed", e); } catch (IOException e) { - S_LOGGER.error("IOException caught while trying to connect to the BigSwitch Controller", e); + logger.error("IOException caught while trying to connect to the BigSwitch Controller", e); method.releaseConnection(); throw new BigSwitchBcfApiException("API call to BigSwitch Controller Failed", e); } @@ -439,7 +440,7 @@ private String responseToErrorMessage(final HttpMethodBase method) { try { return method.getResponseBodyAsString(2048); } catch (IOException e) { - S_LOGGER.debug("Error while loading response body", e); + logger.debug("Error while loading response body", e); } } diff --git a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/bigswitch/BigSwitchBcfUtils.java b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/bigswitch/BigSwitchBcfUtils.java index 35ca009a80c2..db2e1311b86c 100644 --- a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/bigswitch/BigSwitchBcfUtils.java +++ b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/bigswitch/BigSwitchBcfUtils.java @@ -26,7 +26,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.net.util.SubnetUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bouncycastle.util.IPAddress; import com.cloud.agent.AgentManager; @@ -76,7 +77,7 @@ import com.cloud.vm.dao.VMInstanceDao; public class BigSwitchBcfUtils { - private static final Logger s_logger = Logger.getLogger(BigSwitchBcfUtils.class); + protected Logger logger = LogManager.getLogger(getClass()); private final NetworkDao _networkDao; private final NicDao _nicDao; @@ -447,7 +448,7 @@ public String syncTopologyToBcfHost(HostVO bigswitchBcfHost){ } BcfAnswer syncAnswer = (BcfAnswer) _agentMgr.easySend(bigswitchBcfHost.getId(), syncCmd); if (syncAnswer == null || !syncAnswer.getResult()) { - s_logger.error("SyncBcfTopologyCommand failed"); + logger.error("SyncBcfTopologyCommand failed"); return null; } return syncAnswer.getHash(); @@ -462,7 +463,7 @@ public String syncTopologyToBcfHost(HostVO bigswitchBcfHost, boolean natEnabled) } BcfAnswer syncAnswer = (BcfAnswer) _agentMgr.easySend(bigswitchBcfHost.getId(), syncCmd); if (syncAnswer == null || !syncAnswer.getResult()) { - s_logger.error("SyncBcfTopologyCommand failed"); + logger.error("SyncBcfTopologyCommand failed"); return null; } return syncAnswer.getHash(); @@ -481,7 +482,7 @@ public BcfAnswer sendBcfCommandWithNetworkSyncCheck(BcfCommand cmd, Network netw BcfAnswer answer = (BcfAnswer) _agentMgr.easySend(cluster.getPrimary().getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error ("BCF API Command failed"); + logger.error ("BCF API Command failed"); throw new IllegalArgumentException("Failed API call to Big Switch Network plugin"); } diff --git a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/element/BigSwitchBcfElement.java b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/element/BigSwitchBcfElement.java index 776f76fabca0..5fc9480c6102 100644 --- a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/element/BigSwitchBcfElement.java +++ b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/element/BigSwitchBcfElement.java @@ -29,7 +29,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; import org.apache.commons.net.util.SubnetUtils; @@ -128,7 +127,6 @@ public class BigSwitchBcfElement extends AdapterBase implements BigSwitchBcfElementService, ConnectivityProvider, IpDeployer, SourceNatServiceProvider, StaticNatServiceProvider, NetworkACLServiceProvider, FirewallServiceProvider, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(BigSwitchBcfElement.class); private static final Map> capabilities = setCapabilities(); @@ -194,18 +192,18 @@ public Provider getProvider() { } private boolean canHandle(Network network, Service service) { - s_logger.debug("Checking if BigSwitchBcfElement can handle service " + service.getName() + " on network " + network.getDisplayText()); + logger.debug("Checking if BigSwitchBcfElement can handle service " + service.getName() + " on network " + network.getDisplayText()); if (network.getBroadcastDomainType() != BroadcastDomainType.Vlan) { return false; } if (!_networkModel.isProviderForNetwork(getProvider(), network.getId())) { - s_logger.debug("BigSwitchBcfElement is not a provider for network " + network.getDisplayText()); + logger.debug("BigSwitchBcfElement is not a provider for network " + network.getDisplayText()); return false; } if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), service, BcfConstants.BIG_SWITCH_BCF)) { - s_logger.debug("BigSwitchBcfElement can't provide the " + service.getName() + " service on network " + network.getDisplayText()); + logger.debug("BigSwitchBcfElement can't provide the " + service.getName() + " service on network " + network.getDisplayText()); return false; } @@ -298,7 +296,7 @@ public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm } if (network.getBroadcastUri() == null) { - s_logger.error("Nic has no broadcast Uri"); + logger.error("Nic has no broadcast Uri"); return false; } @@ -356,7 +354,7 @@ public boolean canEnableIndividualServices() { @Override public boolean verifyServicesCombination(Set services) { if (!services.contains(Service.Connectivity)) { - s_logger.warn("Unable to provide services without Connectivity service enabled for this element"); + logger.warn("Unable to provide services without Connectivity service enabled for this element"); return false; } return true; @@ -642,14 +640,14 @@ public boolean applyStaticNats(Network network, String dstIp = rule.getDestIpAddress(); String mac = rule.getSourceMacAddress(); if(!rule.isForRevoke()) { - s_logger.debug("BCF enables static NAT for public IP: " + srcIp + " private IP " + dstIp + logger.debug("BCF enables static NAT for public IP: " + srcIp + " private IP " + dstIp + " mac " + mac); CreateBcfStaticNatCommand cmd = new CreateBcfStaticNatCommand( tenantId, network.getUuid(), dstIp, srcIp, mac); _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network); } else { - s_logger.debug("BCF removes static NAT for public IP: " + srcIp + " private IP " + dstIp + logger.debug("BCF removes static NAT for public IP: " + srcIp + " private IP " + dstIp + " mac " + mac); DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand(tenantId, srcIp); @@ -700,6 +698,11 @@ public boolean applyNetworkACLs(Network network, return true; } + @Override + public boolean reorderAclRules(Vpc vpc, List networks, List networkACLItems) { + return true; + } + @Override public boolean applyFWRules(Network network, List rules) diff --git a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/guru/BigSwitchBcfGuestNetworkGuru.java b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/guru/BigSwitchBcfGuestNetworkGuru.java index 7cb50edb4efc..f9c11e507483 100644 --- a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/guru/BigSwitchBcfGuestNetworkGuru.java +++ b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/guru/BigSwitchBcfGuestNetworkGuru.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.CreateBcfAttachmentCommand; @@ -91,7 +90,6 @@ * removes them when the VM is destroyed. */ public class BigSwitchBcfGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigrationResponder { - private static final Logger s_logger = Logger.getLogger(BigSwitchBcfGuestNetworkGuru.class); @Inject PhysicalNetworkDao _physicalNetworkDao; @@ -139,32 +137,32 @@ protected boolean canHandle(NetworkOffering offering, NetworkType networkType, P isMyIsolationMethod(physicalNetwork)) { return true; } else { - s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); + logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); return false; } } @Override - public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner) { // Check if the isolation type of the physical network is BCF_SEGMENT, then delegate GuestNetworkGuru to design PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId()); if (physnet == null || physnet.getIsolationMethods() == null || !physnet.getIsolationMethods().contains("BCF_SEGMENT")) { - s_logger.debug("Refusing to design this network, the physical isolation type is not BCF_SEGMENT"); + logger.debug("Refusing to design this network, the physical isolation type is not BCF_SEGMENT"); return null; } List devices = _bigswitchBcfDao.listByPhysicalNetwork(physnet.getId()); if (devices.isEmpty()) { - s_logger.error("No BigSwitch Controller on physical network " + physnet.getName()); + logger.error("No BigSwitch Controller on physical network " + physnet.getName()); return null; } for (BigSwitchBcfDeviceVO d: devices){ - s_logger.debug("BigSwitch Controller " + d.getUuid() + logger.debug("BigSwitch Controller " + d.getUuid() + " found on physical network " + physnet.getId()); } - s_logger.debug("Physical isolation type is BCF_SEGMENT, asking GuestNetworkGuru to design this network"); - NetworkVO networkObject = (NetworkVO)super.design(offering, plan, userSpecified, owner); + logger.debug("Physical isolation type is BCF_SEGMENT, asking GuestNetworkGuru to design this network"); + NetworkVO networkObject = (NetworkVO)super.design(offering, plan, userSpecified, name, vpcId, owner); if (networkObject == null) { return null; } @@ -311,7 +309,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat public void shutdown(NetworkProfile profile, NetworkOffering offering) { NetworkVO networkObject = _networkDao.findById(profile.getId()); if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Vlan || networkObject.getBroadcastUri() == null) { - s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); + logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); return; } @@ -355,7 +353,7 @@ public boolean prepareMigration(NicProfile nic, Network network, tenantId = vpc.getUuid(); tenantName = vpc.getName(); boolean released = _vpcDao.releaseFromLockTable(vpc.getId()); - s_logger.debug("BCF guru release lock vpc id: " + vpc.getId() + logger.debug("BCF guru release lock vpc id: " + vpc.getId() + " released? " + released); } else { // use network id in CS as tenant in BSN @@ -401,14 +399,14 @@ public boolean prepareMigration(NicProfile nic, Network network, public void rollbackMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { - s_logger.debug("BCF guru rollback migration"); + logger.debug("BCF guru rollback migration"); } @Override public void commitMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { - s_logger.debug("BCF guru commit migration"); + logger.debug("BCF guru commit migration"); } private void bcfUtilsInit(){ diff --git a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/resource/BigSwitchBcfResource.java b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/resource/BigSwitchBcfResource.java index de33b8ae7b44..63e8206ec824 100644 --- a/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/resource/BigSwitchBcfResource.java +++ b/plugins/network-elements/bigswitch/src/main/java/com/cloud/network/resource/BigSwitchBcfResource.java @@ -25,7 +25,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -70,7 +69,6 @@ import com.cloud.utils.component.ManagerBase; public class BigSwitchBcfResource extends ManagerBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(BigSwitchBcfResource.class); private String _name; private String _guid; @@ -176,20 +174,20 @@ public PingCommand getCurrentStatus(long id) { try{ executeRequest(new SyncBcfTopologyCommand(true, true), _numRetries); } catch(Exception e){ - s_logger.error("BigSwitch BCF sync error", e); + logger.error("BigSwitch BCF sync error", e); } } else { try{ executeRequest(new SyncBcfTopologyCommand(true, false), _numRetries); } catch (Exception e){ - s_logger.error("BigSwitch BCF sync error", e); + logger.error("BigSwitch BCF sync error", e); } } } try { ControlClusterStatus ccs = _bigswitchBcfApi.getControlClusterStatus(); if (!ccs.getStatus()) { - s_logger.error("ControlCluster state is not ready: " + ccs.getStatus()); + logger.error("ControlCluster state is not ready: " + ccs.getStatus()); return null; } if (ccs.isTopologySyncRequested()) { @@ -200,11 +198,11 @@ public PingCommand getCurrentStatus(long id) { executeRequest(new SyncBcfTopologyCommand(true, false), _numRetries); } } else { - s_logger.debug("topology sync needed but no topology history"); + logger.debug("topology sync needed but no topology history"); } } } catch (BigSwitchBcfApiException e) { - s_logger.error("getControlClusterStatus failed", e); + logger.error("getControlClusterStatus failed", e); return null; } try { @@ -222,7 +220,7 @@ public PingCommand getCurrentStatus(long id) { } } catch (BigSwitchBcfApiException e) { - s_logger.error("getCapabilities failed", e); + logger.error("getCapabilities failed", e); } return new PingCommand(Host.Type.L2Networking, id); } @@ -274,7 +272,7 @@ public Answer executeRequest(Command cmd, int numRetries) { } else if (cmd instanceof GetControllerDataCommand) { return executeRequest((GetControllerDataCommand)cmd, numRetries); } - s_logger.debug("Received unsupported command " + cmd.toString()); + logger.debug("Received unsupported command " + cmd.toString()); return Answer.createUnsupportedCommandAnswer(cmd); } @@ -575,7 +573,7 @@ private Answer executeRequest(MaintainCommand cmd) { } private Answer retry(Command cmd, int numRetries) { - s_logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); + logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); return executeRequest(cmd, numRetries); } diff --git a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchApiTest.java b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchApiTest.java index 31b7e38cda1d..0a36058b6c19 100644 --- a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchApiTest.java +++ b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchApiTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchBcfUtilsTest.java b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchBcfUtilsTest.java index 554eac9aa2af..a488888e5d0b 100644 --- a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchBcfUtilsTest.java +++ b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/bigswitch/BigSwitchBcfUtilsTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -73,16 +74,22 @@ public class BigSwitchBcfUtilsTest { NetworkModel networkModel; @Mock BigSwitchBcfUtils bsUtil; + private AutoCloseable closeable; @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); bsUtil = new BigSwitchBcfUtils(networkDao, nicDao, vmDao, hostDao, vpcDao, bigswitchBcfDao, agentMgr, vlanDao, ipAddressDao, fwRulesDao, fwCidrsDao, aclItemDao, aclItemCidrsDao, networkModel); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void getSubnetMaskLengthTest() { Integer rc = bsUtil.getSubnetMaskLength("255.255.255.254"); diff --git a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/resource/BigSwitchBcfResourceTest.java b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/resource/BigSwitchBcfResourceTest.java index 005e2f6ee870..16b244418020 100644 --- a/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/resource/BigSwitchBcfResourceTest.java +++ b/plugins/network-elements/bigswitch/src/test/java/com/cloud/network/resource/BigSwitchBcfResourceTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; diff --git a/plugins/network-elements/brocade-vcs/pom.xml b/plugins/network-elements/brocade-vcs/pom.xml index ed045eb65f62..1363658d1793 100644 --- a/plugins/network-elements/brocade-vcs/pom.xml +++ b/plugins/network-elements/brocade-vcs/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -32,7 +32,7 @@ org.jvnet.jaxb2.maven2 maven-jaxb2-plugin - 0.14.0 + 0.15.3 interface diff --git a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/api/commands/ListBrocadeVcsDeviceNetworksCmd.java b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/api/commands/ListBrocadeVcsDeviceNetworksCmd.java index 584a6e665b74..707415b0f583 100644 --- a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/api/commands/ListBrocadeVcsDeviceNetworksCmd.java +++ b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/api/commands/ListBrocadeVcsDeviceNetworksCmd.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseListCmd; @@ -48,7 +47,6 @@ @APICommand(name = "listBrocadeVcsDeviceNetworks", responseObject = NetworkResponse.class, description = "lists network that are using a brocade vcs switch", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListBrocadeVcsDeviceNetworksCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListBrocadeVcsDeviceNetworksCmd.class.getName()); private static final String s_name = "listbrocadevcsdevicenetworks"; @Inject protected BrocadeVcsElementService brocadeVcsElementService; diff --git a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/brocade/BrocadeVcsApi.java b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/brocade/BrocadeVcsApi.java index eb03515b5d5d..cc7f99bb64e3 100644 --- a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/brocade/BrocadeVcsApi.java +++ b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/brocade/BrocadeVcsApi.java @@ -42,7 +42,8 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.network.schema.interfacevlan.InterfaceVlan; import com.cloud.network.schema.interfacevlan.Interface; @@ -61,7 +62,7 @@ import com.cloud.network.schema.showvcs.Output; public class BrocadeVcsApi { - private static final Logger s_logger = Logger.getLogger(BrocadeVcsApi.class); + protected Logger logger = LogManager.getLogger(getClass()); private final String _host; private final String _adminuser; @@ -74,7 +75,7 @@ protected HttpRequestBase createMethod(String type, String uri) throws BrocadeVc try { url = new URL(Constants.PROTOCOL, _host, Constants.PORT, uri).toString(); } catch (final MalformedURLException e) { - s_logger.error("Unable to build Brocade Switch API URL", e); + logger.error("Unable to build Brocade Switch API URL", e); throw new BrocadeVcsApiException("Unable to build Brocade Switch API URL", e); } @@ -338,12 +339,12 @@ protected boolean executeUpdateObject(T newObject, String uri) throws Brocad try { errorMessage = responseToErrorMessage(response); } catch (final IOException e) { - s_logger.error("Failed to update object : " + e.getMessage()); + logger.error("Failed to update object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to update object : " + e.getMessage()); } pm.releaseConnection(); - s_logger.error("Failed to update object : " + errorMessage); + logger.error("Failed to update object : " + errorMessage); throw new BrocadeVcsApiException("Failed to update object : " + errorMessage); } @@ -363,12 +364,12 @@ protected String convertToString(T object) throws BrocadeVcsApiException { marshaller.marshal(object, stringWriter); } catch (final JAXBException e) { - s_logger.error("Failed to convert object to string : " + e.getMessage()); + logger.error("Failed to convert object to string : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to convert object to string : " + e.getMessage()); } final String str = stringWriter.toString(); - s_logger.info(str); + logger.info(str); return str; @@ -387,11 +388,11 @@ protected Output convertToXML(String object) throws BrocadeVcsApiException { if (result instanceof Output) { output = (Output)result; - s_logger.info(output); + logger.info(output); } } catch (final JAXBException e) { - s_logger.error("Failed to convert string to object : " + e.getMessage()); + logger.error("Failed to convert string to object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to convert string to object : " + e.getMessage()); } @@ -417,12 +418,12 @@ protected boolean executeCreateObject(T newObject, String uri) throws Brocad try { errorMessage = responseToErrorMessage(response); } catch (final IOException e) { - s_logger.error("Failed to create object : " + e.getMessage()); + logger.error("Failed to create object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to create object : " + e.getMessage()); } pm.releaseConnection(); - s_logger.error("Failed to create object : " + errorMessage); + logger.error("Failed to create object : " + errorMessage); throw new BrocadeVcsApiException("Failed to create object : " + errorMessage); } @@ -451,12 +452,12 @@ protected Output executeRetreiveStatus(String uri) throws BrocadeVcsApiException try { errorMessage = responseToErrorMessage(response); } catch (final IOException e) { - s_logger.error("Failed to retreive status : " + e.getMessage()); + logger.error("Failed to retreive status : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to retreive status : " + e.getMessage()); } pm.releaseConnection(); - s_logger.error("Failed to retreive status : " + errorMessage); + logger.error("Failed to retreive status : " + errorMessage); throw new BrocadeVcsApiException("Failed to retreive status : " + errorMessage); } @@ -464,12 +465,12 @@ protected Output executeRetreiveStatus(String uri) throws BrocadeVcsApiException sb = new StringBuffer(); while ((readLine = br.readLine()) != null) { - s_logger.debug(readLine); + logger.debug(readLine); sb.append(readLine); } } catch (final Exception e) { - s_logger.error("Failed to retreive status : " + e.getMessage()); + logger.error("Failed to retreive status : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to retreive status : " + e.getMessage()); } @@ -494,12 +495,12 @@ protected void executeDeleteObject(String uri) throws BrocadeVcsApiException { try { errorMessage = responseToErrorMessage(response); } catch (final IOException e) { - s_logger.error("Failed to delete object : " + e.getMessage()); + logger.error("Failed to delete object : " + e.getMessage()); throw new BrocadeVcsApiException("Failed to delete object : " + e.getMessage()); } dm.releaseConnection(); - s_logger.error("Failed to delete object : " + errorMessage); + logger.error("Failed to delete object : " + errorMessage); throw new BrocadeVcsApiException("Failed to delete object : " + errorMessage); } dm.releaseConnection(); @@ -514,7 +515,7 @@ protected HttpResponse executeMethod(HttpRequestBase method) throws BrocadeVcsAp response = _client.execute(method); } } catch (final IOException e) { - s_logger.error("IOException caught while trying to connect to the Brocade Switch", e); + logger.error("IOException caught while trying to connect to the Brocade Switch", e); method.releaseConnection(); throw new BrocadeVcsApiException("API call to Brocade Switch Failed", e); } diff --git a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/element/BrocadeVcsElement.java b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/element/BrocadeVcsElement.java index f075b3202e6a..daf9c1c4e08d 100644 --- a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/element/BrocadeVcsElement.java +++ b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/element/BrocadeVcsElement.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -92,7 +91,6 @@ @Component public class BrocadeVcsElement extends AdapterBase implements NetworkElement, ResourceStateAdapter, BrocadeVcsElementService { - private static final Logger s_logger = Logger.getLogger(BrocadeVcsElement.class); private static final Map> capabilities = setCapabilities(); @@ -138,18 +136,18 @@ public Provider getProvider() { } protected boolean canHandle(Network network, Service service) { - s_logger.debug("Checking if BrocadeVcsElement can handle service " + service.getName() + " on network " + network.getDisplayText()); + logger.debug("Checking if BrocadeVcsElement can handle service " + service.getName() + " on network " + network.getDisplayText()); if (network.getBroadcastDomainType() != BroadcastDomainType.Vcs) { return false; } if (!_networkModel.isProviderForNetwork(getProvider(), network.getId())) { - s_logger.debug("BrocadeVcsElement is not a provider for network " + network.getDisplayText()); + logger.debug("BrocadeVcsElement is not a provider for network " + network.getDisplayText()); return false; } if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), service, Network.Provider.BrocadeVcs)) { - s_logger.debug("BrocadeVcsElement can't provide the " + service.getName() + " service on network " + network.getDisplayText()); + logger.debug("BrocadeVcsElement can't provide the " + service.getName() + " service on network " + network.getDisplayText()); return false; } @@ -166,7 +164,7 @@ public boolean configure(String name, Map params) throws Configu @Override public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - s_logger.debug("entering BrocadeVcsElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); + logger.debug("entering BrocadeVcsElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); if (!canHandle(network, Service.Connectivity)) { return false; @@ -234,7 +232,7 @@ public boolean canEnableIndividualServices() { public boolean verifyServicesCombination(Set services) { if (!services.contains(Service.Connectivity)) { - s_logger.warn("Unable to provide services without Connectivity service enabled for this element"); + logger.warn("Unable to provide services without Connectivity service enabled for this element"); return false; } return true; diff --git a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/guru/BrocadeVcsGuestNetworkGuru.java b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/guru/BrocadeVcsGuestNetworkGuru.java index 6a201cf988bb..8d2125d70eb0 100644 --- a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/guru/BrocadeVcsGuestNetworkGuru.java +++ b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/guru/BrocadeVcsGuestNetworkGuru.java @@ -56,13 +56,11 @@ import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachineProfile; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; public class BrocadeVcsGuestNetworkGuru extends GuestNetworkGuru { - private static final Logger s_logger = Logger.getLogger(BrocadeVcsGuestNetworkGuru.class); @Inject NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao; @@ -91,22 +89,23 @@ protected boolean canHandle(NetworkOffering offering, final NetworkType networkT && isMyIsolationMethod(physicalNetwork) && _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) { return true; } else { - s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); + logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); return false; } } @Override - public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner) { // Check of the isolation type of the related physical network is VLAN PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId()); DataCenter dc = _dcDao.findById(plan.getDataCenterId()); if (!canHandle(offering, dc.getNetworkType(), physnet)) { - s_logger.debug("Refusing to design this network"); + logger.debug("Refusing to design this network"); return null; } - s_logger.debug("Physical isolation type is VCS, asking GuestNetworkGuru to design this network"); - NetworkVO networkObject = (NetworkVO)super.design(offering, plan, userSpecified, owner); + + logger.debug("Physical isolation type is VCS, asking GuestNetworkGuru to design this network"); + NetworkVO networkObject = (NetworkVO)super.design(offering, plan, userSpecified, name, vpcId, owner); if (networkObject == null) { return null; } @@ -130,7 +129,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin List devices = _brocadeVcsDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { - s_logger.error("No Brocade VCS Switch on physical network " + physicalNetworkId); + logger.error("No Brocade VCS Switch on physical network " + physicalNetworkId); return null; } @@ -142,8 +141,8 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin CreateNetworkAnswer answer = (CreateNetworkAnswer)_agentMgr.easySend(brocadeVcsHost.getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("CreateNetworkCommand failed"); - s_logger.error("Unable to create network " + network.getId()); + logger.error("CreateNetworkCommand failed"); + logger.error("Unable to create network " + network.getId()); return null; } @@ -167,7 +166,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D List devices = _brocadeVcsDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId()); + logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId()); return; } for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) { @@ -179,7 +178,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D AssociateMacToNetworkAnswer answer = (AssociateMacToNetworkAnswer)_agentMgr.easySend(brocadeVcsHost.getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("AssociateMacToNetworkCommand failed"); + logger.error("AssociateMacToNetworkCommand failed"); throw new InsufficientVirtualNetworkCapacityException("Unable to associate mac " + interfaceMac + " to network " + network.getId(), DataCenter.class, dc.getId()); } } @@ -193,7 +192,7 @@ public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm List devices = _brocadeVcsDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId()); + logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId()); return; } for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) { @@ -204,8 +203,8 @@ public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm DisassociateMacFromNetworkAnswer answer = (DisassociateMacFromNetworkAnswer)_agentMgr.easySend(brocadeVcsHost.getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("DisassociateMacFromNetworkCommand failed"); - s_logger.error("Unable to disassociate mac " + interfaceMac + " from network " + network.getId()); + logger.error("DisassociateMacFromNetworkCommand failed"); + logger.error("Unable to disassociate mac " + interfaceMac + " from network " + network.getId()); return; } } @@ -233,13 +232,13 @@ public boolean trash(Network network, NetworkOffering offering) { if (brocadeVcsNetworkVlanMapping != null) { vlanTag = brocadeVcsNetworkVlanMapping.getVlanId(); } else { - s_logger.error("Not able to find vlanId for network " + network.getId()); + logger.error("Not able to find vlanId for network " + network.getId()); return false; } List devices = _brocadeVcsDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId()); + logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId()); return false; } for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) { @@ -250,8 +249,8 @@ public boolean trash(Network network, NetworkOffering offering) { DeleteNetworkAnswer answer = (DeleteNetworkAnswer)_agentMgr.easySend(brocadeVcsHost.getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("DeleteNetworkCommand failed"); - s_logger.error("Unable to delete network " + network.getId()); + logger.error("DeleteNetworkCommand failed"); + logger.error("Unable to delete network " + network.getId()); return false; } } diff --git a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/resource/BrocadeVcsResource.java b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/resource/BrocadeVcsResource.java index 0a323992b867..845580b11563 100644 --- a/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/resource/BrocadeVcsResource.java +++ b/plugins/network-elements/brocade-vcs/src/main/java/com/cloud/network/resource/BrocadeVcsResource.java @@ -21,7 +21,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -50,7 +51,7 @@ import com.cloud.resource.ServerResource; public class BrocadeVcsResource implements ServerResource { - private static final Logger s_logger = Logger.getLogger(BrocadeVcsResource.class); + protected Logger logger = LogManager.getLogger(getClass()); private String _name; private String _guid; @@ -143,7 +144,7 @@ public PingCommand getCurrentStatus(long id) { try { output = _brocadeVcsApi.getSwitchStatus(); } catch (BrocadeVcsApiException e) { - s_logger.error("getSwitchStatus failed", e); + logger.error("getSwitchStatus failed", e); return null; } @@ -151,7 +152,7 @@ public PingCommand getCurrentStatus(long id) { if (vcsNodes != null && !vcsNodes.isEmpty()) { for (VcsNodeInfo vcsNodeInfo : vcsNodes) { if (!"Online".equals(vcsNodeInfo.getNodeState())) { - s_logger.error("Brocade Switch is not ready: " + id); + logger.error("Brocade Switch is not ready: " + id); return null; } } @@ -179,7 +180,7 @@ public Answer executeRequest(Command cmd, int numRetries) { } else if (cmd instanceof DeleteNetworkCommand) { return executeRequest((DeleteNetworkCommand)cmd, numRetries); } - s_logger.debug("Received unsupported command " + cmd.toString()); + logger.debug("Received unsupported command " + cmd.toString()); return Answer.createUnsupportedCommandAnswer(cmd); } @@ -276,7 +277,7 @@ private Answer executeRequest(MaintainCommand cmd) { } private Answer retry(Command cmd, int numRetries) { - s_logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); + logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); return executeRequest(cmd, numRetries); } diff --git a/plugins/network-elements/brocade-vcs/src/main/resources/META-INF/cloudstack/vcs/spring-vcs-context.xml b/plugins/network-elements/brocade-vcs/src/main/resources/META-INF/cloudstack/vcs/spring-vcs-context.xml index 1773c83d185c..4ba9ecbf46a2 100644 --- a/plugins/network-elements/brocade-vcs/src/main/resources/META-INF/cloudstack/vcs/spring-vcs-context.xml +++ b/plugins/network-elements/brocade-vcs/src/main/resources/META-INF/cloudstack/vcs/spring-vcs-context.xml @@ -1,12 +1,12 @@ - org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/AddCiscoAsa1000vResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/AddCiscoAsa1000vResourceCmd.java index 5c912a278f2f..b792637b3dbd 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/AddCiscoAsa1000vResourceCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/AddCiscoAsa1000vResourceCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -43,7 +42,6 @@ @APICommand(name = "addCiscoAsa1000vResource", responseObject = CiscoAsa1000vResourceResponse.class, description = "Adds a Cisco Asa 1000v appliance", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddCiscoAsa1000vResourceCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(AddCiscoAsa1000vResourceCmd.class.getName()); private static final String s_name = "addCiscoAsa1000vResource"; @Inject CiscoAsa1000vService _ciscoAsa1000vService; diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java index 15d69b68c30f..858b81423188 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ @APICommand(name = "addCiscoVnmcResource", responseObject = CiscoVnmcResourceResponse.class, description = "Adds a Cisco Vnmc Controller", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddCiscoVnmcResourceCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(AddCiscoVnmcResourceCmd.class.getName()); private static final String s_name = "addCiscoVnmcResource"; @Inject CiscoVnmcElementService _ciscoVnmcElementService; diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/DeleteCiscoAsa1000vResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/DeleteCiscoAsa1000vResourceCmd.java index cdd4fbaca0e6..c0c8101ed80c 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/DeleteCiscoAsa1000vResourceCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/DeleteCiscoAsa1000vResourceCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ @APICommand(name = "deleteCiscoAsa1000vResource", responseObject = SuccessResponse.class, description = "Deletes a Cisco ASA 1000v appliance", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteCiscoAsa1000vResourceCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(DeleteCiscoAsa1000vResourceCmd.class.getName()); private static final String s_name = "deleteCiscoAsa1000vResource"; @Inject CiscoAsa1000vService _ciscoAsa1000vService; diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java index 2f1aecab98b8..456b8cf40088 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ @APICommand(name = "deleteCiscoVnmcResource", responseObject = SuccessResponse.class, description = "Deletes a Cisco Vnmc controller", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteCiscoVnmcResourceCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(DeleteCiscoVnmcResourceCmd.class.getName()); private static final String s_name = "deleteCiscoVnmcResource"; @Inject CiscoVnmcElementService _ciscoVnmcElementService; diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/ListCiscoAsa1000vResourcesCmd.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/ListCiscoAsa1000vResourcesCmd.java index abf0bea11fa2..82974c270aaa 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/ListCiscoAsa1000vResourcesCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/ListCiscoAsa1000vResourcesCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -46,7 +45,6 @@ @APICommand(name = "listCiscoAsa1000vResources", responseObject = CiscoAsa1000vResourceResponse.class, description = "Lists Cisco ASA 1000v appliances", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListCiscoAsa1000vResourcesCmd extends BaseListCmd { - private static final Logger s_logger = Logger.getLogger(ListCiscoAsa1000vResourcesCmd.class.getName()); private static final String s_name = "listCiscoAsa1000vResources"; @Inject CiscoAsa1000vService _ciscoAsa1000vService; diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/ListCiscoVnmcResourcesCmd.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/ListCiscoVnmcResourcesCmd.java index c5e05e8013c0..f2a364faa720 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/ListCiscoVnmcResourcesCmd.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/api/commands/ListCiscoVnmcResourcesCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -46,7 +45,6 @@ @APICommand(name = "listCiscoVnmcResources", responseObject = CiscoVnmcResourceResponse.class, description = "Lists Cisco VNMC controllers", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListCiscoVnmcResourcesCmd extends BaseListCmd { - private static final Logger s_logger = Logger.getLogger(ListCiscoVnmcResourcesCmd.class.getName()); private static final String s_name = "listCiscoVnmcResources"; @Inject CiscoVnmcElementService _ciscoVnmcElementService; diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/cisco/CiscoVnmcConnectionImpl.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/cisco/CiscoVnmcConnectionImpl.java index 8b8e58958432..90597d7b1e19 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/cisco/CiscoVnmcConnectionImpl.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/cisco/CiscoVnmcConnectionImpl.java @@ -30,7 +30,8 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -46,7 +47,7 @@ public class CiscoVnmcConnectionImpl implements CiscoVnmcConnection { private final String _password; private String _cookie; - private static final Logger s_logger = Logger.getLogger(CiscoVnmcConnectionImpl.class); + protected static Logger LOGGER = LogManager.getLogger(CiscoVnmcConnectionImpl.class); private enum VnmcXml { LOGIN("login.xml", "mgmt-controller"), @@ -141,7 +142,7 @@ private String getXml(String filename) { return xml; } catch (Exception e) { - s_logger.debug(e); + LOGGER.debug(e); return null; } } @@ -1291,7 +1292,7 @@ private Document getDocument(String xml) throws ExecutionException { doc = ParserUtils.getSaferDocumentBuilderFactory().newDocumentBuilder().parse(xmlSource); } catch (Exception e) { - s_logger.error(e); + LOGGER.error(e); throw new ExecutionException(e.getMessage()); } diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/element/CiscoVnmcElement.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/element/CiscoVnmcElement.java index ed650022d0cd..bea5a2c3f25e 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/element/CiscoVnmcElement.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/element/CiscoVnmcElement.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -135,7 +134,6 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServiceProvider, FirewallServiceProvider, PortForwardingServiceProvider, IpDeployer, StaticNatServiceProvider, ResourceStateAdapter, NetworkElement, CiscoVnmcElementService, CiscoAsa1000vService { - private static final Logger s_logger = Logger.getLogger(CiscoVnmcElement.class); private static final Map> capabilities = setCapabilities(); @Inject @@ -272,7 +270,7 @@ public boolean implement(final Network network, final NetworkOffering offering, final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); if (zone.getNetworkType() == NetworkType.Basic) { - s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic); + logger.debug("Not handling network implement in zone of type " + NetworkType.Basic); return false; } @@ -282,24 +280,24 @@ public boolean implement(final Network network, final NetworkOffering offering, final List devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No Cisco Vnmc device on network " + network.getName()); + logger.error("No Cisco Vnmc device on network " + network.getName()); return false; } List asaList = _ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (asaList.isEmpty()) { - s_logger.debug("No Cisco ASA 1000v device on network " + network.getName()); + logger.debug("No Cisco ASA 1000v device on network " + network.getName()); return false; } NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId()); if (asaForNetwork != null) { - s_logger.debug("Cisco ASA 1000v device already associated with network " + network.getName()); + logger.debug("Cisco ASA 1000v device already associated with network " + network.getName()); return true; } if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.CiscoVnmc)) { - s_logger.error("SourceNat service is not provided by Cisco Vnmc device on network " + network.getName()); + logger.error("SourceNat service is not provided by Cisco Vnmc device on network " + network.getName()); return false; } @@ -307,20 +305,20 @@ public boolean implement(final Network network, final NetworkOffering offering, // ensure that there is an ASA 1000v assigned to this network CiscoAsa1000vDevice assignedAsa = assignAsa1000vToNetwork(network); if (assignedAsa == null) { - s_logger.error("Unable to assign ASA 1000v device to network " + network.getName()); + logger.error("Unable to assign ASA 1000v device to network " + network.getName()); throw new CloudRuntimeException("Unable to assign ASA 1000v device to network " + network.getName()); } ClusterVO asaCluster = _clusterDao.findById(assignedAsa.getClusterId()); ClusterVSMMapVO clusterVsmMap = _clusterVsmMapDao.findByClusterId(assignedAsa.getClusterId()); if (clusterVsmMap == null) { - s_logger.error("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it"); + logger.error("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it"); throw new CloudRuntimeException("Vmware cluster " + asaCluster.getName() + " has no Cisco Nexus VSM device associated with it"); } CiscoNexusVSMDeviceVO vsmDevice = _vsmDeviceDao.findById(clusterVsmMap.getVsmId()); if (vsmDevice == null) { - s_logger.error("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName()); + logger.error("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName()); throw new CloudRuntimeException("Unable to load details of Cisco Nexus VSM device associated with cluster " + asaCluster.getName()); } @@ -355,14 +353,14 @@ public boolean implement(final Network network, final NetworkOffering offering, long callerUserId = CallContext.current().getCallingUserId(); outsideIp = _ipAddrMgr.allocateIp(owner, false, caller, callerUserId, zone, true, null); } catch (ResourceAllocationException e) { - s_logger.error("Unable to allocate additional public Ip address. Exception details " + e); + logger.error("Unable to allocate additional public Ip address. Exception details " + e); throw new CloudRuntimeException("Unable to allocate additional public Ip address. Exception details " + e); } try { outsideIp = _ipAddrMgr.associateIPToGuestNetwork(outsideIp.getId(), network.getId(), true); } catch (ResourceAllocationException e) { - s_logger.error("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + + logger.error("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details " + e); throw new CloudRuntimeException("Unable to assign allocated additional public Ip " + outsideIp.getAddress().addr() + " to network with vlan " + vlanId + ". Exception details " + e); @@ -375,33 +373,33 @@ public boolean implement(final Network network, final NetworkOffering offering, // all public ip addresses must be from same subnet, this essentially means single public subnet in zone if (!createLogicalEdgeFirewall(vlanId, network.getGateway(), gatewayNetmask, outsideIp.getAddress().addr(), sourceNatIp.getNetmask(), publicGateways, ciscoVnmcHost.getId())) { - s_logger.error("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName()); + logger.error("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName()); throw new CloudRuntimeException("Failed to create logical edge firewall in Cisco VNMC device for network " + network.getName()); } // create stuff in VSM for ASA device if (!configureNexusVsmForAsa(vlanId, network.getGateway(), vsmDevice.getUserName(), vsmDevice.getPassword(), vsmDevice.getipaddr(), assignedAsa.getInPortProfile(), ciscoVnmcHost.getId())) { - s_logger.error("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() + " for ASA device for network " + network.getName()); + logger.error("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() + " for ASA device for network " + network.getName()); throw new CloudRuntimeException("Failed to configure Cisco Nexus VSM " + vsmDevice.getipaddr() + " for ASA device for network " + network.getName()); } // configure source NAT if (!configureSourceNat(vlanId, network.getCidr(), sourceNatIp, ciscoVnmcHost.getId())) { - s_logger.error("Failed to configure source NAT in Cisco VNMC device for network " + network.getName()); + logger.error("Failed to configure source NAT in Cisco VNMC device for network " + network.getName()); throw new CloudRuntimeException("Failed to configure source NAT in Cisco VNMC device for network " + network.getName()); } // associate Asa 1000v instance with logical edge firewall if (!associateAsaWithLogicalEdgeFirewall(vlanId, assignedAsa.getManagementIp(), ciscoVnmcHost.getId())) { - s_logger.error("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() + ") with logical edge firewall in VNMC for network " + + logger.error("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() + ") with logical edge firewall in VNMC for network " + network.getName()); throw new CloudRuntimeException("Failed to associate Cisco ASA 1000v (" + assignedAsa.getManagementIp() + ") with logical edge firewall in VNMC for network " + network.getName()); } } catch (CloudRuntimeException e) { unassignAsa1000vFromNetwork(network); - s_logger.error("CiscoVnmcElement failed", e); + logger.error("CiscoVnmcElement failed", e); return false; } catch (Exception e) { unassignAsa1000vFromNetwork(network); @@ -477,7 +475,7 @@ public boolean canEnableIndividualServices() { @Override public boolean verifyServicesCombination(Set services) { if (!services.contains(Service.Firewall)) { - s_logger.warn("CiscoVnmc must be used as Firewall Service Provider in the network"); + logger.warn("CiscoVnmc must be used as Firewall Service Provider in the network"); return false; } return true; @@ -642,26 +640,26 @@ public IpDeployer getIpDeployer(Network network) { public boolean applyFWRules(Network network, List rules) throws ResourceUnavailableException { if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Firewall, Provider.CiscoVnmc)) { - s_logger.error("Firewall service is not provided by Cisco Vnmc device on network " + network.getName()); + logger.error("Firewall service is not provided by Cisco Vnmc device on network " + network.getName()); return false; } // Find VNMC host for physical network List devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No Cisco Vnmc device on network " + network.getName()); + logger.error("No Cisco Vnmc device on network " + network.getName()); return true; } // Find if ASA 1000v is associated with network NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId()); if (asaForNetwork == null) { - s_logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName()); + logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName()); return true; } if (network.getState() == Network.State.Allocated) { - s_logger.debug("External firewall was asked to apply firewall rules for network with ID " + network.getId() + + logger.debug("External firewall was asked to apply firewall rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands."); return true; } @@ -688,7 +686,7 @@ public boolean applyFWRules(Network network, List rules) if (answer == null || !answer.getResult()) { String details = (answer != null) ? answer.getDetails() : "details unavailable"; String msg = "Unable to apply firewall rules to Cisco ASA 1000v appliance due to: " + details + "."; - s_logger.error(msg); + logger.error(msg); throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId()); } } @@ -700,26 +698,26 @@ public boolean applyFWRules(Network network, List rules) public boolean applyPFRules(Network network, List rules) throws ResourceUnavailableException { if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.PortForwarding, Provider.CiscoVnmc)) { - s_logger.error("Port forwarding service is not provided by Cisco Vnmc device on network " + network.getName()); + logger.error("Port forwarding service is not provided by Cisco Vnmc device on network " + network.getName()); return false; } // Find VNMC host for physical network List devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No Cisco Vnmc device on network " + network.getName()); + logger.error("No Cisco Vnmc device on network " + network.getName()); return true; } // Find if ASA 1000v is associated with network NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId()); if (asaForNetwork == null) { - s_logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName()); + logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName()); return true; } if (network.getState() == Network.State.Allocated) { - s_logger.debug("External firewall was asked to apply port forwarding rules for network with ID " + network.getId() + + logger.debug("External firewall was asked to apply port forwarding rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands."); return true; } @@ -743,7 +741,7 @@ public boolean applyPFRules(Network network, List rules) thr if (answer == null || !answer.getResult()) { String details = (answer != null) ? answer.getDetails() : "details unavailable"; String msg = "Unable to apply port forwarding rules to Cisco ASA 1000v appliance due to: " + details + "."; - s_logger.error(msg); + logger.error(msg); throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId()); } } @@ -754,26 +752,26 @@ public boolean applyPFRules(Network network, List rules) thr @Override public boolean applyStaticNats(Network network, List rules) throws ResourceUnavailableException { if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.StaticNat, Provider.CiscoVnmc)) { - s_logger.error("Static NAT service is not provided by Cisco Vnmc device on network " + network.getName()); + logger.error("Static NAT service is not provided by Cisco Vnmc device on network " + network.getName()); return false; } // Find VNMC host for physical network List devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No Cisco Vnmc device on network " + network.getName()); + logger.error("No Cisco Vnmc device on network " + network.getName()); return true; } // Find if ASA 1000v is associated with network NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId()); if (asaForNetwork == null) { - s_logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName()); + logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName()); return true; } if (network.getState() == Network.State.Allocated) { - s_logger.debug("External firewall was asked to apply static NAT rules for network with ID " + network.getId() + + logger.debug("External firewall was asked to apply static NAT rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands."); return true; } @@ -798,7 +796,7 @@ public boolean applyStaticNats(Network network, List rules) if (answer == null || !answer.getResult()) { String details = (answer != null) ? answer.getDetails() : "details unavailable"; String msg = "Unable to apply static NAT rules to Cisco ASA 1000v appliance due to: " + details + "."; - s_logger.error(msg); + logger.error(msg); throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId()); } } diff --git a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/resource/CiscoVnmcResource.java b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/resource/CiscoVnmcResource.java index 4b8ee6f42c47..bbecdaf05e02 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/resource/CiscoVnmcResource.java +++ b/plugins/network-elements/cisco-vnmc/src/main/java/com/cloud/network/resource/CiscoVnmcResource.java @@ -23,7 +23,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -81,7 +82,7 @@ public void setConnection(CiscoVnmcConnectionImpl connection) { _connection = connection; } - private static final Logger s_logger = Logger.getLogger(CiscoVnmcResource.class); + protected Logger logger = LogManager.getLogger(getClass()); @Override public Answer executeRequest(Command cmd) { @@ -244,7 +245,7 @@ private boolean refreshVnmcConnection() { try { ret = _connection.login(); } catch (ExecutionException ex) { - s_logger.error("Login to Vnmc failed", ex); + logger.error("Login to Vnmc failed", ex); } return ret; } @@ -312,7 +313,7 @@ private Answer execute(SetSourceNatCommand cmd, int numRetries) { } } catch (ExecutionException e) { String msg = "SetSourceNatCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -404,7 +405,7 @@ private Answer execute(SetFirewallRulesCommand cmd, int numRetries) { } } catch (ExecutionException e) { String msg = "SetFirewallRulesCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -489,7 +490,7 @@ private Answer execute(SetStaticNatRulesCommand cmd, int numRetries) { } } catch (ExecutionException e) { String msg = "SetStaticNatRulesCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -579,7 +580,7 @@ private Answer execute(SetPortForwardingRulesCommand cmd, int numRetries) { } } catch (ExecutionException e) { String msg = "SetPortForwardingRulesCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -637,7 +638,7 @@ private Answer execute(CreateLogicalEdgeFirewallCommand cmd, int numRetries) { throw new ExecutionException("Failed to create edge firewall in VNMC for guest network with vlan " + cmd.getVlanId()); } catch (ExecutionException e) { String msg = "CreateLogicalEdgeFirewallCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -658,14 +659,14 @@ private Answer execute(ConfigureNexusVsmForAsaCommand cmd, int numRetries) { params.add(new Pair(OperationType.addvlanid, vlanId)); try { helper = new NetconfHelper(cmd.getVsmIp(), cmd.getVsmUsername(), cmd.getVsmPassword()); - s_logger.debug("Connected to Cisco VSM " + cmd.getVsmIp()); + logger.debug("Connected to Cisco VSM " + cmd.getVsmIp()); helper.addVServiceNode(vlanId, cmd.getIpAddress()); - s_logger.debug("Created vservice node for ASA appliance in Cisco VSM for vlan " + vlanId); + logger.debug("Created vservice node for ASA appliance in Cisco VSM for vlan " + vlanId); helper.updatePortProfile(cmd.getAsaInPortProfile(), SwitchPortMode.access, params); - s_logger.debug("Updated inside port profile for ASA appliance in Cisco VSM with new vlan " + vlanId); + logger.debug("Updated inside port profile for ASA appliance in Cisco VSM with new vlan " + vlanId); } catch (CloudRuntimeException e) { String msg = "ConfigureVSMForASACommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } finally { if( helper != null) { @@ -700,7 +701,7 @@ private Answer execute(AssociateAsaWithLogicalEdgeFirewallCommand cmd, int numRe } } catch (ExecutionException e) { String msg = "AssociateAsaWithLogicalEdgeFirewallCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -721,7 +722,7 @@ private Answer execute(CleanupLogicalEdgeFirewallCommand cmd, int numRetries) { _connection.deleteTenant(tenant); } catch (ExecutionException e) { String msg = "CleanupLogicalEdgeFirewallCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } diff --git a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/associate-acl-policy-set.xml b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/associate-acl-policy-set.xml index e3113ae22c7f..cd6d3073ea05 100755 --- a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/associate-acl-policy-set.xml +++ b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/associate-acl-policy-set.xml @@ -16,7 +16,7 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - diff --git a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-dhcp-policy.xml b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-dhcp-policy.xml index cab9f9861ecc..bf3a60c67b95 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-dhcp-policy.xml +++ b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-dhcp-policy.xml @@ -60,13 +60,13 @@ under the License. status="created"/> - - - + + + diff --git a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-edge-firewall.xml b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-edge-firewall.xml index d2ab997ce733..ba430bf6b9d7 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-edge-firewall.xml +++ b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-edge-firewall.xml @@ -74,7 +74,7 @@ under the License. - + - diff --git a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-source-nat-pool.xml b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-source-nat-pool.xml index 957bc9f6a9a4..b3951fc09538 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-source-nat-pool.xml +++ b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-source-nat-pool.xml @@ -22,7 +22,7 @@ under the License. diff --git a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-source-nat-rule.xml b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-source-nat-rule.xml index 9980df1d2c7e..131bcdfbf5b6 100644 --- a/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-source-nat-rule.xml +++ b/plugins/network-elements/cisco-vnmc/src/main/scripts/network/cisco/create-source-nat-rule.xml @@ -16,8 +16,8 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - @@ -56,7 +56,7 @@ under the License. diff --git a/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/element/CiscoVnmcElementTest.java b/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/element/CiscoVnmcElementTest.java index 311dcf68c745..b013acd0f3e5 100644 --- a/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/element/CiscoVnmcElementTest.java +++ b/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/element/CiscoVnmcElementTest.java @@ -18,8 +18,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/resource/CiscoVnmcResourceTest.java b/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/resource/CiscoVnmcResourceTest.java index a5be7b641c63..b331a2f72280 100644 --- a/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/resource/CiscoVnmcResourceTest.java +++ b/plugins/network-elements/cisco-vnmc/src/test/java/com/cloud/network/resource/CiscoVnmcResourceTest.java @@ -17,9 +17,9 @@ package com.cloud.network.resource; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/network-elements/dns-notifier/pom.xml b/plugins/network-elements/dns-notifier/pom.xml index a0bc4d0482f5..8d2ecaa30f2c 100644 --- a/plugins/network-elements/dns-notifier/pom.xml +++ b/plugins/network-elements/dns-notifier/pom.xml @@ -22,7 +22,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml cloud-plugin-example-dns-notifier diff --git a/plugins/network-elements/dns-notifier/src/main/resources/components-example.xml b/plugins/network-elements/dns-notifier/src/main/resources/components-example.xml index 76a6cad9b4ac..1498a2e72bf4 100755 --- a/plugins/network-elements/dns-notifier/src/main/resources/components-example.xml +++ b/plugins/network-elements/dns-notifier/src/main/resources/components-example.xml @@ -170,7 +170,7 @@ under the License. true - + @@ -178,7 +178,7 @@ under the License. - + diff --git a/plugins/network-elements/elastic-loadbalancer/pom.xml b/plugins/network-elements/elastic-loadbalancer/pom.xml index bca3ceb210a7..9e2f395cd0ae 100644 --- a/plugins/network-elements/elastic-loadbalancer/pom.xml +++ b/plugins/network-elements/elastic-loadbalancer/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/element/ElasticLoadBalancerElement.java b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/element/ElasticLoadBalancerElement.java index 87ecf0071f10..c1ea7823811b 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/element/ElasticLoadBalancerElement.java +++ b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/element/ElasticLoadBalancerElement.java @@ -24,7 +24,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; @@ -56,7 +55,6 @@ @Component public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalancingServiceProvider, IpDeployer { - private static final Logger s_logger = Logger.getLogger(ElasticLoadBalancerElement.class); private static final Map> capabilities = setCapabilities(); @Inject NetworkModel _networkManager; @@ -74,7 +72,7 @@ public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalan private boolean canHandle(Network network, List rules) { if (network.getGuestType() != Network.GuestType.Shared || network.getTrafficType() != TrafficType.Guest) { - s_logger.debug("Not handling network with type " + network.getGuestType() + " and traffic type " + network.getTrafficType()); + logger.debug("Not handling network with type " + network.getGuestType() + " and traffic type " + network.getTrafficType()); return false; } @@ -84,7 +82,7 @@ private boolean canHandle(Network network, List rules) { if (schemeCaps != null) { for (LoadBalancingRule rule : rules) { if (!schemeCaps.contains(rule.getScheme().toString())) { - s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + this.getName()); + logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + this.getName()); return false; } } @@ -226,4 +224,8 @@ public boolean handlesOnlyRulesInTransitionState() { return true; } + @Override + public void expungeLbVmRefs(List vmIds, Long batchSize) { + _lbMgr.expungeLbVmRefs(vmIds, batchSize); + } } diff --git a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManager.java b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManager.java index f885f7e1012d..a687c8113165 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManager.java +++ b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManager.java @@ -37,4 +37,6 @@ public LoadBalancer handleCreateLoadBalancerRule(CreateLoadBalancerRuleCmd lb, A NetworkRuleConflictException; public void handleDeleteLoadBalancerRule(LoadBalancer lb, long callerUserId, Account caller); + + void expungeLbVmRefs(List vmIds, Long batchSize); } diff --git a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 6975f76e9681..c7f4b8bf2443 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.config.ApiServiceConfiguration; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -103,7 +102,6 @@ @Component public class ElasticLoadBalancerManagerImpl extends ManagerBase implements ElasticLoadBalancerManager, VirtualMachineGuru { - private static final Logger s_logger = Logger.getLogger(ElasticLoadBalancerManagerImpl.class); @Inject private AgentManager _agentMgr; @@ -162,7 +160,7 @@ private boolean sendCommandsToRouter(final DomainRouterVO elbVm, Commands cmds) try { answers = _agentMgr.send(elbVm.getHostId(), cmds); } catch (OperationTimedoutException e) { - s_logger.warn("ELB: Timed Out", e); + logger.warn("ELB: Timed Out", e); throw new AgentUnavailableException("Unable to send commands to virtual elbVm ", elbVm.getHostId(), e); } @@ -249,7 +247,7 @@ public boolean applyLoadBalancerRules(Network network, List r DomainRouterVO elbVm = findElbVmForLb(rules.get(0)); if (elbVm == null) { - s_logger.warn("Unable to apply lb rules, ELB vm doesn't exist in the network " + network.getId()); + logger.warn("Unable to apply lb rules, ELB vm doesn't exist in the network " + network.getId()); throw new ResourceUnavailableException("Unable to apply lb rules", DataCenter.class, network.getDataCenterId()); } @@ -269,10 +267,10 @@ public boolean applyLoadBalancerRules(Network network, List r } return applyLBRules(elbVm, lbRules, network.getId()); } else if (elbVm.getState() == State.Stopped || elbVm.getState() == State.Stopping) { - s_logger.debug("ELB VM is in " + elbVm.getState() + ", so not sending apply LoadBalancing rules commands to the backend"); + logger.debug("ELB VM is in " + elbVm.getState() + ", so not sending apply LoadBalancing rules commands to the backend"); return true; } else { - s_logger.warn("Unable to apply loadbalancing rules, ELB VM is not in the right state " + elbVm.getState()); + logger.warn("Unable to apply loadbalancing rules, ELB VM is not in the right state " + elbVm.getState()); throw new ResourceUnavailableException("Unable to apply loadbalancing rules, ELB VM is not in the right state", VirtualRouter.class, elbVm.getId()); } } @@ -296,13 +294,13 @@ public boolean configure(String name, Map params) throws Configu // this can sometimes happen, if DB is manually or programmatically manipulated if (offerings == null || offerings.size() < 2) { String msg = "Data integrity problem : System Offering For Elastic LB VM has been removed?"; - s_logger.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key()); _enabled = (enabled == null) ? false : Boolean.parseBoolean(enabled); - s_logger.info("Elastic Load balancer enabled: " + _enabled); + logger.info("Elastic Load balancer enabled: " + _enabled); if (_enabled) { String traffType = _configDao.getValue(Config.ElasticLoadBalancerNetwork.key()); if ("guest".equalsIgnoreCase(traffType)) { @@ -311,11 +309,11 @@ public boolean configure(String name, Map params) throws Configu _frontendTrafficType = TrafficType.Public; } else throw new ConfigurationException("ELB: Traffic type for front end of load balancer has to be guest or public; found : " + traffType); - s_logger.info("ELB: Elastic Load Balancer: will balance on " + traffType); + logger.info("ELB: Elastic Load Balancer: will balance on " + traffType); int gcIntervalMinutes = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmGcInterval.key()), 5); if (gcIntervalMinutes < 5) gcIntervalMinutes = 5; - s_logger.info("ELB: Elastic Load Balancer: scheduling GC to run every " + gcIntervalMinutes + " minutes"); + logger.info("ELB: Elastic Load Balancer: scheduling GC to run every " + gcIntervalMinutes + " minutes"); _gcThreadPool = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ELBVM-GC")); _gcThreadPool.scheduleAtFixedRate(new CleanupThread(), gcIntervalMinutes, gcIntervalMinutes, TimeUnit.MINUTES); _itMgr.registerGuru(VirtualMachine.Type.ElasticLoadBalancerVm, this); @@ -327,7 +325,7 @@ public boolean configure(String name, Map params) throws Configu } private DomainRouterVO stop(DomainRouterVO elbVm, boolean forced) throws ConcurrentOperationException, ResourceUnavailableException { - s_logger.debug("Stopping ELB vm " + elbVm); + logger.debug("Stopping ELB vm " + elbVm); try { _itMgr.advanceStop(elbVm.getUuid(), forced); return _routerDao.findById(elbVm.getId()); @@ -346,7 +344,7 @@ void garbageCollectUnusedElbVms() { List unusedElbVms = _elbVmMapDao.listUnusedElbVms(); if (unusedElbVms != null) { if (unusedElbVms.size() > 0) { - s_logger.info("Found " + unusedElbVms.size() + " unused ELB vms"); + logger.info("Found " + unusedElbVms.size() + " unused ELB vms"); } Set currentGcCandidates = new HashSet(); for (DomainRouterVO elbVm : unusedElbVms) { @@ -359,22 +357,22 @@ void garbageCollectUnusedElbVms() { boolean gceed = false; try { - s_logger.info("Attempting to stop ELB VM: " + elbVm); + logger.info("Attempting to stop ELB VM: " + elbVm); stop(elbVm, true); gceed = true; } catch (ConcurrentOperationException e) { - s_logger.warn("Unable to stop unused ELB vm " + elbVm + " due to ", e); + logger.warn("Unable to stop unused ELB vm " + elbVm + " due to ", e); } catch (ResourceUnavailableException e) { - s_logger.warn("Unable to stop unused ELB vm " + elbVm + " due to ", e); + logger.warn("Unable to stop unused ELB vm " + elbVm + " due to ", e); continue; } if (gceed) { try { - s_logger.info("Attempting to destroy ELB VM: " + elbVm); + logger.info("Attempting to destroy ELB VM: " + elbVm); _itMgr.expunge(elbVm.getUuid()); _routerDao.remove(elbVm.getId()); } catch (ResourceUnavailableException e) { - s_logger.warn("Unable to destroy unused ELB vm " + elbVm + " due to ", e); + logger.warn("Unable to destroy unused ELB vm " + elbVm + " due to ", e); gceed = false; } } @@ -444,14 +442,14 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl } else if (nic.getTrafficType() == TrafficType.Control) { // control command is sent over management network in VMware if (dest.getHost().getHypervisorType() == HypervisorType.VMware) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Check if we need to add management server explicit route to ELB vm. pod cidr: " + dest.getPod().getCidrAddress() + "/" + if (logger.isInfoEnabled()) { + logger.info("Check if we need to add management server explicit route to ELB vm. pod cidr: " + dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize() + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + ApiServiceConfiguration.ManagementServerAddresses.value()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Added management server explicit route to ELB vm."); + if (logger.isDebugEnabled()) { + logger.debug("Added management server explicit route to ELB vm."); } // always add management explicit route, for basic networking setup buf.append(" mgmtcidr=").append(_mgmtCidr); @@ -478,8 +476,8 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl } String msPublicKey = _configDao.getValue("ssh.publickey"); buf.append(" authorized_key=").append(VirtualMachineGuru.getEncodedMsPublicKey(msPublicKey)); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Boot Args for " + profile + ": " + buf.toString()); } if (controlNic == null) { @@ -514,7 +512,7 @@ public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { CheckSshAnswer answer = (CheckSshAnswer)cmds.getAnswer("checkSsh"); if (answer == null || !answer.getResult()) { - s_logger.warn("Unable to ssh to the ELB VM: " + (answer != null ? answer.getDetails() : "No answer (answer for \"checkSsh\" was null)")); + logger.warn("Unable to ssh to the ELB VM: " + (answer != null ? answer.getDetails() : "No answer (answer for \"checkSsh\" was null)")); return false; } @@ -549,7 +547,7 @@ public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile prof } if (controlNic == null) { - s_logger.error("Control network doesn't exist for the ELB vm " + elbVm); + logger.error("Control network doesn't exist for the ELB vm " + elbVm); return false; } @@ -567,7 +565,7 @@ public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile prof lbRules.add(loadBalancing); } - s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of ELB vm " + elbVm + " start."); + logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of ELB vm " + elbVm + " start."); if (!lbRules.isEmpty()) { createApplyLoadBalancingRulesCommands(lbRules, elbVm, cmds, guestNetworkId); } @@ -601,4 +599,8 @@ public void prepareStop(VirtualMachineProfile profile) { public void finalizeUnmanage(VirtualMachine vm) { } + @Override + public void expungeLbVmRefs(List vmIds, Long batchSize) { + _elbVmMapDao.expungeByLbVmList(vmIds, batchSize); + } } diff --git a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/LoadBalanceRuleHandler.java b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/LoadBalanceRuleHandler.java index ed52174d7e0a..6812fa495324 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/LoadBalanceRuleHandler.java +++ b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/LoadBalanceRuleHandler.java @@ -30,7 +30,8 @@ import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.configuration.ConfigurationManagerImpl; import com.cloud.dc.DataCenter; @@ -100,7 +101,7 @@ public class LoadBalanceRuleHandler { - private static final Logger s_logger = Logger.getLogger(LoadBalanceRuleHandler.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private IPAddressDao _ipAddressDao; @@ -162,7 +163,7 @@ public LoadBalanceRuleHandler(String instance, Account systemAcct) { public void handleDeleteLoadBalancerRule(final LoadBalancer lb, final long userId, final Account caller) { final List remainingLbs = _loadBalancerDao.listByIpAddress(lb.getSourceIpAddressId()); if (remainingLbs.size() == 0) { - s_logger.debug("ELB mgr: releasing ip " + lb.getSourceIpAddressId() + " since no LB rules remain for this ip address"); + logger.debug("ELB mgr: releasing ip " + lb.getSourceIpAddressId() + " since no LB rules remain for this ip address"); releaseIp(lb.getSourceIpAddressId(), userId, caller); } } @@ -181,7 +182,7 @@ public LoadBalancer handleCreateLoadBalancerRule(final CreateLoadBalancerRuleCmd account = _accountDao.acquireInLockTable(account.getId()); if (account == null) { - s_logger.warn("ELB: CreateLoadBalancer: Failed to acquire lock on account"); + logger.warn("ELB: CreateLoadBalancer: Failed to acquire lock on account"); throw new CloudRuntimeException("Failed to acquire lock on account"); } try { @@ -202,19 +203,19 @@ private DomainRouterVO deployLoadBalancerVM(final Long networkId, final IPAddres params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true); final Account owner = _accountService.getActiveAccountByName("system", new Long(1)); final DeployDestination dest = new DeployDestination(dc, pod, null, null); - s_logger.debug("About to deploy ELB vm "); + logger.debug("About to deploy ELB vm "); try { final DomainRouterVO elbVm = deployELBVm(network, dest, owner, params); if (elbVm == null) { throw new InvalidParameterValueException("Could not deploy or find existing ELB VM"); } - s_logger.debug("Deployed ELB vm = " + elbVm); + logger.debug("Deployed ELB vm = " + elbVm); return elbVm; } catch (final Throwable t) { - s_logger.warn("Error while deploying ELB VM: ", t); + logger.warn("Error while deploying ELB VM: ", t); return null; } @@ -238,8 +239,8 @@ private DomainRouterVO deployELBVm(Network guestNetwork, final DeployDestination owner = _accountService.getSystemAccount(); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Starting a ELB vm for network configurations: " + guestNetwork + " in " + dest); + if (logger.isDebugEnabled()) { + logger.debug("Starting a ELB vm for network configurations: " + guestNetwork + " in " + dest); } assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork; @@ -251,8 +252,8 @@ private DomainRouterVO deployELBVm(Network guestNetwork, final DeployDestination if (elbVm == null) { final long id = _routerDao.getNextInSequence(Long.class, "id"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating the ELB vm " + id); + if (logger.isDebugEnabled()) { + logger.debug("Creating the ELB vm " + id); } final List offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork); @@ -309,7 +310,7 @@ private DomainRouterVO deployELBVm(Network guestNetwork, final DeployDestination } private void releaseIp(final long ipId, final long userId, final Account caller) { - s_logger.info("ELB: Release public IP for loadbalancing " + ipId); + logger.info("ELB: Release public IP for loadbalancing " + ipId); final IPAddressVO ipvo = _ipAddressDao.findById(ipId); ipvo.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipvo.getId(), ipvo); @@ -337,17 +338,17 @@ private LoadBalancer handleCreateLoadBalancerRuleWithLock(final CreateLoadBalanc if (lb.getSourceIpAddressId() != null) { throwExceptionIfSuppliedlLbNameIsNotAssociatedWithIpAddress(lb); } else { - s_logger.debug("Could not find any existing frontend ips for this account for this LB rule, acquiring a new frontent IP for ELB"); + logger.debug("Could not find any existing frontend ips for this account for this LB rule, acquiring a new frontent IP for ELB"); final PublicIp ip = allocDirectIp(account, networkId); ipId = ip.getId(); newIp = true; } } else { ipId = existingLbs.get(0).getSourceIpAddressId(); - s_logger.debug("ELB: Found existing frontend ip for this account for this LB rule " + ipId); + logger.debug("ELB: Found existing frontend ip for this account for this LB rule " + ipId); } } else { - s_logger.warn("ELB: Found existing load balancers matching requested new LB"); + logger.warn("ELB: Found existing load balancers matching requested new LB"); throw new NetworkRuleConflictException("ELB: Found existing load balancers matching requested new LB"); } @@ -360,7 +361,7 @@ private LoadBalancer handleCreateLoadBalancerRuleWithLock(final CreateLoadBalanc result = _lbMgr.createPublicLoadBalancer(lb.getXid(), lb.getName(), lb.getDescription(), lb.getSourcePortStart(), lb.getDefaultPortStart(), ipId.longValue(), lb.getProtocol(), lb.getAlgorithm(), false, CallContext.current(), lb.getLbProtocol(), true, null); } catch (final NetworkRuleConflictException e) { - s_logger.warn("Failed to create LB rule, not continuing with ELB deployment"); + logger.warn("Failed to create LB rule, not continuing with ELB deployment"); if (newIp) { releaseIp(ipId, CallContext.current().getCallingUserId(), account); } @@ -375,7 +376,7 @@ private LoadBalancer handleCreateLoadBalancerRuleWithLock(final CreateLoadBalanc elbVm = deployLoadBalancerVM(networkId, ipAddr); if (elbVm == null) { final Network network = _networkModel.getNetwork(networkId); - s_logger.warn("Failed to deploy a new ELB vm for ip " + ipAddr + " in network " + network + "lb name=" + lb.getName()); + logger.warn("Failed to deploy a new ELB vm for ip " + ipAddr + " in network " + network + "lb name=" + lb.getName()); if (newIp) { releaseIp(ipId, CallContext.current().getCallingUserId(), account); } @@ -390,8 +391,8 @@ private LoadBalancer handleCreateLoadBalancerRuleWithLock(final CreateLoadBalanc } if (elbVm == null) { - s_logger.warn("No ELB VM can be found or deployed"); - s_logger.warn("Deleting LB since we failed to deploy ELB VM"); + logger.warn("No ELB VM can be found or deployed"); + logger.warn("Deleting LB since we failed to deploy ELB VM"); _lbDao.remove(result.getId()); return null; } @@ -450,7 +451,7 @@ public PublicIp doInTransaction(final TransactionStatus status) throws Insuffici final IPAddressVO ipvo = _ipAddressDao.findById(ip.getId()); ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId()); _ipAddressDao.update(ipvo.getId(), ipvo); - s_logger.info("Acquired frontend IP for ELB " + ip); + logger.info("Acquired frontend IP for ELB " + ip); return ip; } @@ -476,7 +477,7 @@ protected static void addCandidateVmIsPodIpMatches(final DomainRouterVO candidat } protected DomainRouterVO start(final DomainRouterVO elbVm, final Map params) throws ConcurrentOperationException { - s_logger.debug("Starting ELB VM " + elbVm); + logger.debug("Starting ELB VM " + elbVm); _itMgr.start(elbVm.getUuid(), params); return _routerDao.findById(elbVm.getId()); } diff --git a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/dao/ElasticLbVmMapDao.java b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/dao/ElasticLbVmMapDao.java index 83aa6118a63d..eec7eaa4f5f1 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/dao/ElasticLbVmMapDao.java +++ b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/dao/ElasticLbVmMapDao.java @@ -40,4 +40,6 @@ public interface ElasticLbVmMapDao extends GenericDao { List listLbsForElbVm(long elbVmId); + int expungeByLbVmList(List vmIds, Long batchSize); + } diff --git a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/dao/ElasticLbVmMapDaoImpl.java b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/dao/ElasticLbVmMapDaoImpl.java index bbe79ef31030..ea1673967a59 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/dao/ElasticLbVmMapDaoImpl.java +++ b/plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/dao/ElasticLbVmMapDaoImpl.java @@ -21,6 +21,7 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import com.cloud.network.ElasticLbVmMapVO; @@ -136,4 +137,16 @@ public List listLbsForElbVm(long elbVmId) { return _loadbalancerDao.search(sc, null); } + @Override + public int expungeByLbVmList(List vmIds, Long batchSize) { + if (CollectionUtils.isEmpty(vmIds)) { + return 0; + } + SearchBuilder sb = createSearchBuilder(); + sb.and("vmIds", sb.entity().getElbVmId(), SearchCriteria.Op.IN); + SearchCriteria sc = sb.create(); + sc.setParameters("vmIds", vmIds.toArray()); + return batchExpunge(sc, batchSize); + } + } diff --git a/plugins/network-elements/elastic-loadbalancer/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/network-elements/elastic-loadbalancer/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/network-elements/elastic-loadbalancer/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/network-elements/globodns/pom.xml b/plugins/network-elements/globodns/pom.xml index 891c61441d13..c0200921f206 100644 --- a/plugins/network-elements/globodns/pom.xml +++ b/plugins/network-elements/globodns/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -32,5 +32,10 @@ com.globo.globodns globodns-client + + mysql + mysql-connector-java + test + diff --git a/plugins/network-elements/globodns/src/main/java/com/globo/globodns/cloudstack/element/GloboDnsElement.java b/plugins/network-elements/globodns/src/main/java/com/globo/globodns/cloudstack/element/GloboDnsElement.java index 28b2988cf6ab..09830d9a810f 100644 --- a/plugins/network-elements/globodns/src/main/java/com/globo/globodns/cloudstack/element/GloboDnsElement.java +++ b/plugins/network-elements/globodns/src/main/java/com/globo/globodns/cloudstack/element/GloboDnsElement.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -80,7 +79,6 @@ @Component public class GloboDnsElement extends AdapterBase implements ResourceStateAdapter, NetworkElement, GloboDnsElementService, Configurable { - private static final Logger s_logger = Logger.getLogger(GloboDnsElement.class); private static final Map> capabilities = setCapabilities(); @@ -132,7 +130,7 @@ public boolean prepare(final Network network, final NicProfile nic, final Virtua throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (!isTypeSupported(vm.getType())) { - s_logger.info("GloboDNS only manages records for VMs of type User, ConsoleProxy and DomainRouter. VM " + vm + " is " + vm.getType()); + logger.info("GloboDNS only manages records for VMs of type User, ConsoleProxy and DomainRouter. VM " + vm + " is " + vm.getType()); return false; } @@ -162,7 +160,7 @@ public boolean release(final Network network, NicProfile nic, final VirtualMachi ResourceUnavailableException { if (!isTypeSupported(vm.getType())) { - s_logger.info("GloboDNS only manages records for VMs of type User, ConsoleProxy and DomainRouter. VM " + vm + " is " + vm.getType()); + logger.info("GloboDNS only manages records for VMs of type User, ConsoleProxy and DomainRouter. VM " + vm + " is " + vm.getType()); return false; } diff --git a/plugins/network-elements/globodns/src/main/java/com/globo/globodns/cloudstack/resource/GloboDnsResource.java b/plugins/network-elements/globodns/src/main/java/com/globo/globodns/cloudstack/resource/GloboDnsResource.java index 84c1b5b44e57..9f399a92e0d9 100644 --- a/plugins/network-elements/globodns/src/main/java/com/globo/globodns/cloudstack/resource/GloboDnsResource.java +++ b/plugins/network-elements/globodns/src/main/java/com/globo/globodns/cloudstack/resource/GloboDnsResource.java @@ -21,7 +21,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -68,7 +67,6 @@ public class GloboDnsResource extends ManagerBase implements ServerResource { private static final String REVERSE_DOMAIN_SUFFIX = "in-addr.arpa"; private static final String DEFAULT_AUTHORITY_TYPE = "M"; - private static final Logger s_logger = Logger.getLogger(GloboDnsResource.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -125,7 +123,7 @@ public Type getType() { @Override public StartupCommand[] initialize() { - s_logger.trace("initialize called"); + logger.trace("initialize called"); StartupCommand cmd = new StartupCommand(getType()); cmd.setName(_name); cmd.setGuid(_guid); @@ -197,7 +195,7 @@ public Answer execute(RemoveDomainCommand cmd) { if (!cmd.isOverride()) { for (Record record : _globoDns.getRecordAPI().listAll(domain.getId())) { if (record.getTypeNSRecordAttributes().getId() == null) { - s_logger.warn("There are records in domain " + cmd.getNetworkDomain() + " and override is not enable. I will not delete this domain."); + logger.warn("There are records in domain " + cmd.getNetworkDomain() + " and override is not enable. I will not delete this domain."); return new Answer(cmd, true, "Domain keeped"); } } @@ -205,7 +203,7 @@ public Answer execute(RemoveDomainCommand cmd) { _globoDns.getDomainAPI().removeDomain(domain.getId()); scheduleExportChangesToBind(); } else { - s_logger.warn("Domain " + cmd.getNetworkDomain() + " already been deleted."); + logger.warn("Domain " + cmd.getNetworkDomain() + " already been deleted."); } return new Answer(cmd, true, "Domain removed"); @@ -246,7 +244,7 @@ public Answer execute(CreateOrUpdateRecordAndReverseCommand cmd) { Domain domain = searchDomain(cmd.getNetworkDomain(), false); if (domain == null) { domain = _globoDns.getDomainAPI().createDomain(cmd.getNetworkDomain(), cmd.getReverseTemplateId(), DEFAULT_AUTHORITY_TYPE); - s_logger.warn("Domain " + cmd.getNetworkDomain() + " doesn't exist, maybe someone removed it. It was automatically created with template " + logger.warn("Domain " + cmd.getNetworkDomain() + " doesn't exist, maybe someone removed it. It was automatically created with template " + cmd.getReverseTemplateId()); } @@ -287,7 +285,7 @@ protected boolean createOrUpdateReverse(String networkIp, String reverseRecordCo Domain reverseDomain = searchDomain(reverseDomainName, true); if (reverseDomain == null) { reverseDomain = _globoDns.getDomainAPI().createReverseDomain(reverseDomainName, templateId, DEFAULT_AUTHORITY_TYPE); - s_logger.info("Created reverse domain " + reverseDomainName + " with template " + templateId); + logger.info("Created reverse domain " + reverseDomainName + " with template " + templateId); } // create reverse @@ -303,14 +301,14 @@ public Answer execute(CreateOrUpdateDomainCommand cmd) { if (domain == null) { // create domain = _globoDns.getDomainAPI().createDomain(cmd.getDomainName(), cmd.getTemplateId(), DEFAULT_AUTHORITY_TYPE); - s_logger.info("Created domain " + cmd.getDomainName() + " with template " + cmd.getTemplateId()); + logger.info("Created domain " + cmd.getDomainName() + " with template " + cmd.getTemplateId()); if (domain == null) { return new Answer(cmd, false, "Unable to create domain " + cmd.getDomainName()); } else { needsExport = true; } } else { - s_logger.warn("Domain " + cmd.getDomainName() + " already exist."); + logger.warn("Domain " + cmd.getDomainName() + " already exist."); } return new Answer(cmd); } catch (GloboDnsException e) { @@ -331,16 +329,16 @@ public Answer execute(CreateOrUpdateDomainCommand cmd) { protected boolean removeRecord(String recordName, String recordValue, String bindZoneName, boolean reverse, boolean override) { Domain domain = searchDomain(bindZoneName, reverse); if (domain == null) { - s_logger.warn("Domain " + bindZoneName + " doesn't exists in GloboDNS. Record " + recordName + " has already been removed."); + logger.warn("Domain " + bindZoneName + " doesn't exists in GloboDNS. Record " + recordName + " has already been removed."); return false; } Record record = searchRecord(recordName, domain.getId()); if (record == null) { - s_logger.warn("Record " + recordName + " in domain " + bindZoneName + " has already been removed."); + logger.warn("Record " + recordName + " in domain " + bindZoneName + " has already been removed."); return false; } else { if (!override && !record.getContent().equals(recordValue)) { - s_logger.warn("Record " + recordName + " in domain " + bindZoneName + " have different value from " + recordValue + logger.warn("Record " + recordName + " in domain " + bindZoneName + " have different value from " + recordValue + " and override is not enable. I will not delete it."); return false; } @@ -363,7 +361,7 @@ private boolean createOrUpdateRecord(Long domainId, String name, String ip, Stri if (record == null) { // Create new record record = _globoDns.getRecordAPI().createRecord(domainId, name, ip, type); - s_logger.info("Created record " + record.getName() + " in domain " + domainId); + logger.info("Created record " + record.getName() + " in domain " + domainId); } else { if (!ip.equals(record.getContent())) { if (Boolean.TRUE.equals(override)) { @@ -384,10 +382,10 @@ public void scheduleExportChangesToBind() { try { Export export = _globoDns.getExportAPI().scheduleExport(); if (export != null) { - s_logger.info("GloboDns Export: " + export.getResult()); + logger.info("GloboDns Export: " + export.getResult()); } } catch (GloboDnsException e) { - s_logger.warn("Error on scheduling export. Although everything was persist, someone need to manually force export in GloboDns", e); + logger.warn("Error on scheduling export. Although everything was persist, someone need to manually force export in GloboDns", e); } } @@ -428,11 +426,11 @@ private Record searchRecord(String recordName, Long domainId) { // GloboDns search name in name and content. We need to iterate to check if recordName exists only in name for (Record candidate : candidates) { if (recordName.equalsIgnoreCase(candidate.getName())) { - s_logger.debug("Record " + recordName + " in domain id " + domainId + " found in GloboDNS"); + logger.debug("Record " + recordName + " in domain id " + domainId + " found in GloboDNS"); return candidate; } } - s_logger.debug("Record " + recordName + " in domain id " + domainId + " not found in GloboDNS"); + logger.debug("Record " + recordName + " in domain id " + domainId + " not found in GloboDNS"); return null; } diff --git a/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/element/GloboDnsElementTest.java b/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/element/GloboDnsElementTest.java index 23a3bd6c70fc..77a737a35cfe 100644 --- a/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/element/GloboDnsElementTest.java +++ b/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/element/GloboDnsElementTest.java @@ -16,8 +16,8 @@ */ package com.globo.globodns.cloudstack.element; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/resource/GloboDnsResourceTest.java b/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/resource/GloboDnsResourceTest.java index d89d7e7f4637..74b270d61d33 100644 --- a/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/resource/GloboDnsResourceTest.java +++ b/plugins/network-elements/globodns/src/test/java/com/globo/globodns/cloudstack/resource/GloboDnsResourceTest.java @@ -18,7 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.Mockito.spy; diff --git a/plugins/network-elements/internal-loadbalancer/pom.xml b/plugins/network-elements/internal-loadbalancer/pom.xml index bf2b9f0a13c0..f3126a8e024b 100644 --- a/plugins/network-elements/internal-loadbalancer/pom.xml +++ b/plugins/network-elements/internal-loadbalancer/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java b/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java index 3e522f6be4f5..0a9b4a7131a3 100644 --- a/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java +++ b/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java @@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd; import org.apache.cloudstack.api.command.admin.internallb.CreateInternalLoadBalancerElementCmd; @@ -84,9 +83,10 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.network.router.NetworkHelper; +import org.springframework.stereotype.Component; +@Component public class InternalLoadBalancerElement extends AdapterBase implements LoadBalancingServiceProvider, InternalLoadBalancerElementService, IpDeployer { - private static final Logger s_logger = Logger.getLogger(InternalLoadBalancerElement.class); protected static final Map> capabilities = setCapabilities(); private static InternalLoadBalancerElement internalLbElement = null; @@ -114,25 +114,18 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala @Qualifier("networkHelper") protected NetworkHelper _networkHelper; - protected InternalLoadBalancerElement() { - } - - public static InternalLoadBalancerElement getInstance() { - if (internalLbElement == null) { - internalLbElement = new InternalLoadBalancerElement(); - } - return internalLbElement; + public InternalLoadBalancerElement() { } private boolean canHandle(Network config, Scheme lbScheme) { //works in Advance zone only DataCenter dc = _entityMgr.findById(DataCenter.class, config.getDataCenterId()); if (dc.getNetworkType() != NetworkType.Advanced) { - s_logger.trace("Not hanling zone of network type " + dc.getNetworkType()); + logger.trace("Not hanling zone of network type " + dc.getNetworkType()); return false; } if (config.getGuestType() != Network.GuestType.Isolated || config.getTrafficType() != TrafficType.Guest) { - s_logger.trace("Not handling network with Type " + config.getGuestType() + " and traffic type " + config.getTrafficType()); + logger.trace("Not handling network with Type " + config.getGuestType() + " and traffic type " + config.getTrafficType()); return false; } @@ -141,14 +134,14 @@ private boolean canHandle(Network config, Scheme lbScheme) { String schemeCaps = lbCaps.get(Capability.LbSchemes); if (schemeCaps != null && lbScheme != null) { if (!schemeCaps.contains(lbScheme.toString())) { - s_logger.debug("Scheme " + lbScheme.toString() + " is not supported by the provider " + getName()); + logger.debug("Scheme " + lbScheme.toString() + " is not supported by the provider " + getName()); return false; } } } if (!_ntwkModel.isProviderSupportServiceInNetwork(config.getId(), Service.Lb, getProvider())) { - s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + Service.Lb + " in the network " + config); + logger.trace("Element " + getProvider().getName() + " doesn't support service " + Service.Lb + " in the network " + config); return false; } return true; @@ -169,7 +162,7 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin ResourceUnavailableException, InsufficientCapacityException { if (!canHandle(network, null)) { - s_logger.trace("No need to implement " + getName()); + logger.trace("No need to implement " + getName()); return true; } @@ -181,7 +174,7 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (!canHandle(network, null)) { - s_logger.trace("No need to prepare " + getName()); + logger.trace("No need to prepare " + getName()); return true; } @@ -200,16 +193,16 @@ protected boolean implementInternalLbVms(Network network, DeployDestination dest Ip sourceIp = new Ip(ip); long active = _appLbDao.countActiveBySourceIp(sourceIp, network.getId()); if (active > 0) { - s_logger.debug("Have to implement internal lb vm for source ip " + sourceIp + " as a part of network " + network + " implement as there are " + active + + logger.debug("Have to implement internal lb vm for source ip " + sourceIp + " as a part of network " + network + " implement as there are " + active + " internal lb rules exist for this ip"); List internalLbVms; try { internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null); } catch (InsufficientCapacityException e) { - s_logger.warn("Failed to deploy element " + getName() + " for ip " + sourceIp + " due to:", e); + logger.warn("Failed to deploy element " + getName() + " for ip " + sourceIp + " due to:", e); return false; } catch (ConcurrentOperationException e) { - s_logger.warn("Failed to deploy element " + getName() + " for ip " + sourceIp + " due to:", e); + logger.warn("Failed to deploy element " + getName() + " for ip " + sourceIp + " due to:", e); return false; } @@ -239,11 +232,11 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle result = result && _internalLbMgr.destroyInternalLbVm(internalLbVm.getId(), context.getAccount(), context.getCaller().getId()); if (cleanup) { if (!result) { - s_logger.warn("Failed to stop internal lb element " + internalLbVm + ", but would try to process clean up anyway."); + logger.warn("Failed to stop internal lb element " + internalLbVm + ", but would try to process clean up anyway."); } result = (_internalLbMgr.destroyInternalLbVm(internalLbVm.getId(), context.getAccount(), context.getCaller().getId())); if (!result) { - s_logger.warn("Failed to clean up internal lb element " + internalLbVm); + logger.warn("Failed to clean up internal lb element " + internalLbVm); } } } @@ -312,7 +305,7 @@ public boolean applyLBRules(Network network, List rules) thro //2) Get rules to apply Map> rulesToApply = getLbRulesToApply(rules); - s_logger.debug("Applying " + rulesToApply.size() + " on element " + getName()); + logger.debug("Applying " + rulesToApply.size() + " on element " + getName()); for (Ip sourceIp : vmsToDestroy) { //2.1 Destroy internal lb vm @@ -320,11 +313,11 @@ public boolean applyLBRules(Network network, List rules) thro if (vms.size() > 0) { //only one internal lb per IP exists try { - s_logger.debug(String.format("Destroying internal lb vm for ip %s as all the rules for this vm are in Revoke state", sourceIp.addr())); + logger.debug(String.format("Destroying internal lb vm for ip %s as all the rules for this vm are in Revoke state", sourceIp.addr())); return _internalLbMgr.destroyInternalLbVm(vms.get(0).getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), _accountMgr.getUserIncludingRemoved(User.UID_SYSTEM).getId()); } catch (ConcurrentOperationException e) { - s_logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e); + logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e); return false; } } @@ -340,10 +333,10 @@ public boolean applyLBRules(Network network, List rules) thro DeployDestination dest = new DeployDestination(_entityMgr.findById(DataCenter.class, network.getDataCenterId()), null, null, null); internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest, _accountMgr.getAccount(network.getAccountId()), null); } catch (InsufficientCapacityException e) { - s_logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e); + logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e); return false; } catch (ConcurrentOperationException e) { - s_logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e); + logger.warn(String.format("Failed to apply lb rule(s) for ip %s on the element %s due to: ", sourceIp.addr(), getName()), e); return false; } @@ -381,7 +374,7 @@ protected Set getVmsToDestroy(Network network, List rules for (Ip sourceIp : lbPublicIps) { //2) Check if there are non revoked rules for the source ip address if (_appLbDao.countBySourceIpAndNotRevoked(sourceIp, network.getId()) == 0) { - s_logger.debug("Have to destroy internal lb vm for source ip " + sourceIp + " as it has 0 rules in non-Revoke state"); + logger.debug("Have to destroy internal lb vm for source ip " + sourceIp + " as it has 0 rules in non-Revoke state"); vmsToDestroy.add(sourceIp); } } @@ -404,7 +397,7 @@ protected Map> groupBySourceIp(List searchForInternalLoadBalancerElemen return sc.list(); } + @Override + public Type getProviderType() { + return Type.InternalLbVm; + } + @Override public boolean applyIps(Network network, List ipAddress, Set services) throws ResourceUnavailableException { //do nothing here; this element just has to extend the ip deployer diff --git a/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManager.java b/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManager.java index 339b0c1c3f38..8332c8be9355 100644 --- a/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManager.java +++ b/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManager.java @@ -32,7 +32,7 @@ public interface InternalLoadBalancerVMManager { //RAM/CPU for the system offering used by Internal LB VMs - public static final int DEFAULT_INTERNALLB_VM_RAMSIZE = 256; // 256 MB + public static final int DEFAULT_INTERNALLB_VM_RAMSIZE = 512; // 512 MB public static final int DEFAULT_INTERNALLB_VM_CPU_MHZ = 256; // 256 MHz /** diff --git a/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java b/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java index a53f27188aab..9a5c5a7c6a99 100644 --- a/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java +++ b/plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO; import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -119,8 +118,13 @@ import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.Hyperv; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.KVM; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.LXC; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.VMware; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.XenServer; + public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements InternalLoadBalancerVMManager, InternalLoadBalancerVMService, VirtualMachineGuru { - private static final Logger s_logger = Logger.getLogger(InternalLoadBalancerVMManagerImpl.class); static final private String InternalLbVmNamePrefix = "b"; private String _instance; @@ -204,14 +208,14 @@ public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile } else if (nic.getTrafficType() == TrafficType.Control) { controlNic = nic; // Internal LB control command is sent over management server in VMware - if (dest.getHost().getHypervisorType() == HypervisorType.VMware) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Check if we need to add management server explicit route to Internal LB. pod cidr: " + dest.getPod().getCidrAddress() + "/" + + if (dest.getHost().getHypervisorType() == VMware) { + if (logger.isInfoEnabled()) { + logger.info("Check if we need to add management server explicit route to Internal LB. pod cidr: " + dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize() + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + _mgmtHost); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Add management server explicit route to Internal LB."); + if (logger.isInfoEnabled()) { + logger.info("Add management server explicit route to Internal LB."); } buf.append(" mgmtcidr=").append(_mgmtCidr); @@ -236,8 +240,8 @@ public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile final String type = "ilbvm"; buf.append(" type=" + type); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Boot Args for " + profile + ": " + buf.toString()); } return true; @@ -272,7 +276,7 @@ public boolean finalizeStart(final VirtualMachineProfile profile, final long hos if (answer != null && answer instanceof CheckSshAnswer) { final CheckSshAnswer sshAnswer = (CheckSshAnswer)answer; if (sshAnswer == null || !sshAnswer.getResult()) { - s_logger.warn("Unable to ssh to the internal LB VM: " + sshAnswer.getDetails()); + logger.warn("Unable to ssh to the internal LB VM: " + sshAnswer.getDetails()); result = false; } } else { @@ -296,7 +300,7 @@ public boolean finalizeStart(final VirtualMachineProfile profile, final long hos if (answer != null && answer instanceof GetDomRVersionAnswer) { final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer; if (answer == null || !answer.getResult()) { - s_logger.warn("Unable to get the template/scripts version of internal LB VM " + internalLbVm.getInstanceName() + " due to: " + versionAnswer.getDetails()); + logger.warn("Unable to get the template/scripts version of internal LB VM " + internalLbVm.getInstanceName() + " due to: " + versionAnswer.getDetails()); result = false; } else { internalLbVm.setTemplateVersion(versionAnswer.getTemplateVersion()); @@ -316,7 +320,7 @@ public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachine final NicProfile controlNic = getNicProfileByTrafficType(profile, TrafficType.Control); if (controlNic == null) { - s_logger.error("Control network doesn't exist for the internal LB vm " + internalLbVm); + logger.error("Control network doesn't exist for the internal LB vm " + internalLbVm); return false; } @@ -380,7 +384,7 @@ public boolean configure(final String name, final Map params) th if (off != null) { _internalLbVmOfferingId = off.getId(); } else { - s_logger.warn("Invalid offering UUID is passed in " + Config.InternalLbVmServiceOfferingId.key() + "; the default offering will be used instead"); + logger.warn("Invalid offering UUID is passed in " + Config.InternalLbVmServiceOfferingId.key() + "; the default offering will be used instead"); } } @@ -392,15 +396,15 @@ public boolean configure(final String name, final Map params) th Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.InternalLoadBalancerVm, true); if (offerings == null || offerings.size() < 2) { String msg = "Data integrity problem : System Offering For Internal LB VM has been removed?"; - s_logger.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } } _itMgr.registerGuru(VirtualMachine.Type.InternalLoadBalancerVm, this); - if (s_logger.isInfoEnabled()) { - s_logger.info(getName() + " has been configured"); + if (logger.isInfoEnabled()) { + logger.info(getName() + " has been configured"); } return true; @@ -431,7 +435,7 @@ protected void finalizeSshAndVersionOnStart(final Commands cmds, final VirtualMa } protected void finalizeLbRulesForIp(final Commands cmds, final DomainRouterVO internalLbVm, final Provider provider, final Ip sourceIp, final long guestNtwkId) { - s_logger.debug("Resending load balancing rules as a part of start for " + internalLbVm); + logger.debug("Resending load balancing rules as a part of start for " + internalLbVm); final List lbs = _lbDao.listBySrcIpSrcNtwkId(sourceIp, guestNtwkId); final List lbRules = new ArrayList(); if (_ntwkModel.isProviderSupportServiceInNetwork(guestNtwkId, Service.Lb, provider)) { @@ -445,7 +449,7 @@ protected void finalizeLbRulesForIp(final Commands cmds, final DomainRouterVO in } } - s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of Intenrnal LB vm" + internalLbVm + " start."); + logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of Intenrnal LB vm" + internalLbVm + " start."); if (!lbRules.isEmpty()) { createApplyLoadBalancingRulesCommands(lbRules, internalLbVm, cmds, guestNtwkId); } @@ -513,7 +517,7 @@ protected String getInternalLbControlIp(final long internalLbVmId) { } if (controlIpAddress == null) { - s_logger.warn("Unable to find Internal LB control ip in its attached NICs!. Internal LB vm: " + internalLbVmId); + logger.warn("Unable to find Internal LB control ip in its attached NICs!. Internal LB vm: " + internalLbVmId); final DomainRouterVO internalLbVm = _internalLbVmDao.findById(internalLbVmId); return internalLbVm.getPrivateIpAddress(); } @@ -523,8 +527,8 @@ protected String getInternalLbControlIp(final long internalLbVmId) { @Override public boolean destroyInternalLbVm(final long vmId, final Account caller, final Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Attempting to destroy Internal LB vm " + vmId); + if (logger.isDebugEnabled()) { + logger.debug("Attempting to destroy Internal LB vm " + vmId); } final DomainRouterVO internalLbVm = _internalLbVmDao.findById(vmId); @@ -554,7 +558,7 @@ public VirtualRouter stopInternalLbVm(final long vmId, final boolean forced, fin protected VirtualRouter stopInternalLbVm(final DomainRouterVO internalLbVm, final boolean forced, final Account caller, final long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException { - s_logger.debug("Stopping internal lb vm " + internalLbVm); + logger.debug("Stopping internal lb vm " + internalLbVm); try { _itMgr.advanceStop(internalLbVm.getUuid(), forced); return _internalLbVmDao.findById(internalLbVm.getId()); @@ -579,7 +583,7 @@ protected List startInternalLbVms(final Map param if (internalLbVms != null) { runningInternalLbVms = new ArrayList(); } else { - s_logger.debug("Have no internal lb vms to start"); + logger.debug("Have no internal lb vms to start"); return null; } @@ -605,8 +609,8 @@ protected List findOrDeployInternalLbVm(final Network guestNetwo throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Lock is acquired for network id " + lock.getId() + " as a part of internal lb startup in " + dest); + if (logger.isDebugEnabled()) { + logger.debug("Lock is acquired for network id " + lock.getId() + " as a part of internal lb startup in " + dest); } final long internalLbProviderId = getInternalLbProviderId(guestNetwork); @@ -622,7 +626,7 @@ protected List findOrDeployInternalLbVm(final Network guestNetwo final DeploymentPlan plan = planAndInternalLbVms.first(); if (internalLbVms.size() > 0) { - s_logger.debug("Found " + internalLbVms.size() + " internal lb vms for the requested IP " + requestedGuestIp.addr()); + logger.debug("Found " + internalLbVms.size() + " internal lb vms for the requested IP " + requestedGuestIp.addr()); return internalLbVms; } @@ -642,8 +646,8 @@ protected List findOrDeployInternalLbVm(final Network guestNetwo } finally { if (lock != null) { _networkDao.releaseFromLockTable(lock.getId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Lock is released for network id " + lock.getId() + " as a part of internal lb vm startup in " + dest); + if (logger.isDebugEnabled()) { + logger.debug("Lock is released for network id " + lock.getId() + " as a part of internal lb vm startup in " + dest); } } } @@ -675,7 +679,7 @@ protected LinkedHashMap> createInternalLbVmN //1) Guest network - default if (guestNetwork != null) { - s_logger.debug("Adding nic for Internal LB in Guest network " + guestNetwork); + logger.debug("Adding nic for Internal LB in Guest network " + guestNetwork); final NicProfile guestNic = new NicProfile(); if (guestIp != null) { guestNic.setIPv4Address(guestIp.addr()); @@ -694,7 +698,7 @@ protected LinkedHashMap> createInternalLbVmN } //2) Control network - s_logger.debug("Adding nic for Internal LB vm in Control network "); + logger.debug("Adding nic for Internal LB vm in Control network "); final List offerings = _ntwkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork); final NetworkOffering controlOffering = offerings.get(0); final Network controlConfig = _ntwkMgr.setupNetwork(_accountMgr.getSystemAccount(), controlOffering, plan, null, null, false).get(0); @@ -746,33 +750,25 @@ protected DomainRouterVO deployInternalLbVm(final Account owner, final DeployDes final HypervisorType hType = iter.next(); try { final long id = _internalLbVmDao.getNextInSequence(Long.class, "id"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating the internal lb vm " + id + " in datacenter " + dest.getDataCenter() + " with hypervisor type " + hType); + if (logger.isDebugEnabled()) { + logger.debug("Creating the internal lb vm " + id + " in datacenter " + dest.getDataCenter() + " with hypervisor type " + hType); } String templateName = null; - switch (hType) { - case XenServer: + if (hType.equals(XenServer)) { templateName = VirtualNetworkApplianceManager.RouterTemplateXen.valueIn(dest.getDataCenter().getId()); - break; - case KVM: + } else if (hType.equals(KVM)) { templateName = VirtualNetworkApplianceManager.RouterTemplateKvm.valueIn(dest.getDataCenter().getId()); - break; - case VMware: + } else if (hType.equals(VMware)) { templateName = VirtualNetworkApplianceManager.RouterTemplateVmware.valueIn(dest.getDataCenter().getId()); - break; - case Hyperv: + } else if (hType.equals(Hyperv)) { templateName = VirtualNetworkApplianceManager.RouterTemplateHyperV.valueIn(dest.getDataCenter().getId()); - break; - case LXC: + } else if (hType.equals(LXC)) { templateName = VirtualNetworkApplianceManager.RouterTemplateLxc.valueIn(dest.getDataCenter().getId()); - break; - default: - break; } final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName); if (template == null) { - s_logger.debug(hType + " won't support system vm, skip it"); + logger.debug(hType + " won't support system vm, skip it"); continue; } @@ -793,7 +789,7 @@ protected DomainRouterVO deployInternalLbVm(final Account owner, final DeployDes internalLbVm = _internalLbVmDao.findById(internalLbVm.getId()); } catch (final InsufficientCapacityException ex) { if (allocateRetry < 2 && iter.hasNext()) { - s_logger.debug("Failed to allocate the Internal lb vm with hypervisor type " + hType + ", retrying one more time"); + logger.debug("Failed to allocate the Internal lb vm with hypervisor type " + hType + ", retrying one more time"); continue; } else { throw ex; @@ -808,7 +804,7 @@ protected DomainRouterVO deployInternalLbVm(final Account owner, final DeployDes break; } catch (final InsufficientCapacityException ex) { if (startRetry < 2 && iter.hasNext()) { - s_logger.debug("Failed to start the Internal lb vm " + internalLbVm + " with hypervisor type " + hType + ", " + + logger.debug("Failed to start the Internal lb vm " + internalLbVm + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time"); // destroy the internal lb vm destroyInternalLbVm(internalLbVm.getId(), _accountMgr.getSystemAccount(), User.UID_SYSTEM); @@ -829,10 +825,10 @@ protected DomainRouterVO deployInternalLbVm(final Account owner, final DeployDes protected DomainRouterVO startInternalLbVm(DomainRouterVO internalLbVm, final Account caller, final long callerUserId, final Map params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { - s_logger.debug("Starting Internal LB VM " + internalLbVm); + logger.debug("Starting Internal LB VM " + internalLbVm); _itMgr.start(internalLbVm.getUuid(), params, null, null); if (internalLbVm.isStopPending()) { - s_logger.info("Clear the stop pending flag of Internal LB VM " + internalLbVm.getHostName() + " after start router successfully!"); + logger.info("Clear the stop pending flag of Internal LB VM " + internalLbVm.getHostName() + " after start router successfully!"); internalLbVm.setStopPending(false); internalLbVm = _internalLbVmDao.persist(internalLbVm); } @@ -871,10 +867,10 @@ protected List getHypervisors(final DeployDestination dest, fina public boolean applyLoadBalancingRules(final Network network, final List rules, final List internalLbVms) throws ResourceUnavailableException { if (rules == null || rules.isEmpty()) { - s_logger.debug("No lb rules to be applied for network " + network); + logger.debug("No lb rules to be applied for network " + network); return true; } - s_logger.info("lb rules to be applied for network "); + logger.info("lb rules to be applied for network "); //only one internal lb vm is supported per ip address at this time if (internalLbVms == null || internalLbVms.isEmpty()) { throw new CloudRuntimeException("Can't apply the lb rules on network " + network + " as the list of internal lb vms is empty"); @@ -884,10 +880,10 @@ public boolean applyLoadBalancingRules(final Network network, final List - + diff --git a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java index 7bb4db1bb80f..8643ea4ac74a 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java +++ b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java @@ -26,7 +26,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -86,7 +86,7 @@ public void setUp() { Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider); Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider); - Mockito.when(_vrProviderDao.persist(Matchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement); + Mockito.when(_vrProviderDao.persist(ArgumentMatchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement); } //TESTS FOR getInternalLoadBalancerElement METHOD diff --git a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementTest.java b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementTest.java index 28a78960cdfe..79482418ad0c 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementTest.java +++ b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbelement/InternalLbElementTest.java @@ -31,7 +31,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -116,10 +116,10 @@ public void setUp() { Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider); Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider); - Mockito.when(_vrProviderDao.persist(Matchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement); + Mockito.when(_vrProviderDao.persist(ArgumentMatchers.any(VirtualRouterProviderVO.class))).thenReturn(validElement); DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null); - Mockito.when(_entityMgr.findById(Matchers.eq(DataCenter.class), Matchers.anyLong())).thenReturn(dc); + Mockito.when(_entityMgr.findById(ArgumentMatchers.eq(DataCenter.class), ArgumentMatchers.anyLong())).thenReturn(dc); } //TEST FOR getProvider() method diff --git a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java index 62fd2dd2845d..1550649f847a 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java +++ b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java @@ -31,7 +31,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -164,15 +164,15 @@ public void setUp() { } createNetwork(); - Mockito.when(_ntwkModel.getNetwork(Matchers.anyLong())).thenReturn(ntwk); + Mockito.when(_ntwkModel.getNetwork(ArgumentMatchers.anyLong())).thenReturn(ntwk); - Mockito.when(_itMgr.toNicTO(Matchers.any(NicProfile.class), Matchers.any(HypervisorType.class))).thenReturn(null); - Mockito.when(_domainRouterDao.findById(Matchers.anyLong())).thenReturn(vm); + Mockito.when(_itMgr.toNicTO(ArgumentMatchers.any(NicProfile.class), ArgumentMatchers.any(HypervisorType.class))).thenReturn(null); + Mockito.when(_domainRouterDao.findById(ArgumentMatchers.anyLong())).thenReturn(vm); final DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null); - Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc); + Mockito.when(_dcDao.findById(ArgumentMatchers.anyLong())).thenReturn(dc); final NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO(); networkOfferingVO.setConcurrentConnections(500); - Mockito.when(_offeringDao.findById(Matchers.anyLong())).thenReturn(networkOfferingVO); + Mockito.when(_offeringDao.findById(ArgumentMatchers.anyLong())).thenReturn(networkOfferingVO); Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm); Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null); diff --git a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java index 9141190df1f9..afd75da50e18 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java +++ b/plugins/network-elements/internal-loadbalancer/src/test/java/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java @@ -30,7 +30,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -105,7 +105,7 @@ public void setUp() { Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1)); Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2)); - Mockito.when(_accountDao.findByIdIncludingRemoved(Matchers.anyLong())).thenReturn(new AccountVO(2)); + Mockito.when(_accountDao.findByIdIncludingRemoved(ArgumentMatchers.anyLong())).thenReturn(new AccountVO(2)); CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); final DomainRouterVO validVm = diff --git a/plugins/network-elements/internal-loadbalancer/src/test/resources/lb_element.xml b/plugins/network-elements/internal-loadbalancer/src/test/resources/lb_element.xml index 0529392384e1..0f7cecb35c87 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/resources/lb_element.xml +++ b/plugins/network-elements/internal-loadbalancer/src/test/resources/lb_element.xml @@ -1,19 +1,19 @@ - @@ -46,5 +46,5 @@ - + diff --git a/plugins/network-elements/internal-loadbalancer/src/test/resources/lb_svc.xml b/plugins/network-elements/internal-loadbalancer/src/test/resources/lb_svc.xml index b104f0b9288d..b87d26cd91ae 100644 --- a/plugins/network-elements/internal-loadbalancer/src/test/resources/lb_svc.xml +++ b/plugins/network-elements/internal-loadbalancer/src/test/resources/lb_svc.xml @@ -1,19 +1,19 @@ - @@ -44,7 +44,7 @@ - + - + diff --git a/plugins/network-elements/juniper-contrail/pom.xml b/plugins/network-elements/juniper-contrail/pom.xml index f2c82115b121..3f71146d5802 100644 --- a/plugins/network-elements/juniper-contrail/pom.xml +++ b/plugins/network-elements/juniper-contrail/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -113,6 +113,10 @@ + + ch.qos.reload4j + reload4j + com.mysql mysql-connector-j diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java index 4771441e9e7c..44cbc6c305f0 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailElementImpl.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.network.contrail.model.VMInterfaceModel; import org.apache.cloudstack.network.contrail.model.VirtualMachineModel; import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.deploy.DeployDestination; @@ -65,10 +64,11 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.NicDao; + @Component public class ContrailElementImpl extends AdapterBase - implements ContrailElement, StaticNatServiceProvider, IpDeployer, SourceNatServiceProvider, DhcpServiceProvider { + implements ContrailElement, StaticNatServiceProvider, IpDeployer, SourceNatServiceProvider, DhcpServiceProvider { private final Map> _capabilities = InitCapabilities(); @Inject @@ -83,7 +83,6 @@ public class ContrailElementImpl extends AdapterBase NicDao _nicDao; @Inject ServerDBSync _dbSync; - private static final Logger s_logger = Logger.getLogger(ContrailElement.class); // PluggableService @Override @@ -119,10 +118,10 @@ public Map> getCapabilities() { */ @Override public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException { - s_logger.debug("NetworkElement implement: " + network.getName() + ", traffic type: " + network.getTrafficType()); + ResourceUnavailableException, InsufficientCapacityException { + logger.debug("NetworkElement implement: " + network.getName() + ", traffic type: " + network.getTrafficType()); if (network.getTrafficType() == TrafficType.Guest) { - s_logger.debug("ignore network " + network.getName()); + logger.debug("ignore network " + network.getName()); return true; } VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType()); @@ -137,23 +136,23 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin } _manager.getDatabase().getVirtualNetworks().add(vnModel); } catch (Exception ex) { - s_logger.warn("virtual-network update: ", ex); + logger.warn("virtual-network update: ", ex); } return true; } @Override public boolean prepare(Network network, NicProfile nicProfile, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) - throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - s_logger.debug("NetworkElement prepare: " + network.getName() + ", traffic type: " + network.getTrafficType()); + logger.debug("NetworkElement prepare: " + network.getName() + ", traffic type: " + network.getTrafficType()); if (network.getTrafficType() == TrafficType.Guest) { - s_logger.debug("ignore network " + network.getName()); + logger.debug("ignore network " + network.getName()); return true; } - s_logger.debug("network: " + network.getId()); + logger.debug("network: " + network.getId()); VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType()); @@ -183,7 +182,7 @@ public boolean prepare(Network network, NicProfile nicProfile, VirtualMachinePro try { vmiModel.build(_manager.getModelController(), (VMInstanceVO)vm.getVirtualMachine(), nic); } catch (IOException ex) { - s_logger.warn("vm interface set", ex); + logger.warn("vm interface set", ex); return false; } @@ -197,7 +196,7 @@ public boolean prepare(Network network, NicProfile nicProfile, VirtualMachinePro try { vmModel.update(_manager.getModelController()); } catch (Exception ex) { - s_logger.warn("virtual-machine-update", ex); + logger.warn("virtual-machine-update", ex); return false; } _manager.getDatabase().getVirtualMachines().add(vmModel); @@ -207,11 +206,11 @@ public boolean prepare(Network network, NicProfile nicProfile, VirtualMachinePro @Override public boolean release(Network network, NicProfile nicProfile, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, - ResourceUnavailableException { + ResourceUnavailableException { if (network.getTrafficType() == TrafficType.Guest) { return true; } else if (!_manager.isManagedPhysicalNetwork(network)) { - s_logger.debug("release ignore network " + network.getId()); + logger.debug("release ignore network " + network.getId()); return true; } @@ -220,7 +219,7 @@ public boolean release(Network network, NicProfile nicProfile, VirtualMachinePro VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid()); if (vmModel == null) { - s_logger.debug("vm " + vm.getInstanceName() + " not in local database"); + logger.debug("vm " + vm.getInstanceName() + " not in local database"); return true; } VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid()); @@ -228,7 +227,7 @@ public boolean release(Network network, NicProfile nicProfile, VirtualMachinePro try { vmiModel.destroy(_manager.getModelController()); } catch (IOException ex) { - s_logger.warn("virtual-machine-interface delete", ex); + logger.warn("virtual-machine-interface delete", ex); } vmModel.removeSuccessor(vmiModel); } @@ -250,7 +249,7 @@ public boolean release(Network network, NicProfile nicProfile, VirtualMachinePro */ @Override public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { - s_logger.debug("NetworkElement shutdown"); + logger.debug("NetworkElement shutdown"); return true; } @@ -259,45 +258,45 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle */ @Override public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - s_logger.debug("NetworkElement destroy"); + logger.debug("NetworkElement destroy"); return true; } @Override public boolean isReady(PhysicalNetworkServiceProvider provider) { - Map serviceMap = ((ConfigurationServerImpl)_configServer).getServicesAndProvidersForNetwork( _manager.getRouterOffering().getId()); - List types = new ArrayList(); - types.add(TrafficType.Control); - types.add(TrafficType.Management); - types.add(TrafficType.Storage); - List systemNets = _manager.findSystemNetworks(types); - if (systemNets != null && !systemNets.isEmpty()) { - for (NetworkVO net: systemNets) { - s_logger.debug("update system network service: " + net.getName() + "; service provider: " + serviceMap); - _networksDao.update(net.getId(), net, serviceMap); - } - } else { - s_logger.debug("no system networks created yet"); - } - serviceMap = ((ConfigurationServerImpl)_configServer).getServicesAndProvidersForNetwork( _manager.getPublicRouterOffering().getId()); - types = new ArrayList(); - types.add(TrafficType.Public); - systemNets = _manager.findSystemNetworks(types); - if (systemNets != null && !systemNets.isEmpty()) { - for (NetworkVO net: systemNets) { - s_logger.debug("update system network service: " + net.getName() + "; service provider: " + serviceMap); - _networksDao.update(net.getId(), net, serviceMap); - } - } else { - s_logger.debug("no system networks created yet"); - } - return true; - } + Map serviceMap = ((ConfigurationServerImpl)_configServer).getServicesAndProvidersForNetwork( _manager.getRouterOffering().getId()); + List types = new ArrayList(); + types.add(TrafficType.Control); + types.add(TrafficType.Management); + types.add(TrafficType.Storage); + List systemNets = _manager.findSystemNetworks(types); + if (systemNets != null && !systemNets.isEmpty()) { + for (NetworkVO net: systemNets) { + logger.debug("update system network service: " + net.getName() + "; service provider: " + serviceMap); + _networksDao.update(net.getId(), net, serviceMap); + } + } else { + logger.debug("no system networks created yet"); + } + serviceMap = ((ConfigurationServerImpl)_configServer).getServicesAndProvidersForNetwork( _manager.getPublicRouterOffering().getId()); + types = new ArrayList(); + types.add(TrafficType.Public); + systemNets = _manager.findSystemNetworks(types); + if (systemNets != null && !systemNets.isEmpty()) { + for (NetworkVO net: systemNets) { + logger.debug("update system network service: " + net.getName() + "; service provider: " + serviceMap); + _networksDao.update(net.getId(), net, serviceMap); + } + } else { + logger.debug("no system networks created yet"); + } + return true; + } @Override public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, - ResourceUnavailableException { - s_logger.debug("NetworkElement shutdown ProviderInstances"); + ResourceUnavailableException { + logger.debug("NetworkElement shutdown ProviderInstances"); return true; } @@ -309,8 +308,8 @@ public boolean canEnableIndividualServices() { @Override public boolean verifyServicesCombination(Set services) { // TODO Auto-generated method stub - s_logger.debug("NetworkElement verifyServices"); - s_logger.debug("Services: " + services); + logger.debug("NetworkElement verifyServices"); + logger.debug("Services: " + services); return true; } @@ -328,11 +327,11 @@ public boolean applyIps(Network network, List ipAddre } if (isFloatingIpCreate(ip)) { if (_manager.createFloatingIp(ip)) { - s_logger.debug("Successfully created floating ip: " + ip.getAddress().addr()); + logger.debug("Successfully created floating ip: " + ip.getAddress().addr()); } } else { if (_manager.deleteFloatingIp(ip)) { - s_logger.debug("Successfully deleted floating ip: " + ip.getAddress().addr()); + logger.debug("Successfully deleted floating ip: " + ip.getAddress().addr()); } } } @@ -353,26 +352,26 @@ private boolean isFloatingIpCreate(PublicIpAddress ip) { @Override public boolean addDhcpEntry(Network network, NicProfile nic, - VirtualMachineProfile vm, - DeployDestination dest, ReservationContext context) - throws ConcurrentOperationException, InsufficientCapacityException, - ResourceUnavailableException { - return false; + VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, InsufficientCapacityException, + ResourceUnavailableException { + return false; } @Override public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, - VirtualMachineProfile vm, - DeployDestination dest, ReservationContext context) - throws ConcurrentOperationException, InsufficientCapacityException, - ResourceUnavailableException { - return false; + VirtualMachineProfile vm, + DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, InsufficientCapacityException, + ResourceUnavailableException { + return false; } @Override public boolean removeDhcpSupportForSubnet(Network network) - throws ResourceUnavailableException { - return false; + throws ResourceUnavailableException { + return false; } @Override diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailGuru.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailGuru.java index 775ca7e09066..345cdc1e6c6c 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailGuru.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailGuru.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.network.contrail.model.VMInterfaceModel; import org.apache.cloudstack.network.contrail.model.VirtualMachineModel; import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; @@ -89,7 +88,6 @@ public class ContrailGuru extends AdapterBase implements NetworkGuru { @Inject DataCenterDao _dcDao; - private static final Logger s_logger = Logger.getLogger(ContrailGuru.class); private static final TrafficType[] TrafficTypes = {TrafficType.Guest}; private boolean canHandle(NetworkOffering offering, NetworkType networkType, PhysicalNetwork physicalNetwork) { @@ -119,12 +117,12 @@ public String getName() { } @Override - public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner) { // Check of the isolation type of the related physical network is L3VPN PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId()); DataCenter dc = _dcDao.findById(plan.getDataCenterId()); if (!canHandle(offering, dc.getNetworkType(),physnet)) { - s_logger.debug("Refusing to design this network"); + logger.debug("Refusing to design this network"); return null; } NetworkVO network = @@ -134,14 +132,19 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use network.setCidr(userSpecified.getCidr()); network.setGateway(userSpecified.getGateway()); } - s_logger.debug("Allocated network " + userSpecified.getName() + (network.getCidr() == null ? "" : " subnet: " + network.getCidr())); + logger.debug("Allocated network " + userSpecified.getName() + (network.getCidr() == null ? "" : " subnet: " + network.getCidr())); return network; } + @Override + public void setup(Network network, long networkId) { + // do nothing + } + @Override public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapacityException { - s_logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType()); + logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType()); VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType()); if (vnModel == null) { @@ -154,7 +157,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin vnModel.update(_manager.getModelController()); } } catch (Exception ex) { - s_logger.warn("virtual-network update: ", ex); + logger.warn("virtual-network update: ", ex); return network; } _manager.getDatabase().getVirtualNetworks().add(vnModel); @@ -162,7 +165,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin if (network.getVpcId() != null) { List ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true); if (ips.isEmpty()) { - s_logger.debug("Creating a source nat ip for network " + network); + logger.debug("Creating a source nat ip for network " + network); Account owner = _accountMgr.getAccount(network.getAccountId()); try { PublicIp publicIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); @@ -172,7 +175,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin _ipAddressDao.update(ip.getId(), ip); _ipAddressDao.releaseFromLockTable(ip.getId()); } catch (Exception e) { - s_logger.error("Unable to allocate source nat ip: " + e); + logger.error("Unable to allocate source nat ip: " + e); } } } @@ -188,7 +191,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin @Override public NicProfile allocate(Network network, NicProfile profile, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException { - s_logger.debug("allocate NicProfile on " + network.getName()); + logger.debug("allocate NicProfile on " + network.getName()); if (profile != null && profile.getRequestedIPv4() != null) { throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + profile); @@ -202,7 +205,7 @@ public NicProfile allocate(Network network, NicProfile profile, VirtualMachinePr try { broadcastUri = new URI("vlan://untagged"); } catch (Exception e) { - s_logger.warn("unable to instantiate broadcast URI: " + e); + logger.warn("unable to instantiate broadcast URI: " + e); } profile.setBroadcastUri(broadcastUri); @@ -215,8 +218,8 @@ public NicProfile allocate(Network network, NicProfile profile, VirtualMachinePr @Override public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException { - s_logger.debug("reserve NicProfile on network id: " + network.getId() + " " + network.getName()); - s_logger.debug("deviceId: " + nic.getDeviceId()); + logger.debug("reserve NicProfile on network id: " + network.getId() + " " + network.getName()); + logger.debug("deviceId: " + nic.getDeviceId()); NicVO nicVO = _nicDao.findById(nic.getId()); assert nicVO != null; @@ -242,7 +245,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D vmiModel.build(_manager.getModelController(), (VMInstanceVO)vm.getVirtualMachine(), nicVO); vmiModel.setActive(); } catch (IOException ex) { - s_logger.error("virtual-machine-interface set", ex); + logger.error("virtual-machine-interface set", ex); return; } @@ -251,17 +254,17 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId()); ipModel.addToVMInterface(vmiModel); } else { - s_logger.debug("Reuse existing instance-ip object on " + ipModel.getName()); + logger.debug("Reuse existing instance-ip object on " + ipModel.getName()); } if (nic.getIPv4Address() != null) { - s_logger.debug("Nic using existing IP address " + nic.getIPv4Address()); + logger.debug("Nic using existing IP address " + nic.getIPv4Address()); ipModel.setAddress(nic.getIPv4Address()); } try { vmModel.update(_manager.getModelController()); } catch (Exception ex) { - s_logger.warn("virtual-machine update", ex); + logger.warn("virtual-machine update", ex); return; } @@ -272,15 +275,15 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D if (nic.getMacAddress() == null) { MacAddressesType macs = vmi.getMacAddresses(); if (macs == null) { - s_logger.debug("no mac address is allocated for Nic " + nicVO.getUuid()); + logger.debug("no mac address is allocated for Nic " + nicVO.getUuid()); } else { - s_logger.info("VMI " + _manager.getVifNameByVmUuid(vm.getUuid(), nicVO.getDeviceId()) + " got mac address: " + macs.getMacAddress().get(0)); + logger.info("VMI " + _manager.getVifNameByVmUuid(vm.getUuid(), nicVO.getDeviceId()) + " got mac address: " + macs.getMacAddress().get(0)); nic.setMacAddress(macs.getMacAddress().get(0)); } } if (nic.getIPv4Address() == null) { - s_logger.debug("Allocated IP address " + ipModel.getAddress()); + logger.debug("Allocated IP address " + ipModel.getAddress()); nic.setIPv4Address(ipModel.getAddress()); if (network.getCidr() != null) { nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr())); @@ -296,7 +299,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D @Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { - s_logger.debug("release NicProfile " + nic.getId()); + logger.debug("release NicProfile " + nic.getId()); return true; } @@ -306,7 +309,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat */ @Override public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { - s_logger.debug("deallocate NicProfile " + nic.getId() + " on " + network.getName()); + logger.debug("deallocate NicProfile " + nic.getId() + " on " + network.getName()); NicVO nicVO = _nicDao.findById(nic.getId()); assert nicVO != null; @@ -330,7 +333,7 @@ public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm try { vmModel.delete(_manager.getModelController()); } catch (IOException ex) { - s_logger.warn("virtual-machine delete", ex); + logger.warn("virtual-machine delete", ex); return; } } @@ -340,12 +343,12 @@ public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm @Override public void updateNicProfile(NicProfile profile, Network network) { // TODO Auto-generated method stub - s_logger.debug("update NicProfile " + profile.getId() + " on " + network.getName()); + logger.debug("update NicProfile " + profile.getId() + " on " + network.getName()); } @Override public void shutdown(NetworkProfile network, NetworkOffering offering) { - s_logger.debug("NetworkGuru shutdown"); + logger.debug("NetworkGuru shutdown"); VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType()); if (vnModel == null) { return; @@ -354,21 +357,21 @@ public void shutdown(NetworkProfile network, NetworkOffering offering) { _manager.getDatabase().getVirtualNetworks().remove(vnModel); vnModel.delete(_manager.getModelController()); } catch (IOException e) { - s_logger.warn("virtual-network delete", e); + logger.warn("virtual-network delete", e); } } @Override public boolean trash(Network network, NetworkOffering offering) { // TODO Auto-generated method stub - s_logger.debug("NetworkGuru trash"); + logger.debug("NetworkGuru trash"); return true; } @Override public void updateNetworkProfile(NetworkProfile networkProfile) { // TODO Auto-generated method stub - s_logger.debug("NetworkGuru updateNetworkProfile"); + logger.debug("NetworkGuru updateNetworkProfile"); } @Override diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailManagerImpl.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailManagerImpl.java index 7021b9ac235e..6da2e216ff82 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailManagerImpl.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailManagerImpl.java @@ -40,7 +40,6 @@ import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationService; @@ -143,7 +142,6 @@ public class ContrailManagerImpl extends ManagerBase implements ContrailManager @Inject NetworkACLDao _networkAclDao; - private static final Logger s_logger = Logger.getLogger(ContrailManager.class); private ApiConnector _api; @@ -173,8 +171,8 @@ public boolean start() { try { _dbSyncTimer.schedule(new DBSyncTask(), 0, _dbSyncInterval); } catch (Exception ex) { - s_logger.debug("Unable to start DB Sync timer " + ex.getMessage()); - s_logger.debug("timer start", ex); + logger.debug("Unable to start DB Sync timer " + ex.getMessage()); + logger.debug("timer start", ex); } return true; } @@ -219,7 +217,7 @@ private NetworkOffering locatePublicNetworkOffering(String offeringName, ConfigurationManager configMgr = (ConfigurationManager) _configService; NetworkOfferingVO voffer = configMgr.createNetworkOffering(offeringName, offeringDisplayText, TrafficType.Public, null, true, Availability.Optional, null, serviceProviderMap, true, - Network.GuestType.Shared, false, null, false, null, true, false, null, true, null, false, false, false, null, null, true, null); + Network.GuestType.Shared, false, null, false, null, true, false, null, true, null, false, false, false, false, null, null, null, true, null, null, false); long id = voffer.getId(); _networkOfferingDao.update(id, voffer); return _networkOfferingDao.findById(id); @@ -254,7 +252,7 @@ private NetworkOffering locateNetworkOffering(String offeringName, ConfigurationManager configMgr = (ConfigurationManager)_configService; NetworkOfferingVO voffer = configMgr.createNetworkOffering(offeringName, offeringDisplayText, TrafficType.Guest, null, false, Availability.Optional, null, serviceProviderMap, true, - Network.GuestType.Isolated, false, null, false, null, false, true, null, true, null, false, offeringName.equals(vpcRouterOfferingName), false, null, null, true, null); + Network.GuestType.Isolated, false, null, false, null, false, true, null, true, null, false, offeringName.equals(vpcRouterOfferingName), false, false, null, null, null, true, null, null, false); if (offeringName.equals(vpcRouterOfferingName)) { voffer.setInternalLb(true); } @@ -295,7 +293,7 @@ private VpcOffering locateVpcOffering() { } serviceProviderMap.put(svc, providerSet); } - vpcOffer = _vpcProvSvc.createVpcOffering(juniperVPCOfferingName, juniperVPCOfferingDisplayText, services, serviceProviderMap, null, null, null, null, null, VpcOffering.State.Enabled); + vpcOffer = _vpcProvSvc.createVpcOffering(juniperVPCOfferingName, juniperVPCOfferingDisplayText, services, serviceProviderMap, null, null, null, false, null, null, null, VpcOffering.State.Enabled, null, false); long id = vpcOffer.getId(); _vpcOffDao.update(id, (VpcOfferingVO)vpcOffer); return _vpcOffDao.findById(id); @@ -335,10 +333,10 @@ public boolean configure(String name, Map params) throws Configu } _api = ApiConnectorFactory.build(hostname, port); } catch (IOException ex) { - s_logger.warn("Unable to read " + configuration, ex); + logger.warn("Unable to read " + configuration, ex); throw new ConfigurationException(); } catch (Exception ex) { - s_logger.debug("Exception in configure: " + ex); + logger.debug("Exception in configure: " + ex); ex.printStackTrace(); throw new ConfigurationException(); } finally { @@ -355,7 +353,7 @@ public boolean configure(String name, Map params) throws Configu Provider.JuniperContrailVpcRouter); _vpcOffering = locateVpcOffering(); }catch (Exception ex) { - s_logger.debug("Exception in locating network offerings: " + ex); + logger.debug("Exception in locating network offerings: " + ex); ex.printStackTrace(); throw new ConfigurationException(); } @@ -519,12 +517,12 @@ public void findInfrastructureNetworks(PhysicalNetworkVO phys, List d public void syncNetworkDB(short syncMode) throws IOException { if (_dbSync.syncAll(syncMode) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) { if (syncMode == DBSyncGeneric.SYNC_MODE_CHECK) { - s_logger.info("# Cloudstack DB & VNC are out of sync #"); + logger.info("# Cloudstack DB & VNC are out of sync #"); } else { - s_logger.info("# Cloudstack DB & VNC were out of sync, performed re-sync operation #"); + logger.info("# Cloudstack DB & VNC were out of sync, performed re-sync operation #"); } } else { - s_logger.info("# Cloudstack DB & VNC are in sync #"); + logger.info("# Cloudstack DB & VNC are in sync #"); } } @@ -534,13 +532,13 @@ public class DBSyncTask extends TimerTask { @Override public void run() { try { - s_logger.debug("DB Sync task is running"); + logger.debug("DB Sync task is running"); syncNetworkDB(_syncMode); // Change to check mode _syncMode = DBSyncGeneric.SYNC_MODE_CHECK; } catch (Exception ex) { - s_logger.debug(ex); - s_logger.info("Unable to sync network db"); + logger.debug(ex); + logger.info("Unable to sync network db"); } } } @@ -591,7 +589,7 @@ public List findSystemNetworks(List types) { sc.setParameters("trafficType", types.toArray()); List dbNets = _networksDao.search(sc, null); if (dbNets == null) { - s_logger.debug("no system networks for the given traffic types: " + types.toString()); + logger.debug("no system networks for the given traffic types: " + types.toString()); dbNets = new ArrayList(); } @@ -666,7 +664,7 @@ public List findManagedNetworks(List types) { List dbNets = _networksDao.search(sc, null); if (dbNets == null) { - s_logger.debug("no juniper managed networks for the given traffic types: " + types.toString()); + logger.debug("no juniper managed networks for the given traffic types: " + types.toString()); dbNets = new ArrayList(); } @@ -708,7 +706,7 @@ public List findManagedVpcs() { sc.setParameters("vpcOffering", getVpcOffering().getId()); List vpcs = _vpcDao.search(sc, null); if (vpcs == null || vpcs.size() == 0) { - s_logger.debug("no vpcs found"); + logger.debug("no vpcs found"); return null; } return vpcs; @@ -732,7 +730,7 @@ public List findManagedACLs() { sc.setParameters("vpcId", vpcIds.toArray()); List acls = _networkAclDao.search(sc, null); if (acls == null || acls.size() == 0) { - s_logger.debug("no acls found"); + logger.debug("no acls found"); return null; } /* only return if acl is associated to any network */ @@ -756,7 +754,7 @@ public List findManagedPublicIps() { List dbNets = findManagedNetworks(null); if (dbNets == null || dbNets.isEmpty()) { - s_logger.debug("Juniper managed networks is empty"); + logger.debug("Juniper managed networks is empty"); return null; } @@ -778,7 +776,7 @@ public List findManagedPublicIps() { List publicIps = _ipAddressDao.search(sc, null); if (publicIps == null) { - s_logger.debug("no public ips"); + logger.debug("no public ips"); return null; } @@ -803,7 +801,7 @@ private void initializeDefaultVirtualNetworkModels() { vnModel.update(getModelController()); } } catch (Exception ex) { - s_logger.warn("virtual-network update: ", ex); + logger.warn("virtual-network update: ", ex); } getDatabase().getVirtualNetworks().add(vnModel); } @@ -918,7 +916,7 @@ public VirtualNetworkModel lookupPublicNetworkModel() { } getDatabase().getVirtualNetworks().add(vnModel); } catch (Exception ex) { - s_logger.warn("virtual-network update: ", ex); + logger.warn("virtual-network update: ", ex); } return vnModel; } @@ -938,7 +936,7 @@ public boolean createFloatingIp(PublicIpAddress ip) { fipPoolModel.update(getModelController()); vnModel.setFipPoolModel(fipPoolModel); } catch (Exception ex) { - s_logger.warn("floating-ip-pool create: ", ex); + logger.warn("floating-ip-pool create: ", ex); return false; } } @@ -952,7 +950,7 @@ public boolean createFloatingIp(PublicIpAddress ip) { try { fipModel.update(getModelController()); } catch (Exception ex) { - s_logger.warn("floating-ip create: ", ex); + logger.warn("floating-ip create: ", ex); return false; } } @@ -969,7 +967,7 @@ public boolean deleteFloatingIp(PublicIpAddress ip) { try { fipModel.destroy(getModelController()); } catch (IOException ex) { - s_logger.warn("floating ip delete", ex); + logger.warn("floating ip delete", ex); return false; } fipPoolModel.removeSuccessor(fipModel); @@ -993,7 +991,7 @@ public List getFloatingIps() { try { fipPool = (FloatingIpPool)_api.findByFQN(FloatingIpPool.class, fipPoolName); } catch (Exception ex) { - s_logger.debug(ex); + logger.debug(ex); } if (fipPool == null) { return null; @@ -1003,7 +1001,7 @@ public List getFloatingIps() { try { return (List)_api.getObjects(FloatingIp.class, ips); } catch (IOException ex) { - s_logger.debug(ex); + logger.debug(ex); return null; } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailVpcElementImpl.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailVpcElementImpl.java index 689b252b2a73..d5060443c9e8 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailVpcElementImpl.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ContrailVpcElementImpl.java @@ -25,13 +25,13 @@ import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel; import org.apache.cloudstack.network.contrail.model.NetworkPolicyModel; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.IpAddress; import com.cloud.network.Network; import com.cloud.network.Network.Provider; import com.cloud.network.element.NetworkACLServiceProvider; @@ -46,8 +46,6 @@ @Component public class ContrailVpcElementImpl extends ContrailElementImpl implements NetworkACLServiceProvider, VpcProvider { - private static final Logger s_logger = - Logger.getLogger(ContrailElement.class); @Inject NetworkACLDao _networkACLDao; @@ -63,7 +61,7 @@ public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // TODO Auto-generated method stub - s_logger.debug("NetworkElement implementVpc"); + logger.debug("NetworkElement implementVpc"); return true; } @@ -71,7 +69,7 @@ public boolean implementVpc(Vpc vpc, DeployDestination dest, public boolean shutdownVpc(Vpc vpc, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub - s_logger.debug("NetworkElement shutdownVpc"); + logger.debug("NetworkElement shutdownVpc"); return true; } @@ -79,7 +77,7 @@ public boolean shutdownVpc(Vpc vpc, ReservationContext context) public boolean createPrivateGateway(PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub - s_logger.debug("NetworkElement createPrivateGateway"); + logger.debug("NetworkElement createPrivateGateway"); return false; } @@ -87,7 +85,7 @@ public boolean createPrivateGateway(PrivateGateway gateway) public boolean deletePrivateGateway(PrivateGateway privateGateway) throws ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub - s_logger.debug("NetworkElement deletePrivateGateway"); + logger.debug("NetworkElement deletePrivateGateway"); return false; } @@ -95,7 +93,7 @@ public boolean deletePrivateGateway(PrivateGateway privateGateway) public boolean applyStaticRoutes(Vpc vpc, List routes) throws ResourceUnavailableException { // TODO Auto-generated method stub - s_logger.debug("NetworkElement applyStaticRoutes"); + logger.debug("NetworkElement applyStaticRoutes"); return true; } @@ -103,9 +101,9 @@ public boolean applyStaticRoutes(Vpc vpc, List routes) public boolean applyNetworkACLs(Network net, List rules) throws ResourceUnavailableException { - s_logger.debug("NetworkElement applyNetworkACLs"); + logger.debug("NetworkElement applyNetworkACLs"); if (rules == null || rules.isEmpty()) { - s_logger.debug("no rules to apply"); + logger.debug("no rules to apply"); return true; } @@ -125,7 +123,7 @@ public boolean applyNetworkACLs(Network net, project = _manager.getDefaultVncProject(); } } catch (IOException ex) { - s_logger.warn("read project", ex); + logger.warn("read project", ex); return false; } policyModel.setProject(project); @@ -143,7 +141,7 @@ public boolean applyNetworkACLs(Network net, try { policyModel.build(_manager.getModelController(), rules); } catch (Exception e) { - s_logger.error(e); + logger.error(e); e.printStackTrace(); return false; } @@ -154,7 +152,7 @@ public boolean applyNetworkACLs(Network net, } _manager.getDatabase().getNetworkPolicys().add(policyModel); } catch (Exception ex) { - s_logger.error("network-policy update: ", ex); + logger.error("network-policy update: ", ex); ex.printStackTrace(); return false; } @@ -185,13 +183,22 @@ public boolean applyNetworkACLs(Network net, return true; } + @Override + public boolean reorderAclRules(Vpc vpc, List networks, List networkACLItems) { + return true; + } + @Override public boolean applyACLItemsToPrivateGw(PrivateGateway privateGateway, List rules) throws ResourceUnavailableException { // TODO Auto-generated method stub - s_logger.debug("NetworkElement applyACLItemsToPrivateGw"); + logger.debug("NetworkElement applyACLItemsToPrivateGw"); return true; } + @Override + public boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address) { + return true; + } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/DBSyncGeneric.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/DBSyncGeneric.java index fdfd9df2a435..7cb47224ed72 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/DBSyncGeneric.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/DBSyncGeneric.java @@ -26,13 +26,14 @@ import net.juniper.contrail.api.ApiObjectBase; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.api.Identity; public class DBSyncGeneric { - private static final Logger s_logger = Logger.getLogger(DBSyncGeneric.class); + protected Logger logger = LogManager.getLogger(getClass()); /* for each synchronization VNC class, following methods * needs to be defined. @@ -141,7 +142,7 @@ private Boolean filter(Class cls, Object... parameters) throws InvocationTarg String filterMethod = filterMethodPrefix + getClassName(cls); Method method = _methodMap.get(filterMethod); if (method == null) { - s_logger.debug("Method not implemented: " + getClassName(_scope.getClass()) + ":" + filterMethod); + logger.debug("Method not implemented: " + getClassName(_scope.getClass()) + ":" + filterMethod); return false; } return (Boolean)method.invoke(_scope, parameters); @@ -151,7 +152,7 @@ private Boolean equal(Class cls, Object... parameters) throws InvocationTarge String equalMethod = equalMethodPrefix + getClassName(cls); Method method = _methodMap.get(equalMethod); if (method == null) { - s_logger.debug("Method not implemented: " + getClassName(_scope.getClass()) + ":" + equalMethod); + logger.debug("Method not implemented: " + getClassName(_scope.getClass()) + ":" + equalMethod); return true; } return (Boolean)method.invoke(_scope, parameters); @@ -300,7 +301,7 @@ public boolean syncGeneric(Class cls, List dbList, List vncList) throws SyncStats stats = new SyncStats(); stats.log("Sync log for <" + getClassName(cls) + ">"); - s_logger.debug("Generic db sync : " + getClassName(cls)); + logger.debug("Generic db sync : " + getClassName(cls)); java.util.Collections.sort(dbList, this.dbComparator(cls)); java.util.Collections.sort(vncList, this.vncComparator(cls)); @@ -308,16 +309,16 @@ public boolean syncGeneric(Class cls, List dbList, List vncList) throws syncCollections(cls, dbList, vncList, _syncMode != SYNC_MODE_CHECK, stats); if (_syncMode != SYNC_MODE_CHECK) { - s_logger.debug("Sync stats<" + getClassName(cls) + ">: " + stats.toString()); - s_logger.debug(stats.logMsg); - s_logger.debug("Generic db sync : " + getClassName(cls) + " done"); + logger.debug("Sync stats<" + getClassName(cls) + ">: " + stats.toString()); + logger.debug(stats.logMsg); + logger.debug("Generic db sync : " + getClassName(cls) + " done"); } else { - s_logger.debug("Sync state checking stats<" + getClassName(cls) + ">: " + stats.toString()); + logger.debug("Sync state checking stats<" + getClassName(cls) + ">: " + stats.toString()); if (!stats.isSynchronized()) { - s_logger.debug("DB and VNC objects out of sync is detected : " + getClassName(cls)); - s_logger.debug("Log message: \n" + stats.logMsg); + logger.debug("DB and VNC objects out of sync is detected : " + getClassName(cls)); + logger.debug("Log message: \n" + stats.logMsg); } else { - s_logger.debug("DB and VNC objects are in sync : " + getClassName(cls)); + logger.debug("DB and VNC objects are in sync : " + getClassName(cls)); } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/EventUtils.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/EventUtils.java index 78ec01344ca7..d47bf6eceeb0 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/EventUtils.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/EventUtils.java @@ -18,20 +18,19 @@ package org.apache.cloudstack.network.contrail.management; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import org.apache.log4j.Logger; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.stereotype.Component; - -import org.apache.cloudstack.context.CallContext; -import org.apache.cloudstack.framework.events.EventBus; -import org.apache.cloudstack.framework.events.EventBusException; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.framework.events.EventDistributor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.stereotype.Component; import com.cloud.event.ActionEvent; import com.cloud.event.ActionEvents; @@ -42,15 +41,20 @@ import com.cloud.utils.component.ComponentContext; import com.cloud.utils.component.ComponentMethodInterceptor; + @Component public class EventUtils { - private static final Logger s_logger = Logger.getLogger(EventUtils.class); + protected static Logger LOGGER = LogManager.getLogger(EventUtils.class); - protected static EventBus s_eventBus = null; + private static EventDistributor eventDistributor; public EventUtils() { } + public static void setEventDistributor(EventDistributor eventDistributorImpl) { + eventDistributor = eventDistributorImpl; + } + private static void publishOnMessageBus(String eventCategory, String eventType, String details, Event.State state) { if (state != com.cloud.event.Event.State.Completed) { @@ -58,7 +62,7 @@ private static void publishOnMessageBus(String eventCategory, String eventType, } try { - s_eventBus = ComponentContext.getComponent(EventBus.class); + setEventDistributor(ComponentContext.getComponent(EventDistributor.class)); } catch (NoSuchBeanDefinitionException nbe) { return; // no provider is configured to provide events bus, so just return } @@ -66,23 +70,17 @@ private static void publishOnMessageBus(String eventCategory, String eventType, org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, eventCategory, eventType, EventTypes.getEntityForEvent(eventType), null); - Map eventDescription = new HashMap(); + Map eventDescription = new HashMap<>(); eventDescription.put("event", eventType); eventDescription.put("status", state.toString()); eventDescription.put("details", details); event.setDescription(eventDescription); - try { - s_eventBus.publish(event); - } catch (EventBusException evx) { - String errMsg = "Failed to publish contrail event."; - s_logger.warn(errMsg, evx); - } - + eventDistributor.publish(event); } public static class EventInterceptor implements ComponentMethodInterceptor, MethodInterceptor { - private static final Logger s_logger = Logger.getLogger(EventInterceptor.class); + protected Logger LOGGER = LogManager.getLogger(getClass()); public EventInterceptor() { @@ -118,7 +116,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable { } protected List getActionEvents(Method m) { - List result = new ArrayList(); + List result = new ArrayList<>(); ActionEvents events = m.getAnnotation(ActionEvents.class); @@ -155,7 +153,7 @@ public void interceptComplete(Method method, Object target, Object event) { @Override public void interceptException(Method method, Object target, Object event) { - s_logger.debug("interceptException"); + LOGGER.debug("interceptException"); } @Override diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java index 6ad0746ba6b1..dc453f75c150 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java @@ -28,7 +28,6 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.deploy.DeploymentPlan; @@ -48,7 +47,6 @@ */ @Component public class ManagementNetworkGuru extends ContrailGuru { - private static final Logger s_logger = Logger.getLogger(ManagementNetworkGuru.class); private static final TrafficType[] TrafficTypes = {TrafficType.Management}; private final String configuration = "contrail.properties"; @@ -71,7 +69,7 @@ public boolean configure(String name, Map params) throws Configu } inputFile = new FileInputStream(configFile); } catch (FileNotFoundException e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); throw new ConfigurationException(e.getMessage()); } @@ -79,14 +77,14 @@ public boolean configure(String name, Map params) throws Configu try { configProps.load(inputFile); } catch (IOException e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); throw new ConfigurationException(e.getMessage()); } finally { closeAutoCloseable(inputFile, "error closing config file"); } _mgmtCidr = configProps.getProperty("management.cidr"); _mgmtGateway = configProps.getProperty("management.gateway"); - s_logger.info("Management network " + _mgmtCidr + " gateway: " + _mgmtGateway); + logger.info("Management network " + _mgmtCidr + " gateway: " + _mgmtGateway); return true; } @@ -111,7 +109,7 @@ private boolean canHandle(NetworkOffering offering) { } @Override - public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner) { if (!canHandle(offering)) { return null; @@ -123,7 +121,7 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use network.setCidr(_mgmtCidr); network.setGateway(_mgmtGateway); } - s_logger.debug("Allocated network " + userSpecified.getName() + (network.getCidr() == null ? "" : " subnet: " + network.getCidr())); + logger.debug("Allocated network " + userSpecified.getName() + (network.getCidr() == null ? "" : " subnet: " + network.getCidr())); return network; } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServerDBSyncImpl.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServerDBSyncImpl.java index 320ac489ba9d..70d8c6deef92 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServerDBSyncImpl.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServerDBSyncImpl.java @@ -41,7 +41,8 @@ import net.juniper.contrail.api.types.VirtualNetwork; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.network.contrail.model.FloatingIpModel; @@ -118,7 +119,7 @@ public class ServerDBSyncImpl implements ServerDBSync { _dbSync = new DBSyncGeneric(this); } - private static final Logger s_logger = Logger.getLogger(ServerDBSync.class); + protected Logger logger = LogManager.getLogger(getClass()); /* * API for syncing all classes of vnc objects with cloudstack @@ -131,7 +132,7 @@ public short syncAll(short syncMode) { short syncState = SYNC_STATE_IN_SYNC; /* vnc classes need to be synchronized with cloudstack */ - s_logger.debug("syncing cloudstack db with vnc"); + logger.debug("syncing cloudstack db with vnc"); try { for (Class cls : _vncClasses) { @@ -141,29 +142,29 @@ public short syncAll(short syncMode) { _dbSync.setSyncMode(syncMode); if (_dbSync.getSyncMode() == DBSyncGeneric.SYNC_MODE_CHECK) { - s_logger.debug("sync check start: " + DBSyncGeneric.getClassName(cls)); + logger.debug("sync check start: " + DBSyncGeneric.getClassName(cls)); } else { - s_logger.debug("sync start: " + DBSyncGeneric.getClassName(cls)); + logger.debug("sync start: " + DBSyncGeneric.getClassName(cls)); } if (_dbSync.sync(cls) == false) { if (_dbSync.getSyncMode() == DBSyncGeneric.SYNC_MODE_CHECK) { - s_logger.info("out of sync detected: " + DBSyncGeneric.getClassName(cls)); + logger.info("out of sync detected: " + DBSyncGeneric.getClassName(cls)); } else { - s_logger.info("out of sync detected and re-synced: " + DBSyncGeneric.getClassName(cls)); + logger.info("out of sync detected and re-synced: " + DBSyncGeneric.getClassName(cls)); } syncState = SYNC_STATE_OUT_OF_SYNC; } if (_dbSync.getSyncMode() == DBSyncGeneric.SYNC_MODE_CHECK) { - s_logger.debug("sync check finish: " + DBSyncGeneric.getClassName(cls)); + logger.debug("sync check finish: " + DBSyncGeneric.getClassName(cls)); } else { - s_logger.debug("sync finish: " + DBSyncGeneric.getClassName(cls)); + logger.debug("sync finish: " + DBSyncGeneric.getClassName(cls)); } /* unlock the sync mode */ _lockSyncMode.unlock(); } } catch (Exception ex) { - s_logger.warn("DB Synchronization", ex); + logger.warn("DB Synchronization", ex); syncState = SYNC_STATE_UNKNOWN; if (_lockSyncMode.isLocked()) { _lockSyncMode.unlock(); @@ -176,16 +177,16 @@ public short syncAll(short syncMode) { @Override public void syncClass(Class cls) { - s_logger.debug("syncClass: " + cls.getName()); + logger.debug("syncClass: " + cls.getName()); try { - s_logger.debug("sync start: " + DBSyncGeneric.getClassName(cls)); + logger.debug("sync start: " + DBSyncGeneric.getClassName(cls)); _lockSyncMode.lock(); _dbSync.setSyncMode(DBSyncGeneric.SYNC_MODE_UPDATE); _dbSync.sync(cls); _lockSyncMode.unlock(); - s_logger.debug("sync finish: " + DBSyncGeneric.getClassName(cls)); + logger.debug("sync finish: " + DBSyncGeneric.getClassName(cls)); } catch (Exception ex) { - s_logger.warn("Sync error: " + cls.getName(), ex); + logger.warn("Sync error: " + cls.getName(), ex); if (_lockSyncMode.isLocked()) { _lockSyncMode.unlock(); } @@ -240,7 +241,7 @@ public boolean syncDomain() throws Exception { List vncList = api.list(net.juniper.contrail.api.types.Domain.class, null); return _dbSync.syncGeneric(net.juniper.contrail.api.types.Domain.class, dbList, vncList); } catch (Exception ex) { - s_logger.warn("syncDomain", ex); + logger.warn("syncDomain", ex); throw ex; } } @@ -252,7 +253,7 @@ public void createDomain(DomainVO db, StringBuffer syncLogMesg) throws IOExcepti vnc.setName(db.getName()); vnc.setUuid(db.getUuid()); if (!api.create(vnc)) { - s_logger.error("Unable to create domain " + vnc.getName()); + logger.error("Unable to create domain " + vnc.getName()); syncLogMesg.append("Error: Virtual domain# VNC : Unable to create domain: " + vnc.getName() + "\n"); return; } @@ -268,7 +269,7 @@ public void deleteDomain(net.juniper.contrail.api.types.Domain vnc, StringBuffer try { deleteChildren(vnc.getProjects(), net.juniper.contrail.api.types.Project.class, syncLogMesg); } catch (Exception ex) { - s_logger.warn("deleteDomain", ex); + logger.warn("deleteDomain", ex); } api.delete(vnc); @@ -341,7 +342,7 @@ public boolean syncProject() throws Exception { List vncList = api.list(net.juniper.contrail.api.types.Project.class, null); return _dbSync.syncGeneric(net.juniper.contrail.api.types.Project.class, dbList, vncList); } catch (Exception ex) { - s_logger.warn("syncProject", ex); + logger.warn("syncProject", ex); throw ex; } } @@ -353,7 +354,7 @@ public void createProject(ProjectVO db, StringBuffer syncLogMesg) throws IOExcep vnc.setName(db.getName()); vnc.setUuid(db.getUuid()); if (!api.create(vnc)) { - s_logger.error("Unable to create project: " + vnc.getName()); + logger.error("Unable to create project: " + vnc.getName()); syncLogMesg.append("Error: Virtual project# VNC : Unable to create project: " + vnc.getName() + "\n"); return; } @@ -371,7 +372,7 @@ public void deleteProject(net.juniper.contrail.api.types.Project vnc, StringBuff deleteChildren(vnc.getNetworkIpams(), net.juniper.contrail.api.types.NetworkIpam.class, syncLogMesg); deleteChildren(vnc.getNetworkPolicys(), net.juniper.contrail.api.types.NetworkPolicy.class, syncLogMesg); } catch (Exception ex) { - s_logger.warn("deleteProject", ex); + logger.warn("deleteProject", ex); } api.delete(vnc); @@ -464,10 +465,10 @@ public boolean syncVirtualNetwork() throws Exception { vncList.add(vn); } } - s_logger.debug("sync VN - DB size: " + dbNets.size() + " VNC Size: " + vncList.size()); + logger.debug("sync VN - DB size: " + dbNets.size() + " VNC Size: " + vncList.size()); return _dbSync.syncGeneric(VirtualNetwork.class, dbNets, vncList); } catch (Exception ex) { - s_logger.warn("sync virtual-networks", ex); + logger.warn("sync virtual-networks", ex); throw ex; } } @@ -510,7 +511,7 @@ public void createVirtualNetwork(NetworkVO dbNet, StringBuffer syncLogMesg) thro syncLogMesg.append("VN# DB: " + _manager.getCanonicalName(dbNet) + "(" + dbNet.getUuid() + "); VNC: none; action: create\n"); if (_manager.getDatabase().lookupVirtualNetwork(dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType()) != null) { - s_logger.warn("VN model object is already present in DB: " + dbNet.getUuid() + ", name: " + dbNet.getName()); + logger.warn("VN model object is already present in DB: " + dbNet.getUuid() + ", name: " + dbNet.getName()); } VirtualNetworkModel vnModel = new VirtualNetworkModel(dbNet, dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType()); @@ -518,7 +519,7 @@ public void createVirtualNetwork(NetworkVO dbNet, StringBuffer syncLogMesg) thro NetworkACLVO acl = _networkACLDao.findById(dbNet.getNetworkACLId()); NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.getUuid()); if (policyModel == null) { - s_logger.error("Network(" + dbNet.getName() + ") has ACL but policy model not created: " + + logger.error("Network(" + dbNet.getName() + ") has ACL but policy model not created: " + acl.getUuid() + ", name: " + acl.getName()); } else { vnModel.addToNetworkPolicy(policyModel); @@ -532,11 +533,11 @@ public void createVirtualNetwork(NetworkVO dbNet, StringBuffer syncLogMesg) thro vnModel.update(_manager.getModelController()); } } catch (InternalErrorException ex) { - s_logger.warn("create virtual-network", ex); + logger.warn("create virtual-network", ex); syncLogMesg.append("Error: VN# VNC : Unable to create network " + dbNet.getName() + "\n"); return; } - s_logger.debug("add model " + vnModel.getName()); + logger.debug("add model " + vnModel.getName()); _manager.getDatabase().getVirtualNetworks().add(vnModel); syncLogMesg.append("VN# VNC: " + dbNet.getUuid() + ", " + vnModel.getName() + " created\n"); } else { @@ -598,7 +599,7 @@ public Boolean equalVirtualNetwork(NetworkVO dbn, VirtualNetwork vnet, StringBuf NetworkACLVO acl = _networkACLDao.findById(dbn.getNetworkACLId()); NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.getUuid()); if (policyModel == null) { - s_logger.error("Network(" + dbn.getName() + ") has ACL but policy model not created: " + + logger.error("Network(" + dbn.getName() + ") has ACL but policy model not created: " + acl.getUuid() + ", name: " + acl.getName()); } else { vnModel.addToNetworkPolicy(policyModel); @@ -615,14 +616,14 @@ public Boolean equalVirtualNetwork(NetworkVO dbn, VirtualNetwork vnet, StringBuf } _manager.getDatabase().getVirtualNetworks().remove(current); } - s_logger.debug("add model " + vnModel.getName()); + logger.debug("add model " + vnModel.getName()); _manager.getDatabase().getVirtualNetworks().add(vnModel); try { if (!vnModel.verify(_manager.getModelController())) { vnModel.update(_manager.getModelController()); } } catch (Exception ex) { - s_logger.warn("update virtual-network", ex); + logger.warn("update virtual-network", ex); } if (current != null) { NetworkPolicyModel oldPolicyModel = current.getNetworkPolicyModel(); @@ -661,10 +662,10 @@ public boolean syncVirtualMachine() { List vmDbList = _vmInstanceDao.listAll(); @SuppressWarnings("unchecked") List vncVmList = (List)api.list(VirtualMachine.class, null); - s_logger.debug("sync VM: CS size: " + vmDbList.size() + " VNC size: " + vncVmList.size()); + logger.debug("sync VM: CS size: " + vmDbList.size() + " VNC size: " + vncVmList.size()); return _dbSync.syncGeneric(VirtualMachine.class, vmDbList, vncVmList); } catch (Exception ex) { - s_logger.warn("sync virtual-machines", ex); + logger.warn("sync virtual-machines", ex); } return false; } @@ -699,7 +700,7 @@ public void createVirtualMachine(VMInstanceVO dbVm, StringBuffer syncLogMesg) th try { vmModel.update(_manager.getModelController()); } catch (InternalErrorException ex) { - s_logger.warn("create virtual-machine", ex); + logger.warn("create virtual-machine", ex); return; } _manager.getDatabase().getVirtualMachines().add(vmModel); @@ -757,7 +758,7 @@ public void deleteVirtualMachine(VirtualMachine vncVm, StringBuffer syncLogMesg) deleteVirtualMachineInterfaces(vncVm.getVirtualMachineInterfaces(), syncLogMesg); api.delete(VirtualMachine.class, vncVm.getUuid()); } catch (IOException ex) { - s_logger.warn("delete virtual-machine", ex); + logger.warn("delete virtual-machine", ex); return; } syncLogMesg.append("VM# VNC: " + vncVm.getName() + " deleted\n"); @@ -783,7 +784,7 @@ private void buildNicResources(VirtualMachineModel vmModel, VMInstanceVO dbVm, S VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType()); if (vnModel == null) { - s_logger.warn("Unable to locate virtual-network for network id " + network.getId()); + logger.warn("Unable to locate virtual-network for network id " + network.getId()); continue; } vmiModel.addToVirtualMachine(vmModel); @@ -805,7 +806,7 @@ public Boolean equalVirtualMachine(VMInstanceVO dbVm, VirtualMachine vncVm, Stri try { buildNicResources(vmModel, dbVm, syncLogMsg); } catch (IOException ex) { - s_logger.warn("build nic information for " + dbVm.getInstanceName(), ex); + logger.warn("build nic information for " + dbVm.getInstanceName(), ex); } } @@ -818,7 +819,7 @@ public Boolean equalVirtualMachine(VMInstanceVO dbVm, VirtualMachine vncVm, Stri try { vmModel.update(_manager.getModelController()); } catch (Exception ex) { - s_logger.warn("update virtual-machine", ex); + logger.warn("update virtual-machine", ex); } } else { //compare @@ -845,7 +846,7 @@ public boolean syncFloatingIp() throws Exception { try { status = _dbSync.syncGeneric(FloatingIp.class, ipList, vncList); } catch (Exception ex) { - s_logger.warn("sync floating-ips", ex); + logger.warn("sync floating-ips", ex); throw ex; } return status; @@ -915,21 +916,21 @@ public Boolean equalFloatingIp(IPAddressVO db, FloatingIp vnc, StringBuffer sync fipPoolModel.update(_manager.getModelController()); vnModel.setFipPoolModel(fipPoolModel); } catch (Exception ex) { - s_logger.warn("floating-ip-pool create: ", ex); + logger.warn("floating-ip-pool create: ", ex); return false; } } FloatingIpModel current = fipPoolModel.getFloatingIpModel(db.getUuid()); if (current == null) { - s_logger.debug("add model " + db.getAddress().addr()); + logger.debug("add model " + db.getAddress().addr()); FloatingIpModel fipModel = new FloatingIpModel(db.getUuid()); fipModel.addToFloatingIpPool(fipPoolModel); fipModel.build(_manager.getModelController(), PublicIp.createFromAddrAndVlan(db, _vlanDao.findById(db.getVlanId()))); try { fipModel.update(_manager.getModelController()); } catch (Exception ex) { - s_logger.warn("floating-ip create: ", ex); + logger.warn("floating-ip create: ", ex); return false; } } @@ -957,10 +958,10 @@ public boolean syncNetworkPolicy() throws Exception { vncList.add(policy); } } - s_logger.debug("sync Network Policy - DB size: " + dbAcls.size() + " VNC Size: " + vncList.size()); + logger.debug("sync Network Policy - DB size: " + dbAcls.size() + " VNC Size: " + vncList.size()); return _dbSync.syncGeneric(NetworkPolicy.class, dbAcls, vncList); } catch (Exception ex) { - s_logger.warn("sync network-policys", ex); + logger.warn("sync network-policys", ex); throw ex; } } @@ -988,7 +989,7 @@ public void createNetworkPolicy(NetworkACLVO db, StringBuffer syncLogMesg) throw "(" + db.getUuid() + "); VNC: none; action: create\n"); if (_manager.getDatabase().lookupNetworkPolicy(db.getUuid()) != null) { - s_logger.warn("Policy model object is already present in DB: " + + logger.warn("Policy model object is already present in DB: " + db.getUuid() + ", name: " + db.getName()); } NetworkPolicyModel policyModel = new NetworkPolicyModel(db.getUuid(), db.getName()); @@ -1001,7 +1002,7 @@ public void createNetworkPolicy(NetworkACLVO db, StringBuffer syncLogMesg) throw project = _manager.getDefaultVncProject(); } } catch (IOException ex) { - s_logger.warn("read project", ex); + logger.warn("read project", ex); throw ex; } policyModel.setProject(project); @@ -1018,12 +1019,12 @@ public void createNetworkPolicy(NetworkACLVO db, StringBuffer syncLogMesg) throw policyModel.update(_manager.getModelController()); } } catch (Exception ex) { - s_logger.warn("create network-policy", ex); + logger.warn("create network-policy", ex); syncLogMesg.append("Error: Policy# VNC : Unable to create network policy " + db.getName() + "\n"); return; } - s_logger.debug("add model " + policyModel.getName()); + logger.debug("add model " + policyModel.getName()); _manager.getDatabase().getNetworkPolicys().add(policyModel); syncLogMesg.append("Policy# VNC: " + db.getUuid() + ", " + policyModel.getName() + " created\n"); } else { @@ -1071,7 +1072,7 @@ public Boolean equalNetworkPolicy(NetworkACLVO db, NetworkPolicy policy, StringB project = _manager.getDefaultVncProject(); } } catch (IOException ex) { - s_logger.warn("read project", ex); + logger.warn("read project", ex); } policyModel.setProject(project); List rules = _networkACLItemDao.listByACL(db.getId()); @@ -1084,14 +1085,14 @@ public Boolean equalNetworkPolicy(NetworkACLVO db, NetworkPolicy policy, StringB if (current != null) { _manager.getDatabase().getNetworkPolicys().remove(current); } - s_logger.debug("add policy model " + policyModel.getName()); + logger.debug("add policy model " + policyModel.getName()); _manager.getDatabase().getNetworkPolicys().add(policyModel); try { if (!policyModel.verify(_manager.getModelController())) { policyModel.update(_manager.getModelController()); } } catch (Exception ex) { - s_logger.warn("update network-policy", ex); + logger.warn("update network-policy", ex); } } else { //compare @@ -1122,14 +1123,14 @@ public void createServiceInstance(ServiceInstanceModel siModel, StringBuffer log public void deleteServiceInstance(ServiceInstance siObj, StringBuffer logMsg) { final ApiConnector api = _manager.getApiConnector(); - s_logger.debug("delete " + siObj.getQualifiedName()); + logger.debug("delete " + siObj.getQualifiedName()); if (!_rwMode) { return; } try { api.delete(siObj); } catch (IOException ex) { - s_logger.warn("service-instance delete", ex); + logger.warn("service-instance delete", ex); } } @@ -1141,7 +1142,7 @@ public void deleteServiceInstance(ServiceInstance siObj, StringBuffer logMsg) { * @param logMsg */ public void equalServiceInstance(ServiceInstanceModel siModel, ServiceInstance siObj, StringBuffer logMsg) { - s_logger.debug("equal " + siModel.getQualifiedName()); + logger.debug("equal " + siModel.getQualifiedName()); } static class ServiceInstanceComparator implements Comparator, Serializable { @@ -1169,7 +1170,7 @@ public boolean syncServiceInstance() { _dbSync.syncCollections(ServiceInstance.class, _manager.getDatabase().getServiceInstances(), siList, _rwMode, stats); inSync = stats.create == 0 && stats.delete == 0; } catch (Exception ex) { - s_logger.warn("synchronize service-instances", ex); + logger.warn("synchronize service-instances", ex); return false; } return inSync; diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServerEventHandlerImpl.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServerEventHandlerImpl.java index 05dcdce1a92f..2ddb28ea9f22 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServerEventHandlerImpl.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServerEventHandlerImpl.java @@ -22,7 +22,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.framework.messagebus.MessageBus; @@ -62,7 +63,7 @@ public class ServerEventHandlerImpl implements ServerEventHandler { private HashMap _methodMap; private HashMap> _classMap; - private static final Logger s_logger = Logger.getLogger(MessageHandler.class); + protected Logger logger = LogManager.getLogger(getClass()); ServerEventHandlerImpl() { setMethodMap(); @@ -85,7 +86,7 @@ private void setClassMap() { @MessageHandler(topic = ".*") public void defaultMessageHandler(String subject, String topic, Object args) { - s_logger.info("DB Event Received - topic: " + topic + "; subject: " + subject); + logger.info("DB Event Received - topic: " + topic + "; subject: " + subject); org.apache.cloudstack.framework.events.Event event = (org.apache.cloudstack.framework.events.Event)args; @@ -108,18 +109,18 @@ public void defaultMessageHandler(String subject, String topic, Object args) { defaultHandler(subject, topic, event); } } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); } } /* Default create handler */ void defaultCreateHandler(String subject, String topic, org.apache.cloudstack.framework.events.Event event) { - s_logger.debug("Default handler is invoked for subject: " + subject + "; topic: " + topic); - s_logger.debug("description: " + event.getDescription()); - s_logger.debug("category: " + event.getEventCategory()); - s_logger.debug("type: " + event.getResourceType()); - s_logger.debug("event-type: " + event.getEventType()); + logger.debug("Default handler is invoked for subject: " + subject + "; topic: " + topic); + logger.debug("description: " + event.getDescription()); + logger.debug("category: " + event.getEventCategory()); + logger.debug("type: " + event.getResourceType()); + logger.debug("event-type: " + event.getEventType()); Class cls = _classMap.get(event.getResourceType()); @@ -133,12 +134,12 @@ void defaultCreateHandler(String subject, String topic, org.apache.cloudstack.fr /* Default handler */ void defaultDeleteHandler(String subject, String topic, org.apache.cloudstack.framework.events.Event event) { - s_logger.debug("Default handler is invoked for subject: " + subject + "; topic: " + topic); + logger.debug("Default handler is invoked for subject: " + subject + "; topic: " + topic); - s_logger.debug("description: " + event.getDescription()); - s_logger.debug("category: " + event.getEventCategory()); - s_logger.debug("type: " + event.getResourceType()); - s_logger.debug("event-type: " + event.getEventType()); + logger.debug("description: " + event.getDescription()); + logger.debug("category: " + event.getEventCategory()); + logger.debug("type: " + event.getResourceType()); + logger.debug("event-type: " + event.getEventType()); Class cls = _classMap.get(event.getResourceType()); if (cls != null) { _dbSync.syncClass(cls); @@ -149,12 +150,12 @@ void defaultDeleteHandler(String subject, String topic, org.apache.cloudstack.fr /* Default handler */ void defaultHandler(String subject, String topic, org.apache.cloudstack.framework.events.Event event) { - s_logger.debug("Default handler is invoked for subject: " + subject + "; topic: " + topic); + logger.debug("Default handler is invoked for subject: " + subject + "; topic: " + topic); - s_logger.debug("description: " + event.getDescription()); - s_logger.debug("category: " + event.getEventCategory()); - s_logger.debug("type: " + event.getResourceType()); - s_logger.debug("event-type: " + event.getEventType()); + logger.debug("description: " + event.getDescription()); + logger.debug("category: " + event.getEventCategory()); + logger.debug("type: " + event.getResourceType()); + logger.debug("event-type: " + event.getEventType()); Class cls = _classMap.get(event.getResourceType()); if (cls != null) { _dbSync.syncClass(cls); @@ -177,19 +178,19 @@ private long parseForId(String resourceType, String description) { try { id = Long.parseLong(idStr.trim()); } catch (Exception e) { - s_logger.debug("Unable to parse id string<" + idStr.trim() + "> for long value, ignored"); + logger.debug("Unable to parse id string<" + idStr.trim() + "> for long value, ignored"); } return id; } public void onDomainCreate(String subject, String topic, org.apache.cloudstack.framework.events.Event event) { - s_logger.info("onDomainCreate; topic: " + topic + "; subject: " + subject); + logger.info("onDomainCreate; topic: " + topic + "; subject: " + subject); try { long id = parseForId(event.getResourceType(), event.getDescription()); if (id != 0) { DomainVO domain = _domainDao.findById(id); if (domain != null) { - s_logger.info("createDomain for name: " + domain.getName() + "; uuid: " + domain.getUuid()); + logger.info("createDomain for name: " + domain.getName() + "; uuid: " + domain.getUuid()); StringBuffer logMesg = new StringBuffer(); _dbSync.createDomain(domain, logMesg); } else { @@ -201,18 +202,18 @@ public void onDomainCreate(String subject, String topic, org.apache.cloudstack.f _dbSync.syncClass(net.juniper.contrail.api.types.Domain.class); } } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); } } public void onProjectCreate(String subject, String topic, org.apache.cloudstack.framework.events.Event event) { - s_logger.info("onProjectCreate; topic: " + topic + "; subject: " + subject); + logger.info("onProjectCreate; topic: " + topic + "; subject: " + subject); try { long id = parseForId(event.getResourceType(), event.getDescription()); if (id != 0) { ProjectVO project = _projectDao.findById(id); if (project != null) { - s_logger.info("createProject for name: " + project.getName() + "; uuid: " + project.getUuid()); + logger.info("createProject for name: " + project.getName() + "; uuid: " + project.getUuid()); StringBuffer logMesg = new StringBuffer(); _dbSync.createProject(project, logMesg); } else { @@ -224,7 +225,7 @@ public void onProjectCreate(String subject, String topic, org.apache.cloudstack. _dbSync.syncClass(net.juniper.contrail.api.types.Project.class); } } catch (Exception e) { - s_logger.info(e); + logger.info(e); } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java index d754e143411e..08941c56e3c5 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/management/ServiceManagerImpl.java @@ -31,7 +31,8 @@ import org.apache.cloudstack.network.contrail.model.ServiceInstanceModel; import org.apache.cloudstack.network.contrail.model.VirtualMachineModel; import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.api.ApiDBUtils; import com.cloud.dc.DataCenter; @@ -63,7 +64,7 @@ import net.juniper.contrail.api.types.ServiceInstance; public class ServiceManagerImpl implements ServiceManager { - private static final Logger s_logger = Logger.getLogger(ServiceManager.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject UserDao _userDao; @@ -140,7 +141,7 @@ private ServiceVirtualMachine createServiceVM(DataCenter zone, Account owner, Vi @Override public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owner, VirtualMachineTemplate template, ServiceOffering serviceOffering, String name, Network left, Network right) { - s_logger.debug("createServiceInstance by " + owner.getAccountName()); + logger.debug("createServiceInstance by " + owner.getAccountName()); // TODO: permission model. // service instances need to be able to access the public network. if (left.getTrafficType() == TrafficType.Guest) { @@ -166,7 +167,7 @@ public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owne try { project = _manager.getVncProject(owner.getDomainId(), owner.getAccountId()); } catch (IOException ex) { - s_logger.warn("read project", ex); + logger.warn("read project", ex); throw new CloudRuntimeException(ex); } @@ -176,7 +177,7 @@ public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owne throw new InvalidParameterValueException("service-instance " + name + " already exists uuid=" + srvid); } } catch (IOException ex) { - s_logger.warn("service-instance lookup", ex); + logger.warn("service-instance lookup", ex); throw new CloudRuntimeException(ex); } @@ -187,18 +188,18 @@ public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owne try { serviceModel.update(_manager.getModelController()); } catch (Exception ex) { - s_logger.warn("service-instance update", ex); + logger.warn("service-instance update", ex); throw new CloudRuntimeException(ex); } - s_logger.debug("service-instance object created"); + logger.debug("service-instance object created"); ServiceInstance siObj; try { _manager.getDatabase().getServiceInstances().add(serviceModel); siObj = serviceModel.getServiceInstance(); } catch (Exception ex) { - s_logger.warn("DB add", ex); + logger.warn("DB add", ex); throw new CloudRuntimeException(ex); } @@ -206,7 +207,7 @@ public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owne String svmName = name.replace(" ", "_") + "-1"; ServiceVirtualMachine svm = createServiceVM(zone, owner, template, serviceOffering, svmName, siObj, left, right); - s_logger.debug("created VMInstance " + svm.getUuid()); + logger.debug("created VMInstance " + svm.getUuid()); // 3. Create the virtual-machine model and push the update. VirtualMachineModel instanceModel = new VirtualMachineModel(svm, svm.getUuid()); @@ -215,7 +216,7 @@ public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owne instanceModel.setServiceInstance(_manager.getModelController(), svm, serviceModel); instanceModel.update(_manager.getModelController()); } catch (Exception ex) { - s_logger.warn("service virtual-machine update", ex); + logger.warn("service virtual-machine update", ex); throw new CloudRuntimeException(ex); } @@ -224,7 +225,7 @@ public ServiceVirtualMachine createServiceInstance(DataCenter zone, Account owne @Override public void startServiceInstance(long instanceId) { - s_logger.debug("start service instance " + instanceId); + logger.debug("start service instance " + instanceId); UserVmVO vm = _vmDao.findById(instanceId); _vmManager.start(vm.getUuid(), null); @@ -232,7 +233,7 @@ public void startServiceInstance(long instanceId) { @Override public ServiceInstanceResponse createServiceInstanceResponse(long instanceId) { - s_logger.debug("ServiceInstance response for id: " + instanceId); + logger.debug("ServiceInstance response for id: " + instanceId); UserVmVO vm = _vmDao.findById(instanceId); ServiceInstanceResponse response = new ServiceInstanceResponse(); diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/FloatingIpModel.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/FloatingIpModel.java index 23bd911d8fef..4a411fa809d1 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/FloatingIpModel.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/FloatingIpModel.java @@ -22,7 +22,6 @@ import net.juniper.contrail.api.ApiConnector; import net.juniper.contrail.api.types.FloatingIp; -import org.apache.log4j.Logger; import org.apache.cloudstack.network.contrail.management.ContrailManager; @@ -34,7 +33,6 @@ import com.cloud.vm.VMInstanceVO; public class FloatingIpModel extends ModelObjectBase { - private static final Logger s_logger = Logger.getLogger(FloatingIpModel.class); private String _uuid; private long _id; @@ -95,7 +93,7 @@ public void delete(ModelController controller) throws IOException { try { api.delete(FloatingIp.class, _uuid); } catch (IOException ex) { - s_logger.warn("floating ip delete", ex); + logger.warn("floating ip delete", ex); } } @@ -159,7 +157,7 @@ public void update(ModelController controller) throws InternalErrorException, IO Long vmId = ipAddrVO.getAssociatedWithVmId(); Long networkId = ipAddrVO.getAssociatedWithNetworkId(); if (vmId == null || networkId == null) { - s_logger.debug("Floating ip is not yet associated to either vm or network"); + logger.debug("Floating ip is not yet associated to either vm or network"); return; } NicVO nic = controller.getNicDao().findByNtwkIdAndInstanceId(networkId, vmId); @@ -180,7 +178,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.create(fip); } catch (Exception ex) { - s_logger.debug("floating ip create", ex); + logger.debug("floating ip create", ex); throw new CloudRuntimeException("Failed to create floating ip", ex); } _fip = fip; @@ -188,7 +186,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.update(fip); } catch (IOException ex) { - s_logger.warn("floating ip update", ex); + logger.warn("floating ip update", ex); throw new CloudRuntimeException("Unable to update floating ip object", ex); } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/FloatingIpPoolModel.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/FloatingIpPoolModel.java index 31a29b79abbe..1ae7dc924d32 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/FloatingIpPoolModel.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/FloatingIpPoolModel.java @@ -23,7 +23,6 @@ import net.juniper.contrail.api.ApiConnector; import net.juniper.contrail.api.types.FloatingIpPool; -import org.apache.log4j.Logger; import org.apache.cloudstack.network.contrail.management.ContrailManager; @@ -31,7 +30,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class FloatingIpPoolModel extends ModelObjectBase { - private static final Logger s_logger = Logger.getLogger(FloatingIpPoolModel.class); private String _name; @@ -87,7 +85,7 @@ public void delete(ModelController controller) throws IOException { } _fipPool = null; } catch (IOException ex) { - s_logger.warn("floating ip pool delete", ex); + logger.warn("floating ip pool delete", ex); } } @@ -140,7 +138,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.create(fipPool); } catch (Exception ex) { - s_logger.debug("floating ip pool create", ex); + logger.debug("floating ip pool create", ex); throw new CloudRuntimeException("Failed to create floating ip pool", ex); } _fipPool = fipPool; @@ -148,7 +146,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.update(fipPool); } catch (IOException ex) { - s_logger.warn("floating ip pool update", ex); + logger.warn("floating ip pool update", ex); throw new CloudRuntimeException("Unable to update floating ip ppol object", ex); } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/InstanceIpModel.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/InstanceIpModel.java index 8693e61a72b0..2acc0fb14314 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/InstanceIpModel.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/InstanceIpModel.java @@ -25,12 +25,10 @@ import net.juniper.contrail.api.types.VirtualMachineInterface; import net.juniper.contrail.api.types.VirtualNetwork; -import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; public class InstanceIpModel extends ModelObjectBase { - private static final Logger s_logger = Logger.getLogger(InstanceIpModel.class); private String _name; private String _uuid; @@ -47,7 +45,7 @@ public void addToVMInterface(VMInterfaceModel vmiModel) { _vmiModel = vmiModel; if (vmiModel != null) { vmiModel.addSuccessor(this); - s_logger.debug("vmiModel has " + vmiModel.successors().size() + " IP addresses"); + logger.debug("vmiModel has " + vmiModel.successors().size() + " IP addresses"); } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ModelObject.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ModelObject.java index f829d3c45297..fce3a46e2e96 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ModelObject.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ModelObject.java @@ -22,7 +22,8 @@ import java.lang.ref.WeakReference; import java.util.TreeSet; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.exception.InternalErrorException; @@ -45,7 +46,7 @@ public interface ModelObject { public static class ModelReference implements Comparable, Serializable { private static final long serialVersionUID = -2019113974956703526L; - private static final Logger s_logger = Logger.getLogger(ModelReference.class); + protected Logger logger = LogManager.getLogger(getClass()); /* * WeakReference class is not serializable by definition. So, we cannot enforce its serialization unless we write the implementation of diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ModelObjectBase.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ModelObjectBase.java index 52bcd9392268..0c13951a8aaf 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ModelObjectBase.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ModelObjectBase.java @@ -17,11 +17,15 @@ package org.apache.cloudstack.network.contrail.model; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + import java.io.Serializable; import java.util.Comparator; import java.util.TreeSet; public abstract class ModelObjectBase implements ModelObject { + protected Logger logger = LogManager.getLogger(getClass()); public static class UuidComparator implements Comparator, Serializable { @Override public int compare(ModelObject lhs, ModelObject rhs) { diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/NetworkPolicyModel.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/NetworkPolicyModel.java index 1b509dc26550..d53d045ed5b1 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/NetworkPolicyModel.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/NetworkPolicyModel.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.network.Networks; @@ -43,7 +42,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class NetworkPolicyModel extends ModelObjectBase { - private static final Logger s_logger = Logger.getLogger(NetworkPolicyModel.class); private String _uuid; private String _fqName; @@ -82,7 +80,7 @@ public NetworkVO cidrToNetwork(ModelController controller, String cidr) { return null; } if (dbNets.size() > 1) { - s_logger.warn("more than one network found with cidr: " + cidr); + logger.warn("more than one network found with cidr: " + cidr); } return dbNets.get(0); } @@ -235,7 +233,7 @@ public String getUuid() { public void update(ModelController controller) throws InternalErrorException, IOException { ApiConnector api = controller.getApiAccessor(); if (_project == null) { - s_logger.debug("Project is null for the policy: " + _name); + logger.debug("Project is null for the policy: " + _name); throw new IOException("Project is null for the policy: " + _name); } @@ -254,7 +252,7 @@ public void update(ModelController controller) throws InternalErrorException, IO policy.setParent(_project); } } catch (IOException ex) { - s_logger.warn("network-policy read", ex); + logger.warn("network-policy read", ex); return; } } @@ -264,7 +262,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.create(policy); } catch (Exception ex) { - s_logger.debug("network policy create", ex); + logger.debug("network policy create", ex); throw new CloudRuntimeException("Failed to create network policy", ex); } _policy = policy; @@ -272,7 +270,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.update(policy); } catch (IOException ex) { - s_logger.warn("network policy update", ex); + logger.warn("network policy update", ex); throw new CloudRuntimeException("Unable to update network policy", ex); } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ServiceInstanceModel.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ServiceInstanceModel.java index d0db7b80b521..7f2bfe73e891 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ServiceInstanceModel.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/ServiceInstanceModel.java @@ -32,14 +32,12 @@ import org.apache.cloudstack.network.contrail.management.ContrailManager; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.offering.ServiceOffering; import com.cloud.template.VirtualMachineTemplate; import com.cloud.utils.exception.CloudRuntimeException; public class ServiceInstanceModel extends ModelObjectBase { - private static final Logger s_logger = Logger.getLogger(ServiceInstanceModel.class); private String _uuid; private String _fqName; @@ -125,7 +123,7 @@ public void build(ModelController controller, ServiceInstance siObj) { ServiceTemplate tmpl = (ServiceTemplate)api.findById(ServiceTemplate.class, ref.getUuid()); _templateId = tmpl.getUuid(); } catch (IOException ex) { - s_logger.warn("service-template read", ex); + logger.warn("service-template read", ex); } } } @@ -149,7 +147,7 @@ private ServiceInstance createServiceInstance(ModelController controller) { ApiConnector api = controller.getApiAccessor(); project = (Project)api.findById(Project.class, _projectId); } catch (IOException ex) { - s_logger.warn("project read", ex); + logger.warn("project read", ex); throw new CloudRuntimeException("Unable to create service-instance object", ex); } } @@ -165,7 +163,7 @@ private ServiceInstance createServiceInstance(ModelController controller) { ApiConnector api = controller.getApiAccessor(); api.create(si_obj); } catch (IOException ex) { - s_logger.warn("service-instance create", ex); + logger.warn("service-instance create", ex); throw new CloudRuntimeException("Unable to create service-instance object", ex); } @@ -180,13 +178,13 @@ private void clearServicePolicy(ModelController controller) { _policy.delete(controller.getManager().getModelController()); _policy = null; } catch (Exception e) { - s_logger.error(e); + logger.error(e); } try { _left.update(controller.getManager().getModelController()); _right.update(controller.getManager().getModelController()); } catch (Exception ex) { - s_logger.error("virtual-network update for policy delete: ", ex); + logger.error("virtual-network update for policy delete: ", ex); } } @@ -200,7 +198,7 @@ private NetworkPolicyModel setServicePolicy(ModelController controller) { try { policyModel.build(controller.getManager().getModelController(), _leftName, _rightName, "in-network", siList, "pass"); } catch (Exception e) { - s_logger.error(e); + logger.error(e); return null; } try { @@ -209,7 +207,7 @@ private NetworkPolicyModel setServicePolicy(ModelController controller) { } controller.getManager().getDatabase().getNetworkPolicys().add(policyModel); } catch (Exception ex) { - s_logger.error("network-policy update: ", ex); + logger.error("network-policy update: ", ex); } return policyModel; } @@ -241,7 +239,7 @@ private ServiceTemplate locateServiceTemplate(ModelController controller) { ApiConnector api = controller.getApiAccessor(); tmpl = (ServiceTemplate)api.findById(ServiceTemplate.class, _templateId); } catch (IOException ex) { - s_logger.warn("service-template read", ex); + logger.warn("service-template read", ex); throw new CloudRuntimeException("Unable to create service-template object", ex); } if (tmpl == null) { diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModel.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModel.java index dbfb969f9aeb..87d57b29afff 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModel.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModel.java @@ -20,7 +20,6 @@ import java.io.IOException; import org.apache.cloudstack.network.contrail.management.ContrailManager; -import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; import com.cloud.network.Network; @@ -33,7 +32,6 @@ import net.juniper.contrail.api.types.VirtualMachineInterfacePropertiesType; public class VMInterfaceModel extends ModelObjectBase { - private static final Logger s_logger = Logger.getLogger(VMInterfaceModel.class); private String _uuid; @@ -187,7 +185,7 @@ void setServiceTag(String tag) { @Override public void update(ModelController controller) throws InternalErrorException, IOException { if (!_netActive || !_nicActive) { - s_logger.debug("vm interface update, _netActive: " + _netActive + ", _nicActive: " + _nicActive); + logger.debug("vm interface update, _netActive: " + _netActive + ", _nicActive: " + _nicActive); delete(controller); return; } @@ -246,7 +244,7 @@ public void update(ModelController controller) throws InternalErrorException, IO // TODO: if there are no instance-ip successors present and we have an instance-ip object reference // delete the object. if (ipCount == 0) { - s_logger.warn("virtual-machine-interface " + _uuid + " has no instance-ip"); + logger.warn("virtual-machine-interface " + _uuid + " has no instance-ip"); } } diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java index 550bdde1c216..479ef2a0e5db 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.network.contrail.management.ContrailManager; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; import com.cloud.network.dao.NetworkDao; @@ -45,7 +44,6 @@ import com.google.gson.reflect.TypeToken; public class VirtualMachineModel extends ModelObjectBase { - private static final Logger s_logger = Logger.getLogger(VirtualMachineModel.class); private final String _uuid; private long _instanceId; @@ -81,7 +79,7 @@ public void build(ModelController controller, VMInstanceVO instance) { setProperties(controller, instance); UserVm userVm = controller.getVmDao().findById(instance.getId()); if (userVm != null && userVm.getUserData() != null) { - s_logger.debug("vm " + instance.getInstanceName() + " user data: " + userVm.getUserData()); + logger.debug("vm " + instance.getInstanceName() + " user data: " + userVm.getUserData()); final Gson json = new Gson(); Map kvmap = json.fromJson(userVm.getUserData(), new TypeToken>() { }.getType()); @@ -102,7 +100,7 @@ public void build(ModelController controller, VMInstanceVO instance) { // Throw a CloudRuntimeException in case the UUID is not valid. String message = "Invalid UUID ({0}) given for the service-instance for VM {1}."; message = MessageFormat.format(message, instance.getId(), serviceUuid); - s_logger.warn(message); + logger.warn(message); throw new CloudRuntimeException(message); } } @@ -124,7 +122,7 @@ private void buildServiceInstance(ModelController controller, String serviceUuid try { siObj = (ServiceInstance) api.findById(ServiceInstance.class, serviceUuid); } catch (IOException ex) { - s_logger.warn("service-instance read", ex); + logger.warn("service-instance read", ex); throw new CloudRuntimeException("Unable to read service-instance object", ex); } @@ -166,7 +164,7 @@ public void delete(ModelController controller) throws IOException { try { api.delete(VirtualMachine.class, _uuid); } catch (IOException ex) { - s_logger.warn("virtual-machine delete", ex); + logger.warn("virtual-machine delete", ex); } if (_serviceModel != null) { @@ -235,7 +233,7 @@ boolean isActiveInstance(VMInstanceVO instance) { return false; default: - s_logger.warn("Unknown VMInstance state " + instance.getState().getDescription()); + logger.warn("Unknown VMInstance state " + instance.getState().getDescription()); } return true; } @@ -252,7 +250,7 @@ public void setProperties(ModelController controller, VMInstanceVO instance) { try { _projectId = manager.getProjectId(instance.getDomainId(), instance.getAccountId()); } catch (IOException ex) { - s_logger.warn("project read", ex); + logger.warn("project read", ex); throw new CloudRuntimeException(ex); } _initialized = true; @@ -321,7 +319,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { project = (Project)api.findById(Project.class, _projectId); } catch (IOException ex) { - s_logger.debug("project read", ex); + logger.debug("project read", ex); throw new CloudRuntimeException("Failed to read project", ex); } vm.setParent(project); @@ -339,7 +337,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.create(vm); } catch (Exception ex) { - s_logger.debug("virtual-machine create", ex); + logger.debug("virtual-machine create", ex); throw new CloudRuntimeException("Failed to create virtual-machine", ex); } _vm = vm; @@ -347,7 +345,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.update(vm); } catch (IOException ex) { - s_logger.warn("virtual-machine update", ex); + logger.warn("virtual-machine update", ex); throw new CloudRuntimeException("Unable to update virtual-machine object", ex); } } @@ -367,7 +365,7 @@ public boolean verify(ModelController controller) { try { _vm = (VirtualMachine) api.findById(VirtualMachine.class, _uuid); } catch (IOException e) { - s_logger.error("virtual-machine verify", e); + logger.error("virtual-machine verify", e); } if (_vm == null) { diff --git a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java index 7563714528bb..08a4609c43ef 100644 --- a/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java +++ b/plugins/network-elements/juniper-contrail/src/main/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java @@ -33,7 +33,6 @@ import net.juniper.contrail.api.types.VnSubnetsType; import org.apache.cloudstack.network.contrail.management.ContrailManager; -import org.apache.log4j.Logger; import com.cloud.dc.VlanVO; import com.cloud.dc.dao.VlanDao; @@ -44,7 +43,6 @@ import com.cloud.utils.net.NetUtils; public class VirtualNetworkModel extends ModelObjectBase { - private static final Logger s_logger = Logger.getLogger(VirtualNetworkModel.class); private String _uuid; private long _id; @@ -141,7 +139,7 @@ public void delete(ModelController controller) throws IOException { try { api.delete(VirtualNetwork.class, _uuid); } catch (IOException ex) { - s_logger.warn("virtual-network delete", ex); + logger.warn("virtual-network delete", ex); } } @@ -182,7 +180,7 @@ public void setProperties(ModelController controller, Network network) { try { _uuid = manager.findVirtualNetworkId(network); } catch (IOException ex) { - s_logger.warn("Unable to read virtual-network", ex); + logger.warn("Unable to read virtual-network", ex); } } @@ -191,7 +189,7 @@ public void setProperties(ModelController controller, Network network) { try { _projectId = manager.getProjectId(network.getDomainId(), network.getAccountId()); } catch (IOException ex) { - s_logger.warn("project read", ex); + logger.warn("project read", ex); throw new CloudRuntimeException(ex); } @@ -223,7 +221,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { project = (Project)api.findById(Project.class, _projectId); } catch (IOException ex) { - s_logger.debug("project read", ex); + logger.debug("project read", ex); throw new CloudRuntimeException("Failed to read project", ex); } vn.setParent(project); @@ -248,16 +246,16 @@ public void update(ModelController controller) throws InternalErrorException, IO try { String ipam_id = api.findByName(NetworkIpam.class, null, "default-network-ipam"); if (ipam_id == null) { - s_logger.debug("could not find default-network-ipam"); + logger.debug("could not find default-network-ipam"); return; } ipam = (NetworkIpam)api.findById(NetworkIpam.class, ipam_id); if (ipam == null) { - s_logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id); + logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id); return; } } catch (IOException ex) { - s_logger.error(ex); + logger.error(ex); return; } _ipam = ipam; @@ -287,7 +285,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.create(vn); } catch (Exception ex) { - s_logger.debug("virtual-network create", ex); + logger.debug("virtual-network create", ex); throw new CloudRuntimeException("Failed to create virtual-network", ex); } _vn = vn; @@ -295,7 +293,7 @@ public void update(ModelController controller) throws InternalErrorException, IO try { api.update(vn); } catch (IOException ex) { - s_logger.warn("virtual-network update", ex); + logger.warn("virtual-network update", ex); throw new CloudRuntimeException("Unable to update virtual-network object", ex); } } @@ -321,16 +319,16 @@ public void read(ModelController controller) { try { String ipam_id = api.findByName(NetworkIpam.class, null, "default-network-ipam"); if (ipam_id == null) { - s_logger.debug("could not find default-network-ipam"); + logger.debug("could not find default-network-ipam"); return; } ipam = (NetworkIpam)api.findById(NetworkIpam.class, ipam_id); if (ipam == null) { - s_logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id); + logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id); return; } } catch (IOException ex) { - s_logger.error(ex); + logger.error(ex); return; } _ipam = ipam; @@ -415,7 +413,7 @@ public boolean verify(ModelController controller) { diff.removeAll(vncSubnets); if (!diff.isEmpty()) { - s_logger.debug("Subnets changed, network: " + _name + "; db: " + dbSubnets + ", vnc: " + vncSubnets + ", diff: " + diff); + logger.debug("Subnets changed, network: " + _name + "; db: " + dbSubnets + ", vnc: " + vncSubnets + ", diff: " + diff); return false; } @@ -451,7 +449,7 @@ public boolean compare(ModelController controller, ModelObject o) { try { latest = (VirtualNetworkModel)o; } catch (ClassCastException ex) { - s_logger.warn("Invalid model object is passed to cast to VirtualNetworkModel"); + logger.warn("Invalid model object is passed to cast to VirtualNetworkModel"); return false; } @@ -469,7 +467,7 @@ public boolean compare(ModelController controller, ModelObject o) { List newSubnets = new ArrayList(); if ((currentIpamRefs == null && newIpamRefs != null) || (currentIpamRefs != null && newIpamRefs == null)) { //Check for existence only - s_logger.debug("ipams differ: current=" + currentIpamRefs + ", new=" + newIpamRefs); + logger.debug("ipams differ: current=" + currentIpamRefs + ", new=" + newIpamRefs); return false; } if (currentIpamRefs == null) { @@ -502,7 +500,7 @@ public boolean compare(ModelController controller, ModelObject o) { diff.removeAll(newSubnets); if (!diff.isEmpty()) { - s_logger.debug("Subnets differ, network: " + _name + "; db: " + currentSubnets + ", vnc: " + newSubnets + ", diff: " + diff); + logger.debug("Subnets differ, network: " + _name + "; db: " + currentSubnets + ", vnc: " + newSubnets + ", diff: " + diff); return false; } diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ApiConnectorMockito.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ApiConnectorMockito.java index 0c5df0695571..2cd929479995 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ApiConnectorMockito.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ApiConnectorMockito.java @@ -30,12 +30,10 @@ import net.juniper.contrail.api.ObjectReference; import net.juniper.contrail.api.types.NetworkIpam; -import org.apache.log4j.Logger; import com.google.common.collect.ImmutableMap; public class ApiConnectorMockito implements ApiConnector { - private static final Logger s_logger = Logger.getLogger(ApiConnectorMockito.class); static final Map object_map = new ImmutableMap.Builder().put("network-ipam:default-network-ipam", new NetworkIpam()) .build(); @@ -53,19 +51,16 @@ public ApiConnector getSpy() { @Override public boolean create(ApiObjectBase arg0) throws IOException { - s_logger.debug("create " + arg0.getClass().getName() + " id: " + arg0.getUuid()); return _spy.create(arg0); } @Override public void delete(ApiObjectBase arg0) throws IOException { - s_logger.debug("delete " + arg0.getClass().getName() + " id: " + arg0.getUuid()); _spy.delete(arg0); } @Override public void delete(Class arg0, String arg1) throws IOException { - s_logger.debug("create " + arg0.getName() + " id: " + arg1); _spy.delete(arg0, arg1); } @@ -83,19 +78,16 @@ public ApiObjectBase find(Class arg0, ApiObjectBase arg @Override public ApiObjectBase findByFQN(Class arg0, String arg1) throws IOException { - s_logger.debug("find " + arg0.getName() + " name: " + arg1); return _mock.findByFQN(arg0, arg1); } @Override public ApiObjectBase findById(Class arg0, String arg1) throws IOException { - s_logger.debug("find " + arg0.getName() + " id: " + arg1); return _mock.findById(arg0, arg1); } @Override public String findByName(Class arg0, List arg1) throws IOException { - s_logger.debug("find " + arg0.getName() + " name: " + arg1); return _mock.findByName(arg0, arg1); } @@ -107,31 +99,26 @@ public String findByName(Class arg0, ApiObjectBase arg1 msg.append(" parent: " + arg1.getName()); } msg.append(" name: " + arg2); - s_logger.debug(msg.toString()); return _mock.findByName(arg0, arg1, arg2); } @Override public List getObjects(Class arg0, List> arg1) throws IOException { - s_logger.debug("getObjects" + arg0.getName()); return _mock.getObjects(arg0, arg1); } @Override public List list(Class arg0, List arg1) throws IOException { - s_logger.debug("list" + arg0.getName()); return _mock.list(arg0, arg1); } @Override public boolean read(ApiObjectBase arg0) throws IOException { - s_logger.debug("read " + arg0.getClass().getName() + " id: " + arg0.getUuid()); return _mock.read(arg0); } @Override public boolean update(ApiObjectBase arg0) throws IOException { - s_logger.debug("update " + arg0.getClass().getName() + " id: " + arg0.getUuid()); return _spy.update(arg0); } diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java index 61f83008389c..19e617e9d13b 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/IntegrationTestConfiguration.java @@ -24,7 +24,7 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationGroupDaoImpl; import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDaoImpl; import org.eclipse.jetty.security.IdentityService; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -390,8 +390,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) { } }); Mockito.when( - mock.createAffinityGroup(Matchers.any(String.class), Matchers.any(Long.class), Matchers.any(Long.class), Matchers.any(String.class), Matchers.any(String.class), - Matchers.any(String.class))).thenReturn(gmock); + mock.createAffinityGroup(ArgumentMatchers.any(String.class), ArgumentMatchers.any(Long.class), ArgumentMatchers.any(Long.class), ArgumentMatchers.any(String.class), ArgumentMatchers.any(String.class), + ArgumentMatchers.any(String.class))).thenReturn(gmock); } catch (Exception e) { e.printStackTrace(); } @@ -482,7 +482,7 @@ public DeploymentPlanningManager deploymentPlanningManager() { public DomainChecker domainChecker() { DomainChecker mock = Mockito.mock(DomainChecker.class); try { - Mockito.when(mock.checkAccess(Matchers.any(Account.class), Matchers.any(DataCenter.class))).thenReturn(true); + Mockito.when(mock.checkAccess(ArgumentMatchers.any(Account.class), ArgumentMatchers.any(DataCenter.class))).thenReturn(true); } catch (Exception e) { e.printStackTrace(); } @@ -498,23 +498,23 @@ public EndPointSelector endPointSelector() { public EntityManager entityManager() { EntityManager mock = Mockito.mock(EntityManager.class); try { - Mockito.when(mock.findById(Matchers.same(Account.class), Matchers.anyLong())).thenReturn(_accountDao.findById(Account.ACCOUNT_ID_SYSTEM)); - Mockito.when(mock.findById(Matchers.same(User.class), Matchers.anyLong())).thenReturn(_userDao.findById(User.UID_SYSTEM)); - Mockito.when(mock.findById(Matchers.same(NetworkOffering.class), Matchers.any(Long.class))).thenAnswer(new Answer() { + Mockito.when(mock.findById(ArgumentMatchers.same(Account.class), ArgumentMatchers.anyLong())).thenReturn(_accountDao.findById(Account.ACCOUNT_ID_SYSTEM)); + Mockito.when(mock.findById(ArgumentMatchers.same(User.class), ArgumentMatchers.anyLong())).thenReturn(_userDao.findById(User.UID_SYSTEM)); + Mockito.when(mock.findById(ArgumentMatchers.same(NetworkOffering.class), ArgumentMatchers.any(Long.class))).thenAnswer(new Answer() { @Override public NetworkOffering answer(final InvocationOnMock invocation) throws Throwable { Long id = (Long)invocation.getArguments()[1]; return _networkOfferingDao.findById(id); } }); - Mockito.when(mock.findById(Matchers.same(IpAddress.class), Matchers.any(Long.class))).thenAnswer(new Answer() { + Mockito.when(mock.findById(ArgumentMatchers.same(IpAddress.class), ArgumentMatchers.any(Long.class))).thenAnswer(new Answer() { @Override public IpAddress answer(final InvocationOnMock invocation) throws Throwable { Long id = (Long)invocation.getArguments()[1]; return _ipAddressDao.findById(id); } }); - Mockito.when(mock.findById(Matchers.same(DataCenter.class), Matchers.any(Long.class))).thenAnswer(new Answer() { + Mockito.when(mock.findById(ArgumentMatchers.same(DataCenter.class), ArgumentMatchers.any(Long.class))).thenAnswer(new Answer() { @Override public DataCenter answer(final InvocationOnMock invocation) throws Throwable { Long id = (Long)invocation.getArguments()[1]; diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java index 99d46d57f670..c630f0bf6b97 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java @@ -27,8 +27,7 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -87,7 +86,6 @@ import com.cloud.vm.dao.UserVmDao; public class ManagementServerMock { - private static final Logger s_logger = Logger.getLogger(ManagementServerMock.class); @Inject private AccountManager _accountMgr; @@ -126,7 +124,6 @@ static void setParameter(BaseCmd cmd, String name, BaseCmd.CommandType fieldType try { field = cls.getDeclaredField(name); } catch (Exception ex) { - s_logger.warn("class: " + cls.getName() + "\t" + ex); return; } field.setAccessible(true); @@ -135,7 +132,6 @@ static void setParameter(BaseCmd cmd, String name, BaseCmd.CommandType fieldType try { field.set(cmd, value); } catch (Exception ex) { - s_logger.warn(ex); return; } break; @@ -144,7 +140,6 @@ static void setParameter(BaseCmd cmd, String name, BaseCmd.CommandType fieldType try { field.setLong(cmd, -1L); } catch (Exception ex) { - s_logger.warn(ex); return; } } @@ -153,7 +148,6 @@ static void setParameter(BaseCmd cmd, String name, BaseCmd.CommandType fieldType try { field.set(cmd, value); } catch (Exception ex) { - s_logger.warn(ex); return; } break; @@ -161,7 +155,6 @@ static void setParameter(BaseCmd cmd, String name, BaseCmd.CommandType fieldType try { field.set(cmd, value); } catch (Exception ex) { - s_logger.warn(ex); return; } break; @@ -186,8 +179,6 @@ private void createPublicVlanIpRange() { if (nets != null && !nets.isEmpty()) { NetworkVO public_net = nets.get(0); public_net_id = public_net.getId(); - } else { - s_logger.debug("no public network found in the zone: " + _zone.getId()); } Account system = _accountMgr.getSystemAccount(); @@ -200,11 +191,9 @@ private void createPublicVlanIpRange() { setParameter(cmd, "networkID", BaseCmd.CommandType.LONG, public_net_id); setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, _zone.getId()); setParameter(cmd, "vlan", BaseCmd.CommandType.STRING, "untagged"); - s_logger.debug("createPublicVlanIpRange execute : zone id: " + _zone.getId() + ", public net id: " + public_net_id); try { _configService.createVlanAndPublicIpRange(cmd); } catch (Exception e) { - s_logger.debug("createPublicVlanIpRange: " + e); } } @@ -229,7 +218,7 @@ public Object answer(InvocationOnMock invocation) { } }; try { - Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback); + Mockito.when(_agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Commands.class))).thenAnswer(callback); } catch (AgentUnavailableException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -278,7 +267,7 @@ public Object answer(InvocationOnMock invocation) { }; try { - Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback); + Mockito.when(_agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Commands.class))).thenAnswer(callback); } catch (AgentUnavailableException e) { e.printStackTrace(); } catch (OperationTimedoutException e) { @@ -360,7 +349,6 @@ private void locatePhysicalNetwork() { Pair, Integer> providers = _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrailRouter.getName(), null, null, null); if (providers.second() == 0) { - s_logger.debug("Add " + Provider.JuniperContrailRouter.getName() + " to network " + _znet.getName()); PhysicalNetworkServiceProvider provider = _networkService.addProviderToPhysicalNetwork(_znet.getId(), Provider.JuniperContrailRouter.getName(), null, null); _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Enabled.toString(), null); } else { @@ -371,12 +359,10 @@ private void locatePhysicalNetwork() { } providers = _networkService.listNetworkServiceProviders(_znet.getId(), null, PhysicalNetworkServiceProvider.State.Enabled.toString(), null, null); - s_logger.debug(_znet.getName() + " has " + providers.second().toString() + " Enabled providers"); for (PhysicalNetworkServiceProvider provider : providers.first()) { if (provider.getProviderName().equals(Provider.JuniperContrailRouter.getName())) { continue; } - s_logger.debug("Disabling " + provider.getProviderName()); _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Disabled.toString(), null); } } diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/MockAccountManager.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/MockAccountManager.java index 67cfe1df3e1b..6bb9752d7640 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/MockAccountManager.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/MockAccountManager.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.UserTwoFactorAuthenticationSetupResponse; import org.apache.cloudstack.auth.UserTwoFactorAuthenticator; import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.RoleType; @@ -73,7 +72,6 @@ import com.cloud.utils.db.TransactionStatus; public class MockAccountManager extends ManagerBase implements AccountManager { - private static final Logger s_logger = Logger.getLogger(MockAccountManager.class); @Inject AccountDao _accountDao; @@ -98,7 +96,7 @@ public boolean configure(final String name, final Map params) th throw new ConfigurationException("Unable to find the system user using " + User.UID_SYSTEM); } CallContext.register(_systemUser, _systemAccount); - s_logger.info("MockAccountManager initialization successful"); + logger.info("MockAccountManager initialization successful"); return true; } @@ -348,6 +346,11 @@ public UserTwoFactorAuthenticationSetupResponse setupUserTwoFactorAuthentication return null; } + @Override + public List getApiNameList() { + return null; + } + @Override public boolean deleteUserAccount(long arg0) { // TODO Auto-generated method stub @@ -511,4 +514,14 @@ public String getConfigComponentName() { public ConfigKey[] getConfigKeys() { return null; } + + public void validateUserPasswordAndUpdateIfNeeded(String newPassword, UserVO user, + String currentPassword, + boolean skipCurrentPassValidation) { + } + + @Override + public void checkApiAccess(Account account, String command) throws PermissionDeniedException { + + } } diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java index 3ad36acc1601..cbd93669c689 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.command.user.project.DeleteProjectCmd; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.utils.identity.ManagementServerNode; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -89,7 +88,6 @@ * Exercise the public API. */ public class NetworkProviderTest extends TestCase { - private static final Logger s_logger = Logger.getLogger(NetworkProviderTest.class); @Inject public ContrailManager _contrailMgr; @@ -122,9 +120,7 @@ public class NetworkProviderTest extends TestCase { @BeforeClass public static void globalSetUp() throws Exception { ApiConnectorFactory.setImplementation(ApiConnectorMock.class); - s_logger.info("mysql server is getting launched "); s_mysqlSrverPort = TestDbSetup.init(null); - s_logger.info("mysql server launched on port " + s_mysqlSrverPort); s_msId = ManagementServerNode.getManagementServerId(); s_lockController = Merovingian2.createLockController(s_msId); @@ -143,7 +139,6 @@ public static void globalTearDown() throws Exception { } ctx.close(); - s_logger.info("destroying mysql server instance running at port <" + s_mysqlSrverPort + ">"); TestDbSetup.destroy(s_mysqlSrverPort, null); } @@ -154,7 +149,6 @@ public void setUp() throws Exception { ComponentContext.initComponentsLifeCycle(); } catch (Exception ex) { ex.printStackTrace(); - s_logger.error(ex.getMessage()); } Account system = _accountMgr.getSystemAccount(); User user = _accountMgr.getSystemUser(); @@ -177,7 +171,6 @@ private void purgeTestNetwork() { DataCenter zone = _server.getZone(); List list = _networkService.getIsolatedNetworksOwnedByAccountInZone(zone.getId(), system); for (Network net : list) { - s_logger.debug("Delete network " + net.getName()); _networkService.deleteNetwork(net.getId(), false); } } @@ -264,7 +257,6 @@ public void deleteFloatingIp(IPAddressVO ip) throws Exception { try { proxy.execute(); } catch (Exception e) { - s_logger.debug("DisableStaticNatCmd exception: " + e); e.printStackTrace(); throw e; } @@ -284,7 +276,6 @@ public IPAddressVO createFloatingIp(Network network, UserVm vm) throws Exception ((AssociateIPAddrCmd)cmd).create(); ((AssociateIPAddrCmd)cmd).execute(); } catch (Exception e) { - s_logger.debug("AssociateIPAddrCmd exception: " + e); e.printStackTrace(); throw e; } @@ -310,7 +301,6 @@ public IPAddressVO createFloatingIp(Network network, UserVm vm) throws Exception try { proxy.execute(); } catch (Exception e) { - s_logger.debug("EnableStaticNatCmd exception: " + e); e.printStackTrace(); throw e; } @@ -330,7 +320,6 @@ public void createProject(String name) { ((CreateProjectCmd)proxy).create(); ((CreateProjectCmd)proxy).execute(); } catch (Exception e) { - s_logger.debug("CreateProjectCmd exception: " + e); e.printStackTrace(); fail("create project cmd failed"); } @@ -465,11 +454,11 @@ public void dbSyncTest() { //now db sync if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_UPDATE) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) { - s_logger.info("# Cloudstack DB & VNC are out of sync - resync done"); + //# Cloudstack DB & VNC are out of sync - resync done } if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_CHECK) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) { - s_logger.info("# Cloudstack DB & VNC are still out of sync"); + //# Cloudstack DB & VNC are still out of sync fail("DB Sync failed"); } } diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/PublicNetworkTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/PublicNetworkTest.java index 9564ec0a24ab..914545e26830 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/PublicNetworkTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/management/PublicNetworkTest.java @@ -33,7 +33,6 @@ import net.juniper.contrail.api.types.VirtualMachineInterface; import net.juniper.contrail.api.types.VirtualNetwork; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -60,7 +59,6 @@ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:/publicNetworkContext.xml") public class PublicNetworkTest extends TestCase { - private static final Logger s_logger = Logger.getLogger(PublicNetworkTest.class); @Inject public ContrailManager _contrailMgr; @@ -77,9 +75,7 @@ public class PublicNetworkTest extends TestCase { @BeforeClass public static void globalSetUp() throws Exception { ApiConnectorFactory.setImplementation(ApiConnectorMockito.class); - s_logger.info("mysql server is getting launched "); s_mysqlServerPort = TestDbSetup.init(null); - s_logger.info("mysql server launched on port " + s_mysqlServerPort); s_msId = ManagementServerNode.getManagementServerId(); s_lockController = Merovingian2.createLockController(s_msId); } @@ -97,7 +93,6 @@ public static void globalTearDown() throws Exception { } ctx.close(); - s_logger.info("destroying mysql server instance running at port <" + s_mysqlServerPort + ">"); TestDbSetup.destroy(s_mysqlServerPort, null); } @@ -108,7 +103,6 @@ public void setUp() throws Exception { ComponentContext.initComponentsLifeCycle(); } catch (Exception ex) { ex.printStackTrace(); - s_logger.error(ex.getMessage()); } _server = ComponentContext.inject(new ManagementServerMock()); diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java index 06ea2d986c01..fa0f2afcc6d5 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/InstanceIpModelTest.java @@ -17,9 +17,9 @@ package org.apache.cloudstack.network.contrail.model; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -27,7 +27,6 @@ import java.util.UUID; import org.apache.cloudstack.network.contrail.management.ContrailManagerImpl; -import org.apache.log4j.Logger; import org.junit.Test; import com.cloud.network.Network; @@ -44,8 +43,6 @@ import net.juniper.contrail.api.ApiConnectorMock; public class InstanceIpModelTest extends TestCase { - private static final Logger s_logger = - Logger.getLogger(InstanceIpModelTest.class); @Test public void testCreateInstanceIp() throws IOException { diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModelTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModelTest.java index 71238a91e816..5339066dd007 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModelTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VMInterfaceModelTest.java @@ -17,9 +17,9 @@ package org.apache.cloudstack.network.contrail.model; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -27,7 +27,6 @@ import java.util.UUID; import org.apache.cloudstack.network.contrail.management.ContrailManagerImpl; -import org.apache.log4j.Logger; import org.junit.Test; import com.cloud.network.Network; @@ -45,8 +44,6 @@ import net.juniper.contrail.api.types.VirtualMachineInterface; public class VMInterfaceModelTest extends TestCase { - private static final Logger s_logger = - Logger.getLogger(VMInterfaceModelTest.class); @Test public void testCreateVMInterface() throws IOException { diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModelTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModelTest.java index dec4a409aea3..0219c3200deb 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModelTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualMachineModelTest.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.network.contrail.model; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -30,7 +30,6 @@ import org.apache.cloudstack.network.contrail.management.ContrailManagerImpl; import org.apache.cloudstack.network.contrail.management.ModelDatabase; -import org.apache.log4j.Logger; import org.junit.Test; import com.cloud.network.Network; @@ -40,8 +39,6 @@ import com.cloud.vm.dao.UserVmDao; public class VirtualMachineModelTest extends TestCase { - private static final Logger s_logger = - Logger.getLogger(VirtualMachineModelTest.class); @Test public void testVirtualMachineDBLookup() { @@ -60,7 +57,6 @@ public void testVirtualMachineDBLookup() { VirtualMachineModel vm2 = new VirtualMachineModel(vm, "fbc1f8fa-4b78-45ee-bba0-b551dbf94575"); db.getVirtualMachines().add(vm2); - s_logger.debug("No of Vitual Machines added to database : " + db.getVirtualMachines().size()); assertEquals(3, db.getVirtualMachines().size()); diff --git a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModelTest.java b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModelTest.java index e4abfc97711e..2b2cd9af9f06 100644 --- a/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModelTest.java +++ b/plugins/network-elements/juniper-contrail/src/test/java/org/apache/cloudstack/network/contrail/model/VirtualNetworkModelTest.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.network.contrail.management.ContrailManager; import org.apache.cloudstack.network.contrail.management.ContrailManagerImpl; import org.apache.cloudstack.network.contrail.management.ModelDatabase; -import org.apache.log4j.Logger; import org.junit.Before; import org.junit.Test; @@ -47,7 +46,6 @@ public class VirtualNetworkModelTest extends TestCase { - private static final Logger s_logger = Logger.getLogger(VirtualNetworkModelTest.class); private ModelController controller; @@ -144,8 +142,6 @@ public void testDBLookup() { db.getVirtualNetworks().add(guestModel1); VirtualNetworkModel guestModel2 = new VirtualNetworkModel(network, UUID.randomUUID().toString(), "test", TrafficType.Guest); db.getVirtualNetworks().add(guestModel2); - s_logger.debug("networks: " + db.getVirtualNetworks().size()); - s_logger.debug("No of Vitual Networks added to database : " + db.getVirtualNetworks().size()); assertEquals(4, db.getVirtualNetworks().size()); assertSame(storageModel, db.lookupVirtualNetwork(null, storageModel.getName(), TrafficType.Storage)); assertSame(mgmtModel, db.lookupVirtualNetwork(null, mgmtModel.getName(), TrafficType.Management)); diff --git a/plugins/network-elements/juniper-contrail/src/test/resources/commonContext.xml b/plugins/network-elements/juniper-contrail/src/test/resources/commonContext.xml index 77c2365fba88..708b8dbb6c52 100644 --- a/plugins/network-elements/juniper-contrail/src/test/resources/commonContext.xml +++ b/plugins/network-elements/juniper-contrail/src/test/resources/commonContext.xml @@ -1,18 +1,18 @@ - - + diff --git a/plugins/network-elements/juniper-contrail/src/test/resources/mysql_db_start.sh b/plugins/network-elements/juniper-contrail/src/test/resources/mysql_db_start.sh index 265cdea40be7..86c8bdaaa9ca 100644 --- a/plugins/network-elements/juniper-contrail/src/test/resources/mysql_db_start.sh +++ b/plugins/network-elements/juniper-contrail/src/test/resources/mysql_db_start.sh @@ -47,5 +47,5 @@ echo "new mysql server is started on port "$PORT echo $db echo "commands ...." -echo "to connect(from local host): mysql -h 127.0.0.1 -P "$PORT +echo "to connect(from local host): mysql -h 127.0.0.1 -P "$PORT echo "to stop: mysqladmin -S /tmp/mysql"$PORT"/mysqld.sock shutdown -u root" diff --git a/plugins/network-elements/juniper-contrail/src/test/resources/providerContext.xml b/plugins/network-elements/juniper-contrail/src/test/resources/providerContext.xml index fc7e10b5d5c2..adf0e1994809 100644 --- a/plugins/network-elements/juniper-contrail/src/test/resources/providerContext.xml +++ b/plugins/network-elements/juniper-contrail/src/test/resources/providerContext.xml @@ -22,7 +22,7 @@ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd diff --git a/plugins/network-elements/juniper-contrail/src/test/resources/publicNetworkContext.xml b/plugins/network-elements/juniper-contrail/src/test/resources/publicNetworkContext.xml index b2c28d2b29b6..a8edec62d1f3 100644 --- a/plugins/network-elements/juniper-contrail/src/test/resources/publicNetworkContext.xml +++ b/plugins/network-elements/juniper-contrail/src/test/resources/publicNetworkContext.xml @@ -1,20 +1,20 @@ - configParams = new HashMap(); @@ -595,7 +593,7 @@ public ExternalLoadBalancerDeviceVO addNetscalerLoadBalancer(AddNetscalerLoadBal if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) { String msg = "Only Netscaler VPX load balancers can be specified for dedicated use"; - s_logger.debug(msg); + logger.debug(msg); throw new InvalidParameterValueException(msg); } @@ -604,13 +602,13 @@ public ExternalLoadBalancerDeviceVO addNetscalerLoadBalancer(AddNetscalerLoadBal if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName()) && !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) { String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider"; - s_logger.debug(msg); + logger.debug(msg); throw new InvalidParameterValueException(msg); } if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) { String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider"; - s_logger.debug(msg); + logger.debug(msg); throw new InvalidParameterValueException(msg); } @@ -762,7 +760,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { try { _agentMgr.reconnect(host.getId()); } catch (AgentUnavailableException e) { - s_logger.warn("failed to reconnect host " + host, e); + logger.warn("failed to reconnect host " + host, e); } return lbDeviceVo; } @@ -927,7 +925,7 @@ public boolean deleteNetscalerControlCenter(DeleteNetscalerControlCenterCmd cmd) _hostDao.update(ncc.getId(), ncc); _resourceMgr.deleteHost(ncc.getId(), false, false); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); return false; } } @@ -1049,7 +1047,7 @@ public boolean verifyServicesCombination(Set services) { // NetScaler can only act as Lb and Static Nat service provider if (services != null && !services.isEmpty() && !netscalerServices.containsAll(services)) { - s_logger.warn( + logger.warn( "NetScaler network element can only support LB and Static NAT services and service combination " + services + " is not supported."); @@ -1058,10 +1056,10 @@ public boolean verifyServicesCombination(Set services) { buff.append(service.getName()); buff.append(" "); } - s_logger.warn( + logger.warn( "NetScaler network element can only support LB and Static NAT services and service combination " + buff.toString() + " is not supported."); - s_logger.warn( + logger.warn( "NetScaler network element can only support LB and Static NAT services and service combination " + services + " is not supported."); return false; @@ -1103,14 +1101,14 @@ public boolean applyElasticLoadBalancerRules(Network network, List rules) } catch (Exception e) { errMsg = "Could not allocate a NetSclaer load balancer for configuring static NAT rules due to" + e.getMessage(); - s_logger.error(errMsg); + logger.error(errMsg); throw new ResourceUnavailableException(errMsg, this.getClass(), 0); } } if (!isNetscalerDevice(lbDevice.getDeviceName())) { errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element will not be handling the static nat rules."; - s_logger.error(errMsg); + logger.error(errMsg); throw new ResourceUnavailableException(errMsg, this.getClass(), 0); } SetStaticNatRulesAnswer answer = null; @@ -1214,7 +1212,7 @@ public boolean applyStaticNats(Network config, List rules) if (lbDevice == null) { String errMsg = "There is no NetScaler device configured to perform EIP to guest IP address: " + rule.getDestIpAddress(); - s_logger.error(errMsg); + logger.error(errMsg); throw new ResourceUnavailableException(errMsg, this.getClass(), 0); } @@ -1231,7 +1229,7 @@ public boolean applyStaticNats(Network config, List rules) cmd); if (answer == null) { String errMsg = "Failed to configure INAT rule on NetScaler device " + lbDevice.getHostId(); - s_logger.error(errMsg); + logger.error(errMsg); throw new ResourceUnavailableException(errMsg, this.getClass(), 0); } } @@ -1240,7 +1238,7 @@ public boolean applyStaticNats(Network config, List rules) } return true; } catch (Exception e) { - s_logger.error("Failed to configure StaticNat rule due to " + e.getMessage()); + logger.error("Failed to configure StaticNat rule due to " + e.getMessage()); return false; } } @@ -1278,14 +1276,14 @@ public List getElasticLBRulesHealthCheck(Network network, ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network); if (lbDeviceVO == null) { - s_logger.warn( + logger.warn( "There is no external load balancer device assigned to this network either network is not implement are already shutdown so just returning"); return null; } if (!isNetscalerDevice(lbDeviceVO.getDeviceName())) { errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element can not be handle elastic load balancer rules."; - s_logger.error(errMsg); + logger.error(errMsg); throw new ResourceUnavailableException(errMsg, this.getClass(), 0); } @@ -1332,10 +1330,10 @@ public List updateHealthChecks(Network network, List rules) { if (schemeCaps != null) { for (LoadBalancingRule rule : rules) { if (!schemeCaps.contains(rule.getScheme().toString())) { - s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + getName()); return false; } diff --git a/plugins/network-elements/netscaler/src/main/java/com/cloud/network/resource/NetScalerControlCenterResource.java b/plugins/network-elements/netscaler/src/main/java/com/cloud/network/resource/NetScalerControlCenterResource.java index c447d6005610..72186a677c69 100644 --- a/plugins/network-elements/netscaler/src/main/java/com/cloud/network/resource/NetScalerControlCenterResource.java +++ b/plugins/network-elements/netscaler/src/main/java/com/cloud/network/resource/NetScalerControlCenterResource.java @@ -50,7 +50,8 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.BasicClientConnectionManager; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -117,7 +118,7 @@ public class NetScalerControlCenterResource implements ServerResource { private String _sessionid; public static final int DEFAULT_PORT = 443; private static final Gson s_gson = GsonHelper.getGson(); - private static final Logger s_logger = Logger.getLogger(NetScalerControlCenterResource.class); + protected Logger logger = LogManager.getLogger(NetScalerControlCenterResource.class); protected Gson _gson; private final String _objectNamePathSep = "-"; final String protocol="https"; @@ -188,7 +189,7 @@ public boolean configure(String name, Map params) throws Configu } catch (ConfigurationException e) { throw new ConfigurationException(e.getMessage()); } catch (ExecutionException e) { - s_logger.debug("Execution Exception :" + e.getMessage()); + logger.debug("Execution Exception :" + e.getMessage()); throw new ConfigurationException("Failed to add the device. Please check the device is NCC and It is reachable from Management Server."); } } @@ -204,10 +205,10 @@ public void getServicePackages() throws ExecutionException { org.json.JSONObject jsonBody = new JSONObject(); org.json.JSONObject jsonCredentials = new JSONObject(); result = getHttpRequest(jsonBody.toString(), agentUri, _sessionid); - s_logger.debug("List of Service Packages in NCC:: " + result); + logger.debug("List of Service Packages in NCC:: " + result); } catch (URISyntaxException e) { String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } catch (Exception e) { throw new ExecutionException("Failed to log in to NCC device at " + _ip + " due to " + e.getMessage()); @@ -235,18 +236,18 @@ private synchronized String login() throws ExecutionException{ jsonResponse = new JSONObject(result); org.json.JSONArray loginResponse = jsonResponse.getJSONArray("login"); _sessionid = jsonResponse.getJSONArray("login").getJSONObject(0).getString("sessionid"); - s_logger.debug("New Session id from NCC :" + _sessionid); + logger.debug("New Session id from NCC :" + _sessionid); set_nccsession(_sessionid); - s_logger.debug("session on Static Session variable" + get_nccsession()); + logger.debug("session on Static Session variable" + get_nccsession()); } - s_logger.debug("Login to NCC Device response :: " + result); + logger.debug("Login to NCC Device response :: " + result); return result; } catch (URISyntaxException e) { String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } catch (JSONException e) { - s_logger.debug("JSON Exception :" + e.getMessage()); + logger.debug("JSON Exception :" + e.getMessage()); throw new ExecutionException("Failed to log in to NCC device at " + _ip + " due to " + e.getMessage()); } catch (Exception e) { throw new ExecutionException("Failed to log in to NCC device at " + _ip + " due to " + e.getMessage()); @@ -315,7 +316,7 @@ private void keepSessionAlive() throws ExecutionException { "/cs/cca/v1/cloudstacks", null, null); org.json.JSONObject jsonBody = new JSONObject(); getHttpRequest(jsonBody.toString(), agentUri, _sessionid); - s_logger.debug("Keeping Session Alive"); + logger.debug("Keeping Session Alive"); } catch (URISyntaxException e) { e.printStackTrace(); } @@ -336,10 +337,10 @@ private String queryAsyncJob(String jobId) throws ExecutionException { result = getHttpRequest(jsonBody.toString(), agentUri, _sessionid); JSONObject response = new JSONObject(result); if(response != null ) { - s_logger.debug("Job Status result for ["+jobId + "]:: " + result + " Tick and currentTime :" + System.currentTimeMillis() +" -" + startTick + "job cmd timeout :" +_nccCmdTimeout); + logger.debug("Job Status result for ["+jobId + "]:: " + result + " Tick and currentTime :" + System.currentTimeMillis() +" -" + startTick + "job cmd timeout :" +_nccCmdTimeout); String status = response.getJSONObject("journalcontext").getString("status").toUpperCase(); String message = response.getJSONObject("journalcontext").getString("message"); - s_logger.debug("Job Status Progress Status ["+ jobId + "]:: " + status); + logger.debug("Job Status Progress Status ["+ jobId + "]:: " + status); switch(status) { case "FINISHED": return status; @@ -357,7 +358,7 @@ private String queryAsyncJob(String jobId) throws ExecutionException { } catch (URISyntaxException e) { String errMsg = "Could not generate URI for NetScaler ControlCenter"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } catch (JSONException e) { e.printStackTrace(); } @@ -371,25 +372,25 @@ private synchronized Answer execute(NetScalerImplementNetworkCommand cmd, int nu new URI("https", null, _ip, DEFAULT_PORT, "/cs/adcaas/v1/networks", null, null); org.json.JSONObject jsonBody = new JSONObject(cmd.getDetails()); - s_logger.debug("Sending Network Implement to NCC:: " + jsonBody); + logger.debug("Sending Network Implement to NCC:: " + jsonBody); result = postHttpRequest(jsonBody.toString(), agentUri, _sessionid); - s_logger.debug("Result of Network Implement to NCC:: " + result); + logger.debug("Result of Network Implement to NCC:: " + result); result = queryAsyncJob(result); - s_logger.debug("Done query async of network implement request :: " + result); + logger.debug("Done query async of network implement request :: " + result); return new Answer(cmd, true, "Successfully allocated device"); } catch (URISyntaxException e) { String errMsg = "Could not generate URI for NetScaler ControlCenter "; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } catch (ExecutionException e) { if(e.getMessage().equalsIgnoreCase(NccHttpCode.NOT_FOUND)) { return new Answer(cmd, true, "Successfully unallocated the device"); }else if(e.getMessage().startsWith("ERROR, ROLLBACK") ) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); return new Answer(cmd, false, e.getMessage()); } else { if (shouldRetry(numRetries)) { - s_logger.debug("Retrying the command NetScalerImplementNetworkCommand retry count: " + numRetries, e); + logger.debug("Retrying the command NetScalerImplementNetworkCommand retry count: " + numRetries, e); return retry(cmd, numRetries); } else { return new Answer(cmd, false, e.getMessage()); @@ -397,7 +398,7 @@ private synchronized Answer execute(NetScalerImplementNetworkCommand cmd, int nu } } catch (Exception e) { if (shouldRetry(numRetries)) { - s_logger.debug("Retrying the command NetScalerImplementNetworkCommand retry count: " + numRetries, e); + logger.debug("Retrying the command NetScalerImplementNetworkCommand retry count: " + numRetries, e); return retry(cmd, numRetries); } else { return new Answer(cmd, false, e.getMessage()); @@ -448,14 +449,14 @@ private Answer execute(HealthCheckLBConfigCommand cmd, int numRetries) { hcLB.add(loadBalancer); } } catch (ExecutionException e) { - s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e); + logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { return new HealthCheckLBConfigAnswer(hcLB); } } catch (Exception e) { - s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e); + logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { @@ -474,7 +475,7 @@ private String getLBHealthChecks(long networkid) throws ExecutionException { "/cs/adcaas/v1/networks/"+ networkid +"/lbhealthstatus", null, null); org.json.JSONObject jsonBody = new JSONObject(); response = getHttpRequest(jsonBody.toString(), agentUri, _sessionid); - s_logger.debug("LBHealthcheck Response :" + response); + logger.debug("LBHealthcheck Response :" + response); } catch (URISyntaxException e) { e.printStackTrace(); } @@ -494,24 +495,24 @@ private synchronized Answer execute(LoadBalancerConfigCommand cmd, int numRetrie "/cs/adcaas/v1/loadbalancerCmds", null, null); JSONObject lbConfigCmd = new JSONObject(); JSONObject lbcmd = new JSONObject(gsonLBConfig); - s_logger.debug("LB config from gsonstring to JSONObject : " + lbcmd.toString() + "\n" + "gson cmd is :: \t" + gsonLBConfig); + logger.debug("LB config from gsonstring to JSONObject : " + lbcmd.toString() + "\n" + "gson cmd is :: \t" + gsonLBConfig); lbConfigCmd.put("LoadBalancerConfigCommand", lbcmd.getJSONArray("loadBalancers")); - s_logger.debug("LB config paylod : " + lbConfigCmd.toString()); + logger.debug("LB config paylod : " + lbConfigCmd.toString()); String result = postHttpRequest(lbConfigCmd.toString(), agentUri, _sessionid); - s_logger.debug("Result of lbconfigcmg is "+ result); + logger.debug("Result of lbconfigcmg is "+ result); result = queryAsyncJob(result); - s_logger.debug("Done query async of LB ConfigCmd implement request and result:: " + result); + logger.debug("Done query async of LB ConfigCmd implement request and result:: " + result); return new Answer(cmd); } catch (ExecutionException e) { - s_logger.error("Failed to execute LoadBalancerConfigCommand due to ", e); + logger.error("Failed to execute LoadBalancerConfigCommand due to ", e); if(e.getMessage().equalsIgnoreCase(NccHttpCode.NOT_FOUND)) { return new Answer(cmd, true, "LB Rule is not present in NS device. So returning as removed the LB Rule"); } else if(e.getMessage().startsWith("ERROR, ROLLBACK COMPLETED") || e.getMessage().startsWith("ERROR, ROLLBACK FAILED")) { - s_logger.error("Failed to execute LoadBalancerConfigCommand due to : " + e.getMessage()); + logger.error("Failed to execute LoadBalancerConfigCommand due to : " + e.getMessage()); return new Answer(cmd, false, e.getMessage()); } else if (e.getMessage().startsWith(NccHttpCode.INTERNAL_ERROR)) { - s_logger.error("Failed to execute LoadBalancerConfigCommand as Internal Error returning Internal error ::" + e.getMessage() ); + logger.error("Failed to execute LoadBalancerConfigCommand as Internal Error returning Internal error ::" + e.getMessage() ); return new Answer(cmd, false, e.getMessage()); } if (shouldRetry(numRetries)) { @@ -520,7 +521,7 @@ private synchronized Answer execute(LoadBalancerConfigCommand cmd, int numRetrie return new Answer(cmd, false, e.getMessage()); } } catch (Exception e) { - s_logger.error("Failed to execute LoadBalancerConfigCommand due to ", e); + logger.error("Failed to execute LoadBalancerConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { @@ -614,16 +615,16 @@ private ExternalNetworkResourceUsageAnswer getPublicIpBytesSentAndReceived(Exter } } } - s_logger.debug("IPStats Response :" + response); + logger.debug("IPStats Response :" + response); } catch (URISyntaxException e) { e.printStackTrace(); } catch (ExecutionException e) { - s_logger.debug("Seesion Alive" + e.getMessage()); + logger.debug("Seesion Alive" + e.getMessage()); e.printStackTrace(); } } catch (Exception e) { - s_logger.error("Failed to get bytes sent and received statistics due to " + e); + logger.error("Failed to get bytes sent and received statistics due to " + e); throw new ExecutionException(e.getMessage()); } @@ -632,7 +633,7 @@ private ExternalNetworkResourceUsageAnswer getPublicIpBytesSentAndReceived(Exter private Answer retry(Command cmd, int numRetries) { int numRetriesRemaining = numRetries - 1; - s_logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetriesRemaining); + logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetriesRemaining); return executeRequest(cmd, numRetriesRemaining); } @@ -643,7 +644,7 @@ private boolean shouldRetry(int numRetries) { return true; } } catch (Exception e) { - s_logger.error("Failed to log in to Netscaler ControlCenter device at " + _ip + " due to " + e.getMessage()); + logger.error("Failed to log in to Netscaler ControlCenter device at " + _ip + " due to " + e.getMessage()); return false; } return false; @@ -661,7 +662,7 @@ private boolean refreshNCCConnection() { keepSessionAlive(); return true; } catch (ExecutionException ex) { - s_logger.debug("Failed to keep up the session alive ", ex); + logger.debug("Failed to keep up the session alive ", ex); } return ret; } @@ -748,7 +749,7 @@ public static String cleanPassword(String logString) { } return cleanLogString; } - public static HttpClient getHttpClient() { + public HttpClient getHttpClient() { HttpClient httpClient = null; TrustStrategy easyStrategy = new TrustStrategy() { @@ -766,18 +767,18 @@ public boolean isTrusted(X509Certificate[] chain, String authType) ClientConnectionManager ccm = new BasicClientConnectionManager(registry); httpClient = new DefaultHttpClient(ccm); } catch (KeyManagementException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (UnrecoverableKeyException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (NoSuchAlgorithmException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (KeyStoreException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } return httpClient; } - public static String getHttpRequest(final String jsonCmd, final URI agentUri, String sessionID) throws ExecutionException { + public String getHttpRequest(final String jsonCmd, final URI agentUri, String sessionID) throws ExecutionException { // Using Apache's HttpClient for HTTP POST // Java-only approach discussed at on StackOverflow concludes with // comment to use Apache HttpClient @@ -785,7 +786,7 @@ public static String getHttpRequest(final String jsonCmd, final URI agentUri, St // use Apache. String logMessage = StringEscapeUtils.unescapeJava(jsonCmd); logMessage = cleanPassword(logMessage); - s_logger.debug("GET request to " + agentUri.toString() + logger.debug("GET request to " + agentUri.toString() + " with contents " + logMessage); // Create request @@ -802,40 +803,40 @@ public static String getHttpRequest(final String jsonCmd, final URI agentUri, St StringEntity cmdJson = new StringEntity(jsonCmd); request.addHeader("content-type", "application/json"); request.addHeader("Cookie", "SessId=" + sessionID); - s_logger.debug("Sending cmd to " + agentUri.toString() + logger.debug("Sending cmd to " + agentUri.toString() + " cmd data:" + logMessage); HttpResponse response = httpClient.execute(request); // Unsupported commands will not route. if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { String errMsg = "Failed to send : HTTP error code : " + response.getStatusLine().getStatusCode(); - s_logger.error(errMsg); + logger.error(errMsg); String unsupportMsg = "Unsupported command " + agentUri.getPath() + ". Are you sure you got the right f of" + " server?"; Answer ans = new UnsupportedAnswer(null, unsupportMsg); - s_logger.error(ans); + logger.error(ans); result = s_gson.toJson(new Answer[] {ans}); } else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { String errMsg = "Failed send to " + agentUri.toString() + " : HTTP error code : " + response.getStatusLine().getStatusCode(); - s_logger.error(errMsg); + logger.error(errMsg); throw new ExecutionException("UNAUTHORIZED"); } else { result = EntityUtils.toString(response.getEntity()); String logResult = cleanPassword(StringEscapeUtils.unescapeJava(result)); - s_logger.debug("Get response is " + logResult); + logger.debug("Get response is " + logResult); } } catch (ClientProtocolException protocolEx) { // Problem with HTTP message exchange - s_logger.error(protocolEx); + logger.error(protocolEx); } catch (IOException connEx) { // Problem with underlying communications - s_logger.error(connEx); + logger.error(connEx); } finally { httpClient.getConnectionManager().shutdown(); } return result; } - public static String postHttpRequest(final String jsonCmd, final URI agentUri, String sessionID) throws ExecutionException { + public String postHttpRequest(final String jsonCmd, final URI agentUri, String sessionID) throws ExecutionException { // Using Apache's HttpClient for HTTP POST // Java-only approach discussed at on StackOverflow concludes with // comment to use Apache HttpClient @@ -843,7 +844,7 @@ public static String postHttpRequest(final String jsonCmd, final URI agentUri, S // use Apache. String logMessage = StringEscapeUtils.unescapeJava(jsonCmd); logMessage = cleanPassword(logMessage); - s_logger.debug("POST request to " + agentUri.toString() + logger.debug("POST request to " + agentUri.toString() + " with contents " + logMessage); // Create request @@ -863,13 +864,13 @@ public boolean isTrusted(X509Certificate[] chain, String authType) ClientConnectionManager ccm = new BasicClientConnectionManager(registry); httpClient = new DefaultHttpClient(ccm); } catch (KeyManagementException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (UnrecoverableKeyException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (NoSuchAlgorithmException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (KeyStoreException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } String result = null; @@ -885,7 +886,7 @@ public boolean isTrusted(X509Certificate[] chain, String authType) request.addHeader("content-type", "application/json"); request.addHeader("Cookie", "SessId=" + sessionID); request.setEntity(cmdJson); - s_logger.debug("Sending cmd to " + agentUri.toString() + logger.debug("Sending cmd to " + agentUri.toString() + " cmd data:" + logMessage + "SEssion id: " + sessionID); HttpResponse response = httpClient.execute(request); @@ -895,7 +896,7 @@ public boolean isTrusted(X509Certificate[] chain, String authType) throw new ExecutionException(NccHttpCode.NOT_FOUND); } else if ((response.getStatusLine().getStatusCode() != HttpStatus.SC_OK ) && (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED )) { String errMsg = "Command Not Success " + agentUri.toString() + " : HTTP error code : " + response.getStatusLine().getStatusCode(); - s_logger.error(errMsg); + logger.error(errMsg); throw new ExecutionException(NccHttpCode.INTERNAL_ERROR + " " + errMsg); } else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { //Successfully created the resource in the NCC, Now get the Job ID and send to the response @@ -907,15 +908,15 @@ public boolean isTrusted(X509Certificate[] chain, String authType) } else { result = EntityUtils.toString(response.getEntity()); String logResult = cleanPassword(StringEscapeUtils.unescapeJava(result)); - s_logger.debug("POST response is " + logResult); + logger.debug("POST response is " + logResult); } } catch (ClientProtocolException protocolEx) { // Problem with HTTP message exchange - s_logger.error(protocolEx); + logger.error(protocolEx); } catch (IOException connEx) { // Problem with underlying communications - s_logger.error(connEx); + logger.error(connEx); } finally { httpClient.getConnectionManager().shutdown(); } diff --git a/plugins/network-elements/netscaler/src/main/java/com/cloud/network/resource/NetscalerResource.java b/plugins/network-elements/netscaler/src/main/java/com/cloud/network/resource/NetscalerResource.java index 99f7102b13b9..548f5509a890 100644 --- a/plugins/network-elements/netscaler/src/main/java/com/cloud/network/resource/NetscalerResource.java +++ b/plugins/network-elements/netscaler/src/main/java/com/cloud/network/resource/NetscalerResource.java @@ -30,7 +30,8 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.commons.io.output.ByteArrayOutputStream; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bouncycastle.util.io.pem.PemObject; import org.bouncycastle.util.io.pem.PemWriter; @@ -162,7 +163,7 @@ public class NetscalerResource implements ServerResource { private String _publicIPNetmask; private String _publicIPVlan; - private static final Logger s_logger = Logger.getLogger(NetscalerResource.class); + protected static Logger LOGGER = LogManager.getLogger(NetscalerResource.class); protected Gson _gson; private final String _objectNamePathSep = "-"; @@ -471,12 +472,12 @@ private synchronized Answer execute(final IpAssocCommand cmd, final int numRetri saveConfiguration(); results[i++] = ip.getPublicIp() + " - success"; final String action = ip.isAdd() ? "associate" : "remove"; - if (s_logger.isDebugEnabled()) { - s_logger.debug("Netscaler load balancer " + _ip + " successfully executed IPAssocCommand to " + action + " IP " + ip); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Netscaler load balancer " + _ip + " successfully executed IPAssocCommand to " + action + " IP " + ip); } } } catch (final ExecutionException e) { - s_logger.error("Netscaler loadbalancer " + _ip + " failed to execute IPAssocCommand due to " + e.getMessage()); + LOGGER.error("Netscaler loadbalancer " + _ip + " failed to execute IPAssocCommand due to " + e.getMessage()); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { @@ -526,14 +527,14 @@ private Answer execute(final HealthCheckLBConfigCommand cmd, final int numRetrie } } catch (final ExecutionException e) { - s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e); + LOGGER.error("Failed to execute HealthCheckLBConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { return new HealthCheckLBConfigAnswer(hcLB); } } catch (final Exception e) { - s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e); + LOGGER.error("Failed to execute HealthCheckLBConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { @@ -583,8 +584,8 @@ private synchronized Answer execute(final LoadBalancerConfigCommand cmd, final i // create a load balancing virtual server addLBVirtualServer(nsVirtualServerName, srcIp, srcPort, lbAlgorithm, lbProtocol, loadBalancer.getStickinessPolicies(), null); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Created load balancing virtual server " + nsVirtualServerName + " on the Netscaler device"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Created load balancing virtual server " + nsVirtualServerName + " on the Netscaler device"); } // create a new monitor @@ -700,9 +701,9 @@ private synchronized Answer execute(final LoadBalancerConfigCommand cmd, final i pemWriter.writeObject(pemObject); pemWriter.flush(); } catch (final IOException e) { - if (s_logger.isDebugEnabled()) + if (LOGGER.isDebugEnabled()) { - s_logger.debug("couldn't write PEM to a string", e); + LOGGER.debug("couldn't write PEM to a string", e); } // else just close the certDataStream } @@ -732,9 +733,9 @@ private synchronized Answer execute(final LoadBalancerConfigCommand cmd, final i SSL.createSslCertKey(_netscalerService, certFilename, keyFilename, certKeyName, sslCert.getPassword()); } } catch (final IOException e) { - if (s_logger.isDebugEnabled()) + if (LOGGER.isDebugEnabled()) { - s_logger.debug("couldn't open buffer for certificate", e); + LOGGER.debug("couldn't open buffer for certificate", e); } // else just close the certDataStream } @@ -747,8 +748,8 @@ private synchronized Answer execute(final LoadBalancerConfigCommand cmd, final i } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully added LB destination: " + destination.getDestIp() + ":" + destination.getDestPort() + " to load balancer " + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully added LB destination: " + destination.getDestIp() + ":" + destination.getDestPort() + " to load balancer " + srcIp + ":" + srcPort); } @@ -885,21 +886,21 @@ private synchronized Answer execute(final LoadBalancerConfigCommand cmd, final i } - if (s_logger.isInfoEnabled()) { - s_logger.info("Successfully executed resource LoadBalancerConfigCommand: " + _gson.toJson(cmd)); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Successfully executed resource LoadBalancerConfigCommand: " + _gson.toJson(cmd)); } saveConfiguration(); return new Answer(cmd); } catch (final ExecutionException e) { - s_logger.error("Failed to execute LoadBalancerConfigCommand due to ", e); + LOGGER.error("Failed to execute LoadBalancerConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { return new Answer(cmd, e); } } catch (final Exception e) { - s_logger.error("Failed to execute LoadBalancerConfigCommand due to ", e); + LOGGER.error("Failed to execute LoadBalancerConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { @@ -965,7 +966,7 @@ private synchronized Answer execute(final CreateLoadBalancerApplianceCommand cmd try { Thread.sleep(10000); } catch (final InterruptedException e) { - s_logger.debug("[ignored] interrupted while waiting for netscaler to be 'up'."); + LOGGER.debug("[ignored] interrupted while waiting for netscaler to be 'up'."); } final ns refreshNsObj = new ns(); refreshNsObj.set_id(newVpx.get_id()); @@ -1002,8 +1003,8 @@ private synchronized Answer execute(final CreateLoadBalancerApplianceCommand cmd return new Answer(cmd, new ExecutionException("Failed to create VPX instance " + vpxName + " on the netscaler SDX device " + _ip)); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Successfully provisioned VPX instance " + vpxName + " on the Netscaler SDX device " + _ip); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Successfully provisioned VPX instance " + vpxName + " on the Netscaler SDX device " + _ip); } // physical interfaces on the SDX range from 10/1 to 10/8 & 1/1 to 1/8 of which two different port or same port can be used for public and private interfaces @@ -1218,13 +1219,13 @@ private static void createSite(final nitro_service client, final String siteName } else { gslbsite.add(client, site); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully created GSLB site: " + siteName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully created GSLB site: " + siteName); } } catch (final Exception e) { final String errMsg = "Failed to create GSLB site: " + siteName + " due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1237,23 +1238,23 @@ private static void deleteSite(final nitro_service client, final String siteName if (site != null) { final gslbsite_gslbservice_binding[] serviceBindings = gslbsite_gslbservice_binding.get(client, siteName); if (serviceBindings != null && serviceBindings.length > 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("There are services associated with GSLB site: " + siteName + " so ignoring site deletion"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("There are services associated with GSLB site: " + siteName + " so ignoring site deletion"); } } gslbsite.delete(client, siteName); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully deleted GSLB site: " + siteName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully deleted GSLB site: " + siteName); } } else { - if (s_logger.isDebugEnabled()) { - s_logger.warn("Ignoring delete request for non existing GSLB site: " + siteName); + if (LOGGER.isDebugEnabled()) { + LOGGER.warn("Ignoring delete request for non existing GSLB site: " + siteName); } } } catch (final Exception e) { final String errMsg = "Failed to delete GSLB site: " + siteName + " due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1265,8 +1266,8 @@ private static void updateSite(final nitro_service client, final String siteType gslbsite site; site = getSiteObject(client, siteName); if (site == null) { - if (s_logger.isDebugEnabled()) { - s_logger.warn("Ignoring update request for non existing GSLB site: " + siteName); + if (LOGGER.isDebugEnabled()) { + LOGGER.warn("Ignoring update request for non existing GSLB site: " + siteName); } return; } @@ -1280,14 +1281,14 @@ private static void updateSite(final nitro_service client, final String siteType site.set_sessionexchange("ENABLED"); gslbsite.update(client, site); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully updated GSLB site: " + siteName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully updated GSLB site: " + siteName); } } catch (final Exception e) { final String errMsg = "Failed to update GSLB site: " + siteName + " due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1335,14 +1336,14 @@ private static void updateSite(final nitro_service client, final String siteType gslbvserver.add(client, vserver); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully added GSLB virtual server: " + vserverName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully added GSLB virtual server: " + vserverName); } } catch (final Exception e) { final String errMsg = "Failed to add GSLB virtual server: " + vserverName + " due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1354,18 +1355,18 @@ private static void deleteVirtualServer(final nitro_service client, final String final gslbvserver vserver = getVserverObject(client, vserverName); if (vserver != null) { gslbvserver.delete(client, vserver); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully deleted GSLB virtual server: " + vserverName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully deleted GSLB virtual server: " + vserverName); } } else { - if (s_logger.isDebugEnabled()) { - s_logger.warn("Ignoring delete request for non existing GSLB virtual server: " + vserverName); + if (LOGGER.isDebugEnabled()) { + LOGGER.warn("Ignoring delete request for non existing GSLB virtual server: " + vserverName); } } } catch (final Exception e) { final String errMsg = "Failed to delete GSLB virtual server: " + vserverName + " due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1410,13 +1411,13 @@ private static void createService(final nitro_service client, final String servi } else { gslbservice.add(client, service); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully created service: " + serviceName + " at site: " + siteName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully created service: " + serviceName + " at site: " + siteName); } } catch (final Exception e) { final String errMsg = "Failed to created service: " + serviceName + " at site: " + siteName + " due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1427,18 +1428,18 @@ private static void deleteService(final nitro_service client, final String servi final gslbservice service = getServiceObject(client, serviceName); if (service != null) { gslbservice.delete(client, serviceName); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully deleted service: " + serviceName); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully deleted service: " + serviceName); } } else { - if (s_logger.isDebugEnabled()) { - s_logger.warn("Ignoring delete request for non existing service: " + serviceName); + if (LOGGER.isDebugEnabled()) { + LOGGER.warn("Ignoring delete request for non existing service: " + serviceName); } } } catch (final Exception e) { final String errMsg = "Failed to delete service: " + serviceName + " due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1453,22 +1454,22 @@ private static void createVserverServiceBinding(final nitro_service client, fina binding.set_servicename(serviceName); binding.set_weight(weight); gslbvserver_gslbservice_binding.add(client, binding); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully created service: " + serviceName + " and virtual server: " + vserverName + " binding"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully created service: " + serviceName + " and virtual server: " + vserverName + " binding"); } } catch (final nitro_exception ne) { if (ne.getErrorCode() == 273) { return; } errMsg = "Failed to create service: " + serviceName + " and virtual server: " + vserverName + " binding due to " + ne.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } catch (final Exception e) { errMsg = "Failed to create service: " + serviceName + " and virtual server: " + vserverName + " binding due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1481,8 +1482,8 @@ private static void deleteVserverServiceBinding(final nitro_service client, fina for (final gslbvserver_gslbservice_binding binding : bindings) { if (binding.get_servicename().equalsIgnoreCase(serviceName) && binding.get_name().equals(vserverName)) { gslbvserver_gslbservice_binding.delete(client, binding); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully deleted service: " + serviceName + " and virtual server: " + vserverName + " binding"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully deleted service: " + serviceName + " and virtual server: " + vserverName + " binding"); } break; } @@ -1490,8 +1491,8 @@ private static void deleteVserverServiceBinding(final nitro_service client, fina } } catch (final Exception e) { final String errMsg = "Failed to create service: " + serviceName + " and virtual server: " + vserverName + " binding due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1505,8 +1506,8 @@ private static void createVserverDomainBinding(final nitro_service client, final binding.set_domainname(domainName); binding.set_name(vserverName); gslbvserver_domain_binding.add(client, binding); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully added virtual server: " + vserverName + " domain name: " + domainName + " binding"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully added virtual server: " + vserverName + " domain name: " + domainName + " binding"); } return; } catch (final nitro_exception e) { @@ -1518,8 +1519,8 @@ private static void createVserverDomainBinding(final nitro_service client, final errMsg = e.getMessage(); } errMsg = "Failed to create virtual server: " + vserverName + " domain name: " + domainName + " binding" + errMsg; - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1531,8 +1532,8 @@ private static void deleteVserverDomainBinding(final nitro_service client, final for (final gslbvserver_domain_binding binding : bindings) { if (binding.get_domainname().equalsIgnoreCase(domainName)) { gslbvserver_domain_binding.delete(client, binding); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully deleted virtual server: " + vserverName + " and " + " domain: " + domainName + " binding"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Successfully deleted virtual server: " + vserverName + " and " + " domain: " + domainName + " binding"); } break; } @@ -1540,8 +1541,8 @@ private static void deleteVserverDomainBinding(final nitro_service client, final } } catch (final Exception e) { final String errMsg = "Failed to delete virtual server: " + vserverName + " and domain " + domainName + " binding due to " + e.getMessage(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1562,8 +1563,8 @@ private static void createGslbServiceMonitor(final nitro_service nsService, fina } } catch (final Exception e) { final String errMsg = "Failed to create GSLB monitor for service public ip" + servicePublicIp; - if (s_logger.isDebugEnabled()) { - s_logger.debug(errMsg); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(errMsg); } throw new ExecutionException(errMsg); } @@ -1578,12 +1579,12 @@ private static void deleteGslbServiceMonitor(final nitro_service nsService, fina } catch (final nitro_exception ne) { if (ne.getErrorCode() != NitroError.NS_RESOURCE_NOT_EXISTS) { final String errMsg = "Failed to delete monitor " + monitorName + " for GSLB service due to " + ne.getMessage(); - s_logger.debug(errMsg); + LOGGER.debug(errMsg); throw new com.cloud.utils.exception.ExecutionException(errMsg); } } catch (final Exception e) { final String errMsg = "Failed to delete monitor " + monitorName + " for GSLB service due to " + e.getMessage(); - s_logger.debug(errMsg); + LOGGER.debug(errMsg); throw new com.cloud.utils.exception.ExecutionException(errMsg); } } @@ -1597,7 +1598,7 @@ private static void createGslbServiceGslbMonitorBinding(final nitro_service nsSe } catch (final Exception e) { // TODO: Nitro API version 10.* is not compatible for NetScalers 9.*, so may fail // against NetScaler version lesser than 10 hence ignore the exception - s_logger.warn("Failed to bind monitor to GSLB service due to " + e.getMessage()); + LOGGER.warn("Failed to bind monitor to GSLB service due to " + e.getMessage()); } } @@ -1607,13 +1608,13 @@ private static void deleteGslbServiceGslbMonitorBinding(final nitro_service nsSe if (monitorBindings != null && monitorBindings.length > 0) { for (final gslbservice_lbmonitor_binding binding : monitorBindings) { if (binding.get_monitor_name().equalsIgnoreCase(monitorName)) { - s_logger.info("Found a binding between monitor " + binding.get_monitor_name() + " and " + binding.get_servicename()); + LOGGER.info("Found a binding between monitor " + binding.get_monitor_name() + " and " + binding.get_servicename()); gslbservice_lbmonitor_binding.delete(nsService, binding); } } } } catch (final Exception e) { - s_logger.debug("Failed to delete GSLB monitor " + monitorName + " and GSLB service " + serviceName + " binding due to " + e.getMessage() + + LOGGER.debug("Failed to delete GSLB monitor " + monitorName + " and GSLB service " + serviceName + " binding due to " + e.getMessage() + " but moving on ..., will be cleaned up as part of GSLB " + " service delete any way.."); } } @@ -1626,7 +1627,7 @@ private static gslbsite getSiteObject(final nitro_service client, final String s return site; } } catch (final Exception e) { - s_logger.info("[ignored]" + LOGGER.info("[ignored]" + "error getting site: " + e.getLocalizedMessage()); } return null; @@ -1747,7 +1748,7 @@ private static void deleteKeyFile(final String nsIp, final String username, fina } private static void createSslCertKey(final nitro_service ns, final String certFilename, final String keyFilename, final String certKeyName, final String password) throws ExecutionException { - s_logger.debug("Adding cert to netscaler"); + LOGGER.debug("Adding cert to netscaler"); try { final sslcertkey certkey = new sslcertkey(); certkey.set_certkey(certKeyName); @@ -1772,7 +1773,7 @@ private static void createSslCertKey(final nitro_service ns, final String certFi } private static void bindCertKeyToVserver(final nitro_service ns, final String certKeyName, final String vserver) throws ExecutionException { - s_logger.debug("Adding cert to netscaler"); + LOGGER.debug("Adding cert to netscaler"); try { final sslvserver_sslcertkey_binding cert_binding = new sslvserver_sslcertkey_binding(); @@ -1999,7 +2000,7 @@ private synchronized Answer execute(final DestroyLoadBalancerApplianceCommand cm if (vpxToDelete == null) { final String msg = "There is no VPX instance " + vpxName + " on the Netscaler SDX device " + _ip + " to delete"; - s_logger.warn(msg); + LOGGER.warn(msg); return new DestroyLoadBalancerApplianceAnswer(cmd, true, msg); } @@ -2008,7 +2009,7 @@ private synchronized Answer execute(final DestroyLoadBalancerApplianceCommand cm nsDelObj.set_id(vpxToDelete.get_id()); vpxToDelete = ns.delete(_netscalerSdxService, nsDelObj); final String msg = "Deleted VPX instance " + vpxName + " on Netscaler SDX " + _ip + " successfully."; - s_logger.info(msg); + LOGGER.info(msg); return new DestroyLoadBalancerApplianceAnswer(cmd, true, msg); } catch (final Exception e) { if (shouldRetry(numRetries)) { @@ -2060,7 +2061,7 @@ private synchronized Answer execute(final SetStaticNatRulesCommand cmd, final in throw e; } } - s_logger.debug("Created Inat rule on the Netscaler device " + _ip + " to enable static NAT from " + srcIp + " to " + dstIP); + LOGGER.debug("Created Inat rule on the Netscaler device " + _ip + " to enable static NAT from " + srcIp + " to " + dstIP); } try { final rnat[] rnatRules = rnat.get(_netscalerService); @@ -2088,7 +2089,7 @@ private synchronized Answer execute(final SetStaticNatRulesCommand cmd, final in throw e; } } - s_logger.debug("Created Rnat rule on the Netscaler device " + _ip + " to enable revese static NAT from " + dstIP + " to " + srcIp); + LOGGER.debug("Created Rnat rule on the Netscaler device " + _ip + " to enable revese static NAT from " + dstIP + " to " + srcIp); } } else { try { @@ -2108,7 +2109,7 @@ private synchronized Answer execute(final SetStaticNatRulesCommand cmd, final in throw e; } } - s_logger.debug("Deleted Inat rule on the Netscaler device " + _ip + " to remove static NAT from " + srcIp + " to " + dstIP); + LOGGER.debug("Deleted Inat rule on the Netscaler device " + _ip + " to remove static NAT from " + srcIp + " to " + dstIP); } saveConfiguration(); @@ -2692,8 +2693,8 @@ private void addLBVirtualServer(final String virtualServerName, final String pub throw new ExecutionException("Failed to create new load balancing virtual server:" + virtualServerName + " due to " + apiCallResult.message); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Created load balancing virtual server " + virtualServerName + " on the Netscaler device"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Created load balancing virtual server " + virtualServerName + " on the Netscaler device"); } } catch (final nitro_exception e) { throw new ExecutionException("Failed to create new virtual server:" + virtualServerName + " due to " + e.getMessage()); @@ -2742,9 +2743,9 @@ private void addLBMonitor(final String nsMonitorName, final String lbProtocol, f csMon.set_type(lbProtocol); if (lbProtocol.equalsIgnoreCase("HTTP")) { csMon.set_httprequest(hcp.getpingPath()); - s_logger.trace("LB Protocol is HTTP, Applying ping path on HealthCheck Policy"); + LOGGER.trace("LB Protocol is HTTP, Applying ping path on HealthCheck Policy"); } else { - s_logger.debug("LB Protocol is not HTTP, Skipping to apply ping path on HealthCheck Policy"); + LOGGER.debug("LB Protocol is not HTTP, Skipping to apply ping path on HealthCheck Policy"); } csMon.set_interval(hcp.getHealthcheckInterval()); @@ -2752,11 +2753,11 @@ private void addLBMonitor(final String nsMonitorName, final String lbProtocol, f csMon.set_resptimeout(hcp.getResponseTime()); csMon.set_failureretries(hcp.getUnhealthThresshold()); csMon.set_successretries(hcp.getHealthcheckThresshold()); - s_logger.debug("Monitor properites going to get created :interval :: " + csMon.get_interval() + "respTimeOUt:: " + csMon.get_resptimeout() + + LOGGER.debug("Monitor properites going to get created :interval :: " + csMon.get_interval() + "respTimeOUt:: " + csMon.get_resptimeout() + "failure retires(unhealththresshold) :: " + csMon.get_failureretries() + "successtries(healththresshold) ::" + csMon.get_successretries()); lbmonitor.add(_netscalerService, csMon); } else { - s_logger.debug("Monitor :" + nsMonitorName + " is already existing. Skipping to delete and create it"); + LOGGER.debug("Monitor :" + nsMonitorName + " is already existing. Skipping to delete and create it"); } } catch (final nitro_exception e) { throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage()); @@ -2776,9 +2777,9 @@ private void bindServiceToMonitor(final String nsServiceName, final String nsMon serviceMonitor.set_monitor_name(nsMonitorName); serviceMonitor.set_name(nsServiceName); serviceMonitor.set_monstate("ENABLED"); - s_logger.debug("Trying to bind the monitor :" + nsMonitorName + " to the service :" + nsServiceName); + LOGGER.debug("Trying to bind the monitor :" + nsMonitorName + " to the service :" + nsServiceName); com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding.add(_netscalerService, serviceMonitor); - s_logger.debug("Successfully binded the monitor :" + nsMonitorName + " to the service :" + nsServiceName); + LOGGER.debug("Successfully binded the monitor :" + nsMonitorName + " to the service :" + nsServiceName); } } catch (final nitro_exception e) { throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage()); @@ -2798,9 +2799,9 @@ private void unBindServiceToMonitor(final String nsServiceName, final String nsM new com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding(); serviceMonitor.set_monitor_name(nsMonitorName); serviceMonitor.set_name(nsServiceName); - s_logger.debug("Trying to unbind the monitor :" + nsMonitorName + " from the service :" + nsServiceName); + LOGGER.debug("Trying to unbind the monitor :" + nsMonitorName + " from the service :" + nsServiceName); service_lbmonitor_binding.delete(_netscalerService, serviceMonitor); - s_logger.debug("Successfully unbinded the monitor :" + nsMonitorName + " from the service :" + nsServiceName); + LOGGER.debug("Successfully unbinded the monitor :" + nsMonitorName + " from the service :" + nsServiceName); } } catch (final nitro_exception e) { @@ -2822,7 +2823,7 @@ private void removeLBMonitor(final String nsMonitorName) throws ExecutionExcepti final lbmonitor monitorObj = lbmonitor.get(_netscalerService, nsMonitorName); monitorObj.set_respcode(null); lbmonitor.delete(_netscalerService, monitorObj); - s_logger.info("Successfully deleted monitor : " + nsMonitorName); + LOGGER.info("Successfully deleted monitor : " + nsMonitorName); } } catch (final nitro_exception e) { if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) { @@ -2849,8 +2850,8 @@ public synchronized void applyAutoScaleConfig(final LoadBalancerTO loadBalancer) } // AutoScale APIs are successful executed, now save the configuration. saveConfiguration(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Successfully executed resource AutoScaleConfig"); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Successfully executed resource AutoScaleConfig"); } } @@ -2863,8 +2864,8 @@ private synchronized boolean createAutoScaleConfig(final LoadBalancerTO loadBala generateAutoScaleVmGroupIdentifier(loadBalancerTO); final String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort); final AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Created load balancing virtual server " + nsVirtualServerName + " on the Netscaler device"); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Created load balancing virtual server " + nsVirtualServerName + " on the Netscaler device"); } addLBVirtualServer(nsVirtualServerName, srcIp, srcPort, lbAlgorithm, lbProtocol, loadBalancerTO.getStickinessPolicies(), vmGroupTO); @@ -3507,7 +3508,7 @@ private boolean isAutoScaleSupportedInNetScaler() throws ExecutionException { // TODO: Config team has introduce a new command to check // the list of entities supported in a NetScaler. Can use that // once it is present in AutoScale branch. - s_logger.warn("AutoScale is not supported in NetScaler"); + LOGGER.warn("AutoScale is not supported in NetScaler"); return false; } return true; @@ -3563,7 +3564,7 @@ private ExternalNetworkResourceUsageAnswer getPublicIpBytesSentAndReceived(final } } } catch (final Exception e) { - s_logger.error("Failed to get bytes sent and received statistics due to " + e); + LOGGER.error("Failed to get bytes sent and received statistics due to " + e); throw new ExecutionException(e.getMessage()); } @@ -3572,7 +3573,7 @@ private ExternalNetworkResourceUsageAnswer getPublicIpBytesSentAndReceived(final private Answer retry(final Command cmd, final int numRetries) { final int numRetriesRemaining = numRetries - 1; - s_logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetriesRemaining); + LOGGER.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetriesRemaining); return executeRequest(cmd, numRetriesRemaining); } @@ -3583,7 +3584,7 @@ private boolean shouldRetry(final int numRetries) { return true; } } catch (final Exception e) { - s_logger.error("Failed to log in to Netscaler device at " + _ip + " due to " + e.getMessage()); + LOGGER.error("Failed to log in to Netscaler device at " + _ip + " due to " + e.getMessage()); } return false; } diff --git a/plugins/network-elements/netscaler/src/main/java/com/cloud/network/vm/NetScalerVMManagerImpl.java b/plugins/network-elements/netscaler/src/main/java/com/cloud/network/vm/NetScalerVMManagerImpl.java index 2293ccbbaa55..7b2ef012bed6 100644 --- a/plugins/network-elements/netscaler/src/main/java/com/cloud/network/vm/NetScalerVMManagerImpl.java +++ b/plugins/network-elements/netscaler/src/main/java/com/cloud/network/vm/NetScalerVMManagerImpl.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.lb.dao.ApplicationLoadBalancerRuleDao; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -95,7 +94,6 @@ import com.cloud.vm.dao.VMInstanceDao; public class NetScalerVMManagerImpl extends ManagerBase implements NetScalerVMManager, VirtualMachineGuru { - private static final Logger s_logger = Logger.getLogger(NetScalerVMManagerImpl.class); static final private String NetScalerLbVmNamePrefix = "NS"; @Inject @@ -196,8 +194,8 @@ public void finalizeUnmanage(VirtualMachine vm) { @Override public boolean configure(String name, Map params) throws ConfigurationException { _itMgr.registerGuru(VirtualMachine.Type.NetScalerVm, this); - if (s_logger.isInfoEnabled()) { - s_logger.info(getName() + " has been configured"); + if (logger.isInfoEnabled()) { + logger.info(getName() + " has been configured"); } return true; } @@ -208,7 +206,7 @@ public String getName() { } protected VirtualRouter stopInternalLbVm(DomainRouterVO internalLbVm, boolean forced, Account caller, long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException { - s_logger.debug("Stopping internal lb vm " + internalLbVm); + logger.debug("Stopping internal lb vm " + internalLbVm); try { _itMgr.advanceStop(internalLbVm.getUuid(), forced); return _internalLbVmDao.findById(internalLbVm.getId()); @@ -220,7 +218,7 @@ protected VirtualRouter stopInternalLbVm(DomainRouterVO internalLbVm, boolean fo public VirtualRouterProvider addNetScalerLoadBalancerElement(long ntwkSvcProviderId) { VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, com.cloud.network.VirtualRouterProvider.Type.NetScalerVm); if (element != null) { - s_logger.debug("There is already an " + getName() + " with service provider id " + ntwkSvcProviderId); + logger.debug("There is already an " + getName() + " with service provider id " + ntwkSvcProviderId); return element; } @@ -261,7 +259,7 @@ public Map deployNsVpx(Account owner, DeployDestination dest, De Account systemAcct = _accountMgr.getSystemAccount(); if (template == null) { - s_logger.error(" Unable to find the NS VPX template"); + logger.error(" Unable to find the NS VPX template"); throw new CloudRuntimeException("Unable to find the Template" + templateId); } long dataCenterId = dest.getDataCenter().getId(); @@ -384,7 +382,7 @@ public Map deployNsVpx(Account owner, DeployDestination dest, De protected void startNsVpx(VMInstanceVO nsVpx, Map params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { - s_logger.debug("Starting NS Vpx " + nsVpx); + logger.debug("Starting NS Vpx " + nsVpx); _itMgr.start(nsVpx.getUuid(), params, null, null); } @@ -409,7 +407,7 @@ public Map deployNetscalerServiceVm(DeployNetscalerVpxCmd cmd) { protected VirtualRouter stopNetScalerVm(final long vmId, final boolean forced, final Account caller, final long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException { final DomainRouterVO netscalerVm = _routerDao.findById(vmId); - s_logger.debug("Stopping NetScaler vm " + netscalerVm); + logger.debug("Stopping NetScaler vm " + netscalerVm); if (netscalerVm == null || netscalerVm.getRole() != Role.NETSCALER_VM) { throw new InvalidParameterValueException("Can't find NetScaler vm by id specified"); @@ -433,7 +431,7 @@ public VirtualRouter stopNetscalerServiceVm(Long id, boolean forced, Account cal @Override public VirtualRouter stopNetScalerVm(Long vmId, boolean forced, Account caller, long callingUserId) { final DomainRouterVO netscalerVm = _routerDao.findById(vmId); - s_logger.debug("Stopping NetScaler vm " + netscalerVm); + logger.debug("Stopping NetScaler vm " + netscalerVm); if (netscalerVm == null || netscalerVm.getRole() != Role.NETSCALER_VM) { throw new InvalidParameterValueException("Can't find NetScaler vm by id specified"); diff --git a/plugins/network-elements/nicira-nvp/pom.xml b/plugins/network-elements/nicira-nvp/pom.xml index 72c728fd013f..902a479af902 100644 --- a/plugins/network-elements/nicira-nvp/pom.xml +++ b/plugins/network-elements/nicira-nvp/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java index a3217cc7284e..864fb6c68991 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -50,7 +49,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNiciraNvpDeviceNetworksCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNiciraNvpDeviceNetworksCmd.class.getName()); private static final String s_name = "listniciranvpdevicenetworks"; @Inject protected NiciraNvpElementService niciraNvpElementService; diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java index 1146a5435ca4..356b452a9e48 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java @@ -31,7 +31,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; @@ -139,7 +138,6 @@ public class NiciraNvpElement extends AdapterBase implements ConnectivityProvide private static final int MAX_PORT = 65535; private static final int MIN_PORT = 0; - private static final Logger s_logger = Logger.getLogger(NiciraNvpElement.class); private static final Map> capabilities = setCapabilities(); @@ -189,18 +187,18 @@ public Provider getProvider() { } protected boolean canHandle(Network network, Service service) { - s_logger.debug("Checking if NiciraNvpElement can handle service " + service.getName() + " on network " + network.getDisplayText()); + logger.debug("Checking if NiciraNvpElement can handle service " + service.getName() + " on network " + network.getDisplayText()); if (network.getBroadcastDomainType() != BroadcastDomainType.Lswitch) { return false; } if (!networkModel.isProviderForNetwork(getProvider(), network.getId())) { - s_logger.debug("NiciraNvpElement is not a provider for network " + network.getDisplayText()); + logger.debug("NiciraNvpElement is not a provider for network " + network.getDisplayText()); return false; } if (!ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), service, Network.Provider.NiciraNvp)) { - s_logger.debug("NiciraNvpElement can't provide the " + service.getName() + " service on network " + network.getDisplayText()); + logger.debug("NiciraNvpElement can't provide the " + service.getName() + " service on network " + network.getDisplayText()); return false; } @@ -217,20 +215,20 @@ public boolean configure(String name, Map params) throws Configu @Override public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); + logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); if (!canHandle(network, Service.Connectivity)) { return false; } if (network.getBroadcastUri() == null) { - s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); + logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); return false; } List devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); + logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -252,7 +250,7 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin } else if (network.getGuestType().equals(GuestType.Isolated) && networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) { // Implement SourceNat immediately as we have al the info already - s_logger.debug("Apparently we are supposed to provide SourceNat on this network"); + logger.debug("Apparently we are supposed to provide SourceNat on this network"); PublicIp sourceNatIp = ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); @@ -278,7 +276,7 @@ else if (network.getGuestType().equals(GuestType.Isolated) && networkModel.isPro context.getAccount().getAccountName()); CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { - s_logger.error("Failed to create Logical Router for network " + network.getDisplayText()); + logger.error("Failed to create Logical Router for network " + network.getDisplayText()); return false; } @@ -315,7 +313,7 @@ private boolean sharedNetworkSupportUUIDVlanId(Network network, String lSwitchUu new ConfigureSharedNetworkUuidCommand(lRouterUuid, lSwitchUuid, portIpAddress, ownerName, network.getId()); ConfigureSharedNetworkUuidAnswer answer = (ConfigureSharedNetworkUuidAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { - s_logger.error("Failed to configure Logical Router for Shared network " + network.getDisplayText()); + logger.error("Failed to configure Logical Router for Shared network " + network.getDisplayText()); return false; } return true; @@ -334,7 +332,7 @@ private boolean sharedNetworkSupportNumericalVlanId(Network network, String lSwi new ConfigureSharedNetworkVlanIdCommand(lSwitchUuid, l2GatewayServiceUuid , vlanId, ownerName, network.getId()); ConfigureSharedNetworkVlanIdAnswer answer = (ConfigureSharedNetworkVlanIdAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { - s_logger.error("Failed to configure Shared network " + network.getDisplayText()); + logger.error("Failed to configure Shared network " + network.getDisplayText()); return false; } } @@ -359,7 +357,7 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm } if (network.getBroadcastUri() == null) { - s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); + logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); return false; } @@ -367,7 +365,7 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm List devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); + logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -379,14 +377,14 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer)agentMgr.easySend(niciraNvpHost.getId(), findCmd); if (answer.getResult()) { - s_logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid()); + logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid()); UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(), BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName()); agentMgr.easySend(niciraNvpHost.getId(), cmd); return true; } else { - s_logger.error("Stale entry found for nic " + nic.getName() + " with logical switchport uuid " + existingNicMap.getLogicalSwitchPortUuid()); + logger.error("Stale entry found for nic " + nic.getName() + " with logical switchport uuid " + existingNicMap.getLogicalSwitchPortUuid()); niciraNvpNicMappingDao.remove(existingNicMap.getId()); } } @@ -397,7 +395,7 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("CreateLogicalSwitchPortCommand failed"); + logger.error("CreateLogicalSwitchPortCommand failed"); return false; } @@ -417,7 +415,7 @@ public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm } if (network.getBroadcastUri() == null) { - s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); + logger.error("Nic has no broadcast Uri with the LSwitch Uuid"); return false; } @@ -425,7 +423,7 @@ public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm List devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); + logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -433,7 +431,7 @@ public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm NiciraNvpNicMappingVO nicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid()); if (nicMap == null) { - s_logger.error("No mapping for nic " + nic.getName()); + logger.error("No mapping for nic " + nic.getName()); return false; } @@ -441,7 +439,7 @@ public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("DeleteLogicalSwitchPortCommand failed"); + logger.error("DeleteLogicalSwitchPortCommand failed"); return false; } @@ -458,7 +456,7 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle List devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); + logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -466,13 +464,13 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle //Dont destroy logical router when removing Shared Networks if (! network.getGuestType().equals(GuestType.Shared) && networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) { - s_logger.debug("Apparently we were providing SourceNat on this network"); + logger.debug("Apparently we were providing SourceNat on this network"); // Deleting the LogicalRouter will also take care of all provisioned // nat rules. NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId()); if (routermapping == null) { - s_logger.warn("No logical router uuid found for network " + network.getDisplayText()); + logger.warn("No logical router uuid found for network " + network.getDisplayText()); // This might be cause by a failed deployment, so don't make shutdown fail as well. return true; } @@ -480,7 +478,7 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle DeleteLogicalRouterCommand cmd = new DeleteLogicalRouterCommand(routermapping.getLogicalRouterUuid()); DeleteLogicalRouterAnswer answer = (DeleteLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) { - s_logger.error("Failed to delete LogicalRouter for network " + network.getDisplayText()); + logger.error("Failed to delete LogicalRouter for network " + network.getDisplayText()); return false; } @@ -521,11 +519,11 @@ public boolean verifyServicesCombination(Set services) { // This element can only function in a Nicra Nvp based // SDN network, so Connectivity needs to be present here if (!services.contains(Service.Connectivity)) { - s_logger.warn("Unable to provide services without Connectivity service enabled for this element"); + logger.warn("Unable to provide services without Connectivity service enabled for this element"); return false; } if ((services.contains(Service.PortForwarding) || services.contains(Service.StaticNat)) && !services.contains(Service.SourceNat)) { - s_logger.warn("Unable to provide StaticNat and/or PortForwarding without the SourceNat service"); + logger.warn("Unable to provide StaticNat and/or PortForwarding without the SourceNat service"); return false; } return true; @@ -807,7 +805,7 @@ public boolean applyIps(Network network, List ipAddre // SourceNat is required for StaticNat and PortForwarding List devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); + logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -816,7 +814,7 @@ public boolean applyIps(Network network, List ipAddre NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId()); if (routermapping == null) { - s_logger.error("No logical router uuid found for network " + network.getDisplayText()); + logger.error("No logical router uuid found for network " + network.getDisplayText()); return false; } @@ -835,7 +833,7 @@ public boolean applyIps(Network network, List ipAddre //FIXME answer can be null if the host is down return answer.getResult(); } else { - s_logger.debug("No need to provision ip addresses as we are not providing L3 services."); + logger.debug("No need to provision ip addresses as we are not providing L3 services."); } return true; @@ -852,7 +850,7 @@ public boolean applyStaticNats(Network network, List rules) List devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); + logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -860,7 +858,7 @@ public boolean applyStaticNats(Network network, List rules) NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId()); if (routermapping == null) { - s_logger.error("No logical router uuid found for network " + network.getDisplayText()); + logger.error("No logical router uuid found for network " + network.getDisplayText()); return false; } @@ -892,7 +890,7 @@ public boolean applyPFRules(Network network, List rules) thr List devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); + logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId()); return false; } NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -900,7 +898,7 @@ public boolean applyPFRules(Network network, List rules) thr NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId()); if (routermapping == null) { - s_logger.error("No logical router uuid found for network " + network.getDisplayText()); + logger.error("No logical router uuid found for network " + network.getDisplayText()); return false; } diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java index 3ffc601990cd..daf2420b528c 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java @@ -27,7 +27,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.CreateLogicalSwitchAnswer; @@ -82,7 +81,6 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru implements NetworkGuruAdditionalFunctions{ private static final int MAX_NAME_LENGTH = 40; - private static final Logger s_logger = Logger.getLogger(NiciraNvpGuestNetworkGuru.class); @Inject protected NetworkModel networkModel; @@ -138,24 +136,24 @@ private boolean supportedGuestTypes(NetworkOffering offering, GuestType... types } @Override - public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) { + public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, String name, Long vpcId, final Account owner) { // Check of the isolation type of the related physical network is supported final PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId()); final DataCenter dc = _dcDao.findById(plan.getDataCenterId()); if (!canHandle(offering, dc.getNetworkType(), physnet)) { - s_logger.debug("Refusing to design this network"); + logger.debug("Refusing to design this network"); return null; } final List devices = niciraNvpDao.listByPhysicalNetwork(physnet.getId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + physnet.getName()); + logger.error("No NiciraNvp Controller on physical network " + physnet.getName()); return null; } - s_logger.debug("Nicira Nvp " + devices.get(0).getUuid() + " found on physical network " + physnet.getId()); + logger.debug("Nicira Nvp " + devices.get(0).getUuid() + " found on physical network " + physnet.getId()); - s_logger.debug("Physical isolation type is supported, asking GuestNetworkGuru to design this network"); - final NetworkVO networkObject = (NetworkVO) super.design(offering, plan, userSpecified, owner); + logger.debug("Physical isolation type is supported, asking GuestNetworkGuru to design this network"); + final NetworkVO networkObject = (NetworkVO) super.design(offering, plan, userSpecified, name, vpcId, owner); if (networkObject == null) { return null; } @@ -203,7 +201,7 @@ public Network implement(final Network network, final NetworkOffering offering, final List devices = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId); + logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId); return null; } final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -217,7 +215,7 @@ public Network implement(final Network network, final NetworkOffering offering, checkL2GatewayServiceSharedNetwork(niciraNvpHost); } catch (Exception e){ - s_logger.error("L2 Gateway Service Issue: " + e.getMessage()); + logger.error("L2 Gateway Service Issue: " + e.getMessage()); return null; } } @@ -227,16 +225,16 @@ public Network implement(final Network network, final NetworkOffering offering, final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("CreateLogicalSwitchCommand failed"); + logger.error("CreateLogicalSwitchCommand failed"); return null; } try { implemented.setBroadcastUri(new URI("lswitch", answer.getLogicalSwitchUuid(), null)); implemented.setBroadcastDomainType(BroadcastDomainType.Lswitch); - s_logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString()); + logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString()); } catch (final URISyntaxException e) { - s_logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e); + logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e); return null; } @@ -278,13 +276,13 @@ public boolean release(final NicProfile nic, final VirtualMachineProfile vm, fin public void shutdown(final NetworkProfile profile, final NetworkOffering offering) { final NetworkVO networkObject = networkDao.findById(profile.getId()); if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Lswitch || networkObject.getBroadcastUri() == null) { - s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); + logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); return; } final List devices = niciraNvpDao.listByPhysicalNetwork(networkObject.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No NiciraNvp Controller on physical network " + networkObject.getPhysicalNetworkId()); + logger.error("No NiciraNvp Controller on physical network " + networkObject.getPhysicalNetworkId()); return; } final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); @@ -300,7 +298,7 @@ public void shutdown(final NetworkProfile profile, final NetworkOffering offerin final DeleteLogicalSwitchAnswer answer = (DeleteLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("DeleteLogicalSwitchCommand failed"); + logger.error("DeleteLogicalSwitchCommand failed"); } super.shutdown(profile, offering); @@ -310,30 +308,30 @@ private void sharedNetworksCleanup(NetworkVO networkObject, String logicalSwitch NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(networkObject.getId()); if (routermapping == null) { // Case 1: Numerical Vlan Provided -> No lrouter used. - s_logger.info("Shared Network " + networkObject.getDisplayText() + " didn't use Logical Router"); + logger.info("Shared Network " + networkObject.getDisplayText() + " didn't use Logical Router"); } else { //Case 2: Logical Router's UUID provided as Vlan id -> Remove lrouter port but not lrouter. String lRouterUuid = routermapping.getLogicalRouterUuid(); - s_logger.debug("Finding Logical Router Port on Logical Router " + lRouterUuid + " with attachment_lswitch_uuid=" + logicalSwitchUuid + " to delete it"); + logger.debug("Finding Logical Router Port on Logical Router " + lRouterUuid + " with attachment_lswitch_uuid=" + logicalSwitchUuid + " to delete it"); final FindLogicalRouterPortCommand cmd = new FindLogicalRouterPortCommand(lRouterUuid, logicalSwitchUuid); final FindLogicalRouterPortAnswer answer = (FindLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer != null && answer.getResult()) { String logicalRouterPortUuid = answer.getLogicalRouterPortUuid(); - s_logger.debug("Found Logical Router Port " + logicalRouterPortUuid + ", deleting it"); + logger.debug("Found Logical Router Port " + logicalRouterPortUuid + ", deleting it"); final DeleteLogicalRouterPortCommand cmdDeletePort = new DeleteLogicalRouterPortCommand(lRouterUuid, logicalRouterPortUuid); final DeleteLogicalRouterPortAnswer answerDelete = (DeleteLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmdDeletePort); if (answerDelete != null && answerDelete.getResult()){ - s_logger.info("Successfully deleted Logical Router Port " + logicalRouterPortUuid); + logger.info("Successfully deleted Logical Router Port " + logicalRouterPortUuid); } else { - s_logger.error("Could not delete Logical Router Port " + logicalRouterPortUuid); + logger.error("Could not delete Logical Router Port " + logicalRouterPortUuid); } } else { - s_logger.error("Find Logical Router Port failed"); + logger.error("Find Logical Router Port failed"); } } } diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpTag.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpTag.java index 625e49c21a53..1c1fd7f3ace6 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpTag.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpTag.java @@ -19,11 +19,12 @@ package com.cloud.network.nicira; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class NiciraNvpTag { private static final int TAG_MAX_LEN = 40; - private static final Logger s_logger = Logger.getLogger(NiciraNvpTag.class); + protected Logger logger = LogManager.getLogger(getClass()); private String scope; private String tag; @@ -33,7 +34,7 @@ public NiciraNvpTag() { public NiciraNvpTag(String scope, String tag) { this.scope = scope; if (tag.length() > 40) { - s_logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters"); + logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters"); this.tag = tag.substring(0, TAG_MAX_LEN); } else { this.tag = tag; @@ -54,7 +55,7 @@ public String getTag() { public void setTag(String tag) { if (tag.length() > 40) { - s_logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters"); + logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters"); this.tag = tag.substring(0, 40); } else { this.tag = tag; diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java index aa428b08dc3d..f9c86be9d08f 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java @@ -30,7 +30,6 @@ import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; import com.cloud.utils.rest.BasicRestClient; import com.cloud.utils.rest.CloudstackRESTException; @@ -41,7 +40,6 @@ public class NiciraRestClient extends BasicRestClient { - private static final Logger s_logger = Logger.getLogger(NiciraRestClient.class); private static final String CONTENT_TYPE = HttpConstants.CONTENT_TYPE; private static final String TEXT_HTML_CONTENT_TYPE = HttpConstants.TEXT_HTML_CONTENT_TYPE; @@ -81,12 +79,12 @@ CloseableHttpResponse execute(final HttpUriRequest request, final int previousSt throw new CloudstackRESTException("Reached max executions limit of " + executionLimit); } counter.incrementExecutionCounter(); - s_logger.debug("Executing " + request.getMethod() + " request [execution count = " + counter.getValue() + "]"); + logger.debug("Executing " + request.getMethod() + " request [execution count = " + counter.getValue() + "]"); final CloseableHttpResponse response = super.execute(request); final StatusLine statusLine = response.getStatusLine(); final int statusCode = statusLine.getStatusCode(); - s_logger.debug("Status of last request: " + statusLine.toString()); + logger.debug("Status of last request: " + statusLine.toString()); if (HttpStatusCodeHelper.isUnauthorized(statusCode)) { return handleUnauthorizedResponse(request, previousStatusCode, response, statusCode); } else if (HttpStatusCodeHelper.isSuccess(statusCode)) { @@ -102,7 +100,7 @@ private CloseableHttpResponse handleUnauthorizedResponse(final HttpUriRequest re throws CloudstackRESTException { super.closeResponse(response); if (HttpStatusCodeHelper.isUnauthorized(previousStatusCode)) { - s_logger.error(responseToErrorMessage(response)); + logger.error(responseToErrorMessage(response)); throw new CloudstackRESTException("Two consecutive failed attempts to authenticate against REST server"); } final HttpUriRequest authenticateRequest = createAuthenticationRequest(); @@ -138,7 +136,7 @@ private String responseToErrorMessage(final CloseableHttpResponse response) { final String respobnseBody = EntityUtils.toString(entity); errorMessage = respobnseBody.subSequence(0, maxResponseErrorMesageLength).toString(); } catch (final IOException e) { - s_logger.debug("Could not read response body. Response: " + response, e); + logger.debug("Could not read response body. Response: " + response, e); } } diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java index 80a9386e4f43..c2841f18c1cb 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java @@ -26,7 +26,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -52,7 +53,7 @@ public class NiciraNvpResource implements ServerResource { - private static final Logger s_logger = Logger.getLogger(NiciraNvpResource.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final int NAME_MAX_LEN = 40; public static final int NUM_RETRIES = 2; @@ -176,11 +177,11 @@ public PingCommand getCurrentStatus(final long id) { final ControlClusterStatus ccs = niciraNvpApi.getControlClusterStatus(); getApiProviderMajorityVersion(ccs); if (!"stable".equals(ccs.getClusterStatus())) { - s_logger.error("ControlCluster state is not stable: " + ccs.getClusterStatus()); + logger.error("ControlCluster state is not stable: " + ccs.getClusterStatus()); return null; } } catch (final NiciraNvpApiException e) { - s_logger.error("getControlClusterStatus failed", e); + logger.error("getControlClusterStatus failed", e); return null; } return new PingCommand(Host.Type.L2Networking, id); @@ -210,7 +211,7 @@ public Answer executeRequest(final Command cmd) { try { return wrapper.execute(cmd, this); } catch (final Exception e) { - s_logger.debug("Received unsupported command " + cmd.toString()); + logger.debug("Received unsupported command " + cmd.toString()); return Answer.createUnsupportedCommandAnswer(cmd); } } diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraCheckHealthCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraCheckHealthCommandWrapper.java index 34e4548cf816..821b9f6d87c0 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraCheckHealthCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraCheckHealthCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.network.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckHealthAnswer; @@ -35,7 +34,6 @@ public class NiciraCheckHealthCommandWrapper extends CommandWrapper { private static final String CONTROL_CLUSTER_STATUS_IS_STABLE = "stable"; - private static final Logger s_logger = Logger.getLogger(NiciraCheckHealthCommandWrapper.class); @Override public Answer execute(final CheckHealthCommand command, final NiciraNvpResource serverResource) { @@ -45,11 +43,11 @@ public Answer execute(final CheckHealthCommand command, final NiciraNvpResource final ControlClusterStatus clusterStatus = niciraNvpApi.getControlClusterStatus(); final String status = clusterStatus.getClusterStatus(); if (clusterIsUnstable(status)) { - s_logger.warn("Control cluster is not stable. Current status is " + status); + logger.warn("Control cluster is not stable. Current status is " + status); healthy = false; } } catch (final NiciraNvpApiException e) { - s_logger.error("Exception caught while checking control cluster status during health check", e); + logger.error("Exception caught while checking control cluster status during health check", e); healthy = false; } diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigurePortForwardingRulesCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigurePortForwardingRulesCommandWrapper.java index bb19e75b704f..7b7108c3d419 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigurePortForwardingRulesCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigurePortForwardingRulesCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = ConfigurePortForwardingRulesOnLogicalRouterCommand.class) public final class NiciraNvpConfigurePortForwardingRulesCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigurePortForwardingRulesCommandWrapper.class); @Override public Answer execute(final ConfigurePortForwardingRulesOnLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) { @@ -71,14 +69,14 @@ public Answer execute(final ConfigurePortForwardingRulesOnLogicalRouterCommand c if (storedRule.equalsIgnoreUuid(rulepair[1])) { // The outgoing rule exists outgoing = storedRule; - s_logger.debug("Found matching outgoing rule " + outgoing.getUuid()); + logger.debug("Found matching outgoing rule " + outgoing.getUuid()); if (incoming != null) { break; } } else if (storedRule.equalsIgnoreUuid(rulepair[0])) { // The incoming rule exists incoming = storedRule; - s_logger.debug("Found matching incoming rule " + incoming.getUuid()); + logger.debug("Found matching incoming rule " + incoming.getUuid()); if (outgoing != null) { break; } @@ -86,26 +84,26 @@ public Answer execute(final ConfigurePortForwardingRulesOnLogicalRouterCommand c } if (incoming != null && outgoing != null) { if (rule.revoked()) { - s_logger.debug("Deleting incoming rule " + incoming.getUuid()); + logger.debug("Deleting incoming rule " + incoming.getUuid()); niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), incoming.getUuid()); - s_logger.debug("Deleting outgoing rule " + outgoing.getUuid()); + logger.debug("Deleting outgoing rule " + outgoing.getUuid()); niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), outgoing.getUuid()); } } else { if (rule.revoked()) { - s_logger.warn("Tried deleting a rule that does not exist, " + rule.getSrcIp() + " -> " + rule.getDstIp()); + logger.warn("Tried deleting a rule that does not exist, " + rule.getSrcIp() + " -> " + rule.getDstIp()); break; } rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0]); - s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[0])); + logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[0])); try { rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[1]); - s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[1])); + logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[1])); } catch (final NiciraNvpApiException ex) { - s_logger.warn("NiciraNvpApiException during create call, rolling back previous create"); + logger.warn("NiciraNvpApiException during create call, rolling back previous create"); niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0].getUuid()); throw ex; // Rethrow the original exception } diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java index 5f3198abb4f3..bdbf612d3afd 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer; @@ -47,7 +46,6 @@ @ResourceWrapper(handles = ConfigureSharedNetworkUuidCommand.class) public final class NiciraNvpConfigureSharedNetworkUuidCommandWrapper extends CommandWrapper{ - private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigureSharedNetworkUuidCommandWrapper.class); @Override public Answer execute(ConfigureSharedNetworkUuidCommand command, NiciraNvpResource niciraNvpResource) { @@ -60,10 +58,10 @@ public Answer execute(ConfigureSharedNetworkUuidCommand command, NiciraNvpResour final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - s_logger.debug("Attaching Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId); + logger.debug("Attaching Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId); //Step 1: Get lSwitch displayName - s_logger.info("Looking for Logical Switch " + logicalSwitchUuid + " display name"); + logger.info("Looking for Logical Switch " + logicalSwitchUuid + " display name"); String logicalSwitchDisplayName; try{ List lSwitchList = niciraNvpApi.findLogicalSwitch(logicalSwitchUuid); @@ -72,30 +70,30 @@ public Answer execute(ConfigureSharedNetworkUuidCommand command, NiciraNvpResour logicalSwitchDisplayName = lSwitchList.get(0).getDisplayName(); } else { - s_logger.error("More than one Logical Switch found with uuid " + logicalSwitchUuid); + logger.error("More than one Logical Switch found with uuid " + logicalSwitchUuid); throw new CloudRuntimeException("More than one Logical Switch found with uuid=" + logicalSwitchUuid); } } else { - s_logger.error("Logical Switch " + logicalSwitchUuid + " not found"); + logger.error("Logical Switch " + logicalSwitchUuid + " not found"); throw new CloudRuntimeException("Logical Switch " + logicalSwitchUuid + " not found"); } } catch (NiciraNvpApiException e){ - s_logger.warn("Logical Switch " + logicalSwitchUuid + " not found, retrying"); + logger.warn("Logical Switch " + logicalSwitchUuid + " not found, retrying"); final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); retryUtility.addRetry(command, NUM_RETRIES); return retryUtility.retry(command, ConfigureSharedNetworkUuidAnswer.class, e); } catch (CloudRuntimeException e){ - s_logger.info("Shared network UUID vlan id failed due to : " + e.getMessage()); + logger.info("Shared network UUID vlan id failed due to : " + e.getMessage()); return new ConfigureSharedNetworkUuidAnswer(command, false, e.getMessage()); } - s_logger.info("Found display name " + logicalSwitchDisplayName + " for Logical Switch " + logicalSwitchUuid); + logger.info("Found display name " + logicalSwitchDisplayName + " for Logical Switch " + logicalSwitchUuid); //Step 2: Create lRouterPort - s_logger.debug("Creating Logical Router Port in Logical Router " + logicalRouterUuid); + logger.debug("Creating Logical Router Port in Logical Router " + logicalRouterUuid); LogicalRouterPort lRouterPort = null; try { lRouterPort = new LogicalRouterPort(); @@ -108,85 +106,85 @@ public Answer execute(ConfigureSharedNetworkUuidCommand command, NiciraNvpResour lRouterPort = niciraNvpApi.createLogicalRouterPort(logicalRouterUuid, lRouterPort); } catch (NiciraNvpApiException e){ - s_logger.warn("Could not create Logical Router Port on Logical Router " + logicalRouterUuid + " due to: " + e.getMessage() + ", retrying"); + logger.warn("Could not create Logical Router Port on Logical Router " + logicalRouterUuid + " due to: " + e.getMessage() + ", retrying"); return handleException(e, command, niciraNvpResource); } - s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully created in Logical Router " + logicalRouterUuid); + logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully created in Logical Router " + logicalRouterUuid); //Step 3: Create lSwitchPort - s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")"); + logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")"); LogicalSwitchPort lSwitchPort = null; try { lSwitchPort = new LogicalSwitchPort(niciraNvpResource.truncate("lrouter-uplink", NAME_MAX_LEN), tags, true); lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort); } catch (NiciraNvpApiException e){ - s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ") due to: " + e.getMessage()); + logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ") due to: " + e.getMessage()); cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi); return handleException(e, command, niciraNvpResource); } - s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")"); + logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")"); //Step 4: Attach lRouterPort to lSwitchPort with a PatchAttachment - s_logger.debug("Attaching Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment"); + logger.debug("Attaching Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment"); try { niciraNvpApi.updateLogicalRouterPortAttachment(logicalRouterUuid, lRouterPort.getUuid(), new PatchAttachment(lSwitchPort.getUuid())); } catch (NiciraNvpApiException e) { - s_logger.warn("Could not attach Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying"); + logger.warn("Could not attach Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying"); cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi); cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi); return handleException(e, command, niciraNvpResource); } - s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully attached to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment"); + logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully attached to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment"); //Step 5: Attach lSwitchPort to lRouterPort with a PatchAttachment - s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment"); + logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment"); try { niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), new PatchAttachment(lRouterPort.getUuid())); } catch (NiciraNvpApiException e){ - s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying"); + logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying"); cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi); cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi); return handleException(e, command, niciraNvpResource); } - s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment"); + logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment"); - s_logger.info("Successfully attached Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId); + logger.info("Successfully attached Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId); return new ConfigureSharedNetworkUuidAnswer(command, true, "OK"); } private void cleanupLSwitchPort(String logicalSwitchUuid, LogicalSwitchPort lSwitchPort, NiciraNvpApi niciraNvpApi) { - s_logger.warn("Deleting previously created Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid); + logger.warn("Deleting previously created Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid); try { niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lSwitchPort.getUuid()); } catch (NiciraNvpApiException exceptionDeleteLSwitchPort) { - s_logger.error("Error while deleting Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid + " due to: " + exceptionDeleteLSwitchPort.getMessage()); + logger.error("Error while deleting Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid + " due to: " + exceptionDeleteLSwitchPort.getMessage()); } - s_logger.warn("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully deleted"); + logger.warn("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully deleted"); } private void cleanupLRouterPort(String logicalRouterUuid, LogicalRouterPort lRouterPort, NiciraNvpApi niciraNvpApi) { - s_logger.warn("Deleting previously created Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") from Logical Router " + logicalRouterUuid + " and retrying"); + logger.warn("Deleting previously created Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") from Logical Router " + logicalRouterUuid + " and retrying"); try { niciraNvpApi.deleteLogicalRouterPort(logicalRouterUuid, lRouterPort.getUuid()); } catch (NiciraNvpApiException exceptionDelete) { - s_logger.error("Error while deleting Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") from Logical Router " + logicalRouterUuid + " due to: " + exceptionDelete.getMessage()); + logger.error("Error while deleting Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") from Logical Router " + logicalRouterUuid + " due to: " + exceptionDelete.getMessage()); } - s_logger.warn("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully deleted"); + logger.warn("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully deleted"); } private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkUuidCommand command, NiciraNvpResource niciraNvpResource) { if (HttpStatusCodeHelper.isConflict(e.getErrorCode())){ - s_logger.warn("There's been a conflict in NSX side, aborting implementation"); + logger.warn("There's been a conflict in NSX side, aborting implementation"); return new ConfigureSharedNetworkUuidAnswer(command, false, "FAILED: There's been a conflict in NSX side"); } else { - s_logger.warn("Error code: " + e.getErrorCode() + ", retrying"); + logger.warn("Error code: " + e.getErrorCode() + ", retrying"); final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); retryUtility.addRetry(command, NUM_RETRIES); return retryUtility.retry(command, ConfigureSharedNetworkUuidAnswer.class, e); diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java index 4fa9876976b0..ebc84f23754c 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer; @@ -44,7 +43,6 @@ @ResourceWrapper(handles = ConfigureSharedNetworkVlanIdCommand.class) public class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper extends CommandWrapper{ - private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.class); @Override public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) { @@ -55,10 +53,10 @@ public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpReso tags.add(new NiciraNvpTag("cs_account", command.getOwnerName())); final long networkId = command.getNetworkId(); - s_logger.debug("Connecting Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + " network " + networkId); + logger.debug("Connecting Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + " network " + networkId); final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid); + logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid); LogicalSwitchPort lSwitchPort = null; try { lSwitchPort = new LogicalSwitchPort(); @@ -68,12 +66,12 @@ public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpReso lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort); } catch (NiciraNvpApiException e){ - s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " due to: " + e.getMessage() + ", retrying"); + logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " due to: " + e.getMessage() + ", retrying"); return handleException(e, command, niciraNvpResource); } - s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid); + logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid); - s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") on VLAN " + command.getVlanId() + " using L2GatewayAttachment"); + logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") on VLAN " + command.getVlanId() + " using L2GatewayAttachment"); try { final L2GatewayAttachment attachment = new L2GatewayAttachment(l2GatewayServiceUuid); if (command.getVlanId() != 0) { @@ -82,33 +80,33 @@ public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpReso niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), attachment); } catch (NiciraNvpApiException e){ - s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", errorCode: " + e.getErrorCode()); + logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", errorCode: " + e.getErrorCode()); cleanup(logicalSwitchUuid, lSwitchPort, niciraNvpApi); return handleException(e, command, niciraNvpResource); } - s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached on VLAN " + command.getVlanId() + " using L2GatewayAttachment"); + logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached on VLAN " + command.getVlanId() + " using L2GatewayAttachment"); - s_logger.debug("Successfully connected Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + ", network " + networkId + ", through Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ")"); + logger.debug("Successfully connected Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + ", network " + networkId + ", through Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ")"); return new ConfigureSharedNetworkVlanIdAnswer(command, true, "OK"); } private void cleanup(String logicalSwitchUuid, LogicalSwitchPort lSwitchPort, NiciraNvpApi niciraNvpApi) { - s_logger.warn("Deleting previously created Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid); + logger.warn("Deleting previously created Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid); try { niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lSwitchPort.getUuid()); } catch (NiciraNvpApiException exceptionDeleteLSwitchPort) { - s_logger.error("Error while deleting Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid + " due to: " + exceptionDeleteLSwitchPort.getMessage()); + logger.error("Error while deleting Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid + " due to: " + exceptionDeleteLSwitchPort.getMessage()); } - s_logger.warn("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully deteled"); + logger.warn("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully deteled"); } private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) { if (HttpStatusCodeHelper.isConflict(e.getErrorCode())){ - s_logger.warn("There's been a conflict in NSX side, aborting implementation"); + logger.warn("There's been a conflict in NSX side, aborting implementation"); return new ConfigureSharedNetworkVlanIdAnswer(command, false, "FAILED: There's been a conflict in NSX side"); } else { - s_logger.warn("Error code: " + e.getErrorCode() + ", retrying"); + logger.warn("Error code: " + e.getErrorCode() + ", retrying"); final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); retryUtility.addRetry(command, NUM_RETRIES); return retryUtility.retry(command, ConfigureSharedNetworkVlanIdAnswer.class, e); diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureStaticNatRulesCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureStaticNatRulesCommandWrapper.java index 595a623b0e40..bc6c03f87aac 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureStaticNatRulesCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureStaticNatRulesCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = ConfigureStaticNatRulesOnLogicalRouterCommand.class) public final class NiciraNvpConfigureStaticNatRulesCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigureStaticNatRulesCommandWrapper.class); @Override public Answer execute(final ConfigureStaticNatRulesOnLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) { @@ -63,14 +61,14 @@ public Answer execute(final ConfigureStaticNatRulesOnLogicalRouterCommand comman if (storedRule.equalsIgnoreUuid(rulepair[1])) { // The outgoing rule exists outgoing = storedRule; - s_logger.debug("Found matching outgoing rule " + outgoing.getUuid()); + logger.debug("Found matching outgoing rule " + outgoing.getUuid()); if (incoming != null) { break; } } else if (storedRule.equalsIgnoreUuid(rulepair[0])) { // The incoming rule exists incoming = storedRule; - s_logger.debug("Found matching incoming rule " + incoming.getUuid()); + logger.debug("Found matching incoming rule " + incoming.getUuid()); if (outgoing != null) { break; } @@ -78,26 +76,26 @@ public Answer execute(final ConfigureStaticNatRulesOnLogicalRouterCommand comman } if (incoming != null && outgoing != null) { if (rule.revoked()) { - s_logger.debug("Deleting incoming rule " + incoming.getUuid()); + logger.debug("Deleting incoming rule " + incoming.getUuid()); niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), incoming.getUuid()); - s_logger.debug("Deleting outgoing rule " + outgoing.getUuid()); + logger.debug("Deleting outgoing rule " + outgoing.getUuid()); niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), outgoing.getUuid()); } } else { if (rule.revoked()) { - s_logger.warn("Tried deleting a rule that does not exist, " + rule.getSrcIp() + " -> " + rule.getDstIp()); + logger.warn("Tried deleting a rule that does not exist, " + rule.getSrcIp() + " -> " + rule.getDstIp()); break; } rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0]); - s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[0])); + logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[0])); try { rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[1]); - s_logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[1])); + logger.debug("Created " + niciraNvpResource.natRuleToString(rulepair[1])); } catch (final NiciraNvpApiException ex) { - s_logger.debug("Failed to create SourceNatRule, rolling back DestinationNatRule"); + logger.debug("Failed to create SourceNatRule, rolling back DestinationNatRule"); niciraNvpApi.deleteLogicalRouterNatRule(command.getLogicalRouterUuid(), rulepair[0].getUuid()); throw ex; // Rethrow original exception } diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalRouterCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalRouterCommandWrapper.java index 1031b3b78702..267a59da09eb 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalRouterCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalRouterCommandWrapper.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CreateLogicalRouterAnswer; @@ -50,7 +49,6 @@ @ResourceWrapper(handles = CreateLogicalRouterCommand.class) public final class NiciraNvpCreateLogicalRouterCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(NiciraNvpCreateLogicalRouterCommandWrapper.class); @Override public Answer execute(final CreateLogicalRouterCommand command, final NiciraNvpResource niciraNvpResource) { @@ -65,7 +63,7 @@ public Answer execute(final CreateLogicalRouterCommand command, final NiciraNvpR final String publicNetworkIpAddress = command.getPublicIpCidr(); final String internalNetworkAddress = command.getInternalIpCidr(); - s_logger.debug("Creating a logical router with external ip " + publicNetworkIpAddress + " and internal ip " + internalNetworkAddress + "on gateway service " + + logger.debug("Creating a logical router with external ip " + publicNetworkIpAddress + " and internal ip " + internalNetworkAddress + "on gateway service " + gatewayServiceUuid); final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchPortCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchPortCommandWrapper.java index 63df438239c7..a0d30542fd6d 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchPortCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpCreateLogicalSwitchPortCommandWrapper.java @@ -21,7 +21,6 @@ import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CreateLogicalSwitchPortAnswer; @@ -39,7 +38,6 @@ @ResourceWrapper(handles = CreateLogicalSwitchPortCommand.class) public final class NiciraNvpCreateLogicalSwitchPortCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(NiciraNvpCreateLogicalSwitchPortCommandWrapper.class); @Override public Answer execute(final CreateLogicalSwitchPortCommand command, final NiciraNvpResource niciraNvpResource) { @@ -56,7 +54,7 @@ public Answer execute(final CreateLogicalSwitchPortCommand command, final Nicira try { niciraNvpApi.updateLogicalSwitchPortAttachment(command.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid)); } catch (final NiciraNvpApiException ex) { - s_logger.warn("modifyLogicalSwitchPort failed after switchport was created, removing switchport"); + logger.warn("modifyLogicalSwitchPort failed after switchport was created, removing switchport"); niciraNvpApi.deleteLogicalSwitchPort(command.getLogicalSwitchUuid(), newPort.getUuid()); throw ex; // Rethrow the original exception } diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterPortCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterPortCommandWrapper.java index a087f0731974..a585641bebfd 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterPortCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterPortCommandWrapper.java @@ -21,7 +21,6 @@ import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.DeleteLogicalRouterPortAnswer; @@ -36,7 +35,6 @@ @ResourceWrapper(handles = DeleteLogicalRouterPortCommand.class) public class NiciraNvpDeleteLogicalRouterPortCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(NiciraNvpDeleteLogicalRouterPortCommandWrapper.class); @Override public Answer execute(DeleteLogicalRouterPortCommand command, NiciraNvpResource niciraNvpResource) { @@ -44,7 +42,7 @@ public Answer execute(DeleteLogicalRouterPortCommand command, NiciraNvpResource final String logicalRouterPortUuid = command.getLogicalRouterPortUuid(); final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - s_logger.debug("Deleting Logical Router Port " + logicalRouterPortUuid + " in Logical Router " + logicalRouterUuid); + logger.debug("Deleting Logical Router Port " + logicalRouterPortUuid + " in Logical Router " + logicalRouterUuid); try { niciraNvpApi.deleteLogicalRouterPort(logicalRouterUuid, logicalRouterPortUuid); return new DeleteLogicalRouterPortAnswer(command, true, "Logical Router Port " + logicalRouterPortUuid + " deleted"); diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java index 621f503d0634..03858d197305 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.FindL2GatewayServiceAnswer; @@ -40,7 +39,6 @@ @ResourceWrapper(handles = FindL2GatewayServiceCommand.class) public class NiciraNvpFindL2GatewayServiceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(NiciraNvpFindL2GatewayServiceCommandWrapper.class); @Override public Answer execute(FindL2GatewayServiceCommand command, NiciraNvpResource niciraNvpResource) { @@ -49,7 +47,7 @@ public Answer execute(FindL2GatewayServiceCommand command, NiciraNvpResource nic final String type = config.getType(); final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - s_logger.info("Looking for L2 Gateway Service " + uuid + " of type " + type); + logger.info("Looking for L2 Gateway Service " + uuid + " of type " + type); try { List lstGW = niciraNvpApi.findL2GatewayServiceByUuidAndType(uuid, type); @@ -59,7 +57,7 @@ public Answer execute(FindL2GatewayServiceCommand command, NiciraNvpResource nic return new FindL2GatewayServiceAnswer(command, true, "L2 Gateway Service " + lstGW.get(0).getDisplayName()+ " found", lstGW.get(0).getUuid()); } } catch (NiciraNvpApiException e) { - s_logger.error("Error finding Gateway Service due to: " + e.getMessage()); + logger.error("Error finding Gateway Service due to: " + e.getMessage()); final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); retryUtility.addRetry(command, NUM_RETRIES); return retryUtility.retry(command, FindL2GatewayServiceAnswer.class, e); diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalRouterPortCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalRouterPortCommandWrapper.java index 364d478ae162..f0ee21662985 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalRouterPortCommandWrapper.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalRouterPortCommandWrapper.java @@ -23,7 +23,6 @@ import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.FindLogicalRouterPortAnswer; @@ -39,7 +38,6 @@ @ResourceWrapper(handles = FindLogicalRouterPortCommand.class) public class NiciraNvpFindLogicalRouterPortCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(NiciraNvpFindLogicalRouterPortCommandWrapper.class); @Override public Answer execute(FindLogicalRouterPortCommand command, NiciraNvpResource niciraNvpResource) { @@ -47,7 +45,7 @@ public Answer execute(FindLogicalRouterPortCommand command, NiciraNvpResource ni final String attachmentLswitchUuid = command.getAttachmentLswitchUuid(); final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi(); - s_logger.debug("Finding Logical Router Port in Logical Router " + logicalRouterUuid + " and attachmentLSwitchUuid " + attachmentLswitchUuid); + logger.debug("Finding Logical Router Port in Logical Router " + logicalRouterUuid + " and attachmentLSwitchUuid " + attachmentLswitchUuid); try{ List lRouterPorts = niciraNvpApi.findLogicalRouterPortByAttachmentLSwitchUuid(logicalRouterUuid, attachmentLswitchUuid); @@ -58,7 +56,7 @@ public Answer execute(FindLogicalRouterPortCommand command, NiciraNvpResource ni } } catch (NiciraNvpApiException e){ - s_logger.error("Error finding Logical Router Port due to: " + e.getMessage()); + logger.error("Error finding Logical Router Port due to: " + e.getMessage()); final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility(); retryUtility.addRetry(command, NUM_RETRIES); return retryUtility.retry(command, FindLogicalRouterPortAnswer.class, e); diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/utils/CommandRetryUtility.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/utils/CommandRetryUtility.java index f097cbcb83a0..3fd933ccbe13 100644 --- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/utils/CommandRetryUtility.java +++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/utils/CommandRetryUtility.java @@ -23,7 +23,8 @@ import java.lang.reflect.InvocationTargetException; import java.util.concurrent.ConcurrentHashMap; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -31,7 +32,7 @@ public class CommandRetryUtility { - private static final Logger s_logger = Logger.getLogger(CommandRetryUtility.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int ZERO = 0; private static CommandRetryUtility instance; @@ -72,7 +73,7 @@ public Answer retry(final Command command, final Class answerC if (numRetries > ZERO) { commandsToRetry.put(command, --numRetries); - s_logger.warn("Retrying " + command.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); + logger.warn("Retrying " + command.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); return serverResource.executeRequest(command); } else { diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java index 7c698459f79a..4c3288d73448 100644 --- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java +++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java @@ -21,9 +21,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -267,7 +267,7 @@ public boolean matches(final ConfigurePublicIpsOnLogicalRouterCommand command) { @Test public void implementSharedNetworkUuidVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - // SHARED NETWORKS CASE 1: LOGICAL ROUTER'S UUID AS VLAN ID + // SHARED NETWORKS CASE 1: loggerICAL ROUTER'S UUID AS VLAN ID final Network network = mock(Network.class); when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa")); diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java index c99404a3ec31..c6ad8a6d9070 100644 --- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java +++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java @@ -21,9 +21,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -168,7 +168,7 @@ public void testDesign() { final Network network = mock(Network.class); final Account account = mock(Account.class); - final Network designednetwork = guru.design(offering, plan, network, account); + final Network designednetwork = guru.design(offering, plan, network, "", 1L, account); assertTrue(designednetwork != null); assertTrue(designednetwork.getBroadcastDomainType() == BroadcastDomainType.Lswitch); } @@ -192,7 +192,7 @@ public void testDesignNoElementOnPhysicalNetwork() { final Network network = mock(Network.class); final Account account = mock(Account.class); - final Network designednetwork = guru.design(offering, plan, network, account); + final Network designednetwork = guru.design(offering, plan, network, "", 1L, account); assertTrue(designednetwork == null); } @@ -215,7 +215,7 @@ public void testDesignNoIsolationMethodSTT() { final Network network = mock(Network.class); final Account account = mock(Account.class); - final Network designednetwork = guru.design(offering, plan, network, account); + final Network designednetwork = guru.design(offering, plan, network, "", 1L, account); assertTrue(designednetwork == null); } @@ -241,7 +241,7 @@ public void testDesignNoConnectivityInOffering() { final Network network = mock(Network.class); final Account account = mock(Account.class); - final Network designednetwork = guru.design(offering, plan, network, account); + final Network designednetwork = guru.design(offering, plan, network, "", 1L, account); assertTrue(designednetwork == null); } diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraNvpApiTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraNvpApiTest.java index 34518cedad58..ed3eccaaafc1 100644 --- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraNvpApiTest.java +++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraNvpApiTest.java @@ -23,7 +23,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.hasSize; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; diff --git a/plugins/network-elements/nicira-nvp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/network-elements/nicira-nvp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/network-elements/nicira-nvp/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/network-elements/nsx/pom.xml b/plugins/network-elements/nsx/pom.xml new file mode 100644 index 000000000000..9e8d6ee7bce8 --- /dev/null +++ b/plugins/network-elements/nsx/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + cloud-plugin-network-nsx + Apache CloudStack Plugin - NSX Network + + + org.apache.cloudstack + cloudstack-plugins + 4.20.0.0-SNAPSHOT + ../../pom.xml + + + + com.vmware + nsx-java-sdk + 4.1.0.2.0 + + + com.vmware + nsx-gpm-java-sdk + 4.1.0.2.0 + + + com.vmware + nsx-policy-java-sdk + 4.1.0.2.0 + + + com.vmware.vapi + vapi-authentication + 2.40.0 + + + * + * + + + + + com.vmware.vapi + vapi-runtime + 2.40.0 + + + diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/NsxAnswer.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/NsxAnswer.java new file mode 100644 index 000000000000..a667adda7945 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/NsxAnswer.java @@ -0,0 +1,41 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; + +public class NsxAnswer extends Answer { + + private boolean objectExists; + + public NsxAnswer(final Command command, final boolean success, final String details) { + super(command, success, details); + } + + public NsxAnswer(final Command command, final Exception e) { + super(command, e); + } + + public boolean isObjectExistent() { + return objectExists; + } + + public void setObjectExists(boolean objectExisted) { + this.objectExists = objectExisted; + } +} diff --git a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/util/LoggerFactory.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/StartupNsxCommand.java similarity index 77% rename from services/console-proxy/server/src/main/java/com/cloud/consoleproxy/util/LoggerFactory.java rename to plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/StartupNsxCommand.java index 121411adf162..8a5ac35e57e9 100644 --- a/services/console-proxy/server/src/main/java/com/cloud/consoleproxy/util/LoggerFactory.java +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/StartupNsxCommand.java @@ -14,8 +14,13 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -package com.cloud.consoleproxy.util; +package org.apache.cloudstack; -public interface LoggerFactory { - Logger getLogger(Class clazz); +import com.cloud.agent.api.StartupCommand; +import com.cloud.host.Host; + +public class StartupNsxCommand extends StartupCommand { + public StartupNsxCommand() { + super(Host.Type.L2Networking); + } } diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxDhcpRelayConfigCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxDhcpRelayConfigCommand.java new file mode 100644 index 000000000000..6ef75b21e309 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxDhcpRelayConfigCommand.java @@ -0,0 +1,77 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import java.util.List; +import java.util.Objects; + +public class CreateNsxDhcpRelayConfigCommand extends NsxCommand { + + private Long vpcId; + private String vpcName; + private long networkId; + private String networkName; + private List addresses; + + public CreateNsxDhcpRelayConfigCommand(long domainId, long accountId, long zoneId, + Long vpcId, String vpcName, long networkId, String networkName, + List addresses) { + super(domainId, accountId, zoneId); + this.vpcId = vpcId; + this.vpcName = vpcName; + this.networkId = networkId; + this.networkName = networkName; + this.addresses = addresses; + } + + public Long getVpcId() { + return vpcId; + } + + public String getVpcName() { + return vpcName; + } + + public long getNetworkId() { + return networkId; + } + + public String getNetworkName() { + return networkName; + } + + public List getAddresses() { + return addresses; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + CreateNsxDhcpRelayConfigCommand that = (CreateNsxDhcpRelayConfigCommand) o; + return networkId == that.networkId && Objects.equals(vpcId, that.vpcId) && Objects.equals(vpcName, that.vpcName) && Objects.equals(networkName, that.networkName) && Objects.equals(addresses, that.addresses); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), vpcId, vpcName, networkId, networkName, addresses); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxDistributedFirewallRulesCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxDistributedFirewallRulesCommand.java new file mode 100644 index 000000000000..f598a2014298 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxDistributedFirewallRulesCommand.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import org.apache.cloudstack.resource.NsxNetworkRule; + +import java.util.List; +import java.util.Objects; + +public class CreateNsxDistributedFirewallRulesCommand extends NsxCommand { + + private Long vpcId; + private long networkId; + private List rules; + + public CreateNsxDistributedFirewallRulesCommand(long domainId, long accountId, long zoneId, + Long vpcId, long networkId, + List rules) { + super(domainId, accountId, zoneId); + this.vpcId = vpcId; + this.networkId = networkId; + this.rules = rules; + } + + public Long getVpcId() { + return vpcId; + } + + public long getNetworkId() { + return networkId; + } + + public List getRules() { + return rules; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + CreateNsxDistributedFirewallRulesCommand that = (CreateNsxDistributedFirewallRulesCommand) o; + return networkId == that.networkId && Objects.equals(vpcId, that.vpcId) && Objects.equals(rules, that.rules); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), vpcId, networkId, rules); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxLoadBalancerRuleCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxLoadBalancerRuleCommand.java new file mode 100644 index 000000000000..92acc83064d7 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxLoadBalancerRuleCommand.java @@ -0,0 +1,87 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import org.apache.cloudstack.resource.NsxLoadBalancerMember; + +import java.util.List; +import java.util.Objects; + +public class CreateNsxLoadBalancerRuleCommand extends NsxNetworkCommand { + + private final String publicPort; + private final String privatePort; + private final String algorithm; + private final String protocol; + List memberList; + + private final long lbId; + public CreateNsxLoadBalancerRuleCommand(long domainId, long accountId, long zoneId, Long networkResourceId, + String networkResourceName, boolean isResourceVpc, + List memberList, long lbId, String publicPort, + String privatePort, String algorithm, String protocol) { + super(domainId, accountId, zoneId, networkResourceId, networkResourceName, isResourceVpc); + this.lbId = lbId; + this.memberList = memberList; + this.publicPort = publicPort; + this.privatePort = privatePort; + this.algorithm = algorithm; + this.protocol = protocol; + } + + + public long getLbId() { + return lbId; + } + + public String getPublicPort() { + return publicPort; + } + + public String getPrivatePort() { + return privatePort; + } + + public List getMemberList() { + return memberList; + } + + public String getAlgorithm() { + return algorithm; + } + + public String getProtocol() { + return protocol; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + CreateNsxLoadBalancerRuleCommand command = (CreateNsxLoadBalancerRuleCommand) o; + return lbId == command.lbId && Objects.equals(publicPort, command.publicPort) && Objects.equals(privatePort, command.privatePort) && Objects.equals(algorithm, command.algorithm) && Objects.equals(protocol, command.protocol) && Objects.equals(memberList, command.memberList); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), publicPort, privatePort, algorithm, protocol, memberList, lbId); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxPortForwardRuleCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxPortForwardRuleCommand.java new file mode 100644 index 000000000000..d72295563c7e --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxPortForwardRuleCommand.java @@ -0,0 +1,71 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import java.util.Objects; + +public class CreateNsxPortForwardRuleCommand extends NsxNetworkCommand { + private final String publicPort; + private final String privatePort; + private final String protocol; + private final long ruleId; + + + public CreateNsxPortForwardRuleCommand(long domainId, long accountId, long zoneId, Long networkResourceId, + String networkResourceName, boolean isResourceVpc, Long vmId, + long ruleId, String publicIp, String vmIp, String publicPort, String privatePort, String protocol) { + super(domainId, accountId, zoneId, networkResourceId, networkResourceName, isResourceVpc, vmId, publicIp, vmIp); + this.publicPort = publicPort; + this.privatePort = privatePort; + this.ruleId = ruleId; + this.protocol = protocol; + + } + + public String getPublicPort() { + return publicPort; + } + + public String getPrivatePort() { + return privatePort; + } + + public long getRuleId() { + return ruleId; + } + + public String getProtocol() { + return protocol; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + CreateNsxPortForwardRuleCommand that = (CreateNsxPortForwardRuleCommand) o; + return ruleId == that.ruleId && Objects.equals(publicPort, that.publicPort) && Objects.equals(privatePort, that.privatePort) && Objects.equals(protocol, that.protocol); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), publicPort, privatePort, protocol, ruleId); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxSegmentCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxSegmentCommand.java new file mode 100644 index 000000000000..b4b86bd640a6 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxSegmentCommand.java @@ -0,0 +1,79 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import java.util.Objects; + +public class CreateNsxSegmentCommand extends NsxCommand { + + private Long vpcId; + private String vpcName; + private long networkId; + private String networkName; + private String networkGateway; + private String networkCidr; + + public CreateNsxSegmentCommand(long domainId, long accountId, long zoneId, + Long vpcId, String vpcName, long networkId, String networkName, + String networkGateway, String networkCidr) { + super(domainId, accountId, zoneId); + this.vpcId = vpcId; + this.vpcName = vpcName; + this.networkId = networkId; + this.networkName = networkName; + this.networkGateway = networkGateway; + this.networkCidr = networkCidr; + } + + public Long getVpcId() { + return vpcId; + } + + public String getVpcName() { + return vpcName; + } + + public long getNetworkId() { + return networkId; + } + + public String getNetworkName() { + return networkName; + } + + public String getNetworkGateway() { + return networkGateway; + } + + public String getNetworkCidr() { + return networkCidr; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + CreateNsxSegmentCommand command = (CreateNsxSegmentCommand) o; + return Objects.equals(networkName, command.networkName); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), networkName); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxStaticNatCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxStaticNatCommand.java new file mode 100644 index 000000000000..08c13420d1d3 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxStaticNatCommand.java @@ -0,0 +1,25 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +public class CreateNsxStaticNatCommand extends NsxNetworkCommand { + + public CreateNsxStaticNatCommand(long domainId, long accountId, long zoneId, Long networkResourceId, String networkResourceName, + boolean isResourceVpc, Long vmId, String publicIp, String vmIp) { + super(domainId, accountId, zoneId, networkResourceId, networkResourceName, isResourceVpc, vmId, publicIp, vmIp); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxTier1GatewayCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxTier1GatewayCommand.java new file mode 100644 index 000000000000..90e4b3a25bdd --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateNsxTier1GatewayCommand.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import java.util.Objects; + +public class CreateNsxTier1GatewayCommand extends NsxCommand { + + private Long networkResourceId; + private String networkResourceName; + private boolean isResourceVpc; + private boolean sourceNatEnabled; + + public CreateNsxTier1GatewayCommand(long domainId, long accountId, long zoneId, + Long networkResourceId, String networkResourceName, boolean isResourceVpc, + boolean sourceNatEnabled) { + super(domainId, accountId, zoneId); + this.networkResourceId = networkResourceId; + this.networkResourceName = networkResourceName; + this.isResourceVpc = isResourceVpc; + this.sourceNatEnabled = sourceNatEnabled; + } + + public Long getNetworkResourceId() { + return networkResourceId; + } + + public boolean isResourceVpc() { + return isResourceVpc; + } + + public String getNetworkResourceName() { + return networkResourceName; + } + + public boolean isSourceNatEnabled() { + return sourceNatEnabled; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + CreateNsxTier1GatewayCommand that = (CreateNsxTier1GatewayCommand) o; + return Objects.equals(networkResourceName, that.networkResourceName); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), networkResourceName); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateOrUpdateNsxTier1NatRuleCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateOrUpdateNsxTier1NatRuleCommand.java new file mode 100644 index 000000000000..c14be743ea08 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/CreateOrUpdateNsxTier1NatRuleCommand.java @@ -0,0 +1,69 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import java.util.Objects; + +public class CreateOrUpdateNsxTier1NatRuleCommand extends NsxCommand { + + private String tier1GatewayName; + private String action; + private String translatedIpAddress; + private String natRuleId; + + public CreateOrUpdateNsxTier1NatRuleCommand(long domainId, long accountId, long zoneId, + String tier1GatewayName, String action, String translatedIpAddress, String natRuleId) { + super(domainId, accountId, zoneId); + this.tier1GatewayName = tier1GatewayName; + this.action = action; + this.translatedIpAddress = translatedIpAddress; + this.natRuleId = natRuleId; + } + + public String getTier1GatewayName() { + return tier1GatewayName; + } + + public String getAction() { + return action; + } + + public String getTranslatedIpAddress() { + return translatedIpAddress; + } + + public String getNatRuleId() { + return natRuleId; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + CreateOrUpdateNsxTier1NatRuleCommand that = (CreateOrUpdateNsxTier1NatRuleCommand) o; + return Objects.equals(tier1GatewayName, that.tier1GatewayName) && Objects.equals(action, that.action) && Objects.equals(translatedIpAddress, that.translatedIpAddress) && Objects.equals(natRuleId, that.natRuleId); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), tier1GatewayName, action, translatedIpAddress, natRuleId); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxDistributedFirewallRulesCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxDistributedFirewallRulesCommand.java new file mode 100644 index 000000000000..ad88f23b3b18 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxDistributedFirewallRulesCommand.java @@ -0,0 +1,27 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import org.apache.cloudstack.resource.NsxNetworkRule; + +import java.util.List; + +public class DeleteNsxDistributedFirewallRulesCommand extends CreateNsxDistributedFirewallRulesCommand { + public DeleteNsxDistributedFirewallRulesCommand(long domainId, long accountId, long zoneId, Long vpcId, long networkId, List rules) { + super(domainId, accountId, zoneId, vpcId, networkId, rules); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxLoadBalancerRuleCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxLoadBalancerRuleCommand.java new file mode 100644 index 000000000000..72aa61fdca37 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxLoadBalancerRuleCommand.java @@ -0,0 +1,58 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import org.apache.cloudstack.resource.NsxLoadBalancerMember; + +import java.util.List; +import java.util.Objects; + +public class DeleteNsxLoadBalancerRuleCommand extends NsxNetworkCommand { + private long lbId; + List memberList; + + public DeleteNsxLoadBalancerRuleCommand(long domainId, long accountId, long zoneId, Long networkResourceId, + String networkResourceName, boolean isResourceVpc, + List memberList, long lbId, long vmId) { + super(domainId, accountId, zoneId, networkResourceId, networkResourceName, isResourceVpc, vmId); + this.lbId = lbId; + this.memberList = memberList; + } + + public long getLbId() { + return lbId; + } + + public List getMemberList() { return memberList; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + DeleteNsxLoadBalancerRuleCommand that = (DeleteNsxLoadBalancerRuleCommand) o; + return lbId == that.lbId && Objects.equals(memberList, that.memberList); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), lbId, memberList); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxNatRuleCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxNatRuleCommand.java new file mode 100644 index 000000000000..c5231b19ac40 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxNatRuleCommand.java @@ -0,0 +1,73 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import com.cloud.network.Network; + +import java.util.Objects; + +public class DeleteNsxNatRuleCommand extends NsxNetworkCommand { + private Long ruleId; + private Network.Service service; + + private String privatePort; + private String protocol; + public DeleteNsxNatRuleCommand(long domainId, long accountId, long zoneId, Long networkResourceId, String networkResourceName, + boolean isResourceVpc, Long vmId, Long ruleId, String privatePort, String protocol) { + super(domainId, accountId, zoneId, networkResourceId, networkResourceName, isResourceVpc, vmId); + this.ruleId = ruleId; + this.privatePort = privatePort; + this.protocol = protocol; + } + + public Long getRuleId() { + return ruleId; + } + + public Network.Service getService() { + return service; + } + + public void setService(Network.Service service) { + this.service = service; + } + + public String getPrivatePort() { + return privatePort; + } + + public String getProtocol() { + return protocol; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + DeleteNsxNatRuleCommand that = (DeleteNsxNatRuleCommand) o; + return Objects.equals(ruleId, that.ruleId) && Objects.equals(service, that.service) && Objects.equals(privatePort, that.privatePort) && Objects.equals(protocol, that.protocol); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), ruleId, service, privatePort, protocol); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxSegmentCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxSegmentCommand.java new file mode 100644 index 000000000000..882b55388ff6 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxSegmentCommand.java @@ -0,0 +1,70 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import java.util.Objects; + +public class DeleteNsxSegmentCommand extends NsxCommand { + + private Long vpcId; + private String vpcName; + + private long networkId; + private String networkName; + + public DeleteNsxSegmentCommand(long domainId, long accountId, long zoneId, Long vpcId, + String vpcName, long networkId, String networkName) { + super(domainId, accountId, zoneId); + this.vpcId = vpcId; + this.vpcName = vpcName; + this.networkId = networkId; + this.networkName = networkName; + } + + public Long getVpcId() { + return vpcId; + } + + public String getVpcName() { + return vpcName; + } + + public long getNetworkId() { + return networkId; + } + + public String getNetworkName() { + return networkName; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + DeleteNsxSegmentCommand command = (DeleteNsxSegmentCommand) o; + return networkId == command.networkId && Objects.equals(vpcId, command.vpcId) && Objects.equals(vpcName, command.vpcName) && Objects.equals(networkName, command.networkName); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), vpcId, vpcName, networkId, networkName); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxTier1GatewayCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxTier1GatewayCommand.java new file mode 100644 index 000000000000..d05acc180026 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/DeleteNsxTier1GatewayCommand.java @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import java.util.Objects; + +public class DeleteNsxTier1GatewayCommand extends NsxCommand { + + private Long networkResourceId; + private String networkResourceName; + private boolean isResourceVpc; + + public DeleteNsxTier1GatewayCommand(long domainId, long accountId, long zoneId, + Long networkResourceId, String networkResourceName, boolean isResourceVpc) { + super(domainId, accountId, zoneId); + this.networkResourceId = networkResourceId; + this.networkResourceName = networkResourceName; + this.isResourceVpc = isResourceVpc; + } + + public Long getNetworkResourceId() { + return networkResourceId; + } + + public String getNetworkResourceName() { + return networkResourceName; + } + + public boolean isResourceVpc() { + return isResourceVpc; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass() || !super.equals(o)) { + return false; + } + DeleteNsxTier1GatewayCommand that = (DeleteNsxTier1GatewayCommand) o; + return isResourceVpc == that.isResourceVpc && Objects.equals(networkResourceId, that.networkResourceId) && Objects.equals(networkResourceName, that.networkResourceName); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), networkResourceId, networkResourceName, isResourceVpc); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/NsxCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/NsxCommand.java new file mode 100644 index 000000000000..7c5e3a1d9fa8 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/NsxCommand.java @@ -0,0 +1,67 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import com.cloud.agent.api.Command; + +import java.util.Objects; + +public class NsxCommand extends Command { + private long zoneId; + private long accountId; + private long domainId; + + public NsxCommand() { + } + + public NsxCommand(long domainId, long accountId, long zoneId) { + this.zoneId = zoneId; + this.accountId = accountId; + this.domainId = domainId; + } + + public long getZoneId() { + return zoneId; + } + + public long getAccountId() { + return accountId; + } + + public long getDomainId() { + return domainId; + } + + @Override + public boolean executeInSequence() { + return false; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + NsxCommand that = (NsxCommand) o; + return Objects.equals(zoneId, that.zoneId) && Objects.equals(accountId, that.accountId) && Objects.equals(domainId, that.domainId); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), zoneId, accountId, domainId); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/NsxNetworkCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/NsxNetworkCommand.java new file mode 100644 index 000000000000..4cad50db356b --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/NsxNetworkCommand.java @@ -0,0 +1,117 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import java.util.Objects; + +public class NsxNetworkCommand extends NsxCommand { + private Long networkResourceId; + private String networkResourceName; + private boolean isResourceVpc; + private Long vmId; + private String publicIp; + private String vmIp; + + public NsxNetworkCommand(long domainId, long accountId, long zoneId, Long networkResourceId, String networkResourceName, + boolean isResourceVpc, Long vmId, String publicIp, String vmIp) { + super(domainId, accountId, zoneId); + this.networkResourceId = networkResourceId; + this.networkResourceName = networkResourceName; + this.isResourceVpc = isResourceVpc; + this.vmId = vmId; + this.publicIp = publicIp; + this.vmIp = vmIp; + } + + public NsxNetworkCommand(long domainId, long accountId, long zoneId, Long networkResourceId, String networkResourceName, + boolean isResourceVpc) { + super(domainId, accountId, zoneId); + this.networkResourceId = networkResourceId; + this.networkResourceName = networkResourceName; + this.isResourceVpc = isResourceVpc; + } + + public NsxNetworkCommand(long domainId, long accountId, long zoneId, Long networkResourceId, String networkResourceName, + boolean isResourceVpc, Long vmId) { + this(domainId, accountId, zoneId, networkResourceId, networkResourceName, isResourceVpc); + this.vmId = vmId; + } + + public Long getNetworkResourceId() { + return networkResourceId; + } + + public void setNetworkResourceId(long networkResourceId) { + this.networkResourceId = networkResourceId; + } + + public String getNetworkResourceName() { + return networkResourceName; + } + + public void setNetworkResourceName(String networkResourceName) { + this.networkResourceName = networkResourceName; + } + + public boolean isResourceVpc() { + return isResourceVpc; + } + + public void setResourceVpc(boolean resourceVpc) { + isResourceVpc = resourceVpc; + } + + public Long getVmId() { + return vmId; + } + + public void setVmId(Long vmId) { + this.vmId = vmId; + } + + public String getPublicIp() { + return publicIp; + } + + public void setPublicIp(String publicIp) { + this.publicIp = publicIp; + } + + public String getVmIp() { + return vmIp; + } + + public void setVmIp(String vmIp) { + this.vmIp = vmIp; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + NsxNetworkCommand that = (NsxNetworkCommand) o; + return networkResourceId == that.networkResourceId && vmId == that.vmId && + Objects.equals(networkResourceName, that.networkResourceName) && Objects.equals(publicIp, that.publicIp) + && Objects.equals(vmIp, that.vmIp); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), networkResourceId, networkResourceName, vmId, publicIp, vmIp); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/StartupNsxCommand.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/StartupNsxCommand.java new file mode 100644 index 000000000000..22deacca3544 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/agent/api/StartupNsxCommand.java @@ -0,0 +1,27 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.agent.api; + +import com.cloud.agent.api.StartupCommand; +import com.cloud.host.Host; + +public class StartupNsxCommand extends StartupCommand { + + public StartupNsxCommand() { + super(Host.Type.L2Networking); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/AddNsxControllerCmd.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/AddNsxControllerCmd.java new file mode 100644 index 000000000000..8e36599bf32a --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/AddNsxControllerCmd.java @@ -0,0 +1,130 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command; + +import com.cloud.network.nsx.NsxProvider; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.response.NsxControllerResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.service.NsxProviderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; + + +@APICommand(name = AddNsxControllerCmd.APINAME, description = "Add NSX Controller to CloudStack", + responseObject = NsxControllerResponse.class, requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, since = "4.19.0") +public class AddNsxControllerCmd extends BaseCmd { + public static final String APINAME = "addNsxController"; + public static final Logger LOGGER = LoggerFactory.getLogger(AddNsxControllerCmd.class.getName()); + + @Inject + NsxProviderService nsxProviderService; + + @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, + description = "the ID of zone") + private Long zoneId; + + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "NSX controller / provider name") + private String name; + + @Parameter(name = ApiConstants.NSX_PROVIDER_HOSTNAME, type = CommandType.STRING, required = true, description = "NSX controller hostname / IP address") + private String hostname; + + @Parameter(name = ApiConstants.NSX_PROVIDER_PORT, type = CommandType.STRING, description = "NSX controller port") + private String port; + @Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "Username to log into NSX controller") + private String username; + @Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "Password to login into NSX controller") + private String password; + + @Parameter(name = ApiConstants.TIER0_GATEWAY, type = CommandType.STRING, required = true, description = "Tier-0 Gateway address") + private String tier0Gateway; + + @Parameter(name = ApiConstants.EDGE_CLUSTER, type = CommandType.STRING, required = true, description = "Edge Cluster name") + private String edgeCluster; + + @Parameter(name = ApiConstants.TRANSPORT_ZONE, type = CommandType.STRING, required = true, description = "Transport Zone controls to which hosts a logical switch can reach") + private String transportZone; + + public NsxProviderService getNsxProviderService() { + return nsxProviderService; + } + + public Long getZoneId() { + return zoneId; + } + + public String getName() { + return name; + } + + public String getHostname() { + return hostname; + } + + public String getPort() { + return port; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getTier0Gateway() { + return tier0Gateway; + } + + public String getEdgeCluster() { + return edgeCluster; + } + + public String getTransportZone() { + return transportZone; + } + + @Override + public void execute() throws ServerApiException { + NsxProvider nsxProvider = nsxProviderService.addProvider(this); + NsxControllerResponse nsxControllerResponse = + nsxProviderService.createNsxControllerResponse( + nsxProvider); + if (nsxControllerResponse == null) + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add NSX controller"); + else { + nsxControllerResponse.setResponseName(getCommandName()); + setResponseObject(nsxControllerResponse); + } + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/DeleteNsxControllerCmd.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/DeleteNsxControllerCmd.java new file mode 100644 index 000000000000..5a3e55864008 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/DeleteNsxControllerCmd.java @@ -0,0 +1,87 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command; + +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.response.NsxControllerResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.service.NsxProviderService; + +import javax.inject.Inject; + +import static org.apache.cloudstack.api.command.DeleteNsxControllerCmd.APINAME; + +@APICommand(name = APINAME, description = "delete NSX Controller to CloudStack", + responseObject = NsxControllerResponse.class, requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, since = "4.19.0") +public class DeleteNsxControllerCmd extends BaseCmd { + public static final String APINAME = "deleteNsxController"; + + @Inject + protected NsxProviderService nsxProviderService; +///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.NSX_CONTROLLER_ID, type = CommandType.UUID, entityType = NsxControllerResponse.class, + required = true, description = "NSX Controller ID") + private Long nsxControllerId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getNsxControllerId() { + return nsxControllerId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + + @Override + public void execute() throws ServerApiException, ConcurrentOperationException { + try { + boolean deleted = nsxProviderService.deleteNsxController(getNsxControllerId()); + if (deleted) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove NSX Controller from Zone"); + } + } catch (InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); + } catch (CloudRuntimeException e) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); + } + } + + @Override + public long getEntityOwnerId() { + return 0; + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/ListNsxControllersCmd.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/ListNsxControllersCmd.java new file mode 100644 index 000000000000..94b5855e7830 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/command/ListNsxControllersCmd.java @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.utils.StringUtils; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NsxControllerResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.service.NsxProviderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import java.util.List; + +import static org.apache.cloudstack.api.command.ListNsxControllersCmd.APINAME; + +@APICommand(name = APINAME, description = "list all NSX controllers added to CloudStack", + responseObject = NsxControllerResponse.class, requestHasSensitiveInfo = false, + responseHasSensitiveInfo = false, since = "4.19.0") +public class ListNsxControllersCmd extends BaseListCmd { + public static final String APINAME = "listNsxControllers"; + public static final Logger LOGGER = LoggerFactory.getLogger(ListNsxControllersCmd.class.getName()); + + @Inject + private NsxProviderService nsxProviderService; + + @Parameter(name = ApiConstants.ZONE_ID, description = "NSX controller added to the specific zone", + type = CommandType.UUID, entityType = ZoneResponse.class) + Long zoneId; + + @Override + public void execute() throws ServerApiException, ConcurrentOperationException { + List baseResponseList = nsxProviderService.listNsxProviders(zoneId); + List pagingList = StringUtils.applyPagination(baseResponseList, this.getStartIndex(), this.getPageSizeVal()); + ListResponse listResponse = new ListResponse<>(); + listResponse.setResponses(pagingList); + listResponse.setResponseName(getCommandName()); + setResponseObject(listResponse); + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/response/NsxControllerResponse.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/response/NsxControllerResponse.java new file mode 100644 index 000000000000..910c5e115bf5 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/api/response/NsxControllerResponse.java @@ -0,0 +1,136 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import com.cloud.network.nsx.NsxProvider; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; + +@EntityReference(value = {NsxProvider.class}) +public class NsxControllerResponse extends BaseResponse { + @SerializedName(ApiConstants.NSX_PROVIDER_UUID) + @Param(description = "NSX controller ID") + private String uuid; + @SerializedName(ApiConstants.NAME) + @Param(description = "NSX controller name") + private String name; + + @SerializedName(ApiConstants.ZONE_ID) + @Param(description = "Zone ID to which the NSX controller is associated with") + private String zoneId; + + @SerializedName(ApiConstants.ZONE_NAME) + @Param(description = "Zone name to which the NSX controller is associated with") + private String zoneName; + + @SerializedName(ApiConstants.HOST_NAME) + @Param(description = "NSX controller hostname or IP address") + private String hostname; + + @SerializedName(ApiConstants.PORT) + @Param(description = "NSX controller port") + private String port; + + @SerializedName(ApiConstants.TIER0_GATEWAY) + @Param(description = "The tier-0 gateway network. Tier-0 gateway is responsible for handling" + + " traffic between logical and physical networks" + ) + private String tier0Gateway; + + @SerializedName(ApiConstants.EDGE_CLUSTER) + @Param(description = "The name of the edge cluster. An edge cluster is a logical grouping of edge nodes in NSX") + private String edgeCluster; + + @SerializedName(ApiConstants.TRANSPORT_ZONE) + @Param(description = "The name of the transport zone. A transport zone controls to which hosts a logical switch can reach") + private String transportZone; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getZoneId() { + return zoneId; + } + + public void setZoneId(String zoneId) { + this.zoneId = zoneId; + } + + public String getZoneName() { + return zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public String getHostname() { + return hostname; + } + + public void setHostname(String hostname) { + this.hostname = hostname; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getTier0Gateway() { + return tier0Gateway; + } + + public void setTier0Gateway(String tier0Gateway) { + this.tier0Gateway = tier0Gateway; + } + + public String getEdgeCluster() { + return edgeCluster; + } + + public void setEdgeCluster(String edgeCluster) { + this.edgeCluster = edgeCluster; + } + + public String getTransportZone() { + return transportZone; + } + + public void setTransportZone(String transportZone) { + this.transportZone = transportZone; + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxLoadBalancerMember.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxLoadBalancerMember.java new file mode 100644 index 000000000000..00960ddb78a5 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxLoadBalancerMember.java @@ -0,0 +1,41 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.resource; + +public class NsxLoadBalancerMember { + private long vmId; + private String vmIp; + private int port; + + public NsxLoadBalancerMember(long vmId, String vmIp, int port) { + this.vmId = vmId; + this.vmIp = vmIp; + this.port = port; + } + + public long getVmId() { + return vmId; + } + + public String getVmIp() { + return vmIp; + } + + public int getPort() { + return port; + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxNetworkRule.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxNetworkRule.java new file mode 100644 index 000000000000..c11141db9d42 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxNetworkRule.java @@ -0,0 +1,397 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.resource; + +import com.cloud.network.Network; + +import java.util.List; + +public class NsxNetworkRule { + + public enum NsxRuleAction { + ALLOW, DROP + } + + private long domainId; + private long accountId; + private long zoneId; + private Long networkResourceId; + private String networkResourceName; + private boolean isVpcResource; + private long vmId; + private long ruleId; + private String publicIp; + private String vmIp; + private String publicPort; + private String privatePort; + private String protocol; + private String algorithm; + private List memberList; + private NsxRuleAction aclAction; + private List sourceCidrList; + private List destinationCidrList; + private Integer icmpCode; + + private Integer icmpType; + private String trafficType; + private Network.Service service; + + public long getDomainId() { + return domainId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + public long getAccountId() { + return accountId; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public long getZoneId() { + return zoneId; + } + + public void setZoneId(long zoneId) { + this.zoneId = zoneId; + } + + public Long getNetworkResourceId() { + return networkResourceId; + } + + public void setNetworkResourceId(Long networkResourceId) { + this.networkResourceId = networkResourceId; + } + + public String getNetworkResourceName() { + return networkResourceName; + } + + public void setNetworkResourceName(String networkResourceName) { + this.networkResourceName = networkResourceName; + } + + public boolean isVpcResource() { + return isVpcResource; + } + + public void setVpcResource(boolean vpcResource) { + isVpcResource = vpcResource; + } + + public long getVmId() { + return vmId; + } + + public void setVmId(long vmId) { + this.vmId = vmId; + } + + public long getRuleId() { + return ruleId; + } + + public void setRuleId(long ruleId) { + this.ruleId = ruleId; + } + + public String getPublicIp() { + return publicIp; + } + + public void setPublicIp(String publicIp) { + this.publicIp = publicIp; + } + + public String getVmIp() { + return vmIp; + } + + public void setVmIp(String vmIp) { + this.vmIp = vmIp; + } + + public String getPublicPort() { + return publicPort; + } + + public void setPublicPort(String publicPort) { + this.publicPort = publicPort; + } + + public String getPrivatePort() { + return privatePort; + } + + public void setPrivatePort(String privatePort) { + this.privatePort = privatePort; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public void setAlgorithm(String algorithm) { + this.algorithm = algorithm; + } + + public String getAlgorithm() { + return algorithm; + } + + public List getMemberList() { + return memberList; + } + + public void setMemberList(List memberList) { + this.memberList = memberList; + } + + public NsxRuleAction getAclAction() { + return aclAction; + } + + public void setAclAction(NsxRuleAction aclAction) { + this.aclAction = aclAction; + } + + public Network.Service getService() { + return service; + } + + public void setService(Network.Service service) { + this.service = service; + } + + public Integer getIcmpCode() { + return icmpCode; + } + + public void setIcmpCode(Integer icmpCode) { + this.icmpCode = icmpCode; + } + + public Integer getIcmpType() { + return icmpType; + } + + public void setIcmpType(Integer icmpType) { + this.icmpType = icmpType; + } + + public List getSourceCidrList() { + return sourceCidrList; + } + + public void setSourceCidrList(List sourceCidrList) { + this.sourceCidrList = sourceCidrList; + } + + public List getDestinationCidrList() { + return destinationCidrList; + } + + public void setDestinationCidrList(List destinationCidrList) { + this.destinationCidrList = destinationCidrList; + } + + public String getTrafficType() { + return trafficType; + } + + public void setTrafficType(String trafficType) { + this.trafficType = trafficType; + } + + public static final class Builder { + private long domainId; + private long accountId; + private long zoneId; + private Long networkResourceId; + private String networkResourceName; + private boolean isVpcResource; + private long vmId; + + private long ruleId; + private String publicIp; + private String vmIp; + private String publicPort; + private String privatePort; + private String protocol; + private String algorithm; + private List memberList; + private NsxRuleAction aclAction; + private List sourceCidrList; + private List destinationidrList; + private String trafficType; + private Integer icmpType; + private Integer icmpCode; + private Network.Service service; + + public Builder() { + // Default constructor + } + + public Builder setDomainId(long domainId) { + this.domainId = domainId; + return this; + } + + public Builder setAccountId(long accountId) { + this.accountId = accountId; + return this; + } + + public Builder setZoneId(long zoneId) { + this.zoneId = zoneId; + return this; + } + + public Builder setNetworkResourceId(Long networkResourceId) { + this.networkResourceId = networkResourceId; + return this; + } + + public Builder setNetworkResourceName(String networkResourceName) { + this.networkResourceName = networkResourceName; + return this; + } + + public Builder setVpcResource(boolean isVpcResource) { + this.isVpcResource = isVpcResource; + return this; + } + + + public Builder setVmId(long vmId) { + this.vmId = vmId; + return this; + } + + public Builder setRuleId(long ruleId) { + this.ruleId = ruleId; + return this; + } + + public Builder setPublicIp(String publicIp) { + this.publicIp = publicIp; + return this; + } + + public Builder setVmIp(String vmIp) { + this.vmIp = vmIp; + return this; + } + + public Builder setPublicPort(String publicPort) { + this.publicPort = publicPort; + return this; + } + + public Builder setPrivatePort(String privatePort) { + this.privatePort = privatePort; + return this; + } + + public Builder setProtocol(String protocol) { + this.protocol = protocol; + return this; + } + + public Builder setAlgorithm(String algorithm) { + this.algorithm = algorithm; + return this; + } + + public Builder setMemberList(List memberList) { + this.memberList = memberList; + return this; + } + + + public Builder setAclAction(NsxRuleAction aclAction) { + this.aclAction = aclAction; + return this; + } + + public Builder setTrafficType(String trafficType) { + this.trafficType = trafficType; + return this; + } + + public Builder setIcmpType(Integer icmpType) { + this.icmpType = icmpType; + return this; + } + + public Builder setIcmpCode(Integer icmpCode) { + this.icmpCode = icmpCode; + return this; + } + + public Builder setSourceCidrList(List sourceCidrList) { + this.sourceCidrList = sourceCidrList; + return this; + } + + public Builder setDestinationCidrList(List destinationCidrList) { + this.destinationidrList = destinationCidrList; + return this; + } + + public Builder setService(Network.Service service) { + this.service = service; + return this; + } + + public NsxNetworkRule build() { + NsxNetworkRule rule = new NsxNetworkRule(); + rule.setDomainId(this.domainId); + rule.setAccountId(this.accountId); + rule.setZoneId(this.zoneId); + rule.setNetworkResourceId(this.networkResourceId); + rule.setNetworkResourceName(this.networkResourceName); + rule.setVpcResource(this.isVpcResource); + rule.setVmId(this.vmId); + rule.setVmIp(this.vmIp); + rule.setPublicIp(this.publicIp); + rule.setPublicPort(this.publicPort); + rule.setPrivatePort(this.privatePort); + rule.setProtocol(this.protocol); + rule.setRuleId(this.ruleId); + rule.setAlgorithm(this.algorithm); + rule.setMemberList(this.memberList); + rule.setAclAction(this.aclAction); + rule.setIcmpType(this.icmpType); + rule.setIcmpCode(this.icmpCode); + rule.setSourceCidrList(this.sourceCidrList); + rule.setDestinationCidrList(this.destinationidrList); + rule.setTrafficType(this.trafficType); + rule.setService(service); + return rule; + } + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxOpObject.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxOpObject.java new file mode 100644 index 000000000000..bb411249b886 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxOpObject.java @@ -0,0 +1,129 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.resource; + +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.vpc.VpcVO; + +import java.util.Objects; + +public class NsxOpObject { + VpcVO vpcVO; + NetworkVO networkVO; + long accountId; + long domainId; + long zoneId; + + public VpcVO getVpcVO() { + return vpcVO; + } + + public void setVpcVO(VpcVO vpcVO) { + this.vpcVO = vpcVO; + } + + public NetworkVO getNetworkVO() { + return networkVO; + } + + public void setNetworkVO(NetworkVO networkVO) { + this.networkVO = networkVO; + } + + public long getAccountId() { + return accountId; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public long getDomainId() { + return domainId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + public long getZoneId() { + return zoneId; + } + + public void setZoneId(long zoneId) { + this.zoneId = zoneId; + } + + public String getNetworkResourceName() { + return Objects.nonNull(vpcVO) ? vpcVO.getName() : networkVO.getName(); + } + + public boolean isVpcResource() { + return Objects.nonNull(vpcVO); + } + + public long getNetworkResourceId() { + return Objects.nonNull(vpcVO) ? vpcVO.getId() : networkVO.getId(); + } + + public static final class Builder { + VpcVO vpcVO; + NetworkVO networkVO; + long accountId; + long domainId; + long zoneId; + + public Builder() { + // Default constructor + } + + public Builder vpcVO(VpcVO vpcVO) { + this.vpcVO = vpcVO; + return this; + } + + public Builder networkVO(NetworkVO networkVO) { + this.networkVO = networkVO; + return this; + } + + public Builder domainId(long domainId) { + this.domainId = domainId; + return this; + } + + public Builder accountId(long accountId) { + this.accountId = accountId; + return this; + } + + public Builder zoneId(long zoneId) { + this.zoneId = zoneId; + return this; + } + + public NsxOpObject build() { + NsxOpObject object = new NsxOpObject(); + object.setVpcVO(this.vpcVO); + object.setNetworkVO(this.networkVO); + object.setDomainId(this.domainId); + object.setAccountId(this.accountId); + object.setZoneId(this.zoneId); + return object; + } + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxResource.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxResource.java new file mode 100644 index 000000000000..76815b0deebe --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/resource/NsxResource.java @@ -0,0 +1,500 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.resource; + +import com.cloud.agent.IAgentControl; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.CheckHealthAnswer; +import com.cloud.agent.api.CheckHealthCommand; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.PingCommand; +import com.cloud.agent.api.ReadyAnswer; +import com.cloud.agent.api.ReadyCommand; +import com.cloud.agent.api.StartupCommand; +import com.cloud.host.Host; +import com.cloud.network.Network; +import com.cloud.resource.ServerResource; +import com.cloud.utils.exception.CloudRuntimeException; + +import com.vmware.nsx.model.TransportZone; +import com.vmware.nsx.model.TransportZoneListResult; +import com.vmware.nsx_policy.model.Segment; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.StartupNsxCommand; +import org.apache.cloudstack.agent.api.CreateNsxDhcpRelayConfigCommand; +import org.apache.cloudstack.agent.api.CreateNsxDistributedFirewallRulesCommand; +import org.apache.cloudstack.agent.api.CreateNsxLoadBalancerRuleCommand; +import org.apache.cloudstack.agent.api.CreateNsxPortForwardRuleCommand; +import org.apache.cloudstack.agent.api.CreateNsxSegmentCommand; +import org.apache.cloudstack.agent.api.CreateNsxStaticNatCommand; +import org.apache.cloudstack.agent.api.CreateNsxTier1GatewayCommand; +import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxDistributedFirewallRulesCommand; +import org.apache.cloudstack.agent.api.DeleteNsxLoadBalancerRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxSegmentCommand; +import org.apache.cloudstack.agent.api.DeleteNsxNatRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxTier1GatewayCommand; +import org.apache.cloudstack.service.NsxApiClient; +import org.apache.cloudstack.utils.NsxControllerUtils; +import org.apache.commons.collections.CollectionUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.naming.ConfigurationException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +public class NsxResource implements ServerResource { + protected Logger logger = LogManager.getLogger(getClass()); + private static final String DHCP_RELAY_CONFIGS_PATH_PREFIX = "/infra/dhcp-relay-configs"; + + private String name; + protected String hostname; + protected String username; + protected String password; + protected String guid; + protected String port; + protected String tier0Gateway; + protected String edgeCluster; + protected String transportZone; + protected String zoneId; + + protected NsxApiClient nsxApiClient; + + @Override + public Host.Type getType() { + return Host.Type.Routing; + } + @Override + public StartupCommand[] initialize() { + StartupNsxCommand sc = new StartupNsxCommand(); + sc.setGuid(guid); + sc.setName(name); + sc.setDataCenter(zoneId); + sc.setPod(""); + sc.setPrivateIpAddress(""); + sc.setStorageIpAddress(""); + sc.setVersion(""); + return new StartupCommand[] {sc}; + } + + @Override + public PingCommand getCurrentStatus(long id) { + return null; + } + + @Override + public Answer executeRequest(Command cmd) { + if (cmd instanceof ReadyCommand) { + return executeRequest((ReadyCommand) cmd); + } else if (cmd instanceof CheckHealthCommand) { + return executeRequest((CheckHealthCommand) cmd); + } else if (cmd instanceof DeleteNsxTier1GatewayCommand) { + return executeRequest((DeleteNsxTier1GatewayCommand) cmd); + } else if (cmd instanceof DeleteNsxSegmentCommand) { + return executeRequest((DeleteNsxSegmentCommand) cmd); + } else if (cmd instanceof CreateNsxSegmentCommand) { + return executeRequest((CreateNsxSegmentCommand) cmd); + } else if (cmd instanceof CreateNsxTier1GatewayCommand) { + return executeRequest((CreateNsxTier1GatewayCommand) cmd); + } else if (cmd instanceof CreateNsxDhcpRelayConfigCommand) { + return executeRequest((CreateNsxDhcpRelayConfigCommand) cmd); + } else if (cmd instanceof CreateOrUpdateNsxTier1NatRuleCommand) { + return executeRequest((CreateOrUpdateNsxTier1NatRuleCommand) cmd); + } else if (cmd instanceof CreateNsxStaticNatCommand) { + return executeRequest((CreateNsxStaticNatCommand) cmd); + } else if (cmd instanceof DeleteNsxNatRuleCommand) { + return executeRequest((DeleteNsxNatRuleCommand) cmd); + } else if (cmd instanceof CreateNsxPortForwardRuleCommand) { + return executeRequest((CreateNsxPortForwardRuleCommand) cmd); + } else if (cmd instanceof CreateNsxLoadBalancerRuleCommand) { + return executeRequest((CreateNsxLoadBalancerRuleCommand) cmd); + } else if (cmd instanceof DeleteNsxLoadBalancerRuleCommand) { + return executeRequest((DeleteNsxLoadBalancerRuleCommand) cmd); + } else if (cmd instanceof DeleteNsxDistributedFirewallRulesCommand) { + return executeRequest((DeleteNsxDistributedFirewallRulesCommand) cmd); + } else if (cmd instanceof CreateNsxDistributedFirewallRulesCommand) { + return executeRequest((CreateNsxDistributedFirewallRulesCommand) cmd); + } else { + return Answer.createUnsupportedCommandAnswer(cmd); + } + } + + @Override + public void disconnected() { + // Do nothing + } + + @Override + public IAgentControl getAgentControl() { + return null; + } + + @Override + public void setAgentControl(IAgentControl agentControl) { + // Do nothing + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public void setConfigParams(Map params) { + // Do nothing + } + + @Override + public Map getConfigParams() { + return new HashMap<>(); + } + + @Override + public int getRunLevel() { + return 0; + } + + @Override + public void setRunLevel(int level) { + // Do nothing + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + hostname = (String) params.get("hostname"); + if (hostname == null) { + throw new ConfigurationException("Missing NSX hostname from params: " + params); + } + + port = (String) params.get("port"); + if (port == null) { + throw new ConfigurationException("Missing NSX port from params: " + params); + } + + username = (String) params.get("username"); + if (username == null) { + throw new ConfigurationException("Missing NSX username from params: " + params); + } + + password = (String) params.get("password"); + if (password == null) { + throw new ConfigurationException("Missing NSX password from params: " + params); + } + + this.name = (String) params.get("name"); + if (this.name == null) { + throw new ConfigurationException("Unable to find name"); + } + + guid = (String) params.get("guid"); + if (guid == null) { + throw new ConfigurationException("Unable to find the guid"); + } + + zoneId = (String) params.get("zoneId"); + if (zoneId == null) { + throw new ConfigurationException("Unable to find zone"); + } + + tier0Gateway = (String) params.get("tier0Gateway"); + if (tier0Gateway == null) { + throw new ConfigurationException("Missing NSX tier0 gateway"); + } + + edgeCluster = (String) params.get("edgeCluster"); + if (edgeCluster == null) { + throw new ConfigurationException("Missing NSX edgeCluster"); + } + + transportZone = (String) params.get("transportZone"); + if (transportZone == null) { + throw new ConfigurationException("Missing NSX transportZone"); + } + + nsxApiClient = new NsxApiClient(hostname, port, username, password.toCharArray()); + return true; + } + + private Answer executeRequest(CreateOrUpdateNsxTier1NatRuleCommand cmd) { + String tier1GatewayName = cmd.getTier1GatewayName(); + String action = cmd.getAction(); + String translatedIpAddress = cmd.getTranslatedIpAddress(); + String natRuleId = cmd.getNatRuleId(); + String natId = "USER"; + try { + nsxApiClient.createTier1NatRule(tier1GatewayName, natId, natRuleId, action, translatedIpAddress); + } catch (CloudRuntimeException e) { + String msg = String.format("Error creating the NAT rule with ID %s on Tier1 Gateway %s: %s", natRuleId, tier1GatewayName, e.getMessage()); + logger.error(msg, e); + return new NsxAnswer(cmd, e); + } + return new NsxAnswer(cmd, true, ""); + } + + private Answer executeRequest(CreateNsxDhcpRelayConfigCommand cmd) { + long datacenterId = cmd.getZoneId(); + long domainId = cmd.getDomainId(); + long accountId = cmd.getAccountId(); + Long vpcId = cmd.getVpcId(); + long networkId = cmd.getNetworkId(); + String vpcName = cmd.getVpcName(); + String networkName = cmd.getNetworkName(); + List addresses = cmd.getAddresses(); + + String dhcpRelayConfigName = NsxControllerUtils.getNsxDhcpRelayConfigId(datacenterId, domainId, accountId, vpcId, networkId); + + String msg = String.format("Creating DHCP relay config with name %s on network %s of VPC %s", + dhcpRelayConfigName, networkName, vpcName); + logger.debug(msg); + + try { + nsxApiClient.createDhcpRelayConfig(dhcpRelayConfigName, addresses); + } catch (CloudRuntimeException e) { + msg = String.format("Error creating the DHCP relay config with name %s: %s", dhcpRelayConfigName, e.getMessage()); + logger.error(msg, e); + return new NsxAnswer(cmd, e); + } + + String segmentName = NsxControllerUtils.getNsxSegmentId(domainId, accountId, datacenterId, vpcId, networkId); + String dhcpConfigPath = String.format("%s/%s", DHCP_RELAY_CONFIGS_PATH_PREFIX, dhcpRelayConfigName); + try { + Segment segment = nsxApiClient.getSegmentById(segmentName); + segment.setDhcpConfigPath(dhcpConfigPath); + nsxApiClient.updateSegment(segmentName, segment); + } catch (CloudRuntimeException e) { + msg = String.format("Error adding the DHCP relay config with name %s to the segment %s: %s", dhcpRelayConfigName, segmentName, e.getMessage()); + logger.error(msg); + return new NsxAnswer(cmd, e); + } + + return new NsxAnswer(cmd, true, ""); + } + + private Answer executeRequest(ReadyCommand cmd) { + return new ReadyAnswer(cmd); + } + + private Answer executeRequest(CheckHealthCommand cmd) { + return new CheckHealthAnswer(cmd, nsxApiClient.isNsxControllerActive()); + } + + private Answer executeRequest(CreateNsxTier1GatewayCommand cmd) { + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), cmd.getNetworkResourceId(), cmd.isResourceVpc()); + boolean sourceNatEnabled = cmd.isSourceNatEnabled(); + try { + nsxApiClient.createTier1Gateway(tier1GatewayName, tier0Gateway, edgeCluster, sourceNatEnabled); + return new NsxAnswer(cmd, true, ""); + } catch (CloudRuntimeException e) { + String msg = String.format("Cannot create tier 1 gateway %s (%s: %s): %s", tier1GatewayName, + (cmd.isResourceVpc() ? "VPC" : "NETWORK"), cmd.getNetworkResourceName(), e.getMessage()); + logger.error(msg); + return new NsxAnswer(cmd, e); + } + } + + private Answer executeRequest(DeleteNsxTier1GatewayCommand cmd) { + String tier1Id = NsxControllerUtils.getTier1GatewayName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), cmd.getNetworkResourceId(), cmd.isResourceVpc()); + String lbName = NsxControllerUtils.getLoadBalancerName(tier1Id); + try { + nsxApiClient.deleteLoadBalancer(lbName); + nsxApiClient.deleteTier1Gateway(tier1Id); + } catch (Exception e) { + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + private Answer executeRequest(CreateNsxSegmentCommand cmd) { + try { + String siteId = nsxApiClient.getDefaultSiteId(); + String enforcementPointPath = nsxApiClient.getDefaultEnforcementPointPath(siteId); + TransportZoneListResult transportZoneListResult = nsxApiClient.getTransportZones(); + if (CollectionUtils.isEmpty(transportZoneListResult.getResults())) { + String errorMsg = String.format("Failed to create network: %s as no transport zones were found in the linked NSX infrastructure", cmd.getNetworkName()); + logger.error(errorMsg); + return new NsxAnswer(cmd, new CloudRuntimeException(errorMsg)); + } + List transportZones = transportZoneListResult.getResults().stream().filter(tz -> tz.getDisplayName().equals(transportZone)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(transportZones)) { + String errorMsg = String.format("Failed to create network: %s as no transport zone of name %s was found in the linked NSX infrastructure", cmd.getNetworkName(), transportZone); + logger.error(errorMsg); + return new NsxAnswer(cmd, new CloudRuntimeException(errorMsg)); + } + + String segmentName = NsxControllerUtils.getNsxSegmentId(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), cmd.getVpcId(), cmd.getNetworkId()); + String gatewayAddress = cmd.getNetworkGateway() + "/" + cmd.getNetworkCidr().split("/")[1]; + + Long networkResourceId = Objects.isNull(cmd.getVpcId()) ? cmd.getNetworkId() : cmd.getVpcId(); + boolean isResourceVpc = !Objects.isNull(cmd.getVpcId()); + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(cmd.getDomainId(), cmd.getAccountId(), + cmd.getZoneId(), networkResourceId, isResourceVpc); + nsxApiClient.createSegment(segmentName, tier1GatewayName, gatewayAddress, enforcementPointPath, transportZones); + nsxApiClient.createGroupForSegment(segmentName); + } catch (Exception e) { + logger.error(String.format("Failed to create network: %s", cmd.getNetworkName())); + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + private NsxAnswer executeRequest(DeleteNsxSegmentCommand cmd) { + String segmentName = NsxControllerUtils.getNsxSegmentId(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getVpcId(), cmd.getNetworkId()); + try { + nsxApiClient.deleteSegment(cmd.getZoneId(), cmd.getDomainId(), cmd.getAccountId(), cmd.getVpcId(), cmd.getNetworkId(), segmentName); + } catch (Exception e) { + logger.error(String.format("Failed to delete NSX segment %s: %s", segmentName, e.getMessage())); + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + private NsxAnswer executeRequest(CreateNsxStaticNatCommand cmd) { + String staticNatRuleName = NsxControllerUtils.getStaticNatRuleName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getNetworkResourceId(), cmd.isResourceVpc()); + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getNetworkResourceId(), cmd.isResourceVpc()); + try { + nsxApiClient.createStaticNatRule(cmd.getNetworkResourceName(), tier1GatewayName, staticNatRuleName, cmd.getPublicIp(), cmd.getVmIp()); + } catch (Exception e) { + logger.error(String.format("Failed to add NSX static NAT rule %s for network: %s", staticNatRuleName, cmd.getNetworkResourceName())); + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + private NsxAnswer executeRequest(CreateNsxPortForwardRuleCommand cmd) { + String ruleName = NsxControllerUtils.getPortForwardRuleName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getNetworkResourceId(), cmd.getRuleId(), cmd.isResourceVpc()); + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getNetworkResourceId(), cmd.isResourceVpc()); + try { + String privatePort = cmd.getPrivatePort(); + logger.debug("Checking if the rule {} exists on Tier 1 Gateway: {}", ruleName, tier1GatewayName); + if (nsxApiClient.doesPfRuleExist(ruleName, tier1GatewayName)) { + String msg = String.format("Port forward rule for port: %s (%s) exits on NSX, not adding it again", ruleName, privatePort); + logger.debug(msg); + NsxAnswer answer = new NsxAnswer(cmd, true, msg); + answer.setObjectExists(true); + return answer; + } + String service = privatePort.contains("-") ? nsxApiClient.getServicePath(ruleName, privatePort, cmd.getProtocol(), null, null) : + nsxApiClient.getNsxInfraServices(ruleName, privatePort, cmd.getProtocol(), null, null); + nsxApiClient.createPortForwardingRule(ruleName, tier1GatewayName, cmd.getNetworkResourceName(), cmd.getPublicIp(), + cmd.getVmIp(), cmd.getPublicPort(), service); + } catch (Exception e) { + String msg = String.format("Failed to add NSX port forward rule %s for network: %s", ruleName, cmd.getNetworkResourceName()); + logger.error(msg, e); + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + private NsxAnswer executeRequest(DeleteNsxNatRuleCommand cmd) { + String ruleName = null; + if (cmd.getService() == Network.Service.StaticNat) { + ruleName = NsxControllerUtils.getStaticNatRuleName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getNetworkResourceId(), cmd.isResourceVpc()); + } else if (cmd.getService() == Network.Service.PortForwarding) { + ruleName = NsxControllerUtils.getPortForwardRuleName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getNetworkResourceId(), cmd.getRuleId(), cmd.isResourceVpc()); + } + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getNetworkResourceId(), cmd.isResourceVpc()); + try { + nsxApiClient.deleteNatRule(cmd.getService(), cmd.getPrivatePort(), cmd.getProtocol(), + cmd.getNetworkResourceName(), tier1GatewayName, ruleName); + } catch (Exception e) { + String msg = String.format("Failed to delete NSX rule %s for network %s: due to %s", ruleName, cmd.getNetworkResourceName(), e.getMessage()); + logger.error(msg, e); + return new NsxAnswer(cmd, new CloudRuntimeException(msg)); + } + return new NsxAnswer(cmd, true, null); + } + + private NsxAnswer executeRequest(CreateNsxLoadBalancerRuleCommand cmd) { + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(cmd.getDomainId(), cmd.getAccountId(), cmd.getZoneId(), + cmd.getNetworkResourceId(), cmd.isResourceVpc()); + String ruleName = NsxControllerUtils.getLoadBalancerRuleName(tier1GatewayName, cmd.getLbId()); + try { + nsxApiClient.createAndAddNsxLbVirtualServer(tier1GatewayName, cmd.getLbId(), cmd.getPublicIp(), cmd.getPublicPort(), + cmd.getMemberList(), cmd.getAlgorithm(), cmd.getProtocol(), cmd.getPrivatePort()); + } catch (Exception e) { + logger.error(String.format("Failed to add NSX load balancer rule %s for network: %s", ruleName, cmd.getNetworkResourceName())); + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + private NsxAnswer executeRequest(DeleteNsxLoadBalancerRuleCommand cmd) { + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(cmd.getDomainId(), cmd.getAccountId(), + cmd.getZoneId(), cmd.getNetworkResourceId(), cmd.isResourceVpc()); + String ruleName = NsxControllerUtils.getLoadBalancerRuleName(tier1GatewayName, cmd.getLbId()); + try { + nsxApiClient.deleteNsxLbResources(tier1GatewayName, cmd.getLbId()); + } catch (Exception e) { + logger.error(String.format("Failed to add NSX load balancer rule %s for network: %s", ruleName, cmd.getNetworkResourceName())); + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + private NsxAnswer executeRequest(CreateNsxDistributedFirewallRulesCommand cmd) { + String segmentName = NsxControllerUtils.getNsxSegmentId(cmd.getDomainId(), cmd.getAccountId(), + cmd.getZoneId(), cmd.getVpcId(), cmd.getNetworkId()); + List rules = cmd.getRules(); + try { + nsxApiClient.createSegmentDistributedFirewall(segmentName, rules); + } catch (Exception e) { + logger.error(String.format("Failed to create NSX distributed firewall %s: %s", segmentName, e.getMessage()), e); + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + private NsxAnswer executeRequest(DeleteNsxDistributedFirewallRulesCommand cmd) { + String segmentName = NsxControllerUtils.getNsxSegmentId(cmd.getDomainId(), cmd.getAccountId(), + cmd.getZoneId(), cmd.getVpcId(), cmd.getNetworkId()); + List rules = cmd.getRules(); + try { + nsxApiClient.deleteDistributedFirewallRules(segmentName, rules); + } catch (Exception e) { + logger.error(String.format("Failed to delete NSX distributed firewall %s: %s", segmentName, e.getMessage()), e); + return new NsxAnswer(cmd, new CloudRuntimeException(e.getMessage())); + } + return new NsxAnswer(cmd, true, null); + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxApiClient.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxApiClient.java new file mode 100644 index 000000000000..1ba1cc0fcc3b --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxApiClient.java @@ -0,0 +1,1113 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.network.Network; +import com.cloud.network.nsx.NsxService; +import com.cloud.utils.exception.CloudRuntimeException; +import com.vmware.nsx.cluster.Status; +import com.vmware.nsx.model.ClusterStatus; +import com.vmware.nsx.model.ControllerClusterStatus; +import com.vmware.nsx.model.TransportZone; +import com.vmware.nsx.model.TransportZoneListResult; +import com.vmware.nsx_policy.infra.DhcpRelayConfigs; +import com.vmware.nsx_policy.infra.LbAppProfiles; +import com.vmware.nsx_policy.infra.LbMonitorProfiles; +import com.vmware.nsx_policy.infra.LbPools; +import com.vmware.nsx_policy.infra.LbServices; +import com.vmware.nsx_policy.infra.LbVirtualServers; +import com.vmware.nsx_policy.infra.Segments; +import com.vmware.nsx_policy.infra.Services; +import com.vmware.nsx_policy.infra.Sites; +import com.vmware.nsx_policy.infra.Tier1s; +import com.vmware.nsx_policy.infra.domains.Groups; +import com.vmware.nsx_policy.infra.domains.SecurityPolicies; +import com.vmware.nsx_policy.infra.domains.groups.members.SegmentPorts; +import com.vmware.nsx_policy.infra.domains.security_policies.Rules; +import com.vmware.nsx_policy.infra.sites.EnforcementPoints; +import com.vmware.nsx_policy.infra.tier_0s.LocaleServices; +import com.vmware.nsx_policy.infra.tier_1s.nat.NatRules; +import com.vmware.nsx_policy.model.ApiError; +import com.vmware.nsx_policy.model.DhcpRelayConfig; +import com.vmware.nsx_policy.model.EnforcementPointListResult; +import com.vmware.nsx_policy.model.Group; +import com.vmware.nsx_policy.model.GroupListResult; +import com.vmware.nsx_policy.model.ICMPTypeServiceEntry; +import com.vmware.nsx_policy.model.L4PortSetServiceEntry; +import com.vmware.nsx_policy.model.LBAppProfileListResult; +import com.vmware.nsx_policy.model.LBIcmpMonitorProfile; +import com.vmware.nsx_policy.model.LBMonitorProfileListResult; +import com.vmware.nsx_policy.model.LBPool; +import com.vmware.nsx_policy.model.LBPoolListResult; +import com.vmware.nsx_policy.model.LBPoolMember; +import com.vmware.nsx_policy.model.LBService; +import com.vmware.nsx_policy.model.LBTcpMonitorProfile; +import com.vmware.nsx_policy.model.LBVirtualServer; +import com.vmware.nsx_policy.model.LBVirtualServerListResult; +import com.vmware.nsx_policy.model.LocaleServicesListResult; +import com.vmware.nsx_policy.model.PathExpression; +import com.vmware.nsx_policy.model.PolicyGroupMembersListResult; +import com.vmware.nsx_policy.model.PolicyNatRule; +import com.vmware.nsx_policy.model.PolicyNatRuleListResult; +import com.vmware.nsx_policy.model.Rule; +import com.vmware.nsx_policy.model.SecurityPolicy; +import com.vmware.nsx_policy.model.Segment; +import com.vmware.nsx_policy.model.SegmentSubnet; +import com.vmware.nsx_policy.model.ServiceListResult; +import com.vmware.nsx_policy.model.SiteListResult; +import com.vmware.nsx_policy.model.Tier1; +import com.vmware.vapi.bindings.Service; +import com.vmware.vapi.bindings.Structure; +import com.vmware.vapi.bindings.StubConfiguration; +import com.vmware.vapi.cis.authn.SecurityContextFactory; +import com.vmware.vapi.client.ApiClient; +import com.vmware.vapi.client.ApiClients; +import com.vmware.vapi.client.Configuration; +import com.vmware.vapi.core.ExecutionContext; +import com.vmware.vapi.internal.protocol.RestProtocol; +import com.vmware.vapi.internal.protocol.client.rest.authn.BasicAuthenticationAppender; +import com.vmware.vapi.protocol.HttpConfiguration; +import com.vmware.vapi.std.errors.Error; +import org.apache.cloudstack.resource.NsxLoadBalancerMember; +import org.apache.cloudstack.resource.NsxNetworkRule; +import org.apache.cloudstack.utils.NsxControllerUtils; +import org.apache.commons.collections.CollectionUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.commons.lang3.BooleanUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static org.apache.cloudstack.utils.NsxControllerUtils.getServerPoolMemberName; +import static org.apache.cloudstack.utils.NsxControllerUtils.getServerPoolName; +import static org.apache.cloudstack.utils.NsxControllerUtils.getServiceName; +import static org.apache.cloudstack.utils.NsxControllerUtils.getVirtualServerName; +import static org.apache.cloudstack.utils.NsxControllerUtils.getServiceEntryName; +import static org.apache.cloudstack.utils.NsxControllerUtils.getLoadBalancerName; +import static org.apache.cloudstack.utils.NsxControllerUtils.getLoadBalancerAlgorithm; +import static org.apache.cloudstack.utils.NsxControllerUtils.getActiveMonitorProfileName; +import static org.apache.cloudstack.utils.NsxControllerUtils.getTier1GatewayName; + +public class NsxApiClient { + + protected ApiClient apiClient; + protected Function, Service> nsxService; + + public static final int RESPONSE_TIMEOUT_SECONDS = 60; + protected Logger logger = LogManager.getLogger(getClass()); + + // Constants + private static final String CLUSTER_STATUS_STABLE = "STABLE"; + private static final String TIER_1_RESOURCE_TYPE = "Tier1"; + private static final String TIER_1_LOCALE_SERVICE_ID = "default"; + private static final String SEGMENT_RESOURCE_TYPE = "Segment"; + private static final String TIER_0_GATEWAY_PATH_PREFIX = "/infra/tier-0s/"; + private static final String TIER_1_GATEWAY_PATH_PREFIX = "/infra/tier-1s/"; + protected static final String SEGMENTS_PATH = "/infra/segments"; + protected static final String DEFAULT_DOMAIN = "default"; + protected static final String GROUPS_PATH_PREFIX = "/infra/domains/default/groups"; + // TODO: Pass as global / zone-level setting? + protected static final String NSX_LB_PASSIVE_MONITOR = "/infra/lb-monitor-profiles/default-passive-lb-monitor"; + protected static final String TCP_MONITOR_PROFILE = "LBTcpMonitorProfile"; + protected static final String ICMP_MONITOR_PROFILE = "LBIcmpMonitorProfile"; + protected static final String NAT_ID = "USER"; + + private enum PoolAllocation { ROUTING, LB_SMALL, LB_MEDIUM, LB_LARGE, LB_XLARGE } + + private enum HAMode { ACTIVE_STANDBY, ACTIVE_ACTIVE } + + private enum FailoverMode { PREEMPTIVE, NON_PREEMPTIVE } + + private enum AdminState { UP, DOWN } + + private enum TransportType { OVERLAY, VLAN } + + private enum NatId { USER, INTERNAL, DEFAULT } + + private enum NatAction {SNAT, DNAT, REFLEXIVE} + + private enum FirewallMatch { + MATCH_INTERNAL_ADDRESS, + MATCH_EXTERNAL_ADDRESS, + BYPASS + } + + public enum LBAlgorithm { + ROUND_ROBIN, + LEAST_CONNECTION, + IP_HASH + } + + private enum LBSize { + SMALL, + MEDIUM, + LARGE, + XLARGE + } + + private enum FirewallActions { + ALLOW, + DROP, + REJECT, + JUMP_TO_APPLICATION + } + + public enum RouteAdvertisementType { TIER1_STATIC_ROUTES, TIER1_CONNECTED, TIER1_NAT, + TIER1_LB_VIP, TIER1_LB_SNAT, TIER1_DNS_FORWARDER_IP, TIER1_IPSEC_LOCAL_ENDPOINT + } + + protected NsxApiClient() { + } + + public NsxApiClient(String hostname, String port, String username, char[] password) { + String controllerUrl = String.format("https://%s:%s", hostname, port); + HttpConfiguration.SslConfiguration.Builder sslConfigBuilder = new HttpConfiguration.SslConfiguration.Builder(); + sslConfigBuilder + .disableCertificateValidation() + .disableHostnameVerification(); + HttpConfiguration.SslConfiguration sslConfig = sslConfigBuilder.getConfig(); + + HttpConfiguration httpConfig = new HttpConfiguration.Builder() + .setSoTimeout(RESPONSE_TIMEOUT_SECONDS * 1000) + .setSslConfiguration(sslConfig).getConfig(); + + StubConfiguration stubConfig = new StubConfiguration(); + ExecutionContext.SecurityContext securityContext = SecurityContextFactory + .createUserPassSecurityContext(username, password); + stubConfig.setSecurityContext(securityContext); + + Configuration.Builder configBuilder = new Configuration.Builder() + .register(Configuration.HTTP_CONFIG_CFG, httpConfig) + .register(Configuration.STUB_CONFIG_CFG, stubConfig) + .register(RestProtocol.REST_REQUEST_AUTHENTICATOR_CFG, new BasicAuthenticationAppender()); + Configuration config = configBuilder.build(); + apiClient = ApiClients.newRestClient(controllerUrl, config); + nsxService = apiClient::createStub; + } + + public boolean isNsxControllerActive() { + try { + Status statusService = (Status) nsxService.apply(Status.class); + ClusterStatus clusterStatus = statusService.get(); + if (clusterStatus == null) { + logger.error("Cannot get NSX Cluster Status"); + return false; + } + ControllerClusterStatus status = clusterStatus.getControlClusterStatus(); + if (status == null) { + logger.error("Cannot get NSX Controller Cluster Status"); + return false; + } + return CLUSTER_STATUS_STABLE.equalsIgnoreCase(status.getStatus()); + } catch (Error error) { + logger.error("Error checking NSX Controller Health: {}", error.getMessage()); + return false; + } + } + + public void createTier1NatRule(String tier1GatewayName, String natId, String natRuleId, + String action, String translatedIp) { + NatRules natRulesService = (NatRules) nsxService.apply(NatRules.class); + PolicyNatRule natPolicy = new PolicyNatRule.Builder() + .setAction(action) + .setTranslatedNetwork(translatedIp) + .build(); + natRulesService.patch(tier1GatewayName, natId, natRuleId, natPolicy); + } + + public void createDhcpRelayConfig(String dhcpRelayConfigName, List addresses) { + try { + DhcpRelayConfigs service = (DhcpRelayConfigs) nsxService.apply(DhcpRelayConfigs.class); + DhcpRelayConfig config = new DhcpRelayConfig.Builder() + .setServerAddresses(addresses) + .setId(dhcpRelayConfigName) + .setDisplayName(dhcpRelayConfigName) + .build(); + service.patch(dhcpRelayConfigName, config); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Error creating the DHCP relay config with name %s: %s", dhcpRelayConfigName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(ae.getErrorMessage()); + } + } + + public Segment getSegmentById(String segmentName) { + try { + Segments segmentService = (Segments) nsxService.apply(Segments.class); + return segmentService.get(segmentName); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Error obtaining the segment with name %s: %s", segmentName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(ae.getErrorMessage()); + } + } + + public void updateSegment(String segmentName, Segment segment) { + try { + Segments segmentService = (Segments) nsxService.apply(Segments.class); + segmentService.patch(segmentName, segment); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Error updating the segment with name %s: %s", segmentName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(ae.getErrorMessage()); + } + } + + private Tier1 getTier1Gateway(String tier1GatewayId) { + try { + Tier1s tier1service = (Tier1s) nsxService.apply(Tier1s.class); + return tier1service.get(tier1GatewayId); + } catch (Exception e) { + logger.debug(String.format("NSX Tier-1 gateway with name: %s not found", tier1GatewayId)); + } + return null; + } + + private List getTier0LocalServices(String tier0Gateway) { + try { + LocaleServices tier0LocaleServices = (LocaleServices) nsxService.apply(LocaleServices.class); + LocaleServicesListResult result = tier0LocaleServices.list(tier0Gateway, null, false, null, null, null, null); + return result.getResults(); + } catch (Exception e) { + throw new CloudRuntimeException(String.format("Failed to fetch locale services for tier gateway %s due to %s", tier0Gateway, e.getMessage())); + } + } + + /** + * To instantiate Tier-1 in Edge Cluster + */ + private void createTier1LocaleServices(String tier1Id, String edgeCluster, String tier0Gateway) { + try { + List localeServices = getTier0LocalServices(tier0Gateway); + com.vmware.nsx_policy.infra.tier_1s.LocaleServices tier1LocalService = (com.vmware.nsx_policy.infra.tier_1s.LocaleServices) nsxService.apply(com.vmware.nsx_policy.infra.tier_1s.LocaleServices.class); + com.vmware.nsx_policy.model.LocaleServices localeService = new com.vmware.nsx_policy.model.LocaleServices.Builder() + .setEdgeClusterPath(localeServices.get(0).getEdgeClusterPath()).build(); + tier1LocalService.patch(tier1Id, TIER_1_LOCALE_SERVICE_ID, localeService); + } catch (Error error) { + throw new CloudRuntimeException(String.format("Failed to instantiate tier-1 gateway %s in edge cluster %s", tier1Id, edgeCluster)); + } + } + + private List getRouterAdvertisementTypeList(boolean sourceNatEnabled) { + List types = new ArrayList<>(); + types.add(RouteAdvertisementType.TIER1_IPSEC_LOCAL_ENDPOINT.name()); + types.add(RouteAdvertisementType.TIER1_LB_VIP.name()); + types.add(RouteAdvertisementType.TIER1_NAT.name()); + if (!sourceNatEnabled) { + types.add(RouteAdvertisementType.TIER1_CONNECTED.name()); + } + return types; + } + + public void createTier1Gateway(String name, String tier0Gateway, String edgeCluster, boolean sourceNatEnabled) throws CloudRuntimeException { + String tier0GatewayPath = TIER_0_GATEWAY_PATH_PREFIX + tier0Gateway; + Tier1 tier1 = getTier1Gateway(name); + if (tier1 != null) { + logger.info(String.format("VPC network with name %s exists in NSX zone", name)); + return; + } + + List routeAdvertisementTypes = getRouterAdvertisementTypeList(sourceNatEnabled); + + Tier1s tier1service = (Tier1s) nsxService.apply(Tier1s.class); + tier1 = new Tier1.Builder() + .setTier0Path(tier0GatewayPath) + .setResourceType(TIER_1_RESOURCE_TYPE) + .setPoolAllocation(PoolAllocation.ROUTING.name()) + .setHaMode(HAMode.ACTIVE_STANDBY.name()) + .setFailoverMode(FailoverMode.PREEMPTIVE.name()) + .setRouteAdvertisementTypes(routeAdvertisementTypes) + .setId(name) + .setDisplayName(name) + .build(); + try { + tier1service.patch(name, tier1); + createTier1LocaleServices(name, edgeCluster, tier0Gateway); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Error creating tier 1 gateway %s: %s", name, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + public void deleteTier1Gateway(String tier1Id) { + com.vmware.nsx_policy.infra.tier_1s.LocaleServices localeService = (com.vmware.nsx_policy.infra.tier_1s.LocaleServices) + nsxService.apply(com.vmware.nsx_policy.infra.tier_1s.LocaleServices.class); + if (getTier1Gateway(tier1Id) == null) { + logger.warn(String.format("The Tier 1 Gateway %s does not exist, cannot be removed", tier1Id)); + return; + } + removeTier1GatewayNatRules(tier1Id); + localeService.delete(tier1Id, TIER_1_LOCALE_SERVICE_ID); + Tier1s tier1service = (Tier1s) nsxService.apply(Tier1s.class); + tier1service.delete(tier1Id); + } + + private void removeTier1GatewayNatRules(String tier1Id) { + NatRules natRulesService = (NatRules) nsxService.apply(NatRules.class); + PolicyNatRuleListResult result = natRulesService.list(tier1Id, NAT_ID, null, false, null, null, null, null); + List natRules = result.getResults(); + if (CollectionUtils.isEmpty(natRules)) { + logger.debug(String.format("Didn't find any NAT rule to remove on the Tier 1 Gateway %s", tier1Id)); + } else { + for (PolicyNatRule natRule : natRules) { + logger.debug(String.format("Removing NAT rule %s from Tier 1 Gateway %s", natRule.getId(), tier1Id)); + natRulesService.delete(tier1Id, NAT_ID, natRule.getId()); + } + } + + } + + public String getDefaultSiteId() { + SiteListResult sites = getSites(); + if (CollectionUtils.isEmpty(sites.getResults())) { + String errorMsg = "No sites are found in the linked NSX infrastructure"; + logger.error(errorMsg); + throw new CloudRuntimeException(errorMsg); + } + return sites.getResults().get(0).getId(); + } + + protected SiteListResult getSites() { + try { + Sites sites = (Sites) nsxService.apply(Sites.class); + return sites.list(null, false, null, null, null, null); + } catch (Exception e) { + throw new CloudRuntimeException(String.format("Failed to fetch sites list due to %s", e.getMessage())); + } + } + + public String getDefaultEnforcementPointPath(String siteId) { + EnforcementPointListResult epList = getEnforcementPoints(siteId); + if (CollectionUtils.isEmpty(epList.getResults())) { + String errorMsg = String.format("No enforcement points are found in the linked NSX infrastructure for site ID %s", siteId); + logger.error(errorMsg); + throw new CloudRuntimeException(errorMsg); + } + return epList.getResults().get(0).getPath(); + } + + protected EnforcementPointListResult getEnforcementPoints(String siteId) { + try { + EnforcementPoints enforcementPoints = (EnforcementPoints) nsxService.apply(EnforcementPoints.class); + return enforcementPoints.list(siteId, null, false, null, null, null, null); + } catch (Exception e) { + throw new CloudRuntimeException(String.format("Failed to fetch enforcement points due to %s", e.getMessage())); + } + } + + public TransportZoneListResult getTransportZones() { + try { + com.vmware.nsx.TransportZones transportZones = (com.vmware.nsx.TransportZones) nsxService.apply(com.vmware.nsx.TransportZones.class); + return transportZones.list(null, null, true, null, null, null, null, null, TransportType.OVERLAY.name(), null); + } catch (Exception e) { + throw new CloudRuntimeException(String.format("Failed to fetch transport zones due to %s", e.getMessage())); + } + } + + public void createSegment(String segmentName, String tier1GatewayName, String gatewayAddress, String enforcementPointPath, + List transportZones) { + try { + Segments segmentService = (Segments) nsxService.apply(Segments.class); + SegmentSubnet subnet = new SegmentSubnet.Builder() + .setGatewayAddress(gatewayAddress) + .build(); + Segment segment = new Segment.Builder() + .setResourceType(SEGMENT_RESOURCE_TYPE) + .setId(segmentName) + .setDisplayName(segmentName) + .setConnectivityPath(TIER_1_GATEWAY_PATH_PREFIX + tier1GatewayName) + .setAdminState(AdminState.UP.name()) + .setSubnets(List.of(subnet)) + .setTransportZonePath(enforcementPointPath + "/transport-zones/" + transportZones.get(0).getId()) + .build(); + segmentService.patch(segmentName, segment); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Error creating segment %s: %s", segmentName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + public void deleteSegment(long zoneId, long domainId, long accountId, Long vpcId, long networkId, String segmentName) { + try { + removeSegmentDistributedFirewallRules(segmentName); + if (Objects.isNull(vpcId)) { + String t1GatewayName = getTier1GatewayName(domainId, accountId, zoneId, networkId, false); + deleteLoadBalancer(getLoadBalancerName(t1GatewayName)); + } + removeSegment(segmentName, zoneId); + DhcpRelayConfigs dhcpRelayConfig = (DhcpRelayConfigs) nsxService.apply(DhcpRelayConfigs.class); + String dhcpRelayConfigId = NsxControllerUtils.getNsxDhcpRelayConfigId(zoneId, domainId, accountId, vpcId, networkId); + logger.debug(String.format("Removing the DHCP relay config with ID %s", dhcpRelayConfigId)); + dhcpRelayConfig.delete(dhcpRelayConfigId); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Error deleting segment %s: %s", segmentName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + + protected void removeSegment(String segmentName, long zoneId) { + logger.debug(String.format("Removing the segment with ID %s", segmentName)); + Segments segmentService = (Segments) nsxService.apply(Segments.class); + String errMsg = String.format("The segment with ID %s is not found, skipping removal", segmentName); + try { + Segment segment = segmentService.get(segmentName); + if (segment == null) { + logger.warn(errMsg); + return; + } + } catch (Exception e) { + logger.warn(errMsg); + return; + } + String siteId = getDefaultSiteId(); + String enforcementPointPath = getDefaultEnforcementPointPath(siteId); + SegmentPorts segmentPortsService = (SegmentPorts) nsxService.apply(SegmentPorts.class); + PolicyGroupMembersListResult segmentPortsList = getSegmentPortList(segmentPortsService, segmentName, enforcementPointPath); + Long portCount = segmentPortsList.getResultCount(); + if (portCount > 0L) { + portCount = retrySegmentDeletion(segmentPortsService, segmentName, enforcementPointPath, zoneId); + } + if (portCount == 0L) { + logger.debug(String.format("Removing the segment with ID %s", segmentName)); + removeGroupForSegment(segmentName); + segmentService.delete(segmentName); + } else { + String msg = String.format("Cannot remove the NSX segment %s because there are still %s port group(s) attached to it", segmentName, portCount); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + private PolicyGroupMembersListResult getSegmentPortList(SegmentPorts segmentPortsService, String segmentName, String enforcementPointPath) { + return segmentPortsService.list(DEFAULT_DOMAIN, segmentName, null, enforcementPointPath, + false, null, 50L, false, null); + } + + private Long retrySegmentDeletion(SegmentPorts segmentPortsService, String segmentName, String enforcementPointPath, long zoneId) { + int retries = NsxService.NSX_API_FAILURE_RETRIES.valueIn(zoneId); + int waitingSecs = NsxService.NSX_API_FAILURE_INTERVAL.valueIn(zoneId); + int count = 1; + Long portCount; + do { + try { + logger.info("Waiting for all port groups to be unlinked from the segment {} - " + + "Attempt: {}. Waiting for {} secs", segmentName, count++, waitingSecs); + Thread.sleep(waitingSecs * 1000L); + portCount = getSegmentPortList(segmentPortsService, segmentName, enforcementPointPath).getResultCount(); + retries--; + } catch (InterruptedException e) { + throw new CloudRuntimeException(String.format("Unable to delete segment %s due to: %s", segmentName, e.getLocalizedMessage())); + } + } while (retries > 0 && portCount > 0); + return portCount; + } + + public void createStaticNatRule(String vpcName, String tier1GatewayName, + String ruleName, String publicIp, String vmIp) { + try { + NatRules natService = (NatRules) nsxService.apply(NatRules.class); + PolicyNatRule rule = new PolicyNatRule.Builder() + .setId(ruleName) + .setDisplayName(ruleName) + .setAction(NatAction.DNAT.name()) + .setFirewallMatch(FirewallMatch.MATCH_INTERNAL_ADDRESS.name()) + .setDestinationNetwork(publicIp) + .setTranslatedNetwork(vmIp) + .setEnabled(true) + .build(); + + logger.debug(String.format("Creating NSX static NAT rule %s for tier-1 gateway %s (VPC: %s)", ruleName, tier1GatewayName, vpcName)); + natService.patch(tier1GatewayName, NatId.USER.name(), ruleName, rule); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Error creating NSX Static NAT rule %s for tier-1 gateway %s (VPC: %s), due to %s", + ruleName, tier1GatewayName, vpcName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + protected void deletePortForwardingNatRuleService(String ruleName, String privatePort, String protocol) { + String svcName = getServiceName(ruleName, privatePort, protocol, null, null); + try { + Services services = (Services) nsxService.apply(Services.class); + com.vmware.nsx_policy.model.Service servicePFRule = services.get(svcName); + if (servicePFRule != null && !servicePFRule.getMarkedForDelete() && !BooleanUtils.toBoolean(servicePFRule.getIsDefault())) { + services.delete(svcName); + } + } catch (Error error) { + String msg = String.format("Cannot find service %s associated to rule %s, skipping its deletion: %s", + svcName, ruleName, error.getMessage()); + logger.debug(msg); + } + } + + public void deleteNatRule(Network.Service service, String privatePort, String protocol, String networkName, String tier1GatewayName, String ruleName) { + try { + NatRules natService = (NatRules) nsxService.apply(NatRules.class); + logger.debug("Deleting NSX NAT rule {} for tier-1 gateway {} (network: {})", ruleName, tier1GatewayName, networkName); + PolicyNatRule natRule = natService.get(tier1GatewayName, NatId.USER.name(), ruleName); + if (natRule != null && !natRule.getMarkedForDelete()) { + logger.debug("Deleting rule {} from Tier 1 Gateway {}", ruleName, tier1GatewayName); + natService.delete(tier1GatewayName, NatId.USER.name(), ruleName); + } + } catch (Error error) { + String msg = String.format("Cannot find NAT rule with name %s: %s, skipping deletion", ruleName, error.getMessage()); + logger.debug(msg); + } + + if (service == Network.Service.PortForwarding) { + deletePortForwardingNatRuleService(ruleName, privatePort, protocol); + } + } + + public void createPortForwardingRule(String ruleName, String tier1GatewayName, String networkName, String publicIp, + String vmIp, String publicPort, String service) { + try { + NatRules natService = (NatRules) nsxService.apply(NatRules.class); + logger.debug(String.format("Creating NSX Port-Forwarding NAT %s for network %s", ruleName, networkName)); + PolicyNatRule rule = new PolicyNatRule.Builder() + .setId(ruleName) + .setDisplayName(ruleName) + .setAction(NatAction.DNAT.name()) + .setFirewallMatch(FirewallMatch.MATCH_INTERNAL_ADDRESS.name()) + .setDestinationNetwork(publicIp) + .setTranslatedNetwork(vmIp) + .setTranslatedPorts(String.valueOf(publicPort)) + .setService(service) + .setEnabled(true) + .build(); + natService.patch(tier1GatewayName, NatId.USER.name(), ruleName, rule); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to add NSX Port-forward rule %s for network: %s, due to %s", + ruleName, networkName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + public boolean doesPfRuleExist(String ruleName, String tier1GatewayName) { + try { + NatRules natService = (NatRules) nsxService.apply(NatRules.class); + PolicyNatRule rule = natService.get(tier1GatewayName, NAT_ID, ruleName); + logger.debug("Rule {} from Tier 1 GW {}: {}", ruleName, tier1GatewayName, + rule == null ? "null" : rule.getId() + " " + rule.getPath()); + return !Objects.isNull(rule); + } catch (Error error) { + String msg = String.format("Error checking if port forwarding rule %s exists on Tier 1 Gateway %s: %s", + ruleName, tier1GatewayName, error.getMessage()); + Throwable throwable = error.getCause(); + logger.error(msg, throwable); + return false; + } + } + + List getLbPoolMembers(List memberList, String tier1GatewayName) { + List members = new ArrayList<>(); + for (NsxLoadBalancerMember member : memberList) { + try { + String serverPoolMemberName = getServerPoolMemberName(tier1GatewayName, member.getVmId()); + LBPoolMember lbPoolMember = new LBPoolMember.Builder() + .setDisplayName(serverPoolMemberName) + .setIpAddress(member.getVmIp()) + .setPort(String.valueOf(member.getPort())) + .build(); + members.add(lbPoolMember); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to create NSX LB pool members, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + return members; + } + public void createNsxLbServerPool(List memberList, String tier1GatewayName, String lbServerPoolName, + String algorithm, String privatePort, String protocol) { + try { + String activeMonitorPath = getLbActiveMonitorPath(lbServerPoolName, privatePort, protocol); + List members = getLbPoolMembers(memberList, tier1GatewayName); + LbPools lbPools = (LbPools) nsxService.apply(LbPools.class); + LBPool lbPool = new LBPool.Builder() + .setId(lbServerPoolName) + .setDisplayName(lbServerPoolName) + .setAlgorithm(getLoadBalancerAlgorithm(algorithm)) + .setMembers(members) + .setPassiveMonitorPath(NSX_LB_PASSIVE_MONITOR) + .setActiveMonitorPaths(List.of(activeMonitorPath)) + .build(); + lbPools.patch(lbServerPoolName, lbPool); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to create NSX LB server pool, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + private String getLbActiveMonitorPath(String lbServerPoolName, String port, String protocol) { + LbMonitorProfiles lbActiveMonitor = (LbMonitorProfiles) nsxService.apply(LbMonitorProfiles.class); + String lbMonitorProfileId = getActiveMonitorProfileName(lbServerPoolName, port, protocol); + if ("TCP".equals(protocol.toUpperCase(Locale.ROOT))) { + LBTcpMonitorProfile lbTcpMonitorProfile = new LBTcpMonitorProfile.Builder(TCP_MONITOR_PROFILE) + .setDisplayName(lbMonitorProfileId) + .setMonitorPort(Long.parseLong(port)) + .build(); + lbActiveMonitor.patch(lbMonitorProfileId, lbTcpMonitorProfile); + } else if ("UDP".equals(protocol.toUpperCase(Locale.ROOT))) { + LBIcmpMonitorProfile icmpMonitorProfile = new LBIcmpMonitorProfile.Builder(ICMP_MONITOR_PROFILE) + .setDisplayName(lbMonitorProfileId) + .build(); + lbActiveMonitor.patch(lbMonitorProfileId, icmpMonitorProfile); + } + + LBMonitorProfileListResult listResult = listLBActiveMonitors(lbActiveMonitor); + Optional monitorProfile = listResult.getResults().stream().filter(profile -> profile._getDataValue().getField("id").toString().equals(lbMonitorProfileId)).findFirst(); + return monitorProfile.map(structure -> structure._getDataValue().getField("path").toString()).orElse(null); + } + + LBMonitorProfileListResult listLBActiveMonitors(LbMonitorProfiles lbActiveMonitor) { + return lbActiveMonitor.list(null, false, null, null, null, null); + } + + public void createNsxLoadBalancer(String tier1GatewayName) { + try { + String lbName = getLoadBalancerName(tier1GatewayName); + LbServices lbServices = (LbServices) nsxService.apply(LbServices.class); + LBService lbService = getLbService(lbName); + if (Objects.nonNull(lbService)) { + return; + } + lbService = new LBService.Builder() + .setId(lbName) + .setDisplayName(lbName) + .setEnabled(true) + .setSize(LBSize.SMALL.name()) + .setConnectivityPath(TIER_1_GATEWAY_PATH_PREFIX + tier1GatewayName) + .build(); + lbServices.patch(lbName, lbService); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to create NSX load balancer, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + public void createAndAddNsxLbVirtualServer(String tier1GatewayName, long lbId, String publicIp, String publicPort, + List memberList, String algorithm, String protocol, String privatePort) { + try { + String lbServerPoolName = getServerPoolName(tier1GatewayName, lbId); + createNsxLbServerPool(memberList, tier1GatewayName, lbServerPoolName, algorithm, privatePort, protocol); + createNsxLoadBalancer(tier1GatewayName); + + String lbVirtualServerName = getVirtualServerName(tier1GatewayName, lbId); + String lbServiceName = getLoadBalancerName(tier1GatewayName); + LbVirtualServers lbVirtualServers = (LbVirtualServers) nsxService.apply(LbVirtualServers.class); + if (Objects.nonNull(getLbVirtualServerService(lbVirtualServers, lbServiceName))) { + return; + } + LBVirtualServer lbVirtualServer = new LBVirtualServer.Builder() + .setId(lbVirtualServerName) + .setDisplayName(lbVirtualServerName) + .setApplicationProfilePath(getLbProfileForProtocol(protocol)) + .setIpAddress(publicIp) + .setLbServicePath(getLbPath(lbServiceName)) + .setPoolPath(getLbPoolPath(lbServerPoolName)) + .setPorts(List.of(publicPort)) + .build(); + lbVirtualServers.patch(lbVirtualServerName, lbVirtualServer); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to create and add NSX virtual server to the Load Balancer, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + private LBVirtualServer getLbVirtualServerService(LbVirtualServers lbVirtualServers, String lbVSName) { + try { + LBVirtualServer lbVirtualServer = lbVirtualServers.get(lbVSName); + if (Objects.nonNull(lbVirtualServer)) { + return lbVirtualServer; + } + } catch (Exception e) { + logger.debug(String.format("Found an LB virtual server named: %s on NSX", lbVSName)); + return null; + } + return null; + } + + public void deleteNsxLbResources(String tier1GatewayName, long lbId) { + try { + // Delete associated Virtual servers + LbVirtualServers lbVirtualServers = (LbVirtualServers) nsxService.apply(LbVirtualServers.class); + String lbVirtualServerName = getVirtualServerName(tier1GatewayName, lbId); + lbVirtualServers.delete(lbVirtualServerName, false); + + // Delete LB pool + LbPools lbPools = (LbPools) nsxService.apply(LbPools.class); + String lbServerPoolName = getServerPoolName(tier1GatewayName, lbId); + lbPools.delete(lbServerPoolName, false); + + // delete associated LB Active monitor profile + LbMonitorProfiles lbActiveMonitor = (LbMonitorProfiles) nsxService.apply(LbMonitorProfiles.class); + LBMonitorProfileListResult listResult = listLBActiveMonitors(lbActiveMonitor); + List profileIds = listResult.getResults().stream().filter(profile -> profile._getDataValue().getField("id").toString().contains(lbServerPoolName)) + .map(profile -> profile._getDataValue().getField("id").toString()).collect(Collectors.toList()); + for(String profileId : profileIds) { + lbActiveMonitor.delete(profileId, true); + } + // Delete load balancer + LBVirtualServerListResult lbVsListResult = lbVirtualServers.list(null, null, null, null, null, null); + LBPoolListResult lbPoolListResult = lbPools.list(null, null, null, null, null, null); + if (CollectionUtils.isEmpty(lbVsListResult.getResults()) && CollectionUtils.isEmpty(lbPoolListResult.getResults())) { + String lbName = getLoadBalancerName(tier1GatewayName); + deleteLoadBalancer(lbName); + } + + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to delete NSX Load Balancer resources, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + public void deleteLoadBalancer(String lbName) { + LbServices lbServices = (LbServices) nsxService.apply(LbServices.class); + lbServices.delete(lbName, true); + } + + private String getLbPoolPath(String lbPoolName) { + try { + LbPools lbPools = (LbPools) nsxService.apply(LbPools.class); + LBPool lbPool = lbPools.get(lbPoolName); + return Objects.nonNull(lbPool) ? lbPool.getPath() : null; + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to get NSX LB server pool, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + private LBService getLbService(String lbName) { + try { + LbServices lbServices = (LbServices) nsxService.apply(LbServices.class); + LBService lbService = lbServices.get(lbName); + if (Objects.nonNull(lbService)) { + return lbService; + } + } catch (Exception e) { + return null; + } + return null; + } + + private String getLbPath(String lbServiceName) { + try { + LbServices lbServices = (LbServices) nsxService.apply(LbServices.class); + LBService lbService = lbServices.get(lbServiceName); + return Objects.nonNull(lbService) ? lbService.getPath() : null; + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to get NSX LB server pool, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + private String getLbProfileForProtocol(String protocol) { + try { + LbAppProfiles lbAppProfiles = (LbAppProfiles) nsxService.apply(LbAppProfiles.class); + LBAppProfileListResult lbAppProfileListResults = lbAppProfiles.list(null, null, + null, null, null, null); + Optional appProfile = lbAppProfileListResults.getResults().stream().filter(profile -> profile._getDataValue().getField("path").toString().contains(protocol.toLowerCase(Locale.ROOT))).findFirst(); + return appProfile.map(structure -> structure._getDataValue().getField("path").toString()).orElse(null); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to list NSX LB App profiles, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + public String getNsxInfraServices(String ruleName, String port, String protocol, Integer icmpType, Integer icmpCode) { + try { + Services service = (Services) nsxService.apply(Services.class); + + // Find default service if present + ServiceListResult serviceList = service.list(null, true, false, null, null, null, null); + + List services = serviceList.getResults(); + List matchedDefaultSvc = services.parallelStream().filter(svc -> + (svc.getServiceEntries().get(0)._getDataValue().getField("resource_type").toString().equals("L4PortSetServiceEntry")) && + svc.getServiceEntries().get(0)._getDataValue().getField("destination_ports").toString().equals("["+port+"]") + && svc.getServiceEntries().get(0)._getDataValue().getField("l4_protocol").toString().equals(protocol)) + .map(svc -> svc.getServiceEntries().get(0)._getDataValue().getField("parent_path").toString()) + .collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(matchedDefaultSvc)) { + return matchedDefaultSvc.get(0); + } + + // Else, find if there's a service matching the rule name + String servicePath = getServiceById(ruleName); + if (Objects.nonNull(servicePath)) { + return servicePath; + } + + // Else, create a service entry + return getServicePath(ruleName, port, protocol, icmpType, icmpCode); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to list NSX infra service, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + + private com.vmware.nsx_policy.model.Service getInfraService(String ruleName, String port, String protocol, Integer icmpType, Integer icmpCode) { + Services service = (Services) nsxService.apply(Services.class); + String serviceName = getServiceName(ruleName, port, protocol, icmpType, icmpCode); + createNsxInfraService(service, serviceName, ruleName, port, protocol, icmpType, icmpCode); + return service.get(serviceName); + } + + public String getServicePath(String ruleName, String port, String protocol, Integer icmpType, Integer icmpCode) { + com.vmware.nsx_policy.model.Service svc = getInfraService(ruleName, port, protocol, icmpType, icmpCode); + return svc.getServiceEntries().get(0)._getDataValue().getField("parent_path").toString(); + } + + public void createNsxInfraService(Services service, String serviceName, String ruleName, String port, String protocol, + Integer icmpType, Integer icmpCode) { + try { + List serviceEntries = new ArrayList<>(); + protocol = "ICMP".equalsIgnoreCase(protocol) ? "ICMPv4" : protocol; + String serviceEntryName = getServiceEntryName(ruleName, port, protocol); + if (protocol.equals("ICMPv4")) { + serviceEntries.add(new ICMPTypeServiceEntry.Builder() + .setId(serviceEntryName) + .setDisplayName(serviceEntryName) +// .setIcmpCode(Long.valueOf(icmpCode)) + .setIcmpType(Long.valueOf(icmpType)) + .setProtocol(protocol) + .build() + ); + } else { + serviceEntries.add(new L4PortSetServiceEntry.Builder() + .setId(serviceEntryName) + .setDisplayName(serviceEntryName) + .setDestinationPorts(List.of(port)) + .setL4Protocol(protocol) + .build()); + } + com.vmware.nsx_policy.model.Service infraService = new com.vmware.nsx_policy.model.Service.Builder() + .setServiceEntries(serviceEntries) + .setId(serviceName) + .setDisplayName(serviceName) + .build(); + service.patch(serviceName, infraService); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to create NSX infra service, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + private String getServiceById(String ruleName) { + try { + Services service = (Services) nsxService.apply(Services.class); + com.vmware.nsx_policy.model.Service svc1 = service.get(ruleName); + if (Objects.nonNull(svc1)) { + return ((L4PortSetServiceEntry) svc1.getServiceEntries().get(0)).getParentPath(); + } + } catch (Exception e) { + return null; + } + return null; + } + + /** + * Create a Group for the Segment on the Inventory, with the same name as the segment and being the segment the only member of the group + */ + public void createGroupForSegment(String segmentName) { + logger.info(String.format("Creating Group for Segment %s", segmentName)); + + PathExpression pathExpression = new PathExpression(); + List paths = List.of(String.format("%s/%s", SEGMENTS_PATH, segmentName)); + pathExpression.setPaths(paths); + + Groups service = (Groups) nsxService.apply(Groups.class); + Group group = new Group.Builder() + .setId(segmentName) + .setDisplayName(segmentName) + .setExpression(List.of(pathExpression)) + .build(); + service.patch(DEFAULT_DOMAIN, segmentName, group); + } + + /** + * Remove Segment Group from the Inventory + */ + private void removeGroupForSegment(String segmentName) { + logger.info(String.format("Removing Group for Segment %s", segmentName)); + Groups service = (Groups) nsxService.apply(Groups.class); + service.delete(DEFAULT_DOMAIN, segmentName, true, false); + } + + private void removeSegmentDistributedFirewallRules(String segmentName) { + try { + SecurityPolicies services = (SecurityPolicies) nsxService.apply(SecurityPolicies.class); + services.delete(DEFAULT_DOMAIN, segmentName); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to remove NSX distributed firewall policy for segment %s, due to: %s", segmentName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + public void createSegmentDistributedFirewall(String segmentName, List nsxRules) { + try { + String groupPath = getGroupPath(segmentName); + if (Objects.isNull(groupPath)) { + throw new CloudRuntimeException(String.format("Failed to find group for segment %s", segmentName)); + } + SecurityPolicies services = (SecurityPolicies) nsxService.apply(SecurityPolicies.class); + List rules = getRulesForDistributedFirewall(segmentName, nsxRules); + SecurityPolicy policy = new SecurityPolicy.Builder() + .setDisplayName(segmentName) + .setId(segmentName) + .setCategory("Application") + .setRules(rules) + .setScope(List.of(groupPath)) + .build(); + services.patch(DEFAULT_DOMAIN, segmentName, policy); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to create NSX distributed firewall policy for segment %s, due to: %s", segmentName, ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + public void deleteDistributedFirewallRules(String segmentName, List nsxRules) { + for(NsxNetworkRule rule : nsxRules) { + String ruleId = NsxControllerUtils.getNsxDistributedFirewallPolicyRuleId(segmentName, rule.getRuleId()); + String svcName = getServiceName(ruleId, rule.getPrivatePort(), rule.getProtocol(), rule.getIcmpType(), rule.getIcmpCode()); + // delete rules + Rules rules = (Rules) nsxService.apply(Rules.class); + rules.delete(DEFAULT_DOMAIN, segmentName, ruleId); + // delete service - if any + Services services = (Services) nsxService.apply(Services.class); + services.delete(svcName); + } + } + + private List getRulesForDistributedFirewall(String segmentName, List nsxRules) { + List rules = new ArrayList<>(); + String groupPath = getGroupPath(segmentName); + if (Objects.isNull(groupPath)) { + throw new CloudRuntimeException(String.format("Failed to find group for segment %s", segmentName)); + } + for (NsxNetworkRule rule : nsxRules) { + String ruleId = NsxControllerUtils.getNsxDistributedFirewallPolicyRuleId(segmentName, rule.getRuleId()); + Rule ruleToAdd = new Rule.Builder() + .setAction(rule.getAclAction().toString()) + .setId(ruleId) + .setDisplayName(ruleId) + .setResourceType("SecurityPolicy") + .setSourceGroups(getGroupsForTraffic(rule, segmentName, true)) + .setDestinationGroups(getGroupsForTraffic(rule, segmentName, false)) + .setServices(getServicesListForDistributedFirewallRule(rule, segmentName)) + .setScope(List.of(groupPath)) + .build(); + rules.add(ruleToAdd); + } + return rules; + } + + private List getServicesListForDistributedFirewallRule(NsxNetworkRule rule, String segmentName) { + List services = List.of("ANY"); + if (!rule.getProtocol().equalsIgnoreCase("all")) { + String ruleName = String.format("%s-R%s", segmentName, rule.getRuleId()); + String serviceName = getNsxInfraServices(ruleName, rule.getPrivatePort(), rule.getProtocol(), + rule.getIcmpType(), rule.getIcmpCode()); + services = List.of(serviceName); + } + return services; + } + + protected List getGroupsForTraffic(NsxNetworkRule rule, + String segmentName, boolean source) { + List segmentGroup = List.of(String.format("%s/%s", GROUPS_PATH_PREFIX, segmentName)); + List sourceCidrList = rule.getSourceCidrList(); + List destCidrList = rule.getDestinationCidrList(); + List ingressSource = (rule.getService() == Network.Service.NetworkACL ? segmentGroup : destCidrList); + List egressSource = (rule.getService() == Network.Service.NetworkACL ? sourceCidrList : destCidrList); + + String trafficType = rule.getTrafficType(); + if (trafficType.equalsIgnoreCase("ingress")) { + return source ? sourceCidrList : ingressSource; + } else if (trafficType.equalsIgnoreCase("egress")) { + return source ? segmentGroup : egressSource; + } + String err = String.format("Unsupported traffic type %s", trafficType); + logger.error(err); + throw new CloudRuntimeException(err); + } + + + private List listNsxGroups() { + try { + Groups groups = (Groups) nsxService.apply(Groups.class); + GroupListResult result = groups.list(DEFAULT_DOMAIN, null, false, null, null, null, null, null); + return result.getResults(); + } catch (Error error) { + ApiError ae = error.getData()._convertTo(ApiError.class); + String msg = String.format("Failed to list NSX groups, due to: %s", ae.getErrorMessage()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + private String getGroupPath(String segmentName) { + List groups = listNsxGroups(); + Optional matchingGroup = groups.stream().filter(group -> group.getDisplayName().equals(segmentName)).findFirst(); + return matchingGroup.map(Group::getPath).orElse(null); + + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxElement.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxElement.java new file mode 100644 index 000000000000..7673e5a60386 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxElement.java @@ -0,0 +1,957 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.amazonaws.util.CollectionUtils; +import com.cloud.agent.AgentManager; +import com.cloud.agent.Listener; +import com.cloud.agent.api.AgentControlAnswer; +import com.cloud.agent.api.AgentControlCommand; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.StartupCommand; +import com.cloud.agent.api.to.LoadBalancerTO; +import com.cloud.api.ApiDBUtils; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.deploy.DeployDestination; +import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.ConnectionException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.Status; +import com.cloud.network.IpAddress; +import com.cloud.network.Network; +import com.cloud.network.NetworkModel; +import com.cloud.network.Networks; +import com.cloud.network.PhysicalNetworkServiceProvider; +import com.cloud.network.PublicIpAddress; +import com.cloud.network.VirtualRouterProvider; +import com.cloud.network.dao.IPAddressDao; +import com.cloud.network.dao.IPAddressVO; +import com.cloud.network.dao.LoadBalancerVMMapDao; +import com.cloud.network.dao.LoadBalancerVMMapVO; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.dao.PhysicalNetworkServiceProviderDao; +import com.cloud.network.dao.PhysicalNetworkVO; +import com.cloud.network.dao.VirtualRouterProviderDao; +import com.cloud.network.element.DhcpServiceProvider; +import com.cloud.network.element.DnsServiceProvider; +import com.cloud.network.element.FirewallServiceProvider; +import com.cloud.network.element.IpDeployer; +import com.cloud.network.element.LoadBalancingServiceProvider; +import com.cloud.network.element.NetworkACLServiceProvider; +import com.cloud.network.element.PortForwardingServiceProvider; +import com.cloud.network.element.StaticNatServiceProvider; +import com.cloud.network.element.VirtualRouterElement; +import com.cloud.network.element.VirtualRouterProviderVO; +import com.cloud.network.element.VpcProvider; +import com.cloud.network.lb.LoadBalancingRule; +import com.cloud.network.rules.FirewallRule; +import com.cloud.network.rules.LoadBalancerContainer; +import com.cloud.network.rules.PortForwardingRule; +import com.cloud.network.rules.StaticNat; +import com.cloud.network.vpc.NetworkACLItem; +import com.cloud.network.vpc.PrivateGateway; +import com.cloud.network.vpc.StaticRouteProfile; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.offering.NetworkOffering; +import com.cloud.resource.ResourceManager; +import com.cloud.resource.ResourceStateAdapter; +import com.cloud.resource.ServerResource; +import com.cloud.resource.UnableDeleteHostException; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.uservm.UserVm; +import com.cloud.utils.Pair; +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.db.QueryBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.NicProfile; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachineProfile; +import com.cloud.vm.dao.VMInstanceDao; +import net.sf.ehcache.config.InvalidConfigurationException; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.StartupNsxCommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.command.admin.internallb.ConfigureInternalLoadBalancerElementCmd; +import org.apache.cloudstack.api.command.admin.internallb.CreateInternalLoadBalancerElementCmd; +import org.apache.cloudstack.api.command.admin.internallb.ListInternalLoadBalancerElementsCmd; +import org.apache.cloudstack.network.element.InternalLoadBalancerElementService; +import org.apache.cloudstack.resource.NsxLoadBalancerMember; +import org.apache.cloudstack.resource.NsxNetworkRule; +import org.apache.cloudstack.resource.NsxOpObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.cloudstack.resourcedetail.FirewallRuleDetailVO; +import org.apache.cloudstack.resourcedetail.dao.FirewallRuleDetailsDao; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.LongFunction; +import java.util.stream.Collectors; + +@Component +public class NsxElement extends AdapterBase implements DhcpServiceProvider, DnsServiceProvider, VpcProvider, + StaticNatServiceProvider, IpDeployer, PortForwardingServiceProvider, NetworkACLServiceProvider, + LoadBalancingServiceProvider, FirewallServiceProvider, InternalLoadBalancerElementService, ResourceStateAdapter, Listener { + + + @Inject + AccountManager accountMgr; + @Inject + NsxServiceImpl nsxService; + @Inject + DataCenterDao dataCenterDao; + @Inject + NetworkDao networkDao; + @Inject + AgentManager agentManager; + @Inject + ResourceManager resourceManager; + @Inject + PhysicalNetworkDao physicalNetworkDao; + @Inject + NetworkModel networkModel; + @Inject + DomainDao domainDao; + @Inject + protected VpcOfferingServiceMapDao vpcOfferingServiceMapDao; + @Inject + IPAddressDao ipAddressDao; + @Inject + VMInstanceDao vmInstanceDao; + @Inject + VpcDao vpcDao; + @Inject + LoadBalancerVMMapDao lbVmMapDao; + @Inject + VirtualRouterProviderDao vrProviderDao; + @Inject + PhysicalNetworkServiceProviderDao pNtwkSvcProviderDao; + @Inject + FirewallRuleDetailsDao firewallRuleDetailsDao; + + protected Logger logger = LogManager.getLogger(getClass()); + + private final Map> capabilities = initCapabilities(); + + + private static Map> initCapabilities() { + Map> capabilities = new HashMap<>(); + + Map dhcpCapabilities = Map.of(Network.Capability.DhcpAccrossMultipleSubnets, "true"); + capabilities.put(Network.Service.Dhcp, dhcpCapabilities); + + Map dnsCapabilities = new HashMap<>(); + dnsCapabilities.put(Network.Capability.AllowDnsSuffixModification, "true"); + capabilities.put(Network.Service.Dns, dnsCapabilities); + + capabilities.put(Network.Service.StaticNat, null); + + // Set capabilities for LB service + Map lbCapabilities = new HashMap(); + lbCapabilities.put(Network.Capability.SupportedLBAlgorithms, "roundrobin,leastconn"); + lbCapabilities.put(Network.Capability.SupportedLBIsolation, "dedicated"); + lbCapabilities.put(Network.Capability.SupportedProtocols, "tcp, udp"); + lbCapabilities.put(Network.Capability.SupportedStickinessMethods, VirtualRouterElement.getHAProxyStickinessCapability()); + lbCapabilities.put(Network.Capability.LbSchemes, String.join(",", LoadBalancerContainer.Scheme.Internal.name(), LoadBalancerContainer.Scheme.Public.name())); + + capabilities.put(Network.Service.Lb, lbCapabilities); + capabilities.put(Network.Service.PortForwarding, null); + capabilities.put(Network.Service.NetworkACL, null); + + Map firewallCapabilities = new HashMap<>(); + firewallCapabilities.put(Network.Capability.SupportedProtocols, "tcp,udp,icmp"); + firewallCapabilities.put(Network.Capability.SupportedEgressProtocols, "tcp,udp,icmp,all"); + firewallCapabilities.put(Network.Capability.MultipleIps, "true"); + firewallCapabilities.put(Network.Capability.TrafficStatistics, "per public ip"); + firewallCapabilities.put(Network.Capability.SupportedTrafficDirection, "ingress, egress"); + capabilities.put(Network.Service.Firewall, firewallCapabilities); + + Map sourceNatCapabilities = new HashMap<>(); + sourceNatCapabilities.put(Network.Capability.RedundantRouter, "true"); + sourceNatCapabilities.put(Network.Capability.SupportedSourceNatTypes, "peraccount"); + capabilities.put(Network.Service.SourceNat, sourceNatCapabilities); + return capabilities; + } + @Override + public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + return true; + } + + @Override + public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + return true; + } + + @Override + public boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavailableException { + return true; + } + + @Override + public boolean setExtraDhcpOptions(Network network, long nicId, Map dhcpOptions) { + return true; + } + + @Override + public boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vmProfile) throws ResourceUnavailableException { + return true; + } + + @Override + public boolean addDnsEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + return true; + } + + @Override + public boolean configDnsSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + return true; + } + + @Override + public boolean removeDnsSupportForSubnet(Network network) throws ResourceUnavailableException { + return true; + } + + @Override + public Map> getCapabilities() { + return capabilities; + } + + @Override + public boolean applyIps(Network network, List ipAddress, Set services) throws ResourceUnavailableException { + return true; + } + + @Override + public Network.Provider getProvider() { + return Network.Provider.Nsx; + } + + @Override + public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + // TODO: Check if the network is NSX based (was already implemented as part of the guru.setup() + return true; + } + + @Override + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + return false; + } + + @Override + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + return false; + } + + @Override + public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { + return canHandle(network, Network.Service.Connectivity); + } + + @Override + public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + Account account = accountMgr.getAccount(network.getAccountId()); + NetworkVO networkVO = networkDao.findById(network.getId()); + DataCenterVO zone = dataCenterDao.findById(network.getDataCenterId()); + DomainVO domain = domainDao.findById(account.getDomainId()); + if (Objects.isNull(zone)) { + String msg = String.format("Cannot find zone with ID %s", network.getDataCenterId()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + return nsxService.deleteNetwork(zone.getId(), account.getId(), domain.getId(), networkVO); + } + + @Override + public boolean isReady(PhysicalNetworkServiceProvider provider) { + return true; + } + + @Override + public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + return false; + } + + @Override + public boolean canEnableIndividualServices() { + return true; + } + + @Override + public boolean verifyServicesCombination(Set services) { + return true; + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + agentManager.registerForHostEvents(this, true, true, true); + resourceManager.registerResourceStateAdapter(this.getClass().getSimpleName(), this); + return true; + } + + @Override + public boolean start() { + return false; + } + + @Override + public boolean stop() { + return false; + } + + @Override + public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { + return null; + } + + @Override + public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map details, List hostTags) { + if (!(startup[0] instanceof StartupNsxCommand)) { + return null; + } + host.setType(Host.Type.L2Networking); + return host; + } + + @Override + public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { + return null; + } + + private DomainVO getDomainFromAccount(Account account) { + DomainVO domain = domainDao.findById(account.getDomainId()); + if (Objects.isNull(domain)) { + String msg = String.format("Unable to find domain with id: %s", account.getDomainId()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + return domain; + } + + @Override + public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { + DataCenterVO zone = zoneFunction.apply(vpc.getZoneId()); + Pair isNsxAndAccount = validateVpcConfigurationAndGetAccount(zone, vpc); + if (Boolean.FALSE.equals(isNsxAndAccount.first())) { + return true; + } + if (Boolean.TRUE.equals(isNsxAndAccount.first()) && Objects.isNull(isNsxAndAccount.second())) { + throw new InvalidParameterValueException(String.format("Failed to find account with id %s", vpc.getAccountId())); + } + return true; + } + + @Override + public boolean shutdownVpc(Vpc vpc, ReservationContext context) throws ConcurrentOperationException { + DataCenterVO zone = zoneFunction.apply(vpc.getZoneId()); + Pair isNsxAndAccount = validateVpcConfigurationAndGetAccount(zone, vpc); + if (Boolean.FALSE.equals(isNsxAndAccount.first())) { + return true; + } + if (Boolean.TRUE.equals(isNsxAndAccount.first()) && Objects.isNull(isNsxAndAccount.second())) { + throw new InvalidParameterValueException(String.format("Failed to find account with id %s", vpc.getAccountId())); + } + Account account = isNsxAndAccount.second(); + DomainVO domain = getDomainFromAccount(account); + return nsxService.deleteVpcNetwork(vpc.getZoneId(), account.getId(), domain.getId(), vpc.getId(), vpc.getName()); + } + + private Pair validateVpcConfigurationAndGetAccount(DataCenterVO zone, Vpc vpc) { + if (Objects.isNull(zone)) { + throw new InvalidParameterValueException(String.format("Failed to find zone with id %s", vpc.getZoneId())); + } + Account account = null; + boolean forNsx = false; + List physicalNetworks = physicalNetworkDao.listByZoneAndTrafficType(zone.getId(), Networks.TrafficType.Guest); + if (CollectionUtils.isNullOrEmpty(physicalNetworks)) { + String err = String.format("Desired physical network is not present in the zone %s for traffic type %s. ", zone.getName(), Networks.TrafficType.Guest.name()); + logger.error(err); + throw new InvalidConfigurationException(err); + } + List filteredPhysicalNetworks = physicalNetworks.stream().filter(x -> x.getIsolationMethods().contains("NSX")).collect(Collectors.toList()); + if (CollectionUtils.isNullOrEmpty(filteredPhysicalNetworks)) { + String err = String.format("No physical network with NSX isolation type for traffic type %s is present in the zone %s.", Networks.TrafficType.Guest.name(), zone.getName()); + logger.error(err); + throw new InvalidConfigurationException(err); + } + if (filteredPhysicalNetworks.get(0).getIsolationMethods().contains("NSX")) { + account = accountMgr.getAccount(vpc.getAccountId()); + forNsx = true; + } + return new Pair<>(forNsx, account); + } + + @Override + public boolean createPrivateGateway(PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException { + return false; + } + + @Override + public boolean deletePrivateGateway(PrivateGateway privateGateway) throws ConcurrentOperationException, ResourceUnavailableException { + return false; + } + + @Override + public boolean applyStaticRoutes(Vpc vpc, List routes) throws ResourceUnavailableException { + return false; + } + + @Override + public boolean applyACLItemsToPrivateGw(PrivateGateway gateway, List rules) throws ResourceUnavailableException { + return false; + } + + @Override + public boolean processAnswers(long agentId, long seq, Answer[] answers) { + return false; + } + + @Override + public boolean processCommands(long agentId, long seq, Command[] commands) { + return false; + } + + @Override + public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) { + return null; + } + + @Override + public void processHostAdded(long hostId) { + // Do nothing + } + + @Override + public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException { + // Do nothing + } + + @Override + public boolean processDisconnect(long agentId, Status state) { + return false; + } + + @Override + public void processHostAboutToBeRemoved(long hostId) { + // Do nothing + } + + @Override + public void processHostRemoved(long hostId, long clusterId) { + // Do nothing + } + + @Override + public boolean isRecurring() { + return false; + } + + @Override + public int getTimeout() { + return 0; + } + + @Override + public boolean processTimeout(long agentId, long seq) { + return false; + } + + protected boolean canHandle(Network network, Network.Service service) { + logger.debug("Checking if Nsx Element can handle service " + service.getName() + " on network " + + network.getDisplayText()); + + if (!networkModel.isProviderForNetwork(getProvider(), network.getId())) { + logger.debug("Nsx Element is not a provider for network " + network.getDisplayText()); + return false; + } + + return true; + } + + private final LongFunction zoneFunction = zoneId -> dataCenterDao.findById(zoneId); + + @Override + public IpDeployer getIpDeployer(Network network) { + return this; + } + + @Override + public boolean applyStaticNats(Network config, List rules) throws ResourceUnavailableException { + for(StaticNat staticNat : rules) { + long sourceIpAddressId = staticNat.getSourceIpAddressId(); + IPAddressVO ipAddressVO = ipAddressDao.findByIdIncludingRemoved(sourceIpAddressId); + VMInstanceVO vm = vmInstanceDao.findByIdIncludingRemoved(ipAddressVO.getAssociatedWithVmId()); + // floating ip is released when nic was deleted + if (vm == null || networkModel.getNicInNetworkIncludingRemoved(vm.getId(), config.getId()) == null) { + continue; + } + Pair vpcOrNetwork = getVpcOrNetwork(config.getVpcId(), config.getId()); + VpcVO vpc = vpcOrNetwork.first(); + NetworkVO network = vpcOrNetwork.second(); + Long networkResourceId = Objects.nonNull(vpc) ? vpc.getId() : network.getId(); + String networkResourceName = Objects.nonNull(vpc) ? vpc.getName() : network.getName(); + boolean isVpcResource = Objects.nonNull(vpc); + if (!staticNat.isForRevoke()) { + return nsxService.createStaticNatRule(config.getDataCenterId(), config.getDomainId(), config.getAccountId(), + networkResourceId, networkResourceName, isVpcResource, vm.getId(), + ipAddressVO.getAddress().addr(), staticNat.getDestIpAddress()); + } else { + return nsxService.deleteStaticNatRule(config.getDataCenterId(), config.getDomainId(), config.getAccountId(), + networkResourceId, networkResourceName, isVpcResource); + } + } + return false; + } + + protected synchronized boolean applyPFRulesInternal(Network network, List rules) { + return Transaction.execute((TransactionCallback) status -> { + boolean result = true; + for (PortForwardingRule rule : rules) { + IPAddressVO publicIp = ApiDBUtils.findIpAddressById(rule.getSourceIpAddressId()); + UserVm vm = ApiDBUtils.findUserVmById(rule.getVirtualMachineId()); + if (vm == null && rule.getState() != FirewallRule.State.Revoke) { + continue; + } + NsxOpObject nsxObject = getNsxOpObject(network); + String publicPort = getPublicPortRange(rule); + + String privatePort = getPrivatePFPortRange(rule); + + NsxNetworkRule networkRule = new NsxNetworkRule.Builder() + .setDomainId(nsxObject.getDomainId()) + .setAccountId(nsxObject.getAccountId()) + .setZoneId(nsxObject.getZoneId()) + .setNetworkResourceId(nsxObject.getNetworkResourceId()) + .setNetworkResourceName(nsxObject.getNetworkResourceName()) + .setVpcResource(nsxObject.isVpcResource()) + .setVmId(Objects.nonNull(vm) ? vm.getId() : 0) + .setVmIp(Objects.nonNull(vm) ? vm.getPrivateIpAddress() : null) + .setPublicIp(publicIp.getAddress().addr()) + .setPrivatePort(privatePort) + .setPublicPort(publicPort) + .setRuleId(rule.getId()) + .setProtocol(rule.getProtocol().toUpperCase(Locale.ROOT)) + .build(); + FirewallRuleDetailVO ruleDetail = firewallRuleDetailsDao.findDetail(rule.getId(), ApiConstants.FOR_NSX); + if (Arrays.asList(FirewallRule.State.Add, FirewallRule.State.Active).contains(rule.getState())) { + if ((ruleDetail == null && FirewallRule.State.Add == rule.getState()) || (ruleDetail != null && !ruleDetail.getValue().equalsIgnoreCase("true"))) { + logger.debug("Creating port forwarding rule on NSX for VM {} to ports {} - {}", + vm.getUuid(), rule.getDestinationPortStart(), rule.getDestinationPortEnd()); + NsxAnswer answer = nsxService.createPortForwardRule(networkRule); + boolean pfRuleResult = answer.getResult(); + if (pfRuleResult && !answer.isObjectExistent()) { + logger.debug("Port forwarding rule {} created on NSX, adding detail on firewall rules details", rule.getId()); + if (ruleDetail == null && FirewallRule.State.Add == rule.getState()) { + logger.debug("Adding new firewall detail for rule {}", rule.getId()); + firewallRuleDetailsDao.addDetail(rule.getId(), ApiConstants.FOR_NSX, "true", false); + } else { + logger.debug("Updating firewall detail for rule {}", rule.getId()); + ruleDetail.setValue("true"); + firewallRuleDetailsDao.update(ruleDetail.getId(), ruleDetail); + } + } + result &= pfRuleResult; + } + } else if (rule.getState() == FirewallRule.State.Revoke) { + if (ruleDetail == null || (ruleDetail != null && ruleDetail.getValue().equalsIgnoreCase("true"))) { + boolean pfRuleResult = nsxService.deletePortForwardRule(networkRule); + if (pfRuleResult && ruleDetail != null) { + logger.debug("Updating firewall rule detail {} for rule {}, set to false", ruleDetail.getId(), rule.getId()); + ruleDetail.setValue("false"); + firewallRuleDetailsDao.update(ruleDetail.getId(), ruleDetail); + } + result &= pfRuleResult; + } + } + } + return result; + }); + } + + @Override + public boolean applyPFRules(Network network, List rules) throws ResourceUnavailableException { + if (!canHandle(network, Network.Service.PortForwarding)) { + return false; + } + return applyPFRulesInternal(network, rules); + } + + public Pair getVpcOrNetwork(Long vpcId, long networkId) { + VpcVO vpc = null; + NetworkVO network = null; + if (Objects.nonNull(vpcId)) { + vpc = vpcDao.findById(vpcId); + if (Objects.isNull(vpc)) { + throw new CloudRuntimeException(String.format("Failed to find VPC with id: %s", vpcId)); + } + } else { + network = networkDao.findById(networkId); + if (Objects.isNull(network)) { + throw new CloudRuntimeException(String.format("Failed to find network with id: %s", networkId)); + } + } + return new Pair<>(vpc, network); + } + + private static String getPublicPortRange(PortForwardingRule rule) { + return Objects.equals(rule.getSourcePortStart(), rule.getSourcePortEnd()) ? + String.valueOf(rule.getSourcePortStart()) : + String.valueOf(rule.getSourcePortStart()).concat("-").concat(String.valueOf(rule.getSourcePortEnd())); + } + + private static String getPrivatePFPortRange(PortForwardingRule rule) { + return rule.getDestinationPortStart() == rule.getDestinationPortEnd() ? + String.valueOf(rule.getDestinationPortStart()) : + String.valueOf(rule.getDestinationPortStart()).concat("-").concat(String.valueOf(rule.getDestinationPortEnd())); + } + + private static String getPrivatePortRange(FirewallRule rule) { + return Objects.equals(rule.getSourcePortStart(), rule.getSourcePortEnd()) ? + String.valueOf(rule.getSourcePortStart()) : + String.valueOf(rule.getSourcePortStart()).concat("-").concat(String.valueOf(rule.getSourcePortEnd())); + } + + private static String getPrivatePortRangeForACLRule(NetworkACLItem rule) { + return Objects.equals(rule.getSourcePortStart(), rule.getSourcePortEnd()) ? + String.valueOf(rule.getSourcePortStart()) : + String.valueOf(rule.getSourcePortStart()).concat("-").concat(String.valueOf(rule.getSourcePortEnd())); + } + + private long getResourceId(String resource, VpcVO vpc, NetworkVO network) { + switch (resource) { + case "domain": + return Objects.nonNull(vpc) ? vpc.getDomainId() : network.getDomainId(); + case "account": + return Objects.nonNull(vpc) ? vpc.getAccountId() : network.getAccountId(); + case "zone": + return Objects.nonNull(vpc) ? vpc.getZoneId() : network.getDataCenterId(); + default: + return 0; + } + } + + private NsxOpObject getNsxOpObject(Network network) { + Pair vpcOrNetwork = getVpcOrNetwork(network.getVpcId(), network.getId()); + VpcVO vpc = vpcOrNetwork.first(); + NetworkVO networkVO = vpcOrNetwork.second(); + long domainId = getResourceId("domain", vpc, networkVO); + long accountId = getResourceId("account", vpc, networkVO); + long zoneId = getResourceId("zone", vpc, networkVO); + + return new NsxOpObject.Builder() + .vpcVO(vpc) + .networkVO(networkVO) + .domainId(domainId) + .accountId(accountId) + .zoneId(zoneId) + .build(); + } + + @Override + public boolean applyLBRules(Network network, List rules) throws ResourceUnavailableException { + boolean result = true; + for (LoadBalancingRule loadBalancingRule : rules) { + IPAddressVO publicIp = ipAddressDao.findByIpAndDcId(network.getDataCenterId(), + loadBalancingRule.getSourceIp().addr()); + NsxOpObject nsxObject = getNsxOpObject(network); + + List lbMembers = getLoadBalancerMembers(loadBalancingRule); + NsxNetworkRule networkRule = new NsxNetworkRule.Builder() + .setDomainId(nsxObject.getDomainId()) + .setAccountId(nsxObject.getAccountId()) + .setZoneId(nsxObject.getZoneId()) + .setNetworkResourceId(nsxObject.getNetworkResourceId()) + .setNetworkResourceName(nsxObject.getNetworkResourceName()) + .setVpcResource(nsxObject.isVpcResource()) + .setMemberList(lbMembers) + .setPublicIp(LoadBalancerContainer.Scheme.Public == loadBalancingRule.getScheme() ? + publicIp.getAddress().addr() : loadBalancingRule.getSourceIp().addr()) + .setPublicPort(String.valueOf(loadBalancingRule.getSourcePortStart())) + .setPrivatePort(String.valueOf(loadBalancingRule.getDefaultPortStart())) + .setRuleId(loadBalancingRule.getId()) + .setProtocol(loadBalancingRule.getLbProtocol().toUpperCase(Locale.ROOT)) + .setAlgorithm(loadBalancingRule.getAlgorithm()) + .build(); + if (Arrays.asList(FirewallRule.State.Add, FirewallRule.State.Active).contains(loadBalancingRule.getState())) { + result &= nsxService.createLbRule(networkRule); + } else if (loadBalancingRule.getState() == FirewallRule.State.Revoke) { + result &= nsxService.deleteLbRule(networkRule); + } + } + return result; + } + + @Override + public boolean validateLBRule(Network network, LoadBalancingRule rule) { + return true; + } + + @Override + public List updateHealthChecks(Network network, List lbrules) { + return new ArrayList<>(); + } + + @Override + public boolean handlesOnlyRulesInTransitionState() { + return false; + } + + private List getLoadBalancerMembers(LoadBalancingRule lbRule) { + List lbVms = lbVmMapDao.listByLoadBalancerId(lbRule.getId(), false); + List lbMembers = new ArrayList<>(); + + for (LoadBalancerVMMapVO lbVm : lbVms) { + NsxLoadBalancerMember member = new NsxLoadBalancerMember(lbVm.getInstanceId(), lbVm.getInstanceIp(), lbRule.getDefaultPortStart()); + lbMembers.add(member); + } + return lbMembers; + } + + @Override + public boolean applyNetworkACLs(Network network, List rules) throws ResourceUnavailableException { + if (!canHandle(network, Network.Service.NetworkACL)) { + return false; + } + + List nsxDelNetworkRules = new ArrayList<>(); + boolean success = true; + for (NetworkACLItem rule : rules) { + String privatePort = getPrivatePortRangeForACLRule(rule); + NsxNetworkRule networkRule = getNsxNetworkRuleForAcl(rule, privatePort); + if (Arrays.asList(NetworkACLItem.State.Active, NetworkACLItem.State.Add).contains(rule.getState())) { + success = success && nsxService.addFirewallRules(network, List.of(networkRule)); + } else if (NetworkACLItem.State.Revoke == rule.getState()) { + nsxDelNetworkRules.add(networkRule); + } + } + + if (!nsxDelNetworkRules.isEmpty()) { + success = nsxService.deleteFirewallRules(network, nsxDelNetworkRules); + if (!success) { + logger.warn("Not all firewall rules were successfully deleted"); + } + } + return success; + } + + @Override + public boolean reorderAclRules(Vpc vpc, List networks, List networkACLItems) { + List aclRulesList = new ArrayList<>(); + for (NetworkACLItem rule : networkACLItems) { + String privatePort = getPrivatePortRangeForACLRule(rule); + aclRulesList.add(getNsxNetworkRuleForAcl(rule, privatePort)); + } + for (Network network: networks) { + nsxService.deleteFirewallRules(network, aclRulesList); + } + boolean success = true; + for (Network network : networks) { + for (NsxNetworkRule aclRule : aclRulesList) { + success = success && nsxService.addFirewallRules(network, List.of(aclRule)); + } + } + return success; + } + + private NsxNetworkRule getNsxNetworkRuleForAcl(NetworkACLItem rule, String privatePort) { + return new NsxNetworkRule.Builder() + .setRuleId(rule.getId()) + .setSourceCidrList(Objects.nonNull(rule.getSourceCidrList()) ? transformCidrListValues(rule.getSourceCidrList()) : List.of("ANY")) + .setAclAction(transformActionValue(rule.getAction())) + .setTrafficType(rule.getTrafficType().toString()) + .setProtocol(rule.getProtocol().toUpperCase()) + .setPublicPort(String.valueOf(rule.getSourcePortStart())) + .setPrivatePort(privatePort) + .setIcmpCode(rule.getIcmpCode()) + .setIcmpType(rule.getIcmpType()) + .setService(Network.Service.NetworkACL) + .build(); + } + @Override + public boolean applyFWRules(Network network, List rules) throws ResourceUnavailableException { + + if (!canHandle(network, Network.Service.Firewall)) { + return false; + } + List nsxAddNetworkRules = new ArrayList<>(); + List nsxDelNetworkRules = new ArrayList<>(); + for (FirewallRule rule : rules) { + NsxNetworkRule networkRule = new NsxNetworkRule.Builder() + .setRuleId(rule.getId()) + .setAclAction(NsxNetworkRule.NsxRuleAction.ALLOW) + .setSourceCidrList(Objects.nonNull(rule.getSourceCidrList()) ? + transformCidrListValues(rule.getSourceCidrList()) : List.of("ANY")) + .setDestinationCidrList(Objects.nonNull(rule.getDestinationCidrList()) ? + transformCidrListValues(rule.getDestinationCidrList()) : List.of("ANY")) + .setIcmpCode(rule.getIcmpCode()) + .setIcmpType(rule.getIcmpType()) + .setPrivatePort(getPrivatePortRange(rule)) + .setTrafficType(rule.getTrafficType().toString()) + .setService(Network.Service.Firewall) + .setProtocol(rule.getProtocol().toUpperCase(Locale.ROOT)) + .build(); + if (rule.getState() == FirewallRule.State.Add) { + nsxAddNetworkRules.add(networkRule); + } else if (rule.getState() == FirewallRule.State.Revoke) { + nsxDelNetworkRules.add(networkRule); + } + } + boolean success = true; + if (!nsxDelNetworkRules.isEmpty()) { + success = nsxService.deleteFirewallRules(network, nsxDelNetworkRules); + if (!success) { + logger.warn("Not all firewall rules were successfully deleted"); + } + } + return success && nsxService.addFirewallRules(network, nsxAddNetworkRules); + } + + protected NsxNetworkRule.NsxRuleAction transformActionValue(NetworkACLItem.Action action) { + if (action == NetworkACLItem.Action.Allow) { + return NsxNetworkRule.NsxRuleAction.ALLOW; + } else if (action == NetworkACLItem.Action.Deny) { + return NsxNetworkRule.NsxRuleAction.DROP; + } + String err = String.format("Unsupported action %s", action.toString()); + logger.error(err); + throw new CloudRuntimeException(err); + } + + /** + * Replace 0.0.0.0/0 to ANY on each occurrence + */ + protected List transformCidrListValues(List sourceCidrList) { + List list = new ArrayList<>(); + if (org.apache.commons.collections.CollectionUtils.isNotEmpty(sourceCidrList)) { + for (String cidr : sourceCidrList) { + if (cidr.equals("0.0.0.0/0")) { + list.add("ANY"); + } else { + list.add(cidr); + } + } + } + return list; + } + + @Override + public VirtualRouterProvider configureInternalLoadBalancerElement(long id, boolean enable) { + VirtualRouterProviderVO element = vrProviderDao.findById(id); + if (element == null || element.getType() != VirtualRouterProvider.Type.Nsx) { + throw new InvalidParameterValueException("Can't find " + getName() + " " + + "element with network service provider id " + id + " to be used as a provider for " + + getName()); + } + + element.setEnabled(enable); + element = vrProviderDao.persist(element); + + return element; + } + + @Override + public VirtualRouterProvider addInternalLoadBalancerElement(long ntwkSvcProviderId) { + VirtualRouterProviderVO element = vrProviderDao.findByNspIdAndType(ntwkSvcProviderId, VirtualRouterProvider.Type.Nsx); + if (element != null) { + logger.debug("There is already an " + getName() + " with service provider id " + ntwkSvcProviderId); + return null; + } + + PhysicalNetworkServiceProvider provider = pNtwkSvcProviderDao.findById(ntwkSvcProviderId); + if (provider == null || !provider.getProviderName().equalsIgnoreCase(getName())) { + throw new InvalidParameterValueException("Invalid network service provider is specified"); + } + + element = new VirtualRouterProviderVO(ntwkSvcProviderId, VirtualRouterProvider.Type.Nsx); + element = vrProviderDao.persist(element); + return element; + } + + @Override + public VirtualRouterProvider getInternalLoadBalancerElement(long id) { + VirtualRouterProvider provider = vrProviderDao.findById(id); + if (provider == null || provider.getType() != VirtualRouterProvider.Type.Nsx) { + throw new InvalidParameterValueException("Unable to find " + getName() + " by id"); + } + return provider; + } + + @Override + public List searchForInternalLoadBalancerElements(Long id, Long ntwkSvsProviderId, Boolean enabled) { + QueryBuilder sc = QueryBuilder.create(VirtualRouterProviderVO.class); + if (id != null) { + sc.and(sc.entity().getId(), SearchCriteria.Op.EQ, id); + } + if (ntwkSvsProviderId != null) { + sc.and(sc.entity().getNspId(), SearchCriteria.Op.EQ, ntwkSvsProviderId); + } + if (enabled != null) { + sc.and(sc.entity().isEnabled(), SearchCriteria.Op.EQ, enabled); + } + + //return only Internal LB elements + sc.and(sc.entity().getType(), SearchCriteria.Op.EQ, VirtualRouterProvider.Type.Nsx); + + return sc.list(); + } + + @Override + public VirtualRouterProvider.Type getProviderType() { + return VirtualRouterProvider.Type.Nsx; + } + + @Override + public List> getCommands() { + List> cmdList = new ArrayList>(); + cmdList.add(CreateInternalLoadBalancerElementCmd.class); + cmdList.add(ConfigureInternalLoadBalancerElementCmd.class); + cmdList.add(ListInternalLoadBalancerElementsCmd.class); + return cmdList; + } + + @Override + public boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address) { + return nsxService.updateVpcSourceNatIp(vpc, address); + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxGuestNetworkGuru.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxGuestNetworkGuru.java new file mode 100644 index 000000000000..032967d40617 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxGuestNetworkGuru.java @@ -0,0 +1,342 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; + +import com.cloud.dc.DataCenter; +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.NetworkMigrationResponder; +import com.cloud.network.NetworkModel; +import com.cloud.network.NetworkProfile; +import com.cloud.network.Network; +import com.cloud.network.Networks; +import com.cloud.network.PhysicalNetwork; +import com.cloud.network.PublicIpAddress; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.dao.PhysicalNetworkVO; +import com.cloud.network.guru.GuestNetworkGuru; +import com.cloud.network.vpc.VpcVO; +import com.cloud.offering.NetworkOffering; +import com.cloud.offerings.NetworkOfferingVO; +import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; +import com.cloud.user.Account; +import com.cloud.user.dao.AccountDao; +import com.cloud.utils.db.DB; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.NicProfile; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.CreateNsxDhcpRelayConfigCommand; +import org.apache.cloudstack.agent.api.CreateNsxSegmentCommand; +import org.apache.cloudstack.agent.api.CreateNsxTier1GatewayCommand; +import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand; +import org.apache.cloudstack.utils.NsxControllerUtils; + +import org.apache.cloudstack.utils.NsxHelper; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.inject.Inject; +import java.util.List; +import java.util.Objects; + +public class NsxGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigrationResponder { + protected Logger logger = LogManager.getLogger(getClass()); + + @Inject + NetworkOfferingServiceMapDao networkOfferingServiceMapDao; + @Inject + NsxControllerUtils nsxControllerUtils; + @Inject + AccountDao accountDao; + @Inject + DomainDao domainDao; + @Inject + NetworkModel networkModel; + + public NsxGuestNetworkGuru() { + super(); + _isolationMethods = new PhysicalNetwork.IsolationMethod[] {new PhysicalNetwork.IsolationMethod("NSX")}; + } + + @Override + public boolean canHandle(NetworkOffering offering, DataCenter.NetworkType networkType, + PhysicalNetwork physicalNetwork) { + return networkType == DataCenter.NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) + && isMyIsolationMethod(physicalNetwork) && (NetworkOffering.NetworkMode.ROUTED.equals(offering.getNetworkMode()) + || (networkOfferingServiceMapDao.isProviderForNetworkOffering( + offering.getId(), Network.Provider.Nsx) && NetworkOffering.NetworkMode.NATTED.equals(offering.getNetworkMode()))); + } + + @Override + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner) { + PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId()); + DataCenter dc = _dcDao.findById(plan.getDataCenterId()); + + if (!canHandle(offering, dc.getNetworkType(), physnet)) { + logger.debug("Refusing to design this network"); + return null; + } + + NetworkVO network = (NetworkVO) super.design(offering, plan, userSpecified, name, vpcId, owner); + if (network == null) { + return null; + } + network.setBroadcastDomainType(Networks.BroadcastDomainType.NSX); + + if (userSpecified != null) { + if ((userSpecified.getIp6Cidr() == null && userSpecified.getIp6Gateway() != null) || ( + userSpecified.getIp6Cidr() != null && userSpecified.getIp6Gateway() == null)) { + throw new InvalidParameterValueException("cidrv6 and gatewayv6 must be specified together."); + } + + if (userSpecified.getIp6Cidr() != null) { + network.setIp6Cidr(userSpecified.getIp6Cidr()); + network.setIp6Gateway(userSpecified.getIp6Gateway()); + } + } + + network.setBroadcastDomainType(Networks.BroadcastDomainType.NSX); + network.setState(Network.State.Allocated); + + NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), + network.getBroadcastDomainType(), network.getNetworkOfferingId(), Network.State.Implemented, + network.getDataCenterId(), network.getPhysicalNetworkId(), offering.isRedundantRouter()); + implemented.setAccountId(owner.getAccountId()); + + if (network.getGateway() != null) { + implemented.setGateway(network.getGateway()); + } + + if (network.getCidr() != null) { + implemented.setCidr(network.getCidr()); + } + + if (vpcId != null) { + implemented.setVpcId(vpcId); + } + + if (name != null) { + implemented.setName(name); + } + implemented.setBroadcastUri(Networks.BroadcastDomainType.NSX.toUri("nsx")); + + return network; + } + + @Override + public void setup(Network network, long networkId) { + try { + NetworkVO designedNetwork = _networkDao.findById(networkId); + long zoneId = network.getDataCenterId(); + DataCenter zone = _dcDao.findById(zoneId); + if (isNull(zone)) { + throw new CloudRuntimeException(String.format("Failed to find zone with id: %s", zoneId)); + } + createNsxSegment(designedNetwork, zone); + } catch (Exception ex) { + throw new CloudRuntimeException("unable to create NSX network " + network.getUuid() + "due to: " + ex.getMessage()); + } + } + + @Override + @DB + public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) { + // Do nothing + } + + @Override + public Network implement(Network network, NetworkOffering offering, DeployDestination dest, + ReservationContext context) { + NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), + network.getBroadcastDomainType(), network.getNetworkOfferingId(), Network.State.Implemented, + network.getDataCenterId(), network.getPhysicalNetworkId(), offering.isRedundantRouter()); + implemented.setAccountId(network.getAccountId()); + + if (network.getGateway() != null) { + implemented.setGateway(network.getGateway()); + } + + if (network.getCidr() != null) { + implemented.setCidr(network.getCidr()); + } + + if (network.getVpcId() != null) { + implemented.setVpcId(network.getVpcId()); + } + + if (network.getName() != null) { + implemented.setName(network.getName()); + } + implemented.setBroadcastUri(Networks.BroadcastDomainType.NSX.toUri("nsx")); + return implemented; + } + + @Override + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { + NicProfile nicProfile = super.allocate(network, nic, vm); + if (vm.getType() != VirtualMachine.Type.DomainRouter) { + return nicProfile; + } + + final DataCenter zone = _dcDao.findById(network.getDataCenterId()); + long zoneId = network.getDataCenterId(); + if (Objects.isNull(zone)) { + String msg = String.format("Unable to find zone with id: %s", zoneId); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + Account account = accountDao.findById(network.getAccountId()); + if (Objects.isNull(account)) { + String msg = String.format("Unable to find account with id: %s", network.getAccountId()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + VpcVO vpc = _vpcDao.findById(network.getVpcId()); + if (Objects.isNull(vpc)) { + String msg = String.format("Unable to find VPC with id: %s, allocating for network %s", network.getVpcId(), network.getName()); + logger.debug(msg); + } + + DomainVO domain = domainDao.findById(account.getDomainId()); + if (Objects.isNull(domain)) { + String msg = String.format("Unable to find domain with id: %s", account.getDomainId()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + + NetworkOfferingVO networkOfferingVO = networkOfferingDao.findById(network.getNetworkOfferingId()); + + if (isNull(network.getVpcId()) && networkOfferingVO.getNetworkMode().equals(NetworkOffering.NetworkMode.NATTED)) { + long domainId = domain.getId(); + long accountId = account.getId(); + long dataCenterId = zone.getId(); + long resourceId = network.getId(); + PublicIpAddress ipAddress = networkModel.getSourceNatIpAddressForGuestNetwork(account, network); + String translatedIp = ipAddress.getAddress().addr(); + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(domainId, accountId, dataCenterId, resourceId, false); + logger.debug(String.format("Creating NSX NAT Rule for Tier1 GW %s for translated IP %s for Isolated network %s", tier1GatewayName, translatedIp, network.getName())); + String natRuleId = NsxControllerUtils.getNsxNatRuleId(domainId, accountId, dataCenterId, resourceId, false); + CreateOrUpdateNsxTier1NatRuleCommand cmd = NsxHelper.createOrUpdateNsxNatRuleCommand(domainId, accountId, dataCenterId, tier1GatewayName, "SNAT", translatedIp, natRuleId); + NsxAnswer nsxAnswer = nsxControllerUtils.sendNsxCommand(cmd, dataCenterId); + if (!nsxAnswer.getResult()) { + String msg = String.format("Could not create NSX NAT Rule on Tier1 Gateway %s for IP %s for Isolated network %s", tier1GatewayName, translatedIp, network.getName()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + + // Create the DHCP relay config for the segment + String iPv4Address = nicProfile.getIPv4Address(); + List addresses = List.of(iPv4Address); + CreateNsxDhcpRelayConfigCommand command = NsxHelper.createNsxDhcpRelayConfigCommand(domain, account, zone, vpc, network, addresses); + NsxAnswer answer = nsxControllerUtils.sendNsxCommand(command, zone.getId()); + if (!answer.getResult()) { + String msg = String.format("Error creating DHCP relay config for network %s and nic %s: %s", network.getName(), nic.getName(), answer.getDetails()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + return nicProfile; + } + + @Override + public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm, + final DeployDestination dest, final ReservationContext context) + throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { + // Do nothing + } + + @Override + public boolean release(final NicProfile nic, final VirtualMachineProfile vm, final String reservationId) { + return true; + } + + @Override + public void shutdown(final NetworkProfile profile, final NetworkOffering offering) { + // Do nothing + } + + @Override + public boolean trash(Network network, NetworkOffering offering) { + return true; + } + + @Override + public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) { + return false; + } + + @Override + public void rollbackMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { + // Do nothing + } + + @Override + public void commitMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { + // Do nothing + } + + public void createNsxSegment(NetworkVO networkVO, DataCenter zone) { + Account account = accountDao.findById(networkVO.getAccountId()); + if (isNull(account)) { + throw new CloudRuntimeException(String.format("Unable to find account with id: %s", networkVO.getAccountId())); + } + DomainVO domain = domainDao.findById(account.getDomainId()); + if (Objects.isNull(domain)) { + String msg = String.format("Unable to find domain with id: %s", account.getDomainId()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + String vpcName = null; + if (nonNull(networkVO.getVpcId())) { + VpcVO vpc = _vpcDao.findById(networkVO.getVpcId()); + if (isNull(vpc)) { + throw new CloudRuntimeException(String.format("Failed to find VPC network with id: %s", networkVO.getVpcId())); + } + vpcName = vpc.getName(); + } else { + logger.debug(String.format("Creating a Tier 1 Gateway for the network %s before creating the NSX segment", networkVO.getName())); + long networkOfferingId = networkVO.getNetworkOfferingId(); + NetworkOfferingVO networkOfferingVO = networkOfferingDao.findById(networkOfferingId); + boolean isSourceNatSupported = !NetworkOffering.NetworkMode.ROUTED.equals(networkOfferingVO.getNetworkMode()) && + networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(networkVO.getNetworkOfferingId(), Network.Service.SourceNat); + CreateNsxTier1GatewayCommand nsxTier1GatewayCommand = new CreateNsxTier1GatewayCommand(domain.getId(), account.getId(), zone.getId(), networkVO.getId(), networkVO.getName(), false, isSourceNatSupported); + + NsxAnswer nsxAnswer = nsxControllerUtils.sendNsxCommand(nsxTier1GatewayCommand, zone.getId()); + if (!nsxAnswer.getResult()) { + String msg = String.format("Could not create a Tier 1 Gateway for network %s: %s", networkVO.getName(), nsxAnswer.getDetails()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + CreateNsxSegmentCommand command = NsxHelper.createNsxSegmentCommand(domain, account, zone, vpcName, networkVO); + NsxAnswer answer = nsxControllerUtils.sendNsxCommand(command, zone.getId()); + if (!answer.getResult()) { + throw new CloudRuntimeException("can not create NSX network"); + } + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxProviderService.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxProviderService.java new file mode 100644 index 000000000000..47dfe04db3ef --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxProviderService.java @@ -0,0 +1,35 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.network.nsx.NsxProvider; +import com.cloud.utils.component.PluggableService; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.command.AddNsxControllerCmd; +import org.apache.cloudstack.api.response.NsxControllerResponse; + +import java.util.List; + +public interface NsxProviderService extends PluggableService { + NsxProvider addProvider(AddNsxControllerCmd cmd); + + NsxControllerResponse createNsxControllerResponse(NsxProvider nsxProvider); + + List listNsxProviders(Long zoneId); + + boolean deleteNsxController(Long nsxControllerId); +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxProviderServiceImpl.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxProviderServiceImpl.java new file mode 100644 index 000000000000..c59ebfd87551 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxProviderServiceImpl.java @@ -0,0 +1,213 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.amazonaws.util.CollectionUtils; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.host.DetailVO; +import com.cloud.host.Host; +import com.cloud.host.dao.HostDetailsDao; +import com.cloud.network.Network; +import com.cloud.network.Networks; +import com.cloud.network.nsx.NsxProvider; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NsxProviderDao; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.dao.PhysicalNetworkVO; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.element.NsxProviderVO; +import com.cloud.resource.ResourceManager; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import com.cloud.utils.exception.CloudRuntimeException; +import com.google.common.annotations.VisibleForTesting; +import org.apache.cloudstack.api.command.DeleteNsxControllerCmd; +import org.apache.cloudstack.api.command.ListNsxControllersCmd; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.command.AddNsxControllerCmd; +import org.apache.cloudstack.api.response.NsxControllerResponse; +import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; +import org.apache.cloudstack.resource.NsxResource; +import org.apache.commons.lang3.StringUtils; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; +import java.util.ArrayList; +import java.util.List; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; + +public class NsxProviderServiceImpl implements NsxProviderService { + + @Inject + NsxProviderDao nsxProviderDao; + @Inject + DataCenterDao dataCenterDao; + @Inject + PhysicalNetworkDao physicalNetworkDao; + @Inject + NetworkDao networkDao; + @Inject + ResourceManager resourceManager; + @Inject + HostDetailsDao hostDetailsDao; + + @Override + public NsxProvider addProvider(AddNsxControllerCmd cmd) { + final Long zoneId = cmd.getZoneId(); + final String name = cmd.getName(); + final String hostname = cmd.getHostname(); + final String port = cmd.getPort() == null || cmd.getPort().equals(StringUtils.EMPTY) ? "443" : cmd.getPort(); + final String username = cmd.getUsername(); + final String password = cmd.getPassword(); + final String tier0Gateway = cmd.getTier0Gateway(); + final String edgeCluster = cmd.getEdgeCluster(); + final String transportZone = cmd.getTransportZone(); + + Map params = new HashMap<>(); + params.put("guid", UUID.randomUUID().toString()); + params.put("zoneId", zoneId.toString()); + params.put("name", name); + params.put("hostname", hostname); + params.put("port", port); + params.put("username", username); + params.put("password", password); + params.put("tier0Gateway", tier0Gateway); + params.put("edgeCluster", edgeCluster); + params.put("transportZone", transportZone); + + Map hostdetails = new HashMap<>(params); + NsxProvider nsxProvider; + + NsxResource nsxResource = new NsxResource(); + try { + nsxResource.configure(hostname, hostdetails); + final Host host = resourceManager.addHost(zoneId, nsxResource, nsxResource.getType(), params); + if (host != null) { + nsxProvider = Transaction.execute((TransactionCallback) status -> { + NsxProviderVO nsxProviderVO = new NsxProviderVO.Builder() + .setZoneId(zoneId) + .setHostId(host.getId()) + .setProviderName(name) + .setHostname(hostname) + .setPort(port) + .setUsername(username) + .setPassword(password) + .setTier0Gateway(tier0Gateway) + .setEdgeCluster(edgeCluster) + .setTransportZone(transportZone) + .build(); + + nsxProviderDao.persist(nsxProviderVO); + + DetailVO detail = new DetailVO(host.getId(), "nsxcontrollerid", + String.valueOf(nsxProviderVO.getId())); + hostDetailsDao.persist(detail); + + return nsxProviderVO; + }); + } else { + throw new CloudRuntimeException("Failed to add NSX controller due to internal error."); + } + } catch (ConfigurationException e) { + throw new CloudRuntimeException(e.getMessage()); + } + return nsxProvider; + } + + @Override + public NsxControllerResponse createNsxControllerResponse(NsxProvider nsxProvider) { + DataCenterVO zone = dataCenterDao.findById(nsxProvider.getZoneId()); + if (Objects.isNull(zone)) { + throw new CloudRuntimeException(String.format("Failed to find zone with id %s", nsxProvider.getZoneId())); + } + NsxControllerResponse response = new NsxControllerResponse(); + response.setName(nsxProvider.getProviderName()); + response.setUuid(nsxProvider.getUuid()); + response.setHostname(nsxProvider.getHostname()); + response.setPort(nsxProvider.getPort()); + response.setZoneId(zone.getUuid()); + response.setZoneName(zone.getName()); + response.setTier0Gateway(nsxProvider.getTier0Gateway()); + response.setEdgeCluster(nsxProvider.getEdgeCluster()); + response.setTransportZone(nsxProvider.getTransportZone()); + response.setObjectName("nsxController"); + return response; + } + + @Override + public List listNsxProviders(Long zoneId) { + List nsxControllersResponseList = new ArrayList<>(); + if (zoneId != null) { + NsxProviderVO nsxProviderVO = nsxProviderDao.findByZoneId(zoneId); + if (Objects.nonNull(nsxProviderVO)) { + nsxControllersResponseList.add(createNsxControllerResponse(nsxProviderVO)); + } + } else { + List nsxProviderVOList = nsxProviderDao.listAll(); + for (NsxProviderVO nsxProviderVO : nsxProviderVOList) { + nsxControllersResponseList.add(createNsxControllerResponse(nsxProviderVO)); + } + } + + return nsxControllersResponseList; + } + + @Override + public boolean deleteNsxController(Long nsxControllerId) { + NsxProviderVO nsxProvider = nsxProviderDao.findById(nsxControllerId); + if (Objects.isNull(nsxProvider)) { + throw new InvalidParameterValueException(String.format("Failed to find NSX controller with id: %s", nsxControllerId)); + } + Long zoneId = nsxProvider.getZoneId(); + // Find the physical network we work for + List physicalNetworks = physicalNetworkDao.listByZone(zoneId); + for (PhysicalNetworkVO physicalNetwork : physicalNetworks) { + List networkList = networkDao.listByPhysicalNetwork(physicalNetwork.getId()); + if (!CollectionUtils.isNullOrEmpty(networkList)) { + validateNetworkState(networkList); + } + } + nsxProviderDao.remove(nsxControllerId); + return true; + } + + @Override + public List> getCommands() { + List> cmdList = new ArrayList<>(); + if (Boolean.TRUE.equals(NetworkOrchestrationService.NSX_ENABLED.value())) { + cmdList.add(AddNsxControllerCmd.class); + cmdList.add(ListNsxControllersCmd.class); + cmdList.add(DeleteNsxControllerCmd.class); + } + return cmdList; + } + + @VisibleForTesting + void validateNetworkState(List networkList) { + for (NetworkVO network : networkList) { + if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.NSX && + ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy))) { + throw new CloudRuntimeException("This NSX Controller cannot be deleted as there are one or more logical networks provisioned by CloudStack on it."); + } + } + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxPublicNetworkGuru.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxPublicNetworkGuru.java new file mode 100644 index 000000000000..4df71056601c --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxPublicNetworkGuru.java @@ -0,0 +1,170 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.dc.VlanDetailsVO; +import com.cloud.dc.dao.VlanDetailsDao; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapacityException; +import com.cloud.network.Network; +import com.cloud.network.Networks; +import com.cloud.network.nsx.NsxService; +import com.cloud.network.dao.IPAddressVO; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.guru.PublicNetworkGuru; +import com.cloud.network.vpc.VpcOffering; +import com.cloud.network.vpc.VpcOfferingVO; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.network.vpc.dao.VpcOfferingDao; +import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao; +import com.cloud.offering.NetworkOffering; +import com.cloud.offerings.dao.NetworkOfferingDao; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.NicProfile; +import com.cloud.vm.VirtualMachineProfile; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.utils.NsxControllerUtils; +import org.apache.cloudstack.utils.NsxHelper; +import org.apache.commons.collections.CollectionUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.inject.Inject; +import java.util.List; +import java.util.stream.Collectors; + +public class NsxPublicNetworkGuru extends PublicNetworkGuru { + + @Inject + private VlanDetailsDao vlanDetailsDao; + @Inject + private VpcDao vpcDao; + @Inject + private VpcOfferingServiceMapDao vpcOfferingServiceMapDao; + @Inject + private NsxControllerUtils nsxControllerUtils; + @Inject + private NsxService nsxService; + @Inject + private VpcOfferingDao vpcOfferingDao; + @Inject + private NetworkOfferingDao offeringDao; + + protected Logger logger = LogManager.getLogger(getClass()); + + public NsxPublicNetworkGuru() { + super(); + } + + @Override + protected boolean canHandle(NetworkOffering offering) { + return isMyTrafficType(offering.getTrafficType()) && offering.isSystemOnly() && offering.isForNsx(); + } + + @Override + public Network design(NetworkOffering offering, DeploymentPlan plan, Network network, String name, Long vpcId, Account owner) { + if (!canHandle(offering)) { + return null; + } + + if (offering.getTrafficType() == Networks.TrafficType.Public) { + return new NetworkVO(offering.getTrafficType(), Networks.Mode.Static, network.getBroadcastDomainType(), offering.getId(), Network.State.Setup, plan.getDataCenterId(), + plan.getPhysicalNetworkId(), offering.isRedundantRouter()); + } + return null; + } + + @Override + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException { + logger.debug("NSX Public network guru: allocate"); + + IPAddressVO ipAddress = _ipAddressDao.findByIp(nic.getIPv4Address()); + if (ipAddress == null) { + String err = String.format("Cannot find the IP address %s", nic.getIPv4Address()); + logger.error(err); + throw new CloudRuntimeException(err); + } + Long vpcId = ipAddress.getVpcId(); + boolean isForVpc = vpcId != null; + VpcVO vpc = vpcDao.findById(vpcId); + if (vpc == null) { + String err = String.format("Cannot find a VPC with ID %s", vpcId); + logger.error(err); + throw new CloudRuntimeException(err); + } + + // For NSX, use VR Public IP != Source NAT + List ips = _ipAddressDao.listByAssociatedVpc(vpc.getId(), true); + if (CollectionUtils.isEmpty(ips)) { + String err = String.format("Cannot find a source NAT IP for the VPC %s", vpc.getName()); + logger.error(err); + throw new CloudRuntimeException(err); + } + ips = ips.stream().filter(x -> !x.getAddress().addr().equals(nic.getIPv4Address())).collect(Collectors.toList()); + // Use Source NAT IP address from the NSX Public Range. Do not Use the VR Public IP address + ipAddress = ips.get(0); + if (ipAddress.isSourceNat() && !ipAddress.isForSystemVms()) { + VlanDetailsVO detail = vlanDetailsDao.findDetail(ipAddress.getVlanId(), ApiConstants.NSX_DETAIL_KEY); + if (detail != null && detail.getValue().equalsIgnoreCase("true")) { + long accountId = vpc.getAccountId(); + long domainId = vpc.getDomainId(); + long dataCenterId = vpc.getZoneId(); + long resourceId = vpc.getId(); + Network.Service[] services = { Network.Service.SourceNat }; + long networkOfferingId = vpc.getVpcOfferingId(); + VpcOfferingVO vpcVO = vpcOfferingDao.findById(networkOfferingId); + boolean sourceNatEnabled = !NetworkOffering.NetworkMode.ROUTED.equals(vpcVO.getNetworkMode()) && + vpcOfferingServiceMapDao.areServicesSupportedByVpcOffering(vpc.getVpcOfferingId(), services); + + logger.info(String.format("Creating Tier 1 Gateway for VPC %s", vpc.getName())); + boolean result = nsxService.createVpcNetwork(dataCenterId, accountId, domainId, resourceId, vpc.getName(), sourceNatEnabled); + if (!result) { + String msg = String.format("Error creating Tier 1 Gateway for VPC %s", vpc.getName()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + + boolean hasNatSupport = false; + VpcOffering vpcOffering = vpcOfferingDao.findById(vpc.getVpcOfferingId()); + hasNatSupport = NetworkOffering.NetworkMode.NATTED.equals(vpcOffering.getNetworkMode()); + + if (!hasNatSupport) { + return nic; + } + + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(domainId, accountId, dataCenterId, resourceId, isForVpc); + String translatedIp = ipAddress.getAddress().addr(); + logger.debug(String.format("Creating NSX Nat Rule for Tier1 GW %s for translated IP %s", tier1GatewayName, translatedIp)); + String natRuleId = NsxControllerUtils.getNsxNatRuleId(domainId, accountId, dataCenterId, resourceId, isForVpc); + CreateOrUpdateNsxTier1NatRuleCommand cmd = NsxHelper.createOrUpdateNsxNatRuleCommand(domainId, accountId, dataCenterId, tier1GatewayName, "SNAT", translatedIp, natRuleId); + NsxAnswer nsxAnswer = nsxControllerUtils.sendNsxCommand(cmd, dataCenterId); + if (!nsxAnswer.getResult()) { + String msg = String.format("Could not create NSX Nat Rule on Tier1 Gateway %s for IP %s", tier1GatewayName, translatedIp); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + } + } + return nic; + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxServiceImpl.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxServiceImpl.java new file mode 100644 index 000000000000..139d8a55e592 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/service/NsxServiceImpl.java @@ -0,0 +1,203 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.network.IpAddress; +import com.cloud.network.Network; +import com.cloud.network.nsx.NsxService; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.CreateNsxDistributedFirewallRulesCommand; +import org.apache.cloudstack.agent.api.CreateNsxLoadBalancerRuleCommand; +import org.apache.cloudstack.agent.api.CreateNsxPortForwardRuleCommand; +import org.apache.cloudstack.agent.api.CreateNsxStaticNatCommand; +import org.apache.cloudstack.agent.api.CreateNsxTier1GatewayCommand; +import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxDistributedFirewallRulesCommand; +import org.apache.cloudstack.agent.api.DeleteNsxLoadBalancerRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxSegmentCommand; +import org.apache.cloudstack.agent.api.DeleteNsxNatRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxTier1GatewayCommand; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.cloudstack.resource.NsxNetworkRule; +import org.apache.cloudstack.utils.NsxControllerUtils; +import org.apache.cloudstack.utils.NsxHelper; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.inject.Inject; +import java.util.List; +import java.util.Objects; + +public class NsxServiceImpl implements NsxService, Configurable { + @Inject + NsxControllerUtils nsxControllerUtils; + @Inject + VpcDao vpcDao; + + protected Logger logger = LogManager.getLogger(getClass()); + + public boolean createVpcNetwork(Long zoneId, long accountId, long domainId, Long vpcId, String vpcName, boolean sourceNatEnabled) { + CreateNsxTier1GatewayCommand createNsxTier1GatewayCommand = + new CreateNsxTier1GatewayCommand(domainId, accountId, zoneId, vpcId, vpcName, true, sourceNatEnabled); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(createNsxTier1GatewayCommand, zoneId); + return result.getResult(); + } + + @Override + public boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address) { + if (vpc == null || address == null) { + return false; + } + long accountId = vpc.getAccountId(); + long domainId = vpc.getDomainId(); + long zoneId = vpc.getZoneId(); + long vpcId = vpc.getId(); + + logger.debug(String.format("Updating the source NAT IP for NSX VPC %s to IP: %s", vpc.getName(), address.getAddress().addr())); + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(domainId, accountId, zoneId, vpcId, true); + String sourceNatRuleId = NsxControllerUtils.getNsxNatRuleId(domainId, accountId, zoneId, vpcId, true); + CreateOrUpdateNsxTier1NatRuleCommand cmd = NsxHelper.createOrUpdateNsxNatRuleCommand(domainId, accountId, zoneId, tier1GatewayName, "SNAT", address.getAddress().addr(), sourceNatRuleId); + NsxAnswer answer = nsxControllerUtils.sendNsxCommand(cmd, zoneId); + if (!answer.getResult()) { + logger.error(String.format("Could not update the source NAT IP address for VPC %s: %s", vpc.getName(), answer.getDetails())); + return false; + } + return true; + } + + public boolean createNetwork(Long zoneId, long accountId, long domainId, Long networkId, String networkName) { + CreateNsxTier1GatewayCommand createNsxTier1GatewayCommand = + new CreateNsxTier1GatewayCommand(domainId, accountId, zoneId, networkId, networkName, false, false); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(createNsxTier1GatewayCommand, zoneId); + return result.getResult(); + } + + public boolean deleteVpcNetwork(Long zoneId, long accountId, long domainId, Long vpcId, String vpcName) { + DeleteNsxTier1GatewayCommand deleteNsxTier1GatewayCommand = + new DeleteNsxTier1GatewayCommand(domainId, accountId, zoneId, vpcId, vpcName, true); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(deleteNsxTier1GatewayCommand, zoneId); + return result.getResult(); + } + + public boolean deleteNetwork(long zoneId, long accountId, long domainId, NetworkVO network) { + String vpcName = null; + if (Objects.nonNull(network.getVpcId())) { + VpcVO vpc = vpcDao.findById(network.getVpcId()); + vpcName = Objects.nonNull(vpc) ? vpc.getName() : null; + } + DeleteNsxSegmentCommand deleteNsxSegmentCommand = new DeleteNsxSegmentCommand(domainId, accountId, zoneId, + network.getVpcId(), vpcName, network.getId(), network.getName()); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(deleteNsxSegmentCommand, network.getDataCenterId()); + if (!result.getResult()) { + String msg = String.format("Could not remove the NSX segment for network %s: %s", network.getName(), result.getDetails()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + + if (Objects.isNull(network.getVpcId())) { + DeleteNsxTier1GatewayCommand deleteNsxTier1GatewayCommand = new DeleteNsxTier1GatewayCommand(domainId, accountId, zoneId, network.getId(), network.getName(), false); + result = nsxControllerUtils.sendNsxCommand(deleteNsxTier1GatewayCommand, zoneId); + } + return result.getResult(); + } + + public boolean createStaticNatRule(long zoneId, long domainId, long accountId, Long networkResourceId, String networkResourceName, + boolean isVpcResource, long vmId, String publicIp, String vmIp) { + CreateNsxStaticNatCommand createNsxStaticNatCommand = new CreateNsxStaticNatCommand(domainId, accountId, zoneId, + networkResourceId, networkResourceName, isVpcResource, vmId, publicIp, vmIp); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(createNsxStaticNatCommand, zoneId); + return result.getResult(); + } + + public boolean deleteStaticNatRule(long zoneId, long domainId, long accountId, Long networkResourceId, String networkResourceName, + boolean isVpcResource) { + DeleteNsxNatRuleCommand deleteNsxStaticNatCommand = new DeleteNsxNatRuleCommand(domainId, accountId, zoneId, + networkResourceId, networkResourceName, isVpcResource, null, null, null, null); + deleteNsxStaticNatCommand.setService(Network.Service.StaticNat); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(deleteNsxStaticNatCommand, zoneId); + return result.getResult(); + } + + public NsxAnswer createPortForwardRule(NsxNetworkRule netRule) { + // TODO: if port doesn't exist in default list of services, create a service entry + CreateNsxPortForwardRuleCommand createPortForwardCmd = new CreateNsxPortForwardRuleCommand(netRule.getDomainId(), + netRule.getAccountId(), netRule.getZoneId(), netRule.getNetworkResourceId(), + netRule.getNetworkResourceName(), netRule.isVpcResource(), netRule.getVmId(), netRule.getRuleId(), + netRule.getPublicIp(), netRule.getVmIp(), netRule.getPublicPort(), netRule.getPrivatePort(), netRule.getProtocol()); + return nsxControllerUtils.sendNsxCommand(createPortForwardCmd, netRule.getZoneId()); + } + + public boolean deletePortForwardRule(NsxNetworkRule netRule) { + DeleteNsxNatRuleCommand deleteCmd = new DeleteNsxNatRuleCommand(netRule.getDomainId(), + netRule.getAccountId(), netRule.getZoneId(), netRule.getNetworkResourceId(), + netRule.getNetworkResourceName(), netRule.isVpcResource(), netRule.getVmId(), netRule.getRuleId(), netRule.getPrivatePort(), netRule.getProtocol()); + deleteCmd.setService(Network.Service.PortForwarding); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(deleteCmd, netRule.getZoneId()); + return result.getResult(); + } + + public boolean createLbRule(NsxNetworkRule netRule) { + CreateNsxLoadBalancerRuleCommand command = new CreateNsxLoadBalancerRuleCommand(netRule.getDomainId(), + netRule.getAccountId(), netRule.getZoneId(), netRule.getNetworkResourceId(), + netRule.getNetworkResourceName(), netRule.isVpcResource(), netRule.getMemberList(), netRule.getRuleId(), + netRule.getPublicPort(), netRule.getPrivatePort(), netRule.getAlgorithm(), netRule.getProtocol()); + command.setPublicIp(netRule.getPublicIp()); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(command, netRule.getZoneId()); + return result.getResult(); + } + + public boolean deleteLbRule(NsxNetworkRule netRule) { + DeleteNsxLoadBalancerRuleCommand command = new DeleteNsxLoadBalancerRuleCommand(netRule.getDomainId(), + netRule.getAccountId(), netRule.getZoneId(), netRule.getNetworkResourceId(), + netRule.getNetworkResourceName(), netRule.isVpcResource(), netRule.getMemberList(), netRule.getRuleId(), + netRule.getVmId()); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(command, netRule.getZoneId()); + return result.getResult(); + } + + public boolean addFirewallRules(Network network, List netRules) { + CreateNsxDistributedFirewallRulesCommand command = new CreateNsxDistributedFirewallRulesCommand(network.getDomainId(), + network.getAccountId(), network.getDataCenterId(), network.getVpcId(), network.getId(), netRules); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(command, network.getDataCenterId()); + return result.getResult(); + } + + public boolean deleteFirewallRules(Network network, List netRules) { + DeleteNsxDistributedFirewallRulesCommand command = new DeleteNsxDistributedFirewallRulesCommand(network.getDomainId(), + network.getAccountId(), network.getDataCenterId(), network.getVpcId(), network.getId(), netRules); + NsxAnswer result = nsxControllerUtils.sendNsxCommand(command, network.getDataCenterId()); + return result.getResult(); + } + + @Override + public String getConfigComponentName() { + return NsxApiClient.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] { + NSX_API_FAILURE_RETRIES, NSX_API_FAILURE_INTERVAL + }; + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/utils/NsxControllerUtils.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/utils/NsxControllerUtils.java new file mode 100644 index 000000000000..f44364f34c8b --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/utils/NsxControllerUtils.java @@ -0,0 +1,151 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.utils; + +import com.cloud.agent.AgentManager; +import com.cloud.agent.api.Answer; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.dao.NsxProviderDao; +import com.cloud.network.element.NsxProviderVO; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.NsxCommand; +import org.apache.cloudstack.service.NsxApiClient; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; + +import static java.util.Objects.isNull; + +@Component +public class NsxControllerUtils { + protected Logger logger = LogManager.getLogger(getClass()); + + @Inject + private AgentManager agentMgr; + @Inject + private NsxProviderDao nsxProviderDao; + + public static String getNsxNatRuleId(long domainId, long accountId, long dataCenterId, long resourceId, boolean isForVpc) { + String resourcePrefix = isForVpc ? "V" : "N"; + return String.format("D%s-A%s-Z%s-%s%s-NAT", domainId, accountId, dataCenterId, resourcePrefix, resourceId); + } + + public static String getNsxDistributedFirewallPolicyRuleId(String segmentName, long ruleId) { + return String.format("%s-R%s", segmentName, ruleId); + } + + public NsxAnswer sendNsxCommand(NsxCommand cmd, long zoneId) throws IllegalArgumentException { + NsxProviderVO nsxProviderVO = nsxProviderDao.findByZoneId(zoneId); + if (nsxProviderVO == null) { + logger.error("No NSX controller was found!"); + throw new InvalidParameterValueException("Failed to find an NSX controller"); + } + Answer answer = agentMgr.easySend(nsxProviderVO.getHostId(), cmd); + + if (answer == null || !answer.getResult()) { + logger.error("NSX API Command failed"); + throw new InvalidParameterValueException("Failed API call to NSX controller"); + } + + return (NsxAnswer) answer; + } + + /** + * Generates the Tier 1 Gateway name and identifier for the resource on the NSX manager + */ + public static String getTier1GatewayName(long domainId, long accountId, long zoneId, + Long networkResourceId, boolean isResourceVpc) { + String resourcePrefix = isResourceVpc ? "V" : "N"; + return String.format("D%s-A%s-Z%s-%s%s", domainId, accountId, zoneId, resourcePrefix, networkResourceId); + } + + public static String getNsxSegmentId(long domainId, long accountId, long zoneId, Long vpcId, long networkId) { + String segmentName = String.format("D%s-A%s-Z%s", domainId, accountId, zoneId); + if (isNull(vpcId)) { + return String.format("%s-S%s", segmentName, networkId); + } + return String.format("%s-V%s-S%s",segmentName, vpcId, networkId); + } + + public static String getNsxDhcpRelayConfigId(long zoneId, long domainId, long accountId, Long vpcId, long networkId) { + String suffix = "Relay"; + if (isNull(vpcId)) { + return String.format("D%s-A%s-Z%s-S%s-%s", domainId, accountId, zoneId, networkId, suffix); + } + return String.format("D%s-A%s-Z%s-V%s-S%s-%s", domainId, accountId, zoneId, vpcId, networkId, suffix); + } + + public static String getStaticNatRuleName(long domainId, long accountId, long zoneId, Long networkResourceId, boolean isVpcResource) { + String suffix = "-STATICNAT"; + return getTier1GatewayName(domainId, accountId, zoneId, networkResourceId, isVpcResource) + suffix; + } + + public static String getPortForwardRuleName(long domainId, long accountId, long zoneId, Long networkResourceId, long ruleId, boolean isVpcResource) { + String suffix = "-PF"; + return getTier1GatewayName(domainId, accountId, zoneId, networkResourceId, isVpcResource) + suffix + ruleId; + } + + public static String getServiceName(String ruleName, String port, String protocol, Integer icmpType, Integer icmpCode) { + return protocol.equalsIgnoreCase("icmp") ? + String.format("%s-SVC-%s-%s-%s", ruleName, icmpType, icmpCode, protocol) : + String.format("%s-SVC-%s-%s", ruleName, port, protocol); + } + + public static String getServiceEntryName(String ruleName, String port, String protocol) { + return ruleName + "-SE-" + port + "-" + protocol; + } + + public static String getLoadBalancerName(String tier1GatewayName) { + return tier1GatewayName + "-LB"; + } + + public static String getLoadBalancerRuleName(String tier1GatewayName, long lbId) { + return tier1GatewayName + "-LB" + lbId; + } + + public static String getServerPoolName(String tier1GatewayName, long lbId) { + return getLoadBalancerRuleName(tier1GatewayName, lbId) + "-SP"; + } + + public static String getActiveMonitorProfileName(String lbServerPoolName, String port, String protocol) { + if (protocol.equalsIgnoreCase("udp")) { + protocol = "ICMP"; + } + return lbServerPoolName + "-" + protocol + "-" + port + "-AM"; + } + + public static String getVirtualServerName(String tier1GatewayName, long lbId) { + return getLoadBalancerRuleName(tier1GatewayName, lbId) + "-VS"; + } + + public static String getServerPoolMemberName(String tier1GatewayName, long vmId) { + return tier1GatewayName + "-VM" + vmId; + } + + public static String getLoadBalancerAlgorithm(String algorithm) { + switch (algorithm) { + case "leastconn": + return NsxApiClient.LBAlgorithm.LEAST_CONNECTION.name(); + case "source": + return NsxApiClient.LBAlgorithm.IP_HASH.name(); + default: + return NsxApiClient.LBAlgorithm.ROUND_ROBIN.name(); + } + } +} diff --git a/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/utils/NsxHelper.java b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/utils/NsxHelper.java new file mode 100644 index 000000000000..b0668a0704f9 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/java/org/apache/cloudstack/utils/NsxHelper.java @@ -0,0 +1,53 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.utils; + +import com.cloud.dc.DataCenter; +import com.cloud.domain.DomainVO; +import com.cloud.network.Network; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.vpc.VpcVO; +import com.cloud.user.Account; +import org.apache.cloudstack.agent.api.CreateNsxDhcpRelayConfigCommand; +import org.apache.cloudstack.agent.api.CreateNsxSegmentCommand; +import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand; + +import java.util.List; + +public class NsxHelper { + + private NsxHelper() { + } + + public static CreateNsxDhcpRelayConfigCommand createNsxDhcpRelayConfigCommand(DomainVO domain, Account account, DataCenter zone, VpcVO vpc, Network network, List addresses) { + Long vpcId = vpc != null ? vpc.getId() : null; + String vpcName = vpc != null ? vpc.getName() : null; + return new CreateNsxDhcpRelayConfigCommand(domain.getId(), account.getId(), zone.getId(), + vpcId, vpcName, network.getId(), network.getName(), addresses); + } + + public static CreateNsxSegmentCommand createNsxSegmentCommand(DomainVO domain, Account account, DataCenter zone, String vpcName, NetworkVO networkVO) { + return new CreateNsxSegmentCommand(domain.getId(), account.getId(), zone.getId(), + networkVO.getVpcId(), vpcName, networkVO.getId(), networkVO.getName(), networkVO.getGateway(), networkVO.getCidr()); + } + + public static CreateOrUpdateNsxTier1NatRuleCommand createOrUpdateNsxNatRuleCommand(long domainId, long accountId, long zoneId, + String tier1Gateway, String action, String ipAddress, + String natRuleId) { + return new CreateOrUpdateNsxTier1NatRuleCommand(domainId, accountId, zoneId, tier1Gateway, action, ipAddress, natRuleId); + } +} diff --git a/plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/core/spring-nsx-core-managers-context.xml b/plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/core/spring-nsx-core-managers-context.xml new file mode 100644 index 000000000000..7010b8c07f44 --- /dev/null +++ b/plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/core/spring-nsx-core-managers-context.xml @@ -0,0 +1,32 @@ + + + + + + + diff --git a/packaging/centos8/cloudstack-sccs b/plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/nsx/module.properties similarity index 92% rename from packaging/centos8/cloudstack-sccs rename to plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/nsx/module.properties index e05d372c7fe4..1630826d102d 100644 --- a/packaging/centos8/cloudstack-sccs +++ b/plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/nsx/module.properties @@ -1,5 +1,4 @@ -#!/bin/sh - +# # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -16,5 +15,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +# -cat /usr/share/cloudstack-common/scripts/gitrev.txt +name=nsx +parent=network diff --git a/plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/nsx/spring-nsx-context.xml b/plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/nsx/spring-nsx-context.xml new file mode 100644 index 000000000000..d5e3e212de1c --- /dev/null +++ b/plugins/network-elements/nsx/src/main/resources/META-INF/cloudstack/nsx/spring-nsx-context.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + diff --git a/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/resource/NsxResourceTest.java b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/resource/NsxResourceTest.java new file mode 100644 index 000000000000..ee4f4fb64c20 --- /dev/null +++ b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/resource/NsxResourceTest.java @@ -0,0 +1,293 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.resource; + +import com.cloud.network.dao.NetworkVO; +import com.cloud.utils.exception.CloudRuntimeException; +import com.vmware.nsx.model.TransportZone; +import com.vmware.nsx.model.TransportZoneListResult; +import com.vmware.nsx_policy.model.EnforcementPoint; +import com.vmware.nsx_policy.model.Site; +import junit.framework.Assert; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.CreateNsxDistributedFirewallRulesCommand; +import org.apache.cloudstack.agent.api.CreateNsxLoadBalancerRuleCommand; +import org.apache.cloudstack.agent.api.CreateNsxPortForwardRuleCommand; +import org.apache.cloudstack.agent.api.CreateNsxSegmentCommand; +import org.apache.cloudstack.agent.api.CreateNsxStaticNatCommand; +import org.apache.cloudstack.agent.api.CreateNsxTier1GatewayCommand; +import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxDistributedFirewallRulesCommand; +import org.apache.cloudstack.agent.api.DeleteNsxNatRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxSegmentCommand; +import org.apache.cloudstack.agent.api.DeleteNsxTier1GatewayCommand; +import org.apache.cloudstack.agent.api.NsxCommand; +import org.apache.cloudstack.service.NsxApiClient; +import org.apache.cloudstack.utils.NsxControllerUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; + +import javax.naming.ConfigurationException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class NsxResourceTest { + + @Mock + NsxApiClient nsxApi; + + NsxResource nsxResource; + AutoCloseable closeable; + @Mock + TransportZoneListResult transportZoneListResult; + + private static final String transportZone = "Overlay"; + private static final String tier0Gateway = "Tier0-GW01"; + private static final String edgeCluster = "EdgeCluster"; + + private static final long domainId = 1L; + private static final long accountId = 2L; + private static final long zoneId = 1L; + + @Before + public void setup() { + closeable = MockitoAnnotations.openMocks(this); + nsxResource = new NsxResource(); + nsxResource.nsxApiClient = nsxApi; + nsxResource.transportZone = transportZone; + nsxResource.tier0Gateway = tier0Gateway; + nsxResource.edgeCluster = edgeCluster; + } + + @After + public void tearDown() throws Exception { + closeable.close(); + } + + @Test + public void testConfigure() throws ConfigurationException { + Map params = new HashMap<>(); + params.put("name", "nsxController"); + params.put("guid", "5944b356-644f-11ee-b8c2-f37bc1b564ff"); + params.put("zoneId", "1"); + params.put("hostname", "host1"); + params.put("username", "admin"); + params.put("password", "password"); + params.put("tier0Gateway", tier0Gateway); + params.put("edgeCluster", edgeCluster); + params.put("transportZone", transportZone); + params.put("port", "443"); + + Assert.assertTrue(nsxResource.configure("nsx", params)); + } + + @Test + public void testConfigure_MissingParameter() throws ConfigurationException { + Map params = new HashMap<>(); + + assertThrows(ConfigurationException.class, () -> nsxResource.configure("nsx", params)); + } + + @Test + public void testCreateNsxTier1Gateway() { + NsxCommand command = new CreateNsxTier1GatewayCommand(domainId, accountId, zoneId, + 3L, "VPC01", true, false); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertTrue(answer.getResult()); + } + + @Test + public void testCreateNsxTier1GatewayError() { + NsxCommand command = new CreateNsxTier1GatewayCommand(domainId, accountId, zoneId, + 3L, "VPC01", true, false); + Mockito.doThrow(new CloudRuntimeException("ERROR")) + .when(nsxApi).createTier1Gateway(anyString(), anyString(), anyString(), anyBoolean()); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertFalse(answer.getResult()); + } + + @Test + public void testDeleteTier1Gateway() { + NsxCommand command = new DeleteNsxTier1GatewayCommand(domainId, accountId, zoneId, + 2L, "VPC01", true); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertTrue(answer.getResult()); + } + + @Test + public void testDeleteTier1GatewayError() { + NsxCommand command = new DeleteNsxTier1GatewayCommand(domainId, accountId, zoneId, + 2L, "VPC01", true); + Mockito.doThrow(new CloudRuntimeException("ERROR")).when(nsxApi).deleteTier1Gateway(anyString()); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertFalse(answer.getResult()); + } + + @Test + public void testCreateNsxSegment() { + NetworkVO tierNetwork = new NetworkVO(); + tierNetwork.setName("tier1"); + tierNetwork.setCidr("10.0.0.0/8"); + tierNetwork.setGateway("10.0.0.1"); + Site site = mock(Site.class); + List siteList = List.of(site); + EnforcementPoint enforcementPoint = mock(EnforcementPoint.class); + List enforcementPointList = List.of(enforcementPoint); + List transportZoneList = List.of(new TransportZone.Builder().setDisplayName(transportZone).build()); + + NsxCommand command = new CreateNsxSegmentCommand(domainId, accountId, zoneId, + 2L, "VPC01", 3L, "Web", "10.10.10.1", "10.10.10.0/24"); + + when(nsxApi.getDefaultSiteId()).thenReturn("site1"); + + when(nsxApi.getDefaultEnforcementPointPath(anyString())).thenReturn("enforcementPointPath"); + + when(nsxApi.getTransportZones()).thenReturn(transportZoneListResult); + when(transportZoneListResult.getResults()).thenReturn(transportZoneList); + + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertTrue(answer.getResult()); + } + + @Test + public void testCreateNsxSegmentEmptySites() { + when(nsxApi.getDefaultSiteId()).thenReturn(null); + CreateNsxSegmentCommand command = Mockito.mock(CreateNsxSegmentCommand.class); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertFalse(answer.getResult()); + } + + @Test + public void testCreateNsxSegmentEmptyEnforcementPoints() { + Site site = mock(Site.class); + when(nsxApi.getDefaultSiteId()).thenReturn("site1"); + when(nsxApi.getDefaultEnforcementPointPath(anyString())).thenReturn(null); + CreateNsxSegmentCommand command = Mockito.mock(CreateNsxSegmentCommand.class); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertFalse(answer.getResult()); + } + + @Test + public void testCreateNsxSegmentEmptyTransportZones() { + Site site = mock(Site.class); + when(nsxApi.getDefaultSiteId()).thenReturn("site1"); + CreateNsxSegmentCommand command = Mockito.mock(CreateNsxSegmentCommand.class); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertFalse(answer.getResult()); + } + + @Test + public void testDeleteNsxSegment() { + NetworkVO tierNetwork = new NetworkVO(); + tierNetwork.setName("tier1"); + DeleteNsxSegmentCommand command = new DeleteNsxSegmentCommand(domainId, accountId, zoneId, + 3L, "VPC01", 2L, "Web"); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertTrue(answer.getResult()); + } + + @Test + public void testDeleteNsxSegmentError() { + NetworkVO tierNetwork = new NetworkVO(); + tierNetwork.setName("tier1"); + DeleteNsxSegmentCommand command = new DeleteNsxSegmentCommand(domainId, accountId, zoneId, + 3L, "VPC01", 2L, "Web"); + doThrow(new CloudRuntimeException("ERROR")).when(nsxApi).deleteSegment(anyLong(), anyLong(), anyLong(), anyLong(), anyLong(), anyString()); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertFalse(answer.getResult()); + } + + @Test + public void testCreateStaticNat() { + CreateNsxStaticNatCommand cmd = new CreateNsxStaticNatCommand(domainId, accountId, zoneId, 3L, "VPC01", true, 2L, "10.1.12.10", "172.30.20.12"); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(cmd); + assertTrue(answer.getResult()); + } + + @Test + public void testCreatePortForwardRule() { + CreateNsxPortForwardRuleCommand cmd = new CreateNsxPortForwardRuleCommand(domainId, accountId, zoneId, 3L, "VPC01", true, 2L, 5L, "10.1.12.10", "172.30.20.12", "2222", "22", "tcp"); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(cmd); + assertTrue(answer.getResult()); + } + + @Test + public void testDeleteNsxNatRule() { + DeleteNsxNatRuleCommand cmd = new DeleteNsxNatRuleCommand(domainId, accountId, zoneId, 3L, "VPC01", true, 2L, 5L, "22", "tcp"); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(cmd); + assertTrue(answer.getResult()); + } + + @Test + public void testCreateNsxLoadBalancerRule() { + List loadBalancerMembers = List.of(new NsxLoadBalancerMember( + 1L, "172.30.20.12", 6443 + )); + CreateNsxLoadBalancerRuleCommand cmd = new CreateNsxLoadBalancerRuleCommand(domainId, accountId, zoneId, + 3L, "VPC01", true, loadBalancerMembers, 1L, "6443", "6443", "RoundRobin", "TCP"); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(cmd); + assertTrue(answer.getResult()); + } + + + @Test + public void testCreateNsxDistributedFirewallRule() { + List networkRules = List.of(new NsxNetworkRule()); + CreateNsxDistributedFirewallRulesCommand cmd = new CreateNsxDistributedFirewallRulesCommand(domainId, accountId, zoneId, + 3L, 1L, networkRules); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(cmd); + assertTrue(answer.getResult()); + } + + @Test + public void testDeleteNsxDistributedFirewallRule() { + List networkRules = List.of(new NsxNetworkRule()); + DeleteNsxDistributedFirewallRulesCommand cmd = new DeleteNsxDistributedFirewallRulesCommand(domainId, accountId, zoneId, + 3L, 1L, networkRules); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(cmd); + assertTrue(answer.getResult()); + } + + @Test + public void testCreateTier1NatRule() { + long vpcId = 5L; + String tier1GatewayName = NsxControllerUtils.getTier1GatewayName(domainId, accountId, zoneId, vpcId, true); + CreateOrUpdateNsxTier1NatRuleCommand command = new CreateOrUpdateNsxTier1NatRuleCommand(domainId, accountId, zoneId, + tier1GatewayName, "SNAT", "10.1.10.10", "natRuleId"); + NsxAnswer answer = (NsxAnswer) nsxResource.executeRequest(command); + assertTrue(answer.getResult()); + } +} diff --git a/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxApiClientTest.java b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxApiClientTest.java new file mode 100644 index 000000000000..fbcca86a28b4 --- /dev/null +++ b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxApiClientTest.java @@ -0,0 +1,111 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.network.Network; +import com.vmware.nsx.cluster.Status; +import com.vmware.nsx.model.ClusterStatus; +import com.vmware.nsx.model.ControllerClusterStatus; +import com.vmware.nsx_policy.infra.domains.Groups; +import com.vmware.nsx_policy.model.Group; +import com.vmware.nsx_policy.model.PathExpression; +import com.vmware.vapi.bindings.Service; +import org.apache.cloudstack.resource.NsxNetworkRule; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockedConstruction; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import java.util.List; +import java.util.function.Function; + +public class NsxApiClientTest { + + @Mock + private Function, Service> nsxService; + @Mock + private Groups groupService; + + private NsxApiClient client = new NsxApiClient(); + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + client.nsxService = nsxService; + Mockito.when(nsxService.apply(Groups.class)).thenReturn(groupService); + } + + @Test + public void testCreateGroupForSegment() { + final Group[] groups = new Group[1]; + final PathExpression[] pathExpressions = new PathExpression[1]; + try (MockedConstruction ignored = Mockito.mockConstruction(Group.class, (mock, context) -> { + groups[0] = mock; + }); MockedConstruction ignoredExp = Mockito.mockConstruction(PathExpression.class, (mock, context) -> { + pathExpressions[0] = mock; + }) + ) { + String segmentName = "segment1"; + client.createGroupForSegment(segmentName); + Mockito.verify(groupService).patch(NsxApiClient.DEFAULT_DOMAIN, segmentName, groups[0]); + String segmentPath = String.format("%s/%s", NsxApiClient.SEGMENTS_PATH, segmentName); + Mockito.verify(groups[0]).setExpression(List.of(pathExpressions[0])); + Mockito.verify(pathExpressions[0]).setPaths(List.of(segmentPath)); + } + } + + @Test + public void testGetGroupsForTrafficIngress() { + NsxNetworkRule rule = Mockito.mock(NsxNetworkRule.class); + Mockito.when(rule.getSourceCidrList()).thenReturn(List.of("ANY")); + Mockito.when(rule.getTrafficType()).thenReturn("Ingress"); + Mockito.when(rule.getService()).thenReturn(Network.Service.NetworkACL); + String segmentName = "segment"; + List sourceGroups = client.getGroupsForTraffic(rule, segmentName, true); + List destinationGroups = client.getGroupsForTraffic(rule, segmentName, false); + Assert.assertEquals(List.of("ANY"), sourceGroups); + Assert.assertEquals(List.of(String.format("%s/%s", NsxApiClient.GROUPS_PATH_PREFIX, segmentName)), destinationGroups); + } + + @Test + public void testGetGroupsForTrafficEgress() { + NsxNetworkRule rule = Mockito.mock(NsxNetworkRule.class); + Mockito.when(rule.getSourceCidrList()).thenReturn(List.of("ANY")); + Mockito.when(rule.getTrafficType()).thenReturn("Egress"); + Mockito.when(rule.getService()).thenReturn(Network.Service.NetworkACL); + String segmentName = "segment"; + List sourceGroups = client.getGroupsForTraffic(rule, segmentName, true); + List destinationGroups = client.getGroupsForTraffic(rule, segmentName, false); + Assert.assertEquals(List.of(String.format("%s/%s", NsxApiClient.GROUPS_PATH_PREFIX, segmentName)), sourceGroups); + Assert.assertEquals(List.of("ANY"), destinationGroups); + } + + @Test + public void testIsNsxControllerActive() { + Status statusService = Mockito.mock(Status.class); + Mockito.when(nsxService.apply(Status.class)).thenReturn(statusService); + ClusterStatus clusterStatus = Mockito.mock(ClusterStatus.class); + ControllerClusterStatus status = Mockito.mock(ControllerClusterStatus.class); + Mockito.when(status.getStatus()).thenReturn("stable"); + Mockito.when(statusService.get()).thenReturn(clusterStatus); + Mockito.when(clusterStatus.getControlClusterStatus()).thenReturn(status); + Assert.assertTrue(client.isNsxControllerActive()); + } +} diff --git a/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxElementTest.java b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxElementTest.java new file mode 100644 index 000000000000..7c44a7324fbe --- /dev/null +++ b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxElementTest.java @@ -0,0 +1,497 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.api.ApiDBUtils; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.deploy.DeployDestination; +import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.hypervisor.Hypervisor; +import com.cloud.network.Network; +import com.cloud.network.NetworkModel; +import com.cloud.network.Networks; +import com.cloud.network.dao.IPAddressDao; +import com.cloud.network.dao.IPAddressVO; +import com.cloud.network.dao.LoadBalancerVMMapDao; +import com.cloud.network.dao.LoadBalancerVO; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.dao.PhysicalNetworkVO; +import com.cloud.network.lb.LoadBalancingRule; +import com.cloud.network.rules.FirewallRule; +import com.cloud.network.rules.FirewallRuleVO; +import com.cloud.network.rules.PortForwardingRule; +import com.cloud.network.rules.PortForwardingRuleVO; +import com.cloud.network.rules.StaticNatImpl; +import com.cloud.network.vpc.NetworkACLItem; +import com.cloud.network.vpc.NetworkACLItemVO; +import com.cloud.network.vpc.Vpc; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao; +import com.cloud.resource.ResourceManager; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.utils.Pair; +import com.cloud.utils.net.Ip; +import com.cloud.vm.NicVO; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.dao.UserVmDao; +import com.cloud.vm.dao.VMInstanceDao; +import org.apache.cloudstack.acl.ControlledEntity; +import org.apache.cloudstack.resource.NsxNetworkRule; +import org.apache.cloudstack.resourcedetail.dao.FirewallRuleDetailsDao; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class NsxElementTest { + + @Mock + DataCenterDao dataCenterDao; + @Mock + NsxServiceImpl nsxService; + @Mock + AccountManager accountManager; + @Mock + NetworkDao networkDao; + @Mock + ResourceManager resourceManager; + @Mock + PhysicalNetworkDao physicalNetworkDao; + @Mock + NetworkModel networkModel; + @Mock + Vpc vpc; + @Mock + DataCenterVO zone; + @Mock + DataCenterVO dataCenterVO; + @Mock + Account account; + @Mock + DomainVO domain; + @Mock + IPAddressDao ipAddressDao; + @Mock + VMInstanceDao vmInstanceDao; + @Mock + VpcDao vpcDao; + @Mock + UserVmDao userVmDao; + @Mock + private VpcOfferingServiceMapDao vpcOfferingServiceMapDao; + @Mock + LoadBalancerVMMapDao lbVmMapDao; + @Mock + FirewallRuleDetailsDao firewallRuleDetailsDao; + + NsxElement nsxElement; + ReservationContext reservationContext; + DeployDestination deployDestination; + @Mock + DomainDao domainDao; + + @Before + public void setup() throws NoSuchFieldException, IllegalAccessException { + nsxElement = new NsxElement(); + + nsxElement.dataCenterDao = dataCenterDao; + nsxElement.nsxService = nsxService; + nsxElement.accountMgr = accountManager; + nsxElement.networkDao = networkDao; + nsxElement.resourceManager = resourceManager; + nsxElement.physicalNetworkDao = physicalNetworkDao; + nsxElement.domainDao = domainDao; + nsxElement.networkModel = networkModel; + nsxElement.vpcOfferingServiceMapDao = vpcOfferingServiceMapDao; + nsxElement.ipAddressDao = ipAddressDao; + nsxElement.vmInstanceDao = vmInstanceDao; + nsxElement.vpcDao = vpcDao; + nsxElement.lbVmMapDao = lbVmMapDao; + nsxElement.firewallRuleDetailsDao = firewallRuleDetailsDao; + + Field field = ApiDBUtils.class.getDeclaredField("s_ipAddressDao"); + field.setAccessible(true); + field.set(null, ipAddressDao); + + field = ApiDBUtils.class.getDeclaredField("s_userVmDao"); + field.setAccessible(true); + field.set(null, userVmDao); + reservationContext = mock(ReservationContext.class); + deployDestination = mock(DeployDestination.class); + + when(vpc.getZoneId()).thenReturn(1L); + when(vpc.getAccountId()).thenReturn(2L); + when(dataCenterVO.getId()).thenReturn(1L); + when(vpc.getName()).thenReturn("VPC01"); + when(accountManager.getAccount(2L)).thenReturn(account); + when(dataCenterDao.findById(anyLong())).thenReturn(dataCenterVO); + when(domainDao.findById(anyLong())).thenReturn(domain); + when(vpc.getZoneId()).thenReturn(1L); + when(vpc.getName()).thenReturn("testVPC"); + + PhysicalNetworkVO physicalNetworkVO = new PhysicalNetworkVO(); + physicalNetworkVO.setIsolationMethods(List.of("NSX")); + List physicalNetworkVOList = List.of(physicalNetworkVO); + + when(physicalNetworkDao.listByZoneAndTrafficType(1L, Networks.TrafficType.Guest)).thenReturn(physicalNetworkVOList); + } + + @Test + public void testImplementVpc() throws ResourceUnavailableException, InsufficientCapacityException { + assertTrue(nsxElement.implementVpc(vpc, deployDestination, reservationContext)); + } + + @Test + public void testShutdownVpc() { + when(nsxService.deleteVpcNetwork(anyLong(), anyLong(), anyLong(), anyLong(), anyString())).thenReturn(true); + + assertTrue(nsxElement.shutdownVpc(vpc, reservationContext)); + } + + @Test + public void testTransformActionValue() { + NsxNetworkRule.NsxRuleAction action = nsxElement.transformActionValue(NetworkACLItem.Action.Deny); + Assert.assertEquals(NsxNetworkRule.NsxRuleAction.DROP, action); + } + + @Test + public void testTransformCidrListValuesEmptyList() { + List values = nsxElement.transformCidrListValues(null); + Assert.assertNotNull(values); + Assert.assertTrue(values.isEmpty()); + } + + @Test + public void testTransformCidrListValuesList() { + List values = nsxElement.transformCidrListValues(List.of("0.0.0.0/0")); + Assert.assertEquals(1, values.size()); + Assert.assertEquals("ANY", values.get(0)); + } + + @Test + public void testCanHandleService() { + when(networkModel.isProviderForNetwork(any(Network.Provider.class), anyLong())).thenReturn(true); + + Network.Service service = new Network.Service("service1", new Network.Capability("capability")); + NetworkVO network = new NetworkVO(); + network.setName("network1"); + assertTrue(nsxElement.canHandle(network, service)); + } + + @Test + public void testApplyStaticNatRules() throws ResourceUnavailableException { + StaticNatImpl rule = new StaticNatImpl(1L , 1L, 3L, 7L, "172.30.10.15", false); + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + + Ip ip = new Ip("10.1.13.15"); + IPAddressVO ipAddress = new IPAddressVO(ip, 2L, 0xaabbccddeeffL, 3L, false); + ipAddress.setAssociatedWithVmId(10L); + + VMInstanceVO vm = new VMInstanceVO(10L, 9L, "vm1", "i-5-10-VM" , VirtualMachine.Type.User, + 18L, Hypervisor.HypervisorType.VMware, 26L, + 2L, 5L, 6L, false, false); + + NicVO nic = Mockito.mock(NicVO.class); + VpcVO vpc = Mockito.mock(VpcVO.class); + + when(ipAddressDao.findByIdIncludingRemoved(anyLong())).thenReturn(ipAddress); + when(vmInstanceDao.findByIdIncludingRemoved(anyLong())).thenReturn(vm); + when(networkModel.getNicInNetworkIncludingRemoved(anyLong(), anyLong())).thenReturn(nic); + when(vpcDao.findById(anyLong())).thenReturn(vpc); + when(vpc.getId()).thenReturn(1L); + when(vpc.getName()).thenReturn("vpc1"); + when(nsxService.createStaticNatRule(anyLong(), anyLong(), anyLong(), anyLong(), anyString(), anyBoolean(), anyLong(), anyString(), anyString())).thenReturn(true); + + assertTrue(nsxElement.applyStaticNats(networkVO, List.of(rule))); + } + + @Test + public void testApplyPFRules_add() throws ResourceUnavailableException { + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + PortForwardingRuleVO rule = new PortForwardingRuleVO("1", 11L, 80, 90, new Ip("172.30.10.11"), 8080, 8090, "tcp", 12L, + 5L, 2L, 15L); + rule.setState(FirewallRule.State.Add); + Network.Service service = new Network.Service("service1", new Network.Capability("capability")); + + when(nsxElement.canHandle(networkVO, service)).thenReturn(true); + assertTrue(nsxElement.applyPFRules(networkVO, List.of(rule))); + } + + @Test + public void testApplyPFRules_delete() throws ResourceUnavailableException { + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + PortForwardingRuleVO rule = new PortForwardingRuleVO("1", 11L, 80, 90, new Ip("172.30.10.11"), 8080, 8090, "tcp", 12L, + 5L, 2L, 15L); + rule.setState(FirewallRule.State.Revoke); + Network.Service service = new Network.Service("service1", new Network.Capability("capability")); + VpcVO vpcVO = Mockito.mock(VpcVO.class); + when(vpcDao.findById(1L)).thenReturn(vpcVO); + when(vpcVO.getDomainId()).thenReturn(2L); + IPAddressVO ipAddress = new IPAddressVO(new Ip("10.1.13.10"), 1L, 1L, 1L,false); + when(ApiDBUtils.findIpAddressById(anyLong())).thenReturn(ipAddress); + when(nsxElement.canHandle(networkVO, service)).thenReturn(true); + when(nsxService.deletePortForwardRule(any(NsxNetworkRule.class))).thenReturn(true); + assertTrue(nsxElement.applyPFRules(networkVO, List.of(rule))); + } + + @Test + public void testGetVpcOrNetworkReturnsVpcIfVpcIdPresent() { + VpcVO vpc = new VpcVO(); + when(vpcDao.findById(anyLong())).thenReturn(vpc); + + Pair vpcNetworkPair = nsxElement.getVpcOrNetwork(1L, 1L); + assertNotNull(vpcNetworkPair.first()); + assertNull(vpcNetworkPair.second()); + } + + @Test + public void testGetVpcOrNetworkReturnsNetworkIfVpcIdNotPresent() { + NetworkVO network = new NetworkVO(); + when(networkDao.findById(anyLong())).thenReturn(network); + + Pair vpcNetworkPair = nsxElement.getVpcOrNetwork(null, 1L); + assertNull(vpcNetworkPair.first()); + assertNotNull(vpcNetworkPair.second()); + } + + private Method getPublicPortRangeMethod() throws NoSuchMethodException { + Method method = NsxElement.class.getDeclaredMethod("getPublicPortRange", PortForwardingRule.class); + method.setAccessible(true); + return method; + } + + private Method getPrivatePFPortRangeMethod() throws NoSuchMethodException { + Method method = NsxElement.class.getDeclaredMethod("getPrivatePFPortRange", PortForwardingRule.class); + method.setAccessible(true); + return method; + } + + private Method getPrivatePortRangeMethod() throws NoSuchMethodException { + Method method = NsxElement.class.getDeclaredMethod("getPrivatePortRange", FirewallRule.class); + method.setAccessible(true); + return method; + } + + private Method getPrivatePortRangeForACLRuleMethod() throws NoSuchMethodException { + Method method = NsxElement.class.getDeclaredMethod("getPrivatePortRangeForACLRule", NetworkACLItem.class); + method.setAccessible(true); + return method; + } + + @Test + public void testGetPublicPortRangeWhenStartAndEndPortNumbersAreDifferent() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + PortForwardingRule rule = new PortForwardingRuleVO("1", 11L, 80, 90, new Ip("172.30.10.11"), 8080, 8090, "tcp", 12L, + 5L, 2L, 15L); + assertEquals("80-90", getPublicPortRangeMethod().invoke(null, rule)); + } + + @Test + public void testGetPublicPortRangeWhenStartAndEndPortNumbersAreSame() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + PortForwardingRule rule = new PortForwardingRuleVO("1", 11L, 80, 80, new Ip("172.30.10.11"), 8080, 8080, "tcp", 12L, + 5L, 2L, 15L); + assertEquals("80", getPublicPortRangeMethod().invoke(null, rule)); + } + + @Test + public void testGetPrivatePFPortRangeWhenStartAndEndPortNumbersAreDifferent() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + PortForwardingRule rule = new PortForwardingRuleVO("1", 11L, 80, 90, new Ip("172.30.10.11"), 8080, 8090, "tcp", 12L, + 5L, 2L, 15L); + assertEquals("8080-8090", getPrivatePFPortRangeMethod().invoke(null, rule)); + } + + @Test + public void testGetPrivatePFPortRangeWhenStartAndEndPortNumbersAreSame() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + PortForwardingRule rule = new PortForwardingRuleVO("1", 11L, 80, 80, new Ip("172.30.10.11"), 8080, 8080, "tcp", 12L, + 5L, 2L, 15L); + assertEquals("8080", getPrivatePFPortRangeMethod().invoke(null, rule)); + } + + @Test + public void testGetPrivatePortRangeWhenStartAndEndPortNumbersAreSame() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + FirewallRuleVO rule = new FirewallRuleVO("1", 11L, 80, 80, "tcp", 23L, 5L, 2L, + FirewallRule.Purpose.Firewall, List.of("172.30.10.0/24"), null, null, null, null, FirewallRule.TrafficType.Egress, FirewallRule.FirewallRuleType.User); + assertEquals("80", getPrivatePortRangeMethod().invoke(null, rule)); + } + + @Test + public void testGetPrivatePortRangeWhenStartAndEndPortNumbersAreDifferent() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + FirewallRuleVO rule = new FirewallRuleVO("1", 11L, 80, 90, "tcp", 23L, 5L, 2L, + FirewallRule.Purpose.Firewall, List.of("172.30.10.0/24"), null, null, null, null, FirewallRule.TrafficType.Egress, FirewallRule.FirewallRuleType.User); + assertEquals("80-90", getPrivatePortRangeMethod().invoke(null, rule)); + } + + @Test + public void testGetPrivatePortRangeForACLWhenStartAndEndPortNumbersAreSame() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + NetworkACLItem rule = new NetworkACLItemVO(80, 80, "udp", 10L, List.of("172.30.10.0/24"), null, null, NetworkACLItem.TrafficType.Ingress, NetworkACLItem.Action.Allow, + 2, null); + assertEquals("80", getPrivatePortRangeForACLRuleMethod().invoke(null, rule)); + } + + @Test + public void testGetPrivatePortRangeForACLWhenStartAndEndPortNumbersAreDifferent() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + NetworkACLItem rule = new NetworkACLItemVO(80, 90, "udp", 10L, List.of("172.30.10.0/24"), null, null, NetworkACLItem.TrafficType.Ingress, NetworkACLItem.Action.Allow, + 2, null); + assertEquals("80-90", getPrivatePortRangeForACLRuleMethod().invoke(null, rule)); + } + + @Test + public void testApplyLBRules_add() throws ResourceUnavailableException { + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + LoadBalancerVO lb = new LoadBalancerVO(null, null, null, 0L, 8080, 8081, null, 0L, 0L, 1L, null, null); + lb.setState(FirewallRule.State.Add); + LoadBalancingRule.LbDestination destination = new LoadBalancingRule.LbDestination(6443, 6443, "172.30.110.11", false); + LoadBalancingRule rule = new LoadBalancingRule(lb, List.of(destination), null, null, new Ip("10.1.13.10"), null, "TCP"); + + VpcVO vpc = Mockito.mock(VpcVO.class); + + IPAddressVO ipAddress = new IPAddressVO(new Ip("10.1.13.10"), 1L, 1L, 1L,false); + when(vpcDao.findById(anyLong())).thenReturn(vpc); + when(vpc.getDomainId()).thenReturn(2L); + when(vpc.getAccountId()).thenReturn(5L); + when(ipAddressDao.findByIpAndDcId(anyLong(), anyString())).thenReturn(ipAddress); + when(nsxService.createLbRule(any(NsxNetworkRule.class))).thenReturn(true); + + assertTrue(nsxElement.applyLBRules(networkVO, List.of(rule))); + } + + @Test + public void testApplyLBRules_delete() throws ResourceUnavailableException { + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + LoadBalancerVO lb = new LoadBalancerVO(null, null, null, 0L, 8080, 8081, null, 0L, 0L, 1L, null, null); + lb.setState(FirewallRule.State.Revoke); + LoadBalancingRule.LbDestination destination = new LoadBalancingRule.LbDestination(6443, 6443, "172.30.110.11", false); + LoadBalancingRule rule = new LoadBalancingRule(lb, List.of(destination), null, null, new Ip("10.1.13.10"), null, "TCP"); + + VpcVO vpc = Mockito.mock(VpcVO.class); + + IPAddressVO ipAddress = new IPAddressVO(new Ip("10.1.13.10"), 1L, 1L, 1L,false); + when(vpcDao.findById(anyLong())).thenReturn(vpc); + when(vpc.getDomainId()).thenReturn(2L); + when(vpc.getAccountId()).thenReturn(5L); + when(ipAddressDao.findByIpAndDcId(anyLong(), anyString())).thenReturn(ipAddress); + when(nsxService.deleteLbRule(any(NsxNetworkRule.class))).thenReturn(true); + + assertTrue(nsxElement.applyLBRules(networkVO, List.of(rule))); + } + + @Test + public void testApplyNetworkAclRules() throws ResourceUnavailableException { + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + NetworkACLItem rule = new NetworkACLItemVO(80, 80, "udp", 10L, List.of("172.30.10.0/24"), null, null, NetworkACLItem.TrafficType.Ingress, NetworkACLItem.Action.Allow, + 2, null); + Network.Service service = new Network.Service("service1", new Network.Capability("capability")); + + when(nsxElement.canHandle(networkVO, service)).thenReturn(true); + assertTrue(nsxElement.applyNetworkACLs(networkVO, List.of(rule))); + } + + @Test + public void testDeleteNetworkAclRules() throws ResourceUnavailableException { + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + NetworkACLItemVO rule = new NetworkACLItemVO(80, 80, "udp", 10L, List.of("172.30.10.0/24"), null, null, NetworkACLItem.TrafficType.Ingress, NetworkACLItem.Action.Allow, + 2, null); + rule.setState(NetworkACLItem.State.Revoke); + Network.Service service = new Network.Service("service1", new Network.Capability("capability")); + + when(nsxElement.canHandle(networkVO, service)).thenReturn(true); + when(nsxService.deleteFirewallRules(any(Network.class), any(List.class))).thenReturn(true); + assertTrue(nsxElement.applyNetworkACLs(networkVO, List.of(rule))); + } + + @Test + public void testApplyFirewallRules() throws ResourceUnavailableException { + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + FirewallRuleVO rule = new FirewallRuleVO("1", 11L, 80, 80, "tcp", 23L, 5L, 2L, + FirewallRule.Purpose.Firewall, List.of("172.30.10.0/24"), null, null, null, null, FirewallRule.TrafficType.Egress, FirewallRule.FirewallRuleType.User); + Network.Service service = new Network.Service("service1", new Network.Capability("capability")); + + when(nsxElement.canHandle(networkVO, service)).thenReturn(true); + when(nsxService.addFirewallRules(any(Network.class), any(List.class))).thenReturn(true); + assertTrue(nsxElement.applyFWRules(networkVO, List.of(rule))); + } + + @Test + public void testRevokeFirewallRules() throws ResourceUnavailableException { + NetworkVO networkVO = new NetworkVO(1L, Networks.TrafficType.Public, Networks.Mode.Static, + Networks.BroadcastDomainType.NSX, 12L, 2L, 5L, 1L, "network1", + "network1", null, Network.GuestType.Isolated, 2L, 2L, + ControlledEntity.ACLType.Domain, false, 1L, false ); + FirewallRuleVO rule = new FirewallRuleVO("1", 11L, 80, 80, "tcp", 23L, 5L, 2L, + FirewallRule.Purpose.Firewall, List.of("172.30.10.0/24"), null, null, null, null, FirewallRule.TrafficType.Egress, FirewallRule.FirewallRuleType.User); + rule.setState(FirewallRule.State.Revoke); + Network.Service service = new Network.Service("service1", new Network.Capability("capability")); + + when(nsxElement.canHandle(networkVO, service)).thenReturn(true); + when(nsxService.deleteFirewallRules(any(Network.class), any(List.class))).thenReturn(true); + when(nsxService.addFirewallRules(any(Network.class), any(List.class))).thenReturn(true); + assertTrue(nsxElement.applyFWRules(networkVO, List.of(rule))); + } +} diff --git a/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxGuestNetworkGuruTest.java b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxGuestNetworkGuruTest.java new file mode 100644 index 000000000000..cb79873f364d --- /dev/null +++ b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxGuestNetworkGuruTest.java @@ -0,0 +1,329 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.dc.DataCenter; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapacityException; +import com.cloud.network.IpAddressManager; +import com.cloud.network.Network; +import com.cloud.network.NetworkModel; +import com.cloud.network.Networks; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.dao.PhysicalNetworkVO; +import com.cloud.network.guru.GuestNetworkGuru; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.offering.NetworkOffering; +import com.cloud.offerings.NetworkOfferingVO; +import com.cloud.offerings.dao.NetworkOfferingDao; +import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; +import com.cloud.user.Account; +import com.cloud.user.AccountVO; +import com.cloud.user.dao.AccountDao; +import com.cloud.utils.Pair; +import com.cloud.vm.NicProfile; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.CreateNsxDhcpRelayConfigCommand; +import org.apache.cloudstack.agent.api.CreateNsxSegmentCommand; +import org.apache.cloudstack.agent.api.CreateNsxTier1GatewayCommand; +import org.apache.cloudstack.agent.api.NsxCommand; +import org.apache.cloudstack.utils.NsxControllerUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.List; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.lenient; + +@RunWith(MockitoJUnitRunner.class) +public class NsxGuestNetworkGuruTest { + + @Mock + PhysicalNetworkDao physicalNetworkDao; + @Mock + DataCenterDao dcDao; + @Mock + VpcDao vpcDao; + @Mock + NetworkOfferingServiceMapDao networkOfferingServiceMapDao; + @Mock + NsxControllerUtils nsxControllerUtils; + @Mock + AccountDao accountDao; + @Mock + PhysicalNetworkVO physicalNetwork; + @Mock + DataCenterVO dataCenterVO; + @Mock + NetworkOffering offering; + @Mock + DeploymentPlan plan; + @Mock + Network network; + @Mock + Account account; + @Mock + VpcVO vpcVO; + @Mock + NetworkModel networkModel; + @Mock + DomainDao domainDao; + @Mock + NetworkDao networkDao; + @Mock + IpAddressManager ipAddressManager; + @Mock + NetworkOfferingDao networkOfferingDao; + + NsxGuestNetworkGuru guru; + AutoCloseable closeable; + + @Before + public void setUp() throws IllegalAccessException, NoSuchFieldException { + closeable = MockitoAnnotations.openMocks(this); + guru = new NsxGuestNetworkGuru(); + + ReflectionTestUtils.setField(guru, "_dcDao", dcDao); + ReflectionTestUtils.setField(guru, "_networkDao", networkDao); + ReflectionTestUtils.setField(guru, "_networkModel", networkModel); + ReflectionTestUtils.setField(guru, "_vpcDao", vpcDao); + ReflectionTestUtils.setField((GuestNetworkGuru) guru, "_ipAddrMgr", ipAddressManager); + ReflectionTestUtils.setField((GuestNetworkGuru) guru, "_networkModel", networkModel); + ReflectionTestUtils.setField((GuestNetworkGuru) guru, "networkOfferingDao", networkOfferingDao); + ReflectionTestUtils.setField((GuestNetworkGuru) guru, "_physicalNetworkDao", physicalNetworkDao); + + guru.networkOfferingServiceMapDao = networkOfferingServiceMapDao; + guru.nsxControllerUtils = nsxControllerUtils; + guru.accountDao = accountDao; + guru.domainDao = domainDao; + + Mockito.when(dataCenterVO.getNetworkType()).thenReturn(DataCenter.NetworkType.Advanced); + + when(physicalNetwork.getIsolationMethods()).thenReturn(List.of("NSX")); + + when(offering.getTrafficType()).thenReturn(Networks.TrafficType.Guest); + when(offering.getGuestType()).thenReturn(Network.GuestType.Isolated); + when(offering.getNetworkMode()).thenReturn(NetworkOffering.NetworkMode.NATTED); + when(offering.getId()).thenReturn(1L); + + when(plan.getDataCenterId()).thenReturn(1L); + when(plan.getPhysicalNetworkId()).thenReturn(1L); + + when(vpcDao.findById(anyLong())).thenReturn(vpcVO); + + when(vpcVO.getName()).thenReturn("VPC01"); + + when(account.getAccountId()).thenReturn(1L); + when(accountDao.findById(anyLong())).thenReturn(mock(AccountVO.class)); + when(domainDao.findById(anyLong())).thenReturn(mock(DomainVO.class)); + + Mockito.when(networkOfferingServiceMapDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.Nsx)).thenReturn( + true); + } + + @After + public void tearDown() throws Exception { + closeable.close(); + } + + @Test + public void testIsMyIsolationMethod() { + assertTrue(guru.isMyIsolationMethod(physicalNetwork)); + } + + @Test + public void testCanHandle() { + assertTrue(guru.canHandle(offering, dataCenterVO.getNetworkType(), physicalNetwork)); + } + + @Test + public void testNsxNetworkDesign() { + when(physicalNetworkDao.findById(ArgumentMatchers.anyLong())).thenReturn(physicalNetwork); + when(dcDao.findById(ArgumentMatchers.anyLong())).thenReturn(dataCenterVO); + + Network designedNetwork = guru.design(offering, plan, network, "", 1L, account); + assertNotNull(designedNetwork); + assertSame(Networks.BroadcastDomainType.NSX, designedNetwork.getBroadcastDomainType()); + assertSame(Network.State.Allocated, designedNetwork.getState()); + } + + @Test + public void testNsxNetworkSetup() { + when(dcDao.findById(ArgumentMatchers.anyLong())).thenReturn(dataCenterVO); + when(networkDao.findById(ArgumentMatchers.anyLong())).thenReturn(mock(NetworkVO.class)); + when(nsxControllerUtils.sendNsxCommand(any(CreateNsxSegmentCommand.class), anyLong())).thenReturn( + new NsxAnswer(new NsxCommand(), true, "")); + + guru.setup(network, 1L); + verify(nsxControllerUtils, times(1)).sendNsxCommand(any(CreateNsxSegmentCommand.class), anyLong()); + } + + @Test + public void testNsxNetworkImplementation() { + final DeployDestination deployDestination = mock(DeployDestination.class); + final ReservationContext reservationContext = mock(ReservationContext.class); + + when(network.getTrafficType()).thenReturn(Networks.TrafficType.Guest); + when(network.getMode()).thenReturn(Networks.Mode.Dhcp); + when(network.getGateway()).thenReturn("192.168.1.1"); + when(network.getCidr()).thenReturn("192.168.1.0/24"); + when(network.getBroadcastDomainType()).thenReturn(Networks.BroadcastDomainType.NSX); + when(network.getNetworkOfferingId()).thenReturn(1L); + lenient().when(network.getState()).thenReturn(Network.State.Implementing); + when(network.getDataCenterId()).thenReturn(2L); + when(network.getPhysicalNetworkId()).thenReturn(3L); + when(network.getVpcId()).thenReturn(4L); + when(offering.isRedundantRouter()).thenReturn(false); + lenient().when(offering.getGuestType()).thenReturn(Network.GuestType.Isolated); + + + final Network implemented = guru.implement(network, offering, deployDestination, reservationContext); + assertEquals(Networks.BroadcastDomainType.NSX.toUri("nsx"), implemented.getBroadcastUri()); + assertEquals("192.168.1.1", implemented.getGateway()); + assertEquals("192.168.1.0/24", implemented.getCidr()); + assertEquals(Networks.Mode.Dhcp, implemented.getMode()); + assertEquals(Networks.BroadcastDomainType.NSX, implemented.getBroadcastDomainType()); + assertEquals(1L, implemented.getNetworkOfferingId()); + assertEquals(Network.State.Implemented, implemented.getState()); + assertEquals(2L, implemented.getDataCenterId()); + assertEquals(3L, implemented.getPhysicalNetworkId().longValue()); + assertEquals(4L, implemented.getVpcId().longValue()); + assertFalse(implemented.isRedundant()); + } + + @Test + public void testAllocateForUserVM() throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { + Network network = Mockito.mock(Network.class); + NicProfile nicProfile = Mockito.mock(NicProfile.class); + VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class); + VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class); + Pair dns = new Pair<>("10.1.5.1", "8.8.8.8"); + String macAddress = "00:00:00:11:1D:1E:CD"; + + when(network.getTrafficType()).thenReturn(Networks.TrafficType.Guest); + when(vmProfile.getVirtualMachine()).thenReturn(virtualMachine); + when(virtualMachine.getType()).thenReturn(VirtualMachine.Type.User); + when(networkModel.getNetworkIp4Dns(any(Network.class), nullable(DataCenter.class))).thenReturn(dns); + when(nicProfile.getMacAddress()).thenReturn(macAddress); + when(networkOfferingDao.isIpv6Supported(anyLong())).thenReturn(false); + + NicProfile profile = guru.allocate(network, nicProfile, vmProfile); + assertNotNull(profile); + } + + @Test + public void testAllocateForDomainRouter() throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { + Network network = Mockito.mock(Network.class); + NicProfile nicProfile = Mockito.mock(NicProfile.class); + VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class); + VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class); + Pair dns = new Pair<>("10.1.5.1", "8.8.8.8"); + String macAddress = "00:00:00:11:1D:1E:CD"; + + when(network.getTrafficType()).thenReturn(Networks.TrafficType.Guest); + when(vmProfile.getType()).thenReturn(VirtualMachine.Type.DomainRouter); + when(vmProfile.getVirtualMachine()).thenReturn(virtualMachine); + when(virtualMachine.getType()).thenReturn(VirtualMachine.Type.DomainRouter); + when(network.getId()).thenReturn(2L); + when(nicProfile.getMacAddress()).thenReturn(macAddress); + when(networkOfferingDao.isIpv6Supported(anyLong())).thenReturn(false); + when(network.getDataCenterId()).thenReturn(1L); + when(network.getAccountId()).thenReturn(5L); + when(network.getVpcId()).thenReturn(51L); + when(dcDao.findById(anyLong())).thenReturn(Mockito.mock(DataCenterVO.class)); + when(accountDao.findById(anyLong())).thenReturn(Mockito.mock(AccountVO.class)); + when(vpcDao.findById(anyLong())).thenReturn(Mockito.mock(VpcVO.class)); + when(domainDao.findById(anyLong())).thenReturn(Mockito.mock(DomainVO.class)); + when(nicProfile.getIPv4Address()).thenReturn("10.1.13.10"); + when(nsxControllerUtils.sendNsxCommand(any(CreateNsxDhcpRelayConfigCommand.class), + anyLong())).thenReturn(new NsxAnswer(new NsxCommand(), true, "")); + + NicProfile profile = guru.allocate(network, nicProfile, vmProfile); + + assertNotNull(profile); + verify(nsxControllerUtils, times(1)).sendNsxCommand(any(CreateNsxDhcpRelayConfigCommand.class), + anyLong()); + } + + @Test + public void testCreateNsxSegmentForVpc() { + NetworkVO networkVO = Mockito.mock(NetworkVO.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + + when(networkVO.getAccountId()).thenReturn(1L); + when(nsxControllerUtils.sendNsxCommand(any(CreateNsxSegmentCommand.class), + anyLong())).thenReturn(new NsxAnswer(new NsxCommand(), true, "")); + guru.createNsxSegment(networkVO, dataCenter); + verify(nsxControllerUtils, times(1)).sendNsxCommand(any(CreateNsxSegmentCommand.class), + anyLong()); + } + + + @Test + public void testCreateNsxSegmentForIsolatedNetwork() { + NetworkVO networkVO = Mockito.mock(NetworkVO.class); + NetworkOfferingVO offeringVO = Mockito.mock(NetworkOfferingVO.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + + when(networkVO.getAccountId()).thenReturn(1L); + when(networkVO.getVpcId()).thenReturn(null); + when(nsxControllerUtils.sendNsxCommand(any(CreateNsxTier1GatewayCommand.class), + anyLong())).thenReturn(new NsxAnswer(new NsxCommand(), true, "")); + when(nsxControllerUtils.sendNsxCommand(any(CreateNsxSegmentCommand.class), + anyLong())).thenReturn(new NsxAnswer(new NsxCommand(), true, "")); + when(networkVO.getNetworkOfferingId()).thenReturn(1L); + when(networkOfferingDao.findById(1L)).thenReturn(offeringVO); + when(offeringVO.getNetworkMode()).thenReturn(NetworkOffering.NetworkMode.NATTED); + guru.createNsxSegment(networkVO, dataCenter); + verify(nsxControllerUtils, times(1)).sendNsxCommand(any(CreateNsxTier1GatewayCommand.class), + anyLong()); + verify(nsxControllerUtils, times(1)).sendNsxCommand(any(CreateNsxSegmentCommand.class), + anyLong()); + } +} diff --git a/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxProviderServiceImplTest.java b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxProviderServiceImplTest.java new file mode 100644 index 000000000000..cb6f6511d24d --- /dev/null +++ b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxProviderServiceImplTest.java @@ -0,0 +1,174 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.host.Host; +import com.cloud.host.dao.HostDetailsDao; +import com.cloud.network.Network; +import com.cloud.network.Networks; +import com.cloud.network.nsx.NsxProvider; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.dao.NsxProviderDao; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.dao.PhysicalNetworkVO; +import com.cloud.network.element.NsxProviderVO; +import com.cloud.resource.ResourceManager; +import com.cloud.resource.ServerResource; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.command.AddNsxControllerCmd; +import org.apache.cloudstack.api.response.NsxControllerResponse; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class NsxProviderServiceImplTest { + @Mock + NsxProviderDao nsxProviderDao; + @Mock + DataCenterDao dataCenterDao; + @Mock + PhysicalNetworkDao physicalNetworkDao; + @Mock + NetworkDao networkDao; + @Mock + ResourceManager resourceManager; + @Mock + HostDetailsDao hostDetailsDao; + + NsxProviderServiceImpl nsxProviderService; + + @Before + public void setup() { + nsxProviderService = new NsxProviderServiceImpl(); + nsxProviderService.resourceManager = resourceManager; + nsxProviderService.nsxProviderDao = nsxProviderDao; + nsxProviderService.hostDetailsDao = hostDetailsDao; + nsxProviderService.dataCenterDao = dataCenterDao; + nsxProviderService.networkDao = networkDao; + nsxProviderService.physicalNetworkDao = physicalNetworkDao; + } + + @Test + public void testAddProvider() { + AddNsxControllerCmd cmd = mock(AddNsxControllerCmd.class); + when(cmd.getZoneId()).thenReturn(1L); + when(cmd.getName()).thenReturn("NsxController"); + when(cmd.getHostname()).thenReturn("192.168.0.100"); + when(cmd.getPort()).thenReturn("443"); + when(cmd.getUsername()).thenReturn("admin"); + when(cmd.getPassword()).thenReturn("password"); + when(cmd.getEdgeCluster()).thenReturn("EdgeCluster"); + when(cmd.getTier0Gateway()).thenReturn("Tier0-GW01"); + when(cmd.getTransportZone()).thenReturn("Overlay"); + when(resourceManager.addHost(anyLong(), any(ServerResource.class), any(Host.Type.class), anyMap())).thenReturn(mock(Host.class)); + try { + NsxProvider provider = nsxProviderService.addProvider(cmd); + Assert.assertNotNull(provider); + } catch (CloudRuntimeException e) { + e.printStackTrace(); + fail("Failed to add NSX controller due to internal error."); + } + } + + @Test + public void testCreateNsxControllerResponse() { + NsxProvider nsxProvider = mock(NsxProvider.class); + DataCenterVO zone = mock(DataCenterVO.class); + String uuid = UUID.randomUUID().toString(); + when(dataCenterDao.findById(anyLong())).thenReturn(zone); + when(zone.getUuid()).thenReturn(UUID.randomUUID().toString()); + when(zone.getName()).thenReturn("ZoneNSX"); + when(nsxProvider.getProviderName()).thenReturn("NSXController"); + when(nsxProvider.getUuid()).thenReturn(uuid); + when(nsxProvider.getHostname()).thenReturn("hostname"); + when(nsxProvider.getPort()).thenReturn("443"); + when(nsxProvider.getTier0Gateway()).thenReturn("Tier0Gw"); + when(nsxProvider.getEdgeCluster()).thenReturn("EdgeCluster"); + when(nsxProvider.getTransportZone()).thenReturn("Overlay"); + + NsxControllerResponse response = nsxProviderService.createNsxControllerResponse(nsxProvider); + + assertEquals("EdgeCluster", response.getEdgeCluster()); + assertEquals("Tier0Gw", response.getTier0Gateway()); + assertEquals("Overlay", response.getTransportZone()); + assertEquals("ZoneNSX", response.getZoneName()); + } + + @Test + public void testListNsxControllers() { + NsxProviderVO nsxProviderVO = Mockito.mock(NsxProviderVO.class); + + when(nsxProviderVO.getZoneId()).thenReturn(1L); + when(dataCenterDao.findById(1L)).thenReturn(mock(DataCenterVO.class)); + when(nsxProviderDao.findByZoneId(anyLong())).thenReturn(nsxProviderVO); + + List baseResponseList = nsxProviderService.listNsxProviders(1L); + assertEquals(1, baseResponseList.size()); + } + + @Test + public void testDeleteNsxController() { + NsxProviderVO nsxProviderVO = Mockito.mock(NsxProviderVO.class); + PhysicalNetworkVO physicalNetworkVO = mock(PhysicalNetworkVO.class); + List physicalNetworkVOList = List.of(physicalNetworkVO); + NetworkVO networkVO = mock(NetworkVO.class); + List networkVOList = List.of(networkVO); + + when(nsxProviderVO.getZoneId()).thenReturn(1L); + when(physicalNetworkVO.getId()).thenReturn(2L); + when(physicalNetworkDao.listByZone(1L)).thenReturn(physicalNetworkVOList); + when(nsxProviderDao.findById(anyLong())).thenReturn(nsxProviderVO); + when(networkDao.listByPhysicalNetwork(anyLong())).thenReturn(networkVOList); + + assertTrue(nsxProviderService.deleteNsxController(1L)); + } + + @Test + public void testNetworkStateValidation() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + NetworkVO networkVO = Mockito.mock(NetworkVO.class); + List networkVOList = List.of(networkVO); + when(networkVO.getBroadcastDomainType()).thenReturn(Networks.BroadcastDomainType.NSX); + when(networkVO.getState()).thenReturn(Network.State.Allocated); + + NsxProviderServiceImpl nsxProviderService = new NsxProviderServiceImpl(); + + assertThrows(CloudRuntimeException.class, () -> nsxProviderService.validateNetworkState(networkVOList)); + } +} diff --git a/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxPublicNetworkGuruTest.java b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxPublicNetworkGuruTest.java new file mode 100644 index 000000000000..1abef392345e --- /dev/null +++ b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxPublicNetworkGuruTest.java @@ -0,0 +1,178 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.dc.VlanDetailsVO; +import com.cloud.dc.dao.VlanDetailsDao; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.InsufficientAddressCapacityException; +import com.cloud.exception.InsufficientVirtualNetworkCapacityException; +import com.cloud.network.Network; +import com.cloud.network.Networks; +import com.cloud.network.dao.IPAddressDao; +import com.cloud.network.dao.IPAddressVO; +import com.cloud.network.guru.PublicNetworkGuru; +import com.cloud.network.vpc.VpcOfferingVO; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.network.vpc.dao.VpcOfferingDao; +import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao; +import com.cloud.offering.NetworkOffering; +import com.cloud.user.Account; +import com.cloud.utils.net.Ip; +import com.cloud.vm.NicProfile; +import com.cloud.vm.VirtualMachineProfile; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand; +import org.apache.cloudstack.agent.api.NsxCommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.utils.NsxControllerUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.times; + +@RunWith(MockitoJUnitRunner.class) +public class NsxPublicNetworkGuruTest { + + NetworkOffering offering; + + NsxPublicNetworkGuru guru; + @Mock + NsxServiceImpl nsxService; + @Mock + IPAddressDao ipAddressDao; + @Mock + VpcDao vpcDao; + @Mock + VlanDetailsDao vlanDetailsDao; + @Mock + VpcOfferingServiceMapDao vpcOfferingServiceMapDao; + @Mock + VpcOfferingDao vpcOfferingDao; + @Mock + NsxControllerUtils nsxControllerUtils; + + @Before + public void setup() { + guru = new NsxPublicNetworkGuru(); + + ReflectionTestUtils.setField((PublicNetworkGuru) guru, "_ipAddressDao", ipAddressDao); + ReflectionTestUtils.setField(guru, "vpcDao", vpcDao); + ReflectionTestUtils.setField(guru, "vlanDetailsDao", vlanDetailsDao); + ReflectionTestUtils.setField(guru, "vpcOfferingServiceMapDao", vpcOfferingServiceMapDao); + ReflectionTestUtils.setField(guru, "nsxService", nsxService); + ReflectionTestUtils.setField(guru, "vpcOfferingDao", vpcOfferingDao); + ReflectionTestUtils.setField(guru, "nsxControllerUtils", nsxControllerUtils); + + offering = Mockito.mock(NetworkOffering.class); + when(offering.getTrafficType()).thenReturn(Networks.TrafficType.Public); + when(offering.isForNsx()).thenReturn(true); + when(offering.isSystemOnly()).thenReturn(true); + } + + @Test + public void testCanHandle() { + Assert.assertTrue(guru.canHandle(offering)); + } + + @Test + public void testCannotHandle() { + NetworkOffering offering = Mockito.mock(NetworkOffering.class); + + when(offering.getTrafficType()).thenReturn(Networks.TrafficType.Guest); + + Assert.assertFalse(guru.canHandle(offering)); + } + + @Test + public void testDesign() { + DeploymentPlan plan = Mockito.mock(DeploymentPlan.class); + Network network = Mockito.mock(Network.class); + Account account = Mockito.mock(Account.class); + +// when(network.getTrafficType()).thenReturn(Networks.TrafficType.Public); + + Network designedNetwork = guru.design(offering, plan, network, "net1", 1L, account); + Assert.assertEquals(Networks.TrafficType.Public, designedNetwork.getTrafficType()); + } + + @Test + public void testDesign_whenOfferingIsForGuestTraffic() { + DeploymentPlan plan = Mockito.mock(DeploymentPlan.class); + Network network = Mockito.mock(Network.class); + Account account = Mockito.mock(Account.class); + + when(offering.getTrafficType()).thenReturn(Networks.TrafficType.Guest); + + Network designedNetwork = guru.design(offering, plan, network, "net1", 1L, account); + Assert.assertNull(designedNetwork); + } + + @Test + public void testAllocate() throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { + String publicIpVR = "10.1.12.10"; + String publicIpNSX = "10.1.13.10"; + Network network = Mockito.mock(Network.class); + NicProfile profile = Mockito.mock(NicProfile.class); + VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class); + IPAddressVO srcNatIpOnVR = new IPAddressVO(new Ip(publicIpVR), 2L , 0xaabbccddeeffL, 2L, true); + srcNatIpOnVR.setVpcId(12L); + IPAddressVO srcNatIpOnNSX = new IPAddressVO(new Ip(publicIpNSX), 2L , 0xaabbccddeeffL, 3L, true); + srcNatIpOnNSX.setVpcId(12L); + VpcVO vpcVO = Mockito.mock(VpcVO.class); + List sourceNatList = List.of(srcNatIpOnNSX); + VlanDetailsVO vlanDetailVO = new VlanDetailsVO(3L,ApiConstants.NSX_DETAIL_KEY, "true", false); + VpcOfferingVO vpcOffering = Mockito.mock(VpcOfferingVO.class); + + + when(profile.getIPv4Address()).thenReturn(publicIpVR); + when(ipAddressDao.findByIp(anyString())).thenReturn(srcNatIpOnVR); + when(vpcDao.findById(anyLong())).thenReturn(vpcVO); + when(ipAddressDao.listByAssociatedVpc(12L, true)).thenReturn(sourceNatList); + when(vlanDetailsDao.findDetail(anyLong(), anyString())).thenReturn(vlanDetailVO); + when(vpcVO.getVpcOfferingId()).thenReturn(12L); + when(vpcVO.getId()).thenReturn(12L); + when(vpcVO.getName()).thenReturn("nsxVPCNet"); + when(vpcOfferingServiceMapDao.areServicesSupportedByVpcOffering(anyLong(), any())).thenReturn(true); + when(nsxService.createVpcNetwork(anyLong(), anyLong(), anyLong(), anyLong(), anyString(), anyBoolean())).thenReturn(true); + when(vpcOfferingDao.findById(anyLong())).thenReturn(vpcOffering); + when(vpcOffering.getNetworkMode()).thenReturn(NetworkOffering.NetworkMode.NATTED); + when(nsxControllerUtils.sendNsxCommand(any(CreateOrUpdateNsxTier1NatRuleCommand.class), + anyLong())).thenReturn(new NsxAnswer(new NsxCommand(), true, "")); + + guru.allocate(network, profile, vmProfile); + + verify(nsxControllerUtils, times(1)).sendNsxCommand(any(CreateOrUpdateNsxTier1NatRuleCommand.class), + anyLong()); + + } +} diff --git a/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxServiceImplTest.java b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxServiceImplTest.java new file mode 100644 index 000000000000..41f47bc610e5 --- /dev/null +++ b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxServiceImplTest.java @@ -0,0 +1,162 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.service; + +import com.cloud.network.IpAddress; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.utils.net.Ip; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.CreateNsxStaticNatCommand; +import org.apache.cloudstack.agent.api.CreateNsxTier1GatewayCommand; +import org.apache.cloudstack.agent.api.CreateOrUpdateNsxTier1NatRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxNatRuleCommand; +import org.apache.cloudstack.agent.api.DeleteNsxSegmentCommand; +import org.apache.cloudstack.agent.api.DeleteNsxTier1GatewayCommand; +import org.apache.cloudstack.utils.NsxControllerUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class NsxServiceImplTest { + @Mock + private NsxControllerUtils nsxControllerUtils; + @Mock + private VpcDao vpcDao; + NsxServiceImpl nsxService; + + AutoCloseable closeable; + + private static final long domainId = 1L; + private static final long accountId = 2L; + private static final long zoneId = 1L; + + @Before + public void setup() { + closeable = MockitoAnnotations.openMocks(this); + nsxService = new NsxServiceImpl(); + nsxService.nsxControllerUtils = nsxControllerUtils; + nsxService.vpcDao = vpcDao; + } + + @After + public void teardown() throws Exception { + closeable.close(); + } + + @Test + public void testCreateVpcNetwork() { + NsxAnswer createNsxTier1GatewayAnswer = mock(NsxAnswer.class); + when(nsxControllerUtils.sendNsxCommand(any(CreateNsxTier1GatewayCommand.class), anyLong())).thenReturn(createNsxTier1GatewayAnswer); + when(createNsxTier1GatewayAnswer.getResult()).thenReturn(true); + + assertTrue(nsxService.createVpcNetwork(1L, 3L, 2L, 5L, "VPC01", false)); + } + + @Test + public void testDeleteVpcNetwork() { + NsxAnswer deleteNsxTier1GatewayAnswer = mock(NsxAnswer.class); + when(nsxControllerUtils.sendNsxCommand(any(DeleteNsxTier1GatewayCommand.class), anyLong())).thenReturn(deleteNsxTier1GatewayAnswer); + when(deleteNsxTier1GatewayAnswer.getResult()).thenReturn(true); + + assertTrue(nsxService.deleteVpcNetwork(1L, 2L, 3L, 10L, "VPC01")); + } + + @Test + public void testDeleteNetworkOnVpc() { + NetworkVO network = new NetworkVO(); + network.setVpcId(1L); + when(vpcDao.findById(1L)).thenReturn(mock(VpcVO.class)); + NsxAnswer deleteNsxSegmentAnswer = mock(NsxAnswer.class); + when(nsxControllerUtils.sendNsxCommand(any(DeleteNsxSegmentCommand.class), anyLong())).thenReturn(deleteNsxSegmentAnswer); + when(deleteNsxSegmentAnswer.getResult()).thenReturn(true); + + assertTrue(nsxService.deleteNetwork(zoneId, accountId, domainId, network)); + } + + @Test + public void testDeleteNetwork() { + NetworkVO network = new NetworkVO(); + network.setVpcId(null); + NsxAnswer deleteNsxSegmentAnswer = mock(NsxAnswer.class); + when(deleteNsxSegmentAnswer.getResult()).thenReturn(true); + when(nsxControllerUtils.sendNsxCommand(any(DeleteNsxSegmentCommand.class), anyLong())).thenReturn(deleteNsxSegmentAnswer); + NsxAnswer deleteNsxTier1GatewayAnswer = mock(NsxAnswer.class); + when(deleteNsxTier1GatewayAnswer.getResult()).thenReturn(true); + when(nsxControllerUtils.sendNsxCommand(any(DeleteNsxTier1GatewayCommand.class), anyLong())).thenReturn(deleteNsxTier1GatewayAnswer); + assertTrue(nsxService.deleteNetwork(zoneId, accountId, domainId, network)); + } + + @Test + public void testUpdateVpcSourceNatIp() { + VpcVO vpc = mock(VpcVO.class); + IpAddress ipAddress = mock(IpAddress.class); + Ip ip = Mockito.mock(Ip.class); + when(ip.addr()).thenReturn("10.1.10.10"); + when(ipAddress.getAddress()).thenReturn(ip); + long vpcId = 1L; + when(vpc.getAccountId()).thenReturn(accountId); + when(vpc.getDomainId()).thenReturn(domainId); + when(vpc.getZoneId()).thenReturn(zoneId); + when(vpc.getId()).thenReturn(vpcId); + NsxAnswer answer = mock(NsxAnswer.class); + when(answer.getResult()).thenReturn(true); + when(nsxControllerUtils.sendNsxCommand(any(CreateOrUpdateNsxTier1NatRuleCommand.class), eq(zoneId))).thenReturn(answer); + nsxService.updateVpcSourceNatIp(vpc, ipAddress); + Mockito.verify(nsxControllerUtils).sendNsxCommand(any(CreateOrUpdateNsxTier1NatRuleCommand.class), eq(zoneId)); + } + + @Test + public void testCreateStaticNatRule() { + long networkId = 1L; + String networkName = "Network-Test"; + long vmId = 1L; + String publicIp = "10.10.1.10"; + String vmIp = "192.168.1.20"; + NsxAnswer answer = Mockito.mock(NsxAnswer.class); + when(answer.getResult()).thenReturn(true); + when(nsxControllerUtils.sendNsxCommand(any(CreateNsxStaticNatCommand.class), eq(zoneId))).thenReturn(answer); + nsxService.createStaticNatRule(zoneId, domainId, accountId, + networkId, networkName, true, vmId, publicIp, vmIp); + Mockito.verify(nsxControllerUtils).sendNsxCommand(any(CreateNsxStaticNatCommand.class), eq(zoneId)); + } + + @Test + public void testDeleteStaticNatRule() { + long networkId = 1L; + String networkName = "Network-Test"; + NsxAnswer answer = Mockito.mock(NsxAnswer.class); + when(answer.getResult()).thenReturn(true); + when(nsxControllerUtils.sendNsxCommand(any(DeleteNsxNatRuleCommand.class), eq(zoneId))).thenReturn(answer); + nsxService.deleteStaticNatRule(zoneId, domainId, accountId, networkId, networkName, true); + Mockito.verify(nsxControllerUtils).sendNsxCommand(any(DeleteNsxNatRuleCommand.class), eq(zoneId)); + } +} diff --git a/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/utils/NsxControllerUtilsTest.java b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/utils/NsxControllerUtilsTest.java new file mode 100644 index 000000000000..9139fdef68f7 --- /dev/null +++ b/plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/utils/NsxControllerUtilsTest.java @@ -0,0 +1,198 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.utils; + +import com.cloud.agent.AgentManager; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.dao.NsxProviderDao; +import com.cloud.network.element.NsxProviderVO; +import org.apache.cloudstack.NsxAnswer; +import org.apache.cloudstack.agent.api.NsxCommand; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class NsxControllerUtilsTest { + + private static final long domainId = 2L; + private static final long accountId = 10L; + private static final long zoneId = 1L; + private static final long nsxProviderHostId = 1L; + + private static final String commonPrefix = String.format("D%s-A%s-Z%s", domainId, accountId, zoneId); + + @Mock + private NsxProviderDao nsxProviderDao; + @Mock + private AgentManager agentMgr; + + @Spy + @InjectMocks + private NsxControllerUtils nsxControllerUtils = new NsxControllerUtils(); + + @Mock + private NsxProviderVO nsxProviderVO; + + @Before + public void setup() { + Mockito.when(nsxProviderDao.findByZoneId(zoneId)).thenReturn(nsxProviderVO); + Mockito.when(nsxProviderVO.getHostId()).thenReturn(nsxProviderHostId); + } + + @Test(expected = InvalidParameterValueException.class) + public void testSendCommandAnswerFailure() { + NsxCommand cmd = Mockito.mock(NsxCommand.class); + Mockito.when(nsxProviderDao.findByZoneId(zoneId)).thenReturn(null); + nsxControllerUtils.sendNsxCommand(cmd, zoneId); + } + + @Test(expected = InvalidParameterValueException.class) + public void testSendCommandNoNsxProvider() { + NsxCommand cmd = Mockito.mock(NsxCommand.class); + Mockito.when(agentMgr.easySend(nsxProviderHostId, cmd)).thenReturn(null); + nsxControllerUtils.sendNsxCommand(cmd, zoneId); + } + + @Test + public void testSendCommand() { + NsxCommand cmd = Mockito.mock(NsxCommand.class); + NsxAnswer answer = Mockito.mock(NsxAnswer.class); + Mockito.when(answer.getResult()).thenReturn(true); + Mockito.when(agentMgr.easySend(nsxProviderHostId, cmd)).thenReturn(answer); + NsxAnswer nsxAnswer = nsxControllerUtils.sendNsxCommand(cmd, zoneId); + Assert.assertNotNull(nsxAnswer); + } + + @Test + public void testGetNsxNatRuleIdForVpc() { + long vpcId = 5L; + String nsxNatRuleId = NsxControllerUtils.getNsxNatRuleId(domainId, accountId, zoneId, vpcId, true); + String ruleIdPart = String.format("V%s-NAT", vpcId); + String expected = String.format("%s-%s", commonPrefix, ruleIdPart); + Assert.assertEquals(expected, nsxNatRuleId); + } + + @Test + public void testGetNsxNatRuleIdForNetwork() { + long networkId = 5L; + String nsxNatRuleId = NsxControllerUtils.getNsxNatRuleId(domainId, accountId, zoneId, networkId, false); + String ruleIdPart = String.format("N%s-NAT", networkId); + String expected = String.format("%s-%s", commonPrefix, ruleIdPart); + Assert.assertEquals(expected, nsxNatRuleId); + } + + @Test + public void testGetNsxSegmentIdForVpcNetwork() { + long vpcId = 5L; + long networkId = 2L; + String nsxSegmentName = NsxControllerUtils.getNsxSegmentId(domainId, accountId, zoneId, vpcId, networkId); + String segmentPart = String.format("V%s-S%s", vpcId, networkId); + String expected = String.format("%s-%s", commonPrefix, segmentPart); + Assert.assertEquals(expected, nsxSegmentName); + } + + @Test + public void testGetNsxSegmentIdForNonVpcNetwork() { + Long vpcId = null; + long networkId = 2L; + String nsxSegmentName = NsxControllerUtils.getNsxSegmentId(domainId, accountId, zoneId, vpcId, networkId); + String segmentPart = String.format("S%s", networkId); + String expected = String.format("%s-%s", commonPrefix, segmentPart); + Assert.assertEquals(expected, nsxSegmentName); + } + + @Test + public void testGetNsxDistributedFirewallPolicyRuleIdForVpcNetwork() { + long vpcId = 5L; + long networkId = 2L; + long ruleId = 1L; + String nsxSegmentName = NsxControllerUtils.getNsxSegmentId(domainId, accountId, zoneId, vpcId, networkId); + String expected = String.format("%s-R%s", nsxSegmentName, ruleId); + Assert.assertEquals(expected, NsxControllerUtils.getNsxDistributedFirewallPolicyRuleId(nsxSegmentName, ruleId)); + } + + @Test + public void testGetTier1GatewayNameForVpcNetwork() { + long networkOnVpcId = 5L; + String networkPart = String.format("V%s", networkOnVpcId); + String expected = String.format("%s-%s", commonPrefix, networkPart); + Assert.assertEquals(expected, NsxControllerUtils.getTier1GatewayName(domainId, accountId, zoneId, networkOnVpcId, true)); + } + + @Test + public void testGetTier1GatewayNameForNetwork() { + long networkId = 5L; + String networkPart = String.format("N%s", networkId); + String expected = String.format("%s-%s", commonPrefix, networkPart); + Assert.assertEquals(expected, NsxControllerUtils.getTier1GatewayName(domainId, accountId, zoneId, networkId, false)); + } + + @Test + public void testGetNsxDhcpRelayConfigIdForVpcNetwork() { + long vpcId = 5L; + long networkId = 2L; + String relayPart = String.format("V%s-S%s-Relay", vpcId, networkId); + String expected = String.format("%s-%s", commonPrefix, relayPart); + String dhcpRelayConfigId = NsxControllerUtils.getNsxDhcpRelayConfigId(zoneId, domainId, accountId, vpcId, networkId); + Assert.assertEquals(expected, dhcpRelayConfigId); + } + + @Test + public void testGetNsxDhcpRelayConfigIdForNetwork() { + Long vpcId = null; + long networkId = 2L; + String relayPart = String.format("S%s-Relay", networkId); + String expected = String.format("%s-%s", commonPrefix, relayPart); + String dhcpRelayConfigId = NsxControllerUtils.getNsxDhcpRelayConfigId(zoneId, domainId, accountId, vpcId, networkId); + Assert.assertEquals(expected, dhcpRelayConfigId); + } + + @Test + public void testGetStaticNatRuleNameForVpc() { + long vpcId = 5L; + String rulePart = String.format("V%s-STATICNAT", vpcId); + String expected = String.format("%s-%s", commonPrefix, rulePart); + String staticNatRuleName = NsxControllerUtils.getStaticNatRuleName(domainId, accountId, zoneId, vpcId, true); + Assert.assertEquals(expected, staticNatRuleName); + } + + @Test + public void testGetStaticNatRuleNameForNetwork() { + long network = 5L; + String rulePart = String.format("N%s-STATICNAT", network); + String expected = String.format("%s-%s", commonPrefix, rulePart); + String staticNatRuleName = NsxControllerUtils.getStaticNatRuleName(domainId, accountId, zoneId, network, false); + Assert.assertEquals(expected, staticNatRuleName); + } + + @Test + public void testGetPortForwardRuleName() { + long vpcId = 5L; + long ruleId = 2L; + String rulePart = String.format("V%s-PF%s", vpcId, ruleId); + String expected = String.format("%s-%s", commonPrefix, rulePart); + String portForwardRuleName = NsxControllerUtils.getPortForwardRuleName(domainId, accountId, zoneId, vpcId, ruleId, true); + Assert.assertEquals(expected, portForwardRuleName); + } +} diff --git a/plugins/network-elements/opendaylight/pom.xml b/plugins/network-elements/opendaylight/pom.xml index 2f2ced7a8054..d8f3bcfc8eb6 100644 --- a/plugins/network-elements/opendaylight/pom.xml +++ b/plugins/network-elements/opendaylight/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/OpendaylightElement.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/OpendaylightElement.java index 9bae4bd19e6f..b35190217d32 100644 --- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/OpendaylightElement.java +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/OpendaylightElement.java @@ -27,7 +27,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.network.opendaylight.agent.commands.StartupOpenDaylightControllerCommand; @@ -59,7 +58,6 @@ @Component public class OpendaylightElement extends AdapterBase implements ConnectivityProvider, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(OpendaylightElement.class); private static final Map> s_capabilities = setCapabilities(); @Inject diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/OpendaylightGuestNetworkGuru.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/OpendaylightGuestNetworkGuru.java index e99ec555b889..7b4851fc285c 100644 --- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/OpendaylightGuestNetworkGuru.java +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/OpendaylightGuestNetworkGuru.java @@ -60,14 +60,12 @@ import org.apache.cloudstack.network.opendaylight.agent.responses.DestroyPortAnswer; import org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerMappingDao; import org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; import java.util.UUID; public class OpendaylightGuestNetworkGuru extends GuestNetworkGuru { - private static final Logger s_logger = Logger.getLogger(OpendaylightGuestNetworkGuru.class); @Inject protected NetworkOfferingServiceMapDao ntwkOfferingSrvcDao; @@ -93,29 +91,29 @@ protected boolean canHandle(NetworkOffering offering, NetworkType networkType, P && ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Provider.Opendaylight)) { return true; } else { - s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); + logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); return false; } } @Override - public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner) { PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId()); DataCenter dc = _dcDao.findById(plan.getDataCenterId()); if (!canHandle(offering, dc.getNetworkType(), physnet)) { - s_logger.debug("Refusing to design this network"); + logger.debug("Refusing to design this network"); return null; } List devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physnet.getId()); if (devices.isEmpty()) { - s_logger.error("No Controller on physical network " + physnet.getName()); + logger.error("No Controller on physical network " + physnet.getName()); return null; } - s_logger.debug("Controller " + devices.get(0).getUuid() + " found on physical network " + physnet.getId()); - s_logger.debug("Physical isolation type is ODL, asking GuestNetworkGuru to design this network"); + logger.debug("Controller " + devices.get(0).getUuid() + " found on physical network " + physnet.getId()); + logger.debug("Physical isolation type is ODL, asking GuestNetworkGuru to design this network"); - NetworkVO networkObject = (NetworkVO)super.design(offering, plan, userSpecified, owner); + NetworkVO networkObject = (NetworkVO)super.design(offering, plan, userSpecified, name, vpcId, owner); if (networkObject == null) { return null; } @@ -158,7 +156,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin List devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { - s_logger.error("No Controller on physical network " + physicalNetworkId); + logger.error("No Controller on physical network " + physicalNetworkId); return null; } OpenDaylightControllerVO controller = devices.get(0); @@ -167,13 +165,13 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin ConfigureNetworkAnswer answer = (ConfigureNetworkAnswer)agentManager.easySend(controller.getHostId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("ConfigureNetworkCommand failed"); + logger.error("ConfigureNetworkCommand failed"); return null; } implemented.setBroadcastUri(BroadcastDomainType.OpenDaylight.toUri(answer.getNetworkUuid())); implemented.setBroadcastDomainType(BroadcastDomainType.OpenDaylight); - s_logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString()); + logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString()); return implemented; } @@ -188,7 +186,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D List devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { - s_logger.error("No Controller on physical network " + physicalNetworkId); + logger.error("No Controller on physical network " + physicalNetworkId); throw new InsufficientVirtualNetworkCapacityException("No OpenDaylight Controller configured for this network", dest.getPod().getId()); } OpenDaylightControllerVO controller = devices.get(0); @@ -196,7 +194,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D AddHypervisorCommand addCmd = new AddHypervisorCommand(dest.getHost().getUuid(), dest.getHost().getPrivateIpAddress()); AddHypervisorAnswer addAnswer = (AddHypervisorAnswer)agentManager.easySend(controller.getHostId(), addCmd); if (addAnswer == null || !addAnswer.getResult()) { - s_logger.error("Failed to add " + dest.getHost().getName() + " as a node to the controller"); + logger.error("Failed to add " + dest.getHost().getName() + " as a node to the controller"); throw new InsufficientVirtualNetworkCapacityException("Failed to add destination hypervisor to the OpenDaylight Controller", dest.getPod().getId()); } @@ -205,7 +203,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D ConfigurePortAnswer answer = (ConfigurePortAnswer)agentManager.easySend(controller.getHostId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("ConfigureNetworkCommand failed"); + logger.error("ConfigureNetworkCommand failed"); throw new InsufficientVirtualNetworkCapacityException("Failed to configure the port on the OpenDaylight Controller", dest.getPod().getId()); } @@ -222,7 +220,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat List devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { - s_logger.error("No Controller on physical network " + physicalNetworkId); + logger.error("No Controller on physical network " + physicalNetworkId); throw new CloudRuntimeException("No OpenDaylight controller on this physical network"); } OpenDaylightControllerVO controller = devices.get(0); @@ -231,7 +229,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat DestroyPortAnswer answer = (DestroyPortAnswer)agentManager.easySend(controller.getHostId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("DestroyPortCommand failed"); + logger.error("DestroyPortCommand failed"); success = false; } } @@ -243,13 +241,13 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat public void shutdown(NetworkProfile profile, NetworkOffering offering) { NetworkVO networkObject = networkDao.findById(profile.getId()); if (networkObject.getBroadcastDomainType() != BroadcastDomainType.OpenDaylight || networkObject.getBroadcastUri() == null) { - s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); + logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); return; } List devices = openDaylightControllerMappingDao.listByPhysicalNetwork(networkObject.getPhysicalNetworkId()); if (devices.isEmpty()) { - s_logger.error("No Controller on physical network " + networkObject.getPhysicalNetworkId()); + logger.error("No Controller on physical network " + networkObject.getPhysicalNetworkId()); return; } OpenDaylightControllerVO controller = devices.get(0); @@ -258,7 +256,7 @@ public void shutdown(NetworkProfile profile, NetworkOffering offering) { DestroyNetworkAnswer answer = (DestroyNetworkAnswer)agentManager.easySend(controller.getHostId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("DestroyNetworkCommand failed"); + logger.error("DestroyNetworkCommand failed"); } super.shutdown(profile, offering); diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java index f6046ddc4248..6b81f8dc38a7 100644 --- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java @@ -21,7 +21,6 @@ import java.net.MalformedURLException; import java.net.URL; -import java.security.InvalidParameterException; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -31,7 +30,8 @@ import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.network.opendaylight.agent.commands.AddHypervisorCommand; import org.apache.cloudstack.network.opendaylight.agent.commands.ConfigureNetworkCommand; @@ -68,10 +68,11 @@ import com.cloud.agent.api.StartupCommand; import com.cloud.host.Host; import com.cloud.host.Host.Type; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.resource.ServerResource; public class OpenDaylightControllerResource implements ServerResource { - private static final Logger s_logger = Logger.getLogger(OpenDaylightControllerResource.class); + protected Logger logger = LogManager.getLogger(getClass()); private Map configuration = new HashMap(); private URL controllerUrl; @@ -182,7 +183,7 @@ public Answer executeRequest(Command cmd) { @Override public void disconnected() { - s_logger.warn("OpenDaylightControllerResource is disconnected from the controller at " + controllerUrl); + logger.warn("OpenDaylightControllerResource is disconnected from the controller at " + controllerUrl); } @@ -225,7 +226,7 @@ private Answer executeRequest(ConfigureNetworkCommand cmd) { break; } } catch (NeutronRestApiException e) { - s_logger.error("Failed to list existing networks on the ODL Controller", e); + logger.error("Failed to list existing networks on the ODL Controller", e); return new ConfigureNetworkAnswer(cmd, e); } @@ -246,7 +247,7 @@ private Answer executeRequest(ConfigureNetworkCommand cmd) { try { wrapper = configureNetwork.createNeutronNetwork(wrapper); } catch (NeutronRestApiException e) { - s_logger.error("createNeutronNetwork failed", e); + logger.error("createNeutronNetwork failed", e); return new ConfigureNetworkAnswer(cmd, e); } @@ -258,7 +259,7 @@ private Answer executeRequest(DestroyNetworkCommand cmd) { try { configureNetwork.deleteNeutronNetwork(cmd.getNetworkUuid()); } catch (NeutronRestApiException e) { - s_logger.error("deleteNeutronNetwork failed", e); + logger.error("deleteNeutronNetwork failed", e); return new DestroyNetworkAnswer(cmd, e); } @@ -287,7 +288,7 @@ private Answer executeRequest(ConfigurePortCommand cmd) { try { portWrapper = configurePort.createNeutronPort(portWrapper); } catch (NeutronRestApiException e) { - s_logger.error("createPortCommand failed", e); + logger.error("createPortCommand failed", e); return new ConfigurePortAnswer(cmd, e); } @@ -300,7 +301,7 @@ private Answer executeRequest(DestroyPortCommand cmd) { try { configurePort.deleteNeutronPort(cmd.getPortId().toString()); } catch (NeutronRestApiException e) { - s_logger.error("deleteNeutronPort failed", e); + logger.error("deleteNeutronPort failed", e); return new DestroyPortAnswer(cmd, e); } @@ -323,7 +324,7 @@ private Answer executeRequest(AddHypervisorCommand cmd) { // Not found in the existing node list, add it nodeActions.updateNeutronNodeV2("OVS", cmd.getHostId(), cmd.getIpAddress(), 6640); } catch (NeutronRestApiException e) { - s_logger.error("Call to OpenDaylight failed", e); + logger.error("Call to OpenDaylight failed", e); return new AddHypervisorAnswer(cmd, e); } return new AddHypervisorAnswer(cmd, true, "Hypervisor " + cmd.getHostId() + " added"); @@ -331,11 +332,11 @@ private Answer executeRequest(AddHypervisorCommand cmd) { private void updateConfiguration() { if (!configuration.containsKey("url") || !configuration.containsKey("username") || !configuration.containsKey("password")) - throw new InvalidParameterException("OpenDaylightControllerResource needs a url, username and password."); + throw new InvalidParameterValueException("OpenDaylightControllerResource needs a url, username and password."); try { controllerUrl = new URL((String)configuration.get("url")); } catch (MalformedURLException e) { - throw new InvalidParameterException("OpenDaylightControllerResource found an invalid controller url"); + throw new InvalidParameterValueException("OpenDaylightControllerResource found an invalid controller url"); } controllerUsername = (String)configuration.get("username"); controllerPassword = (String)configuration.get("password"); diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResourceManagerImpl.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResourceManagerImpl.java index 013c3028071c..8bf68f0c289b 100644 --- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResourceManagerImpl.java +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResourceManagerImpl.java @@ -28,7 +28,8 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; import org.apache.cloudstack.network.opendaylight.api.commands.AddOpenDaylightControllerCmd; @@ -62,7 +63,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class OpenDaylightControllerResourceManagerImpl implements OpenDaylightControllerResourceManager { - private final static Logger s_logger = Logger.getLogger(OpenDaylightControllerResourceManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject HostDao hostDao; diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/NeutronRestApi.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/NeutronRestApi.java index 980936d8ecef..20ba46c45dd3 100644 --- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/NeutronRestApi.java +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/NeutronRestApi.java @@ -31,7 +31,8 @@ import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; @@ -53,7 +54,7 @@ public class NeutronRestApi { - private static final Logger s_logger = Logger.getLogger(NeutronRestApi.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); private static final String PROTOCOL = "https"; @@ -77,7 +78,7 @@ protected NeutronRestApi(final Class httpClazz, final // with the SecureProtocolSocketFactory parameter Protocol.registerProtocol(protocol, new Protocol(protocol, (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), HTTPS_PORT)); } catch (IOException e) { - s_logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e); + logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e); } } @@ -97,31 +98,31 @@ public HttpMethodBase createMethod(final URL neutronUrl, final String uri) throw return httpMethod; } catch (MalformedURLException e) { String error = "Unable to build Neutron API URL"; - s_logger.error(error, e); + logger.error(error, e); throw new NeutronRestApiException(error, e); } catch (NoSuchMethodException e) { String error = "Unable to build Neutron API URL due to reflection error"; - s_logger.error(error, e); + logger.error(error, e); throw new NeutronRestApiException(error, e); } catch (SecurityException e) { String error = "Unable to build Neutron API URL due to security violation"; - s_logger.error(error, e); + logger.error(error, e); throw new NeutronRestApiException(error, e); } catch (InstantiationException e) { String error = "Unable to build Neutron API due to instantiation error"; - s_logger.error(error, e); + logger.error(error, e); throw new NeutronRestApiException(error, e); } catch (IllegalAccessException e) { String error = "Unable to build Neutron API URL due to absence of access modifier"; - s_logger.error(error, e); + logger.error(error, e); throw new NeutronRestApiException(error, e); } catch (IllegalArgumentException e) { String error = "Unable to build Neutron API URL due to wrong argument in constructor"; - s_logger.error(error, e); + logger.error(error, e); throw new NeutronRestApiException(error, e); } catch (InvocationTargetException e) { String error = "Unable to build Neutron API URL due to target error"; - s_logger.error(error, e); + logger.error(error, e); throw new NeutronRestApiException(error, e); } } @@ -130,11 +131,11 @@ public void executeMethod(final HttpMethodBase method) throws NeutronRestApiExce try { client.executeMethod(method); } catch (HttpException e) { - s_logger.error("HttpException caught while trying to connect to the Neutron Controller", e); + logger.error("HttpException caught while trying to connect to the Neutron Controller", e); method.releaseConnection(); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } catch (IOException e) { - s_logger.error("IOException caught while trying to connect to the Neutron Controller", e); + logger.error("IOException caught while trying to connect to the Neutron Controller", e); method.releaseConnection(); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java index 0e8e4319c067..d27789dab953 100644 --- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/Action.java @@ -40,11 +40,12 @@ import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public abstract class Action { - private static final Logger s_logger = Logger.getLogger(Action.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int BODY_RESP_MAX_LEN = 1024; // private static final String DEFAULT @@ -95,14 +96,14 @@ public String executeGet(final String uri, final Map parameters) if (getMethod.getStatusCode() != HttpStatus.SC_OK) { String errorMessage = responseToErrorMessage(getMethod); getMethod.releaseConnection(); - s_logger.error("Failed to retrieve object : " + errorMessage); + logger.error("Failed to retrieve object : " + errorMessage); throw new NeutronRestApiException("Failed to retrieve object : " + errorMessage); } return getMethod.getResponseBodyAsString(); } catch (NeutronRestApiException e) { - s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); + logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } catch (IOException e) { throw new NeutronRestApiException(e); @@ -135,13 +136,13 @@ protected String executePost(final String uri, final StringRequestEntity entity) if (postMethod.getStatusCode() != HttpStatus.SC_CREATED) { String errorMessage = responseToErrorMessage(postMethod); postMethod.releaseConnection(); - s_logger.error("Failed to create object : " + errorMessage); + logger.error("Failed to create object : " + errorMessage); throw new NeutronRestApiException("Failed to create object : " + errorMessage); } return postMethod.getResponseBodyAsString(); } catch (NeutronRestApiException e) { - s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); + logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } catch (IOException e) { throw new NeutronRestApiException("Failed to load json response body", e); @@ -174,11 +175,11 @@ protected void executePut(final String uri, final StringRequestEntity entity) th if (putMethod.getStatusCode() != HttpStatus.SC_OK) { String errorMessage = responseToErrorMessage(putMethod); putMethod.releaseConnection(); - s_logger.error("Failed to update object : " + errorMessage); + logger.error("Failed to update object : " + errorMessage); throw new NeutronRestApiException("Failed to update object : " + errorMessage); } } catch (NeutronRestApiException e) { - s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); + logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } finally { putMethod.releaseConnection(); @@ -206,13 +207,13 @@ protected String executePut(final String uri) throws NeutronRestApiException { if (putMethod.getStatusCode() != HttpStatus.SC_OK) { String errorMessage = responseToErrorMessage(putMethod); putMethod.releaseConnection(); - s_logger.error("Failed to update object : " + errorMessage); + logger.error("Failed to update object : " + errorMessage); throw new NeutronRestApiException("Failed to update object : " + errorMessage); } return putMethod.getResponseBodyAsString(); } catch (NeutronRestApiException e) { - s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); + logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } catch (IOException e) { throw new NeutronRestApiException("Failed to load json response body", e); @@ -244,11 +245,11 @@ protected void executeDelete(final String uri) throws NeutronRestApiException { if (deleteMethod.getStatusCode() != HttpStatus.SC_NO_CONTENT) { String errorMessage = responseToErrorMessage(deleteMethod); deleteMethod.releaseConnection(); - s_logger.error("Failed to delete object : " + errorMessage); + logger.error("Failed to delete object : " + errorMessage); throw new NeutronRestApiException("Failed to delete object : " + errorMessage); } } catch (NeutronRestApiException e) { - s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); + logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } finally { deleteMethod.releaseConnection(); @@ -279,7 +280,7 @@ private String responseToErrorMessage(final HttpMethodBase method) { try { return method.getResponseBodyAsString(BODY_RESP_MAX_LEN); } catch (IOException e) { - s_logger.debug("Error while loading response body", e); + logger.debug("Error while loading response body", e); } } diff --git a/plugins/network-elements/ovs/pom.xml b/plugins/network-elements/ovs/pom.xml index a9eb95cc1e05..f59442e6e4d3 100644 --- a/plugins/network-elements/ovs/pom.xml +++ b/plugins/network-elements/ovs/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/ovs/src/main/java/com/cloud/network/element/OvsElement.java b/plugins/network-elements/ovs/src/main/java/com/cloud/network/element/OvsElement.java index 85dd243306f3..698919542642 100644 --- a/plugins/network-elements/ovs/src/main/java/com/cloud/network/element/OvsElement.java +++ b/plugins/network-elements/ovs/src/main/java/com/cloud/network/element/OvsElement.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.network.topology.NetworkTopology; import org.apache.cloudstack.network.topology.NetworkTopologyContext; -import org.apache.log4j.Logger; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupOvsCommand; @@ -102,7 +101,6 @@ public class OvsElement extends AdapterBase implements NetworkElement, @Inject NetworkTopologyContext _networkTopologyContext; - private static final Logger s_logger = Logger.getLogger(OvsElement.class); private static final Map> capabilities = setCapabilities(); @Override @@ -116,21 +114,21 @@ public Provider getProvider() { } protected boolean canHandle(final Network network, final Service service) { - s_logger.debug("Checking if OvsElement can handle service " + logger.debug("Checking if OvsElement can handle service " + service.getName() + " on network " + network.getDisplayText()); if (network.getBroadcastDomainType() != BroadcastDomainType.Vswitch) { return false; } if (!_networkModel.isProviderForNetwork(getProvider(), network.getId())) { - s_logger.debug("OvsElement is not a provider for network " + logger.debug("OvsElement is not a provider for network " + network.getDisplayText()); return false; } if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), service, Network.Provider.Ovs)) { - s_logger.debug("OvsElement can't provide the " + service.getName() + logger.debug("OvsElement can't provide the " + service.getName() + " service on network " + network.getDisplayText()); return false; } @@ -151,7 +149,7 @@ public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - s_logger.debug("entering OvsElement implement function for network " + logger.debug("entering OvsElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")"); @@ -249,7 +247,7 @@ public boolean canEnableIndividualServices() { @Override public boolean verifyServicesCombination(final Set services) { if (!services.contains(Service.Connectivity)) { - s_logger.warn("Unable to provide services without Connectivity service enabled for this element"); + logger.warn("Unable to provide services without Connectivity service enabled for this element"); return false; } @@ -439,7 +437,7 @@ public boolean applyIps(final Network network, final List routers = _routerDao.listByNetworkAndRole( network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router element doesn't need to associate ip addresses on the backend; virtual " + logger.debug("Virtual router element doesn't need to associate ip addresses on the backend; virtual " + "router doesn't exist in the network " + network.getId()); return true; @@ -464,7 +462,7 @@ public boolean applyStaticNats(final Network network, final List routers = _routerDao.listByNetworkAndRole( network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Ovs element doesn't need to apply static nat on the backend; virtual " + logger.debug("Ovs element doesn't need to apply static nat on the backend; virtual " + "router doesn't exist in the network " + network.getId()); return true; } @@ -487,7 +485,7 @@ public boolean applyPFRules(final Network network, final List routers = _routerDao.listByNetworkAndRole( network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Ovs element doesn't need to apply firewall rules on the backend; virtual " + logger.debug("Ovs element doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId()); return true; } @@ -513,7 +511,7 @@ public boolean applyLBRules(final Network network, final List final List routers = _routerDao.listByNetworkAndRole( network.getId(), Role.VIRTUAL_ROUTER); if (routers == null || routers.isEmpty()) { - s_logger.debug("Virtual router elemnt doesn't need to apply load balancing rules on the backend; virtual " + logger.debug("Virtual router elemnt doesn't need to apply load balancing rules on the backend; virtual " + "router doesn't exist in the network " + network.getId()); return true; @@ -525,7 +523,7 @@ public boolean applyLBRules(final Network network, final List for (final DomainRouterVO domainRouterVO : routers) { result = result && networkTopology.applyLoadBalancingRules(network, rules, domainRouterVO); if (!result) { - s_logger.debug("Failed to apply load balancing rules in network " + network.getId()); + logger.debug("Failed to apply load balancing rules in network " + network.getId()); } } } @@ -566,7 +564,7 @@ private boolean canHandleLbRules(final List rules) { if (schemeCaps != null) { for (final LoadBalancingRule rule : rules) { if (!schemeCaps.contains(rule.getScheme().toString())) { - s_logger.debug("Scheme " + rules.get(0).getScheme() + logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + getName()); return false; diff --git a/plugins/network-elements/ovs/src/main/java/com/cloud/network/guru/OvsGuestNetworkGuru.java b/plugins/network-elements/ovs/src/main/java/com/cloud/network/guru/OvsGuestNetworkGuru.java index f8d851e586e1..97531a915377 100644 --- a/plugins/network-elements/ovs/src/main/java/com/cloud/network/guru/OvsGuestNetworkGuru.java +++ b/plugins/network-elements/ovs/src/main/java/com/cloud/network/guru/OvsGuestNetworkGuru.java @@ -21,7 +21,6 @@ import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenter; @@ -55,8 +54,6 @@ @Component public class OvsGuestNetworkGuru extends GuestNetworkGuru { - private static final Logger s_logger = Logger - .getLogger(OvsGuestNetworkGuru.class); @Inject OvsTunnelManager _ovsTunnelMgr; @@ -89,7 +86,7 @@ && isMyIsolationMethod(physicalNetwork) && physicalNetwork.getIsolationMethods().contains("GRE")) { return true; } else { - s_logger.trace(String.format("We only take care of Guest networks of type %s with Service %s or type with %s provider %s in %s zone", + logger.trace(String.format("We only take care of Guest networks of type %s with Service %s or type with %s provider %s in %s zone", GuestType.Isolated, Service.Connectivity, GuestType.Shared, Network.Provider.Ovs, NetworkType.Advanced)); return false; } @@ -97,17 +94,17 @@ && isMyIsolationMethod(physicalNetwork) @Override public Network design(NetworkOffering offering, DeploymentPlan plan, - Network userSpecified, Account owner) { + Network userSpecified, String name, Long vpcId, Account owner) { PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan .getPhysicalNetworkId()); DataCenter dc = _dcDao.findById(plan.getDataCenterId()); if (!canHandle(offering, dc.getNetworkType(), physnet)) { - s_logger.debug("Refusing to design this network"); + logger.debug("Refusing to design this network"); return null; } NetworkVO config = (NetworkVO)super.design(offering, plan, - userSpecified, owner); + userSpecified, name, vpcId, owner); if (config == null) { return null; } @@ -141,7 +138,7 @@ public Network implement(Network network, NetworkOffering offering, .findById(physicalNetworkId); if (!canHandle(offering, nwType, physnet)) { - s_logger.debug("Refusing to implement this network"); + logger.debug("Refusing to implement this network"); return null; } NetworkVO implemented = (NetworkVO)super.implement(network, offering, @@ -190,13 +187,13 @@ public void shutdown(NetworkProfile profile, NetworkOffering offering) { NetworkVO networkObject = _networkDao.findById(profile.getId()); if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Vswitch || networkObject.getBroadcastUri() == null) { - s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); return; } if (profile.getBroadcastDomainType() == BroadcastDomainType.Vswitch ) { - s_logger.debug("Releasing vnet for the network id=" + profile.getId()); + logger.debug("Releasing vnet for the network id=" + profile.getId()); _dcDao.releaseVnet(BroadcastDomainType.getValue(profile.getBroadcastUri()), profile.getDataCenterId(), profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId()); } diff --git a/plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/OvsTunnelManagerImpl.java b/plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/OvsTunnelManagerImpl.java index aca36092feae..c99a6fd5de3d 100644 --- a/plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/OvsTunnelManagerImpl.java +++ b/plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/OvsTunnelManagerImpl.java @@ -29,7 +29,7 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.messagebus.MessageBus; import org.apache.cloudstack.framework.messagebus.MessageSubscriber; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -92,7 +92,6 @@ @Component public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManager, StateListener { - public static final Logger s_logger = Logger.getLogger(OvsTunnelManagerImpl.class.getName()); // boolean _isEnabled; ScheduledExecutorService _executorPool; @@ -159,13 +158,13 @@ protected OvsTunnelInterfaceVO createInterfaceRecord(String ip, OvsTunnelInterfaceVO lock = _tunnelInterfaceDao .acquireInLockTable(Long.valueOf(1)); if (lock == null) { - s_logger.warn("Cannot lock table ovs_tunnel_account"); + logger.warn("Cannot lock table ovs_tunnel_account"); return null; } _tunnelInterfaceDao.persist(ti); _tunnelInterfaceDao.releaseFromLockTable(lock.getId()); } catch (EntityExistsException e) { - s_logger.debug("A record for the interface for network " + label + logger.debug("A record for the interface for network " + label + " on host id " + hostId + " already exists"); } return ti; @@ -181,7 +180,7 @@ private String handleFetchInterfaceAnswer(Answer[] answers, Long hostId) { } } // Fetch interface failed! - s_logger.warn("Unable to fetch the IP address for the GRE tunnel endpoint" + logger.warn("Unable to fetch the IP address for the GRE tunnel endpoint" + ans.getDetails()); return null; } @@ -193,13 +192,13 @@ protected OvsTunnelNetworkVO createTunnelRecord(long from, long to, long network ta = new OvsTunnelNetworkVO(from, to, key, networkId); OvsTunnelNetworkVO lock = _tunnelNetworkDao.acquireInLockTable(Long.valueOf(1)); if (lock == null) { - s_logger.warn("Cannot lock table ovs_tunnel_account"); + logger.warn("Cannot lock table ovs_tunnel_account"); return null; } _tunnelNetworkDao.persist(ta); _tunnelNetworkDao.releaseFromLockTable(lock.getId()); } catch (EntityExistsException e) { - s_logger.debug("A record for the tunnel from " + from + " to " + to + " already exists"); + logger.debug("A record for the tunnel from " + from + " to " + to + " already exists"); } return ta; } @@ -221,12 +220,12 @@ private void handleCreateTunnelAnswer(Answer[] answers) { } if (!r.getResult()) { tunnel.setState(OvsTunnel.State.Failed.name()); - s_logger.warn("Create GRE tunnel from " + from + " to " + to + " failed due to " + r.getDetails() + logger.warn("Create GRE tunnel from " + from + " to " + to + " failed due to " + r.getDetails() + s); } else { tunnel.setState(OvsTunnel.State.Established.name()); tunnel.setPortName(r.getInPortName()); - s_logger.info("Create GRE tunnel from " + from + " to " + to + " succeeded." + r.getDetails() + s); + logger.info("Create GRE tunnel from " + from + " to " + to + " succeeded." + r.getDetails() + s); } _tunnelNetworkDao.update(tunnel.getId(), tunnel); } @@ -242,23 +241,18 @@ private String getGreEndpointIP(Host host, Network nw) HypervisorType hvType = host.getHypervisorType(); String label = null; - switch (hvType) { - case XenServer: + if (hvType.equals(HypervisorType.XenServer)) { label = physNetTT.getXenNetworkLabel(); - if ((label != null) && (!label.equals(""))) { + if (StringUtils.isNotBlank(label)) { physNetLabel = label; } - break; - case KVM: + } else if (hvType.equals(HypervisorType.KVM)) { label = physNetTT.getKvmNetworkLabel(); - if ((label != null) && (!label.equals(""))) { + if (StringUtils.isNotBlank(label)) { physNetLabel = label; } - break; - default: - throw new CloudRuntimeException("Hypervisor " + - hvType.toString() + - " unsupported by OVS Tunnel Manager"); + } else { + throw new CloudRuntimeException(String.format("Hypervisor %s unsupported by OVS Tunnel Manager", hvType)); } // Try to fetch GRE endpoint IP address for cloud db @@ -271,7 +265,7 @@ private String getGreEndpointIP(Host host, Network nw) //for network with label on target host Commands fetchIfaceCmds = new Commands(new OvsFetchInterfaceCommand(physNetLabel)); - s_logger.debug("Ask host " + host.getId() + + logger.debug("Ask host " + host.getId() + " to retrieve interface for phy net with label:" + physNetLabel); Answer[] fetchIfaceAnswers = _agentMgr.send(host.getId(), fetchIfaceCmds); @@ -297,7 +291,7 @@ private int getGreKey(Network network) { return key; } catch (NumberFormatException e) { - s_logger.debug("Well well, how did '" + key + logger.debug("Well well, how did '" + key + "' end up in the broadcast URI for the network?"); throw new CloudRuntimeException(String.format( "Invalid GRE key parsed from" @@ -309,7 +303,7 @@ private int getGreKey(Network network) { @DB protected void checkAndCreateTunnel(Network nw, Host host) { - s_logger.debug("Creating tunnels with OVS tunnel manager"); + logger.debug("Creating tunnels with OVS tunnel manager"); long hostId = host.getId(); int key = getGreKey(nw); @@ -324,7 +318,7 @@ protected void checkAndCreateTunnel(Network nw, Host host) { OvsTunnelNetworkVO ta = _tunnelNetworkDao.findByFromToNetwork(hostId, rh.longValue(), nw.getId()); // Try and create the tunnel even if a previous attempt failed if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) { - s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue()); + logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue()); if (ta == null) { createTunnelRecord(hostId, rh.longValue(), nw.getId(), key); } @@ -337,7 +331,7 @@ protected void checkAndCreateTunnel(Network nw, Host host) { hostId, nw.getId()); // Try and create the tunnel even if a previous attempt failed if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) { - s_logger.debug("Attempting to create tunnel from:" + + logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId); if (ta == null) { createTunnelRecord(rh.longValue(), hostId, @@ -365,8 +359,8 @@ protected void checkAndCreateTunnel(Network nw, Host host) { Commands cmds = new Commands( new OvsCreateTunnelCommand(otherIp, key, Long.valueOf(hostId), i, nw.getId(), myIp, bridgeName, nw.getUuid())); - s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + nw.getId()); - s_logger.debug("Ask host " + hostId + logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + nw.getId()); + logger.debug("Ask host " + hostId + " to create gre tunnel to " + i); Answer[] answers = _agentMgr.send(hostId, cmds); handleCreateTunnelAnswer(answers); @@ -378,7 +372,7 @@ protected void checkAndCreateTunnel(Network nw, Host host) { String otherIp = getGreEndpointIP(rHost, nw); Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), nw.getId(), otherIp, bridgeName, nw.getUuid())); - s_logger.debug("Ask host " + i + " to create gre tunnel to " + logger.debug("Ask host " + i + " to create gre tunnel to " + hostId); Answer[] answers = _agentMgr.send(i, cmds); handleCreateTunnelAnswer(answers); @@ -389,13 +383,13 @@ protected void checkAndCreateTunnel(Network nw, Host host) { // anyway. This will ensure VIF rules will be triggered if (noHost) { Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, nw.getId())); - s_logger.debug("Ask host " + hostId + " to configure bridge for network:" + nw.getId()); + logger.debug("Ask host " + hostId + " to configure bridge for network:" + nw.getId()); Answer[] answers = _agentMgr.send(hostId, cmds); handleSetupBridgeAnswer(answers); } } catch (GreTunnelException | OperationTimedoutException | AgentUnavailableException e) { // I really thing we should do a better handling of these exceptions - s_logger.warn("Ovs Tunnel network created tunnel failed", e); + logger.warn("Ovs Tunnel network created tunnel failed", e); } } @@ -425,7 +419,7 @@ private void handleDestroyTunnelAnswer(Answer ans, long from, long to, long netw if (ans.getResult()) { OvsTunnelNetworkVO lock = _tunnelNetworkDao.acquireInLockTable(Long.valueOf(1)); if (lock == null) { - s_logger.warn(String.format("failed to lock" + + logger.warn(String.format("failed to lock" + "ovs_tunnel_account, remove record of " + "tunnel(from=%1$s, to=%2$s account=%3$s) failed", from, to, networkId)); @@ -435,11 +429,11 @@ private void handleDestroyTunnelAnswer(Answer ans, long from, long to, long netw _tunnelNetworkDao.removeByFromToNetwork(from, to, networkId); _tunnelNetworkDao.releaseFromLockTable(lock.getId()); - s_logger.debug(String.format("Destroy tunnel(account:%1$s," + + logger.debug(String.format("Destroy tunnel(account:%1$s," + "from:%2$s, to:%3$s) successful", networkId, from, to)); } else { - s_logger.debug(String.format("Destroy tunnel(account:%1$s," + "from:%2$s, to:%3$s) failed", networkId, from, to)); + logger.debug(String.format("Destroy tunnel(account:%1$s," + "from:%2$s, to:%3$s) failed", networkId, from, to)); } } @@ -449,24 +443,24 @@ private void handleDestroyBridgeAnswer(Answer ans, long hostId, long networkId) if (ans.getResult()) { OvsTunnelNetworkVO lock = _tunnelNetworkDao.acquireInLockTable(Long.valueOf(1)); if (lock == null) { - s_logger.warn("failed to lock ovs_tunnel_network," + "remove record"); + logger.warn("failed to lock ovs_tunnel_network," + "remove record"); return; } _tunnelNetworkDao.removeByFromNetwork(hostId, networkId); _tunnelNetworkDao.releaseFromLockTable(lock.getId()); - s_logger.debug(String.format("Destroy bridge for" + + logger.debug(String.format("Destroy bridge for" + "network %1$s successful", networkId)); } else { - s_logger.debug(String.format("Destroy bridge for" + + logger.debug(String.format("Destroy bridge for" + "network %1$s failed", networkId)); } } private void handleSetupBridgeAnswer(Answer[] answers) { //TODO: Add some error management here? - s_logger.debug("Placeholder for something more meanginful to come"); + logger.debug("Placeholder for something more meanginful to come"); } @Override @@ -493,7 +487,7 @@ public void checkAndRemoveHostFromTunnelNetwork(Network nw, Host host) { if (p.getState().equals(OvsTunnel.State.Established.name())) { Command cmd= new OvsDestroyTunnelCommand(p.getNetworkId(), bridgeName, p.getPortName()); - s_logger.debug("Destroying tunnel to " + host.getId() + + logger.debug("Destroying tunnel to " + host.getId() + " from " + p.getFrom()); Answer ans = _agentMgr.send(p.getFrom(), cmd); handleDestroyTunnelAnswer(ans, p.getFrom(), p.getTo(), p.getNetworkId()); @@ -503,11 +497,11 @@ public void checkAndRemoveHostFromTunnelNetwork(Network nw, Host host) { Command cmd = new OvsDestroyBridgeCommand(nw.getId(), generateBridgeNameForVpc(nw.getVpcId()), host.getId()); - s_logger.debug("Destroying bridge for network " + nw.getId() + " on host:" + host.getId()); + logger.debug("Destroying bridge for network " + nw.getId() + " on host:" + host.getId()); Answer ans = _agentMgr.send(host.getId(), cmd); handleDestroyBridgeAnswer(ans, host.getId(), nw.getId()); } catch (Exception e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "exception while removing host from networks: " + e.getLocalizedMessage()); } } else { @@ -521,7 +515,7 @@ public void checkAndRemoveHostFromTunnelNetwork(Network nw, Host host) { int key = getGreKey(nw); String bridgeName = generateBridgeName(nw, key); Command cmd = new OvsDestroyBridgeCommand(nw.getId(), bridgeName, host.getId()); - s_logger.debug("Destroying bridge for network " + nw.getId() + " on host:" + host.getId()); + logger.debug("Destroying bridge for network " + nw.getId() + " on host:" + host.getId()); Answer ans = _agentMgr.send(host.getId(), cmd); handleDestroyBridgeAnswer(ans, host.getId(), nw.getId()); @@ -534,7 +528,7 @@ public void checkAndRemoveHostFromTunnelNetwork(Network nw, Host host) { if (p.getState().equals(OvsTunnel.State.Established.name())) { cmd = new OvsDestroyTunnelCommand(p.getNetworkId(), bridgeName, p.getPortName()); - s_logger.debug("Destroying tunnel to " + host.getId() + + logger.debug("Destroying tunnel to " + host.getId() + " from " + p.getFrom()); ans = _agentMgr.send(p.getFrom(), cmd); handleDestroyTunnelAnswer(ans, p.getFrom(), @@ -542,7 +536,7 @@ public void checkAndRemoveHostFromTunnelNetwork(Network nw, Host host) { } } } catch (Exception e) { - s_logger.warn("Destroy tunnel failed", e); + logger.warn("Destroy tunnel failed", e); } } } @@ -571,12 +565,12 @@ protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) { // since this is the first VM from the VPC being launched on the host, first setup the bridge try { Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, null)); - s_logger.debug("Ask host " + hostId + " to create bridge for vpc " + vpcId + " and configure the " + logger.debug("Ask host " + hostId + " to create bridge for vpc " + vpcId + " and configure the " + " bridge for distributed routing."); Answer[] answers = _agentMgr.send(hostId, cmds); handleSetupBridgeAnswer(answers); } catch (OperationTimedoutException | AgentUnavailableException e) { - s_logger.warn("Ovs Tunnel network created bridge failed", e); + logger.warn("Ovs Tunnel network created bridge failed", e); } // now that bridge is setup, populate network acl's before the VM gets created @@ -584,7 +578,7 @@ protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) { cmd.setSequenceNumber(getNextRoutingPolicyUpdateSequenceNumber(vpcId)); if (!sendVpcRoutingPolicyChangeUpdate(cmd, hostId, bridgeName)) { - s_logger.debug("Failed to send VPC routing policy change update to host : " + hostId + + logger.debug("Failed to send VPC routing policy change update to host : " + hostId + ". But moving on with sending the updates to the rest of the hosts."); } } @@ -608,7 +602,7 @@ protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) { tunnelRecord = _tunnelNetworkDao.findByFromToNetwork(hostId, rh.longValue(), vpcNetwork.getId()); // Try and create the tunnel if does not exit or previous attempt failed if (tunnelRecord == null || tunnelRecord.getState().equals(OvsTunnel.State.Failed.name())) { - s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue()); + logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue()); if (tunnelRecord == null) { createTunnelRecord(hostId, rh.longValue(), vpcNetwork.getId(), key); } @@ -619,7 +613,7 @@ protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) { tunnelRecord = _tunnelNetworkDao.findByFromToNetwork(rh.longValue(), hostId, vpcNetwork.getId()); // Try and create the tunnel if does not exit or previous attempt failed if (tunnelRecord == null || tunnelRecord.getState().equals(OvsTunnel.State.Failed.name())) { - s_logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId); + logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId); if (tunnelRecord == null) { createTunnelRecord(rh.longValue(), hostId, vpcNetwork.getId(), key); } @@ -645,9 +639,9 @@ protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) { + "Failure is on host:" + rHost.getId()); Commands cmds = new Commands( new OvsCreateTunnelCommand(otherIp, key, Long.valueOf(hostId), i, vpcNetwork.getId(), myIp, bridgeName, vpcNetwork.getUuid())); - s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + vpcNetwork.getId()); - s_logger.debug("Ask host " + hostId + logger.debug("Ask host " + hostId + " to create gre tunnel to " + i); Answer[] answers = _agentMgr.send(hostId, cmds); handleCreateTunnelAnswer(answers); @@ -659,14 +653,14 @@ protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) { Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), vpcNetwork.getId(), otherIp, bridgeName, vpcNetwork.getUuid())); - s_logger.debug("Ask host " + i + " to create gre tunnel to " + logger.debug("Ask host " + i + " to create gre tunnel to " + hostId); Answer[] answers = _agentMgr.send(i, cmds); handleCreateTunnelAnswer(answers); } } catch (GreTunnelException | OperationTimedoutException | AgentUnavailableException e) { // I really thing we should do a better handling of these exceptions - s_logger.warn("Ovs Tunnel network created tunnel failed", e); + logger.warn("Ovs Tunnel network created tunnel failed", e); } } } @@ -723,7 +717,7 @@ private void handleVmStateChange(VMInstanceVO vm) { // send topology change update to VPC spanned hosts for (Long id: vpcSpannedHostIds) { if (!sendVpcTopologyChangeUpdate(topologyConfigCommand, id, bridgeName)) { - s_logger.debug("Failed to send VPC topology change update to host : " + id + ". Moving on " + + logger.debug("Failed to send VPC topology change update to host : " + id + ". Moving on " + "with rest of the host update."); } } @@ -732,19 +726,19 @@ private void handleVmStateChange(VMInstanceVO vm) { public boolean sendVpcTopologyChangeUpdate(OvsVpcPhysicalTopologyConfigCommand updateCmd, long hostId, String bridgeName) { try { - s_logger.debug("Sending VPC topology change update to the host " + hostId); + logger.debug("Sending VPC topology change update to the host " + hostId); updateCmd.setHostId(hostId); updateCmd.setBridgeName(bridgeName); Answer ans = _agentMgr.send(hostId, updateCmd); if (ans.getResult()) { - s_logger.debug("Successfully updated the host " + hostId + " with latest VPC topology." ); + logger.debug("Successfully updated the host " + hostId + " with latest VPC topology." ); return true; } else { - s_logger.debug("Failed to update the host " + hostId + " with latest VPC topology." ); + logger.debug("Failed to update the host " + hostId + " with latest VPC topology." ); return false; } } catch (Exception e) { - s_logger.debug("Failed to updated the host " + hostId + " with latest VPC topology.", e ); + logger.debug("Failed to updated the host " + hostId + " with latest VPC topology.", e ); return false; } } @@ -768,7 +762,7 @@ OvsVpcPhysicalTopologyConfigCommand prepareVpcTopologyUpdate(long vpcId) { try { remoteIp = getGreEndpointIP(hostDetails, network); } catch (Exception e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "error getting GRE endpoint: " + e.getLocalizedMessage()); } } @@ -836,13 +830,13 @@ public void onPublishMessage(String senderAddress, String subject, Object args) List vpcSpannedHostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId); for (Long id: vpcSpannedHostIds) { if (!sendVpcRoutingPolicyChangeUpdate(cmd, id, bridgeName)) { - s_logger.debug("Failed to send VPC routing policy change update to host : " + id + + logger.debug("Failed to send VPC routing policy change update to host : " + id + ". But moving on with sending the updates to the rest of the hosts."); } } } } catch (Exception e) { - s_logger.debug("Failed to send VPC routing policy change updates all hosts in vpc", e); + logger.debug("Failed to send VPC routing policy change updates all hosts in vpc", e); } } } @@ -893,19 +887,19 @@ private OvsVpcRoutingPolicyConfigCommand prepareVpcRoutingPolicyUpdate(long vpcI private boolean sendVpcRoutingPolicyChangeUpdate(OvsVpcRoutingPolicyConfigCommand updateCmd, long hostId, String bridgeName) { try { - s_logger.debug("Sending VPC routing policies change update to the host " + hostId); + logger.debug("Sending VPC routing policies change update to the host " + hostId); updateCmd.setHostId(hostId); updateCmd.setBridgeName(bridgeName); Answer ans = _agentMgr.send(hostId, updateCmd); if (ans.getResult()) { - s_logger.debug("Successfully updated the host " + hostId + " with latest VPC routing policies." ); + logger.debug("Successfully updated the host " + hostId + " with latest VPC routing policies." ); return true; } else { - s_logger.debug("Failed to update the host " + hostId + " with latest routing policies." ); + logger.debug("Failed to update the host " + hostId + " with latest routing policies." ); return false; } } catch (Exception e) { - s_logger.debug("Failed to updated the host " + hostId + " with latest routing policies due to" , e ); + logger.debug("Failed to updated the host " + hostId + " with latest routing policies due to" , e ); return false; } } diff --git a/plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/dao/VpcDistributedRouterSeqNoDaoImpl.java b/plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/dao/VpcDistributedRouterSeqNoDaoImpl.java index 92d1e9717456..eb9cbbc849af 100644 --- a/plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/dao/VpcDistributedRouterSeqNoDaoImpl.java +++ b/plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/dao/VpcDistributedRouterSeqNoDaoImpl.java @@ -17,7 +17,6 @@ package com.cloud.network.ovs.dao; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -26,7 +25,6 @@ @Component public class VpcDistributedRouterSeqNoDaoImpl extends GenericDaoBase implements VpcDistributedRouterSeqNoDao { - protected static final Logger s_logger = Logger.getLogger(VpcDistributedRouterSeqNoDaoImpl.class); private SearchBuilder VpcIdSearch; protected VpcDistributedRouterSeqNoDaoImpl() { diff --git a/plugins/network-elements/palo-alto/pom.xml b/plugins/network-elements/palo-alto/pom.xml index 34fb76e2e6fd..c0d816b4a89f 100644 --- a/plugins/network-elements/palo-alto/pom.xml +++ b/plugins/network-elements/palo-alto/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/AddPaloAltoFirewallCmd.java b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/AddPaloAltoFirewallCmd.java index ba1342496b54..214e35d293ea 100644 --- a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/AddPaloAltoFirewallCmd.java +++ b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/AddPaloAltoFirewallCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -43,7 +42,6 @@ @APICommand(name = "addPaloAltoFirewall", responseObject = PaloAltoFirewallResponse.class, description = "Adds a Palo Alto firewall device", requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class AddPaloAltoFirewallCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddPaloAltoFirewallCmd.class.getName()); @Inject PaloAltoFirewallElementService _paFwService; diff --git a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ConfigurePaloAltoFirewallCmd.java b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ConfigurePaloAltoFirewallCmd.java index a1d8ea87794c..77c96d73fd44 100644 --- a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ConfigurePaloAltoFirewallCmd.java +++ b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ConfigurePaloAltoFirewallCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -43,7 +42,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigurePaloAltoFirewallCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ConfigurePaloAltoFirewallCmd.class.getName()); @Inject PaloAltoFirewallElementService _paFwService; diff --git a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/DeletePaloAltoFirewallCmd.java b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/DeletePaloAltoFirewallCmd.java index 40b930977488..378bad4dad89 100644 --- a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/DeletePaloAltoFirewallCmd.java +++ b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/DeletePaloAltoFirewallCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ @APICommand(name = "deletePaloAltoFirewall", responseObject = SuccessResponse.class, description = " delete a Palo Alto firewall device", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePaloAltoFirewallCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePaloAltoFirewallCmd.class.getName()); @Inject PaloAltoFirewallElementService _paElementService; diff --git a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ListPaloAltoFirewallNetworksCmd.java b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ListPaloAltoFirewallNetworksCmd.java index e2d5f96f06fc..f319d2ae6d4c 100644 --- a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ListPaloAltoFirewallNetworksCmd.java +++ b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ListPaloAltoFirewallNetworksCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -47,7 +46,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPaloAltoFirewallNetworksCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListPaloAltoFirewallNetworksCmd.class.getName()); @Inject PaloAltoFirewallElementService _paFwService; diff --git a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ListPaloAltoFirewallsCmd.java b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ListPaloAltoFirewallsCmd.java index cce3ac2b36b1..a3e77dba2bd0 100644 --- a/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ListPaloAltoFirewallsCmd.java +++ b/plugins/network-elements/palo-alto/src/main/java/com/cloud/api/commands/ListPaloAltoFirewallsCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -46,7 +45,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPaloAltoFirewallsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListPaloAltoFirewallsCmd.class.getName()); private static final String s_name = "listpaloaltofirewallresponse"; @Inject PaloAltoFirewallElementService _paFwService; diff --git a/plugins/network-elements/palo-alto/src/main/java/com/cloud/network/element/PaloAltoExternalFirewallElement.java b/plugins/network-elements/palo-alto/src/main/java/com/cloud/network/element/PaloAltoExternalFirewallElement.java index d631d9921017..c81ac5f5f0c3 100644 --- a/plugins/network-elements/palo-alto/src/main/java/com/cloud/network/element/PaloAltoExternalFirewallElement.java +++ b/plugins/network-elements/palo-alto/src/main/java/com/cloud/network/element/PaloAltoExternalFirewallElement.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice; @@ -85,7 +84,6 @@ public class PaloAltoExternalFirewallElement extends ExternalFirewallDeviceManagerImpl implements SourceNatServiceProvider, FirewallServiceProvider, PortForwardingServiceProvider, IpDeployer, PaloAltoFirewallElementService, StaticNatServiceProvider { - private static final Logger s_logger = Logger.getLogger(PaloAltoExternalFirewallElement.class); private static final Map> capabilities = setCapabilities(); @@ -121,18 +119,18 @@ public class PaloAltoExternalFirewallElement extends ExternalFirewallDeviceManag private boolean canHandle(Network network, Service service) { DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); if (zone.getNetworkType() == NetworkType.Advanced && network.getGuestType() != Network.GuestType.Isolated) { - s_logger.trace("Element " + getProvider().getName() + "is not handling network type = " + network.getGuestType()); + logger.trace("Element " + getProvider().getName() + "is not handling network type = " + network.getGuestType()); return false; } if (service == null) { if (!_networkManager.isProviderForNetwork(getProvider(), network.getId())) { - s_logger.trace("Element " + getProvider().getName() + " is not a provider for the network " + network); + logger.trace("Element " + getProvider().getName() + " is not a provider for the network " + network); return false; } } else { if (!_networkManager.isProviderSupportServiceInNetwork(network.getId(), service, getProvider())) { - s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName() + " in the network " + network); + logger.trace("Element " + getProvider().getName() + " doesn't support service " + service.getName() + " in the network " + network); return false; } } @@ -147,7 +145,7 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin // don't have to implement network is Basic zone if (zone.getNetworkType() == NetworkType.Basic) { - s_logger.debug("Not handling network implement in zone of type " + NetworkType.Basic); + logger.debug("Not handling network implement in zone of type " + NetworkType.Basic); return false; } @@ -160,7 +158,7 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin } catch (InsufficientCapacityException capacityException) { // TODO: handle out of capacity exception in more gracefule manner when multiple providers are present for // the network - s_logger.error("Fail to implement the Palo Alto for network " + network, capacityException); + logger.error("Fail to implement the Palo Alto for network " + network, capacityException); return false; } } @@ -182,7 +180,7 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle // don't have to implement network is Basic zone if (zone.getNetworkType() == NetworkType.Basic) { - s_logger.debug("Not handling network shutdown in zone of type " + NetworkType.Basic); + logger.debug("Not handling network shutdown in zone of type " + NetworkType.Basic); return false; } @@ -430,7 +428,7 @@ public PaloAltoFirewallResponse createPaloAltoFirewallResponse(ExternalFirewallD @Override public boolean verifyServicesCombination(Set services) { if (!services.contains(Service.Firewall)) { - s_logger.warn("Palo Alto must be used as Firewall Service Provider in the network"); + logger.warn("Palo Alto must be used as Firewall Service Provider in the network"); return false; } return true; diff --git a/plugins/network-elements/palo-alto/src/main/java/com/cloud/network/resource/PaloAltoResource.java b/plugins/network-elements/palo-alto/src/main/java/com/cloud/network/resource/PaloAltoResource.java index ca45ddb66473..9e60db93efd5 100644 --- a/plugins/network-elements/palo-alto/src/main/java/com/cloud/network/resource/PaloAltoResource.java +++ b/plugins/network-elements/palo-alto/src/main/java/com/cloud/network/resource/PaloAltoResource.java @@ -52,7 +52,8 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -109,7 +110,7 @@ public class PaloAltoResource implements ServerResource { private String _threatProfile; private String _logProfile; private String _pingManagementProfile; - private static final Logger s_logger = Logger.getLogger(PaloAltoResource.class); + protected Logger logger = LogManager.getLogger(getClass()); private static String s_apiUri = "/api"; private static HttpClient s_httpclient; @@ -377,7 +378,7 @@ private boolean refreshPaloAltoConnection() { try { return login(_username, _password); } catch (ExecutionException e) { - s_logger.error("Failed to login due to " + e.getMessage()); + logger.error("Failed to login due to " + e.getMessage()); return false; } } @@ -487,11 +488,11 @@ private Answer execute(IpAssocCommand cmd, int numRetries) { results[i++] = ip.getPublicIp() + " - success"; } catch (ExecutionException e) { - s_logger.error(e); + logger.error(e); if (numRetries > 0 && refreshPaloAltoConnection()) { int numRetriesRemaining = numRetries - 1; - s_logger.debug("Retrying IPAssocCommand. Number of retries remaining: " + numRetriesRemaining); + logger.debug("Retrying IPAssocCommand. Number of retries remaining: " + numRetriesRemaining); return execute(cmd, numRetriesRemaining); } else { results[i++] = IpAssocAnswer.errorResult; @@ -516,7 +517,7 @@ private void implementGuestNetwork(ArrayList cmdList, GuestNet String msg = "Implemented guest network with type " + type + ". Guest VLAN tag: " + privateVlanTag + ", guest gateway: " + privateGateway + "/" + privateCidrNumber; msg += type.equals(GuestNetworkType.SOURCE_NAT) ? ", source NAT IP: " + publicIp : ""; - s_logger.debug(msg); + logger.debug(msg); } private void shutdownGuestNetwork(ArrayList cmdList, GuestNetworkType type, Long publicVlanTag, String sourceNatIpAddress, long privateVlanTag, @@ -536,7 +537,7 @@ private void shutdownGuestNetwork(ArrayList cmdList, GuestNetw String msg = "Shut down guest network with type " + type + ". Guest VLAN tag: " + privateVlanTag + ", guest gateway: " + privateGateway + "/" + privateCidrSize; msg += type.equals(GuestNetworkType.SOURCE_NAT) ? ", source NAT IP: " + sourceNatIpAddress : ""; - s_logger.debug(msg); + logger.debug(msg); } /* @@ -564,11 +565,11 @@ private Answer execute(SetFirewallRulesCommand cmd, int numRetries) { return new Answer(cmd); } catch (ExecutionException e) { - s_logger.error(e); + logger.error(e); if (numRetries > 0 && refreshPaloAltoConnection()) { int numRetriesRemaining = numRetries - 1; - s_logger.debug("Retrying SetFirewallRulesCommand. Number of retries remaining: " + numRetriesRemaining); + logger.debug("Retrying SetFirewallRulesCommand. Number of retries remaining: " + numRetriesRemaining); return execute(cmd, numRetriesRemaining); } else { return new Answer(cmd, e); @@ -603,11 +604,11 @@ private Answer execute(SetStaticNatRulesCommand cmd, int numRetries) { return new Answer(cmd); } catch (ExecutionException e) { - s_logger.error(e); + logger.error(e); if (numRetries > 0 && refreshPaloAltoConnection()) { int numRetriesRemaining = numRetries - 1; - s_logger.debug("Retrying SetStaticNatRulesCommand. Number of retries remaining: " + numRetriesRemaining); + logger.debug("Retrying SetStaticNatRulesCommand. Number of retries remaining: " + numRetriesRemaining); return execute(cmd, numRetriesRemaining); } else { return new Answer(cmd, e); @@ -641,11 +642,11 @@ private Answer execute(SetPortForwardingRulesCommand cmd, int numRetries) { return new Answer(cmd); } catch (ExecutionException e) { - s_logger.error(e); + logger.error(e); if (numRetries > 0 && refreshPaloAltoConnection()) { int numRetriesRemaining = numRetries - 1; - s_logger.debug("Retrying SetPortForwardingRulesCommand. Number of retries remaining: " + numRetriesRemaining); + logger.debug("Retrying SetPortForwardingRulesCommand. Number of retries remaining: " + numRetriesRemaining); return execute(cmd, numRetriesRemaining); } else { return new Answer(cmd, e); @@ -678,7 +679,7 @@ public boolean managePrivateInterface(ArrayList cmdList, PaloA "']/layer3/units/entry[@name='" + interfaceName + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Private sub-interface exists: " + interfaceName + ", " + result); + logger.debug("Private sub-interface exists: " + interfaceName + ", " + result); return result; case ADD: @@ -763,7 +764,7 @@ public boolean managePrivateInterface(ArrayList cmdList, PaloA return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -796,7 +797,7 @@ public boolean managePublicInterface(ArrayList cmdList, PaloAl "']/layer3/units/entry[@name='" + interfaceName + "']/ip/entry[@name='" + publicIp + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Public sub-interface & IP exists: " + interfaceName + " : " + publicIp + ", " + result); + logger.debug("Public sub-interface & IP exists: " + interfaceName + " : " + publicIp + ", " + result); return result; case ADD: @@ -855,7 +856,7 @@ public boolean managePublicInterface(ArrayList cmdList, PaloAl return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -888,7 +889,7 @@ public boolean manageSrcNatRule(ArrayList cmdList, PaloAltoPri params.put("xpath", "/config/devices/entry/vsys/entry[@name='vsys1']/rulebase/nat/rules/entry[@name='" + srcNatName + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Source NAT exists: " + srcNatName + ", " + result); + logger.debug("Source NAT exists: " + srcNatName + ", " + result); return result; case ADD: @@ -932,7 +933,7 @@ public boolean manageSrcNatRule(ArrayList cmdList, PaloAltoPri return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -971,7 +972,7 @@ public boolean manageDstNatRule(ArrayList cmdList, PaloAltoPri params.put("xpath", "/config/devices/entry/vsys/entry[@name='vsys1']/rulebase/nat/rules/entry[@name='" + dstNatName + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Destination NAT exists: " + dstNatName + ", " + result); + logger.debug("Destination NAT exists: " + dstNatName + ", " + result); return result; case ADD: @@ -1079,7 +1080,7 @@ public boolean manageDstNatRule(ArrayList cmdList, PaloAltoPri return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -1118,7 +1119,7 @@ public boolean manageStcNatRule(ArrayList cmdList, PaloAltoPri params.put("xpath", "/config/devices/entry/vsys/entry[@name='vsys1']/rulebase/nat/rules/entry[@name='" + stcNatName + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Static NAT exists: " + stcNatName + ", " + result); + logger.debug("Static NAT exists: " + stcNatName + ", " + result); return result; case ADD: @@ -1178,7 +1179,7 @@ public boolean manageStcNatRule(ArrayList cmdList, PaloAltoPri return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -1212,7 +1213,7 @@ public boolean manageFirewallRule(ArrayList cmdList, PaloAltoP params.put("xpath", "/config/devices/entry/vsys/entry[@name='vsys1']/rulebase/security/rules/entry[@name='" + ruleName + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Firewall policy exists: " + ruleName + ", " + result); + logger.debug("Firewall policy exists: " + ruleName + ", " + result); return result; case ADD: @@ -1333,7 +1334,7 @@ public boolean manageFirewallRule(ArrayList cmdList, PaloAltoP // there is an existing default rule, so we need to remove it and add it back after the new rule is added. if (has_default) { - s_logger.debug("Moving the default egress rule after the new rule: " + ruleName); + logger.debug("Moving the default egress rule after the new rule: " + ruleName); NodeList response_body; Document doc = getDocument(e_response); XPath xpath = XPathFactory.newInstance().newXPath(); @@ -1372,7 +1373,7 @@ public boolean manageFirewallRule(ArrayList cmdList, PaloAltoP da_params.put("xpath", "/config/devices/entry/vsys/entry[@name='vsys1']/rulebase/security/rules/entry[@name='policy_0_" + rule.getSrcVlanTag() + "']"); da_params.put("element", defaultEgressRule); cmdList.add(new DefaultPaloAltoCommand(PaloAltoMethod.POST, da_params)); - s_logger.debug("Completed move of the default egress rule after rule: " + ruleName); + logger.debug("Completed move of the default egress rule after rule: " + ruleName); } return true; @@ -1391,7 +1392,7 @@ public boolean manageFirewallRule(ArrayList cmdList, PaloAltoP return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -1444,7 +1445,7 @@ public boolean manageNetworkIsolation(ArrayList cmdList, PaloA params.put("xpath", "/config/devices/entry/vsys/entry[@name='vsys1']/rulebase/security/rules/entry[@name='" + ruleName + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Firewall policy exists: " + ruleName + ", " + result); + logger.debug("Firewall policy exists: " + ruleName + ", " + result); return result; case ADD: @@ -1486,7 +1487,7 @@ public boolean manageNetworkIsolation(ArrayList cmdList, PaloA return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -1503,7 +1504,7 @@ public boolean managePingProfile(ArrayList cmdList, PaloAltoPr params.put("xpath", "/config/devices/entry/network/profiles/interface-management-profile/entry[@name='" + _pingManagementProfile + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Management profile exists: " + _pingManagementProfile + ", " + result); + logger.debug("Management profile exists: " + _pingManagementProfile + ", " + result); return result; case ADD: @@ -1536,7 +1537,7 @@ public boolean managePingProfile(ArrayList cmdList, PaloAltoPr return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -1565,7 +1566,7 @@ public boolean manageService(ArrayList cmdList, PaloAltoPrimat params.put("xpath", "/config/devices/entry/vsys/entry[@name='vsys1']/service/entry[@name='" + serviceName + "']"); String response = request(PaloAltoMethod.GET, params); boolean result = (validResponse(response) && responseNotEmpty(response)); - s_logger.debug("Service exists: " + serviceName + ", " + result); + logger.debug("Service exists: " + serviceName + ", " + result); return result; case ADD: @@ -1604,7 +1605,7 @@ public boolean manageService(ArrayList cmdList, PaloAltoPrimat return true; default: - s_logger.debug("Unrecognized command."); + logger.debug("Unrecognized command."); return false; } } @@ -1711,7 +1712,7 @@ protected String request(PaloAltoMethod method, Map params) thro debug_msg = debug_msg + prettyFormat(responseBody); debug_msg = debug_msg + "\n" + responseBody.replace("\"", "\\\"") + "\n\n"; // test cases - //s_logger.debug(debug_msg); // this can be commented if we don't want to show each request in the log. + //logger.debug(debug_msg); // this can be commented if we don't want to show each request in the log. return responseBody; } @@ -2064,7 +2065,7 @@ private Document getDocument(String xml) throws ExecutionException { try { doc = ParserUtils.getSaferDocumentBuilderFactory().newDocumentBuilder().parse(xmlSource); } catch (Exception e) { - s_logger.error(e); + logger.error(e); throw new ExecutionException(e.getMessage()); } diff --git a/plugins/network-elements/palo-alto/src/test/java/com/cloud/network/resource/PaloAltoResourceTest.java b/plugins/network-elements/palo-alto/src/test/java/com/cloud/network/resource/PaloAltoResourceTest.java index 931e6ccaed00..58f962f13727 100644 --- a/plugins/network-elements/palo-alto/src/test/java/com/cloud/network/resource/PaloAltoResourceTest.java +++ b/plugins/network-elements/palo-alto/src/test/java/com/cloud/network/resource/PaloAltoResourceTest.java @@ -98,7 +98,7 @@ public void setUp() { _context.put("public_using_ethernet", "true"); _context.put("private_using_ethernet", "true"); _context.put("has_management_profile", "true"); - _context.put("enable_console_output", "false"); // CHANGE TO "true" TO ENABLE CONSOLE LOGGING OF TESTS + _context.put("enable_console_output", "false"); // CHANGE TO "true" TO ENABLE CONSOLE loggerGING OF TESTS _resource.setMockContext(_context); } diff --git a/plugins/network-elements/stratosphere-ssp/pom.xml b/plugins/network-elements/stratosphere-ssp/pom.xml index 67b97ae0d3da..7e16b525dbb7 100644 --- a/plugins/network-elements/stratosphere-ssp/pom.xml +++ b/plugins/network-elements/stratosphere-ssp/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/api/commands/AddSspCmd.java b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/api/commands/AddSspCmd.java index 8558c8c05222..7b4e2b1a30f4 100644 --- a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/api/commands/AddSspCmd.java +++ b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/api/commands/AddSspCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ @APICommand(name = "addStratosphereSsp", responseObject = SspResponse.class, description = "Adds stratosphere ssp server", requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class AddSspCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(AddSspCmd.class.getName()); @Inject SspService _service; @Inject @@ -77,7 +75,7 @@ public long getEntityOwnerId() { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { - s_logger.trace("execute"); + logger.trace("execute"); Host host = _service.addSspHost(this); SspResponse response = new SspResponse(); response.setResponseName(getCommandName()); diff --git a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/api/commands/DeleteSspCmd.java b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/api/commands/DeleteSspCmd.java index 3faa0922338f..c4d13140546f 100644 --- a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/api/commands/DeleteSspCmd.java +++ b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/api/commands/DeleteSspCmd.java @@ -18,7 +18,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "deleteStratosphereSsp", responseObject = SuccessResponse.class, description = "Removes stratosphere ssp server", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSspCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(DeleteSspCmd.class.getName()); @Inject SspService _service; @@ -58,7 +56,7 @@ public long getEntityOwnerId() { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { - s_logger.trace("execute"); + logger.trace("execute"); SuccessResponse resp = new SuccessResponse(); resp.setSuccess(_service.deleteSspHost(this)); this.setResponseObject(resp); diff --git a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/dao/SspUuidDaoImpl.java b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/dao/SspUuidDaoImpl.java index 91d60913103f..dccc1d7ffa90 100644 --- a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/dao/SspUuidDaoImpl.java +++ b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/dao/SspUuidDaoImpl.java @@ -19,7 +19,6 @@ import java.util.List; -import org.apache.log4j.Logger; import com.cloud.network.Network; import com.cloud.utils.db.GenericDaoBase; @@ -30,7 +29,6 @@ public class SspUuidDaoImpl extends GenericDaoBase implements SspUuidDao { - private static final Logger s_logger = Logger.getLogger(SspUuidDaoImpl.class); protected final SearchBuilder native2uuid; protected final SearchBuilder uuid2native; diff --git a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/element/SspClient.java b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/element/SspClient.java index 30630a35d69b..c60813badf62 100644 --- a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/element/SspClient.java +++ b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/element/SspClient.java @@ -40,7 +40,8 @@ import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.message.BasicNameValuePair; import org.apache.http.params.CoreConnectionPNames; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; @@ -49,7 +50,7 @@ * Stratosphere sdn platform api client */ public class SspClient { - private static final Logger s_logger = Logger.getLogger(SspClient.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final HttpClient s_client = new DefaultHttpClient( new PoolingClientConnectionManager()); static { @@ -79,27 +80,27 @@ private String executeMethod(HttpRequestBase req, String path) { req.setURI(new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), path, null, null)); } catch (URISyntaxException e) { - s_logger.error("invalid API URL " + apiUrl + " path " + path, e); + logger.error("invalid API URL " + apiUrl + " path " + path, e); return null; } try { String content = null; try { content = getHttpClient().execute(req, new BasicResponseHandler()); - s_logger.info("ssp api call: " + req); + logger.info("ssp api call: " + req); } catch (HttpResponseException e) { - s_logger.info("ssp api call failed: " + req, e); + logger.info("ssp api call failed: " + req, e); if (e.getStatusCode() == HttpStatus.SC_UNAUTHORIZED && login()) { req.reset(); content = getHttpClient().execute(req, new BasicResponseHandler()); - s_logger.info("ssp api retry call: " + req); + logger.info("ssp api retry call: " + req); } } return content; } catch (ClientProtocolException e) { // includes HttpResponseException - s_logger.error("ssp api call failed: " + req, e); + logger.error("ssp api call failed: " + req, e); } catch (IOException e) { - s_logger.error("ssp api call failed: " + req, e); + logger.error("ssp api call failed: " + req, e); } return null; } @@ -111,7 +112,7 @@ public boolean login() { new BasicNameValuePair("username", username), new BasicNameValuePair("password", password)))); } catch (UnsupportedEncodingException e) { - s_logger.error("invalid username or password", e); + logger.error("invalid username or password", e); return false; } if (executeMethod(method, "/ws.v1/login") != null) { diff --git a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/element/SspElement.java b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/element/SspElement.java index 475c0d4e061a..bfe9de2c837f 100644 --- a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/element/SspElement.java +++ b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/element/SspElement.java @@ -29,7 +29,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.commands.AddSspCmd; import org.apache.cloudstack.api.commands.DeleteSspCmd; @@ -87,7 +86,6 @@ * table for that information. */ public class SspElement extends AdapterBase implements ConnectivityProvider, SspManager, SspService, NetworkMigrationResponder { - private static final Logger s_logger = Logger.getLogger(SspElement.class); public static final String s_SSP_NAME = "StratosphereSsp"; private static final Provider s_ssp_provider = new Provider(s_SSP_NAME, false); @@ -180,7 +178,7 @@ public boolean isReady(PhysicalNetworkServiceProvider provider) { if (fetchSspClients(physicalNetwork.getId(), physicalNetwork.getDataCenterId(), false).size() > 0) { return true; } - s_logger.warn("Ssp api endpoint not found. " + physicalNetwork.toString()); + logger.warn("Ssp api endpoint not found. " + physicalNetwork.toString()); return false; } @@ -194,9 +192,9 @@ public boolean canHandle(PhysicalNetwork physicalNetwork) { if (fetchSspClients(physicalNetwork.getId(), physicalNetwork.getDataCenterId(), true).size() > 0) { return true; } - s_logger.warn("enabled Ssp api endpoint not found. " + physicalNetwork.toString()); + logger.warn("enabled Ssp api endpoint not found. " + physicalNetwork.toString()); } else { - s_logger.warn("PhysicalNetwork is NULL."); + logger.warn("PhysicalNetwork is NULL."); } return false; } @@ -204,7 +202,7 @@ public boolean canHandle(PhysicalNetwork physicalNetwork) { private boolean canHandle(Network network) { if (canHandle(_physicalNetworkDao.findById(network.getPhysicalNetworkId()))) { if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), Service.Connectivity, getProvider())) { - s_logger.info("SSP is implicitly active for " + network); + logger.info("SSP is implicitly active for " + network); } return true; } @@ -231,7 +229,7 @@ public Host addSspHost(AddSspCmd cmd) { _sspCredentialDao.persist(credential); } else { if (cmd.getUsername() != null || cmd.getPassword() != null) { - s_logger.warn("Tenant credential already configured for zone:" + zoneId); + logger.warn("Tenant credential already configured for zone:" + zoneId); } } @@ -246,7 +244,7 @@ public Host addSspHost(AddSspCmd cmd) { _sspTenantDao.persist(tenant); } else { if (cmd.getTenantUuid() != null) { - s_logger.warn("Tenant uuid already configured for zone:" + zoneId); + logger.warn("Tenant uuid already configured for zone:" + zoneId); } } @@ -266,7 +264,7 @@ public Host addSspHost(AddSspCmd cmd) { _hostDao.loadDetails(host); if ("v1Api".equals(host.getDetail("sspHost"))) { if (normalizedUrl.equals(host.getDetail("url"))) { - s_logger.warn("Ssp host already registered " + normalizedUrl); + logger.warn("Ssp host already registered " + normalizedUrl); return host; } } @@ -289,14 +287,14 @@ public Host addSspHost(AddSspCmd cmd) { @Override public boolean deleteSspHost(DeleteSspCmd cmd) { - s_logger.info("deleteStratosphereSsp"); + logger.info("deleteStratosphereSsp"); return _hostDao.remove(cmd.getHostId()); } @Override public boolean createNetwork(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) { if (_sspUuidDao.findUuidByNetwork(network) != null) { - s_logger.info("Network already has ssp TenantNetwork uuid :" + network.toString()); + logger.info("Network already has ssp TenantNetwork uuid :" + network.toString()); return true; } if (!canHandle(network)) { @@ -322,10 +320,10 @@ public boolean createNetwork(Network network, NetworkOffering offering, DeployDe processed = true; } if (processed) { - s_logger.error("Could not allocate an uuid for network " + network.toString()); + logger.error("Could not allocate an uuid for network " + network.toString()); return false; } else { - s_logger.error("Skipping #createNetwork() for " + network.toString()); + logger.error("Skipping #createNetwork() for " + network.toString()); return true; } } @@ -343,10 +341,10 @@ public boolean deleteNetwork(Network network) { } } if (!processed) { - s_logger.error("Ssp api tenant network deletion failed " + network.toString()); + logger.error("Ssp api tenant network deletion failed " + network.toString()); } } else { - s_logger.debug("Silently skipping #deleteNetwork() for " + network.toString()); + logger.debug("Silently skipping #deleteNetwork() for " + network.toString()); } return true; } @@ -356,7 +354,7 @@ public boolean deleteNetwork(Network network) { public boolean createNicEnv(Network network, NicProfile nic, DeployDestination dest, ReservationContext context) { String tenantNetworkUuid = _sspUuidDao.findUuidByNetwork(network); if (tenantNetworkUuid == null) { - s_logger.debug("Skipping #createNicEnv() for nic on " + network.toString()); + logger.debug("Skipping #createNicEnv() for nic on " + network.toString()); return true; } @@ -364,7 +362,7 @@ public boolean createNicEnv(Network network, NicProfile nic, DeployDestination d List tenantPortUuidVos = _sspUuidDao.listUUidVoByNicProfile(nic); for (SspUuidVO tenantPortUuidVo : tenantPortUuidVos) { if (reservationId.equals(tenantPortUuidVo.getReservationId())) { - s_logger.info("Skipping because reservation found " + reservationId); + logger.info("Skipping because reservation found " + reservationId); return true; } } @@ -386,7 +384,7 @@ public boolean createNicEnv(Network network, NicProfile nic, DeployDestination d } } if (tenantPortUuid == null) { - s_logger.debug("#createNicEnv() failed for nic on " + network.toString()); + logger.debug("#createNicEnv() failed for nic on " + network.toString()); return false; } @@ -400,14 +398,14 @@ public boolean createNicEnv(Network network, NicProfile nic, DeployDestination d return true; } } - s_logger.error("Updating vif failed " + nic.toString()); + logger.error("Updating vif failed " + nic.toString()); return false; } @Override public boolean deleteNicEnv(Network network, NicProfile nic, ReservationContext context) { if (context == null) { - s_logger.error("ReservationContext was null for " + nic + " " + network); + logger.error("ReservationContext was null for " + nic + " " + network); return false; } String reservationId = context.getReservationId(); @@ -434,7 +432,7 @@ public boolean deleteNicEnv(Network network, NicProfile nic, ReservationContext } } if (!processed) { - s_logger.warn("Ssp api nic detach failed " + nic.toString()); + logger.warn("Ssp api nic detach failed " + nic.toString()); } processed = false; for (SspClient client : fetchSspClients(network.getPhysicalNetworkId(), network.getDataCenterId(), true)) { @@ -445,7 +443,7 @@ public boolean deleteNicEnv(Network network, NicProfile nic, ReservationContext } } if (!processed) { - s_logger.warn("Ssp api tenant port deletion failed " + nic.toString()); + logger.warn("Ssp api tenant port deletion failed " + nic.toString()); } _sspUuidDao.removeUuid(tenantPortUuid); } @@ -467,7 +465,7 @@ public boolean deleteNicEnv(Network network, NicProfile nic, ReservationContext @Override public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - s_logger.info("implement"); + logger.info("implement"); return createNetwork(network, offering, dest, context); } @@ -480,7 +478,7 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin */ @Override public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { - s_logger.trace("shutdown"); + logger.trace("shutdown"); return deleteNetwork(network); } @@ -494,7 +492,7 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle @Override public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - s_logger.trace("prepare"); + logger.trace("prepare"); return createNicEnv(network, nic, dest, context); } @@ -508,7 +506,7 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm @Override public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - s_logger.trace("release"); + logger.trace("release"); return deleteNicEnv(network, nic, context); } @@ -520,7 +518,7 @@ public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm */ @Override public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - s_logger.trace("destroy"); + logger.trace("destroy"); // nothing to do here. return true; } @@ -528,19 +526,19 @@ public boolean destroy(Network network, ReservationContext context) throws Concu @Override public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - s_logger.trace("shutdownProviderInstances"); + logger.trace("shutdownProviderInstances"); return true; } @Override public boolean canEnableIndividualServices() { - s_logger.trace("canEnableIndividualServices"); + logger.trace("canEnableIndividualServices"); return true; // because there is only Connectivity } @Override public boolean verifyServicesCombination(Set services) { - s_logger.trace("verifyServicesCombination " + services.toString()); + logger.trace("verifyServicesCombination " + services.toString()); return true; } @@ -549,13 +547,13 @@ public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineP try { prepare(network, nic, vm, dest, context); } catch (ConcurrentOperationException e) { - s_logger.error("prepareForMigration failed.", e); + logger.error("prepareForMigration failed.", e); return false; } catch (ResourceUnavailableException e) { - s_logger.error("prepareForMigration failed.", e); + logger.error("prepareForMigration failed.", e); return false; } catch (InsufficientCapacityException e) { - s_logger.error("prepareForMigration failed.", e); + logger.error("prepareForMigration failed.", e); return false; } return true; @@ -566,9 +564,9 @@ public void rollbackMigration(NicProfile nic, Network network, VirtualMachinePro try { release(network, nic, vm, dst); } catch (ConcurrentOperationException e) { - s_logger.error("rollbackMigration failed.", e); + logger.error("rollbackMigration failed.", e); } catch (ResourceUnavailableException e) { - s_logger.error("rollbackMigration failed.", e); + logger.error("rollbackMigration failed.", e); } } @@ -577,9 +575,9 @@ public void commitMigration(NicProfile nic, Network network, VirtualMachineProfi try { release(network, nic, vm, src); } catch (ConcurrentOperationException e) { - s_logger.error("commitMigration failed.", e); + logger.error("commitMigration failed.", e); } catch (ResourceUnavailableException e) { - s_logger.error("commitMigration failed.", e); + logger.error("commitMigration failed.", e); } } diff --git a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/guru/SspGuestNetworkGuru.java b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/guru/SspGuestNetworkGuru.java index 9ede8cc5a3e6..894c258939e2 100644 --- a/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/guru/SspGuestNetworkGuru.java +++ b/plugins/network-elements/stratosphere-ssp/src/main/java/org/apache/cloudstack/network/guru/SspGuestNetworkGuru.java @@ -35,7 +35,6 @@ import com.cloud.vm.VirtualMachineProfile; import org.apache.cloudstack.network.element.SspElement; import org.apache.cloudstack.network.element.SspManager; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -43,7 +42,6 @@ * Stratosphere SDN Platform NetworkGuru */ public class SspGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigrationResponder { - private static final Logger s_logger = Logger.getLogger(SspGuestNetworkGuru.class); @Inject SspManager _sspMgr; @@ -59,7 +57,7 @@ public SspGuestNetworkGuru() { @Override protected boolean canHandle(NetworkOffering offering, NetworkType networkType, PhysicalNetwork physicalNetwork) { - s_logger.trace("canHandle"); + logger.trace("canHandle"); String setting = null; if (physicalNetwork != null && physicalNetwork.getIsolationMethods().contains("SSP")) { @@ -70,18 +68,18 @@ protected boolean canHandle(NetworkOffering offering, NetworkType networkType, P } if (setting != null) { if (networkType != NetworkType.Advanced) { - s_logger.info("SSP enebled by " + setting + " but not active because networkType was " + networkType); + logger.info("SSP enebled by " + setting + " but not active because networkType was " + networkType); } else if (!isMyTrafficType(offering.getTrafficType())) { - s_logger.info("SSP enabled by " + setting + " but not active because traffic type not Guest"); + logger.info("SSP enabled by " + setting + " but not active because traffic type not Guest"); } else if (offering.getGuestType() != Network.GuestType.Isolated) { - s_logger.info("SSP works for network isolatation."); + logger.info("SSP works for network isolatation."); } else if (!_sspMgr.canHandle(physicalNetwork)) { - s_logger.info("SSP manager not ready"); + logger.info("SSP manager not ready"); } else { return true; } } else { - s_logger.debug("SSP not configured to be active"); + logger.debug("SSP not configured to be active"); } return false; } @@ -96,7 +94,7 @@ protected boolean canHandle(NetworkOffering offering, NetworkType networkType, P @Override public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException { - s_logger.trace("implement " + network.toString()); + logger.trace("implement " + network.toString()); super.implement(network, offering, dest, context); _sspMgr.createNetwork(network, offering, dest, context); return network; @@ -104,7 +102,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin @Override public void shutdown(NetworkProfile profile, NetworkOffering offering) { - s_logger.trace("shutdown " + profile.toString()); + logger.trace("shutdown " + profile.toString()); _sspMgr.deleteNetwork(profile); super.shutdown(profile, offering); } @@ -133,10 +131,10 @@ public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineP try { reserve(nic, network, vm, dest, context); } catch (InsufficientVirtualNetworkCapacityException e) { - s_logger.error("prepareForMigration failed", e); + logger.error("prepareForMigration failed", e); return false; } catch (InsufficientAddressCapacityException e) { - s_logger.error("prepareForMigration failed", e); + logger.error("prepareForMigration failed", e); return false; } return true; diff --git a/plugins/network-elements/tungsten/pom.xml b/plugins/network-elements/tungsten/pom.xml index 92e520a0ffd4..1cd1ae2d823f 100644 --- a/plugins/network-elements/tungsten/pom.xml +++ b/plugins/network-elements/tungsten/pom.xml @@ -26,7 +26,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -36,5 +36,14 @@ juniper-tungsten-api 2.0 + + ch.qos.reload4j + reload4j + + + mysql + mysql-connector-java + test + diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/AddTungstenFabricNetworkGatewayToLogicalRouterCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/AddTungstenFabricNetworkGatewayToLogicalRouterCmd.java index 54d6bbc0d79a..d3357d4f2db7 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/AddTungstenFabricNetworkGatewayToLogicalRouterCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/AddTungstenFabricNetworkGatewayToLogicalRouterCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricLogicalRouterResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.List; @@ -43,7 +42,6 @@ @APICommand(name = AddTungstenFabricNetworkGatewayToLogicalRouterCmd.APINAME, description = "add Tungsten-Fabric network gateway to logical router", responseObject = TungstenFabricLogicalRouterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddTungstenFabricNetworkGatewayToLogicalRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddTungstenFabricNetworkGatewayToLogicalRouterCmd.class.getName()); public static final String APINAME = "addTungstenFabricNetworkGatewayToLogicalRouter"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/AddTungstenFabricPolicyRuleCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/AddTungstenFabricPolicyRuleCmd.java index 194157c3f66b..8c3235ef17e0 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/AddTungstenFabricPolicyRuleCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/AddTungstenFabricPolicyRuleCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricRuleResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -42,7 +41,6 @@ responseObject = TungstenFabricRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddTungstenFabricPolicyRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddTungstenFabricPolicyRuleCmd.class.getName()); public static final String APINAME = "addTungstenFabricPolicyRule"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ApplyTungstenFabricPolicyCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ApplyTungstenFabricPolicyCmd.java index 063e6c09a41f..7327606b1884 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ApplyTungstenFabricPolicyCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ApplyTungstenFabricPolicyCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricPolicyResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -41,7 +40,6 @@ responseObject = TungstenFabricPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ApplyTungstenFabricPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ApplyTungstenFabricPolicyCmd.class.getName()); public static final String APINAME = "applyTungstenFabricPolicy"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ApplyTungstenFabricTagCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ApplyTungstenFabricTagCmd.java index 1bad31869ae1..ee30af45fc00 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ApplyTungstenFabricTagCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ApplyTungstenFabricTagCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricTagResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.List; @@ -42,7 +41,6 @@ @APICommand(name = ApplyTungstenFabricTagCmd.APINAME, description = "apply Tungsten-Fabric tag", responseObject = TungstenFabricTagResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ApplyTungstenFabricTagCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ApplyTungstenFabricTagCmd.class.getName()); public static final String APINAME = "applyTungstenFabricTag"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ConfigTungstenFabricServiceCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ConfigTungstenFabricServiceCmd.java index 305eb60abb26..19bf0a339094 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ConfigTungstenFabricServiceCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ConfigTungstenFabricServiceCmd.java @@ -47,7 +47,6 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import java.util.HashMap; import java.util.List; @@ -58,7 +57,6 @@ @APICommand(name = ConfigTungstenFabricServiceCmd.APINAME, description = "config Tungsten-Fabric service", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigTungstenFabricServiceCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ConfigTungstenFabricServiceCmd.class.getName()); public static final String APINAME = "configTungstenFabricService"; public static final String NETWORKOFFERING = "DefaultTungstenFarbicNetworkOffering"; @@ -139,18 +137,18 @@ private void persistDefaultSystemNetwork() { private void persistNetworkServiceMapAvoidingDuplicates(Network network, NetworkServiceMapVO mapVO) { if (mapVO == null) { - s_logger.error("Expected a network-service-provider mapping entity to be persisted"); + logger.error("Expected a network-service-provider mapping entity to be persisted"); return; } Network.Service service = Network.Service.getService(mapVO.getService()); Network.Provider provider = Network.Provider.getProvider(mapVO.getProvider()); if (service == null || provider == null) { - s_logger.error(String.format("Could not obtain the service or the provider " + + logger.error(String.format("Could not obtain the service or the provider " + "from the network-service-provider map with ID = %s", mapVO.getId())); return; } if (networkServiceMapDao.canProviderSupportServiceInNetwork(network.getId(), service, provider)) { - s_logger.debug(String.format("A mapping between the network, service and provider (%s, %s, %s) " + + logger.debug(String.format("A mapping between the network, service and provider (%s, %s, %s) " + "already exists, skipping duplicated entry", network.getId(), service.getName(), provider.getName())); return; diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricAddressGroupCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricAddressGroupCmd.java index edf19df2e5ac..54797d22da35 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricAddressGroupCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricAddressGroupCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricAddressGroupResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -41,7 +40,6 @@ responseObject = TungstenFabricAddressGroupResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricAddressGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricAddressGroupCmd.class.getName()); public static final String APINAME = "createTungstenFabricAddressGroup"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricApplicationPolicySetCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricApplicationPolicySetCmd.java index 4cf39d675dc9..2588d08aa855 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricApplicationPolicySetCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricApplicationPolicySetCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricApplicationPolicySetResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = CreateTungstenFabricApplicationPolicySetCmd.APINAME, description = "create Tungsten-Fabric application policy set", responseObject = TungstenFabricApplicationPolicySetResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricApplicationPolicySetCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricApplicationPolicySetCmd.class.getName()); public static final String APINAME = "createTungstenFabricApplicationPolicySet"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricFirewallPolicyCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricFirewallPolicyCmd.java index d2c93f5dd630..d04baf1de3b8 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricFirewallPolicyCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricFirewallPolicyCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricFirewallPolicyResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -41,7 +40,6 @@ responseObject = TungstenFabricFirewallPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricFirewallPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricFirewallPolicyCmd.class.getName()); public static final String APINAME = "createTungstenFabricFirewallPolicy"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricFirewallRuleCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricFirewallRuleCmd.java index f2cd0684e9ab..ed67f15ff8cf 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricFirewallRuleCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricFirewallRuleCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricFirewallRuleResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -42,7 +41,6 @@ responseObject = TungstenFabricFirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricFirewallRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricFirewallRuleCmd.class.getName()); public static final String APINAME = "createTungstenFabricFirewallRule"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricLogicalRouterCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricLogicalRouterCmd.java index add6e503e2d3..a9a775a16c3e 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricLogicalRouterCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricLogicalRouterCmd.java @@ -34,14 +34,12 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricLogicalRouterResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = CreateTungstenFabricLogicalRouterCmd.APINAME, description = "create Tungsten-Fabric logical router", responseObject = TungstenFabricLogicalRouterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricLogicalRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricLogicalRouterCmd.class.getName()); public static final String APINAME = "createTungstenFabricLogicalRouter"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricManagementNetworkCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricManagementNetworkCmd.java index bb4414eaecf4..831be57a8d21 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricManagementNetworkCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricManagementNetworkCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -41,7 +40,6 @@ responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricManagementNetworkCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricManagementNetworkCmd.class.getName()); public static final String APINAME = "createTungstenFabricManagementNetwork"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricPolicyCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricPolicyCmd.java index a7251d52b6cc..9151825c1223 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricPolicyCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricPolicyCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricPolicyResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -41,7 +40,6 @@ responseObject = TungstenFabricPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricPolicyCmd.class.getName()); public static final String APINAME = "createTungstenFabricPolicy"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricProviderCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricProviderCmd.java index 98cb3f671ef6..27fdc020d446 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricProviderCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricProviderCmd.java @@ -32,14 +32,12 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricProviderResponse; import org.apache.cloudstack.network.tungsten.service.TungstenProviderService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = CreateTungstenFabricProviderCmd.APINAME, description = "Create Tungsten-Fabric provider in cloudstack", responseObject = TungstenFabricProviderResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricProviderCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricProviderCmd.class.getName()); public static final String APINAME = "createTungstenFabricProvider"; @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricPublicNetworkCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricPublicNetworkCmd.java index ba1eb90a4b08..059cff2a9230 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricPublicNetworkCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricPublicNetworkCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.List; @@ -46,7 +45,6 @@ @APICommand(name = CreateTungstenFabricPublicNetworkCmd.APINAME, description = "create Tungsten-Fabric public network", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricPublicNetworkCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricPublicNetworkCmd.class.getName()); public static final String APINAME = "createTungstenFabricPublicNetwork"; diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricServiceGroupCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricServiceGroupCmd.java index ae3b2bf533b5..f92ccd1b7c79 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricServiceGroupCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricServiceGroupCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricServiceGroupResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = CreateTungstenFabricServiceGroupCmd.APINAME, description = "create Tungsten-Fabric service group", responseObject = TungstenFabricServiceGroupResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricServiceGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricServiceGroupCmd.class.getName()); public static final String APINAME = "createTungstenFabricServiceGroup"; diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricTagCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricTagCmd.java index b46e5ffef536..dccc947bd977 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricTagCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricTagCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricTagResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = CreateTungstenFabricTagCmd.APINAME, description = "create Tungsten-Fabric tag", responseObject = TungstenFabricTagResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricTagCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricTagCmd.class.getName()); public static final String APINAME = "createTungstenFabricTag"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricTagTypeCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricTagTypeCmd.java index 4a6d29d5a0be..699a7efcd7db 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricTagTypeCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/CreateTungstenFabricTagTypeCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricTagTypeResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = CreateTungstenFabricTagTypeCmd.APINAME, description = "create Tungsten-Fabric tag type", responseObject = TungstenFabricTagTypeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTungstenFabricTagTypeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTungstenFabricTagTypeCmd.class.getName()); public static final String APINAME = "createTungstenFabricTagType"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricAddressGroupCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricAddressGroupCmd.java index b1b130a48978..c3dbff2310cc 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricAddressGroupCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricAddressGroupCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = DeleteTungstenFabricAddressGroupCmd.APINAME, description = "delete Tungsten-Fabric address group", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricAddressGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricAddressGroupCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricAddressGroup"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricApplicationPolicySetCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricApplicationPolicySetCmd.java index fe1c95230f3d..34da45253fdf 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricApplicationPolicySetCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricApplicationPolicySetCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = DeleteTungstenFabricApplicationPolicySetCmd.APINAME, description = "delete Tungsten-Fabric application policy set", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricApplicationPolicySetCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricApplicationPolicySetCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricApplicationPolicySet"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricFirewallPolicyCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricFirewallPolicyCmd.java index 61d166a71fdd..6a834cd9391b 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricFirewallPolicyCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricFirewallPolicyCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -41,7 +40,6 @@ + "policy", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricFirewallPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricFirewallPolicyCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricFirewallPolicy"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricFirewallRuleCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricFirewallRuleCmd.java index 536aad720367..d1daaf323fc7 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricFirewallRuleCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricFirewallRuleCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = DeleteTungstenFabricFirewallRuleCmd.APINAME, description = "delete Tungsten-Fabric firewall rule", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricFirewallRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricFirewallRuleCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricFirewallRule"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricLogicalRouterCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricLogicalRouterCmd.java index 953b74857f88..2b0b4c64d554 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricLogicalRouterCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricLogicalRouterCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.List; @@ -42,7 +41,6 @@ @APICommand(name = DeleteTungstenFabricLogicalRouterCmd.APINAME, description = "delete Tungsten-Fabric logical router", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricLogicalRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricLogicalRouterCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricLogicalRouter"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricPolicyCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricPolicyCmd.java index 4398a1091271..f30249360799 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricPolicyCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricPolicyCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = DeleteTungstenFabricPolicyCmd.APINAME, description = "delete Tungsten-Fabric policy", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricPolicyCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricPolicy"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricServiceGroupCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricServiceGroupCmd.java index 28be9e59af63..ab3bd7e984bd 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricServiceGroupCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricServiceGroupCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = DeleteTungstenFabricServiceGroupCmd.APINAME, description = "delete Tungsten-Fabric service group", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricServiceGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricServiceGroupCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricServiceGroup"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricTagCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricTagCmd.java index afc15022bd64..44b660291a54 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricTagCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricTagCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = DeleteTungstenFabricTagCmd.APINAME, description = "delete Tungsten-Fabric tag", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricTagCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricTagCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricTag"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricTagTypeCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricTagTypeCmd.java index 418ec5284d47..c9537fc65387 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricTagTypeCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/DeleteTungstenFabricTagTypeCmd.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = DeleteTungstenFabricTagTypeCmd.APINAME, description = "delete Tungsten-Fabric tag type", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTungstenFabricTagTypeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTungstenFabricTagTypeCmd.class.getName()); public static final String APINAME = "deleteTungstenFabricTagType"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/GetLoadBalancerSslCertificateCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/GetLoadBalancerSslCertificateCmd.java index 3e93adb35d5e..eb65ae1aff66 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/GetLoadBalancerSslCertificateCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/GetLoadBalancerSslCertificateCmd.java @@ -34,14 +34,12 @@ import org.apache.cloudstack.network.tungsten.api.response.TlsDataResponse; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = GetLoadBalancerSslCertificateCmd.APINAME, description = "get load balancer certificate", responseObject = TlsDataResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetLoadBalancerSslCertificateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetLoadBalancerSslCertificateCmd.class.getName()); public static final String APINAME = "getLoadBalancerSslCertificate"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricAddressGroupCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricAddressGroupCmd.java index a96bbc4d324f..297823689d6c 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricAddressGroupCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricAddressGroupCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricAddressGroupResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ responseObject = TungstenFabricAddressGroupResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricAddressGroupCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricAddressGroupCmd.class.getName()); public static final String APINAME = "listTungstenFabricAddressGroup"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricApplictionPolicySetCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricApplictionPolicySetCmd.java index b49bdce0fc2c..85b5528af169 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricApplictionPolicySetCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricApplictionPolicySetCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricApplicationPolicySetResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ + "policy set", responseObject = TungstenFabricApplicationPolicySetResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricApplictionPolicySetCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricApplictionPolicySetCmd.class.getName()); public static final String APINAME = "listTungstenFabricApplicationPolicySet"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricFirewallPolicyCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricFirewallPolicyCmd.java index e63e8cb6122c..44c8f7276e5b 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricFirewallPolicyCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricFirewallPolicyCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricFirewallPolicyResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ responseObject = TungstenFabricFirewallPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricFirewallPolicyCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricFirewallPolicyCmd.class.getName()); public static final String APINAME = "listTungstenFabricFirewallPolicy"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricFirewallRuleCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricFirewallRuleCmd.java index 800b0b269299..bfc1c101e2b3 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricFirewallRuleCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricFirewallRuleCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricFirewallRuleResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ responseObject = TungstenFabricFirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricFirewallRuleCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricFirewallRuleCmd.class.getName()); public static final String APINAME = "listTungstenFabricFirewallRule"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricLBHealthMonitorCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricLBHealthMonitorCmd.java index 0dfaa18c549f..7ac43cb19095 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricLBHealthMonitorCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricLBHealthMonitorCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricLBHealthMonitorResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.List; @@ -43,7 +42,6 @@ @APICommand(name = ListTungstenFabricLBHealthMonitorCmd.APINAME, description = "list Tungsten-Fabric LB health monitor", responseObject = TungstenFabricLBHealthMonitorResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricLBHealthMonitorCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricLBHealthMonitorCmd.class.getName()); public static final String APINAME = "listTungstenFabricLBHealthMonitor"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricLogicalRouterCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricLogicalRouterCmd.java index 4178aa6fd055..e33bd3f47c49 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricLogicalRouterCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricLogicalRouterCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricLogicalRouterResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ responseObject = TungstenFabricLogicalRouterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricLogicalRouterCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricLogicalRouterCmd.class.getName()); public static final String APINAME = "listTungstenFabricLogicalRouter"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricNetworkCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricNetworkCmd.java index 907165d349ef..08aa2719f578 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricNetworkCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricNetworkCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricNetworkResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ responseObject = TungstenFabricNetworkResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricNetworkCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricNetworkCmd.class.getName()); public static final String APINAME = "listTungstenFabricNetwork"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricNicCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricNicCmd.java index 6f19cb698f0c..b5daf9570f4d 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricNicCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricNicCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricNicResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -46,7 +45,6 @@ @APICommand(name = ListTungstenFabricNicCmd.APINAME, description = "list Tungsten-Fabric nic", responseObject = TungstenFabricNicResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricNicCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricNicCmd.class.getName()); public static final String APINAME = "listTungstenFabricNic"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricPolicyCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricPolicyCmd.java index b5edf2d32322..3bfef0cda021 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricPolicyCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricPolicyCmd.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricPolicyResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -48,7 +47,6 @@ @APICommand(name = ListTungstenFabricPolicyCmd.APINAME, description = "list Tungsten-Fabric policy", responseObject = TungstenFabricPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricPolicyCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricPolicyCmd.class.getName()); public static final String APINAME = "listTungstenFabricPolicy"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricPolicyRuleCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricPolicyRuleCmd.java index 0bbb292b4f9f..c4c53f26758a 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricPolicyRuleCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricPolicyRuleCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricRuleResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ responseObject = TungstenFabricRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricPolicyRuleCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricPolicyRuleCmd.class.getName()); public static final String APINAME = "listTungstenFabricPolicyRule"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricProvidersCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricProvidersCmd.java index 1e544a6f3388..262e4a9a856d 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricProvidersCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricProvidersCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricProviderResponse; import org.apache.cloudstack.network.tungsten.service.TungstenProviderService; -import org.apache.log4j.Logger; import java.util.List; @@ -43,7 +42,6 @@ @APICommand(name = ListTungstenFabricProvidersCmd.APINAME, responseObject = TungstenFabricProviderResponse.class, description = "Lists Tungsten-Fabric providers", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricProvidersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricProvidersCmd.class.getName()); public static final String APINAME = "listTungstenFabricProviders"; ///////////////////////////////////////////////////// diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricServiceGroupCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricServiceGroupCmd.java index 8d65da425503..eb066520abc1 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricServiceGroupCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricServiceGroupCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricServiceGroupResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ responseObject = TungstenFabricServiceGroupResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricServiceGroupCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricServiceGroupCmd.class.getName()); public static final String APINAME = "listTungstenFabricServiceGroup"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricTagCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricTagCmd.java index 657bc431bc4d..bf73cc0c2272 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricTagCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricTagCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricTagResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -46,7 +45,6 @@ @APICommand(name = ListTungstenFabricTagCmd.APINAME, responseObject = TungstenFabricTagResponse.class, description = "Lists Tungsten-Fabric tags", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricTagCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricTagCmd.class.getName()); public static final String APINAME = "listTungstenFabricTag"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricTagTypeCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricTagTypeCmd.java index bda4ef7a04ab..6ba10f92488e 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricTagTypeCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricTagTypeCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricTagTypeResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -47,7 +46,6 @@ description = "Lists " + "Tungsten-Fabric tags", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricTagTypeCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricTagTypeCmd.class.getName()); public static final String APINAME = "listTungstenFabricTagType"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricVmCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricVmCmd.java index 02e19c5c423c..3626d5d8e3b4 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricVmCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/ListTungstenFabricVmCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricVmResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -46,7 +45,6 @@ @APICommand(name = ListTungstenFabricVmCmd.APINAME, description = "list Tungsten-Fabric vm", responseObject = TungstenFabricVmResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTungstenFabricVmCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTungstenFabricVmCmd.class.getName()); public static final String APINAME = "listTungstenFabricVm"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricNetworkGatewayFromLogicalRouterCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricNetworkGatewayFromLogicalRouterCmd.java index 74536ca4541f..22d2948e773c 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricNetworkGatewayFromLogicalRouterCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricNetworkGatewayFromLogicalRouterCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricLogicalRouterResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.List; @@ -43,7 +42,6 @@ @APICommand(name = RemoveTungstenFabricNetworkGatewayFromLogicalRouterCmd.APINAME, description = "remove Tungsten-Fabric network gateway from logical router", responseObject = TungstenFabricLogicalRouterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveTungstenFabricNetworkGatewayFromLogicalRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveTungstenFabricNetworkGatewayFromLogicalRouterCmd.class.getName()); public static final String APINAME = "removeTungstenFabricNetworkGatewayFromLogicalRouter"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricPolicyCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricPolicyCmd.java index 93ed3ba1d278..ed5226461ad8 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricPolicyCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricPolicyCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricPolicyResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -41,7 +40,6 @@ responseObject = TungstenFabricPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveTungstenFabricPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveTungstenFabricPolicyCmd.class.getName()); public static final String APINAME = "removeTungstenFabricPolicy"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricPolicyRuleCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricPolicyRuleCmd.java index 86ec6555a75b..1cb6a78a802a 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricPolicyRuleCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricPolicyRuleCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricPolicyResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -41,7 +40,6 @@ responseObject = TungstenFabricPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveTungstenFabricPolicyRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveTungstenFabricPolicyRuleCmd.class.getName()); public static final String APINAME = "removeTungstenFabricPolicyRule"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricTagCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricTagCmd.java index 0214eff881c8..ae0de85067cc 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricTagCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/RemoveTungstenFabricTagCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricTagResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import java.util.List; @@ -42,7 +41,6 @@ @APICommand(name = RemoveTungstenFabricTagCmd.APINAME, description = "remove Tungsten-Fabric tag", responseObject = TungstenFabricTagResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveTungstenFabricTagCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveTungstenFabricTagCmd.class.getName()); public static final String APINAME = "removeTungstenFabricTag"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/SynchronizeTungstenFabricDataCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/SynchronizeTungstenFabricDataCmd.java index 458d915956da..0bf5cd46acc2 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/SynchronizeTungstenFabricDataCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/SynchronizeTungstenFabricDataCmd.java @@ -31,14 +31,12 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricProviderResponse; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = SynchronizeTungstenFabricDataCmd.APINAME, description = "Synchronize Tungsten-Fabric data", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class SynchronizeTungstenFabricDataCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(SynchronizeTungstenFabricDataCmd.class.getName()); public static final String APINAME = "synchronizeTungstenFabricData"; @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = TungstenFabricProviderResponse.class, diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/UpdateTungstenFabricLBHealthMonitorCmd.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/UpdateTungstenFabricLBHealthMonitorCmd.java index 9e7cce66e346..c0ffdb925e83 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/UpdateTungstenFabricLBHealthMonitorCmd.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/api/command/UpdateTungstenFabricLBHealthMonitorCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.network.tungsten.api.response.TungstenFabricLBHealthMonitorResponse; import org.apache.cloudstack.network.tungsten.dao.TungstenFabricLBHealthMonitorVO; import org.apache.cloudstack.network.tungsten.service.TungstenService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -45,7 +44,6 @@ responseObject = TungstenFabricLBHealthMonitorResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateTungstenFabricLBHealthMonitorCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(UpdateTungstenFabricLBHealthMonitorCmd.class.getName()); public static final String APINAME = "updateTungstenFabricLBHealthMonitor"; @Inject diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/resource/TungstenResource.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/resource/TungstenResource.java index 0e14dd41aeb9..471083103253 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/resource/TungstenResource.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/resource/TungstenResource.java @@ -161,7 +161,8 @@ import org.apache.cloudstack.network.tungsten.service.TungstenApi; import org.apache.cloudstack.network.tungsten.service.TungstenVRouterApi; import org.apache.cloudstack.network.tungsten.vrouter.Port; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.naming.ConfigurationException; import java.io.IOException; @@ -172,7 +173,7 @@ public class TungstenResource implements ServerResource { - private static final Logger s_logger = Logger.getLogger(TungstenResource.class); + protected Logger logger = LogManager.getLogger(getClass()); private String name; private String guid; @@ -257,7 +258,7 @@ public PingCommand getCurrentStatus(long id) { try { tungstenApi.checkTungstenProviderConnection(); } catch (ServerApiException e) { - s_logger.error("Check Tungsten-Fabric provider connection failed", e); + logger.error("Check Tungsten-Fabric provider connection failed", e); return null; } return new PingCommand(Host.Type.L2Networking, id); @@ -493,7 +494,7 @@ private Answer executeRequestGroup7(Command cmd, int numRetries) { return executeRequest((CreateTungstenDefaultProjectCommand) cmd); } - s_logger.debug("Received unsupported command " + cmd.toString()); + logger.debug("Received unsupported command " + cmd.toString()); return Answer.createUnsupportedCommandAnswer(cmd); } @@ -2302,7 +2303,7 @@ private Answer executeRequest(CreateTungstenDefaultProjectCommand cmd) { } private Answer retry(Command cmd, int numRetries) { - s_logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); + logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries); return executeRequestGroup1(cmd, numRetries); } diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenApi.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenApi.java index 965ce691b55a..a3989034be91 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenApi.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenApi.java @@ -86,7 +86,8 @@ import org.apache.cloudstack.network.tungsten.model.TungstenLoadBalancerMember; import org.apache.cloudstack.network.tungsten.model.TungstenRule; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; import java.net.HttpURLConnection; @@ -99,8 +100,8 @@ public class TungstenApi { - private static final Logger S_LOGGER = Logger.getLogger(TungstenApi.class); - private static final Status.ErrorHandler errorHandler = S_LOGGER::error; + protected Logger logger = LogManager.getLogger(getClass()); + private final Status.ErrorHandler errorHandler = logger::error; public static final String TUNGSTEN_DEFAULT_DOMAIN = "default-domain"; public static final String TUNGSTEN_DEFAULT_PROJECT = "admin"; @@ -208,7 +209,7 @@ public VirtualMachine createTungstenVirtualMachine(String vmUuid, String vmName) status.ifFailure(errorHandler); return (VirtualMachine) apiConnector.findById(VirtualMachine.class, virtualMachine.getUuid()); } catch (IOException e) { - S_LOGGER.error("Unable to create Tungsten-Fabric vm " + vmUuid, e); + logger.error("Unable to create Tungsten-Fabric vm " + vmUuid, e); return null; } } @@ -224,7 +225,7 @@ public VirtualMachineInterface createTungstenVmInterface(String nicUuid, String virtualMachine = (VirtualMachine) apiConnector.findById(VirtualMachine.class, virtualMachineUuid); project = (Project) apiConnector.findById(Project.class, projectUuid); } catch (IOException e) { - S_LOGGER.error("Failed getting the resources needed for virtual machine interface creation from Tungsten-Fabric"); + logger.error("Failed getting the resources needed for virtual machine interface creation from Tungsten-Fabric"); } VirtualMachineInterface virtualMachineInterface = new VirtualMachineInterface(); @@ -248,7 +249,7 @@ public VirtualMachineInterface createTungstenVmInterface(String nicUuid, String return (VirtualMachineInterface) apiConnector.findById(VirtualMachineInterface.class, virtualMachineInterface.getUuid()); } catch (IOException e) { - S_LOGGER.error("Failed creating virtual machine interface in Tungsten-Fabric"); + logger.error("Failed creating virtual machine interface in Tungsten-Fabric"); return null; } } @@ -263,7 +264,7 @@ public InstanceIp createTungstenInstanceIp(String instanceIpName, String ip, Str virtualMachineInterface = (VirtualMachineInterface) apiConnector.findById(VirtualMachineInterface.class, vmInterfaceUuid); } catch (IOException e) { - S_LOGGER.error("Failed getting the resources needed for instance ip creation from Tungsten-Fabric"); + logger.error("Failed getting the resources needed for instance ip creation from Tungsten-Fabric"); return null; } @@ -277,7 +278,7 @@ public InstanceIp createTungstenInstanceIp(String instanceIpName, String ip, Str status.ifFailure(errorHandler); return (InstanceIp) apiConnector.findById(InstanceIp.class, instanceIp.getUuid()); } catch (IOException e) { - S_LOGGER.error("Failed creating instance ip in Tungsten-Fabric"); + logger.error("Failed creating instance ip in Tungsten-Fabric"); return null; } } @@ -292,7 +293,7 @@ public InstanceIp createTungstenInstanceIp(String instanceIpName, String ip, Str virtualMachineInterface = (VirtualMachineInterface) apiConnector.findById(VirtualMachineInterface.class, vmInterfaceUuid); } catch (IOException e) { - S_LOGGER.error("Failed getting the resources needed for instance ip creation with subnet from Tungsten-Fabric"); + logger.error("Failed getting the resources needed for instance ip creation with subnet from Tungsten-Fabric"); return null; } @@ -307,7 +308,7 @@ public InstanceIp createTungstenInstanceIp(String instanceIpName, String ip, Str status.ifFailure(errorHandler); return (InstanceIp) apiConnector.findById(InstanceIp.class, instanceIp.getUuid()); } catch (IOException e) { - S_LOGGER.error("Failed creating instance ip in Tungsten-Fabric"); + logger.error("Failed creating instance ip in Tungsten-Fabric"); return null; } } @@ -325,7 +326,7 @@ public boolean deleteTungstenVmInterface(VirtualMachineInterface vmi) { status.ifFailure(errorHandler); return status.isSuccess(); } catch (IOException e) { - S_LOGGER.error("Failed deleting the virtual machine interface from Tungsten-Fabric"); + logger.error("Failed deleting the virtual machine interface from Tungsten-Fabric"); return false; } } @@ -421,7 +422,7 @@ public ApiObjectBase createTungstenGatewayVmi(String name, String projectUuid, S VirtualMachineInterface.class, project, name); if (virtualMachineInterface != null) { - S_LOGGER.error("interface " + name + " is existed"); + logger.error("interface " + name + " is existed"); return null; } @@ -553,7 +554,7 @@ public String getTungstenNatIp(String projectUuid, String logicalRouterUuid) { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - S_LOGGER.error("can not delay for service instance create"); + logger.error("can not delay for service instance create"); } try { diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenElement.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenElement.java index 578accaa745a..106cf5180c3d 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenElement.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenElement.java @@ -135,7 +135,6 @@ import org.apache.cloudstack.network.tungsten.model.TungstenLoadBalancerMember; import org.apache.cloudstack.network.tungsten.model.TungstenRule; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -154,7 +153,6 @@ public class TungstenElement extends AdapterBase implements StaticNatServiceProvider, IpDeployer, FirewallServiceProvider, LoadBalancingServiceProvider, PortForwardingServiceProvider, ResourceStateAdapter, DnsServiceProvider, Listener, StateListener, NetworkMigrationResponder { - private static final Logger s_logger = Logger.getLogger(TungstenElement.class); private static final String NETWORK = "network"; @@ -273,11 +271,11 @@ private static Map> initCapabil } protected boolean canHandle(Network network, Network.Service service) { - s_logger.debug("Checking if TungstenElement can handle service " + service.getName() + " on network " + logger.debug("Checking if TungstenElement can handle service " + service.getName() + " on network " + network.getDisplayText()); if (!networkModel.isProviderForNetwork(getProvider(), network.getId())) { - s_logger.debug("TungstenElement is not a provider for network " + network.getDisplayText()); + logger.debug("TungstenElement is not a provider for network " + network.getDisplayText()); return false; } diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenFabricUtils.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenFabricUtils.java index f3e321298bc3..b94904ca05ab 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenFabricUtils.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenFabricUtils.java @@ -23,7 +23,8 @@ import com.cloud.network.element.TungstenProviderVO; import org.apache.cloudstack.network.tungsten.agent.api.TungstenAnswer; import org.apache.cloudstack.network.tungsten.agent.api.TungstenCommand; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Component; import javax.inject.Inject; @@ -31,7 +32,7 @@ @Component public class TungstenFabricUtils { - private static final Logger s_logger = Logger.getLogger(TungstenFabricUtils.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AgentManager agentMgr; @@ -42,14 +43,14 @@ public TungstenAnswer sendTungstenCommand(TungstenCommand cmd, long zoneId) thro TungstenProviderVO tungstenProviderVO = tungstenProviderDao.findByZoneId(zoneId); if (tungstenProviderVO == null) { - s_logger.error("No Tungsten-Fabric provider have been found!"); + logger.error("No Tungsten-Fabric provider have been found!"); throw new InvalidParameterValueException("Failed to find a Tungsten-Fabric provider"); } Answer answer = agentMgr.easySend(tungstenProviderVO.getHostId(), cmd); if (answer == null || !answer.getResult()) { - s_logger.error("Tungsten-Fabric API Command failed"); + logger.error("Tungsten-Fabric API Command failed"); throw new InvalidParameterValueException("Failed API call to Tungsten-Fabric Network plugin"); } diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenGuestNetworkGuru.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenGuestNetworkGuru.java index 12fe160f979e..4d22806a139c 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenGuestNetworkGuru.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenGuestNetworkGuru.java @@ -81,7 +81,6 @@ import org.apache.cloudstack.network.tungsten.agent.api.TungstenAnswer; import org.apache.cloudstack.network.tungsten.agent.api.TungstenCommand; import org.apache.cloudstack.network.tungsten.model.TungstenRule; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -90,8 +89,6 @@ public class TungstenGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigrationResponder { - private static final Logger s_logger = Logger.getLogger(TungstenGuestNetworkGuru.class); - @Inject NetworkDao networkDao; @Inject @@ -147,17 +144,17 @@ && isMyIsolationMethod(physicalNetwork) && networkOfferingServiceMapDao.isProvid } @Override - public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner) { PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId()); DataCenter dc = _dcDao.findById(plan.getDataCenterId()); if (!canHandle(offering, dc.getNetworkType(), physnet)) { - s_logger.debug("Refusing to design this network"); + logger.debug("Refusing to design this network"); return null; } - NetworkVO network = (NetworkVO) super.design(offering, plan, userSpecified, owner); + NetworkVO network = (NetworkVO) super.design(offering, plan, userSpecified, name, vpcId, owner); if (network == null) { return null; diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenServiceImpl.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenServiceImpl.java index ad20a98984f7..60b5b7290a90 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenServiceImpl.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenServiceImpl.java @@ -32,6 +32,7 @@ import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.host.Host; import com.cloud.host.HostVO; @@ -215,12 +216,10 @@ import org.apache.cloudstack.network.tungsten.model.TungstenRule; import org.apache.cloudstack.network.tungsten.model.TungstenTag; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -229,7 +228,6 @@ import javax.inject.Inject; public class TungstenServiceImpl extends ManagerBase implements TungstenService { - private static final Logger s_logger = Logger.getLogger(TungstenServiceImpl.class); private static final String NETWORK = "network"; @@ -327,7 +325,7 @@ private void subscribeSynchonizeEvent() { try { syncTungstenDbWithCloudstackProjectsAndDomains(); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -342,7 +340,7 @@ private void subscribeIpAddressEvent() { createTungstenFloatingIp(zoneId, ipAddress); } } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -357,7 +355,7 @@ private void subscribeIpAddressEvent() { } } } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -377,7 +375,7 @@ private void subscribeNetworkPolicyEvent() { network.getDataCenterId()); } } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -389,7 +387,7 @@ private void subscribeVlanEvent() { final VlanVO vlanVO = (VlanVO) args; addPublicNetworkSubnet(vlanVO); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -399,7 +397,7 @@ private void subscribeVlanEvent() { final VlanVO vlanVO = (VlanVO) args; removePublicNetworkSubnet(vlanVO); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -410,7 +408,7 @@ private void subscribePopEvent() { final HostPodVO pod = (HostPodVO) args; addManagementNetworkSubnet(pod); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -419,7 +417,7 @@ private void subscribePopEvent() { final HostPodVO pod = (HostPodVO) args; removeManagementNetworkSubnet(pod); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -430,7 +428,7 @@ private void subscribeDomainEvent() { final DomainVO domain = (DomainVO) args; createTungstenDomain(domain); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -439,7 +437,7 @@ private void subscribeDomainEvent() { final DomainVO domain = (DomainVO) args; deleteTungstenDomain(domain); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -450,7 +448,7 @@ private void subscribeProjectEvent() { final Project project = (Project) args; createTungstenProject(project); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -459,7 +457,7 @@ private void subscribeProjectEvent() { final Project project = (Project) args; deleteTungstenProject(project); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -471,7 +469,7 @@ private void subscribeSecurityGroupEvent() { final SecurityGroup securityGroup = (SecurityGroup) args; createTungstenSecurityGroup(securityGroup); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -481,7 +479,7 @@ private void subscribeSecurityGroupEvent() { final SecurityGroup securityGroup = (SecurityGroup) args; deleteTungstenSecurityGroup(securityGroup); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -491,7 +489,7 @@ private void subscribeSecurityGroupEvent() { final List securityRules = (List) args; addTungstenSecurityGroupRule(securityRules); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -501,7 +499,7 @@ private void subscribeSecurityGroupEvent() { final SecurityRule securityRule = (SecurityRule) args; removeTungstenSecurityGroupRule(securityRule); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -512,7 +510,7 @@ private void subscribeSecondaryNicEvent() { final long id = (long) args; addTungstenNicSecondaryIpAddress(id); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); @@ -521,7 +519,7 @@ private void subscribeSecondaryNicEvent() { final NicSecondaryIpVO nicSecondaryIpVO = (NicSecondaryIpVO) args; removeTungstenNicSecondaryIpAddress(nicSecondaryIpVO); } catch (final Exception e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } }); } @@ -1205,7 +1203,7 @@ public boolean updateLoadBalancerSsl(Network network, LoadBalancingRule loadBala updateTungstenLoadBalancerListenerCommand, network.getDataCenterId()); return updateTungstenLoadBalancerListenerAnswer.getResult(); } else { - s_logger.error("Tungsten-Fabric ssl require user api key"); + logger.error("Tungsten-Fabric ssl require user api key"); } } return true; @@ -2468,7 +2466,7 @@ public boolean applyLBHealthMonitor(final long lbId) { boolean success = true; LoadBalancerVO loadBalancer = loadBalancerDao.findById(lbId); if (loadBalancer == null) { - throw new InvalidParameterException("Invalid Load balancer Id:" + lbId); + throw new InvalidParameterValueException("Invalid Load balancer Id:" + lbId); } if (loadBalancer.getState() == FirewallRule.State.Active) { diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenVRouterApi.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenVRouterApi.java index 1ede3f9a2cb5..491424eb35c9 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenVRouterApi.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenVRouterApi.java @@ -19,12 +19,13 @@ import org.apache.cloudstack.network.tungsten.vrouter.Port; import org.apache.cloudstack.network.tungsten.vrouter.VRouterApiConnector; import org.apache.cloudstack.network.tungsten.vrouter.VRouterApiConnectorFactory; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; public class TungstenVRouterApi { - private static final Logger s_logger = Logger.getLogger(TungstenVRouterApi.class); + protected static Logger LOGGER = LogManager.getLogger(TungstenVRouterApi.class); private TungstenVRouterApi() { } @@ -37,7 +38,7 @@ public static boolean addTungstenVrouterPort(String host, String vrouterPort, Po try { return getvRouterApiConnector(host, vrouterPort).addPort(port); } catch (IOException ex) { - s_logger.error("Fail to add vrouter port : " + ex.getMessage()); + LOGGER.error("Fail to add vrouter port : " + ex.getMessage()); return false; } } diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/vrouter/IntrospectApiConnectorImpl.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/vrouter/IntrospectApiConnectorImpl.java index 5847b3f53b3c..d1d2fef1c225 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/vrouter/IntrospectApiConnectorImpl.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/vrouter/IntrospectApiConnectorImpl.java @@ -21,7 +21,8 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.w3c.dom.Document; import org.xml.sax.SAXException; @@ -33,7 +34,7 @@ import javax.xml.parsers.ParserConfigurationException; public class IntrospectApiConnectorImpl implements IntrospectApiConnector { - private static final Logger s_logger = Logger.getLogger(IntrospectApiConnectorImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private final String vrouterUrl; public IntrospectApiConnectorImpl(VRouter vRouter) { @@ -46,13 +47,13 @@ public Document getSnhItfReq(String uuid) { CloseableHttpResponse httpResponse = httpClient.execute(request)) { return getResponse(httpResponse); } catch (IOException ex) { - s_logger.error("Failed to connect host : " + ex.getMessage()); + logger.error("Failed to connect host : " + ex.getMessage()); return null; } catch (ParserConfigurationException ex) { - s_logger.error("Failed to parse xml configuration : " + ex.getMessage()); + logger.error("Failed to parse xml configuration : " + ex.getMessage()); return null; } catch (SAXException ex) { - s_logger.error("Failed to get xml data : " + ex.getMessage()); + logger.error("Failed to get xml data : " + ex.getMessage()); return null; } } diff --git a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/vrouter/VRouterApiConnectorImpl.java b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/vrouter/VRouterApiConnectorImpl.java index 6e8d727a9a2e..4344020d013b 100644 --- a/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/vrouter/VRouterApiConnectorImpl.java +++ b/plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/vrouter/VRouterApiConnectorImpl.java @@ -27,13 +27,14 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; import java.util.List; public class VRouterApiConnectorImpl implements VRouterApiConnector { - private static final Logger s_logger = Logger.getLogger(VRouterApiConnectorImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private final String vrouterUrl; public VRouterApiConnectorImpl(VRouter vRouter) { @@ -51,7 +52,7 @@ public boolean addPort(final Port port) throws IOException { CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) { return getResponse(httpResponse); } catch (IOException ex) { - s_logger.error("Failed to add vrouter port : " + ex.getMessage()); + logger.error("Failed to add vrouter port : " + ex.getMessage()); return false; } } @@ -63,7 +64,7 @@ public boolean deletePort(final String portId) { CloseableHttpResponse httpResponse = httpClient.execute(httpDelete)) { return getResponse(httpResponse); } catch (IOException ex) { - s_logger.error("Failed to delete vrouter port : " + ex.getMessage()); + logger.error("Failed to delete vrouter port : " + ex.getMessage()); return false; } } @@ -75,7 +76,7 @@ public boolean enablePort(final String portId) { CloseableHttpResponse httpResponse = httpClient.execute(httpPut)) { return getResponse(httpResponse); } catch (IOException ex) { - s_logger.error("Failed to enable vrouter port : " + ex.getMessage()); + logger.error("Failed to enable vrouter port : " + ex.getMessage()); return false; } } @@ -87,7 +88,7 @@ public boolean disablePort(final String portId) { CloseableHttpResponse httpResponse = httpClient.execute(httpPut)) { return getResponse(httpResponse); } catch (IOException ex) { - s_logger.error("Failed to disable vrouter port : " + ex.getMessage()); + logger.error("Failed to disable vrouter port : " + ex.getMessage()); return false; } } @@ -103,7 +104,7 @@ public boolean addGateway(List gatewayList) throws IOException { CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) { return getResponse(httpResponse); } catch (IOException ex) { - s_logger.error("Failed to add route : " + ex.getMessage()); + logger.error("Failed to add route : " + ex.getMessage()); return false; } } @@ -118,7 +119,7 @@ public boolean deleteGateway(List gatewayList) throws IOException { CloseableHttpResponse httpResponse = httpClient.execute(customHttpDelete)) { return getResponse(httpResponse); } catch (IOException ex) { - s_logger.error("Failed to remove route : " + ex.getMessage()); + logger.error("Failed to remove route : " + ex.getMessage()); return false; } } @@ -131,7 +132,7 @@ private boolean getResponse(final CloseableHttpResponse httpResponse) throws IOE return true; } else { String error = jsonObject.get("error").getAsString(); - s_logger.error(error); + logger.error(error); return false; } } diff --git a/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenApiTest.java b/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenApiTest.java index 580bea057d88..030b802aa8bf 100644 --- a/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenApiTest.java +++ b/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenApiTest.java @@ -16,6 +16,8 @@ // under the License. package org.apache.cloudstack.network.tungsten.service; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -54,7 +56,6 @@ import net.juniper.tungsten.api.types.VirtualNetwork; import org.apache.cloudstack.network.tungsten.model.TungstenLoadBalancerMember; import org.apache.cloudstack.network.tungsten.model.TungstenRule; -import org.apache.log4j.Logger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -71,7 +72,7 @@ @RunWith(MockitoJUnitRunner.class) public class TungstenApiTest { - private static final Logger s_logger = Logger.getLogger(TungstenApiTest.class); + protected Logger logger = LogManager.getLogger(getClass()); private final TungstenApi tungstenApi = new TungstenApi(); private Project project; @@ -94,7 +95,7 @@ public class TungstenApiTest { @Before public void setUp() throws Exception { - s_logger.debug("Create Tungsten-Fabric api connector mock."); + logger.debug("Create Tungsten-Fabric api connector mock."); ApiConnector api = new ApiConnectorMock(null, 0); tungstenApi.setApiConnector(api); @@ -102,7 +103,7 @@ public void setUp() throws Exception { projectUuid = UUID.randomUUID().toString(); //create Tungsten-Fabric default domain - s_logger.debug("Create default domain in Tungsten-Fabric."); + logger.debug("Create default domain in Tungsten-Fabric."); Domain domain = new Domain(); domain.setUuid(domainUuid); String defaultDomainName = "default-domain"; @@ -110,7 +111,7 @@ public void setUp() throws Exception { api.create(domain); //create Tungsten-Fabric default project - s_logger.debug("Create default project in Tungsten-Fabric."); + logger.debug("Create default project in Tungsten-Fabric."); Project project = new Project(); project.setUuid(projectUuid); String defaultProjectName = "default-project"; @@ -141,77 +142,77 @@ public void setUp() throws Exception { @Test public void createTungstenNetworkTest() { - s_logger.debug("Creating a virtual network in Tungsten-Fabric."); + logger.debug("Creating a virtual network in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, "")); - s_logger.debug("Get Tungsten-Fabric virtual network and check if it's not null."); + logger.debug("Get Tungsten-Fabric virtual network and check if it's not null."); assertNotNull(tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid)); } @Test public void createTungstenVirtualMachineTest() { - s_logger.debug("Create virtual machine in Tungsten-Fabric."); + logger.debug("Create virtual machine in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName)); - s_logger.debug("Check if virtual machine was created in Tungsten-Fabric."); + logger.debug("Check if virtual machine was created in Tungsten-Fabric."); assertNotNull(tungstenApi.getTungstenObject(VirtualMachine.class, tungstenVmUuid)); } @Test public void createTungstenVirtualMachineInterfaceTest() { - s_logger.debug("Create fabric virtual network in Tungsten-Fabric."); + logger.debug("Create fabric virtual network in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenNetwork(null, "ip-fabric", "ip-fabric", projectUuid, true, false, null, 0, null, true, null, null, null, false, false, "")); - s_logger.debug("Create virtual network in Tungsten-Fabric."); + logger.debug("Create virtual network in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, true, "")); - s_logger.debug("Create virtual machine in Tungsten-Fabric."); + logger.debug("Create virtual machine in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName)); String vmiMacAddress = "02:fc:f3:d6:83:c3"; - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, vmiMacAddress, tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true)); } @Test public void deleteTungstenVirtualMachineInterfaceTest() { - s_logger.debug("Create virtual network in Tungsten-Fabric."); + logger.debug("Create virtual network in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, "")); - s_logger.debug("Create virtual machine in Tungsten-Fabric."); + logger.debug("Create virtual machine in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName)); String vmiMacAddress = "02:fc:f3:d6:83:c3"; - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, vmiMacAddress, tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if the virtual machine interface was created in Tungsten-Fabric."); + logger.debug("Check if the virtual machine interface was created in Tungsten-Fabric."); VirtualMachineInterface vmi = (VirtualMachineInterface) tungstenApi.getTungstenObject(VirtualMachineInterface.class, vmiUuid); assertNotNull(vmi); - s_logger.debug("Delete virtual machine interface from Tungsten-Fabric."); + logger.debug("Delete virtual machine interface from Tungsten-Fabric."); assertTrue(tungstenApi.deleteTungstenVmInterface(vmi)); } @Test public void createTungstenLogicalRouterTest() { - s_logger.debug("Create public network in Tungsten-Fabric."); + logger.debug("Create public network in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenNetwork(tungstenPublicNetworkUuid, tungstenPublicNetworkName, tungstenPublicNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, "")); - s_logger.debug("Create logical router in Tungsten-Fabric."); + logger.debug("Create logical router in Tungsten-Fabric."); assertNotNull( tungstenApi.createTungstenLogicalRouter("TungstenLogicalRouter", projectUuid, tungstenPublicNetworkUuid)); } @@ -220,11 +221,11 @@ public void createTungstenLogicalRouterTest() { public void createTungstenSecurityGroupTest() { String projectFqn = TungstenApi.TUNGSTEN_DEFAULT_DOMAIN + ":" + TungstenApi.TUNGSTEN_DEFAULT_PROJECT; - s_logger.debug("Create a security group in Tungsten-Fabric."); + logger.debug("Create a security group in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenSecurityGroup(tungstenSecurityGroupUuid, tungstenSecurityGroupName, "TungstenSecurityGroupDescription", projectFqn)); - s_logger.debug("Check if the security group was created in Tungsten-Fabric."); + logger.debug("Check if the security group was created in Tungsten-Fabric."); SecurityGroup securityGroup = (SecurityGroup) tungstenApi.getTungstenObject(SecurityGroup.class, tungstenSecurityGroupUuid); assertNotNull(securityGroup); @@ -234,7 +235,7 @@ public void createTungstenSecurityGroupTest() { public void addTungstenSecurityGroupRuleTest() { String projectFqn = TungstenApi.TUNGSTEN_DEFAULT_DOMAIN + ":" + TungstenApi.TUNGSTEN_DEFAULT_PROJECT; - s_logger.debug("Create a security group in Tungsten-Fabric."); + logger.debug("Create a security group in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenSecurityGroup(tungstenSecurityGroupUuid, tungstenSecurityGroupName, "TungstenSecurityGroupDescription", projectFqn)); @@ -243,7 +244,7 @@ public void addTungstenSecurityGroupRuleTest() { tungstenSecurityGroupUuid); assertNotNull(securityGroup); - s_logger.debug("Add a Tungsten-Fabric security group rule to the security group added earlier"); + logger.debug("Add a Tungsten-Fabric security group rule to the security group added earlier"); boolean result = tungstenApi.addTungstenSecurityGroupRule(tungstenSecurityGroupUuid, tungstenSecurityGroupRuleUuid, "ingress", 80, 90, "10.0.0.0/24", "IPv4", "tcp"); assertTrue(result); @@ -253,7 +254,7 @@ public void addTungstenSecurityGroupRuleTest() { public void removeTungstenSecurityGroupRuleTest() { String projectFqn = TungstenApi.TUNGSTEN_DEFAULT_DOMAIN + ":" + TungstenApi.TUNGSTEN_DEFAULT_PROJECT; - s_logger.debug("Create a security group in Tungsten-Fabric."); + logger.debug("Create a security group in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenSecurityGroup(tungstenSecurityGroupUuid, "TungstenSecurityGroup", "TungstenSecurityGroupDescription", projectFqn)); @@ -262,37 +263,37 @@ public void removeTungstenSecurityGroupRuleTest() { tungstenSecurityGroupUuid); assertNotNull(securityGroup); - s_logger.debug("Add a Tungsten-Fabric security group rule to the security group added earlier"); + logger.debug("Add a Tungsten-Fabric security group rule to the security group added earlier"); boolean result1 = tungstenApi.addTungstenSecurityGroupRule(tungstenSecurityGroupUuid, "0a01e4c7-d912-4bd5-9786-5478e3dae7b2", "ingress", 80, 90, "10.0.0.0/24", "IPv4", "tcp"); assertTrue(result1); - s_logger.debug("Add a Tungsten-Fabric security group rule to the security group added earlier"); + logger.debug("Add a Tungsten-Fabric security group rule to the security group added earlier"); boolean result2 = tungstenApi.addTungstenSecurityGroupRule(tungstenSecurityGroupUuid, "fe44b353-21e7-4e6c-af18-1325c5ef886a", "egress", 80, 90, "securitygroup", "IPv4", "tcp"); assertTrue(result2); - s_logger.debug("Delete the Tungsten-Fabric security group rule added earlier"); + logger.debug("Delete the Tungsten-Fabric security group rule added earlier"); assertTrue( tungstenApi.removeTungstenSecurityGroupRule(tungstenSecurityGroupUuid, "0a01e4c7-d912-4bd5-9786-5478e3dae7b2")); } @Test public void createTungstenLoadbalancerTest() { - s_logger.debug("Creating a virtual network in Tungsten-Fabric."); + logger.debug("Creating a virtual network in Tungsten-Fabric."); createTungstenNetworkTest(); - s_logger.debug("Get tungsten virtual network and check if it's not null."); + logger.debug("Get tungsten virtual network and check if it's not null."); assertNotNull(tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid)); - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); createTungstenVirtualMachineInterfaceTest(); - s_logger.debug("Create loadbalancer in Tungsten-Fabric"); + logger.debug("Create loadbalancer in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenLoadbalancer(projectUuid, tungstenLoadbalancerName, vmiUuid, tungstenApi.getSubnetUuid(tungstenNetworkUuid), "192.168.2.100")); - s_logger.debug("Check if the loadbalancer was created in Tungsten-Fabric"); + logger.debug("Check if the loadbalancer was created in Tungsten-Fabric"); Project project = (Project) tungstenApi.getTungstenObject(Project.class, projectUuid); assertNotNull(tungstenApi.getTungstenObjectByName(Loadbalancer.class, project.getQualifiedName(), tungstenLoadbalancerName)); @@ -300,201 +301,201 @@ public void createTungstenLoadbalancerTest() { @Test public void createTungstenLoadbalancerListenerTest() { - s_logger.debug("Create a loadbalancer in Tungsten-Fabric"); + logger.debug("Create a loadbalancer in Tungsten-Fabric"); createTungstenLoadbalancerTest(); - s_logger.debug("Get loadbalancer from Tungsten-Fabric"); + logger.debug("Get loadbalancer from Tungsten-Fabric"); Project project = (Project) tungstenApi.getTungstenObject(Project.class, projectUuid); Loadbalancer loadbalancer = (Loadbalancer) tungstenApi.getTungstenObjectByName(Loadbalancer.class, project.getQualifiedName(), tungstenLoadbalancerName); assertNotNull(loadbalancer); - s_logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); + logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); LoadbalancerListener loadbalancerListener = (LoadbalancerListener) tungstenApi.createTungstenLoadbalancerListener( projectUuid, loadbalancer.getUuid(), tungstenLoadbalancerListenerName, "tcp", 24); - s_logger.debug("Check if the loadbalancer listener was created in Tungsten-Fabric"); + logger.debug("Check if the loadbalancer listener was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObject(LoadbalancerListener.class, loadbalancerListener.getUuid())); } @Test public void createTungstenLoadbalancerHealthMonitorTest() { - s_logger.debug("Create a loadbalancer health monitor in Tungsten-Fabric"); + logger.debug("Create a loadbalancer health monitor in Tungsten-Fabric"); LoadbalancerHealthmonitor loadbalancerHealthmonitor = (LoadbalancerHealthmonitor) tungstenApi.createTungstenLoadbalancerHealthMonitor( projectUuid, "LoadbalancerHealthMonitor", "PING", 3, 5, 5, null, null, null); assertNotNull(loadbalancerHealthmonitor); - s_logger.debug("Check if the loadbalancer health monitor was created in Tungsten-Fabric"); + logger.debug("Check if the loadbalancer health monitor was created in Tungsten-Fabric"); assertNotNull( tungstenApi.getTungstenObject(LoadbalancerHealthmonitor.class, loadbalancerHealthmonitor.getUuid())); } @Test public void createTungstenLoadbalancerPoolTest() { - s_logger.debug("Create a loadbalancer in Tungsten-Fabric"); + logger.debug("Create a loadbalancer in Tungsten-Fabric"); createTungstenLoadbalancerTest(); - s_logger.debug("Get loadbalancer from Tungsten-Fabric"); + logger.debug("Get loadbalancer from Tungsten-Fabric"); Project project = (Project) tungstenApi.getTungstenObject(Project.class, projectUuid); Loadbalancer loadbalancer = (Loadbalancer) tungstenApi.getTungstenObjectByName(Loadbalancer.class, project.getQualifiedName(), tungstenLoadbalancerName); assertNotNull(loadbalancer); - s_logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); + logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); LoadbalancerListener loadbalancerListener = (LoadbalancerListener) tungstenApi.createTungstenLoadbalancerListener( projectUuid, loadbalancer.getUuid(), tungstenLoadbalancerListenerName, "tcp", 24); assertNotNull(loadbalancerListener); - s_logger.debug("Create a loadbalancer health monitor in Tungsten-Fabric"); + logger.debug("Create a loadbalancer health monitor in Tungsten-Fabric"); LoadbalancerHealthmonitor loadbalancerHealthmonitor = (LoadbalancerHealthmonitor) tungstenApi.createTungstenLoadbalancerHealthMonitor( projectUuid, "LoadbalancerHealthMonitor", "PING", 3, 5, 5, null, null, null); assertNotNull(loadbalancerHealthmonitor); - s_logger.debug("Create a loadbalancer pool in Tungsten-Fabric"); + logger.debug("Create a loadbalancer pool in Tungsten-Fabric"); LoadbalancerPool loadbalancerPool = (LoadbalancerPool) tungstenApi.createTungstenLoadbalancerPool(projectUuid, loadbalancerListener.getUuid(), loadbalancerHealthmonitor.getUuid(), tungstenLoadbalancerPoolName, "ROUND_ROBIN", "TCP"); assertNotNull(loadbalancerPool); - s_logger.debug("Check if the loadbalancer pool was created in Tungsten-Fabric"); + logger.debug("Check if the loadbalancer pool was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObject(LoadbalancerPool.class, loadbalancerPool.getUuid())); } @Test public void createTungstenLoadbalancerMemberTest() { - s_logger.debug("Create a loadbalancer pool in Tungsten-Fabric"); + logger.debug("Create a loadbalancer pool in Tungsten-Fabric"); createTungstenLoadbalancerPoolTest(); - s_logger.debug("Get the loadbalancer pool from Tungsten-Fabric"); + logger.debug("Get the loadbalancer pool from Tungsten-Fabric"); Project project = (Project) tungstenApi.getTungstenObject(Project.class, projectUuid); LoadbalancerPool loadbalancerPool = (LoadbalancerPool) tungstenApi.getTungstenObjectByName( LoadbalancerPool.class, project.getQualifiedName(), tungstenLoadbalancerPoolName); assertNotNull(loadbalancerPool); - s_logger.debug("Create a loadbalancer member in Tungsten-Fabric"); + logger.debug("Create a loadbalancer member in Tungsten-Fabric"); LoadbalancerMember loadbalancerMember = (LoadbalancerMember) tungstenApi.createTungstenLoadbalancerMember( loadbalancerPool.getUuid(), "TungstenLoadbalancerMember", "10.0.0.0", null, 24, 5); assertNotNull(loadbalancerMember); - s_logger.debug("Check if the loadbalancer member was created in Tungsten-Fabric"); + logger.debug("Check if the loadbalancer member was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObject(LoadbalancerMember.class, loadbalancerMember.getUuid())); } @Test public void createTungstenInstanceIpTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create a virtual machine in Tungsten-Fabric."); + logger.debug("Create a virtual machine in Tungsten-Fabric."); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if the instance ip is not exist in Tungsten-Fabric"); + logger.debug("Check if the instance ip is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "TungstenInstanceIp")); - s_logger.debug("Create instance ip in Tungsten-Fabric"); + logger.debug("Create instance ip in Tungsten-Fabric"); assertNotNull( tungstenApi.createTungstenInstanceIp("TungstenInstanceIp", "192.168.1.100", tungstenNetworkUuid, vmiUuid)); - s_logger.debug("Check if the instance ip was created in Tungsten-Fabric"); + logger.debug("Check if the instance ip was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "TungstenInstanceIp")); } @Test public void createTungstenInstanceIpWithSubnetTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create a virtual machine in Tungsten-Fabric."); + logger.debug("Create a virtual machine in Tungsten-Fabric."); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if the instance ip is not exist in Tungsten-Fabric"); + logger.debug("Check if the instance ip is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "TungstenInstanceIp")); - s_logger.debug("Create instance ip in Tungsten-Fabric"); + logger.debug("Create instance ip in Tungsten-Fabric"); assertNotNull( tungstenApi.createTungstenInstanceIp("TungstenInstanceIp", "192.168.1.100", tungstenNetworkUuid, vmiUuid, tungstenApi.getSubnetUuid(tungstenNetworkUuid))); - s_logger.debug("Check if the instance ip was created in Tungsten-Fabric"); + logger.debug("Check if the instance ip was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "TungstenInstanceIp")); } @Test public void createTungstenFloatingIpPoolTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); VirtualNetwork virtualNetwork = tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Check if the floating ip pool is not exist in Tungsten-Fabric"); + logger.debug("Check if the floating ip pool is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObjectByName(FloatingIpPool.class, virtualNetwork.getQualifiedName(), "TungstenFip")); - s_logger.debug("Create instance ip in Tungsten-Fabric"); + logger.debug("Create instance ip in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenFloatingIpPool(tungstenNetworkUuid, "TungstenFip")); - s_logger.debug("Check if the instance ip was created in Tungsten-Fabric"); + logger.debug("Check if the instance ip was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObjectByName(FloatingIpPool.class, virtualNetwork.getQualifiedName(), "TungstenFip")); } @Test public void createTungstenLbVmiTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Check if the lb vmi is not exist in Tungsten-Fabric"); + logger.debug("Check if the lb vmi is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObjectByName(VirtualMachineInterface.class, project.getQualifiedName(), "TungstenLbVmi")); - s_logger.debug("Create lb vmi in Tungsten-Fabric"); + logger.debug("Create lb vmi in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenLbVmi("TungstenLbVmi", projectUuid, tungstenNetworkUuid)); - s_logger.debug("Check if the lb vmi was created in Tungsten-Fabric"); + logger.debug("Check if the lb vmi was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObjectByName(VirtualMachineInterface.class, project.getQualifiedName(), "TungstenLbVmi")); } @Test public void updateTungstenObjectTest() { - s_logger.debug("Create public network in Tungsten-Fabric."); + logger.debug("Create public network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenPublicNetworkName, tungstenPublicNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Creating a logical router in Tungsten-Fabric."); + logger.debug("Creating a logical router in Tungsten-Fabric."); LogicalRouter logicalRouter = (LogicalRouter) tungstenApi.createTungstenLogicalRouter("TungstenLogicalRouter", projectUuid, tungstenNetworkUuid); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); VirtualMachineInterface virtualMachineInterface = (VirtualMachineInterface) tungstenApi.createTungstenGatewayVmi( vmiName, projectUuid, tungstenNetworkUuid); - s_logger.debug("Check if the logical router vmi is not exist in Tungsten-Fabric"); + logger.debug("Check if the logical router vmi is not exist in Tungsten-Fabric"); assertNull(logicalRouter.getVirtualMachineInterface()); - s_logger.debug("Update logical router with vmi"); + logger.debug("Update logical router with vmi"); logicalRouter.setVirtualMachineInterface(virtualMachineInterface); tungstenApi.updateTungstenObject(logicalRouter); - s_logger.debug("Check updated logical router have vmi uuid equals created vmi uuid"); + logger.debug("Check updated logical router have vmi uuid equals created vmi uuid"); LogicalRouter updatedlogicalRouter = (LogicalRouter) tungstenApi.getTungstenObjectByName(LogicalRouter.class, project.getQualifiedName(), "TungstenLogicalRouter"); assertEquals(virtualMachineInterface.getUuid(), @@ -503,49 +504,49 @@ public void updateTungstenObjectTest() { @Test public void createTungstenFloatingIpTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create instance ip in Tungsten-Fabric"); + logger.debug("Create instance ip in Tungsten-Fabric"); FloatingIpPool floatingIpPool = (FloatingIpPool) tungstenApi.createTungstenFloatingIpPool(tungstenNetworkUuid, "TungstenFip"); - s_logger.debug("Check if the floating ip pool is not exist in Tungsten-Fabric"); + logger.debug("Check if the floating ip pool is not exist in Tungsten-Fabric"); assertNull( tungstenApi.getTungstenObjectByName(FloatingIp.class, floatingIpPool.getQualifiedName(), "TungstenFi")); - s_logger.debug("Create floating ip in Tungsten-Fabric"); + logger.debug("Create floating ip in Tungsten-Fabric"); assertNotNull( tungstenApi.createTungstenFloatingIp(projectUuid, tungstenNetworkUuid, "TungstenFip", "TungstenFi", "192.168.1.100")); - s_logger.debug("Check if the lb vmi was created in Tungsten-Fabric"); + logger.debug("Check if the lb vmi was created in Tungsten-Fabric"); assertNotNull( tungstenApi.getTungstenObjectByName(FloatingIp.class, floatingIpPool.getQualifiedName(), "TungstenFi")); } @Test public void assignTungstenFloatingIpTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create instance ip in Tungsten-Fabric"); + logger.debug("Create instance ip in Tungsten-Fabric"); tungstenApi.createTungstenFloatingIpPool(tungstenNetworkUuid, "TungstenFip"); - s_logger.debug("Create floating ip in Tungsten-Fabric"); + logger.debug("Create floating ip in Tungsten-Fabric"); tungstenApi.createTungstenFloatingIp(projectUuid, tungstenNetworkUuid, "TungstenFip", "TungstenFi", "192.168.1.100"); - s_logger.debug("Create vm in Tungsten-Fabric"); + logger.debug("Create vm in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if the floating ip was assigned in Tungsten-Fabric"); + logger.debug("Check if the floating ip was assigned in Tungsten-Fabric"); Assert.assertTrue( tungstenApi.assignTungstenFloatingIp(tungstenNetworkUuid, vmiUuid, "TungstenFip", "TungstenFi", "192.168.1.100")); @@ -553,59 +554,59 @@ public void assignTungstenFloatingIpTest() { @Test public void releaseTungstenFloatingIpTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create instance ip in Tungsten-Fabric"); + logger.debug("Create instance ip in Tungsten-Fabric"); tungstenApi.createTungstenFloatingIpPool(tungstenNetworkUuid, "TungstenFip"); - s_logger.debug("Create floating ip in Tungsten-Fabric"); + logger.debug("Create floating ip in Tungsten-Fabric"); tungstenApi.createTungstenFloatingIp(projectUuid, tungstenNetworkUuid, "TungstenFip", "TungstenFi", "192.168.1.100"); - s_logger.debug("Create vm in Tungsten-Fabric"); + logger.debug("Create vm in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if the floating ip was assigned in Tungsten-Fabric"); + logger.debug("Check if the floating ip was assigned in Tungsten-Fabric"); tungstenApi.assignTungstenFloatingIp(tungstenNetworkUuid, vmiUuid, "TungstenFip", "TungstenFi", "192.168.1.100"); - s_logger.debug("Check if the floating ip was assigned in Tungsten-Fabric"); + logger.debug("Check if the floating ip was assigned in Tungsten-Fabric"); Assert.assertTrue(tungstenApi.releaseTungstenFloatingIp(tungstenNetworkUuid, "TungstenFip", "TungstenFi")); } @Test public void createTungstenNetworkPolicyTest() { - s_logger.debug("Prepare network policy rule 1"); + logger.debug("Prepare network policy rule 1"); List tungstenRuleList1 = new ArrayList<>(); TungstenRule tungstenRule1 = new TungstenRule("005f0dea-0196-11ec-a1ed-b42e99f6e187", "pass", ">", "tcp", null, "192.168.100.0", 24, 80, 80, null, "192.168.200.0", 24, 80, 80); tungstenRuleList1.add(tungstenRule1); - s_logger.debug("Create a network policy in Tungsten-Fabric."); + logger.debug("Create a network policy in Tungsten-Fabric."); assertNotNull(tungstenApi.createOrUpdateTungstenNetworkPolicy("policy1", projectUuid, tungstenRuleList1)); - s_logger.debug("Get created network policy and check if network policy rule has created"); + logger.debug("Get created network policy and check if network policy rule has created"); NetworkPolicy networkPolicy = (NetworkPolicy) tungstenApi.getTungstenObjectByName(NetworkPolicy.class, project.getQualifiedName(), "policy1"); assertEquals("005f0dea-0196-11ec-a1ed-b42e99f6e187", networkPolicy.getEntries().getPolicyRule().get(0).getRuleUuid()); - s_logger.debug("Prepare network policy rule 2"); + logger.debug("Prepare network policy rule 2"); List tungstenRuleList2 = new ArrayList<>(); TungstenRule tungstenRule2 = new TungstenRule("105f0dea-0196-11ec-a1ed-b42e99f6e187", "pass", ">", "tcp", null, "192.168.100.0", 24, 80, 80, null, "192.168.200.0", 24, 80, 80); tungstenRuleList2.add(tungstenRule2); - s_logger.debug("update created network policy in Tungsten-Fabric."); + logger.debug("update created network policy in Tungsten-Fabric."); assertNotNull(tungstenApi.createOrUpdateTungstenNetworkPolicy("policy1", projectUuid, tungstenRuleList2)); - s_logger.debug("Get updated network policy and check if network policy rule has updated"); + logger.debug("Get updated network policy and check if network policy rule has updated"); NetworkPolicy networkPolicy1 = (NetworkPolicy) tungstenApi.getTungstenObjectByName(NetworkPolicy.class, project.getQualifiedName(), "policy1"); assertEquals("105f0dea-0196-11ec-a1ed-b42e99f6e187", @@ -614,26 +615,26 @@ public void createTungstenNetworkPolicyTest() { @Test public void applyTungstenNetworkPolicy() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Prepare network policy rule"); + logger.debug("Prepare network policy rule"); List tungstenRuleList = new ArrayList<>(); - s_logger.debug("Create a network policy in Tungsten-Fabric."); + logger.debug("Create a network policy in Tungsten-Fabric."); NetworkPolicy networkPolicy = (NetworkPolicy) tungstenApi.createOrUpdateTungstenNetworkPolicy("policy", projectUuid, tungstenRuleList); - s_logger.debug("Check if network policy was not applied in Tungsten-Fabric."); + logger.debug("Check if network policy was not applied in Tungsten-Fabric."); VirtualNetwork virtualNetwork1 = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid); assertNull(virtualNetwork1.getNetworkPolicy()); - s_logger.debug("Apply network policy to network in Tungsten-Fabric."); + logger.debug("Apply network policy to network in Tungsten-Fabric."); assertNotNull(tungstenApi.applyTungstenNetworkPolicy(networkPolicy.getUuid(), tungstenNetworkUuid, 1, 1)); - s_logger.debug("Check if network policy was applied in Tungsten-Fabric."); + logger.debug("Check if network policy was applied in Tungsten-Fabric."); VirtualNetwork virtualNetwork2 = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid); assertNotNull(virtualNetwork2.getNetworkPolicy()); @@ -641,145 +642,145 @@ public void applyTungstenNetworkPolicy() { @Test public void getTungstenFabricNetworkTest() { - s_logger.debug("Create fabric virtual network in Tungsten-Fabric."); + logger.debug("Create fabric virtual network in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenNetwork(null, "ip-fabric", "ip-fabric", projectUuid, true, false, null, 0, null, true, null, null, null, false, false, "")); - s_logger.debug("Check if fabric network was got in Tungsten-Fabric."); + logger.debug("Check if fabric network was got in Tungsten-Fabric."); assertNotNull(tungstenApi.getTungstenFabricNetwork()); } @Test public void createTungstenDomainTest() { - s_logger.debug("Check if domain was created in Tungsten-Fabric."); + logger.debug("Check if domain was created in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenDomain("domain", "0a01e4c7-d912-4bd5-9786-5478e3dae7b2")); } @Test public void createTungstenProjectTest() { - s_logger.debug("Check if project was created in Tungsten-Fabric."); + logger.debug("Check if project was created in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenProject("project","fe44b353-21e7-4e6c-af18-1325c5ef886a","0a01e4c7-d912-4bd5-9786-5478e3dae7b2", "domain")); } @Test public void deleteTungstenDomainTest() { - s_logger.debug("Create domain in Tungsten-Fabric."); + logger.debug("Create domain in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenDomain("domain", "0a01e4c7-d912-4bd5-9786-5478e3dae7b2")); - s_logger.debug("Check if domain was deleted in Tungsten-Fabric."); + logger.debug("Check if domain was deleted in Tungsten-Fabric."); assertTrue(tungstenApi.deleteTungstenDomain("0a01e4c7-d912-4bd5-9786-5478e3dae7b2")); } @Test public void deleteTungstenProjectTest() { - s_logger.debug("Create project in Tungsten-Fabric."); + logger.debug("Create project in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenProject("project","fe44b353-21e7-4e6c-af18-1325c5ef886a","0a01e4c7-d912-4bd5-9786-5478e3dae7b2", "domain")); - s_logger.debug("Check if project was deleted in Tungsten-Fabric."); + logger.debug("Check if project was deleted in Tungsten-Fabric."); assertTrue(tungstenApi.deleteTungstenProject("fe44b353-21e7-4e6c-af18-1325c5ef886a")); } @Test public void getDefaultTungstenDomainTest() throws IOException { - s_logger.debug("Check if default domain was got in Tungsten-Fabric."); + logger.debug("Check if default domain was got in Tungsten-Fabric."); assertNotNull(tungstenApi.getDefaultTungstenDomain()); } @Test public void updateLoadBalancerMemberTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create a vm in Tungsten-Fabric"); + logger.debug("Create a vm in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Create loadbalancer in Tungsten-Fabric"); + logger.debug("Create loadbalancer in Tungsten-Fabric"); Loadbalancer loadbalancer = (Loadbalancer) tungstenApi.createTungstenLoadbalancer(projectUuid, tungstenLoadbalancerName, vmiUuid, tungstenApi.getSubnetUuid(tungstenNetworkUuid), "192.168.2.100"); - s_logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); + logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); LoadbalancerListener loadbalancerListener = (LoadbalancerListener) tungstenApi.createTungstenLoadbalancerListener( projectUuid, loadbalancer.getUuid(), tungstenLoadbalancerListenerName, "tcp", 24); - s_logger.debug("Create a loadbalancer health monitor in Tungsten-Fabric"); + logger.debug("Create a loadbalancer health monitor in Tungsten-Fabric"); LoadbalancerHealthmonitor loadbalancerHealthmonitor = (LoadbalancerHealthmonitor) tungstenApi.createTungstenLoadbalancerHealthMonitor( projectUuid, "LoadbalancerHealthMonitor", "PING", 3, 5, 5, null, null, null); - s_logger.debug("Create a loadbalancer pool in Tungsten-Fabric"); + logger.debug("Create a loadbalancer pool in Tungsten-Fabric"); LoadbalancerPool loadbalancerPool = (LoadbalancerPool) tungstenApi.createTungstenLoadbalancerPool(projectUuid, loadbalancerListener.getUuid(), loadbalancerHealthmonitor.getUuid(), tungstenLoadbalancerPoolName, "ROUND_ROBIN", "TCP"); - s_logger.debug("Update loadbalancer member 1 in Tungsten-Fabric"); + logger.debug("Update loadbalancer member 1 in Tungsten-Fabric"); List tungstenLoadBalancerMemberList1 = new ArrayList<>(); tungstenLoadBalancerMemberList1.add(new TungstenLoadBalancerMember("member1", "192.168.100.100", 80, 1)); assertTrue(tungstenApi.updateLoadBalancerMember(projectUuid, tungstenLoadbalancerPoolName, tungstenLoadBalancerMemberList1, tungstenApi.getSubnetUuid(tungstenNetworkUuid))); - s_logger.debug("Check if loadbalancer member 2 was updated in Tungsten-Fabric"); + logger.debug("Check if loadbalancer member 2 was updated in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObjectByName(LoadbalancerMember.class, loadbalancerPool.getQualifiedName(), "member1")); - s_logger.debug("Update loadbalancer member 2 in Tungsten-Fabric"); + logger.debug("Update loadbalancer member 2 in Tungsten-Fabric"); List tungstenLoadBalancerMemberList2 = new ArrayList<>(); tungstenLoadBalancerMemberList2.add(new TungstenLoadBalancerMember("member2", "192.168.100.100", 80, 1)); assertTrue(tungstenApi.updateLoadBalancerMember(projectUuid, tungstenLoadbalancerPoolName, tungstenLoadBalancerMemberList2, tungstenApi.getSubnetUuid(tungstenNetworkUuid))); - s_logger.debug("Check if loadbalancer member 1 was deleted in Tungsten-Fabric"); + logger.debug("Check if loadbalancer member 1 was deleted in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObjectByName(LoadbalancerMember.class, loadbalancerPool.getQualifiedName(), "member1")); - s_logger.debug("Check if loadbalancer member 2 was created in Tungsten-Fabric"); + logger.debug("Check if loadbalancer member 2 was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObjectByName(LoadbalancerMember.class, loadbalancerPool.getQualifiedName(), "member2")); } @Test public void updateLoadBalancerPoolTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create floating ip in Tungsten-Fabric"); + logger.debug("Create floating ip in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Create loadbalancer in Tungsten-Fabric"); + logger.debug("Create loadbalancer in Tungsten-Fabric"); Loadbalancer loadbalancer = (Loadbalancer) tungstenApi.createTungstenLoadbalancer(projectUuid, tungstenLoadbalancerName, vmiUuid, tungstenApi.getSubnetUuid(tungstenNetworkUuid), "192.168.2.100"); - s_logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); + logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); LoadbalancerListener loadbalancerListener = (LoadbalancerListener) tungstenApi.createTungstenLoadbalancerListener( projectUuid, loadbalancer.getUuid(), tungstenLoadbalancerListenerName, "tcp", 24); - s_logger.debug("Create a loadbalancer health monitor in Tungsten-Fabric"); + logger.debug("Create a loadbalancer health monitor in Tungsten-Fabric"); LoadbalancerHealthmonitor loadbalancerHealthmonitor = (LoadbalancerHealthmonitor) tungstenApi.createTungstenLoadbalancerHealthMonitor( projectUuid, "LoadbalancerHealthMonitor", "PING", 3, 5, 5, null, null, null); - s_logger.debug("Create a loadbalancer pool in Tungsten-Fabric"); + logger.debug("Create a loadbalancer pool in Tungsten-Fabric"); tungstenApi.createTungstenLoadbalancerPool(projectUuid, loadbalancerListener.getUuid(), loadbalancerHealthmonitor.getUuid(), tungstenLoadbalancerPoolName, "ROUND_ROBIN", "TCP"); - s_logger.debug("Update loadbalancer pool in Tungsten-Fabric"); + logger.debug("Update loadbalancer pool in Tungsten-Fabric"); assertTrue( tungstenApi.updateLoadBalancerPool(projectUuid, tungstenLoadbalancerPoolName, "SOURCE_IP", "APP_COOKIE", "cookie", "UDP", true, "80", "/stats", "admin:abc")); - s_logger.debug("Check if loadbalancer pool was updated in Tungsten-Fabric"); + logger.debug("Check if loadbalancer pool was updated in Tungsten-Fabric"); LoadbalancerPool loadbalancerPool = (LoadbalancerPool) tungstenApi.getTungstenObjectByName( LoadbalancerPool.class, project.getQualifiedName(), tungstenLoadbalancerPoolName); assertEquals("SOURCE_IP", loadbalancerPool.getProperties().getLoadbalancerMethod()); @@ -790,30 +791,30 @@ public void updateLoadBalancerPoolTest() { @Test public void updateLoadBalancerListenerTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create floating ip in Tungsten-Fabric"); + logger.debug("Create floating ip in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Create loadbalancer in Tungsten-Fabric"); + logger.debug("Create loadbalancer in Tungsten-Fabric"); Loadbalancer loadbalancer = (Loadbalancer) tungstenApi.createTungstenLoadbalancer(projectUuid, tungstenLoadbalancerName, vmiUuid, tungstenApi.getSubnetUuid(tungstenNetworkUuid), "192.168.2.100"); - s_logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); + logger.debug("Create a loadbalancer listener in Tungsten-Fabric"); tungstenApi.createTungstenLoadbalancerListener(projectUuid, loadbalancer.getUuid(), tungstenLoadbalancerListenerName, "tcp", 24); - s_logger.debug("update loadbalancer listener in Tungsten-Fabric"); + logger.debug("update loadbalancer listener in Tungsten-Fabric"); assertTrue(tungstenApi.updateLoadBalancerListener(projectUuid, tungstenLoadbalancerListenerName, "udp", 25, "http://host:8080/client/getLoadBalancerSslCertificate")); - s_logger.debug("Check if loadbalancer listener was updated in Tungsten-Fabric"); + logger.debug("Check if loadbalancer listener was updated in Tungsten-Fabric"); LoadbalancerListener loadbalancerListener = (LoadbalancerListener) tungstenApi.getTungstenObjectByName( LoadbalancerListener.class, project.getQualifiedName(), tungstenLoadbalancerListenerName); assertEquals("udp", loadbalancerListener.getProperties().getProtocol()); @@ -824,30 +825,30 @@ public void updateLoadBalancerListenerTest() { @Test public void applyTungstenPortForwardingTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create instance ip in Tungsten-Fabric"); + logger.debug("Create instance ip in Tungsten-Fabric"); tungstenApi.createTungstenFloatingIpPool(tungstenNetworkUuid, "TungstenFip"); - s_logger.debug("Create floating ip in Tungsten-Fabric"); + logger.debug("Create floating ip in Tungsten-Fabric"); FloatingIp floatingIp = (FloatingIp) tungstenApi.createTungstenFloatingIp(projectUuid, tungstenNetworkUuid, "TungstenFip", "TungstenFi", "192.168.1.100"); - s_logger.debug("Create floating ip in Tungsten-Fabric"); + logger.debug("Create floating ip in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if the port mapping is not exist in Tungsten-Fabric"); + logger.debug("Check if the port mapping is not exist in Tungsten-Fabric"); assertNull(floatingIp.getPortMappings()); assertNull(floatingIp.getVirtualMachineInterface()); assertNull(floatingIp.getPortMappingsEnable()); - s_logger.debug("Check if the port mapping was add in Tungsten-Fabric"); + logger.debug("Check if the port mapping was add in Tungsten-Fabric"); assertTrue( tungstenApi.applyTungstenPortForwarding(true, tungstenNetworkUuid, "TungstenFip", "TungstenFi", vmiUuid, "tcp", 8080, 80)); @@ -857,7 +858,7 @@ public void applyTungstenPortForwardingTest() { assertNotNull(floatingIp.getVirtualMachineInterface()); assertTrue(floatingIp.getPortMappingsEnable()); - s_logger.debug("Check if the port mapping was remove in Tungsten-Fabric"); + logger.debug("Check if the port mapping was remove in Tungsten-Fabric"); assertTrue(tungstenApi.applyTungstenPortForwarding(false, tungstenNetworkUuid, "TungstenFip", "TungstenFi", vmiUuid, "tcp", 8080, 80)); assertEquals(0, floatingIp.getPortMappings().getPortMappings().size()); @@ -867,14 +868,14 @@ public void applyTungstenPortForwardingTest() { @Test public void addTungstenNetworkSubnetCommandTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); VirtualNetwork virtualNetwork = tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, null, 0, null, false, null, null, null, false, false, null); - s_logger.debug("Check if network ipam subnet is empty in Tungsten-Fabric"); + logger.debug("Check if network ipam subnet is empty in Tungsten-Fabric"); assertNull(virtualNetwork.getNetworkIpam()); - s_logger.debug("Check if network ipam subnet was added to network in Tungsten-Fabric"); + logger.debug("Check if network ipam subnet was added to network in Tungsten-Fabric"); assertTrue(tungstenApi.addTungstenNetworkSubnetCommand(tungstenNetworkUuid, "10.0.0.0", 24, "10.0.0.1", true, "10.0.0.253", "10.0.0.10", "10.0.0.20", true, "subnetName")); VirtualNetwork virtualNetwork1 = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, @@ -912,18 +913,18 @@ public void addTungstenNetworkSubnetCommandTest() { @Test public void removeTungstenNetworkSubnetCommandTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "192.168.100.0", 23, "192.168.100.1", false, null, null, null, false, false, "subnetName1"); - s_logger.debug("Check if network ipam subnet was added to network in Tungsten-Fabric"); + logger.debug("Check if network ipam subnet was added to network in Tungsten-Fabric"); assertTrue(tungstenApi.addTungstenNetworkSubnetCommand(tungstenNetworkUuid, "10.0.0.0", 24, "10.0.0.1", true, "10.0.0.253", "10.0.0.10", "10.0.0.20", true, "subnetName2")); VirtualNetwork virtualNetwork1 = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid); assertEquals(2, virtualNetwork1.getNetworkIpam().get(0).getAttr().getIpamSubnets().size()); - s_logger.debug("Check if network ipam subnet was removed to network in Tungsten-Fabric"); + logger.debug("Check if network ipam subnet was removed to network in Tungsten-Fabric"); assertTrue(tungstenApi.removeTungstenNetworkSubnetCommand(tungstenNetworkUuid, "subnetName2")); VirtualNetwork virtualNetwork2 = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid); @@ -932,112 +933,112 @@ public void removeTungstenNetworkSubnetCommandTest() { @Test public void createTungstenTagTypeTest() { - s_logger.debug("Check if tag type is not exist in Tungsten-Fabric"); + logger.debug("Check if tag type is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObject(TagType.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Create tag type in Tungsten-Fabric"); + logger.debug("Create tag type in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenTagType("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype")); - s_logger.debug("Check if tag type was created in Tungsten-Fabric"); + logger.debug("Check if tag type was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObject(TagType.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); } @Test public void createTungstenTagTest() { - s_logger.debug("Check if tag is not exist in Tungsten-Fabric"); + logger.debug("Check if tag is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObject(Tag.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenTag("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype", "tagvalue", "123")); - s_logger.debug("Check if tag was created in Tungsten-Fabric"); + logger.debug("Check if tag was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObject(Tag.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); } @Test public void createTungstenApplicationPolicySetTest() { - s_logger.debug("Check if application policy set is not exist in Tungsten-Fabric"); + logger.debug("Check if application policy set is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObject(ApplicationPolicySet.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Create application policy set in Tungsten-Fabric"); + logger.debug("Create application policy set in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenApplicationPolicySet("005f0dea-0196-11ec-a1ed-b42e99f6e187", "applicationpolicyset")); - s_logger.debug("Check if application policy set was created in Tungsten-Fabric"); + logger.debug("Check if application policy set was created in Tungsten-Fabric"); assertNotNull( tungstenApi.getTungstenObject(ApplicationPolicySet.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); } @Test public void createTungstenFirewallPolicyTest() { - s_logger.debug("Create application policy set in Tungsten-Fabric"); + logger.debug("Create application policy set in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenApplicationPolicySet("f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "applicationpolicyset")); - s_logger.debug("Check if firewall policy is not exist in Tungsten-Fabric"); + logger.debug("Check if firewall policy is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObject(FirewallPolicy.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Create firewall policy in Tungsten-Fabric"); + logger.debug("Create firewall policy in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenFirewallPolicy("005f0dea-0196-11ec-a1ed-b42e99f6e187", "f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "firewallpolicy", 1)); - s_logger.debug("Check if firewall policy was created in Tungsten-Fabric"); + logger.debug("Check if firewall policy was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObject(FirewallPolicy.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); } @Test public void createTungstenFirewallRuleTest() { - s_logger.debug("Create application policy set in Tungsten-Fabric"); + logger.debug("Create application policy set in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenApplicationPolicySet("f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "applicationpolicyset")); - s_logger.debug("Create firewall policy in Tungsten-Fabric"); + logger.debug("Create firewall policy in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenFirewallPolicy("1ab1b179-8c6c-492a-868e-0493f4be175c", "f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "firewallpolicy", 1)); - s_logger.debug("Check if firewall rule is not exist in Tungsten-Fabric"); + logger.debug("Check if firewall rule is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObject(FirewallRule.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Create service group in Tungsten-Fabric"); + logger.debug("Create service group in Tungsten-Fabric"); tungstenApi.createTungstenServiceGroup("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "servicegroup", "tcp", 80, 90); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "tagtype1", "tagvalue1", "123"); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("7d5575eb-d029-467e-8b78-6056a8c94a71", "tagtype2", "tagvalue2", "123"); - s_logger.debug("Create address group in Tungsten-Fabric"); + logger.debug("Create address group in Tungsten-Fabric"); tungstenApi.createTungstenAddressGroup("88729834-3ebd-413a-adf9-40aff73cf638", "addressgroup1", "10.0.0.0", 24); - s_logger.debug("Create address group in Tungsten-Fabric"); + logger.debug("Create address group in Tungsten-Fabric"); tungstenApi.createTungstenAddressGroup("9291ae28-56cf-448c-b848-f2334b3c86da", "addressgroup2", "10.0.0.0", 24); - s_logger.debug("Create tag type in Tungsten-Fabric"); + logger.debug("Create tag type in Tungsten-Fabric"); tungstenApi.createTungstenTagType("c1680d93-2614-4f99-a8c5-d4f11b3dfc9d", "tagtype"); - s_logger.debug("Create firewall rule in Tungsten-Fabric"); + logger.debug("Create firewall rule in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenFirewallRule("124d0792-e890-4b7e-8fe8-1b7a6d63c66a", "1ab1b179-8c6c-492a-868e-0493f4be175c", "firewallrule", "pass", "baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "88729834-3ebd-413a-adf9-40aff73cf638", null, ">", "7d5575eb-d029-467e-8b78-6056a8c94a71", "9291ae28-56cf-448c-b848-f2334b3c86da", null, "c1680d93-2614-4f99-a8c5-d4f11b3dfc9d", 1)); - s_logger.debug("Check if firewall rule was created in Tungsten-Fabric"); + logger.debug("Check if firewall rule was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObject(FirewallRule.class, "124d0792-e890-4b7e-8fe8-1b7a6d63c66a")); } @Test public void createTungstenServiceGroupTest() { - s_logger.debug("Check if service group is not exist in Tungsten-Fabric"); + logger.debug("Check if service group is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObject(ServiceGroup.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Create service group in Tungsten-Fabric"); + logger.debug("Create service group in Tungsten-Fabric"); assertNotNull( tungstenApi.createTungstenServiceGroup("005f0dea-0196-11ec-a1ed-b42e99f6e187", "servicegroup", "tcp", 80, 90)); - s_logger.debug("Check if service group was created in Tungsten-Fabric"); + logger.debug("Check if service group was created in Tungsten-Fabric"); ServiceGroup serviceGroup = (ServiceGroup) tungstenApi.getTungstenObject(ServiceGroup.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertNotNull(serviceGroup); @@ -1050,15 +1051,15 @@ public void createTungstenServiceGroupTest() { @Test public void createTungstenAddressGroupTest() { - s_logger.debug("Check if address group is not exist in Tungsten-Fabric"); + logger.debug("Check if address group is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObject(AddressGroup.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Create address group in Tungsten-Fabric"); + logger.debug("Create address group in Tungsten-Fabric"); assertNotNull( tungstenApi.createTungstenAddressGroup("005f0dea-0196-11ec-a1ed-b42e99f6e187", "addressgroup", "10.0.0.0", 24)); - s_logger.debug("Check if address group was created in Tungsten-Fabric"); + logger.debug("Check if address group was created in Tungsten-Fabric"); AddressGroup addressGroup = (AddressGroup) tungstenApi.getTungstenObject(AddressGroup.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertNotNull(addressGroup); @@ -1068,17 +1069,17 @@ public void createTungstenAddressGroupTest() { @Test public void applyTungstenNetworkTagTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); VirtualNetwork virtualNetwork = tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, null, 0, null, false, null, null, null, false, false, null); - s_logger.debug("Check if tag is not apply to network in Tungsten-Fabric"); + logger.debug("Check if tag is not apply to network in Tungsten-Fabric"); assertNull(virtualNetwork.getTag()); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype", "tagvalue", "123"); - s_logger.debug("Check if tag was applied to network in Tungsten-Fabric"); + logger.debug("Check if tag was applied to network in Tungsten-Fabric"); assertTrue(tungstenApi.applyTungstenNetworkTag(List.of(tungstenNetworkUuid), "005f0dea-0196-11ec-a1ed-b42e99f6e187")); VirtualNetwork virtualNetwork1 = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, @@ -1088,16 +1089,16 @@ public void applyTungstenNetworkTagTest() { @Test public void applyTungstenVmTagTest() { - s_logger.debug("Create vm in Tungsten-Fabric"); + logger.debug("Create vm in Tungsten-Fabric"); VirtualMachine virtualMachine = tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Check if tag is not apply to vm in Tungsten-Fabric"); + logger.debug("Check if tag is not apply to vm in Tungsten-Fabric"); assertNull(virtualMachine.getTag()); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype", "tagvalue", "123"); - s_logger.debug("Check if tag was applied to vm in Tungsten-Fabric"); + logger.debug("Check if tag was applied to vm in Tungsten-Fabric"); assertTrue( tungstenApi.applyTungstenVmTag(List.of(tungstenVmUuid), "005f0dea-0196-11ec-a1ed-b42e99f6e187")); VirtualMachine virtualMachine1 = (VirtualMachine) tungstenApi.getTungstenObject(VirtualMachine.class, @@ -1107,24 +1108,24 @@ public void applyTungstenVmTagTest() { @Test public void applyTungstenNicTagTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create vm in Tungsten-Fabric"); + logger.debug("Create vm in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); VirtualMachineInterface virtualMachineInterface = tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if tag is not apply to vmi in Tungsten-Fabric"); + logger.debug("Check if tag is not apply to vmi in Tungsten-Fabric"); assertNull(virtualMachineInterface.getTag()); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype", "tagvalue", "123"); - s_logger.debug("Check if tag was applied to vmi in Tungsten-Fabric"); + logger.debug("Check if tag was applied to vmi in Tungsten-Fabric"); assertTrue(tungstenApi.applyTungstenNicTag(List.of(vmiUuid), "005f0dea-0196-11ec-a1ed-b42e99f6e187")); VirtualMachineInterface virtualMachineInterface1 = (VirtualMachineInterface) tungstenApi.getTungstenObject( VirtualMachineInterface.class, vmiUuid); @@ -1133,18 +1134,18 @@ public void applyTungstenNicTagTest() { @Test public void applyTungstenPolicyTagTest() { - s_logger.debug("Create a network policy in Tungsten-Fabric."); + logger.debug("Create a network policy in Tungsten-Fabric."); List tungstenRuleList1 = new ArrayList<>(); NetworkPolicy networkPolicy = (NetworkPolicy) tungstenApi.createOrUpdateTungstenNetworkPolicy("policy", projectUuid, tungstenRuleList1); - s_logger.debug("Check if tag is not apply to network policy in Tungsten-Fabric"); + logger.debug("Check if tag is not apply to network policy in Tungsten-Fabric"); assertNull(networkPolicy.getTag()); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype", "tagvalue", "123"); - s_logger.debug("Check if tag was applied to network policy in Tungsten-Fabric"); + logger.debug("Check if tag was applied to network policy in Tungsten-Fabric"); assertTrue(tungstenApi.applyTungstenPolicyTag(networkPolicy.getUuid(), "005f0dea-0196-11ec-a1ed-b42e99f6e187")); NetworkPolicy networkPolicy1 = (NetworkPolicy) tungstenApi.getTungstenObjectByName(NetworkPolicy.class, project.getQualifiedName(), "policy"); @@ -1153,78 +1154,78 @@ public void applyTungstenPolicyTagTest() { @Test public void removeTungstenTagTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create vm in Tungsten-Fabric"); + logger.debug("Create vm in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Creating a vmi in Tungsten-Fabric."); + logger.debug("Creating a vmi in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Create a network policy in Tungsten-Fabric."); + logger.debug("Create a network policy in Tungsten-Fabric."); - s_logger.debug("Create a network policy in Tungsten-Fabric."); + logger.debug("Create a network policy in Tungsten-Fabric."); List tungstenRuleList1 = new ArrayList<>(); NetworkPolicy networkPolicy = (NetworkPolicy) tungstenApi.createOrUpdateTungstenNetworkPolicy("policy", projectUuid, tungstenRuleList1); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype", "tagvalue", "123"); - s_logger.debug("Apply tag to network in Tungsten-Fabric"); + logger.debug("Apply tag to network in Tungsten-Fabric"); tungstenApi.applyTungstenNetworkTag(List.of(tungstenNetworkUuid), "005f0dea-0196-11ec-a1ed-b42e99f6e187"); - s_logger.debug("Check if tag was applied to network in Tungsten-Fabric"); + logger.debug("Check if tag was applied to network in Tungsten-Fabric"); VirtualNetwork virtualNetwork = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid); assertEquals(1, virtualNetwork.getTag().size()); - s_logger.debug("Apply tag to vm in Tungsten-Fabric"); + logger.debug("Apply tag to vm in Tungsten-Fabric"); tungstenApi.applyTungstenVmTag(List.of(tungstenVmUuid), "005f0dea-0196-11ec-a1ed-b42e99f6e187"); - s_logger.debug("Check if tag was applied to vm in Tungsten-Fabric"); + logger.debug("Check if tag was applied to vm in Tungsten-Fabric"); VirtualMachine virtualMachine = (VirtualMachine) tungstenApi.getTungstenObject(VirtualMachine.class, tungstenVmUuid); assertEquals(1, virtualMachine.getTag().size()); - s_logger.debug("Apply tag to nic in Tungsten-Fabric"); + logger.debug("Apply tag to nic in Tungsten-Fabric"); tungstenApi.applyTungstenNicTag(List.of(vmiUuid), "005f0dea-0196-11ec-a1ed-b42e99f6e187"); - s_logger.debug("Check if tag was applied to nic in Tungsten-Fabric"); + logger.debug("Check if tag was applied to nic in Tungsten-Fabric"); VirtualMachineInterface virtualMachineInterface = (VirtualMachineInterface) tungstenApi.getTungstenObject( VirtualMachineInterface.class, vmiUuid); assertEquals(1, virtualMachineInterface.getTag().size()); - s_logger.debug("Apply tag to policy in Tungsten-Fabric"); + logger.debug("Apply tag to policy in Tungsten-Fabric"); tungstenApi.applyTungstenPolicyTag(networkPolicy.getUuid(), "005f0dea-0196-11ec-a1ed-b42e99f6e187"); - s_logger.debug("Check if tag was applied to policy in Tungsten-Fabric"); + logger.debug("Check if tag was applied to policy in Tungsten-Fabric"); NetworkPolicy networkPolicy1 = (NetworkPolicy) tungstenApi.getTungstenObject(NetworkPolicy.class, networkPolicy.getUuid()); assertEquals(1, networkPolicy1.getTag().size()); - s_logger.debug("remove tag from network, vm, nic, policy in Tungsten-Fabric"); + logger.debug("remove tag from network, vm, nic, policy in Tungsten-Fabric"); assertNotNull(tungstenApi.removeTungstenTag(List.of(tungstenNetworkUuid), List.of(tungstenVmUuid), List.of(vmiUuid), networkPolicy.getUuid(), null, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Check if tag was removed from network in Tungsten-Fabric"); + logger.debug("Check if tag was removed from network in Tungsten-Fabric"); VirtualNetwork virtualNetwork1 = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid); assertEquals(0, virtualNetwork1.getTag().size()); - s_logger.debug("Check if tag was removed from vm in Tungsten-Fabric"); + logger.debug("Check if tag was removed from vm in Tungsten-Fabric"); VirtualMachine virtualMachine1 = (VirtualMachine) tungstenApi.getTungstenObject(VirtualMachine.class, tungstenVmUuid); assertEquals(0, virtualMachine1.getTag().size()); - s_logger.debug("Check if tag was removed from nic in Tungsten-Fabric"); + logger.debug("Check if tag was removed from nic in Tungsten-Fabric"); VirtualMachineInterface virtualMachineInterface1 = (VirtualMachineInterface) tungstenApi.getTungstenObject( VirtualMachineInterface.class, vmiUuid); assertEquals(0, virtualMachineInterface1.getTag().size()); - s_logger.debug("Check if tag was removed from policy in Tungsten-Fabric"); + logger.debug("Check if tag was removed from policy in Tungsten-Fabric"); NetworkPolicy networkPolicy2 = (NetworkPolicy) tungstenApi.getTungstenObject(NetworkPolicy.class, networkPolicy.getUuid()); assertEquals(0, networkPolicy2.getTag().size()); @@ -1232,29 +1233,29 @@ public void removeTungstenTagTest() { @Test public void removeTungstenPolicyTest() { - s_logger.debug("Create a virtual network in Tungsten-Fabric."); + logger.debug("Create a virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Prepare network policy rule"); + logger.debug("Prepare network policy rule"); List tungstenRuleList = new ArrayList<>(); - s_logger.debug("Create a network policy in Tungsten-Fabric."); + logger.debug("Create a network policy in Tungsten-Fabric."); NetworkPolicy networkPolicy = (NetworkPolicy) tungstenApi.createOrUpdateTungstenNetworkPolicy("policy", projectUuid, tungstenRuleList); - s_logger.debug("Apply network policy to network in Tungsten-Fabric."); + logger.debug("Apply network policy to network in Tungsten-Fabric."); tungstenApi.applyTungstenNetworkPolicy(networkPolicy.getUuid(), tungstenNetworkUuid, 1, 1); - s_logger.debug("Check if network policy was applied in Tungsten-Fabric."); + logger.debug("Check if network policy was applied in Tungsten-Fabric."); VirtualNetwork virtualNetwork = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid); assertEquals(1, virtualNetwork.getNetworkPolicy().size()); - s_logger.debug("Apply network policy to network in Tungsten-Fabric."); + logger.debug("Apply network policy to network in Tungsten-Fabric."); tungstenApi.removeTungstenPolicy(tungstenNetworkUuid, networkPolicy.getUuid()); - s_logger.debug("Check if network policy was applied in Tungsten-Fabric."); + logger.debug("Check if network policy was applied in Tungsten-Fabric."); VirtualNetwork virtualNetwork1 = (VirtualNetwork) tungstenApi.getTungstenObject(VirtualNetwork.class, tungstenNetworkUuid); assertEquals(0, virtualNetwork1.getNetworkPolicy().size()); @@ -1262,26 +1263,26 @@ public void removeTungstenPolicyTest() { @Test public void createTungstenPolicyTest() { - s_logger.debug("Check if policy is not exist in Tungsten-Fabric"); + logger.debug("Check if policy is not exist in Tungsten-Fabric"); assertNull(tungstenApi.getTungstenObject(NetworkPolicy.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Create policy in Tungsten-Fabric"); + logger.debug("Create policy in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenPolicy("005f0dea-0196-11ec-a1ed-b42e99f6e187", "policy", projectUuid)); - s_logger.debug("Check if policy was created in Tungsten-Fabric"); + logger.debug("Check if policy was created in Tungsten-Fabric"); assertNotNull(tungstenApi.getTungstenObject(NetworkPolicy.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); } @Test public void addTungstenPolicyRuleTest() { - s_logger.debug("Create policy in Tungsten-Fabric"); + logger.debug("Create policy in Tungsten-Fabric"); NetworkPolicy networkPolicy = (NetworkPolicy) tungstenApi.createTungstenPolicy( "005f0dea-0196-11ec-a1ed-b42e99f6e187", "policy", projectUuid); - s_logger.debug("Check if policy was created in Tungsten-Fabric"); + logger.debug("Check if policy was created in Tungsten-Fabric"); assertNull(networkPolicy.getEntries()); - s_logger.debug("Check if policy rule was added in Tungsten-Fabric"); + logger.debug("Check if policy rule was added in Tungsten-Fabric"); assertNotNull(tungstenApi.addTungstenPolicyRule("c1680d93-2614-4f99-a8c5-d4f11b3dfc9d", "005f0dea-0196-11ec-a1ed-b42e99f6e187", "pass", "tcp", ">", "network1", "192.168.100.0", 24, 8080, 8081, "network2", "10.0.0.0", 16, 80, 81)); @@ -1338,18 +1339,18 @@ public void addTungstenPolicyRuleTest() { @Test public void listTungstenAddressPolicyTest() { - s_logger.debug("Create policy in Tungsten-Fabric"); + logger.debug("Create policy in Tungsten-Fabric"); ApiObjectBase networkPolicy1 = tungstenApi.createTungstenPolicy("005f0dea-0196-11ec-a1ed-b42e99f6e187", "policy1", projectUuid); - s_logger.debug("Check if network policy was listed in Tungsten-Fabric"); + logger.debug("Check if network policy was listed in Tungsten-Fabric"); List networkPolicyList = tungstenApi.listTungstenAddressPolicy(projectUuid, "policy1"); assertEquals(List.of(networkPolicy1), networkPolicyList); } @Test public void listTungstenPolicyTest() { - s_logger.debug("Create policy in Tungsten-Fabric"); + logger.debug("Create policy in Tungsten-Fabric"); ApiObjectBase apiObjectBase1 = tungstenApi.createTungstenPolicy("005f0dea-0196-11ec-a1ed-b42e99f6e187", "policy1", projectUuid); ApiObjectBase apiObjectBase2 = tungstenApi.createTungstenPolicy("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", @@ -1358,12 +1359,12 @@ public void listTungstenPolicyTest() { policyList1.sort(comparator); List policyList2 = List.of(apiObjectBase1); - s_logger.debug("Check if policy was listed all in Tungsten-Fabric"); + logger.debug("Check if policy was listed all in Tungsten-Fabric"); List policyList3 = tungstenApi.listTungstenPolicy(projectUuid, null); policyList3.sort(comparator); assertEquals(policyList1, policyList3); - s_logger.debug("Check if policy was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if policy was listed with uuid in Tungsten-Fabric"); List policyList4 = tungstenApi.listTungstenPolicy(projectUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(policyList2, policyList4); @@ -1371,7 +1372,7 @@ public void listTungstenPolicyTest() { @Test public void listTungstenNetworkTest() { - s_logger.debug("Create network in Tungsten-Fabric"); + logger.debug("Create network in Tungsten-Fabric"); VirtualNetwork virtualNetwork1 = tungstenApi.createTungstenNetwork("005f0dea-0196-11ec-a1ed-b42e99f6e187", "network1", "network1", projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); @@ -1382,12 +1383,12 @@ public void listTungstenNetworkTest() { networkList1.sort(comparator); List networkList2 = List.of(virtualNetwork1); - s_logger.debug("Check if network was listed all in Tungsten-Fabric"); + logger.debug("Check if network was listed all in Tungsten-Fabric"); List networkList3 = tungstenApi.listTungstenNetwork(projectUuid, null); networkList3.sort(comparator); assertEquals(networkList1, networkList3); - s_logger.debug("Check if network policy was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if network policy was listed with uuid in Tungsten-Fabric"); List networkList4 = tungstenApi.listTungstenNetwork(projectUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(networkList2, networkList4); @@ -1395,19 +1396,19 @@ public void listTungstenNetworkTest() { @Test public void listTungstenVmTest() { - s_logger.debug("Create vm in Tungsten-Fabric"); + logger.debug("Create vm in Tungsten-Fabric"); VirtualMachine vm1 = tungstenApi.createTungstenVirtualMachine("005f0dea-0196-11ec-a1ed-b42e99f6e187", "vm1"); VirtualMachine vm2 = tungstenApi.createTungstenVirtualMachine("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "vm2"); List vmList1 = Arrays.asList(vm1, vm2); vmList1.sort(comparator); List vmList2 = List.of(vm1); - s_logger.debug("Check if vm was listed all in Tungsten-Fabric"); + logger.debug("Check if vm was listed all in Tungsten-Fabric"); List vmList3 = tungstenApi.listTungstenVm(projectUuid, null); vmList3.sort(comparator); assertEquals(vmList1, vmList3); - s_logger.debug("Check if policy was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if policy was listed with uuid in Tungsten-Fabric"); List vmList4 = tungstenApi.listTungstenVm(projectUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(vmList2, vmList4); @@ -1415,17 +1416,17 @@ public void listTungstenVmTest() { @Test public void listTungstenNicTest() { - s_logger.debug("Create network in Tungsten-Fabric"); + logger.debug("Create network in Tungsten-Fabric"); tungstenApi.createTungstenNetwork("005f0dea-0196-11ec-a1ed-b42e99f6e187", "network1", "network1", projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); tungstenApi.createTungstenNetwork("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "network2", "network2", projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create vm in Tungsten-Fabric"); + logger.debug("Create vm in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine("7d5575eb-d029-467e-8b78-6056a8c94a71", "vm1"); tungstenApi.createTungstenVirtualMachine("88729834-3ebd-413a-adf9-40aff73cf638", "vm2"); - s_logger.debug("Creating vmi in Tungsten-Fabric."); + logger.debug("Creating vmi in Tungsten-Fabric."); VirtualMachineInterface vmi1 = tungstenApi.createTungstenVmInterface("9291ae28-56cf-448c-b848-f2334b3c86da", "vmi1", "02:fc:f3:d6:83:c3", "005f0dea-0196-11ec-a1ed-b42e99f6e187", "7d5575eb-d029-467e-8b78-6056a8c94a71", projectUuid, "10.0.0.1", true); @@ -1436,12 +1437,12 @@ public void listTungstenNicTest() { vmiList1.sort(comparator); List vmiList2 = List.of(vmi1); - s_logger.debug("Check if vmi was listed all in Tungsten-Fabric"); + logger.debug("Check if vmi was listed all in Tungsten-Fabric"); List vmiList3 = tungstenApi.listTungstenNic(projectUuid, null); vmiList3.sort(comparator); assertEquals(vmiList1, vmiList3); - s_logger.debug("Check if vmi was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if vmi was listed with uuid in Tungsten-Fabric"); List vmList4 = tungstenApi.listTungstenNic(projectUuid, "9291ae28-56cf-448c-b848-f2334b3c86da"); assertEquals(vmiList2, vmList4); @@ -1449,7 +1450,7 @@ public void listTungstenNicTest() { @Test public void listTungstenTagTest() { - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); ApiObjectBase apiObjectBase1 = tungstenApi.createTungstenTag("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype1", "tagvalue1", "123"); ApiObjectBase apiObjectBase2 = tungstenApi.createTungstenTag("6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "tagtype2", @@ -1479,7 +1480,7 @@ public void listTungstenTagTest() { listTag4.sort(comparator); listTag5.sort(comparator); - s_logger.debug("Create network and apply tag in Tungsten-Fabric"); + logger.debug("Create network and apply tag in Tungsten-Fabric"); tungstenApi.createTungstenNetwork("9291ae28-56cf-448c-b848-f2334b3c86da", "network1", "network1", projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); tungstenApi.applyTungstenNetworkTag(List.of("9291ae28-56cf-448c-b848-f2334b3c86da"), @@ -1487,14 +1488,14 @@ public void listTungstenTagTest() { tungstenApi.applyTungstenNetworkTag(List.of("9291ae28-56cf-448c-b848-f2334b3c86da"), "6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe"); - s_logger.debug("Create vm and apply tag in Tungsten-Fabric"); + logger.debug("Create vm and apply tag in Tungsten-Fabric"); tungstenApi.createTungstenVirtualMachine("124d0792-e890-4b7e-8fe8-1b7a6d63c66a", "vm1"); tungstenApi.applyTungstenVmTag(List.of("124d0792-e890-4b7e-8fe8-1b7a6d63c66a"), "7d5575eb-d029-467e-8b78-6056a8c94a71"); tungstenApi.applyTungstenVmTag(List.of("124d0792-e890-4b7e-8fe8-1b7a6d63c66a"), "88729834-3ebd-413a-adf9-40aff73cf638"); - s_logger.debug("Creating vmi and apply tag in Tungsten-Fabric."); + logger.debug("Creating vmi and apply tag in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface("c1680d93-2614-4f99-a8c5-d4f11b3dfc9d", "vmi1", "02:fc:f3:d6:83:c3", "9291ae28-56cf-448c-b848-f2334b3c86da", "124d0792-e890-4b7e-8fe8-1b7a6d63c66a", projectUuid, "10.0.0.1", true); tungstenApi.applyTungstenNicTag(List.of("c1680d93-2614-4f99-a8c5-d4f11b3dfc9d"), @@ -1502,45 +1503,45 @@ public void listTungstenTagTest() { tungstenApi.applyTungstenNicTag(List.of("c1680d93-2614-4f99-a8c5-d4f11b3dfc9d"), "7b062909-ba9d-4cf3-bbd3-7db93cf6b4fe"); - s_logger.debug("Creating policy and apply tag in Tungsten-Fabric."); + logger.debug("Creating policy and apply tag in Tungsten-Fabric."); tungstenApi.createTungstenPolicy("205f0dea-0196-11ec-a1ed-b42e99f6e187", "policy", projectUuid); tungstenApi.applyTungstenPolicyTag("205f0dea-0196-11ec-a1ed-b42e99f6e187", "8d5575eb-d029-467e-8b78-6056a8c94a71"); tungstenApi.applyTungstenPolicyTag("205f0dea-0196-11ec-a1ed-b42e99f6e187", "98729834-3ebd-413a-adf9-40aff73cf638"); - s_logger.debug("Check if tag was listed with network in Tungsten-Fabric"); + logger.debug("Check if tag was listed with network in Tungsten-Fabric"); List listTag6 = tungstenApi.listTungstenTag("9291ae28-56cf-448c-b848-f2334b3c86da", null, null, null, null, null); listTag6.sort(comparator); assertEquals(listTag1, listTag6); - s_logger.debug("Check if tag was listed with vm in Tungsten-Fabric"); + logger.debug("Check if tag was listed with vm in Tungsten-Fabric"); List listTag7 = tungstenApi.listTungstenTag(null, "124d0792-e890-4b7e-8fe8-1b7a6d63c66a", null, null, null , null); listTag7.sort(comparator); assertEquals(listTag2, listTag7); - s_logger.debug("Check if tag was listed with nic in Tungsten-Fabric"); + logger.debug("Check if tag was listed with nic in Tungsten-Fabric"); List listTag8 = tungstenApi.listTungstenTag(null, null, "c1680d93-2614-4f99-a8c5-d4f11b3dfc9d", null, null, null); listTag8.sort(comparator); assertEquals(listTag3, listTag8); - s_logger.debug("Check if tag was listed with policy in Tungsten-Fabric"); + logger.debug("Check if tag was listed with policy in Tungsten-Fabric"); List listTag9 = tungstenApi.listTungstenTag(null, null, null, "205f0dea-0196-11ec-a1ed-b42e99f6e187", null, null); listTag9.sort(comparator); assertEquals(listTag4, listTag9); - s_logger.debug("Check if tag was listed all in Tungsten-Fabric"); + logger.debug("Check if tag was listed all in Tungsten-Fabric"); List listTag10 = tungstenApi.listTungstenTag(null, null, null, null, null, null); listTag10.sort(comparator); assertEquals(listTag5, listTag10); - s_logger.debug("Check if tag was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if tag was listed with uuid in Tungsten-Fabric"); List listTag11 = tungstenApi.listTungstenTag(null, null, null, null, null, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); listTag11.sort(comparator); @@ -1549,19 +1550,19 @@ public void listTungstenTagTest() { @Test public void listTungstenTagTypeTest() { - s_logger.debug("Create tag type in Tungsten-Fabric"); + logger.debug("Create tag type in Tungsten-Fabric"); ApiObjectBase tagType1 = tungstenApi.createTungstenTagType("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype1"); ApiObjectBase tagType2 = tungstenApi.createTungstenTagType("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "tagtype2"); List tagTypeList1 = Arrays.asList(tagType1, tagType2); tagTypeList1.sort(comparator); List tagTypeList2 = List.of(tagType1); - s_logger.debug("Check if tag type was listed all in Tungsten-Fabric"); + logger.debug("Check if tag type was listed all in Tungsten-Fabric"); List tagTypeList3 = tungstenApi.listTungstenTagType(null); tagTypeList3.sort(comparator); assertEquals(tagTypeList1, tagTypeList3); - s_logger.debug("Check if tag type was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if tag type was listed with uuid in Tungsten-Fabric"); List tagTypeList4 = tungstenApi.listTungstenTagType( "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(tagTypeList2, tagTypeList4); @@ -1569,11 +1570,11 @@ public void listTungstenTagTypeTest() { @Test public void listTungstenNetworkPolicyTest() { - s_logger.debug("Create network in Tungsten-Fabric"); + logger.debug("Create network in Tungsten-Fabric"); tungstenApi.createTungstenNetwork("005f0dea-0196-11ec-a1ed-b42e99f6e187", "network1", "network1", projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create policy in Tungsten-Fabric"); + logger.debug("Create policy in Tungsten-Fabric"); ApiObjectBase apiObjectBase1 = tungstenApi.createTungstenPolicy("6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "policy1", projectUuid); ApiObjectBase apiObjectBase2 = tungstenApi.createTungstenPolicy("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", @@ -1582,18 +1583,18 @@ public void listTungstenNetworkPolicyTest() { List policyList2 = List.of(apiObjectBase1); policyList1.sort(comparator); - s_logger.debug("Apply network policy to network in Tungsten-Fabric."); + logger.debug("Apply network policy to network in Tungsten-Fabric."); tungstenApi.applyTungstenNetworkPolicy("6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "005f0dea-0196-11ec-a1ed-b42e99f6e187", 1, 1); tungstenApi.applyTungstenNetworkPolicy("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "005f0dea-0196-11ec-a1ed-b42e99f6e187", 1, 2); - s_logger.debug("Check if network policy was listed all in Tungsten-Fabric"); + logger.debug("Check if network policy was listed all in Tungsten-Fabric"); List policyList3 = tungstenApi.listTungstenNetworkPolicy( "005f0dea-0196-11ec-a1ed-b42e99f6e187", null); assertEquals(policyList1, policyList3); - s_logger.debug("Check if network policy was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if network policy was listed with uuid in Tungsten-Fabric"); List policyList4 = tungstenApi.listTungstenNetworkPolicy( "005f0dea-0196-11ec-a1ed-b42e99f6e187", "6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe"); assertEquals(policyList2, policyList4); @@ -1601,7 +1602,7 @@ public void listTungstenNetworkPolicyTest() { @Test public void listTungstenApplicationPolicySetTest() { - s_logger.debug("Create application policy set in Tungsten-Fabric"); + logger.debug("Create application policy set in Tungsten-Fabric"); ApiObjectBase applicationPolicySet1 = tungstenApi.createTungstenApplicationPolicySet( "005f0dea-0196-11ec-a1ed-b42e99f6e187", "aps1"); ApiObjectBase applicationPolicySet2 = tungstenApi.createTungstenApplicationPolicySet( @@ -1610,12 +1611,12 @@ public void listTungstenApplicationPolicySetTest() { apsList1.sort(comparator); List apsList2 = List.of(applicationPolicySet1); - s_logger.debug("Check if application policy set was listed all in Tungsten-Fabric"); + logger.debug("Check if application policy set was listed all in Tungsten-Fabric"); List apsList3 = tungstenApi.listTungstenApplicationPolicySet(null); apsList3.sort(comparator); assertEquals(apsList1, apsList3); - s_logger.debug("Check if application policy set was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if application policy set was listed with uuid in Tungsten-Fabric"); List apsList4 = tungstenApi.listTungstenApplicationPolicySet( "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(apsList2, apsList4); @@ -1623,13 +1624,13 @@ public void listTungstenApplicationPolicySetTest() { @Test public void listTungstenFirewallPolicyTest() { - s_logger.debug("Create application policy set in Tungsten-Fabric"); + logger.debug("Create application policy set in Tungsten-Fabric"); tungstenApi.createTungstenApplicationPolicySet("f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "aps1"); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("7d5575eb-d029-467e-8b78-6056a8c94a71", "tagtype1", "tagvalue1", "123"); - s_logger.debug("Create firewall policy in Tungsten-Fabric"); + logger.debug("Create firewall policy in Tungsten-Fabric"); ApiObjectBase fwPolicy1 = tungstenApi.createTungstenFirewallPolicy("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "firewallpolicy1", 1); ApiObjectBase fwPolicy2 = tungstenApi.createTungstenFirewallPolicy("6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", @@ -1638,13 +1639,13 @@ public void listTungstenFirewallPolicyTest() { fwPolicyList1.sort(comparator); List fwPolicyList2 = List.of(fwPolicy1); - s_logger.debug("Check if firewall policy set was listed all with application policy set in Tungsten-Fabric"); + logger.debug("Check if firewall policy set was listed all with application policy set in Tungsten-Fabric"); List fwPolicyList3 = tungstenApi.listTungstenFirewallPolicy( "f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", null); fwPolicyList3.sort(comparator); assertEquals(fwPolicyList1, fwPolicyList3); - s_logger.debug( + logger.debug( "Check if firewall policy set was listed with uuid and application policy set in Tungsten-Fabric"); List fwPolicyList4 = tungstenApi.listTungstenFirewallPolicy( "f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "baf714fa-80a1-454f-9c32-c4d4a6f5c5a4"); @@ -1653,32 +1654,32 @@ public void listTungstenFirewallPolicyTest() { @Test public void listTungstenFirewallRuleTest() { - s_logger.debug("Create application policy set in Tungsten-Fabric"); + logger.debug("Create application policy set in Tungsten-Fabric"); tungstenApi.createTungstenApplicationPolicySet("f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "aps"); - s_logger.debug("Create firewall policy in Tungsten-Fabric"); + logger.debug("Create firewall policy in Tungsten-Fabric"); tungstenApi.createTungstenFirewallPolicy("005f0dea-0196-11ec-a1ed-b42e99f6e187", "f5ba12c8-d4c5-4c20-a57d-67a9b6fca652", "firewallpolicy", 1); - s_logger.debug("Create service group in Tungsten-Fabric"); + logger.debug("Create service group in Tungsten-Fabric"); tungstenApi.createTungstenServiceGroup("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "servicegroup1", "tcp", 80, 90); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "tagtype1", "tagvalue1", "123"); - s_logger.debug("Create tag in Tungsten-Fabric"); + logger.debug("Create tag in Tungsten-Fabric"); tungstenApi.createTungstenTag("7d5575eb-d029-467e-8b78-6056a8c94a71", "tagtype2", "tagvalue2", "123"); - s_logger.debug("Create address group in Tungsten-Fabric"); + logger.debug("Create address group in Tungsten-Fabric"); tungstenApi.createTungstenAddressGroup("88729834-3ebd-413a-adf9-40aff73cf638", "addressgroup1", "10.0.0.0", 24); - s_logger.debug("Create address group in Tungsten-Fabric"); + logger.debug("Create address group in Tungsten-Fabric"); tungstenApi.createTungstenAddressGroup("9291ae28-56cf-448c-b848-f2334b3c86da", "addressgroup2", "10.0.0.0", 24); - s_logger.debug("Create tag type in Tungsten-Fabric"); + logger.debug("Create tag type in Tungsten-Fabric"); tungstenApi.createTungstenTagType("c1680d93-2614-4f99-a8c5-d4f11b3dfc9d", "tagtype1"); - s_logger.debug("Create firewall rule in Tungsten-Fabric"); + logger.debug("Create firewall rule in Tungsten-Fabric"); ApiObjectBase firewallRule1 = tungstenApi.createTungstenFirewallRule("124d0792-e890-4b7e-8fe8-1b7a6d63c66a", "005f0dea-0196-11ec-a1ed-b42e99f6e187", "firewallrule1", "pass", "baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "88729834-3ebd-413a-adf9-40aff73cf638", null, ">", @@ -1694,13 +1695,13 @@ public void listTungstenFirewallRuleTest() { fwRuleList1.sort(comparator); List fwRuleList2 = List.of(firewallRule1); - s_logger.debug("Check if firewall rule set was listed all with firewall policy in Tungsten-Fabric"); + logger.debug("Check if firewall rule set was listed all with firewall policy in Tungsten-Fabric"); List fwRuleList3 = tungstenApi.listTungstenFirewallRule( "005f0dea-0196-11ec-a1ed-b42e99f6e187", null); fwRuleList3.sort(comparator); assertEquals(fwRuleList1, fwRuleList3); - s_logger.debug("Check if firewall rule set was listed with uuid and firewall policy in Tungsten-Fabric"); + logger.debug("Check if firewall rule set was listed with uuid and firewall policy in Tungsten-Fabric"); List fwRuleList4 = tungstenApi.listTungstenFirewallRule( "005f0dea-0196-11ec-a1ed-b42e99f6e187", "124d0792-e890-4b7e-8fe8-1b7a6d63c66a"); assertEquals(fwRuleList2, fwRuleList4); @@ -1708,7 +1709,7 @@ public void listTungstenFirewallRuleTest() { @Test public void listTungstenServiceGroupTest() { - s_logger.debug("Create service group in Tungsten-Fabric"); + logger.debug("Create service group in Tungsten-Fabric"); ApiObjectBase serviceGroup1 = tungstenApi.createTungstenServiceGroup("005f0dea-0196-11ec-a1ed-b42e99f6e187", "serviceGroup1", "tcp", 80, 80); ApiObjectBase serviceGroup2 = tungstenApi.createTungstenServiceGroup("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", @@ -1717,12 +1718,12 @@ public void listTungstenServiceGroupTest() { serviceGroupList1.sort(comparator); List serviceGroupList2 = List.of(serviceGroup1); - s_logger.debug("Check if service group was listed all in Tungsten-Fabric"); + logger.debug("Check if service group was listed all in Tungsten-Fabric"); List serviceGroupList3 = tungstenApi.listTungstenServiceGroup(null); serviceGroupList3.sort(comparator); assertEquals(serviceGroupList1, serviceGroupList3); - s_logger.debug("Check if tag type was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if tag type was listed with uuid in Tungsten-Fabric"); List serviceGroupList4 = tungstenApi.listTungstenServiceGroup( "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(serviceGroupList2, serviceGroupList4); @@ -1730,7 +1731,7 @@ public void listTungstenServiceGroupTest() { @Test public void listTungstenAddressGroupTest() { - s_logger.debug("Create address group in Tungsten-Fabric"); + logger.debug("Create address group in Tungsten-Fabric"); ApiObjectBase addressGroup1 = tungstenApi.createTungstenAddressGroup("005f0dea-0196-11ec-a1ed-b42e99f6e187", "addressGroup1", "10.0.0.0", 24); ApiObjectBase addressGroup2 = tungstenApi.createTungstenAddressGroup("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", @@ -1739,12 +1740,12 @@ public void listTungstenAddressGroupTest() { addressGroupList1.sort(comparator); List addressGroupList2 = List.of(addressGroup1); - s_logger.debug("Check if service group was listed all in Tungsten-Fabric"); + logger.debug("Check if service group was listed all in Tungsten-Fabric"); List addressGroupList3 = tungstenApi.listTungstenAddressGroup(null); addressGroupList3.sort(comparator); assertEquals(addressGroupList1, addressGroupList3); - s_logger.debug("Check if service group was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if service group was listed with uuid in Tungsten-Fabric"); List addressGroupList4 = tungstenApi.listTungstenAddressGroup( "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(addressGroupList2, addressGroupList4); @@ -1752,20 +1753,20 @@ public void listTungstenAddressGroupTest() { @Test public void removeTungstenNetworkPolicyRuleTest() { - s_logger.debug("Create policy in Tungsten-Fabric"); + logger.debug("Create policy in Tungsten-Fabric"); tungstenApi.createTungstenPolicy("005f0dea-0196-11ec-a1ed-b42e99f6e187", "policy", projectUuid); - s_logger.debug("Add policy rule in Tungsten-Fabric"); + logger.debug("Add policy rule in Tungsten-Fabric"); tungstenApi.addTungstenPolicyRule("c1680d93-2614-4f99-a8c5-d4f11b3dfc9d", "005f0dea-0196-11ec-a1ed-b42e99f6e187", "pass", "tcp", ">", "network1", "192.168.100.0", 24, 8080, 8081, "network2", "10.0.0.0", 16, 80, 81); - s_logger.debug("Check if policy rule was add to network policy in Tungsten-Fabric"); + logger.debug("Check if policy rule was add to network policy in Tungsten-Fabric"); NetworkPolicy networkPolicy1 = (NetworkPolicy) tungstenApi.getTungstenObject(NetworkPolicy.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(1, networkPolicy1.getEntries().getPolicyRule().size()); - s_logger.debug("Check if policy rule was remove from network policy in Tungsten-Fabric"); + logger.debug("Check if policy rule was remove from network policy in Tungsten-Fabric"); assertNotNull(tungstenApi.removeTungstenNetworkPolicyRule("005f0dea-0196-11ec-a1ed-b42e99f6e187", "c1680d93-2614-4f99-a8c5-d4f11b3dfc9d")); NetworkPolicy networkPolicy2 = (NetworkPolicy) tungstenApi.getTungstenObject(NetworkPolicy.class, @@ -1781,10 +1782,10 @@ public void updateTungstenVrouterConfig() { @Test public void deleteTungstenObjectTest() { - s_logger.debug("Create tag type in Tungsten-Fabric"); + logger.debug("Create tag type in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenTagType("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype")); - s_logger.debug("Check if tag type was deleted in Tungsten-Fabric"); + logger.debug("Check if tag type was deleted in Tungsten-Fabric"); ApiObjectBase apiObjectBase = tungstenApi.getTungstenObject(TagType.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertTrue(tungstenApi.deleteTungstenObject(apiObjectBase)); @@ -1793,17 +1794,17 @@ public void deleteTungstenObjectTest() { @Test public void deleteTungstenObjectWithUuidTest() { - s_logger.debug("Create tag type in Tungsten-Fabric"); + logger.debug("Create tag type in Tungsten-Fabric"); assertNotNull(tungstenApi.createTungstenTagType("005f0dea-0196-11ec-a1ed-b42e99f6e187", "tagtype")); - s_logger.debug("Check if tag type was deleted in Tungsten-Fabric"); + logger.debug("Check if tag type was deleted in Tungsten-Fabric"); assertTrue(tungstenApi.deleteTungstenObject(TagType.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); assertNull(tungstenApi.getTungstenObject(TagType.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); } @Test public void getTungstenListObjectTest() { - s_logger.debug("Create network in Tungsten-Fabric"); + logger.debug("Create network in Tungsten-Fabric"); VirtualNetwork network1 = tungstenApi.createTungstenNetwork("005f0dea-0196-11ec-a1ed-b42e99f6e187", "network1", "network1", projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); @@ -1814,12 +1815,12 @@ public void getTungstenListObjectTest() { list1.sort(comparator); List list2 = List.of(network1); - s_logger.debug("Check if network was listed all in Tungsten-Fabric"); + logger.debug("Check if network was listed all in Tungsten-Fabric"); List list3 = tungstenApi.getTungstenListObject(VirtualNetwork.class, project, null); list3.sort(comparator); assertEquals(list1, list3); - s_logger.debug("Check if network was listed with uuid in Tungsten-Fabric"); + logger.debug("Check if network was listed with uuid in Tungsten-Fabric"); List list4 = tungstenApi.getTungstenListObject(VirtualNetwork.class, null, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(list2, list4); @@ -1829,33 +1830,33 @@ public void getTungstenListObjectTest() { public void addInstanceToSecurityGroupTest() { String projectFqn = TungstenApi.TUNGSTEN_DEFAULT_DOMAIN + ":" + TungstenApi.TUNGSTEN_DEFAULT_PROJECT; - s_logger.debug("Create a security group in Tungsten-Fabric."); + logger.debug("Create a security group in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenSecurityGroup(tungstenSecurityGroupUuid, tungstenSecurityGroupName, "TungstenSecurityGroupDescription", projectFqn)); - s_logger.debug("Create virtual network in Tungsten-Fabric."); + logger.debug("Create virtual network in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, "")); - s_logger.debug("Create virtual machine in Tungsten-Fabric."); + logger.debug("Create virtual machine in Tungsten-Fabric."); assertNotNull(tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName)); - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); assertNotNull( tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true)); - s_logger.debug("Check if instance have no security group in Tungsten-Fabric."); + logger.debug("Check if instance have no security group in Tungsten-Fabric."); VirtualMachineInterface virtualMachineInterface1 = (VirtualMachineInterface) tungstenApi.getTungstenObject( VirtualMachineInterface.class, vmiUuid); assertNull(virtualMachineInterface1.getSecurityGroup()); assertFalse(virtualMachineInterface1.getPortSecurityEnabled()); - s_logger.debug("Add instance to security group in Tungsten-Fabric."); + logger.debug("Add instance to security group in Tungsten-Fabric."); tungstenApi.addInstanceToSecurityGroup(vmiUuid, List.of(tungstenSecurityGroupUuid)); - s_logger.debug("Check if instance was added to security group in Tungsten-Fabric."); + logger.debug("Check if instance was added to security group in Tungsten-Fabric."); VirtualMachineInterface virtualMachineInterface2 = (VirtualMachineInterface) tungstenApi.getTungstenObject( VirtualMachineInterface.class, vmiUuid); assertEquals(1, virtualMachineInterface2.getSecurityGroup().size()); @@ -1867,33 +1868,33 @@ public void addInstanceToSecurityGroupTest() { public void removeInstanceFromSecurityGroupTest() { String projectFqn = TungstenApi.TUNGSTEN_DEFAULT_DOMAIN + ":" + TungstenApi.TUNGSTEN_DEFAULT_PROJECT; - s_logger.debug("Create a security group in Tungsten-Fabric."); + logger.debug("Create a security group in Tungsten-Fabric."); tungstenApi.createTungstenSecurityGroup(tungstenSecurityGroupUuid, tungstenSecurityGroupName, "TungstenSecurityGroupDescription", projectFqn); - s_logger.debug("Create virtual network in Tungsten-Fabric."); + logger.debug("Create virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create virtual machine in Tungsten-Fabric."); + logger.debug("Create virtual machine in Tungsten-Fabric."); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Add instance to security group in Tungsten-Fabric."); + logger.debug("Add instance to security group in Tungsten-Fabric."); tungstenApi.addInstanceToSecurityGroup(vmiUuid, List.of(tungstenSecurityGroupUuid)); - s_logger.debug("Check if instance was added to security group in Tungsten-Fabric."); + logger.debug("Check if instance was added to security group in Tungsten-Fabric."); VirtualMachineInterface virtualMachineInterface1 = (VirtualMachineInterface) tungstenApi.getTungstenObject( VirtualMachineInterface.class, vmiUuid); assertEquals(1, virtualMachineInterface1.getSecurityGroup().size()); - s_logger.debug("Remove instance from security group in Tungsten-Fabric."); + logger.debug("Remove instance from security group in Tungsten-Fabric."); assertTrue(tungstenApi.removeInstanceFromSecurityGroup(vmiUuid, List.of(tungstenSecurityGroupUuid))); - s_logger.debug("Check if instance was removed from security group in Tungsten-Fabric."); + logger.debug("Check if instance was removed from security group in Tungsten-Fabric."); VirtualMachineInterface virtualMachineInterface2 = (VirtualMachineInterface) tungstenApi.getTungstenObject( VirtualMachineInterface.class, vmiUuid); assertEquals(0, virtualMachineInterface2.getSecurityGroup().size()); @@ -1902,21 +1903,21 @@ public void removeInstanceFromSecurityGroupTest() { @Test public void addSecondaryIpAddressTest() { - s_logger.debug("Create virtual network in Tungsten-Fabric."); + logger.debug("Create virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create virtual machine in Tungsten-Fabric."); + logger.debug("Create virtual machine in Tungsten-Fabric."); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if secondary ip address was not exist in Tungsten-Fabric."); + logger.debug("Check if secondary ip address was not exist in Tungsten-Fabric."); assertNull(tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "secondaryip")); - s_logger.debug("Check if secondary ip address was added to nic in Tungsten-Fabric."); + logger.debug("Check if secondary ip address was added to nic in Tungsten-Fabric."); assertTrue(tungstenApi.addSecondaryIpAddress(tungstenNetworkUuid, vmiUuid, "secondaryip1", "10.0.0.100")); InstanceIp instanceIp2 = (InstanceIp) tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "secondaryip1"); @@ -1925,7 +1926,7 @@ public void addSecondaryIpAddressTest() { assertEquals(vmiUuid, instanceIp2.getVirtualMachineInterface().get(0).getUuid()); assertTrue(instanceIp2.getSecondary()); - s_logger.debug("Check if secondary ip address with ip v6 was added to nic in Tungsten-Fabric."); + logger.debug("Check if secondary ip address with ip v6 was added to nic in Tungsten-Fabric."); assertTrue(tungstenApi.addSecondaryIpAddress(tungstenNetworkUuid, vmiUuid, "secondaryip2", "fd00::100")); InstanceIp instanceIp3 = (InstanceIp) tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "secondaryip2"); @@ -1935,32 +1936,32 @@ public void addSecondaryIpAddressTest() { @Test public void removeSecondaryIpAddressTest() { - s_logger.debug("Create virtual network in Tungsten-Fabric."); + logger.debug("Create virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create virtual machine in Tungsten-Fabric."); + logger.debug("Create virtual machine in Tungsten-Fabric."); tungstenApi.createTungstenVirtualMachine(tungstenVmUuid, tungstenVmName); - s_logger.debug("Create virtual machine interface in Tungsten-Fabric."); + logger.debug("Create virtual machine interface in Tungsten-Fabric."); tungstenApi.createTungstenVmInterface(vmiUuid, vmiName, "02:fc:f3:d6:83:c3", tungstenNetworkUuid, tungstenVmUuid, projectUuid, "10.0.0.1", true); - s_logger.debug("Check if secondary ip address was added to nic in Tungsten-Fabric."); + logger.debug("Check if secondary ip address was added to nic in Tungsten-Fabric."); assertTrue(tungstenApi.addSecondaryIpAddress(tungstenNetworkUuid, vmiUuid, "secondaryip", "10.0.0.100")); assertNotNull(tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "secondaryip")); - s_logger.debug("Check if secondary ip address was removed from nic in Tungsten-Fabric."); + logger.debug("Check if secondary ip address was removed from nic in Tungsten-Fabric."); assertTrue(tungstenApi.removeSecondaryIpAddress("secondaryip")); assertNull(tungstenApi.getTungstenObjectByName(InstanceIp.class, null, "secondaryip")); } @Test public void createRoutingLogicalRouterTest() { - s_logger.debug("Check if logical router was not exist in Tungsten-Fabric."); + logger.debug("Check if logical router was not exist in Tungsten-Fabric."); assertNull(tungstenApi.getTungstenObject(LogicalRouter.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); - s_logger.debug("Check if logical router was created in Tungsten-Fabric."); + logger.debug("Check if logical router was created in Tungsten-Fabric."); assertNotNull(tungstenApi.createRoutingLogicalRouter(projectUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187", "TungstenLogicalRouter")); assertNotNull(tungstenApi.getTungstenObject(LogicalRouter.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); @@ -1968,7 +1969,7 @@ public void createRoutingLogicalRouterTest() { @Test public void listRoutingLogicalRouterTest() { - s_logger.debug("Create logical router in Tungsten-Fabric."); + logger.debug("Create logical router in Tungsten-Fabric."); ApiObjectBase apiObjectBase1 = tungstenApi.createRoutingLogicalRouter(projectUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187", "logicalRouter1"); ApiObjectBase apiObjectBase2 = tungstenApi.createRoutingLogicalRouter(projectUuid, @@ -1977,7 +1978,7 @@ public void listRoutingLogicalRouterTest() { list1.sort(comparator); List list2 = List.of(apiObjectBase1); - s_logger.debug("Check if logical router was listed all in Tungsten-Fabric."); + logger.debug("Check if logical router was listed all in Tungsten-Fabric."); List list3 = tungstenApi.listRoutingLogicalRouter(null); list3.sort(comparator); assertEquals(list1, list3); @@ -1987,19 +1988,19 @@ public void listRoutingLogicalRouterTest() { @Test public void addNetworkGatewayToLogicalRouterTest() { - s_logger.debug("Create virtual network in Tungsten-Fabric."); + logger.debug("Create virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, false, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create logical router in Tungsten-Fabric."); + logger.debug("Create logical router in Tungsten-Fabric."); tungstenApi.createRoutingLogicalRouter(projectUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187", "logicalRouter1"); - s_logger.debug("Check if logical router have no network gateway in Tungsten-Fabric."); + logger.debug("Check if logical router have no network gateway in Tungsten-Fabric."); LogicalRouter logicalRouter1 = (LogicalRouter) tungstenApi.getTungstenObject(LogicalRouter.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertNull(logicalRouter1.getVirtualMachineInterface()); - s_logger.debug("Check if network gateway was added to logical router in Tungsten-Fabric."); + logger.debug("Check if network gateway was added to logical router in Tungsten-Fabric."); assertNotNull( tungstenApi.addNetworkGatewayToLogicalRouter(tungstenNetworkUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187", "192.168.100.100")); @@ -2010,14 +2011,14 @@ public void addNetworkGatewayToLogicalRouterTest() { @Test public void removeNetworkGatewayFromLogicalRouterTest() { - s_logger.debug("Create virtual network in Tungsten-Fabric."); + logger.debug("Create virtual network in Tungsten-Fabric."); tungstenApi.createTungstenNetwork(tungstenNetworkUuid, tungstenNetworkName, tungstenNetworkName, projectUuid, false, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); - s_logger.debug("Create logical router in Tungsten-Fabric."); + logger.debug("Create logical router in Tungsten-Fabric."); tungstenApi.createRoutingLogicalRouter(projectUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187", "logicalRouter1"); - s_logger.debug("Check if network gateway was added to logical router in Tungsten-Fabric."); + logger.debug("Check if network gateway was added to logical router in Tungsten-Fabric."); assertNotNull( tungstenApi.addNetworkGatewayToLogicalRouter(tungstenNetworkUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187", "192.168.100.100")); @@ -2025,7 +2026,7 @@ public void removeNetworkGatewayFromLogicalRouterTest() { "005f0dea-0196-11ec-a1ed-b42e99f6e187"); assertEquals(1, logicalRouter1.getVirtualMachineInterface().size()); - s_logger.debug("Check if network gateway was removed from logical router in Tungsten-Fabric."); + logger.debug("Check if network gateway was removed from logical router in Tungsten-Fabric."); assertNotNull(tungstenApi.removeNetworkGatewayFromLogicalRouter(tungstenNetworkUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187")); LogicalRouter logicalRouter2 = (LogicalRouter) tungstenApi.getTungstenObject(LogicalRouter.class, @@ -2035,7 +2036,7 @@ public void removeNetworkGatewayFromLogicalRouterTest() { @Test public void listConnectedNetworkFromLogicalRouterTest() { - s_logger.debug("Create network in Tungsten-Fabric"); + logger.debug("Create network in Tungsten-Fabric"); VirtualNetwork virtualNetwork1 = tungstenApi.createTungstenNetwork("6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "network1", "network1", projectUuid, true, false, "10.0.0.0", 24, "10.0.0.1", true, null, "10.0.0.10", "10.0.0.20", false, false, ""); @@ -2045,16 +2046,16 @@ public void listConnectedNetworkFromLogicalRouterTest() { List list1 = Arrays.asList(virtualNetwork1, virtualNetwork2); list1.sort(comparator); - s_logger.debug("Create logical router in Tungsten-Fabric."); + logger.debug("Create logical router in Tungsten-Fabric."); tungstenApi.createRoutingLogicalRouter(projectUuid, "005f0dea-0196-11ec-a1ed-b42e99f6e187", "logicalRouter"); - s_logger.debug("Add network gateway to logical router in Tungsten-Fabric."); + logger.debug("Add network gateway to logical router in Tungsten-Fabric."); tungstenApi.addNetworkGatewayToLogicalRouter("6b062909-ba9d-4cf3-bbd3-7db93cf6b4fe", "005f0dea-0196-11ec-a1ed-b42e99f6e187", "192.168.100.100"); tungstenApi.addNetworkGatewayToLogicalRouter("baf714fa-80a1-454f-9c32-c4d4a6f5c5a4", "005f0dea-0196-11ec-a1ed-b42e99f6e187", "192.168.100.101"); - s_logger.debug("Check if connected network in logical router was listed in Tungsten-Fabric."); + logger.debug("Check if connected network in logical router was listed in Tungsten-Fabric."); LogicalRouter logicalRouter = (LogicalRouter) tungstenApi.getTungstenObject(LogicalRouter.class, "005f0dea-0196-11ec-a1ed-b42e99f6e187"); List list2 = tungstenApi.listConnectedNetworkFromLogicalRouter(logicalRouter); diff --git a/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenGuestNetworkGuruTest.java b/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenGuestNetworkGuruTest.java index 6a5a0132442a..f66e026ba91b 100644 --- a/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenGuestNetworkGuruTest.java +++ b/plugins/network-elements/tungsten/src/test/java/org/apache/cloudstack/network/tungsten/service/TungstenGuestNetworkGuruTest.java @@ -233,7 +233,7 @@ public void testCanDesign() { final Network network = mock(Network.class); final Account account = mock(Account.class); - final Network designedNetwork = guru.design(offering, plan, network, account); + final Network designedNetwork = guru.design(offering, plan, network, "", 1L, account); assertNotNull(designedNetwork); assertSame(Networks.BroadcastDomainType.TUNGSTEN, designedNetwork.getBroadcastDomainType()); assertSame(Network.State.Allocated, designedNetwork.getState()); diff --git a/plugins/network-elements/tungsten/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/network-elements/tungsten/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/network-elements/tungsten/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/network-elements/vxlan/pom.xml b/plugins/network-elements/vxlan/pom.xml index 0806868dc524..34d7890bae9a 100644 --- a/plugins/network-elements/vxlan/pom.xml +++ b/plugins/network-elements/vxlan/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/network-elements/vxlan/src/main/java/com/cloud/network/guru/VxlanGuestNetworkGuru.java b/plugins/network-elements/vxlan/src/main/java/com/cloud/network/guru/VxlanGuestNetworkGuru.java index 410ed3c5c346..fc92775c6972 100644 --- a/plugins/network-elements/vxlan/src/main/java/com/cloud/network/guru/VxlanGuestNetworkGuru.java +++ b/plugins/network-elements/vxlan/src/main/java/com/cloud/network/guru/VxlanGuestNetworkGuru.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenter; @@ -47,7 +46,6 @@ @Component public class VxlanGuestNetworkGuru extends GuestNetworkGuru { - private static final Logger s_logger = Logger.getLogger(VxlanGuestNetworkGuru.class); public VxlanGuestNetworkGuru() { super(); @@ -62,14 +60,14 @@ protected boolean canHandle(NetworkOffering offering, final NetworkType networkT isMyIsolationMethod(physicalNetwork) && !offering.isSystemOnly()) { return true; } else { - s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " or " + GuestType.L2 + " in zone of type " + NetworkType.Advanced); + logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " or " + GuestType.L2 + " in zone of type " + NetworkType.Advanced); return false; } } @Override - public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { - NetworkVO network = (NetworkVO)super.design(offering, plan, userSpecified, owner); + public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner) { + NetworkVO network = (NetworkVO)super.design(offering, plan, userSpecified, name, vpcId, owner); if (network == null) { return null; } @@ -151,7 +149,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservat public void shutdown(NetworkProfile profile, NetworkOffering offering) { NetworkVO networkObject = _networkDao.findById(profile.getId()); if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Vxlan || networkObject.getBroadcastUri() == null) { - s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); + logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); return; } diff --git a/plugins/network-elements/vxlan/src/test/java/com/cloud/network/guru/VxlanGuestNetworkGuruTest.java b/plugins/network-elements/vxlan/src/test/java/com/cloud/network/guru/VxlanGuestNetworkGuruTest.java index 27c2ad53e8ce..71f86791725d 100644 --- a/plugins/network-elements/vxlan/src/test/java/com/cloud/network/guru/VxlanGuestNetworkGuruTest.java +++ b/plugins/network-elements/vxlan/src/test/java/com/cloud/network/guru/VxlanGuestNetworkGuruTest.java @@ -18,9 +18,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -138,7 +138,7 @@ public void testDesign() { Network network = mock(Network.class); Account account = mock(Account.class); - Network designednetwork = guru.design(offering, plan, network, account); + Network designednetwork = guru.design(offering, plan, network, "", 1L, account); assertTrue(designednetwork != null); assertTrue(designednetwork.getBroadcastDomainType() == BroadcastDomainType.Vxlan); } diff --git a/plugins/outofbandmanagement-drivers/ipmitool/pom.xml b/plugins/outofbandmanagement-drivers/ipmitool/pom.xml index 66300e37269e..af7952a8a561 100644 --- a/plugins/outofbandmanagement-drivers/ipmitool/pom.xml +++ b/plugins/outofbandmanagement-drivers/ipmitool/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolOutOfBandManagementDriver.java b/plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolOutOfBandManagementDriver.java index 2c42554afccf..2fe747594105 100644 --- a/plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolOutOfBandManagementDriver.java +++ b/plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolOutOfBandManagementDriver.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverCommand; import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverPowerCommand; import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse; -import org.apache.log4j.Logger; import org.joda.time.Duration; import java.util.Arrays; @@ -39,7 +38,6 @@ import org.apache.commons.lang3.StringUtils; public final class IpmitoolOutOfBandManagementDriver extends AdapterBase implements OutOfBandManagementDriver, Configurable { - public static final Logger LOG = Logger.getLogger(IpmitoolOutOfBandManagementDriver.class); private static volatile boolean isDriverEnabled = false; private static boolean isIpmiToolBinAvailable = false; @@ -70,14 +68,14 @@ private String getIpmiUserId(ImmutableMap op if (!output.isSuccess()) { String oneLineCommand = StringUtils.join(ipmiToolCommands, " "); String message = String.format("Failed to find IPMI user [%s] to change password. Command [%s], error [%s].", username, oneLineCommand, output.getError()); - LOG.debug(message); + logger.debug(message); throw new CloudRuntimeException(message); } final String userId = IPMITOOL.findIpmiUser(output.getResult(), username); if (StringUtils.isEmpty(userId)) { String message = String.format("No IPMI user ID found for the username [%s].", username); - LOG.debug(message); + logger.debug(message); throw new CloudRuntimeException(message); } return userId; @@ -88,7 +86,7 @@ public OutOfBandManagementDriverResponse execute(final OutOfBandManagementDriver initDriver(); if (!isIpmiToolBinAvailable) { String message = "Aborting operation due to ipmitool binary not available for execution."; - LOG.debug(message); + logger.debug(message); return new OutOfBandManagementDriverResponse(null, message, false); } } @@ -96,7 +94,7 @@ public OutOfBandManagementDriverResponse execute(final OutOfBandManagementDriver OutOfBandManagementDriverResponse response = new OutOfBandManagementDriverResponse(null, "Unsupported Command", false); if (!isDriverEnabled) { String message = "Driver not enabled or shutdown."; - LOG.debug(message); + logger.debug(message); response.setError(message); return response; } @@ -108,7 +106,7 @@ public OutOfBandManagementDriverResponse execute(final OutOfBandManagementDriver if (response != null && !response.isSuccess() && response.getError().contains("RAKP 2 HMAC is invalid")) { String message = String.format("Setting authFailure as 'true' due to [%s].", response.getError()); - LOG.debug(message); + logger.debug(message); response.setAuthFailure(true); } return response; @@ -126,12 +124,12 @@ private OutOfBandManagementDriverResponse execute(final OutOfBandManagementDrive String result = response.getResult().trim(); if (response.isSuccess()) { - LOG.debug(String.format("The command [%s] was successful and got the result [%s].", oneLineCommand, result)); + logger.debug(String.format("The command [%s] was successful and got the result [%s].", oneLineCommand, result)); if (cmd.getPowerOperation().equals(OutOfBandManagement.PowerOperation.STATUS)) { response.setPowerState(IPMITOOL.parsePowerState(result)); } } else { - LOG.debug(String.format("The command [%s] failed and got the result [%s]. Error: [%s].", oneLineCommand, result, response.getError())); + logger.debug(String.format("The command [%s] failed and got the result [%s]. Error: [%s].", oneLineCommand, result, response.getError())); } return response; } @@ -150,10 +148,10 @@ private void initDriver() { final OutOfBandManagementDriverResponse output = IPMITOOL.executeCommands(Arrays.asList(IpmiToolPath.value(), "-V")); if (output.isSuccess() && output.getResult().startsWith("ipmitool version")) { isIpmiToolBinAvailable = true; - LOG.debug(String.format("OutOfBandManagementDriver ipmitool initialized [%s].", output.getResult())); + logger.debug(String.format("OutOfBandManagementDriver ipmitool initialized [%s].", output.getResult())); } else { isIpmiToolBinAvailable = false; - LOG.error(String.format("OutOfBandManagementDriver ipmitool failed initialization with error [%s]; standard output [%s].", output.getError(), output.getResult())); + logger.error(String.format("OutOfBandManagementDriver ipmitool failed initialization with error [%s]; standard output [%s].", output.getError(), output.getResult())); } } diff --git a/plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapper.java b/plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapper.java index 6fe98c0925c6..86ec615e5523 100644 --- a/plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapper.java +++ b/plugins/outofbandmanagement-drivers/ipmitool/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapper.java @@ -25,7 +25,8 @@ import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse; import org.apache.cloudstack.utils.process.ProcessResult; import org.apache.cloudstack.utils.process.ProcessRunner; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.joda.time.Duration; import java.util.ArrayList; @@ -33,7 +34,7 @@ import java.util.concurrent.ExecutorService; public final class IpmitoolWrapper { - public static final Logger LOG = Logger.getLogger(IpmitoolWrapper.class); + protected Logger logger = LogManager.getLogger(getClass()); private final ProcessRunner RUNNER; @@ -155,7 +156,7 @@ public OutOfBandManagementDriverResponse executeCommands(final List comm public OutOfBandManagementDriverResponse executeCommands(final List commands, final Duration timeOut) { final ProcessResult result = RUNNER.executeCommands(commands, timeOut); - if (LOG.isTraceEnabled()) { + if (logger.isTraceEnabled()) { List cleanedCommands = new ArrayList(); int maskNextCommand = 0; for (String command : commands) { @@ -171,7 +172,7 @@ public OutOfBandManagementDriverResponse executeCommands(final List comm } cleanedCommands.add(command); } - LOG.trace("Executed ipmitool process with commands: " + StringUtils.join(cleanedCommands, ", ") + + logger.trace("Executed ipmitool process with commands: " + StringUtils.join(cleanedCommands, ", ") + "\nIpmitool execution standard output: " + result.getStdOutput() + "\nIpmitool execution error output: " + result.getStdError()); } diff --git a/plugins/outofbandmanagement-drivers/ipmitool/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java b/plugins/outofbandmanagement-drivers/ipmitool/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java index 26115f7a8cf3..01e4e2321b37 100644 --- a/plugins/outofbandmanagement-drivers/ipmitool/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java +++ b/plugins/outofbandmanagement-drivers/ipmitool/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/ipmitool/IpmitoolWrapperTest.java @@ -26,7 +26,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.List; import java.util.concurrent.ExecutorService; diff --git a/plugins/outofbandmanagement-drivers/nested-cloudstack/pom.xml b/plugins/outofbandmanagement-drivers/nested-cloudstack/pom.xml index a7f1c6c26c36..25d8e4054db6 100644 --- a/plugins/outofbandmanagement-drivers/nested-cloudstack/pom.xml +++ b/plugins/outofbandmanagement-drivers/nested-cloudstack/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/outofbandmanagement-drivers/nested-cloudstack/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriver.java b/plugins/outofbandmanagement-drivers/nested-cloudstack/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriver.java index fcf2caa6b96a..7f73e1dda88b 100644 --- a/plugins/outofbandmanagement-drivers/nested-cloudstack/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriver.java +++ b/plugins/outofbandmanagement-drivers/nested-cloudstack/src/main/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriver.java @@ -31,14 +31,12 @@ import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverCommand; import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverPowerCommand; import org.apache.cloudstack.outofbandmanagement.driver.OutOfBandManagementDriverResponse; -import org.apache.log4j.Logger; import java.io.IOException; import java.util.List; import java.util.Map; public final class NestedCloudStackOutOfBandManagementDriver extends AdapterBase implements OutOfBandManagementDriver { - private static final Logger LOG = Logger.getLogger(NestedCloudStackOutOfBandManagementDriver.class); public OutOfBandManagementDriverResponse execute(final OutOfBandManagementDriverCommand cmd) { OutOfBandManagementDriverResponse response = new OutOfBandManagementDriverResponse(null, "Unsupported Command", false); @@ -79,7 +77,7 @@ protected OutOfBandManagement.PowerState getNestedVMPowerState(final String json } } } catch (IOException e) { - LOG.warn("Exception caught while de-serializing and reading state of the nested-cloudstack VM from the response: " + jsonResponse + ", with exception:", e); + logger.warn("Exception caught while de-serializing and reading state of the nested-cloudstack VM from the response: " + jsonResponse + ", with exception:", e); } return OutOfBandManagement.PowerState.Unknown; } @@ -130,7 +128,7 @@ private OutOfBandManagementDriverResponse execute(final OutOfBandManagementDrive try { apiResponse = client.executeRequest(apacheCloudStackRequest); } catch (final ApacheCloudStackClientRequestRuntimeException e) { - LOG.error("Nested CloudStack oobm plugin failed due to API error: ", e); + logger.error("Nested CloudStack oobm plugin failed due to API error: ", e); final OutOfBandManagementDriverResponse failedResponse = new OutOfBandManagementDriverResponse(e.getResponse(), "HTTP error code: " + e.getStatusCode(), false); if (e.getStatusCode() == 401) { failedResponse.setAuthFailure(true); diff --git a/plugins/outofbandmanagement-drivers/nested-cloudstack/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriverTest.java b/plugins/outofbandmanagement-drivers/nested-cloudstack/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriverTest.java index 5629773b9efd..f0f045fa2205 100644 --- a/plugins/outofbandmanagement-drivers/nested-cloudstack/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriverTest.java +++ b/plugins/outofbandmanagement-drivers/nested-cloudstack/src/test/java/org/apache/cloudstack/outofbandmanagement/driver/nestedcloudstack/NestedCloudStackOutOfBandManagementDriverTest.java @@ -25,7 +25,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; diff --git a/plugins/outofbandmanagement-drivers/redfish/pom.xml b/plugins/outofbandmanagement-drivers/redfish/pom.xml index 766a22fc1318..df19ef997b06 100644 --- a/plugins/outofbandmanagement-drivers/redfish/pom.xml +++ b/plugins/outofbandmanagement-drivers/redfish/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/pom.xml b/plugins/pom.xml index 27d316f56c19..3580976fa168 100755 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT @@ -62,6 +62,7 @@ backup/dummy backup/networker + backup/nas ca/root-ca @@ -79,6 +80,7 @@ event-bus/inmemory event-bus/kafka event-bus/rabbitmq + event-bus/webhook ha-planners/skip-heurestics @@ -118,6 +120,7 @@ shutdown + storage/sharedfs/storagevm storage/image/default storage/image/s3 storage/image/sample @@ -135,6 +138,7 @@ storage/volume/flasharray storage/volume/primera storage/object/minio + storage/object/ceph storage/object/simulator @@ -228,6 +232,7 @@ backup/veeam hypervisors/vmware network-elements/cisco-vnmc + network-elements/nsx network-elements/juniper-contrail network-elements/tungsten diff --git a/plugins/shutdown/pom.xml b/plugins/shutdown/pom.xml index 7c46f03d0f60..f995e5c82d24 100644 --- a/plugins/shutdown/pom.xml +++ b/plugins/shutdown/pom.xml @@ -26,7 +26,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/CancelShutdownCmd.java b/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/CancelShutdownCmd.java index fe6204fd0cc3..aa90d7fcbdc9 100644 --- a/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/CancelShutdownCmd.java +++ b/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/CancelShutdownCmd.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; -import org.apache.log4j.Logger; import com.cloud.user.Account; @@ -35,7 +34,6 @@ public class CancelShutdownCmd extends BaseShutdownActionCmd { - public static final Logger LOG = Logger.getLogger(CancelShutdownCmd.class); public static final String APINAME = "cancelShutdown"; @Override diff --git a/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/PrepareForShutdownCmd.java b/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/PrepareForShutdownCmd.java index 01ea1797a105..c86d28560470 100644 --- a/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/PrepareForShutdownCmd.java +++ b/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/PrepareForShutdownCmd.java @@ -20,7 +20,6 @@ import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; -import org.apache.log4j.Logger; import com.cloud.user.Account; @@ -34,7 +33,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class PrepareForShutdownCmd extends BaseShutdownActionCmd { - public static final Logger LOG = Logger.getLogger(PrepareForShutdownCmd.class); public static final String APINAME = "prepareForShutdown"; @Override diff --git a/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/ReadyForShutdownCmd.java b/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/ReadyForShutdownCmd.java index 1e6b3e1a2d5e..de4db9c04284 100644 --- a/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/ReadyForShutdownCmd.java +++ b/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/ReadyForShutdownCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.response.ManagementServerResponse; import org.apache.cloudstack.api.response.ReadyForShutdownResponse; import org.apache.cloudstack.shutdown.ShutdownManager; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = ReadyForShutdownCmd.APINAME, @@ -35,7 +34,6 @@ responseObject = ReadyForShutdownResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReadyForShutdownCmd extends BaseCmd { - public static final Logger LOG = Logger.getLogger(ReadyForShutdownCmd.class); public static final String APINAME = "readyForShutdown"; @Inject diff --git a/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/TriggerShutdownCmd.java b/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/TriggerShutdownCmd.java index 3abde0b1f3b1..b4ef7c1f67a6 100644 --- a/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/TriggerShutdownCmd.java +++ b/plugins/shutdown/src/main/java/org/apache/cloudstack/api/command/TriggerShutdownCmd.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; -import org.apache.log4j.Logger; import com.cloud.user.Account; @@ -33,7 +32,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class TriggerShutdownCmd extends BaseShutdownActionCmd { - public static final Logger LOG = Logger.getLogger(TriggerShutdownCmd.class); public static final String APINAME = "triggerShutdown"; ///////////////////////////////////////////////////// diff --git a/plugins/shutdown/src/main/java/org/apache/cloudstack/shutdown/ShutdownManagerImpl.java b/plugins/shutdown/src/main/java/org/apache/cloudstack/shutdown/ShutdownManagerImpl.java index da3bba54bdc3..c33243357fcd 100644 --- a/plugins/shutdown/src/main/java/org/apache/cloudstack/shutdown/ShutdownManagerImpl.java +++ b/plugins/shutdown/src/main/java/org/apache/cloudstack/shutdown/ShutdownManagerImpl.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.shutdown.command.PrepareForShutdownManagementServerHostCommand; import org.apache.cloudstack.shutdown.command.TriggerShutdownManagementServerHostCommand; import org.apache.cloudstack.utils.identity.ManagementServerNode; -import org.apache.log4j.Logger; import com.cloud.agent.api.Command; import com.cloud.cluster.ClusterManager; @@ -49,8 +48,6 @@ import com.google.gson.Gson; public class ShutdownManagerImpl extends ManagerBase implements ShutdownManager, PluggableService{ - - private static Logger logger = Logger.getLogger(ShutdownManagerImpl.class); Gson gson; @Inject diff --git a/plugins/storage-allocators/random/pom.xml b/plugins/storage-allocators/random/pom.xml index c40b9eb3266d..4442f000e73f 100644 --- a/plugins/storage-allocators/random/pom.xml +++ b/plugins/storage-allocators/random/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/storage-allocators/random/src/main/java/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java b/plugins/storage-allocators/random/src/main/java/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java index 87a6bf56a6e3..dd8f2e78b736 100644 --- a/plugins/storage-allocators/random/src/main/java/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java +++ b/plugins/storage-allocators/random/src/main/java/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java @@ -20,7 +20,6 @@ import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; @@ -32,7 +31,6 @@ import com.cloud.vm.VirtualMachineProfile; public class RandomStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(RandomStoragePoolAllocator.class); @Override public List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) { @@ -45,21 +43,21 @@ public List select(DiskProfile dskCh, VirtualMachineProfile vmProfi Long clusterId = plan.getClusterId(); if (podId == null) { - s_logger.debug("RandomStoragePoolAllocator is returning null since the pod ID is null. This may be a zone wide storage."); + logger.debug("RandomStoragePoolAllocator is returning null since the pod ID is null. This may be a zone wide storage."); return null; } - s_logger.debug(String.format("Looking for pools in dc [%s], pod [%s] and cluster [%s].", dcId, podId, clusterId)); + logger.debug(String.format("Looking for pools in dc [%s], pod [%s] and cluster [%s].", dcId, podId, clusterId)); List pools = storagePoolDao.listBy(dcId, podId, clusterId, ScopeType.CLUSTER); if (pools.size() == 0) { - s_logger.debug(String.format("RandomStoragePoolAllocator found no storage pools available for allocation in dc [%s], pod [%s] and cluster [%s]. Returning an empty list.", + logger.debug(String.format("RandomStoragePoolAllocator found no storage pools available for allocation in dc [%s], pod [%s] and cluster [%s]. Returning an empty list.", dcId, podId, clusterId)); return suitablePools; } Collections.shuffle(pools); - s_logger.debug(String.format("RandomStoragePoolAllocator has [%s] pools to check for allocation [%s].", pools.size(), pools)); + logger.debug(String.format("RandomStoragePoolAllocator has [%s] pools to check for allocation [%s].", pools.size(), pools)); for (StoragePoolVO pool : pools) { if (suitablePools.size() == returnUpTo) { @@ -68,7 +66,7 @@ public List select(DiskProfile dskCh, VirtualMachineProfile vmProfi StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()); if (filter(avoid, pol, dskCh, plan)) { - s_logger.trace(String.format("Found suitable local storage pool [%s], adding to list.", pool)); + logger.trace(String.format("Found suitable local storage pool [%s], adding to list.", pool)); suitablePools.add(pol); } } diff --git a/plugins/storage/image/default/pom.xml b/plugins/storage/image/default/pom.xml index f0a54a5e297a..fe91a9dbe966 100644 --- a/plugins/storage/image/default/pom.xml +++ b/plugins/storage/image/default/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java b/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java index fca6db26169b..d9a12d382bac 100644 --- a/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java +++ b/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java @@ -26,7 +26,6 @@ import com.cloud.host.dao.HostDao; import com.cloud.storage.Upload; import com.cloud.utils.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -46,7 +45,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class CloudStackImageStoreDriverImpl extends NfsImageStoreDriverImpl { - private static final Logger s_logger = Logger.getLogger(CloudStackImageStoreDriverImpl.class); @Inject ConfigurationDao _configDao; @@ -105,14 +103,14 @@ public String createEntityExtractUrl(DataStore store, String installPath, ImageF Answer ans = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); ans = new Answer(cmd, false, errMsg); } else { ans = ep.sendMessage(cmd); } if (ans == null || !ans.getResult()) { String errorString = "Unable to create a link for entity at " + installPath + " on ssvm, " + ans.getDetails(); - s_logger.error(errorString); + logger.error(errorString); throw new CloudRuntimeException(errorString); } // Construct actual URL locally now that the symlink exists at SSVM @@ -130,7 +128,7 @@ private String generateCopyUrl(String ipAddress, String fileName, String filePat _sslCopy = Boolean.parseBoolean(sslCfg); } if(_sslCopy && (_ssvmUrlDomain == null || _ssvmUrlDomain.isEmpty())){ - s_logger.warn("Empty secondary storage url domain, ignoring SSL"); + logger.warn("Empty secondary storage url domain, ignoring SSL"); _sslCopy = false; } if (_sslCopy) { @@ -156,14 +154,14 @@ public void deleteEntityExtractUrl(DataStore store, String installPath, String d Answer ans = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); ans = new Answer(cmd, false, errMsg); } else { ans = ep.sendMessage(cmd); } if (ans == null || !ans.getResult()) { String errorString = "Unable to delete the url " + downloadUrl + " for path " + installPath + " on ssvm, " + ans.getDetails(); - s_logger.error(errorString); + logger.error(errorString); throw new CloudRuntimeException(errorString); } diff --git a/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java b/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java index 0e53191fb8ef..fca542a181fb 100644 --- a/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java +++ b/plugins/storage/image/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackImageStoreLifeCycleImpl.java @@ -26,7 +26,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.StringUtils; @@ -51,7 +52,7 @@ public class CloudStackImageStoreLifeCycleImpl implements ImageStoreLifeCycle { - private static final Logger s_logger = Logger.getLogger(CloudStackImageStoreLifeCycleImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected ResourceManager _resourceMgr; @Inject @@ -94,7 +95,7 @@ public DataStore initialize(Map dsInfos) { } else { logString = StringUtils.cleanString(url); } - s_logger.info("Trying to add a new data store at " + logString + " to data center " + dcId); + logger.info("Trying to add a new data store at " + logString + " to data center " + dcId); URI uri = null; try { diff --git a/plugins/storage/image/default/src/main/resources/META-INF/cloudstack/storage-image-default/spring-storage-image-default-context.xml b/plugins/storage/image/default/src/main/resources/META-INF/cloudstack/storage-image-default/spring-storage-image-default-context.xml index 6c2dc8ad9a37..6ca997bfec28 100644 --- a/plugins/storage/image/default/src/main/resources/META-INF/cloudstack/storage-image-default/spring-storage-image-default-context.xml +++ b/plugins/storage/image/default/src/main/resources/META-INF/cloudstack/storage-image-default/spring-storage-image-default-context.xml @@ -29,5 +29,5 @@ - + diff --git a/plugins/storage/image/s3/pom.xml b/plugins/storage/image/s3/pom.xml index fcec2ca07ccf..185173d0fe6a 100644 --- a/plugins/storage/image/s3/pom.xml +++ b/plugins/storage/image/s3/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java b/plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java index 3c2bc953d979..9b2f3ddd1001 100644 --- a/plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java +++ b/plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; @@ -42,7 +41,6 @@ import com.cloud.utils.storage.S3.S3Utils; public class S3ImageStoreDriverImpl extends BaseImageStoreDriverImpl { - private static final Logger s_logger = Logger.getLogger(S3ImageStoreDriverImpl.class); @Inject ImageStoreDetailsDao _imageStoreDetailsDao; @@ -88,8 +86,8 @@ public String createEntityExtractUrl(DataStore store, String key, ImageFormat fo */ S3TO s3 = (S3TO)getStoreTO(store); - if(s_logger.isDebugEnabled()) { - s_logger.debug("Generating pre-signed s3 entity extraction URL for object: " + key); + if(logger.isDebugEnabled()) { + logger.debug("Generating pre-signed s3 entity extraction URL for object: " + key); } Date expiration = new Date(); long milliSeconds = expiration.getTime(); @@ -103,7 +101,7 @@ public String createEntityExtractUrl(DataStore store, String key, ImageFormat fo URL s3url = S3Utils.generatePresignedUrl(s3, s3.getBucketName(), key, expiration); - s_logger.info("Pre-Signed URL = " + s3url.toString()); + logger.info("Pre-Signed URL = " + s3url.toString()); return s3url.toString(); } diff --git a/plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java b/plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java index 062fb70ae63f..5e5069af3fc2 100644 --- a/plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java +++ b/plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java @@ -22,7 +22,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; @@ -44,7 +45,7 @@ public class S3ImageStoreLifeCycleImpl implements ImageStoreLifeCycle { - private static final Logger s_logger = Logger.getLogger(S3ImageStoreLifeCycleImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected ResourceManager _resourceMgr; @Inject @@ -78,7 +79,7 @@ public DataStore initialize(Map dsInfos) { DataStoreRole role = (DataStoreRole)dsInfos.get("role"); Map details = (Map)dsInfos.get("details"); - s_logger.info("Trying to add a S3 store with endpoint: " + details.get(ApiConstants.S3_END_POINT)); + logger.info("Trying to add a S3 store with endpoint: " + details.get(ApiConstants.S3_END_POINT)); Map imageStoreParameters = new HashMap(); imageStoreParameters.put("name", name); diff --git a/plugins/storage/image/s3/src/main/resources/META-INF/cloudstack/storage-image-s3/spring-storage-image-s3-context.xml b/plugins/storage/image/s3/src/main/resources/META-INF/cloudstack/storage-image-s3/spring-storage-image-s3-context.xml index 7b2fa465a585..f99585cdaf92 100644 --- a/plugins/storage/image/s3/src/main/resources/META-INF/cloudstack/storage-image-s3/spring-storage-image-s3-context.xml +++ b/plugins/storage/image/s3/src/main/resources/META-INF/cloudstack/storage-image-s3/spring-storage-image-s3-context.xml @@ -30,5 +30,5 @@ - + diff --git a/plugins/storage/image/sample/pom.xml b/plugins/storage/image/sample/pom.xml index 7ea5442c2e4d..fbc9cec1440a 100644 --- a/plugins/storage/image/sample/pom.xml +++ b/plugins/storage/image/sample/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/image/swift/pom.xml b/plugins/storage/image/swift/pom.xml index 1e53179f977a..832972d3816b 100644 --- a/plugins/storage/image/swift/pom.xml +++ b/plugins/storage/image/swift/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/image/swift/src/main/java/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java b/plugins/storage/image/swift/src/main/java/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java index 7e1486214bcf..c3a82c421896 100644 --- a/plugins/storage/image/swift/src/main/java/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java +++ b/plugins/storage/image/swift/src/main/java/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java @@ -27,7 +27,6 @@ import com.cloud.configuration.Config; import com.cloud.utils.SwiftUtil; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult; @@ -53,7 +52,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class SwiftImageStoreDriverImpl extends BaseImageStoreDriverImpl { - private static final Logger s_logger = Logger.getLogger(SwiftImageStoreDriverImpl.class); @Inject ImageStoreDetailsDao _imageStoreDetailsDao; @@ -80,7 +78,7 @@ public String createEntityExtractUrl(DataStore store, String installPath, ImageF if (!result) { String errMsg = "Unable to set Temp-Key: " + tempKey; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -91,7 +89,7 @@ public String createEntityExtractUrl(DataStore store, String installPath, ImageF URL swiftUrl = SwiftUtil.generateTempUrl(swiftTO, containerName, objectName, tempKey, urlExpirationInterval); if (swiftUrl != null) { - s_logger.debug("Swift temp-url: " + swiftUrl.toString()); + logger.debug("Swift temp-url: " + swiftUrl.toString()); return swiftUrl.toString(); } @@ -110,7 +108,7 @@ public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCal EndPoint ep = _epSelector.select(data); if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } diff --git a/plugins/storage/image/swift/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java b/plugins/storage/image/swift/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java index f70eb3fa3e3f..a568270bf2a7 100644 --- a/plugins/storage/image/swift/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java +++ b/plugins/storage/image/swift/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SwiftImageStoreLifeCycleImpl.java @@ -21,7 +21,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -41,7 +42,7 @@ public class SwiftImageStoreLifeCycleImpl implements ImageStoreLifeCycle { - private static final Logger s_logger = Logger.getLogger(SwiftImageStoreLifeCycleImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected ResourceManager _resourceMgr; @Inject @@ -66,7 +67,7 @@ public DataStore initialize(Map dsInfos) { Map details = (Map)dsInfos.get("details"); - s_logger.info("Trying to add a swift store at " + url + " in data center " + dcId); + logger.info("Trying to add a swift store at " + url + " in data center " + dcId); // just need to insert an entry in DB Map imageStoreParameters = new HashMap(); diff --git a/plugins/storage/image/swift/src/main/resources/META-INF/cloudstack/storage-image-swift/spring-storage-image-swift-context.xml b/plugins/storage/image/swift/src/main/resources/META-INF/cloudstack/storage-image-swift/spring-storage-image-swift-context.xml index a84eb4203759..56ed0a2f0ca5 100644 --- a/plugins/storage/image/swift/src/main/resources/META-INF/cloudstack/storage-image-swift/spring-storage-image-swift-context.xml +++ b/plugins/storage/image/swift/src/main/resources/META-INF/cloudstack/storage-image-swift/spring-storage-image-swift-context.xml @@ -29,5 +29,5 @@ - + diff --git a/plugins/storage/object/ceph/pom.xml b/plugins/storage/object/ceph/pom.xml new file mode 100644 index 000000000000..43b3a15731df --- /dev/null +++ b/plugins/storage/object/ceph/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + cloud-plugin-storage-object-ceph + Apache CloudStack Plugin - Ceph RGW object storage provider + + org.apache.cloudstack + cloudstack-plugins + 4.20.0.0-SNAPSHOT + ../../../pom.xml + + + + org.apache.cloudstack + cloud-engine-storage + ${project.version} + + + org.apache.cloudstack + cloud-engine-storage-object + ${project.version} + + + org.apache.cloudstack + cloud-engine-schema + ${project.version} + + + io.github.twonote + radosgw-admin4j + 2.0.9 + + + diff --git a/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImpl.java b/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImpl.java new file mode 100644 index 000000000000..6fece40e6ac5 --- /dev/null +++ b/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImpl.java @@ -0,0 +1,362 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.driver; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.amazonaws.services.s3.model.AmazonS3Exception; +import com.amazonaws.services.s3.model.AccessControlList; +import com.amazonaws.services.s3.model.BucketPolicy; +import com.amazonaws.services.s3.model.BucketVersioningConfiguration; +import com.amazonaws.services.s3.model.DeleteBucketPolicyRequest; +import com.amazonaws.services.s3.model.SetBucketPolicyRequest; +import com.amazonaws.services.s3.model.GetBucketPolicyRequest; +import com.amazonaws.services.s3.model.SetBucketVersioningConfigurationRequest; +import com.cloud.agent.api.to.BucketTO; +import com.cloud.agent.api.to.DataStoreTO; +import org.apache.cloudstack.storage.object.Bucket; +import com.cloud.storage.BucketVO; +import com.cloud.storage.dao.BucketDao; +import com.cloud.user.Account; +import com.cloud.user.AccountDetailsDao; +import com.cloud.user.dao.AccountDao; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.storage.datastore.db.ObjectStoreDao; +import org.apache.cloudstack.storage.datastore.db.ObjectStoreDetailsDao; +import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; +import org.apache.cloudstack.storage.object.BaseObjectStoreDriverImpl; +import org.apache.cloudstack.storage.object.BucketObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.twonote.rgwadmin4j.RgwAdmin; +import org.twonote.rgwadmin4j.RgwAdminBuilder; +import org.twonote.rgwadmin4j.model.BucketInfo; +import org.twonote.rgwadmin4j.model.S3Credential; +import org.twonote.rgwadmin4j.model.User; + +import javax.inject.Inject; +import java.util.List; +import java.util.ArrayList; +import java.util.Optional; +import java.util.Map; +import java.util.HashMap; + +public class CephObjectStoreDriverImpl extends BaseObjectStoreDriverImpl { + private static final Logger s_logger = LogManager.getLogger(CephObjectStoreDriverImpl.class); + + @Inject + AccountDao _accountDao; + + @Inject + AccountDetailsDao _accountDetailsDao; + + @Inject + ObjectStoreDao _storeDao; + + @Inject + BucketDao _bucketDao; + + @Inject + ObjectStoreDetailsDao _storeDetailsDao; + + private static final String ACCESS_KEY = "accesskey"; + private static final String SECRET_KEY = "secretkey"; + + private static final String CEPH_ACCESS_KEY = "ceph-rgw-accesskey"; + private static final String CEPH_SECRET_KEY = "ceph-rgw-secretkey"; + + @Override + public DataStoreTO getStoreTO(DataStore store) { + return null; + } + + @Override + public Bucket createBucket(Bucket bucket, boolean objectLock) { + String bucketName = bucket.getName(); + long storeId = bucket.getObjectStoreId(); + long accountId = bucket.getAccountId(); + AmazonS3 s3client = getS3Client(storeId, accountId); + + try { + if (s3client.getBucketAcl(bucketName) != null) { + throw new CloudRuntimeException("Bucket already exists with name " + bucketName); + } + } catch (AmazonS3Exception e) { + if (e.getStatusCode() != 404) { + throw new CloudRuntimeException(e); + } + } catch (Exception e) { + throw new CloudRuntimeException(e); + } + try { + s3client.createBucket(bucketName); + String accessKey = _accountDetailsDao.findDetail(accountId, CEPH_ACCESS_KEY).getValue(); + String secretKey = _accountDetailsDao.findDetail(accountId, CEPH_SECRET_KEY).getValue(); + ObjectStoreVO store = _storeDao.findById(storeId); + BucketVO bucketVO = _bucketDao.findById(bucket.getId()); + bucketVO.setAccessKey(accessKey); + bucketVO.setSecretKey(secretKey); + bucketVO.setBucketURL(store.getUrl() + "/" + bucketName); + _bucketDao.update(bucket.getId(), bucketVO); + return bucketVO; + } catch (Exception e) { + throw new CloudRuntimeException(e); + } + } + + @Override + public List listBuckets(long storeId) { + RgwAdmin rgwAdmin = getRgwAdminClient(storeId); + List bucketsList = new ArrayList<>(); + try { + List buckets = rgwAdmin.listBucket(); + for(String name : buckets) { + Bucket bucket = new BucketObject(); + bucket.setName(name); + bucketsList.add(bucket); + } + } catch (Exception e) { + throw new CloudRuntimeException(e); + } + return bucketsList; + } + + @Override + public boolean deleteBucket(BucketTO bucket, long storeId) { + RgwAdmin rgwAdmin = getRgwAdminClient(storeId); + + try { + rgwAdmin.removeBucket(bucket.getName()); + } catch (Exception e) { + throw new CloudRuntimeException(e); + } + return true; + } + + @Override + public AccessControlList getBucketAcl(BucketTO bucket, long storeId) { + return null; + } + + @Override + public void setBucketAcl(BucketTO bucket, AccessControlList acl, long storeId) { + + } + + @Override + public void setBucketPolicy(BucketTO bucket, String policy, long storeId) { + String policyConfig; + + if (policy.equalsIgnoreCase("public")) { + s_logger.debug("Setting public policy on bucket " + bucket.getName()); + StringBuilder builder = new StringBuilder(); + builder.append("{\n"); + builder.append(" \"Statement\": [\n"); + builder.append(" {\n"); + builder.append(" \"Action\": [\n"); + builder.append(" \"s3:GetBucketLocation\",\n"); + builder.append(" \"s3:ListBucket\"\n"); + builder.append(" ],\n"); + builder.append(" \"Effect\": \"Allow\",\n"); + builder.append(" \"Principal\": \"*\",\n"); + builder.append(" \"Resource\": \"arn:aws:s3:::" + bucket.getName() + "\"\n"); + builder.append(" },\n"); + builder.append(" {\n"); + builder.append(" \"Action\": \"s3:GetObject\",\n"); + builder.append(" \"Effect\": \"Allow\",\n"); + builder.append(" \"Principal\": \"*\",\n"); + builder.append(" \"Resource\": \"arn:aws:s3:::" + bucket.getName() + "/*\"\n"); + builder.append(" }\n"); + builder.append(" ],\n"); + builder.append(" \"Version\": \"2012-10-17\"\n"); + builder.append("}\n"); + policyConfig = builder.toString(); + } else { + s_logger.debug("Setting private policy on bucket " + bucket.getName()); + policyConfig = "{\"Version\":\"2012-10-17\",\"Statement\":[]}"; + } + + AmazonS3 client = getS3Client(getStoreURL(storeId), bucket.getAccessKey(), bucket.getAccessKey()); + client.setBucketPolicy(new SetBucketPolicyRequest(bucket.getName(), policyConfig)); + } + + @Override + public BucketPolicy getBucketPolicy(BucketTO bucket, long storeId) { + AmazonS3 client = getS3Client(getStoreURL(storeId), bucket.getAccessKey(), bucket.getAccessKey()); + return client.getBucketPolicy(new GetBucketPolicyRequest(bucket.getName())); + } + + @Override + public void deleteBucketPolicy(BucketTO bucket, long storeId) { + AmazonS3 client = getS3Client(getStoreURL(storeId), bucket.getAccessKey(), bucket.getAccessKey()); + client.deleteBucketPolicy(new DeleteBucketPolicyRequest(bucket.getName())); + } + + @Override + public boolean createUser(long accountId, long storeId) { + Account account = _accountDao.findById(accountId); + RgwAdmin rgwAdmin = getRgwAdminClient(storeId); + String username = account.getUuid(); + + s_logger.debug("Attempting to create Ceph RGW user for account " + account.getAccountName() + " with UUID " + username); + try { + Optional user = rgwAdmin.getUserInfo(username); + if (user.isPresent()) { + s_logger.info("User already exists in Ceph RGW: " + username); + return true; + } + } catch (Exception e) { + s_logger.debug("User does not exist. Creating user in Ceph RGW: " + username); + } + + try { + rgwAdmin.createUser(username); + User newUser = rgwAdmin.getUserInfo(username).get(); + S3Credential credentials = newUser.getS3Credentials().get(0); + + Map details = new HashMap<>(); + details.put(CEPH_ACCESS_KEY, credentials.getAccessKey()); + details.put(CEPH_SECRET_KEY, credentials.getSecretKey()); + _accountDetailsDao.persist(accountId, details); + return true; + } catch (Exception e) { + throw new CloudRuntimeException(e); + } + } + + @Override + public boolean setBucketEncryption(BucketTO bucket, long storeId) { + return false; + } + + @Override + public boolean deleteBucketEncryption(BucketTO bucket, long storeId) { + return false; + } + + @Override + public boolean setBucketVersioning(BucketTO bucket, long storeId) { + AmazonS3 client = getS3Client(getStoreURL(storeId), bucket.getAccessKey(), bucket.getAccessKey()); + try { + BucketVersioningConfiguration configuration = + new BucketVersioningConfiguration().withStatus("Enabled"); + + SetBucketVersioningConfigurationRequest setBucketVersioningConfigurationRequest = + new SetBucketVersioningConfigurationRequest(bucket.getName(), configuration); + + client.setBucketVersioningConfiguration(setBucketVersioningConfigurationRequest); + return true; + } catch (AmazonS3Exception e) { + throw new CloudRuntimeException(e); + } + } + + @Override + public boolean deleteBucketVersioning(BucketTO bucket, long storeId) { + AmazonS3 client = getS3Client(getStoreURL(storeId), bucket.getAccessKey(), bucket.getAccessKey()); + try { + BucketVersioningConfiguration configuration = + new BucketVersioningConfiguration().withStatus("Suspended"); + + SetBucketVersioningConfigurationRequest setBucketVersioningConfigurationRequest = + new SetBucketVersioningConfigurationRequest(bucket.getName(), configuration); + + client.setBucketVersioningConfiguration(setBucketVersioningConfigurationRequest); + return true; + } catch (AmazonS3Exception e) { + throw new CloudRuntimeException(e); + } + } + + @Override + public void setBucketQuota(BucketTO bucket, long storeId, long size) { + RgwAdmin rgwAdmin = getRgwAdminClient(storeId); + + try { + rgwAdmin.setBucketQuota(bucket.getName(), -1, size); + } catch (Exception e) { + throw new CloudRuntimeException(e); + } + } + + @Override + public Map getAllBucketsUsage(long storeId) { + RgwAdmin rgwAdmin = getRgwAdminClient(storeId); + try { + List bucketinfo = rgwAdmin.listBucketInfo(); + Map bucketsusage = new HashMap(); + for (BucketInfo bucket: bucketinfo) { + BucketInfo.Usage usage = bucket.getUsage(); + bucketsusage.put(bucket.getBucket(), usage.getRgwMain().getSize_kb()); + } + return bucketsusage; + } catch (Exception e) { + throw new CloudRuntimeException(e); + } + } + + protected RgwAdmin getRgwAdminClient(long storeId) { + ObjectStoreVO store = _storeDao.findById(storeId); + Map storeDetails = _storeDetailsDao.getDetails(storeId); + String url = store.getUrl(); + String accessKey = storeDetails.get(ACCESS_KEY); + String secretKey = storeDetails.get(SECRET_KEY); + RgwAdmin admin = new RgwAdminBuilder() + .accessKey(accessKey) + .secretKey(secretKey) + .endpoint(url + "/admin") + .build(); + if (admin == null) { + throw new CloudRuntimeException("Error while creating Ceph RGW client"); + } + return admin; + } + + private String getStoreURL(long storeId) { + ObjectStoreVO store = _storeDao.findById(storeId); + String url = store.getUrl(); + return url; + } + + protected AmazonS3 getS3Client(long storeId, long accountId) { + String url = getStoreURL(storeId); + String accessKey = _accountDetailsDao.findDetail(accountId, CEPH_ACCESS_KEY).getValue(); + String secretKey = _accountDetailsDao.findDetail(accountId, CEPH_SECRET_KEY).getValue(); + return this.getS3Client(url, accessKey, secretKey); + } + protected AmazonS3 getS3Client(String url, String accessKey, String secretKey) { + AmazonS3 client = AmazonS3ClientBuilder.standard() + .enablePathStyleAccess() + .withCredentials( + new AWSStaticCredentialsProvider( + new BasicAWSCredentials(accessKey, secretKey))) + .withEndpointConfiguration( + new AwsClientBuilder.EndpointConfiguration(url, "auto")) + .build(); + + if (client == null) { + throw new CloudRuntimeException("Error while creating Ceph RGW S3 client"); + } + return client; + } +} diff --git a/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CephObjectStoreLifeCycleImpl.java b/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CephObjectStoreLifeCycleImpl.java new file mode 100644 index 000000000000..a9b13bf338eb --- /dev/null +++ b/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CephObjectStoreLifeCycleImpl.java @@ -0,0 +1,133 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.datastore.lifecycle; + +import com.cloud.agent.api.StoragePoolInfo; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; +import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; +import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; +import org.apache.cloudstack.storage.object.datastore.ObjectStoreHelper; +import org.apache.cloudstack.storage.object.datastore.ObjectStoreProviderManager; +import org.apache.cloudstack.storage.object.store.lifecycle.ObjectStoreLifeCycle; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.twonote.rgwadmin4j.RgwAdmin; +import org.twonote.rgwadmin4j.RgwAdminBuilder; + +import javax.inject.Inject; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CephObjectStoreLifeCycleImpl implements ObjectStoreLifeCycle { + + private static final Logger s_logger = LogManager.getLogger(CephObjectStoreLifeCycleImpl.class); + + @Inject + ObjectStoreHelper objectStoreHelper; + @Inject + ObjectStoreProviderManager objectStoreMgr; + + public CephObjectStoreLifeCycleImpl() { + } + + @SuppressWarnings("unchecked") + @Override + public DataStore initialize(Map dsInfos) { + String url = (String)dsInfos.get("url"); + String name = (String)dsInfos.get("name"); + String providerName = (String)dsInfos.get("providerName"); + Map details = (Map)dsInfos.get("details"); + if (details == null) { + throw new CloudRuntimeException("Ceph RGW Admin credentials are missing"); + } + + String accessKey = details.get("accesskey"); + String secretKey = details.get("secretkey"); + + + Map objectStoreParameters = new HashMap(); + objectStoreParameters.put("name", name); + objectStoreParameters.put("url", url); + + objectStoreParameters.put("providerName", providerName); + objectStoreParameters.put("accesskey", accessKey); + objectStoreParameters.put("secretkey", secretKey); + + s_logger.info("Attempting to connect to Ceph RGW at " + url + " with access key " + accessKey); + + RgwAdmin rgwAdmin = new RgwAdminBuilder() + .accessKey(accessKey) + .secretKey(secretKey) + .endpoint(url + "/admin") + .build(); + try { + List buckets = rgwAdmin.listBucket(); + s_logger.debug("Found " + buckets + " buckets at Ceph RGW: " + url); + s_logger.info("Successfully connected to Ceph RGW: " + url); + } catch (Exception e) { + s_logger.debug("Error while initializing Ceph RGW Object Store: " + e.getMessage()); + throw new RuntimeException("Error while initializing Ceph RGW Object Store. Invalid credentials or URL"); + } + + ObjectStoreVO objectStore = objectStoreHelper.createObjectStore(objectStoreParameters, details); + return objectStoreMgr.getObjectStore(objectStore.getId()); + } + + @Override + public boolean attachCluster(DataStore store, ClusterScope scope) { + return false; + } + + @Override + public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { + return false; + } + + @Override + public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { + return false; + } + + @Override + public boolean maintain(DataStore store) { + return false; + } + + @Override + public boolean cancelMaintain(DataStore store) { + return false; + } + + @Override + public boolean deleteDataStore(DataStore store) { + return false; + } + + /* (non-Javadoc) + * @see org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle#migrateToObjectStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) + */ + @Override + public boolean migrateToObjectStore(DataStore store) { + return false; + } + +} diff --git a/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/provider/CephObjectStoreProviderImpl.java b/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/provider/CephObjectStoreProviderImpl.java new file mode 100644 index 000000000000..e4b0eda42e85 --- /dev/null +++ b/plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/provider/CephObjectStoreProviderImpl.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.provider; + +import com.cloud.utils.component.ComponentContext; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; +import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; +import org.apache.cloudstack.engine.subsystem.api.storage.ObjectStoreProvider; +import org.apache.cloudstack.storage.datastore.driver.CephObjectStoreDriverImpl; +import org.apache.cloudstack.storage.datastore.lifecycle.CephObjectStoreLifeCycleImpl; +import org.apache.cloudstack.storage.object.ObjectStoreDriver; +import org.apache.cloudstack.storage.object.datastore.ObjectStoreHelper; +import org.apache.cloudstack.storage.object.datastore.ObjectStoreProviderManager; +import org.apache.cloudstack.storage.object.store.lifecycle.ObjectStoreLifeCycle; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Component +public class CephObjectStoreProviderImpl implements ObjectStoreProvider { + + @Inject + ObjectStoreProviderManager storeMgr; + @Inject + ObjectStoreHelper helper; + + private final String providerName = "Ceph"; + protected ObjectStoreLifeCycle lifeCycle; + protected ObjectStoreDriver driver; + + @Override + public DataStoreLifeCycle getDataStoreLifeCycle() { + return lifeCycle; + } + + @Override + public String getName() { + return this.providerName; + } + + @Override + public boolean configure(Map params) { + lifeCycle = ComponentContext.inject(CephObjectStoreLifeCycleImpl.class); + driver = ComponentContext.inject(CephObjectStoreDriverImpl.class); + storeMgr.registerDriver(this.getName(), driver); + return true; + } + + @Override + public DataStoreDriver getDataStoreDriver() { + return this.driver; + } + + @Override + public HypervisorHostListener getHostListener() { + return null; + } + + @Override + public Set getTypes() { + Set types = new HashSet(); + types.add(DataStoreProviderType.OBJECT); + return types; + } +} diff --git a/plugins/storage/object/ceph/src/main/resources/META-INF/cloudstack/storage-object-ceph/module.properties b/plugins/storage/object/ceph/src/main/resources/META-INF/cloudstack/storage-object-ceph/module.properties new file mode 100644 index 000000000000..2aa3f3e2fa27 --- /dev/null +++ b/plugins/storage/object/ceph/src/main/resources/META-INF/cloudstack/storage-object-ceph/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=storage-object-ceph +parent=storage diff --git a/plugins/storage/object/ceph/src/main/resources/META-INF/cloudstack/storage-object-ceph/spring-storage-object-ceph-context.xml b/plugins/storage/object/ceph/src/main/resources/META-INF/cloudstack/storage-object-ceph/spring-storage-object-ceph-context.xml new file mode 100644 index 000000000000..c31e652758c3 --- /dev/null +++ b/plugins/storage/object/ceph/src/main/resources/META-INF/cloudstack/storage-object-ceph/spring-storage-object-ceph-context.xml @@ -0,0 +1,31 @@ + + + + diff --git a/plugins/storage/object/ceph/src/test/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImplTest.java b/plugins/storage/object/ceph/src/test/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImplTest.java new file mode 100644 index 000000000000..d0cd2e86a224 --- /dev/null +++ b/plugins/storage/object/ceph/src/test/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImplTest.java @@ -0,0 +1,112 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.datastore.driver; + +import com.amazonaws.services.s3.AmazonS3; +import com.cloud.agent.api.to.BucketTO; +import com.cloud.storage.BucketVO; +import com.cloud.storage.dao.BucketDao; +import com.cloud.user.AccountDetailVO; +import com.cloud.user.AccountDetailsDao; +import com.cloud.user.AccountVO; +import com.cloud.user.dao.AccountDao; +import org.apache.cloudstack.storage.datastore.db.ObjectStoreDao; +import org.apache.cloudstack.storage.datastore.db.ObjectStoreDetailsDao; +import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; +import org.apache.cloudstack.storage.object.Bucket; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.twonote.rgwadmin4j.RgwAdmin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyLong; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class CephObjectStoreDriverImplTest { + + @Spy + CephObjectStoreDriverImpl cephObjectStoreDriverImpl = new CephObjectStoreDriverImpl(); + + @Mock + AmazonS3 rgwClient; + @Mock + RgwAdmin rgwAdmin; + @Mock + ObjectStoreDao objectStoreDao; + @Mock + ObjectStoreVO objectStoreVO; + @Mock + ObjectStoreDetailsDao objectStoreDetailsDao; + @Mock + AccountDao accountDao; + @Mock + BucketDao bucketDao; + @Mock + AccountVO account; + @Mock + AccountDetailsDao accountDetailsDao; + + Bucket bucket; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + cephObjectStoreDriverImpl._storeDao = objectStoreDao; + cephObjectStoreDriverImpl._storeDetailsDao = objectStoreDetailsDao; + cephObjectStoreDriverImpl._accountDao = accountDao; + cephObjectStoreDriverImpl._bucketDao = bucketDao; + cephObjectStoreDriverImpl._accountDetailsDao = accountDetailsDao; + bucket = new BucketVO(); + bucket.setName("test-bucket"); + when(objectStoreVO.getUrl()).thenReturn("http://localhost:8000"); + when(objectStoreDao.findById(any())).thenReturn(objectStoreVO); + } + + @Test + public void testCreateBucket() throws Exception { + doReturn(rgwClient).when(cephObjectStoreDriverImpl).getS3Client(anyLong(), anyLong()); + when(accountDetailsDao.findDetail(anyLong(),anyString())). + thenReturn(new AccountDetailVO(1L, "abc","def")); + when(bucketDao.findById(anyLong())).thenReturn(new BucketVO(bucket.getName())); + Bucket bucketRet = cephObjectStoreDriverImpl.createBucket(bucket, false); + assertEquals(bucketRet.getName(), bucket.getName()); + verify(rgwClient, times(1)).getBucketAcl(anyString()); + verify(rgwClient, times(1)).createBucket(anyString()); + } + + @Test + public void testDeleteBucket() throws Exception { + String bucketName = "test-bucket"; + BucketTO bucket = new BucketTO(bucketName); + doReturn(rgwAdmin).when(cephObjectStoreDriverImpl).getRgwAdminClient(anyLong()); + boolean success = cephObjectStoreDriverImpl.deleteBucket(bucket, 1L); + assertTrue(success); + verify(rgwAdmin, times(1)).removeBucket(anyString()); + } +} diff --git a/plugins/storage/object/ceph/src/test/java/org/apache/cloudstack/storage/datastore/provider/CephObjectStoreProviderImplTest.java b/plugins/storage/object/ceph/src/test/java/org/apache/cloudstack/storage/datastore/provider/CephObjectStoreProviderImplTest.java new file mode 100644 index 000000000000..8b17f52668b6 --- /dev/null +++ b/plugins/storage/object/ceph/src/test/java/org/apache/cloudstack/storage/datastore/provider/CephObjectStoreProviderImplTest.java @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.storage.datastore.provider; + +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.DataStoreProviderType; +import org.junit.Before; +import org.junit.Test; +import org.mockito.MockitoAnnotations; + +import java.util.Set; + +import static org.junit.Assert.assertEquals; + +public class CephObjectStoreProviderImplTest { + + private CephObjectStoreProviderImpl cephObjectStoreProviderImpl; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + cephObjectStoreProviderImpl = new CephObjectStoreProviderImpl(); + } + + @Test + public void testGetName() { + String name = cephObjectStoreProviderImpl.getName(); + assertEquals("Ceph", name); + } + + @Test + public void testGetTypes() { + Set types = cephObjectStoreProviderImpl.getTypes(); + assertEquals(1, types.size()); + assertEquals("OBJECT", types.toArray()[0].toString()); + } +} diff --git a/plugins/storage/object/minio/pom.xml b/plugins/storage/object/minio/pom.xml index f190252e6009..6358ee590e52 100644 --- a/plugins/storage/object/minio/pom.xml +++ b/plugins/storage/object/minio/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImpl.java b/plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImpl.java index b85383a65e83..9dc4b30414e6 100644 --- a/plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImpl.java +++ b/plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImpl.java @@ -38,10 +38,10 @@ import org.apache.cloudstack.storage.object.BucketObject; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.amazonaws.services.s3.model.AccessControlList; import com.amazonaws.services.s3.model.BucketPolicy; +import com.cloud.agent.api.to.BucketTO; import com.cloud.agent.api.to.DataStoreTO; import com.cloud.storage.BucketVO; import com.cloud.storage.dao.BucketDao; @@ -66,7 +66,6 @@ import io.minio.messages.VersioningConfiguration; public class MinIOObjectStoreDriverImpl extends BaseObjectStoreDriverImpl { - private static final Logger s_logger = Logger.getLogger(MinIOObjectStoreDriverImpl.class); protected static final String ACS_PREFIX = "acs"; @Inject @@ -182,7 +181,8 @@ public List listBuckets(long storeId) { } @Override - public boolean deleteBucket(String bucketName, long storeId) { + public boolean deleteBucket(BucketTO bucket, long storeId) { + String bucketName = bucket.getName(); MinioClient minioClient = getMinIOClient(storeId); try { if(!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) { @@ -201,17 +201,18 @@ public boolean deleteBucket(String bucketName, long storeId) { } @Override - public AccessControlList getBucketAcl(String bucketName, long storeId) { + public AccessControlList getBucketAcl(BucketTO bucket, long storeId) { return null; } @Override - public void setBucketAcl(String bucketName, AccessControlList acl, long storeId) { + public void setBucketAcl(BucketTO bucket, AccessControlList acl, long storeId) { } @Override - public void setBucketPolicy(String bucketName, String policy, long storeId) { + public void setBucketPolicy(BucketTO bucket, String policy, long storeId) { + String bucketName = bucket.getName(); String privatePolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[]}"; StringBuilder builder = new StringBuilder(); @@ -251,12 +252,12 @@ public void setBucketPolicy(String bucketName, String policy, long storeId) { } @Override - public BucketPolicy getBucketPolicy(String bucketName, long storeId) { + public BucketPolicy getBucketPolicy(BucketTO bucket, long storeId) { return null; } @Override - public void deleteBucketPolicy(String bucketName, long storeId) { + public void deleteBucketPolicy(BucketTO bucket, long storeId) { } @@ -268,7 +269,7 @@ protected void updateAccountCredentials(final long accountId, final String acces updateNeeded = true; } if (StringUtils.isAllBlank(secretKey, details.get(MINIO_SECRET_KEY))) { - s_logger.error(String.format("Failed to retrieve secret key for MinIO user: %s from store and account details", accessKey)); + logger.error(String.format("Failed to retrieve secret key for MinIO user: %s from store and account details", accessKey)); } if (StringUtils.isNotBlank(secretKey) && (!checkIfNotPresent || StringUtils.isBlank(details.get(MINIO_SECRET_KEY)))) { details.put(MINIO_SECRET_KEY, secretKey); @@ -289,23 +290,23 @@ public boolean createUser(long accountId, long storeId) { try { UserInfo userInfo = minioAdminClient.getUserInfo(accessKey); if(userInfo != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Skipping user creation as the user already exists in MinIO store: %s", accessKey)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Skipping user creation as the user already exists in MinIO store: %s", accessKey)); } updateAccountCredentials(accountId, accessKey, userInfo.secretKey(), true); return true; } } catch (NoSuchAlgorithmException | IOException | InvalidKeyException e) { - s_logger.error(String.format("Error encountered while retrieving user: %s for existing MinIO store user check", accessKey), e); + logger.error(String.format("Error encountered while retrieving user: %s for existing MinIO store user check", accessKey), e); return false; } catch (RuntimeException e) { // MinIO lib may throw RuntimeException with code: XMinioAdminNoSuchUser - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Ignoring error encountered while retrieving user: %s for existing MinIO store user check", accessKey)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Ignoring error encountered while retrieving user: %s for existing MinIO store user check", accessKey)); } - s_logger.trace("Exception during MinIO user check", e); + logger.trace("Exception during MinIO user check", e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("MinIO store user does not exist. Creating user: %s", accessKey)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("MinIO store user does not exist. Creating user: %s", accessKey)); } KeyGenerator generator = null; try { @@ -326,11 +327,11 @@ public boolean createUser(long accountId, long storeId) { } @Override - public boolean setBucketEncryption(String bucketName, long storeId) { + public boolean setBucketEncryption(BucketTO bucket, long storeId) { MinioClient minioClient = getMinIOClient(storeId); try { minioClient.setBucketEncryption(SetBucketEncryptionArgs.builder() - .bucket(bucketName) + .bucket(bucket.getName()) .config(SseConfiguration.newConfigWithSseS3Rule()) .build() ); @@ -341,11 +342,11 @@ public boolean setBucketEncryption(String bucketName, long storeId) { } @Override - public boolean deleteBucketEncryption(String bucketName, long storeId) { + public boolean deleteBucketEncryption(BucketTO bucket, long storeId) { MinioClient minioClient = getMinIOClient(storeId); try { minioClient.deleteBucketEncryption(DeleteBucketEncryptionArgs.builder() - .bucket(bucketName) + .bucket(bucket.getName()) .build() ); } catch (Exception e) { @@ -355,11 +356,11 @@ public boolean deleteBucketEncryption(String bucketName, long storeId) { } @Override - public boolean setBucketVersioning(String bucketName, long storeId) { + public boolean setBucketVersioning(BucketTO bucket, long storeId) { MinioClient minioClient = getMinIOClient(storeId); try { minioClient.setBucketVersioning(SetBucketVersioningArgs.builder() - .bucket(bucketName) + .bucket(bucket.getName()) .config(new VersioningConfiguration(VersioningConfiguration.Status.ENABLED, null)) .build() ); @@ -370,11 +371,11 @@ public boolean setBucketVersioning(String bucketName, long storeId) { } @Override - public boolean deleteBucketVersioning(String bucketName, long storeId) { + public boolean deleteBucketVersioning(BucketTO bucket, long storeId) { MinioClient minioClient = getMinIOClient(storeId); try { minioClient.setBucketVersioning(SetBucketVersioningArgs.builder() - .bucket(bucketName) + .bucket(bucket.getName()) .config(new VersioningConfiguration(VersioningConfiguration.Status.SUSPENDED, null)) .build() ); @@ -385,11 +386,11 @@ public boolean deleteBucketVersioning(String bucketName, long storeId) { } @Override - public void setBucketQuota(String bucketName, long storeId, long size) { + public void setBucketQuota(BucketTO bucket, long storeId, long size) { MinioAdminClient minioAdminClient = getMinIOAdminClient(storeId); try { - minioAdminClient.setBucketQuota(bucketName, size, QuotaUnit.GB); + minioAdminClient.setBucketQuota(bucket.getName(), size, QuotaUnit.GB); } catch (Exception e) { throw new CloudRuntimeException(e); } diff --git a/plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/MinIOObjectStoreLifeCycleImpl.java b/plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/MinIOObjectStoreLifeCycleImpl.java index fb7d1a652fcb..9d620b32b544 100644 --- a/plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/MinIOObjectStoreLifeCycleImpl.java +++ b/plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/MinIOObjectStoreLifeCycleImpl.java @@ -28,7 +28,8 @@ import org.apache.cloudstack.storage.object.datastore.ObjectStoreHelper; import org.apache.cloudstack.storage.object.datastore.ObjectStoreProviderManager; import org.apache.cloudstack.storage.object.store.lifecycle.ObjectStoreLifeCycle; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.inject.Inject; import java.util.HashMap; @@ -36,7 +37,7 @@ public class MinIOObjectStoreLifeCycleImpl implements ObjectStoreLifeCycle { - private static final Logger s_logger = Logger.getLogger(MinIOObjectStoreLifeCycleImpl.class); + protected Logger logger = LogManager.getLogger(MinIOObjectStoreLifeCycleImpl.class); @Inject ObjectStoreHelper objectStoreHelper; @@ -78,9 +79,9 @@ public DataStore initialize(Map dsInfos) { try { // Test connection by listing buckets minioClient.listBuckets(); - s_logger.debug("Successfully connected to MinIO EndPoint: "+url); + logger.debug("Successfully connected to MinIO EndPoint: "+url); } catch (Exception e) { - s_logger.debug("Error while initializing MinIO Object Store: "+e.getMessage()); + logger.debug("Error while initializing MinIO Object Store: "+e.getMessage()); throw new RuntimeException("Error while initializing MinIO Object Store. Invalid credentials or URL"); } diff --git a/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java b/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java index ac88a0ded398..1a8b3d9663a2 100644 --- a/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java +++ b/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java @@ -37,6 +37,8 @@ import org.apache.cloudstack.storage.datastore.db.ObjectStoreDetailsDao; import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; import org.apache.cloudstack.storage.object.Bucket; +import com.cloud.agent.api.to.BucketTO; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -87,9 +89,11 @@ public class MinIOObjectStoreDriverImplTest { Bucket bucket; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); minioObjectStoreDriverImpl._storeDao = objectStoreDao; minioObjectStoreDriverImpl._storeDetailsDao = objectStoreDetailsDao; minioObjectStoreDriverImpl._accountDao = accountDao; @@ -101,6 +105,11 @@ public void setUp() { when(objectStoreDao.findById(any())).thenReturn(objectStoreVO); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testCreateBucket() throws Exception { doReturn(minioClient).when(minioObjectStoreDriverImpl).getMinIOClient(anyLong()); @@ -120,10 +129,11 @@ public void testCreateBucket() throws Exception { @Test public void testDeleteBucket() throws Exception { String bucketName = "test-bucket"; + BucketTO bucket = new BucketTO(bucketName); doReturn(minioClient).when(minioObjectStoreDriverImpl).getMinIOClient(anyLong()); when(minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())).thenReturn(true); doNothing().when(minioClient).removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); - boolean success = minioObjectStoreDriverImpl.deleteBucket(bucketName, 1L); + boolean success = minioObjectStoreDriverImpl.deleteBucket(bucket, 1L); assertTrue(success); verify(minioClient, times(1)).bucketExists(any()); verify(minioClient, times(1)).removeBucket(any()); diff --git a/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/provider/MinIOObjectStoreProviderImplTest.java b/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/provider/MinIOObjectStoreProviderImplTest.java index 8651e00b6ad5..ba7ed270413b 100644 --- a/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/provider/MinIOObjectStoreProviderImplTest.java +++ b/plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/provider/MinIOObjectStoreProviderImplTest.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.storage.datastore.provider; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.DataStoreProviderType; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.MockitoAnnotations; @@ -29,12 +30,19 @@ public class MinIOObjectStoreProviderImplTest { private MinIOObjectStoreProviderImpl minioObjectStoreProviderImpl; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); minioObjectStoreProviderImpl = new MinIOObjectStoreProviderImpl(); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testGetName() { String name = minioObjectStoreProviderImpl.getName(); diff --git a/plugins/storage/object/simulator/pom.xml b/plugins/storage/object/simulator/pom.xml index b69f346c4b69..803a03dba639 100644 --- a/plugins/storage/object/simulator/pom.xml +++ b/plugins/storage/object/simulator/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/object/simulator/src/main/java/org/apache/cloudstack/storage/datastore/driver/SimulatorObjectStoreDriverImpl.java b/plugins/storage/object/simulator/src/main/java/org/apache/cloudstack/storage/datastore/driver/SimulatorObjectStoreDriverImpl.java index 5f25a6061a77..7b9ac59d5b1e 100644 --- a/plugins/storage/object/simulator/src/main/java/org/apache/cloudstack/storage/datastore/driver/SimulatorObjectStoreDriverImpl.java +++ b/plugins/storage/object/simulator/src/main/java/org/apache/cloudstack/storage/datastore/driver/SimulatorObjectStoreDriverImpl.java @@ -20,6 +20,7 @@ import com.amazonaws.services.s3.model.AccessControlList; import com.amazonaws.services.s3.model.BucketPolicy; +import com.cloud.agent.api.to.BucketTO; import com.cloud.agent.api.to.DataStoreTO; import org.apache.cloudstack.storage.object.Bucket; import com.cloud.storage.BucketVO; @@ -28,7 +29,6 @@ import org.apache.cloudstack.storage.datastore.db.ObjectStoreDao; import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; import org.apache.cloudstack.storage.object.BaseObjectStoreDriverImpl; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -37,7 +37,6 @@ import java.util.Map; public class SimulatorObjectStoreDriverImpl extends BaseObjectStoreDriverImpl { - private static final Logger s_logger = Logger.getLogger(SimulatorObjectStoreDriverImpl.class); @Inject ObjectStoreDao _storeDao; @@ -73,32 +72,32 @@ public List listBuckets(long storeId) { } @Override - public boolean deleteBucket(String bucketName, long storeId) { + public boolean deleteBucket(BucketTO bucket, long storeId) { return true; } @Override - public AccessControlList getBucketAcl(String bucketName, long storeId) { + public AccessControlList getBucketAcl(BucketTO bucket, long storeId) { return null; } @Override - public void setBucketAcl(String bucketName, AccessControlList acl, long storeId) { + public void setBucketAcl(BucketTO bucket, AccessControlList acl, long storeId) { } @Override - public void setBucketPolicy(String bucketName, String policy, long storeId) { + public void setBucketPolicy(BucketTO bucket, String policy, long storeId) { } @Override - public BucketPolicy getBucketPolicy(String bucketName, long storeId) { + public BucketPolicy getBucketPolicy(BucketTO bucket, long storeId) { return null; } @Override - public void deleteBucketPolicy(String bucketName, long storeId) { + public void deleteBucketPolicy(BucketTO bucket, long storeId) { } @@ -108,27 +107,27 @@ public boolean createUser(long accountId, long storeId) { } @Override - public boolean setBucketEncryption(String bucketName, long storeId) { + public boolean setBucketEncryption(BucketTO bucket, long storeId) { return true; } @Override - public boolean deleteBucketEncryption(String bucketName, long storeId) { + public boolean deleteBucketEncryption(BucketTO bucket, long storeId) { return true; } @Override - public boolean setBucketVersioning(String bucketName, long storeId) { + public boolean setBucketVersioning(BucketTO bucket, long storeId) { return true; } @Override - public boolean deleteBucketVersioning(String bucketName, long storeId) { + public boolean deleteBucketVersioning(BucketTO bucket, long storeId) { return true; } @Override - public void setBucketQuota(String bucketName, long storeId, long size) { + public void setBucketQuota(BucketTO bucket, long storeId, long size) { } diff --git a/plugins/storage/object/simulator/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SimulatorObjectStoreLifeCycleImpl.java b/plugins/storage/object/simulator/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SimulatorObjectStoreLifeCycleImpl.java index 34e928ced30d..6ceed041e8df 100644 --- a/plugins/storage/object/simulator/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SimulatorObjectStoreLifeCycleImpl.java +++ b/plugins/storage/object/simulator/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SimulatorObjectStoreLifeCycleImpl.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.storage.object.datastore.ObjectStoreHelper; import org.apache.cloudstack.storage.object.datastore.ObjectStoreProviderManager; import org.apache.cloudstack.storage.object.store.lifecycle.ObjectStoreLifeCycle; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.HashMap; @@ -37,8 +36,6 @@ import java.util.Map; public class SimulatorObjectStoreLifeCycleImpl implements ObjectStoreLifeCycle { - - private static final Logger s_logger = Logger.getLogger(SimulatorObjectStoreLifeCycleImpl.class); @Inject protected ResourceManager _resourceMgr; @Inject diff --git a/plugins/storage/object/simulator/src/test/java/org/apache/cloudstack/storage/datastore/provider/SimulatorObjectStoreProviderImplTest.java b/plugins/storage/object/simulator/src/test/java/org/apache/cloudstack/storage/datastore/provider/SimulatorObjectStoreProviderImplTest.java index 57c7eee5cfb2..b6e56925dc54 100644 --- a/plugins/storage/object/simulator/src/test/java/org/apache/cloudstack/storage/datastore/provider/SimulatorObjectStoreProviderImplTest.java +++ b/plugins/storage/object/simulator/src/test/java/org/apache/cloudstack/storage/datastore/provider/SimulatorObjectStoreProviderImplTest.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.storage.datastore.provider; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.MockitoAnnotations; @@ -29,12 +30,19 @@ public class SimulatorObjectStoreProviderImplTest { private SimulatorObjectStoreProviderImpl simulatorObjectStoreProviderImpl; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); simulatorObjectStoreProviderImpl = new SimulatorObjectStoreProviderImpl(); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testGetName() { String name = simulatorObjectStoreProviderImpl.getName(); diff --git a/plugins/storage/sharedfs/storagevm/pom.xml b/plugins/storage/sharedfs/storagevm/pom.xml new file mode 100644 index 000000000000..200663b0d505 --- /dev/null +++ b/plugins/storage/sharedfs/storagevm/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + cloud-plugin-sharedfs-provider-storagevm + Apache CloudStack Plugin - StorageVm shared filesystem provider + + org.apache.cloudstack + cloudstack-plugins + 4.20.0.0-SNAPSHOT + ../../../pom.xml + + diff --git a/plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycle.java b/plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycle.java new file mode 100644 index 000000000000..31159e7d3d95 --- /dev/null +++ b/plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycle.java @@ -0,0 +1,303 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.storage.sharedfs.lifecycle; + +import static org.apache.cloudstack.storage.sharedfs.SharedFS.SharedFSPath; +import static org.apache.cloudstack.storage.sharedfs.SharedFS.SharedFSVmNamePrefix; +import static org.apache.cloudstack.storage.sharedfs.provider.StorageVmSharedFSProvider.SHAREDFSVM_MIN_CPU_COUNT; +import static org.apache.cloudstack.storage.sharedfs.provider.StorageVmSharedFSProvider.SHAREDFSVM_MIN_RAM_SIZE; + +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ManagementServerException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.VirtualMachineMigrationException; +import com.cloud.offering.ServiceOffering; +import com.cloud.storage.LaunchPermissionVO; +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeApiService; +import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.LaunchPermissionDao; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.uservm.UserVm; +import com.cloud.utils.FileUtil; +import com.cloud.utils.Pair; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.utils.net.NetUtils; +import com.cloud.vm.UserVmManager; +import com.cloud.vm.UserVmService; +import com.cloud.vm.UserVmVO; +import com.cloud.vm.dao.NicDao; +import com.cloud.vm.dao.UserVmDao; + +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSLifeCycle; +import org.apache.commons.codec.binary.Base64; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.cloud.dc.DataCenter; +import com.cloud.hypervisor.Hypervisor; +import com.cloud.network.Network; +import com.cloud.resource.ResourceManager; +import com.cloud.service.dao.ServiceOfferingDao; +import com.cloud.storage.VMTemplateVO; +import com.cloud.storage.dao.VMTemplateDao; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.VirtualMachineManager; + +public class StorageVmSharedFSLifeCycle implements SharedFSLifeCycle { + protected Logger logger = LogManager.getLogger(getClass()); + + @Inject + private AccountManager accountMgr; + + @Inject + protected ResourceManager resourceMgr; + + @Inject + private VirtualMachineManager virtualMachineManager; + + @Inject + private VolumeApiService volumeApiService; + + @Inject + protected UserVmService userVmService; + + @Inject + protected UserVmManager userVmManager; + + @Inject + private DataCenterDao dataCenterDao; + + @Inject + private VMTemplateDao templateDao; + + @Inject + VolumeDao volumeDao; + + @Inject + private UserVmDao userVmDao; + + @Inject + NicDao nicDao; + + @Inject + ServiceOfferingDao serviceOfferingDao; + + @Inject + protected LaunchPermissionDao launchPermissionDao; + + private String readResourceFile(String resource) { + try { + return FileUtil.readResourceFile(resource); + } catch (IOException e) { + throw new CloudRuntimeException("Unable to read the user data resource file due to exception " + e.getMessage()); + } + } + + private String getStorageVmConfig(final String fileSystem, final String hypervisorType, final String exportPath) { + String fsVmConfig = readResourceFile("/conf/fsvm-init.yml"); + final String filesystem = "{{ fsvm.filesystem }}"; + final String hypervisor = "{{ fsvm.hypervisor }}"; + final String exportpath = "{{ fsvm.exportpath }}"; + fsVmConfig = fsVmConfig.replace(filesystem, fileSystem); + fsVmConfig = fsVmConfig.replace(hypervisor, hypervisorType); + fsVmConfig = fsVmConfig.replace(exportpath, exportPath); + return fsVmConfig; + } + + private String getStorageVmName(String fileShareName) { + String prefix = String.format("%s-%s", SharedFSVmNamePrefix, fileShareName); + String suffix = Long.toHexString(System.currentTimeMillis()); + + if (!NetUtils.verifyDomainNameLabel(prefix, true)) { + prefix = prefix.replaceAll("[^a-zA-Z0-9-]", ""); + } + int nameLength = prefix.length() + suffix.length() + SharedFSVmNamePrefix.length(); + if (nameLength > 63) { + int prefixLength = prefix.length() - (nameLength - 63); + prefix = prefix.substring(0, prefixLength); + } + return (String.format("%s-%s", prefix, suffix)); + } + + private UserVm deploySharedFSVM(Long zoneId, Account owner, List networkIds, String name, Long serviceOfferingId, Long diskOfferingId, SharedFS.FileSystemType fileSystem, Long size, Long minIops, Long maxIops) throws OperationTimedoutException, ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException { + ServiceOffering serviceOffering = serviceOfferingDao.findById(serviceOfferingId); + DataCenter zone = dataCenterDao.findById(zoneId); + + List hypervisors = resourceMgr.getSupportedHypervisorTypes(zoneId, false, null); + if (hypervisors.size() > 0) { + Collections.shuffle(hypervisors); + } else { + throw new CloudRuntimeException(String.format("No supported hypervisor found for zone %s.", zone.toString())); + } + + String hostName = getStorageVmName(name); + Network.IpAddresses addrs = new Network.IpAddresses(null, null); + Map customParameterMap = new HashMap(); + if (minIops != null) { + customParameterMap.put("minIopsDo", minIops.toString()); + customParameterMap.put("maxIopsDo", maxIops.toString()); + } + List keypairs = new ArrayList(); + + for (final Iterator iter = hypervisors.iterator(); iter.hasNext();) { + final Hypervisor.HypervisorType hypervisor = iter.next(); + VMTemplateVO template = templateDao.findSystemVMReadyTemplate(zoneId, hypervisor); + if (template == null && !iter.hasNext()) { + throw new CloudRuntimeException(String.format("Unable to find the systemvm template for %s or it was not downloaded in %s.", hypervisor.toString(), zone.toString())); + } + + LaunchPermissionVO existingPermission = launchPermissionDao.findByTemplateAndAccount(template.getId(), owner.getId()); + if (existingPermission == null) { + LaunchPermissionVO launchPermission = new LaunchPermissionVO(template.getId(), owner.getId()); + launchPermissionDao.persist(launchPermission); + } + + UserVm vm = null; + String fsVmConfig = getStorageVmConfig(fileSystem.toString().toLowerCase(), hypervisor.toString().toLowerCase(), SharedFSPath); + String base64UserData = Base64.encodeBase64String(fsVmConfig.getBytes(com.cloud.utils.StringUtils.getPreferredCharset())); + CallContext vmContext = CallContext.register(CallContext.current(), ApiCommandResourceType.VirtualMachine); + try { + vm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, networkIds, owner, hostName, hostName, + diskOfferingId, size, null, Hypervisor.HypervisorType.None, BaseCmd.HTTPMethod.POST, base64UserData, + null, null, keypairs, null, addrs, null, null, null, + customParameterMap, null, null, null, null, + true, UserVmManager.SHAREDFSVM, null); + vmContext.setEventResourceId(vm.getId()); + userVmService.startVirtualMachine(vm); + } catch (InsufficientCapacityException ex) { + if (vm != null) { + expungeVm(vm.getId()); + } + if (iter.hasNext()) { + continue; + } else { + throw ex; + } + } finally { + CallContext.unregister(); + } + return vm; + } + return null; + } + + @Override + public void checkPrerequisites(DataCenter zone, Long serviceOfferingId) { + ServiceOffering serviceOffering = serviceOfferingDao.findById(serviceOfferingId); + if (serviceOffering.getCpu() < SHAREDFSVM_MIN_CPU_COUNT.valueIn(zone.getId())) { + throw new InvalidParameterValueException("Service offering's number of cpu should be greater than or equal to " + SHAREDFSVM_MIN_CPU_COUNT.key()); + } + if (serviceOffering.getRamSize() < SHAREDFSVM_MIN_RAM_SIZE.valueIn(zone.getId())) { + throw new InvalidParameterValueException("Service offering's ram size should be greater than or equal to " + SHAREDFSVM_MIN_RAM_SIZE.key()); + } + if (!serviceOffering.isOfferHA()) { + throw new InvalidParameterValueException("Service offering's should be HA enabled"); + } + } + + @Override + public Pair deploySharedFS(SharedFS sharedFS, Long networkId, Long diskOfferingId, Long size, Long minIops, Long maxIops) throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, OperationTimedoutException { + Account owner = accountMgr.getActiveAccountById(sharedFS.getAccountId()); + UserVm vm = deploySharedFSVM(sharedFS.getDataCenterId(), owner, List.of(networkId), sharedFS.getName(), sharedFS.getServiceOfferingId(), diskOfferingId, sharedFS.getFsType(), size, minIops, maxIops); + + List volumes = volumeDao.findByInstanceAndType(vm.getId(), Volume.Type.DATADISK); + return new Pair<>(volumes.get(0).getId(), vm.getId()); + } + + @Override + public void startSharedFS(SharedFS sharedFS) throws OperationTimedoutException, ResourceUnavailableException, InsufficientCapacityException { + UserVmVO vm = userVmDao.findById(sharedFS.getVmId()); + userVmService.startVirtualMachine(vm); + } + + @Override + public boolean stopSharedFS(SharedFS sharedFS, Boolean forced) { + userVmManager.stopVirtualMachine(sharedFS.getVmId(), false); + return true; + } + + private void expungeVm(Long vmId) { + UserVmVO userVM = userVmDao.findById(vmId); + if (userVM == null) { + return; + } + try { + UserVm vm = userVmService.destroyVm(userVM.getId(), true); + if (!userVmManager.expunge(userVM)) { + throw new CloudRuntimeException("Failed to expunge VM " + userVM.toString()); + } + } catch (ResourceUnavailableException e) { + throw new CloudRuntimeException("Failed to expunge VM " + userVM.toString()); + } + userVmDao.remove(vmId); + } + + @Override + public boolean deleteSharedFS(SharedFS sharedFS) { + Long vmId = sharedFS.getVmId(); + Long volumeId = sharedFS.getVolumeId(); + if (vmId != null) { + expungeVm(vmId); + } + + if (volumeId == null) { + return true; + } + VolumeVO volume = volumeDao.findById(volumeId); + Boolean expunge = false; + Boolean forceExpunge = false; + if (volume.getState() == Volume.State.Allocated) { + expunge = true; + forceExpunge = true; + } + volumeApiService.destroyVolume(volume.getId(), CallContext.current().getCallingAccount(), expunge, forceExpunge); + return true; + } + + @Override + public boolean reDeploySharedFS(SharedFS sharedFS) throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, OperationTimedoutException { + UserVm vm = virtualMachineManager.restoreVirtualMachine(sharedFS.getVmId(), null, null, true, null); + return (vm != null); + } + + @Override + public boolean changeSharedFSServiceOffering(SharedFS sharedFS, Long serviceOfferingId) throws ManagementServerException, ResourceUnavailableException, VirtualMachineMigrationException { + return userVmManager.upgradeVirtualMachine(sharedFS.getVmId(), serviceOfferingId, new HashMap()); + } +} diff --git a/plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/provider/StorageVmSharedFSProvider.java b/plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/provider/StorageVmSharedFSProvider.java new file mode 100644 index 000000000000..7f7f5a220131 --- /dev/null +++ b/plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/provider/StorageVmSharedFSProvider.java @@ -0,0 +1,79 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.storage.sharedfs.provider; + +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.apache.cloudstack.storage.sharedfs.SharedFSProvider; +import org.apache.cloudstack.storage.sharedfs.lifecycle.StorageVmSharedFSLifeCycle; + +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.ComponentContext; + +public class StorageVmSharedFSProvider extends AdapterBase implements SharedFSProvider, Configurable { + protected String name = String.valueOf(SharedFSProviderType.SHAREDFSVM); + + public static final ConfigKey SHAREDFSVM_MIN_RAM_SIZE = new ConfigKey("Advanced", + Integer.class, + "sharedfsvm.min.ram.size", + "1024", + "minimum ram size allowed for the compute offering to be used to create the sharedfs vm.", + true, + ConfigKey.Scope.Zone, + SharedFS.SharedFSFeatureEnabled.key()); + + public static final ConfigKey SHAREDFSVM_MIN_CPU_COUNT = new ConfigKey("Advanced", + Integer.class, + "sharedfsvm.min.cpu.count", + "2", + "minimum cpu count allowed for the compute offering to be used to create the sharedfs vm.", + true, + ConfigKey.Scope.Zone, + SharedFS.SharedFSFeatureEnabled.key()); + + protected StorageVmSharedFSLifeCycle lifecycle; + + @Override + public String getName() { + return name; + } + + @Override + public void configure() { + lifecycle = ComponentContext.inject(StorageVmSharedFSLifeCycle.class); + } + + @Override + public StorageVmSharedFSLifeCycle getSharedFSLifeCycle() { + return lifecycle; + } + + @Override + public String getConfigComponentName() { + return StorageVmSharedFSProvider.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] { + SHAREDFSVM_MIN_CPU_COUNT, + SHAREDFSVM_MIN_RAM_SIZE + }; + } +} diff --git a/plugins/storage/sharedfs/storagevm/src/main/resources/META-INF/cloudstack/sharedfs-provider-storagevm/module.properties b/plugins/storage/sharedfs/storagevm/src/main/resources/META-INF/cloudstack/sharedfs-provider-storagevm/module.properties new file mode 100644 index 000000000000..7a0a00262edd --- /dev/null +++ b/plugins/storage/sharedfs/storagevm/src/main/resources/META-INF/cloudstack/sharedfs-provider-storagevm/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=sharedfs-provider-storagevm +parent=storage diff --git a/plugins/storage/sharedfs/storagevm/src/main/resources/META-INF/cloudstack/sharedfs-provider-storagevm/spring-sharedfs-provider-storagevm-context.xml b/plugins/storage/sharedfs/storagevm/src/main/resources/META-INF/cloudstack/sharedfs-provider-storagevm/spring-sharedfs-provider-storagevm-context.xml new file mode 100644 index 000000000000..643b78327fc0 --- /dev/null +++ b/plugins/storage/sharedfs/storagevm/src/main/resources/META-INF/cloudstack/sharedfs-provider-storagevm/spring-sharedfs-provider-storagevm-context.xml @@ -0,0 +1,35 @@ + + + + + + + + diff --git a/plugins/storage/sharedfs/storagevm/src/main/resources/conf/fsvm-init.yml b/plugins/storage/sharedfs/storagevm/src/main/resources/conf/fsvm-init.yml new file mode 100644 index 000000000000..4d3572162c8a --- /dev/null +++ b/plugins/storage/sharedfs/storagevm/src/main/resources/conf/fsvm-init.yml @@ -0,0 +1,220 @@ +#cloud-config +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +--- +write_files: + - path: /usr/local/bin/sharedfs/common + permissions: '0700' + owner: root:root + content: | + #!/bin/bash -e + + LOG_FILE="/var/log/userdata.log" + log() { + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> $LOG_FILE + } + + get_block_device() { + if [ "$HYPERVISOR" == "kvm" ]; then + BLOCK_DEVICE="vdb" + elif [ "$HYPERVISOR" == "xenserver" ]; then + BLOCK_DEVICE="xvdb" + elif [ "$HYPERVISOR" == "vmware" ]; then + BLOCK_DEVICE="sdb" + else + log "Unknown hypervisor" + exit 1 + fi + echo "$BLOCK_DEVICE" + } + + - path: /usr/local/bin/sharedfs/create-shared-filesystem + permissions: '0700' + owner: root:root + content: | + #!/bin/bash -e + + source /usr/local/bin/sharedfs/common + + log "Running add script" + + DISK_SIZE_DIR="/usr/local/var/sharedfs" + DISK_SIZE_FILE="$DISK_SIZE_DIR/previous_disk_size" + + PARTITION="$1" + EXPORT_DIR={{ fsvm.exportpath }} + PERMISSIONS="rw,sync,no_subtree_check,no_root_squash" + + mkdir -p "$EXPORT_DIR" + + FS_TYPE=$(lsblk -no FSTYPE "$PARTITION") + + if [ -z "$FS_TYPE" ]; then + FILESYSTEM={{ fsvm.filesystem }} + if [ "$FILESYSTEM" == "xfs" ]; then + mkfs.xfs "$PARTITION" + log "Formatted Partition $PARTITION with XFS Filesystem." + elif [ "$FILESYSTEM" == "ext4" ]; then + mkfs.ext4 "$PARTITION" + log "Formatted Partition $PARTITION with EXT4 Filesystem." + else + log "Invalid filesystem type specified. Use 'xfs' or 'ext4'." + exit 1 + fi + else + log "Partition $PARTITION already has a filesystem of type $FS_TYPE. Skipping format." + fi + + FS_INFO=$(blkid "$PARTITION") + UUID=$(echo "$FS_INFO" | grep -oP "UUID=\"\K[^\"]+") + TYPE=$(echo "$FS_INFO" | grep -oP "TYPE=\"\K[^\"]+") + + if [ -z "$UUID" ] || [ -z "$TYPE" ]; then + log "Failed to retrieve UUID or TYPE for $PARTITION" + exit 1 + fi + + echo "UUID=$UUID $EXPORT_DIR $TYPE defaults 0 2" >> /etc/fstab + log "Added fstab entry." + + mount -a + + if mountpoint -q "$EXPORT_DIR"; then + log "$PARTITION is successfully mounted on $EXPORT_DIR" + else + log "Failed to mount $PARTITION on $EXPORT_DIR" + exit 1 + fi + + log "Configuring NFS export..." + EXPORT_ENTRY="$EXPORT_DIR *($PERMISSIONS)" + if ! grep -qF "$EXPORT_ENTRY" /etc/exports; then + echo "$EXPORT_ENTRY" | tee -a /etc/exports > /dev/null + fi + exportfs -ra + + log "Enable and restart NFS server..." + systemctl enable nfs-kernel-server + systemctl restart nfs-kernel-server + + CURRENT_DISK_SIZE=$(blockdev --getsz "$PARTITION") + + mkdir -p "$DISK_SIZE_DIR" + echo "$CURRENT_DISK_SIZE" > "$DISK_SIZE_FILE" + + log "NFS share created successfully." + log "Finished running add script." + + - path: /usr/local/bin/sharedfs/resize-filesystem + permissions: '0700' + owner: root:root + content: | + #!/bin/bash -e + + source /usr/local/bin/sharedfs/common + log "Running resize script." + + FILESYSTEM={{ fsvm.filesystem }} + if [ "$FILESYSTEM" == "xfs" ]; then + EXPORT_DIR={{ fsvm.exportpath }} + xfs_growfs "$EXPORT_DIR" + elif [ "$FILESYSTEM" == "ext4" ]; then + PARTITION="/dev/$1" + resize2fs "$PARTITION" + else + log "Invalid filesystem type specified. Use 'xfs' or 'ext4'." + exit 1 + fi + + log "Finished running resize script." + + - path: /etc/systemd/system/resize-sharedfs@.service + permissions: '0700' + owner: root:root + content: | + [Unit] + Description=Resize Shared FileSystem + + [Install] + WantedBy=multi-user.target + + [Service] + Type=oneshot + ExecStart=/usr/local/bin/sharedfs/resize-filesystem %I + + - path: /etc/systemd/system/cloud-dhclient@.service + permissions: '0700' + owner: root:root + content: | + [Unit] + Description=CloudStack service to start dhclient + + [Install] + WantedBy=multi-user.target + + [Service] + Type=oneshot + ExecStart=/usr/sbin/dhclient %I + Restart=on-failure + + - path: /usr/local/bin/sharedfs/fsvm-setup + permissions: '0700' + owner: root:root + content: | + #!/bin/bash -e + + source /usr/local/bin/sharedfs/common + + HYPERVISOR={{ fsvm.hypervisor }} + BLOCK_DEVICE=$(get_block_device "$HYPERVISOR") + + PARTITION="/dev/$BLOCK_DEVICE" + ADD_PARTITION_FILE="/usr/local/bin/sharedfs/create-shared-filesystem" + RESIZE_PARTITION_FILE="/usr/local/bin/sharedfs/resize-filesystem" + + for interface in $(ls /sys/class/net/ | grep '^eth'); do + echo "Starting cloud-dhclient service for interface: $interface" + sudo systemctl start cloud-dhclient@$interface.service + done + log "Existing network interfaces configured" + + UDEV_RESIZE_RULE="KERNEL==\"$BLOCK_DEVICE\", ACTION==\"add|change\", SUBSYSTEM==\"block\", ENV{SYSTEMD_WANTS}=\"resize-sharedfs@%k.service\"" + UDEV_ADD_NIC_RULE="ACTION==\"add\", SUBSYSTEM==\"net\", DRIVERS==\"?*\", ENV{SYSTEMD_WANTS}=\"cloud-dhclient@%k.service\"" + + # Add udev rules + echo "$UDEV_RESIZE_RULE" > /etc/udev/rules.d/99-resize-filesystem.rules + echo "$UDEV_ADD_NIC_RULE" > /etc/udev/rules.d/99-add-nic.rules + + if [ -b "$PARTITION" ]; then + log "Partition $PARTITION exists. Running the $ADD_PARTITION_FILE script" + $ADD_PARTITION_FILE "$PARTITION" + fi + + log "Udev rules added." + + # Reload udev rules + udevadm control --reload-rules + udevadm trigger + + log "Script execution finished successfully." + + sudo touch /home/cloud/success + echo "true" > /home/cloud/success + +runcmd: + - /usr/local/bin/sharedfs/fsvm-setup diff --git a/plugins/storage/sharedfs/storagevm/src/test/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycleTest.java b/plugins/storage/sharedfs/storagevm/src/test/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycleTest.java new file mode 100644 index 000000000000..4393b0565f89 --- /dev/null +++ b/plugins/storage/sharedfs/storagevm/src/test/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycleTest.java @@ -0,0 +1,335 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.storage.sharedfs.lifecycle; + +import static org.apache.cloudstack.storage.sharedfs.provider.StorageVmSharedFSProvider.SHAREDFSVM_MIN_CPU_COUNT; +import static org.apache.cloudstack.storage.sharedfs.provider.StorageVmSharedFSProvider.SHAREDFSVM_MIN_RAM_SIZE; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.Optional; + +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.storage.sharedfs.SharedFS; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + +import com.cloud.dc.DataCenter; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.hypervisor.Hypervisor; +import com.cloud.network.Network; +import com.cloud.offering.ServiceOffering; +import com.cloud.resource.ResourceManager; +import com.cloud.service.ServiceOfferingVO; +import com.cloud.service.dao.ServiceOfferingDao; +import com.cloud.storage.VMTemplateVO; +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeApiService; +import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.DiskOfferingDao; +import com.cloud.storage.dao.LaunchPermissionDao; +import com.cloud.storage.dao.VMTemplateDao; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.uservm.UserVm; +import com.cloud.utils.FileUtil; +import com.cloud.utils.Pair; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.UserVmManager; +import com.cloud.vm.UserVmService; +import com.cloud.vm.UserVmVO; +import com.cloud.vm.VirtualMachineManager; +import com.cloud.vm.dao.NicDao; +import com.cloud.vm.dao.UserVmDao; + +@RunWith(MockitoJUnitRunner.class) +public class StorageVmSharedFSLifeCycleTest { + @Mock + private AccountManager accountMgr; + + @Mock + protected ResourceManager resourceMgr; + + @Mock + private VirtualMachineManager virtualMachineManager; + + @Mock + private VolumeApiService volumeApiService; + + @Mock + protected UserVmService userVmService; + + @Mock + protected UserVmManager userVmManager; + + @Mock + private DataCenterDao dataCenterDao; + + @Mock + private VMTemplateDao templateDao; + + @Mock + VolumeDao volumeDao; + + @Mock + private UserVmDao userVmDao; + + @Mock + NicDao nicDao; + + @Mock + ServiceOfferingDao serviceOfferingDao; + + @Mock + private DiskOfferingDao diskOfferingDao; + + @Mock + protected LaunchPermissionDao launchPermissionDao; + + @Spy + @InjectMocks + StorageVmSharedFSLifeCycle lifeCycle; + + private static final long s_ownerId = 1L; + private static final long s_zoneId = 2L; + private static final long s_diskOfferingId = 3L; + private static final long s_serviceOfferingId = 4L; + private static final long s_templateId = 5L; + private static final long s_volumeId = 6L; + private static final long s_vmId = 7L; + private static final long s_networkId = 8L; + private static final long s_size = 10L; + private static final long s_minIops = 1000L; + private static final long s_maxIops = 2000L; + private static final String s_fsFormat = "EXT4"; + private static final String s_name = "TestSharedFS"; + + private MockedStatic fileUtilMocked; + private MockedStatic callContextMocked; + + private AutoCloseable closeable; + + @Before + public void setUp() { + closeable = MockitoAnnotations.openMocks(this); + callContextMocked = mockStatic(CallContext.class); + CallContext callContextMock = mock(CallContext.class); + callContextMocked.when(CallContext::current).thenReturn(callContextMock); + Account owner = mock(Account.class); + when(callContextMock.getCallingAccount()).thenReturn(owner); + CallContext vmContext = mock(CallContext.class); + when(callContextMock.register(CallContext.current(), ApiCommandResourceType.VirtualMachine)).thenReturn(vmContext); + + fileUtilMocked = mockStatic(FileUtil.class); + fileUtilMocked.when(() -> FileUtil.readResourceFile("/conf/fsvm-init.yml")).thenReturn(""); + } + + @After + public void tearDown() throws Exception { + fileUtilMocked.close(); + callContextMocked.close(); + closeable.close(); + } + + @Test + public void testCheckPrerequisites() { + DataCenterVO zone = mock(DataCenterVO.class); + when(zone.getId()).thenReturn(s_zoneId); + ServiceOfferingVO serviceOfferingVO = mock(ServiceOfferingVO.class); + when(serviceOfferingVO.getCpu()).thenReturn(4); + when(serviceOfferingVO.getRamSize()).thenReturn(1024); + when(serviceOfferingVO.isOfferHA()).thenReturn(true); + when(serviceOfferingDao.findById(s_serviceOfferingId)).thenReturn(serviceOfferingVO); + lifeCycle.checkPrerequisites(zone, s_serviceOfferingId); + } + + @Test + public void testCheckPrerequisitesMinCpuException() { + DataCenterVO zone = mock(DataCenterVO.class); + when(zone.getId()).thenReturn(s_zoneId); + ServiceOfferingVO serviceOfferingVO = mock(ServiceOfferingVO.class); + when(serviceOfferingDao.findById(s_serviceOfferingId)).thenReturn(serviceOfferingVO); + InvalidParameterValueException exception = Assert.assertThrows(InvalidParameterValueException.class, () -> lifeCycle.checkPrerequisites(zone, s_serviceOfferingId)); + Assert.assertEquals(exception.getMessage(), "Service offering's number of cpu should be greater than or equal to " + SHAREDFSVM_MIN_CPU_COUNT.key()); + } + + @Test + public void testCheckPrerequisitesMinRamException() { + DataCenterVO zone = mock(DataCenterVO.class); + when(zone.getId()).thenReturn(s_zoneId); + ServiceOfferingVO serviceOfferingVO = mock(ServiceOfferingVO.class); + when(serviceOfferingDao.findById(s_serviceOfferingId)).thenReturn(serviceOfferingVO); + when(serviceOfferingVO.getCpu()).thenReturn(4); + InvalidParameterValueException exception = Assert.assertThrows(InvalidParameterValueException.class, () -> lifeCycle.checkPrerequisites(zone, s_serviceOfferingId)); + Assert.assertEquals(exception.getMessage(), "Service offering's ram size should be greater than or equal to " + SHAREDFSVM_MIN_RAM_SIZE.key()); + } + + @Test + public void testCheckPrerequisitesHAException() { + DataCenterVO zone = mock(DataCenterVO.class); + when(zone.getId()).thenReturn(s_zoneId); + ServiceOfferingVO serviceOfferingVO = mock(ServiceOfferingVO.class); + when(serviceOfferingDao.findById(s_serviceOfferingId)).thenReturn(serviceOfferingVO); + when(serviceOfferingVO.getCpu()).thenReturn(4); + when(serviceOfferingVO.getRamSize()).thenReturn(1024); + InvalidParameterValueException exception = Assert.assertThrows(InvalidParameterValueException.class, () -> lifeCycle.checkPrerequisites(zone, s_serviceOfferingId)); + Assert.assertEquals(exception.getMessage(), "Service offering's should be HA enabled"); + } + + private SharedFS prepareDeploySharedFS() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException { + SharedFS sharedFS = mock(SharedFS.class); + when(sharedFS.getDataCenterId()).thenReturn(s_zoneId); + when(sharedFS.getName()).thenReturn(s_name); + when(sharedFS.getServiceOfferingId()).thenReturn(s_serviceOfferingId); + when(sharedFS.getFsType()).thenReturn(SharedFS.FileSystemType.valueOf(s_fsFormat)); + when(sharedFS.getAccountId()).thenReturn(s_ownerId); + + DataCenterVO zone = mock(DataCenterVO.class); + when(dataCenterDao.findById(s_zoneId)).thenReturn(zone); + when(resourceMgr.getSupportedHypervisorTypes(s_zoneId, false, null)).thenReturn(List.of(Hypervisor.HypervisorType.KVM)); + + ServiceOfferingVO serviceOffering = mock(ServiceOfferingVO.class); + when(serviceOfferingDao.findById(s_serviceOfferingId)).thenReturn(serviceOffering); + + VMTemplateVO template = mock(VMTemplateVO.class); + when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM)).thenReturn(template); + when(template.getId()).thenReturn(s_templateId); + + return sharedFS; + } + + @Test + public void testDeploySharedFS() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, IOException, OperationTimedoutException { + SharedFS sharedFS = prepareDeploySharedFS(); + when(sharedFS.getAccountId()).thenReturn(s_ownerId); + + Account owner = mock(Account.class); + when(owner.getId()).thenReturn(s_ownerId); + when(accountMgr.getActiveAccountById(s_ownerId)).thenReturn(owner); + + UserVm vm = mock(UserVm.class); + when(vm.getId()).thenReturn(s_vmId); + when(userVmService.createAdvancedVirtualMachine( + any(DataCenter.class), any(ServiceOffering.class), any(VirtualMachineTemplate.class), anyList(), any(Account.class), anyString(), + anyString(), anyLong(), anyLong(), isNull(), any(Hypervisor.HypervisorType.class), any(BaseCmd.HTTPMethod.class), anyString(), + isNull(), isNull(), anyList(), isNull(), any(Network.IpAddresses.class), isNull(), isNull(), isNull(), + anyMap(), isNull(), isNull(), isNull(), isNull(), + anyBoolean(), anyString(), isNull())).thenReturn(vm); + + VolumeVO volume = mock(VolumeVO.class); + when(volume.getId()).thenReturn(s_volumeId); + when(volumeDao.findByInstanceAndType(s_vmId, Volume.Type.DATADISK)).thenReturn(List.of(volume)); + + Pair result = lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops); + Assert.assertEquals(Optional.ofNullable(result.first()), Optional.ofNullable(s_volumeId)); + Assert.assertEquals(Optional.ofNullable(result.second()), Optional.ofNullable(s_vmId)); + } + + @Test(expected = CloudRuntimeException.class) + public void testDeploySharedFSHypervisorNotFound() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, IOException, OperationTimedoutException { + SharedFS sharedFS = mock(SharedFS.class); + when(sharedFS.getDataCenterId()).thenReturn(s_zoneId); + when(sharedFS.getName()).thenReturn(s_name); + when(sharedFS.getServiceOfferingId()).thenReturn(s_serviceOfferingId); + when(sharedFS.getFsType()).thenReturn(SharedFS.FileSystemType.valueOf(s_fsFormat)); + when(sharedFS.getAccountId()).thenReturn(s_ownerId); + + when(accountMgr.getActiveAccountById(s_ownerId)).thenReturn(null); + DataCenterVO zone = mock(DataCenterVO.class); + when(dataCenterDao.findById(s_zoneId)).thenReturn(zone); + lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops); + } + + @Test(expected = CloudRuntimeException.class) + public void testDeploySharedFSTemplateNotFound() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, IOException, OperationTimedoutException { + SharedFS sharedFS = mock(SharedFS.class); + when(sharedFS.getDataCenterId()).thenReturn(s_zoneId); + when(sharedFS.getName()).thenReturn(s_name); + when(sharedFS.getServiceOfferingId()).thenReturn(s_serviceOfferingId); + when(sharedFS.getFsType()).thenReturn(SharedFS.FileSystemType.valueOf(s_fsFormat)); + when(sharedFS.getAccountId()).thenReturn(s_ownerId); + + when(accountMgr.getActiveAccountById(s_ownerId)).thenReturn(null); + DataCenterVO zone = mock(DataCenterVO.class); + when(dataCenterDao.findById(s_zoneId)).thenReturn(zone); + when(resourceMgr.getSupportedHypervisorTypes(s_zoneId, false, null)).thenReturn(List.of(Hypervisor.HypervisorType.KVM)); + + when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM)).thenReturn(null); + lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops); + } + + @Test + public void testDeleteSharedFS() throws ResourceUnavailableException { + SharedFS sharedFS = mock(SharedFS.class); + when(sharedFS.getVmId()).thenReturn(s_vmId); + when(sharedFS.getVolumeId()).thenReturn(s_volumeId); + + UserVmVO vm = mock(UserVmVO.class); + when(vm.getId()).thenReturn(s_vmId); + when(userVmDao.findById(s_vmId)).thenReturn(vm); + when(userVmService.destroyVm(s_vmId, true)).thenReturn(vm); + when(userVmManager.expunge(vm)).thenReturn(true); + + VolumeVO volume = mock(VolumeVO.class); + when(volumeDao.findById(s_volumeId)).thenReturn(volume); + when(volume.getId()).thenReturn(s_volumeId); + when(volume.getState()).thenReturn(Volume.State.Allocated); + + Assert.assertEquals(lifeCycle.deleteSharedFS(sharedFS), true); + } + + @Test + public void testReDeploySharedFS() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, IOException, OperationTimedoutException { + SharedFS sharedFS = mock(SharedFS.class); + Long vmId = 1L; + when(sharedFS.getVmId()).thenReturn(vmId); + UserVm vm = mock(UserVm.class); + when(virtualMachineManager.restoreVirtualMachine(vmId, null, null, true, null)).thenReturn(vm); + boolean result = lifeCycle.reDeploySharedFS(sharedFS); + Assert.assertEquals(result, true); + } +} diff --git a/plugins/storage/volume/adaptive/pom.xml b/plugins/storage/volume/adaptive/pom.xml index 27a823469152..724ecddcf031 100644 --- a/plugins/storage/volume/adaptive/pom.xml +++ b/plugins/storage/volume/adaptive/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/driver/AdaptiveDataStoreDriverImpl.java b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/driver/AdaptiveDataStoreDriverImpl.java index 549604b35777..329de5a398a2 100644 --- a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/driver/AdaptiveDataStoreDriverImpl.java +++ b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/driver/AdaptiveDataStoreDriverImpl.java @@ -18,7 +18,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import java.util.HashMap; import java.util.List; @@ -97,10 +96,12 @@ import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class AdaptiveDataStoreDriverImpl extends CloudStackPrimaryDataStoreDriverImpl { - static final Logger s_logger = Logger.getLogger(AdaptiveDataStoreDriverImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private String providerName = null; @@ -209,7 +210,7 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback callback) { CreateCmdResult result = null; try { - s_logger.info("Volume creation starting for data store [" + dataStore.getName() + + logger.info("Volume creation starting for data store [" + dataStore.getName() + "] and data object [" + dataObject.getUuid() + "] of type [" + dataObject.getType() + "]"); // quota size of the cloudbyte volume will be increased with the given @@ -242,7 +243,7 @@ public void createAsync(DataStore dataStore, DataObject dataObject, if (DataObjectType.TEMPLATE.equals(dataObject.getType())) { volume = api.getVolume(context, dataIn); if (volume != null) { - s_logger.info("Template volume already exists [" + dataObject.getUuid() + "]"); + logger.info("Template volume already exists [" + dataObject.getUuid() + "]"); } } @@ -260,7 +261,7 @@ public void createAsync(DataStore dataStore, DataObject dataObject, throw e; } } - s_logger.info("New volume created on remote storage for [" + dataObject.getUuid() + "]"); + logger.info("New volume created on remote storage for [" + dataObject.getUuid() + "]"); } // set these from the discovered or created volume before proceeding @@ -272,9 +273,9 @@ public void createAsync(DataStore dataStore, DataObject dataObject, result = new CreateCmdResult(dataObject.getUuid(), new Answer(null)); result.setSuccess(true); - s_logger.info("Volume creation complete for [" + dataObject.getUuid() + "]"); + logger.info("Volume creation complete for [" + dataObject.getUuid() + "]"); } catch (Throwable e) { - s_logger.error("Volume creation failed for dataObject [" + dataObject.getUuid() + "]: " + e.toString(), e); + logger.error("Volume creation failed for dataObject [" + dataObject.getUuid() + "]: " + e.toString(), e); result = new CreateCmdResult(null, new Answer(null)); result.setResult(e.toString()); result.setSuccess(false); @@ -288,7 +289,7 @@ public void createAsync(DataStore dataStore, DataObject dataObject, @Override public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback callback) { - s_logger.debug("Delete volume started"); + logger.debug("Delete volume started"); CommandResult result = new CommandResult(); try { StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId()); @@ -304,7 +305,7 @@ public void deleteAsync(DataStore dataStore, DataObject dataObject, result.setResult("Successfully deleted volume"); result.setSuccess(true); } catch (Throwable e) { - s_logger.error("Result to volume delete failed with exception", e); + logger.error("Result to volume delete failed with exception", e); result.setResult(e.toString()); } finally { if (callback != null) @@ -317,7 +318,7 @@ public void copyAsync(DataObject srcdata, DataObject destdata, AsyncCompletionCallback callback) { CopyCommandResult result = null; try { - s_logger.info("Copying volume " + srcdata.getUuid() + " to " + destdata.getUuid() + "]"); + logger.info("Copying volume " + srcdata.getUuid() + " to " + destdata.getUuid() + "]"); if (!canCopy(srcdata, destdata)) { throw new CloudRuntimeException( @@ -329,7 +330,7 @@ public void copyAsync(DataObject srcdata, DataObject destdata, Map details = _storagePoolDao.getDetails(storagePool.getId()); ProviderAdapter api = getAPI(storagePool, details); - s_logger.info("Copy volume " + srcdata.getUuid() + " to " + destdata.getUuid()); + logger.info("Copy volume " + srcdata.getUuid() + " to " + destdata.getUuid()); ProviderVolume outVolume; ProviderAdapterContext context = newManagedVolumeContext(destdata); @@ -346,14 +347,14 @@ public void copyAsync(DataObject srcdata, DataObject destdata, // if we copied from one volume to another, the target volume's disk offering or user input may be of a larger size // we won't, however, shrink a volume if its smaller. if (outVolume.getAllocatedSizeInBytes() < destdata.getSize()) { - s_logger.info("Resizing volume " + destdata.getUuid() + " to requested target volume size of " + destdata.getSize()); + logger.info("Resizing volume " + destdata.getUuid() + " to requested target volume size of " + destdata.getSize()); api.resize(context, destIn, destdata.getSize()); } // initial volume info does not have connection map yet. That is added when grantAccess is called later. String finalPath = generatePathInfo(outVolume, null); persistVolumeData(storagePool, details, destdata, outVolume, null); - s_logger.info("Copy completed from [" + srcdata.getUuid() + "] to [" + destdata.getUuid() + "]"); + logger.info("Copy completed from [" + srcdata.getUuid() + "] to [" + destdata.getUuid() + "]"); VolumeObjectTO voto = new VolumeObjectTO(); voto.setPath(finalPath); @@ -361,7 +362,7 @@ public void copyAsync(DataObject srcdata, DataObject destdata, result = new CopyCommandResult(finalPath, new CopyCmdAnswer(voto)); result.setSuccess(true); } catch (Throwable e) { - s_logger.error("Result to volume copy failed with exception", e); + logger.error("Result to volume copy failed with exception", e); result = new CopyCommandResult(null, null); result.setSuccess(false); result.setResult(e.toString()); @@ -380,20 +381,20 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, @Override public boolean canCopy(DataObject srcData, DataObject destData) { - s_logger.debug("canCopy: Checking srcData [" + srcData.getUuid() + ":" + srcData.getType() + ":" + logger.debug("canCopy: Checking srcData [" + srcData.getUuid() + ":" + srcData.getType() + ":" + srcData.getDataStore().getId() + " AND destData [" + destData.getUuid() + ":" + destData.getType() + ":" + destData.getDataStore().getId() + "]"); try { if (!isSameProvider(srcData)) { - s_logger.debug("canCopy: No we can't -- the source provider is NOT the correct type for this driver!"); + logger.debug("canCopy: No we can't -- the source provider is NOT the correct type for this driver!"); return false; } if (!isSameProvider(destData)) { - s_logger.debug("canCopy: No we can't -- the destination provider is NOT the correct type for this driver!"); + logger.debug("canCopy: No we can't -- the destination provider is NOT the correct type for this driver!"); return false; } - s_logger.debug( + logger.debug( "canCopy: Source and destination are the same so we can copy via storage endpoint, checking that the source actually exists"); StoragePoolVO poolVO = _storagePoolDao.findById(srcData.getDataStore().getId()); Map details = _storagePoolDao.getDetails(srcData.getDataStore().getId()); @@ -421,14 +422,14 @@ public boolean canCopy(DataObject srcData, DataObject destData) { } } } catch (Throwable e) { - s_logger.warn("Problem checking if we canCopy", e); + logger.warn("Problem checking if we canCopy", e); return false; } } @Override public void resize(DataObject data, AsyncCompletionCallback callback) { - s_logger.debug("Resize volume started"); + logger.debug("Resize volume started"); CreateCmdResult result = null; try { @@ -457,12 +458,12 @@ public void resize(DataObject data, AsyncCompletionCallback cal ProviderAdapterContext context = newManagedVolumeContext(data); ProviderAdapterDataObject dataIn = newManagedDataObject(data, poolVO); - if (s_logger.isDebugEnabled()) s_logger.debug("Calling provider API to resize volume " + data.getUuid() + " to " + resizeParameter.newSize); + if (logger.isDebugEnabled()) logger.debug("Calling provider API to resize volume " + data.getUuid() + " to " + resizeParameter.newSize); api.resize(context, dataIn, resizeParameter.newSize); if (vol.isAttachedVM()) { if (VirtualMachine.State.Running.equals(vol.getAttachedVM().getState())) { - if (s_logger.isDebugEnabled()) s_logger.debug("Notify currently attached VM of volume resize for " + data.getUuid() + " to " + resizeParameter.newSize); + if (logger.isDebugEnabled()) logger.debug("Notify currently attached VM of volume resize for " + data.getUuid() + " to " + resizeParameter.newSize); _volumeService.resizeVolumeOnHypervisor(vol.getId(), resizeParameter.newSize, vol.getAttachedVM().getHostId(), vol.getAttachedVM().getInstanceName()); } } @@ -470,7 +471,7 @@ public void resize(DataObject data, AsyncCompletionCallback cal result = new CreateCmdResult(data.getUuid(), new Answer(null)); result.setSuccess(true); } catch (Throwable e) { - s_logger.error("Resize volume failed, please contact cloud support.", e); + logger.error("Resize volume failed, please contact cloud support.", e); result = new CreateCmdResult(null, new Answer(null)); result.setResult(e.toString()); result.setSuccess(false); @@ -483,7 +484,7 @@ public void resize(DataObject data, AsyncCompletionCallback cal } public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore) { - s_logger.debug("Granting host " + host.getName() + " access to volume " + dataObject.getUuid()); + logger.debug("Granting host " + host.getName() + " access to volume " + dataObject.getUuid()); try { StoragePoolVO storagePool = _storagePoolDao.findById(dataObject.getDataStore().getId()); @@ -501,11 +502,11 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore persistVolumeOrTemplateData(storagePool, details, dataObject, vol, connIdMap); - s_logger.info("Granted host " + host.getName() + " access to volume " + dataObject.getUuid()); + logger.info("Granted host " + host.getName() + " access to volume " + dataObject.getUuid()); return true; } catch (Throwable e) { String msg = "Error granting host " + host.getName() + " access to volume " + dataObject.getUuid() + ":" + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } } @@ -516,7 +517,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) return; } - s_logger.debug("Revoking access for host " + host.getName() + " to volume " + dataObject.getUuid()); + logger.debug("Revoking access for host " + host.getName() + " to volume " + dataObject.getUuid()); try { StoragePoolVO storagePool = _storagePoolDao.findById(dataObject.getDataStore().getId()); @@ -534,10 +535,10 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) Map connIdMap = api.getConnectionIdMap(dataIn); persistVolumeOrTemplateData(storagePool, details, dataObject, vol, connIdMap); - s_logger.info("Revoked access for host " + host.getName() + " to volume " + dataObject.getUuid()); + logger.info("Revoked access for host " + host.getName() + " to volume " + dataObject.getUuid()); } catch (Throwable e) { String msg = "Error revoking access for host " + host.getName() + " to volume " + dataObject.getUuid() + ":" + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } } @@ -545,7 +546,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) @Override public void handleQualityOfServiceForVolumeMigration(VolumeInfo volumeInfo, QualityOfServiceState qualityOfServiceState) { - s_logger.info("handleQualityOfServiceVolumeMigration: " + volumeInfo.getUuid() + " " + + logger.info("handleQualityOfServiceVolumeMigration: " + volumeInfo.getUuid() + " " + volumeInfo.getPath() + ": " + qualityOfServiceState.toString()); } @@ -575,7 +576,7 @@ public ChapInfo getChapInfo(DataObject dataObject) { public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback) { CreateCmdResult result = null; try { - s_logger.debug("taking volume snapshot"); + logger.debug("taking volume snapshot"); SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO(); VolumeInfo baseVolume = snapshot.getBaseVolume(); @@ -618,7 +619,7 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback dsInfos) { password = userInfo.split(":")[1]; } - s_logger.info("Registering block storage provider with user=" + username); + logger.info("Registering block storage provider with user=" + username); if (clusterId != null) { @@ -153,7 +150,7 @@ public DataStore initialize(Map dsInfos) { throw new CloudRuntimeException("Pod Id must also be specified when the Cluster Id is specified for Cluster-wide primary storage."); } - s_logger.info("Registering with clusterid=" + clusterId + " which is confirmed to be a KVM host"); + logger.info("Registering with clusterid=" + clusterId + " which is confirmed to be a KVM host"); } else if (podId != null) { throw new CloudRuntimeException("Cluster Id must also be specified when the Pod Id is specified for Cluster-wide primary storage."); @@ -175,7 +172,7 @@ public DataStore initialize(Map dsInfos) { } } - s_logger.info("Validated no other pool exists with this name: " + dsName); + logger.info("Validated no other pool exists with this name: " + dsName); try { PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters(); @@ -238,10 +235,10 @@ public DataStore initialize(Map dsInfos) { parameters.setCapacityBytes(stats.getCapacityInBytes()); } - s_logger.info("Persisting [" + dsName + "] storage pool metadata to database"); + logger.info("Persisting [" + dsName + "] storage pool metadata to database"); return _dataStoreHelper.createPrimaryDataStore(parameters); } catch (Throwable e) { - s_logger.error("Problem persisting storage pool", e); + logger.error("Problem persisting storage pool", e); throw new CloudRuntimeException(e); } } @@ -265,7 +262,7 @@ private Hypervisor.HypervisorType getHypervisorTypeForCluster(long clusterId) { */ @Override public boolean attachCluster(DataStore store, ClusterScope scope) { - s_logger.info("Attaching storage pool [" + store.getName() + "] to cluster [" + scope.getScopeId() + "]"); + logger.info("Attaching storage pool [" + store.getName() + "] to cluster [" + scope.getScopeId() + "]"); _dataStoreHelper.attachCluster(store); StoragePoolVO dataStoreVO = _storagePoolDao.findById(store.getId()); @@ -281,23 +278,23 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { if (dataStoreVO.isManaged()) { //boolean success = false; for (HostVO h : allHosts) { - s_logger.debug("adding host " + h.getName() + " to storage pool " + store.getName()); + logger.debug("adding host " + h.getName() + " to storage pool " + store.getName()); } } - s_logger.debug("In createPool Adding the pool to each of the hosts"); + logger.debug("In createPool Adding the pool to each of the hosts"); List poolHosts = new ArrayList(); for (HostVO h : allHosts) { try { _storageMgr.connectHostToSharedPool(h.getId(), primarystore.getId()); poolHosts.add(h); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e); + logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e); } } if (poolHosts.isEmpty()) { - s_logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId()); + logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId()); _primaryDataStoreDao.expunge(primarystore.getId()); throw new CloudRuntimeException("Failed to access storage pool"); } @@ -307,14 +304,14 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { @Override public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { - s_logger.info("Attaching storage pool [" + store.getName() + "] to host [" + scope.getScopeId() + "]"); + logger.info("Attaching storage pool [" + store.getName() + "] to host [" + scope.getScopeId() + "]"); _dataStoreHelper.attachHost(store, scope, existingInfo); return true; } @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { - s_logger.info("Attaching storage pool [" + dataStore.getName() + "] to zone [" + scope.getScopeId() + "]"); + logger.info("Attaching storage pool [" + dataStore.getName() + "] to zone [" + scope.getScopeId() + "]"); List hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId()); List poolHosts = new ArrayList(); for (HostVO host : hosts) { @@ -322,11 +319,11 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); poolHosts.add(host); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); + logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } if (poolHosts.isEmpty()) { - s_logger.warn("No host can access storage pool " + dataStore + " in this zone."); + logger.warn("No host can access storage pool " + dataStore + " in this zone."); _primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts."); } @@ -339,7 +336,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h */ @Override public boolean maintain(DataStore store) { - s_logger.info("Placing storage pool [" + store.getName() + "] in maintainence mode"); + logger.info("Placing storage pool [" + store.getName() + "] in maintainence mode"); if (_storagePoolAutomation.maintain(store)) { return _dataStoreHelper.maintain(store); } else { @@ -352,7 +349,7 @@ public boolean maintain(DataStore store) { */ @Override public boolean cancelMaintain(DataStore store) { - s_logger.info("Canceling storage pool maintainence for [" + store.getName() + "]"); + logger.info("Canceling storage pool maintainence for [" + store.getName() + "]"); if (_dataStoreHelper.cancelMaintain(store)) { return _storagePoolAutomation.cancelMaintain(store); } else { @@ -365,7 +362,7 @@ public boolean cancelMaintain(DataStore store) { */ @Override public boolean deleteDataStore(DataStore store) { - s_logger.info("Delete datastore called for [" + store.getName() + "]"); + logger.info("Delete datastore called for [" + store.getName() + "]"); return _dataStoreHelper.deletePrimaryDataStore(store); } @@ -374,7 +371,7 @@ public boolean deleteDataStore(DataStore store) { */ @Override public boolean migrateToObjectStore(DataStore store) { - s_logger.info("Migrate datastore called for [" + store.getName() + "]. This is not currently implemented for this provider at this time"); + logger.info("Migrate datastore called for [" + store.getName() + "]. This is not currently implemented for this provider at this time"); return false; } @@ -391,7 +388,7 @@ public void updateStoragePool(StoragePool storagePool, Map newDe */ @Override public void enableStoragePool(DataStore store) { - s_logger.info("Enabling storage pool [" + store.getName() + "]"); + logger.info("Enabling storage pool [" + store.getName() + "]"); _dataStoreHelper.enable(store); } @@ -400,7 +397,7 @@ public void enableStoragePool(DataStore store) { */ @Override public void disableStoragePool(DataStore store) { - s_logger.info("Disabling storage pool [" + store.getName() + "]"); + logger.info("Disabling storage pool [" + store.getName() + "]"); _dataStoreHelper.disable(store); } } diff --git a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryDatastoreAdapterFactoryMap.java b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryDatastoreAdapterFactoryMap.java index e68153512d3d..4fef54014736 100644 --- a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryDatastoreAdapterFactoryMap.java +++ b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryDatastoreAdapterFactoryMap.java @@ -21,13 +21,14 @@ import org.apache.cloudstack.storage.datastore.adapter.ProviderAdapter; import org.apache.cloudstack.storage.datastore.adapter.ProviderAdapterFactory; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class AdaptivePrimaryDatastoreAdapterFactoryMap { - private final Logger logger = Logger.getLogger(ProviderAdapter.class); + protected Logger logger = LogManager.getLogger(getClass()); private Map factoryMap = new HashMap(); private Map apiMap = new HashMap(); diff --git a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryDatastoreProviderImpl.java b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryDatastoreProviderImpl.java index 200844702b28..ddb7b5b0444d 100644 --- a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryDatastoreProviderImpl.java +++ b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryDatastoreProviderImpl.java @@ -24,7 +24,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.component.ComponentContext; @@ -35,7 +36,7 @@ @Component public abstract class AdaptivePrimaryDatastoreProviderImpl implements PrimaryDataStoreProvider { - static final Logger s_logger = Logger.getLogger(AdaptivePrimaryDatastoreProviderImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); AdaptiveDataStoreDriverImpl driver; @@ -46,7 +47,7 @@ public abstract class AdaptivePrimaryDatastoreProviderImpl implements PrimaryDat DataStoreLifeCycle lifecycle; AdaptivePrimaryDatastoreProviderImpl(ProviderAdapterFactory f) { - s_logger.info("Creating " + f.getProviderName()); + logger.info("Creating " + f.getProviderName()); factoryMap.register(f); } @@ -57,7 +58,7 @@ public DataStoreLifeCycle getDataStoreLifeCycle() { @Override public boolean configure(Map params) { - s_logger.info("Configuring " + getName()); + logger.info("Configuring " + getName()); driver = new AdaptiveDataStoreDriverImpl(factoryMap); driver.setProviderName(getName()); lifecycle = ComponentContext.inject(new AdaptiveDataStoreLifeCycleImpl(factoryMap)); diff --git a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryHostListener.java b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryHostListener.java index 2a58c8f86f26..a0c8ee722a03 100644 --- a/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryHostListener.java +++ b/plugins/storage/volume/adaptive/src/main/java/org/apache/cloudstack/storage/datastore/provider/AdaptivePrimaryHostListener.java @@ -19,14 +19,15 @@ import javax.inject.Inject; import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; -import org.apache.log4j.Logger; import com.cloud.exception.StorageConflictException; import com.cloud.storage.StoragePoolHostVO; import com.cloud.storage.dao.StoragePoolHostDao; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class AdaptivePrimaryHostListener implements HypervisorHostListener { - static final Logger s_logger = Logger.getLogger(AdaptivePrimaryHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject StoragePoolHostDao storagePoolHostDao; @@ -37,19 +38,19 @@ public AdaptivePrimaryHostListener(AdaptivePrimaryDatastoreAdapterFactoryMap fac @Override public boolean hostAboutToBeRemoved(long hostId) { - s_logger.debug("hostAboutToBeRemoved called"); + logger.debug("hostAboutToBeRemoved called"); return true; } @Override public boolean hostAdded(long hostId) { - s_logger.debug("hostAdded called"); + logger.debug("hostAdded called"); return true; } @Override public boolean hostConnect(long hostId, long poolId) throws StorageConflictException { - s_logger.debug("hostConnect called for hostid [" + hostId + "], poolId [" + poolId + "]"); + logger.debug("hostConnect called for hostid [" + hostId + "], poolId [" + poolId + "]"); StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId); if (storagePoolHost == null) { storagePoolHost = new StoragePoolHostVO(poolId, hostId, ""); @@ -62,7 +63,7 @@ public boolean hostConnect(long hostId, long poolId) throws StorageConflictExcep @Override public boolean hostDisconnected(long hostId, long poolId) { - s_logger.debug("hostDisconnected called for hostid [" + hostId + "], poolId [" + poolId + "]"); + logger.debug("hostDisconnected called for hostid [" + hostId + "], poolId [" + poolId + "]"); StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId); if (storagePoolHost != null) { @@ -73,13 +74,13 @@ public boolean hostDisconnected(long hostId, long poolId) { @Override public boolean hostEnabled(long hostId) { - s_logger.debug("hostEnabled called"); + logger.debug("hostEnabled called"); return true; } @Override public boolean hostRemoved(long hostId, long clusterId) { - s_logger.debug("hostRemoved called"); + logger.debug("hostRemoved called"); return true; } } diff --git a/plugins/storage/volume/cloudbyte/pom.xml b/plugins/storage/volume/cloudbyte/pom.xml index 39dcda825b51..a7bd35074dca 100644 --- a/plugins/storage/volume/cloudbyte/pom.xml +++ b/plugins/storage/volume/cloudbyte/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java index f9e614692338..60359dd2c266 100644 --- a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java +++ b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/driver/ElastistorPrimaryDataStoreDriver.java @@ -24,7 +24,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult; @@ -70,7 +69,6 @@ */ public class ElastistorPrimaryDataStoreDriver extends CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver { - private static final Logger s_logger = Logger.getLogger(ElastistorPrimaryDataStoreDriver.class); @Inject AccountManager _accountMgr; @@ -154,7 +152,7 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet try { esvolume = ElastistorUtil.createElastistorVolume(volumeName, dataStoreVO.getUuid(), quotaSize, Iops, protocoltype, volumeName); } catch (Throwable e) { - s_logger.error(e.toString(), e); + logger.error(e.toString(), e); result.setResult(e.toString()); callback.complete(result); throw new CloudRuntimeException(e.getMessage()); @@ -191,10 +189,10 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes); _storagePoolDao.update(storagePoolId, storagePool); - s_logger.info("Elastistor volume creation complete."); + logger.info("Elastistor volume creation complete."); } else { errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync"; - s_logger.error(errMsg); + logger.error(errMsg); } result.setResult(errMsg); @@ -276,7 +274,7 @@ public boolean canCopy(DataObject srcData, DataObject destData) { @Override public void resize(DataObject data, AsyncCompletionCallback callback) { - s_logger.debug("Resize elastistor volume started"); + logger.debug("Resize elastistor volume started"); Boolean status = false; VolumeObject vol = (VolumeObject) data; StoragePool pool = (StoragePool) data.getDataStore(); @@ -297,7 +295,7 @@ public void resize(DataObject data, AsyncCompletionCallback cal status = ElastistorUtil.updateElastistorVolumeSize(vol.getUuid(), resizeParameter.newSize); } catch (Throwable e) { - s_logger.error("Resize elastistor volume failed, please contact elastistor admin.", e); + logger.error("Resize elastistor volume failed, please contact elastistor admin.", e); result.setResult(e.toString()); callback.complete(result); } @@ -370,7 +368,7 @@ public ChapInfo getChapInfo(DataObject dataObject) { public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback) { CreateCmdResult result = null; try { - s_logger.info("taking elastistor volume snapshot"); + logger.info("taking elastistor volume snapshot"); SnapshotObjectTO snapshotTO = (SnapshotObjectTO)snapshot.getTO(); String volumeid = snapshotTO.getVolume().getUuid(); @@ -379,10 +377,10 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback dsInfos) { if (details.get("essubnet") != null) ElastistorUtil.setElastistorSubnet(details.get("essubnet")); - s_logger.info("Elastistor details was set successfully."); + logger.info("Elastistor details was set successfully."); if (capacityBytes == null || capacityBytes <= 0) { throw new IllegalArgumentException("'capacityBytes' must be present and greater than 0."); @@ -167,7 +163,7 @@ public DataStore initialize(Map dsInfos) { if (domainName == null) { domainName = "ROOT"; - s_logger.debug("setting the domain to ROOT"); + logger.debug("setting the domain to ROOT"); } // elastistor does not allow same name and ip pools. @@ -220,7 +216,7 @@ public DataStore initialize(Map dsInfos) { private Tsm createElastistorTSM(String storagePoolName, String storageIp, Long capacityBytes, Long capacityIops, String domainName) { - s_logger.info("Creation of elastistor TSM started."); + logger.info("Creation of elastistor TSM started."); Tsm tsm; String elastistorAccountId; @@ -231,11 +227,11 @@ private Tsm createElastistorTSM(String storagePoolName, String storageIp, Long c // create the tsm for the given account id tsm = ElastistorUtil.createElastistorTsm(storagePoolName, storageIp, capacityBytes, capacityIops, elastistorAccountId); } catch (Throwable e) { - s_logger.error("Failed to create TSM in elastistor.", e); + logger.error("Failed to create TSM in elastistor.", e); throw new CloudRuntimeException("Failed to create TSM in elastistor. " + e.getMessage()); } - s_logger.info("Creation of elastistor TSM completed successfully."); + logger.info("Creation of elastistor TSM completed successfully."); return tsm; } @@ -245,7 +241,7 @@ private PrimaryDataStoreParameters createElastistorVolume(PrimaryDataStoreParame try { - s_logger.info("Creation of elastistor volume started."); + logger.info("Creation of elastistor volume started."); FileSystem volume = ElastistorUtil.createElastistorVolume(storagePoolName, tsm.getUuid(), capacityBytes, capacityIops, protocoltype, mountpoint); @@ -253,11 +249,11 @@ private PrimaryDataStoreParameters createElastistorVolume(PrimaryDataStoreParame String accesspath = "/" + volume.getIqn() + "/0"; parameters.setPath(accesspath); } - s_logger.info("Creation of elastistor volume completed successfully."); + logger.info("Creation of elastistor volume completed successfully."); return parameters; } catch (Throwable e) { - s_logger.error("Failed to create volume in elastistor.", e); + logger.error("Failed to create volume in elastistor.", e); throw new CloudRuntimeException("Failed to create volume in elastistor. " + e.getMessage()); } @@ -377,18 +373,18 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { } } - s_logger.debug("In createPool Adding the pool to each of the hosts"); + logger.debug("In createPool Adding the pool to each of the hosts"); List poolHosts = new ArrayList(); for (HostVO h : allHosts) { try { storageMgr.connectHostToSharedPool(h.getId(), primarystore.getId()); poolHosts.add(h); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e); + logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e); } if (poolHosts.isEmpty()) { - s_logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId()); + logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId()); primaryDataStoreDao.expunge(primarystore.getId()); throw new CloudRuntimeException("Failed to access storage pool"); } @@ -398,12 +394,12 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { } private boolean createStoragePool(long hostId, StoragePool pool) { - s_logger.debug("creating pool " + pool.getName() + " on host " + hostId); + logger.debug("creating pool " + pool.getName() + " on host " + hostId); if (pool.getPoolType() != StoragePoolType.NetworkFilesystem && pool.getPoolType() != StoragePoolType.Filesystem && pool.getPoolType() != StoragePoolType.IscsiLUN && pool.getPoolType() != StoragePoolType.Iscsi && pool.getPoolType() != StoragePoolType.VMFS && pool.getPoolType() != StoragePoolType.SharedMountPoint && pool.getPoolType() != StoragePoolType.PreSetup && pool.getPoolType() != StoragePoolType.OCFS2 && pool.getPoolType() != StoragePoolType.RBD && pool.getPoolType() != StoragePoolType.CLVM) { - s_logger.warn(" Doesn't support storage pool type " + pool.getPoolType()); + logger.warn(" Doesn't support storage pool type " + pool.getPoolType()); return false; } CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool); @@ -415,10 +411,10 @@ private boolean createStoragePool(long hostId, StoragePool pool) { String msg = ""; if (answer != null) { msg = "Can not create storage pool through host " + hostId + " due to " + answer.getDetails(); - s_logger.warn(msg); + logger.warn(msg); } else { msg = "Can not create storage pool through host " + hostId + " due to CreateStoragePoolCommand returns null"; - s_logger.warn(msg); + logger.warn(msg); } throw new CloudRuntimeException(msg); } @@ -433,18 +429,18 @@ public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo exis @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { List hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId()); - s_logger.debug("In createPool. Attaching the pool to each of the hosts."); + logger.debug("In createPool. Attaching the pool to each of the hosts."); List poolHosts = new ArrayList(); for (HostVO host : hosts) { try { storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); poolHosts.add(host); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); + logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } if (poolHosts.isEmpty()) { - s_logger.warn("No host can access storage pool " + dataStore + " in this zone."); + logger.warn("No host can access storage pool " + dataStore + " in this zone."); primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts."); } @@ -504,7 +500,7 @@ public boolean deleteDataStore(DataStore store) { } } else { if (answer != null) { - s_logger.error("Failed to delete storage pool: " + answer.getResult()); + logger.error("Failed to delete storage pool: " + answer.getResult()); } } } @@ -527,9 +523,9 @@ private void deleteElastistorVolume(StoragePool pool, boolean managed) { } if (status == true) { - s_logger.info("deletion of elastistor primary storage complete"); + logger.info("deletion of elastistor primary storage complete"); } else { - s_logger.error("deletion of elastistor volume failed"); + logger.error("deletion of elastistor volume failed"); } } @@ -567,7 +563,7 @@ public void updateStoragePool(StoragePool storagePool, Map detai // update the cloudstack db _storagePoolDao.updateCapacityBytes(storagePool.getId(), Long.parseLong(capacityBytes)); - s_logger.info("elastistor TSM storage successfully updated"); + logger.info("elastistor TSM storage successfully updated"); }else{ throw new CloudRuntimeException("Failed to update the storage of Elastistor TSM" + updateTsmStorageCmdResponse.toString()); } @@ -588,7 +584,7 @@ public void updateStoragePool(StoragePool storagePool, Map detai // update the cloudstack db _storagePoolDao.updateCapacityIops(storagePool.getId(), capacity); - s_logger.info("elastistor TSM IOPS successfully updated"); + logger.info("elastistor TSM IOPS successfully updated"); }else{ throw new CloudRuntimeException("Failed to update the IOPS of Elastistor TSM" + updateTsmCmdResponse.toString()); diff --git a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java index 971449806d5b..d2307111a816 100644 --- a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java +++ b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java @@ -43,7 +43,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -60,7 +61,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class ElastistorHostListener implements HypervisorHostListener { - private static final Logger s_logger = Logger.getLogger(DefaultHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AgentManager agentMgr; @Inject @@ -117,7 +118,7 @@ public boolean hostConnect(long hostId, long poolId) { assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId; - s_logger.info("Connection established between " + pool + " host + " + hostId); + logger.info("Connection established between " + pool + " host + " + hostId); return true; } diff --git a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java index 55326b488308..a6b1848da559 100644 --- a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java +++ b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorPrimaryDataStoreProvider.java @@ -25,7 +25,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; @@ -53,7 +54,7 @@ @Component public class ElastistorPrimaryDataStoreProvider implements PrimaryDataStoreProvider { - private static final Logger s_logger = Logger.getLogger(DefaultHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); // these classes will be injected by spring private ElastistorPrimaryDataStoreLifeCycle lifecycle; @@ -97,7 +98,7 @@ public HypervisorHostListener getHostListener() { @Override public boolean configure(Map params) { - s_logger.info("Will configure elastistor's lifecycle, driver, listener & global configurations."); + logger.info("Will configure elastistor's lifecycle, driver, listener & global configurations."); lifecycle = ComponentContext.inject(ElastistorPrimaryDataStoreLifeCycle.class); driver = ComponentContext.inject(ElastistorPrimaryDataStoreDriver.class); @@ -109,7 +110,7 @@ public boolean configure(Map params) { // set the injected configuration object in elastistor util class too!!! ElastistorUtil.setConfigurationDao(configurationDao); - s_logger.info("Successfully configured elastistor's lifecycle, driver, listener & global configurations."); + logger.info("Successfully configured elastistor's lifecycle, driver, listener & global configurations."); return true; } diff --git a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ElastistorUtil.java b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ElastistorUtil.java index 2f2ad259d6cb..6650dad76775 100644 --- a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ElastistorUtil.java +++ b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ElastistorUtil.java @@ -20,6 +20,7 @@ package org.apache.cloudstack.storage.datastore.util; import com.cloud.agent.api.Answer; +import com.cloud.exception.InvalidParameterValueException; import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.google.gson.Gson; @@ -28,7 +29,8 @@ import org.apache.cloudstack.utils.security.SSLUtils; import org.apache.cloudstack.utils.security.SecureSSLSocketFactory; import org.apache.http.auth.InvalidCredentialsException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.ClientResponse; @@ -46,7 +48,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import java.net.ConnectException; -import java.security.InvalidParameterException; import java.security.SecureRandom; import java.security.cert.X509Certificate; import java.util.ArrayList; @@ -55,7 +56,7 @@ public class ElastistorUtil { - private static final Logger s_logger = Logger.getLogger(ElastistorUtil.class); + protected static Logger LOGGER = LogManager.getLogger(ElastistorUtil.class); private static ConfigurationDao configurationDao; @@ -195,8 +196,8 @@ public static ElastiCenterClient getElastistorRestClient() { } catch (InvalidCredentialsException e) { throw new CloudRuntimeException("InvalidCredentialsException:" + e.getMessage(), e); - } catch (InvalidParameterException e) { - throw new CloudRuntimeException("InvalidParameterException:" + e.getMessage(), e); + } catch (InvalidParameterValueException e) { + throw new CloudRuntimeException("InvalidParameterValueException:" + e.getMessage(), e); } catch (SSLHandshakeException e) { throw new CloudRuntimeException("SSLHandshakeException:" + e.getMessage(), e); } catch (ServiceUnavailableException e) { @@ -542,7 +543,7 @@ public static String updateElastistorNfsVolume(String volumeid) throws Throwable UpdateControllerResponse controllerResponse = (UpdateControllerResponse) getElastistorRestClient().executeCommand(controllerCmd); if (controllerResponse.getController().getUuid() != null) { - s_logger.info("updated nfs service to ALL"); + LOGGER.info("updated nfs service to ALL"); return nfsServiceResponse.getNfsService().getDatasetid(); } else { throw new CloudRuntimeException("Updating Nfs Volume Failed"); @@ -617,7 +618,7 @@ public static boolean deleteElastistorTsm(String tsmid, boolean managed) throws if (!managed) { - s_logger.info("elastistor pool is NOT a managed storage , hence deleting the volume then tsm"); + LOGGER.info("elastistor pool is NOT a managed storage , hence deleting the volume then tsm"); String esvolumeid = null; ListTsmsResponse listTsmsResponse = listTsm(tsmid); @@ -633,9 +634,9 @@ public static boolean deleteElastistorTsm(String tsmid, boolean managed) throws int jobstatus = queryAsyncJobResult(jobid); if (jobstatus == 1) { - s_logger.info("elastistor volume successfully deleted"); + LOGGER.info("elastistor volume successfully deleted"); } else { - s_logger.info("now farce deleting the volume"); + LOGGER.info("now farce deleting the volume"); while (jobstatus != 1) { DeleteVolumeResponse deleteVolumeResponse1 = deleteVolume(esvolumeid, "true"); @@ -645,17 +646,17 @@ public static boolean deleteElastistorTsm(String tsmid, boolean managed) throws jobstatus = queryAsyncJobResult(jobid1); } } - s_logger.info("elastistor volume successfully deleted"); + LOGGER.info("elastistor volume successfully deleted"); } } } else { - s_logger.info("no volume present in on the given tsm"); + LOGGER.info("no volume present in on the given tsm"); } } } - s_logger.info("now trying to delete elastistor tsm"); + LOGGER.info("now trying to delete elastistor tsm"); if (tsmid != null) { DeleteTsmCmd deleteTsmCmd = new DeleteTsmCmd(); @@ -666,22 +667,22 @@ public static boolean deleteElastistorTsm(String tsmid, boolean managed) throws String jobstatus = deleteTsmResponse.getJobStatus(); if (jobstatus.equalsIgnoreCase("true")) { - s_logger.info("deletion of elastistor tsm successful"); + LOGGER.info("deletion of elastistor tsm successful"); return true; } else { - s_logger.info("failed to delete elastistor tsm"); + LOGGER.info("failed to delete elastistor tsm"); return false; } } else { - s_logger.info("elastistor tsm id not present"); + LOGGER.info("elastistor tsm id not present"); } } - s_logger.info("tsm id is null"); + LOGGER.info("tsm id is null"); return false; /* - * else { s_logger.error("no volume is present in the tsm"); } } else { - * s_logger.error( + * else { LOGGER.error("no volume is present in the tsm"); } } else { + * LOGGER.error( * "List tsm failed, no tsm present in the eastistor for the given IP " * ); return false; } return false; */ @@ -700,10 +701,10 @@ public static boolean deleteElastistorVolume(String esvolumeid) throws Throwable int jobstatus = queryAsyncJobResult(jobid); if (jobstatus == 1) { - s_logger.info("elastistor volume successfully deleted"); + LOGGER.info("elastistor volume successfully deleted"); return true; } else { - s_logger.info("now force deleting the volume"); + LOGGER.info("now force deleting the volume"); while (jobstatus != 1) { DeleteVolumeResponse deleteVolumeResponse1 = deleteVolume(esvolumeid, "true"); @@ -713,15 +714,15 @@ public static boolean deleteElastistorVolume(String esvolumeid) throws Throwable jobstatus = queryAsyncJobResult(jobid1); } } - s_logger.info("elastistor volume successfully deleted"); + LOGGER.info("elastistor volume successfully deleted"); return true; } } else { - s_logger.info("the given volume is not present on elastistor, datasetrespone is NULL"); + LOGGER.info("the given volume is not present on elastistor, datasetrespone is NULL"); return false; } } else { - s_logger.info("the given volume is not present on elastistor"); + LOGGER.info("the given volume is not present on elastistor"); return false; } @@ -1049,22 +1050,22 @@ private static final class ElastiCenterClient { private String queryparamapikey = "apikey"; private String queryparamresponse = "response"; - public ElastiCenterClient(String address, String key) throws InvalidCredentialsException, InvalidParameterException, SSLHandshakeException, ServiceUnavailableException { + public ElastiCenterClient(String address, String key) throws InvalidCredentialsException, InvalidParameterValueException, SSLHandshakeException, ServiceUnavailableException { elastiCenterAddress = address; apiKey = key; initialize(); } - public void initialize() throws InvalidParameterException, SSLHandshakeException, InvalidCredentialsException, ServiceUnavailableException { + public void initialize() throws InvalidParameterValueException, SSLHandshakeException, InvalidCredentialsException, ServiceUnavailableException { if (apiKey == null || apiKey.trim().isEmpty()) { - throw new InvalidParameterException("Unable to initialize. Please specify a valid API Key."); + throw new InvalidParameterValueException("Unable to initialize. Please specify a valid API Key."); } if (elastiCenterAddress == null || elastiCenterAddress.trim().isEmpty()) { // TODO : Validate the format, like valid IP address or // hostname. - throw new InvalidParameterException("Unable to initialize. Please specify a valid ElastiCenter IP Address or Hostname."); + throw new InvalidParameterValueException("Unable to initialize. Please specify a valid ElastiCenter IP Address or Hostname."); } if (ignoreSSLCertificate) { @@ -1142,7 +1143,7 @@ public Object executeCommand(String command, List> params, } if (command == null || command.trim().isEmpty()) { - throw new InvalidParameterException("No command to execute."); + throw new InvalidParameterValueException("No command to execute."); } try { @@ -1174,9 +1175,9 @@ public Object executeCommand(String command, List> params, if (401 == response.getStatus()) { throw new InvalidCredentialsException("Please specify a valid API Key."); } else if (431 == response.getStatus()) { - throw new InvalidParameterException(response.getHeaders().getFirst("X-Description")); + throw new InvalidParameterValueException(response.getHeaders().getFirst("X-Description")); } else if (432 == response.getStatus()) { - throw new InvalidParameterException(command + " does not exist on the ElastiCenter server. Please specify a valid command or contact your ElastiCenter Administrator."); + throw new InvalidParameterValueException(command + " does not exist on the ElastiCenter server. Please specify a valid command or contact your ElastiCenter Administrator."); } else { throw new ServiceUnavailableException("Internal Error. Please contact your ElastiCenter Administrator."); } @@ -2498,7 +2499,7 @@ public static UpdateTsmStorageCmdResponse updateElastistorTsmStorage(String capa }else{ quotasize = String.valueOf(quotasize) + "G"; } - s_logger.info("elastistor tsm storage is updating to " + quotasize); + LOGGER.info("elastistor tsm storage is updating to " + quotasize); UpdateTsmStorageCmd updateTsmStorageCmd = new UpdateTsmStorageCmd(); updateTsmStorageCmd.putCommandParameter("id", uuid); @@ -2565,7 +2566,7 @@ public String getsize(){ // update the TSM IOPS public static UpdateTsmCmdResponse updateElastistorTsmIOPS(String capacityIOPs,String uuid) throws Throwable{ - s_logger.info("elastistor tsm IOPS is updating to " + capacityIOPs); + LOGGER.info("elastistor tsm IOPS is updating to " + capacityIOPs); UpdateTsmCmd updateTsmCmd = new UpdateTsmCmd(); String throughput = String.valueOf(Long.parseLong(capacityIOPs)*4); diff --git a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ElastistorVolumeApiServiceImpl.java b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ElastistorVolumeApiServiceImpl.java index 709c1fe42658..83f7356eb440 100644 --- a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ElastistorVolumeApiServiceImpl.java +++ b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ElastistorVolumeApiServiceImpl.java @@ -26,7 +26,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.api.response.ListResponse; @@ -47,7 +46,6 @@ @Component public class ElastistorVolumeApiServiceImpl extends ManagerBase implements ElastistorVolumeApiService { - private static final Logger s_logger = Logger.getLogger(ElastistorVolumeApiServiceImpl.class); @Inject protected VolumeDao _volsDao; @@ -74,7 +72,7 @@ public List> getCommands() { cmdList.add(ListElastistorPoolCmd.class); cmdList.add(ListElastistorInterfaceCmd.class); - s_logger.info("Commands were registered successfully with elastistor volume api service. [cmdcount:" + cmdList.size() + "]"); + logger.info("Commands were registered successfully with elastistor volume api service. [cmdcount:" + cmdList.size() + "]"); return cmdList; } @@ -125,7 +123,7 @@ public ListResponse listElastistorVolume(ListElast return response; } catch (Throwable e) { - s_logger.error("Unable to list elastistor volume.", e); + logger.error("Unable to list elastistor volume.", e); throw new CloudRuntimeException("Unable to list elastistor volume. " + e.getMessage()); } } @@ -165,7 +163,7 @@ public ListResponse listElastistorPools(ListElastist return response; } catch (Throwable e) { - s_logger.error("Unable to list elastistor pools.", e); + logger.error("Unable to list elastistor pools.", e); throw new CloudRuntimeException("Unable to list elastistor pools. " + e.getMessage()); } @@ -199,7 +197,7 @@ public ListResponse listElastistorInterfaces(Li return response; } catch (Throwable e) { - s_logger.error("Unable to list elastistor interfaces.", e); + logger.error("Unable to list elastistor interfaces.", e); throw new CloudRuntimeException("Unable to list elastistor interfaces. " + e.getMessage()); } diff --git a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorInterfaceCmd.java b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorInterfaceCmd.java index a100f439be86..67062d23c964 100644 --- a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorInterfaceCmd.java +++ b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorInterfaceCmd.java @@ -25,11 +25,9 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; @APICommand(name = "listElastistorInterface", description = "Lists the network Interfaces of elastistor", responseObject = ListElastistorVolumeResponse.class) public class ListElastistorInterfaceCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListElastistorInterfaceCmd.class.getName()); private static final String s_name = "listElastistorInterfaceResponse"; @Inject diff --git a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorPoolCmd.java b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorPoolCmd.java index d3701b784bdc..32b1fbb64802 100644 --- a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorPoolCmd.java +++ b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorPoolCmd.java @@ -27,12 +27,10 @@ import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; @APICommand(name = "listElastistorPool", description = "Lists the pools of elastistor", responseObject = ListElastistorPoolResponse.class) public class ListElastistorPoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListElastistorPoolCmd.class.getName()); private static final String s_name = "listElastistorPoolResponse"; @Inject diff --git a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorVolumeCmd.java b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorVolumeCmd.java index d2b89e388d29..4c55f8c32096 100644 --- a/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorVolumeCmd.java +++ b/plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/util/ListElastistorVolumeCmd.java @@ -26,11 +26,9 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; @APICommand(name = "listElastistorVolume", description = "Lists the volumes of elastistor", responseObject = ListElastistorVolumeResponse.class) public class ListElastistorVolumeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListElastistorVolumeCmd.class.getName()); private static final String s_name = "listElastistorVolumeResponse"; @Inject diff --git a/plugins/storage/volume/datera/pom.xml b/plugins/storage/volume/datera/pom.xml index e68501fa8fb9..3007095a1ad9 100644 --- a/plugins/storage/volume/datera/pom.xml +++ b/plugins/storage/volume/datera/pom.xml @@ -1,12 +1,12 @@ - @@ -16,7 +16,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/driver/DateraPrimaryDataStoreDriver.java b/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/driver/DateraPrimaryDataStoreDriver.java index b331249243ff..6423b07a909a 100644 --- a/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/driver/DateraPrimaryDataStoreDriver.java +++ b/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/driver/DateraPrimaryDataStoreDriver.java @@ -47,7 +47,8 @@ import org.apache.cloudstack.storage.datastore.util.DateraUtil; import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataObjectType; @@ -87,7 +88,7 @@ import static com.cloud.utils.NumbersUtil.toHumanReadableSize; public class DateraPrimaryDataStoreDriver implements PrimaryDataStoreDriver { - private static final Logger s_logger = Logger.getLogger(DateraPrimaryDataStoreDriver.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int s_lockTimeInSeconds = 300; private static final int s_lowestHypervisorSnapshotReserve = 10; @@ -166,7 +167,7 @@ public DateraObject.AppInstance getDateraAppInstance(DateraObject.DateraConnecti try { appInstance = DateraUtil.getAppInstance(conn, appInstanceName); } catch (DateraObject.DateraError dateraError) { - s_logger.warn("Error getting appInstance " + appInstanceName, dateraError); + logger.warn("Error getting appInstance " + appInstanceName, dateraError); throw new CloudRuntimeException(dateraError.getMessage()); } @@ -192,7 +193,7 @@ public DateraObject.AppInstance getDateraAppInstance(DateraObject.DateraConnecti @Override public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore) { - s_logger.debug("grantAccess() called"); + logger.debug("grantAccess() called"); Preconditions.checkArgument(dataObject != null, "'dataObject' should not be 'null'"); Preconditions.checkArgument(host != null, "'host' should not be 'null'"); @@ -214,7 +215,7 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid()); if (!lock.lock(s_lockTimeInSeconds)) { - s_logger.debug("Couldn't lock the DB (in grantAccess) on the following string: " + cluster.getUuid()); + logger.debug("Couldn't lock the DB (in grantAccess) on the following string: " + cluster.getUuid()); } try { @@ -225,18 +226,18 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore List hosts = _hostDao.findByClusterId(clusterId); if (!DateraUtil.hostsSupport_iScsi(hosts)) { - s_logger.debug("hostsSupport_iScsi() :Host does NOT support iscsci"); + logger.debug("hostsSupport_iScsi() :Host does NOT support iscsci"); return false; } // We don't have the initiator group, create one String initiatorGroupName = DateraUtil.INITIATOR_GROUP_PREFIX + "-" + cluster.getUuid(); - s_logger.debug("Will use initiator group " + String.valueOf(initiatorGroupName)); + logger.debug("Will use initiator group " + String.valueOf(initiatorGroupName)); initiatorGroup = DateraUtil.getInitiatorGroup(conn, initiatorGroupName); if (initiatorGroup == null) { - s_logger.debug("create initiator group " + String.valueOf(initiatorGroupName)); + logger.debug("create initiator group " + String.valueOf(initiatorGroupName)); initiatorGroup = DateraUtil.createInitiatorGroup(conn, initiatorGroupName); // Save it to the DB ClusterDetailsVO clusterDetail = new ClusterDetailsVO(clusterId, initiatorGroupKey, initiatorGroupName); @@ -265,17 +266,17 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore Preconditions.checkArgument(isInitiatorGroupAssignedToAppInstance(conn, initiatorGroup, appInstance), "Initgroup is not assigned to appinstance"); // FIXME: Sleep anyways - s_logger.debug("sleep " + String.valueOf(DateraUtil.POLL_TIMEOUT_MS) + " msec for ACL to be applied"); + logger.debug("sleep " + String.valueOf(DateraUtil.POLL_TIMEOUT_MS) + " msec for ACL to be applied"); Thread.sleep(DateraUtil.POLL_TIMEOUT_MS); // ms - s_logger.debug( + logger.debug( "Initiator group " + String.valueOf(initiatorGroupName) + " is assigned to " + appInstanceName); } return true; } catch (DateraObject.DateraError | UnsupportedEncodingException | InterruptedException dateraError) { - s_logger.warn(dateraError.getMessage(), dateraError); + logger.warn(dateraError.getMessage(), dateraError); throw new CloudRuntimeException("Unable to grant access to volume " + dateraError.getMessage()); } finally { lock.unlock(); @@ -301,13 +302,13 @@ private void addClusterHostsToInitiatorGroup(DateraObject.DateraConnection conn, initiatorName = DateraUtil.INITIATOR_PREFIX + "-" + host.getUuid(); initiator = DateraUtil.createInitiator(conn, initiatorName, iqn); - s_logger.debug("Initiator " + initiatorName + " with " + iqn + "added "); + logger.debug("Initiator " + initiatorName + " with " + iqn + "added "); } Preconditions.checkNotNull(initiator); if (!DateraUtil.isInitiatorPresentInGroup(initiator, initiatorGroup)) { - s_logger.debug("Add " + initiatorName + " to " + initiatorGroupName); + logger.debug("Add " + initiatorName + " to " + initiatorGroupName); DateraUtil.addInitiatorToGroup(conn, initiator.getPath(), initiatorGroupName); } } @@ -349,7 +350,7 @@ private boolean isInitiatorGroupAssignedToAppInstance(DateraObject.DateraConnect */ @Override public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) { - s_logger.debug("revokeAccess() called"); + logger.debug("revokeAccess() called"); Preconditions.checkArgument(dataObject != null, "'dataObject' should not be 'null'"); Preconditions.checkArgument(host != null, "'host' should not be 'null'"); @@ -364,7 +365,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid()); if (!lock.lock(s_lockTimeInSeconds)) { - s_logger.debug("Couldn't lock the DB (in revokeAccess) on the following string: " + cluster.getUuid()); + logger.debug("Couldn't lock the DB (in revokeAccess) on the following string: " + cluster.getUuid()); } try { @@ -388,7 +389,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) } catch (DateraObject.DateraError | UnsupportedEncodingException | InterruptedException dateraError) { String errMesg = "Error revoking access for Volume : " + dataObject.getId(); - s_logger.warn(errMesg, dateraError); + logger.warn(errMesg, dateraError); throw new CloudRuntimeException(errMesg); } finally { lock.unlock(); @@ -461,7 +462,7 @@ private String getAppInstanceName(DataObject dataObject) { name.add(dataObject.getUuid()); // 6db58e3f-14c4-45ac-95e9-60e3a00ce7d0 VolumeVO volumeVo = _volumeDao.findById(dataObject.getId()); - s_logger.debug("volumeName : " + volumeName); + logger.debug("volumeName : " + volumeName); break; case SNAPSHOT: @@ -541,7 +542,7 @@ private String getIpPool(long storagePoolId) { if (storagePoolDetail != null) { ipPool = storagePoolDetail.getValue(); } - s_logger.debug("ipPool: " + ipPool); + logger.debug("ipPool: " + ipPool); return ipPool; } @@ -588,7 +589,7 @@ private long getUsedBytes(StoragePool storagePool, long volumeIdToIgnore) { } } catch (DateraObject.DateraError dateraError) { String errMesg = "Error getting used bytes for storage pool : " + storagePool.getId(); - s_logger.warn(errMesg, dateraError); + logger.warn(errMesg, dateraError); throw new CloudRuntimeException(errMesg); } } @@ -623,7 +624,7 @@ private long getUsedBytes(StoragePool storagePool, long volumeIdToIgnore) { usedSpaceBytes += templatePoolRef.getTemplateSize(); } } - s_logger.debug("usedSpaceBytes: " + toHumanReadableSize(usedSpaceBytes)); + logger.debug("usedSpaceBytes: " + toHumanReadableSize(usedSpaceBytes)); return usedSpaceBytes; } @@ -664,7 +665,7 @@ public long getDataObjectSizeIncludingHypervisorSnapshotReserve(DataObject dataO hypervisorSnapshotReserve = Math.max(hypervisorSnapshotReserve, s_lowestHypervisorSnapshotReserve); volumeSize += volumeSize * (hypervisorSnapshotReserve / 100f); } - s_logger.debug("Volume size: " + toHumanReadableSize(volumeSize)); + logger.debug("Volume size: " + toHumanReadableSize(volumeSize)); break; case TEMPLATE: @@ -677,7 +678,7 @@ public long getDataObjectSizeIncludingHypervisorSnapshotReserve(DataObject dataO } else { volumeSize = (long) (templateSize + templateSize * (s_lowestHypervisorSnapshotReserve / 100f)); } - s_logger.debug("Template volume size:" + toHumanReadableSize(volumeSize)); + logger.debug("Template volume size:" + toHumanReadableSize(volumeSize)); break; } @@ -723,7 +724,7 @@ private void deleteVolume(VolumeInfo volumeInfo, long storagePoolId) { } catch (UnsupportedEncodingException | DateraObject.DateraError e) { String errMesg = "Error deleting app instance for Volume : " + volumeInfo.getId(); - s_logger.warn(errMesg, e); + logger.warn(errMesg, e); throw new CloudRuntimeException(errMesg); } } @@ -750,7 +751,7 @@ private void deleteVolume(VolumeInfo volumeInfo, long storagePoolId) { */ private String createVolume(VolumeInfo volumeInfo, long storagePoolId) { - s_logger.debug("createVolume() called"); + logger.debug("createVolume() called"); Preconditions.checkArgument(volumeInfo != null, "volumeInfo cannot be null"); Preconditions.checkArgument(storagePoolId > 0, "storagePoolId should be > 0"); @@ -763,20 +764,20 @@ private String createVolume(VolumeInfo volumeInfo, long storagePoolId) { long csSnapshotId = getCsIdForCloning(volumeInfo.getId(), "cloneOfSnapshot"); long csTemplateId = getCsIdForCloning(volumeInfo.getId(), "cloneOfTemplate"); - s_logger.debug("csTemplateId is " + String.valueOf(csTemplateId)); + logger.debug("csTemplateId is " + String.valueOf(csTemplateId)); try { if (csSnapshotId > 0) { // creating volume from snapshot. The snapshot could either be a native snapshot // or another volume. - s_logger.debug("Creating volume from snapshot "); + logger.debug("Creating volume from snapshot "); appInstance = createDateraClone(conn, csSnapshotId, volumeInfo, storagePoolId, DataObjectType.SNAPSHOT); } else if (csTemplateId > 0) { // create volume from template. Invoked when creating new ROOT volume - s_logger.debug("Creating volume from template "); + logger.debug("Creating volume from template "); appInstance = createDateraClone(conn, csTemplateId, volumeInfo, storagePoolId, DataObjectType.TEMPLATE); String appInstanceName = appInstance.getName(); @@ -805,18 +806,18 @@ private String createVolume(VolumeInfo volumeInfo, long storagePoolId) { } else { // Just create a standard volume - s_logger.debug("Creating a standard volume "); + logger.debug("Creating a standard volume "); appInstance = createDateraVolume(conn, volumeInfo, storagePoolId); } } catch (UnsupportedEncodingException | DateraObject.DateraError e) { String errMesg = "Unable to create Volume Error: " + e.getMessage(); - s_logger.warn(errMesg); + logger.warn(errMesg); throw new CloudRuntimeException(errMesg, e); } if (appInstance == null) { String errMesg = "appInstance returned null"; - s_logger.warn(errMesg); + logger.warn(errMesg); throw new CloudRuntimeException(errMesg); } @@ -825,8 +826,8 @@ private String createVolume(VolumeInfo volumeInfo, long storagePoolId) { String iqnPath = DateraUtil.generateIqnPath(iqn); VolumeVO volumeVo = _volumeDao.findById(volumeInfo.getId()); - s_logger.debug("volume ID : " + volumeInfo.getId()); - s_logger.debug("volume uuid : " + volumeInfo.getUuid()); + logger.debug("volume ID : " + volumeInfo.getId()); + logger.debug("volume uuid : " + volumeInfo.getUuid()); volumeVo.set_iScsiName(iqnPath); volumeVo.setFolder(appInstance.getName()); @@ -862,7 +863,7 @@ private String createVolume(VolumeInfo volumeInfo, long storagePoolId) { private DateraObject.AppInstance createDateraVolume(DateraObject.DateraConnection conn, VolumeInfo volumeInfo, long storagePoolId) throws UnsupportedEncodingException, DateraObject.DateraError { - s_logger.debug("createDateraVolume() called"); + logger.debug("createDateraVolume() called"); DateraObject.AppInstance appInstance = null; try { @@ -895,8 +896,8 @@ private DateraObject.AppInstance createDateraVolume(DateraObject.DateraConnectio replicas, volumePlacement, ipPool); } } catch (Exception ex) { - s_logger.debug("createDateraVolume() failed"); - s_logger.error(ex); + logger.debug("createDateraVolume() failed"); + logger.error(ex); } return appInstance; } @@ -918,7 +919,7 @@ private DateraObject.AppInstance createDateraClone(DateraObject.DateraConnection VolumeInfo volumeInfo, long storagePoolId, DataObjectType dataType) throws UnsupportedEncodingException, DateraObject.DateraError { - s_logger.debug("createDateraClone() called"); + logger.debug("createDateraClone() called"); String clonedAppInstanceName = getAppInstanceName(volumeInfo); String baseAppInstanceName = null; @@ -930,7 +931,7 @@ private DateraObject.AppInstance createDateraClone(DateraObject.DateraConnection // Clone volume from a snapshot if (snapshotDetails != null && snapshotDetails.getValue() != null) { - s_logger.debug("Clone volume from a snapshot"); + logger.debug("Clone volume from a snapshot"); appInstance = DateraUtil.cloneAppInstanceFromSnapshot(conn, clonedAppInstanceName, snapshotDetails.getValue(), ipPool); @@ -951,14 +952,14 @@ private DateraObject.AppInstance createDateraClone(DateraObject.DateraConnection } else { // Clone volume from an appInstance - s_logger.debug("Clone volume from an appInstance"); + logger.debug("Clone volume from an appInstance"); snapshotDetails = snapshotDetailsDao.findDetail(dataObjectId, DateraUtil.VOLUME_ID); baseAppInstanceName = snapshotDetails.getValue(); } } else if (dataType == DataObjectType.TEMPLATE) { - s_logger.debug("Clone volume from a template"); + logger.debug("Clone volume from a template"); VMTemplateStoragePoolVO templatePoolRef = tmpltPoolDao.findByPoolTemplate(storagePoolId, dataObjectId, null); @@ -996,7 +997,7 @@ private DateraObject.AppInstance createDateraClone(DateraObject.DateraConnection throw new CloudRuntimeException("Unable to create an app instance from snapshot or template " + volumeInfo.getId() + " type " + dataType); } - s_logger.debug("Datera - Cloned " + baseAppInstanceName + " to " + clonedAppInstanceName); + logger.debug("Datera - Cloned " + baseAppInstanceName + " to " + clonedAppInstanceName); return appInstance; } @@ -1013,7 +1014,7 @@ private DateraObject.AppInstance createDateraClone(DateraObject.DateraConnection * @param storagePoolId primary store ID */ private void createTempVolume(SnapshotInfo snapshotInfo, long storagePoolId) { - s_logger.debug("createTempVolume() from snapshot called"); + logger.debug("createTempVolume() from snapshot called"); String ipPool = getIpPool(storagePoolId); long csSnapshotId = snapshotInfo.getId(); @@ -1043,14 +1044,14 @@ private void createTempVolume(SnapshotInfo snapshotInfo, long storagePoolId) { DateraUtil.pollAppInstanceAvailable(conn, clonedAppInstanceName); } catch (DateraObject.DateraError | UnsupportedEncodingException e) { String errMesg = "Unable to create temp volume " + csSnapshotId + "Error:" + e.getMessage(); - s_logger.error(errMesg, e); + logger.error(errMesg, e); throw new CloudRuntimeException(errMesg, e); } if (clonedAppInstance == null) { throw new CloudRuntimeException("Unable to clone volume for snapshot " + snapshotName); } - s_logger.debug("Temp app_instance " + clonedAppInstanceName + " created"); + logger.debug("Temp app_instance " + clonedAppInstanceName + " created"); addTempVolumeToDb(csSnapshotId, clonedAppInstanceName); handleSnapshotDetails(csSnapshotId, DiskTO.IQN, DateraUtil.generateIqnPath(clonedAppInstance.getIqn())); @@ -1059,7 +1060,7 @@ private void createTempVolume(SnapshotInfo snapshotInfo, long storagePoolId) { snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.VOLUME_ID); try { - s_logger.debug("Deleting temp app_instance " + snapshotDetails.getValue()); + logger.debug("Deleting temp app_instance " + snapshotDetails.getValue()); DateraUtil.deleteAppInstance(conn, snapshotDetails.getValue()); } catch (UnsupportedEncodingException | DateraObject.DateraError dateraError) { String errMesg = "Error deleting temp volume " + dateraError.getMessage(); @@ -1085,7 +1086,7 @@ private void createTempVolume(SnapshotInfo snapshotInfo, long storagePoolId) { * @return IQN of the template volume */ public String createTemplateVolume(TemplateInfo templateInfo, long storagePoolId) { - s_logger.debug("createTemplateVolume() as cache template called"); + logger.debug("createTemplateVolume() as cache template called"); verifySufficientBytesForStoragePool(templateInfo, storagePoolId); @@ -1098,7 +1099,7 @@ public String createTemplateVolume(TemplateInfo templateInfo, long storagePoolId long templateSizeBytes = getDataObjectSizeIncludingHypervisorSnapshotReserve(templateInfo, storagePoolDao.findById(storagePoolId)); - s_logger.debug("cached VM template sizeBytes: " + toHumanReadableSize(templateSizeBytes)); + logger.debug("cached VM template sizeBytes: " + toHumanReadableSize(templateSizeBytes)); int templateSizeGib = DateraUtil.bytesToGib(templateSizeBytes); @@ -1108,7 +1109,7 @@ public String createTemplateVolume(TemplateInfo templateInfo, long storagePoolId String volumePlacement = getVolPlacement(storagePoolId); String ipPool = getIpPool(storagePoolId); - s_logger.debug("cached VM template app_instance: " + appInstanceName + " ipPool: " + ipPool + " sizeGib: " + String.valueOf(templateSizeGib)); + logger.debug("cached VM template app_instance: " + appInstanceName + " ipPool: " + ipPool + " sizeGib: " + String.valueOf(templateSizeGib)); DateraObject.AppInstance appInstance = DateraUtil.createAppInstance(conn, appInstanceName, templateSizeGib, templateIops, replicaCount, volumePlacement, ipPool); @@ -1140,10 +1141,10 @@ public String createTemplateVolume(TemplateInfo templateInfo, long storagePoolId } catch (UnsupportedEncodingException | DateraObject.DateraError dateraError) { if (DateraObject.DateraErrorTypes.ConflictError.equals(dateraError)) { String errMesg = "template app Instance " + appInstanceName + " exists"; - s_logger.debug(errMesg, dateraError); + logger.debug(errMesg, dateraError); } else { String errMesg = "Unable to create template app Instance " + dateraError.getMessage(); - s_logger.error(errMesg, dateraError); + logger.error(errMesg, dateraError); throw new CloudRuntimeException(errMesg, dateraError); } } @@ -1166,22 +1167,22 @@ public void createAsync(DataStore dataStore, DataObject dataObject, try { if (dataObject.getType() == DataObjectType.VOLUME) { - s_logger.debug("createAsync - creating volume"); + logger.debug("createAsync - creating volume"); iqn = createVolume((VolumeInfo) dataObject, dataStore.getId()); } else if (dataObject.getType() == DataObjectType.SNAPSHOT) { - s_logger.debug("createAsync - creating snapshot"); + logger.debug("createAsync - creating snapshot"); createTempVolume((SnapshotInfo) dataObject, dataStore.getId()); } else if (dataObject.getType() == DataObjectType.TEMPLATE) { - s_logger.debug("createAsync - creating template"); + logger.debug("createAsync - creating template"); iqn = createTemplateVolume((TemplateInfo) dataObject, dataStore.getId()); } else { errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync"; - s_logger.error(errMsg); + logger.error(errMsg); } } catch (Exception ex) { errMsg = ex.getMessage(); - s_logger.error(errMsg); + logger.error(errMsg); if (callback == null) { throw ex; @@ -1228,13 +1229,13 @@ public void deleteAsync(DataStore dataStore, DataObject dataObject, try { if (dataObject.getType() == DataObjectType.VOLUME) { - s_logger.debug("deleteAsync - deleting volume"); + logger.debug("deleteAsync - deleting volume"); deleteVolume((VolumeInfo) dataObject, dataStore.getId()); } else if (dataObject.getType() == DataObjectType.SNAPSHOT) { - s_logger.debug("deleteAsync - deleting snapshot"); + logger.debug("deleteAsync - deleting snapshot"); deleteSnapshot((SnapshotInfo) dataObject, dataStore.getId()); } else if (dataObject.getType() == DataObjectType.TEMPLATE) { - s_logger.debug("deleteAsync - deleting template"); + logger.debug("deleteAsync - deleting template"); deleteTemplate((TemplateInfo) dataObject, dataStore.getId()); } else { errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync"; @@ -1242,7 +1243,7 @@ public void deleteAsync(DataStore dataStore, DataObject dataObject, } catch (Exception ex) { errMsg = ex.getMessage(); - s_logger.error(errMsg); + logger.error(errMsg); } CommandResult result = new CommandResult(); @@ -1280,7 +1281,7 @@ public boolean canCopy(DataObject srcData, DataObject destData) { */ @Override public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback callback) { - s_logger.debug("takeSnapshot() called"); + logger.debug("takeSnapshot() called"); CreateCmdResult result; @@ -1305,7 +1306,7 @@ public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback dsInfos) { // uuid = DateraUtil.PROVIDER_NAME + "_" + cluster.getUuid() + "_" + storageVip // + "_" + clusterAdminUsername + "_" + numReplicas + "_" + volPlacement; uuid = DateraUtil.PROVIDER_NAME + "_" + clusterUuid + "_" + randomString; - s_logger.debug("Datera - Setting Datera cluster-wide primary storage uuid to " + uuid); + logger.debug("Datera - Setting Datera cluster-wide primary storage uuid to " + uuid); parameters.setPodId(podId); parameters.setClusterId(clusterId); @@ -152,7 +149,7 @@ public DataStore initialize(Map dsInfos) { // "_" + clusterAdminUsername + "_" + numReplicas + "_" + volPlacement; uuid = DateraUtil.PROVIDER_NAME + "_" + zoneUuid + "_" + randomString; - s_logger.debug("Datera - Setting Datera zone-wide primary storage uuid to " + uuid); + logger.debug("Datera - Setting Datera zone-wide primary storage uuid to " + uuid); } if (capacityBytes == null || capacityBytes <= 0) { throw new IllegalArgumentException("'capacityBytes' must be present and greater than 0."); @@ -164,9 +161,9 @@ public DataStore initialize(Map dsInfos) { if (domainName == null) { domainName = "ROOT"; - s_logger.debug("setting the domain to ROOT"); + logger.debug("setting the domain to ROOT"); } - s_logger.debug("Datera - domainName: " + domainName); + logger.debug("Datera - domainName: " + domainName); parameters.setHost(storageVip); parameters.setPort(storagePort); @@ -203,7 +200,7 @@ public DataStore initialize(Map dsInfos) { lClusterDefaultMinIops = Long.parseLong(clusterDefaultMinIops); } } catch (NumberFormatException ex) { - s_logger.warn("Cannot parse the setting of " + DateraUtil.CLUSTER_DEFAULT_MIN_IOPS + logger.warn("Cannot parse the setting of " + DateraUtil.CLUSTER_DEFAULT_MIN_IOPS + ", using default value: " + lClusterDefaultMinIops + ". Exception: " + ex); } @@ -214,7 +211,7 @@ public DataStore initialize(Map dsInfos) { lClusterDefaultMaxIops = Long.parseLong(clusterDefaultMaxIops); } } catch (NumberFormatException ex) { - s_logger.warn("Cannot parse the setting of " + DateraUtil.CLUSTER_DEFAULT_MAX_IOPS + logger.warn("Cannot parse the setting of " + DateraUtil.CLUSTER_DEFAULT_MAX_IOPS + ", using default value: " + lClusterDefaultMaxIops + ". Exception: " + ex); } @@ -267,12 +264,12 @@ public boolean attachCluster(DataStore datastore, ClusterScope scope) { poolHosts.add(host); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + primaryDataStoreInfo, e); + logger.warn("Unable to establish a connection between " + host + " and " + primaryDataStoreInfo, e); } } if (poolHosts.isEmpty()) { - s_logger.warn("No host can access storage pool '" + primaryDataStoreInfo + "' on cluster '" + logger.warn("No host can access storage pool '" + primaryDataStoreInfo + "' on cluster '" + primaryDataStoreInfo.getClusterId() + "'."); storagePoolDao.expunge(primaryDataStoreInfo.getId()); @@ -307,7 +304,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h try { _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); + logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } diff --git a/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/provider/DateraHostListener.java b/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/provider/DateraHostListener.java index 99d0758a96a1..89ac2a9a21c3 100644 --- a/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/provider/DateraHostListener.java +++ b/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/provider/DateraHostListener.java @@ -33,7 +33,8 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.util.DateraObject; import org.apache.cloudstack.storage.datastore.util.DateraUtil; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -60,7 +61,7 @@ import com.cloud.vm.dao.VMInstanceDao; public class DateraHostListener implements HypervisorHostListener { - private static final Logger s_logger = Logger.getLogger(DateraHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private AgentManager _agentMgr; @Inject private AlertManager _alertMgr; @@ -85,7 +86,7 @@ public boolean hostConnect(long hostId, long storagePoolId) { HostVO host = _hostDao.findById(hostId); if (host == null) { - s_logger.error("Failed to add host by HostListener as host was not found with id : " + hostId); + logger.error("Failed to add host by HostListener as host was not found with id : " + hostId); return false; } StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(storagePoolId, hostId); @@ -142,7 +143,7 @@ public boolean hostRemoved(long hostId, long clusterId) { if (!lock.lock(s_lockTimeInSeconds)) { String errMsg = "Couldn't lock the DB on the following string: " + clusterVO.getUuid(); - s_logger.debug(errMsg); + logger.debug(errMsg); throw new CloudRuntimeException(errMsg); } @@ -169,7 +170,7 @@ public boolean hostRemoved(long hostId, long clusterId) { } } catch (DateraObject.DateraError | UnsupportedEncodingException e) { - s_logger.warn("Error while removing host from initiator groups ", e); + logger.warn("Error while removing host from initiator groups ", e); } finally { lock.unlock(); lock.releaseRef(); @@ -307,7 +308,7 @@ private void sendModifyStoragePoolCommand(ModifyStoragePoolCommand cmd, StorageP assert (answer instanceof ModifyStoragePoolAnswer) : "ModifyStoragePoolAnswer expected ; Pool = " + storagePool.getId() + " Host = " + hostId; - s_logger.info("Connection established between storage pool " + storagePool + " and host + " + hostId); + logger.info("Connection established between storage pool " + storagePool + " and host + " + hostId); } private List> getTargets(long clusterId, long storagePoolId) { diff --git a/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/util/DateraUtil.java b/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/util/DateraUtil.java index a1084bf9a40d..6aeedd275464 100644 --- a/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/util/DateraUtil.java +++ b/plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/util/DateraUtil.java @@ -41,7 +41,8 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -57,7 +58,7 @@ public class DateraUtil { - private static final Logger s_logger = Logger.getLogger(DateraUtil.class); + protected static Logger LOGGER = LogManager.getLogger(DateraUtil.class); private static final String API_VERSION = "v2"; public static final String PROVIDER_NAME = "Datera"; @@ -296,7 +297,7 @@ public static DateraObject.AppInstance cloneAppInstanceFromVolume(DateraObject.D public static DateraObject.AppInstance cloneAppInstanceFromVolume(DateraObject.DateraConnection conn, String name, String srcCloneName, String ipPool) throws UnsupportedEncodingException, DateraObject.DateraError { - s_logger.debug("cloneAppInstanceFromVolume() called"); + LOGGER.debug("cloneAppInstanceFromVolume() called"); DateraObject.AppInstance srcAppInstance = getAppInstance(conn, srcCloneName); if (srcAppInstance == null) { @@ -1002,7 +1003,7 @@ public static String extractIqn(String iqnPath) { final String tokens[] = iqnPath.split("/"); if (tokens.length != 3) { final String msg = "Wrong iscsi path " + iqnPath + " it should be /targetIQN/LUN"; - s_logger.warn(msg); + LOGGER.warn(msg); return null; } diff --git a/plugins/storage/volume/default/pom.xml b/plugins/storage/volume/default/pom.xml index 080688fdacfd..1778a2b5c0ff 100644 --- a/plugins/storage/volume/default/pom.xml +++ b/plugins/storage/volume/default/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java index a0aaab1d0aa1..02a28b6e947d 100644 --- a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java @@ -56,7 +56,8 @@ import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.volume.VolumeObject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.ResizeVolumeAnswer; @@ -95,7 +96,7 @@ public Map getCapabilities() { return caps; } - private static final Logger s_logger = Logger.getLogger(CloudStackPrimaryDataStoreDriverImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String NO_REMOTE_ENDPOINT_WITH_ENCRYPTION = "No remote endpoint to send command, unable to find a valid endpoint. Requires encryption support: %s"; @Inject @@ -138,8 +139,8 @@ public DataStoreTO getStoreTO(DataStore store) { } public Answer createVolume(VolumeInfo volume) throws StorageUnavailableException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Creating volume: " + volume); + if (logger.isDebugEnabled()) { + logger.debug("Creating volume: " + volume); } CreateObjectCommand cmd = new CreateObjectCommand(volume.getTO()); @@ -148,7 +149,7 @@ public Answer createVolume(VolumeInfo volume) throws StorageUnavailableException Answer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -207,7 +208,7 @@ public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCal result.setAnswer(answer); } } catch (Exception e) { - s_logger.debug("failed to create volume", e); + logger.debug("failed to create volume", e); errMsg = e.toString(); } } @@ -246,7 +247,7 @@ public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCal } if (ep == null) { String errMsg = "No remote endpoint to send DeleteCommand, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); result.setResult(errMsg); } else { Answer answer = ep.sendMessage(cmd); @@ -255,7 +256,7 @@ public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCal } } } catch (Exception ex) { - s_logger.debug("Unable to destroy volume" + data.getId(), ex); + logger.debug("Unable to destroy volume" + data.getId(), ex); result.setResult(ex.toString()); } callback.complete(result); @@ -263,7 +264,7 @@ public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCal @Override public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback callback) { - s_logger.debug(String.format("Copying volume %s(%s) to %s(%s)", srcdata.getId(), srcdata.getType(), destData.getId(), destData.getType())); + logger.debug(String.format("Copying volume %s(%s) to %s(%s)", srcdata.getId(), srcdata.getType(), destData.getId(), destData.getType())); boolean encryptionRequired = anyVolumeRequiresEncryption(srcdata, destData); DataStore store = destData.getDataStore(); if (store.getRole() == DataStoreRole.Primary) { @@ -289,10 +290,10 @@ public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCa Answer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { - s_logger.debug(String.format("Sending copy command to endpoint %s, where encryption support is %s", ep.getHostAddr(), encryptionRequired ? "required" : "not required")); + logger.debug(String.format("Sending copy command to endpoint %s, where encryption support is %s", ep.getHostAddr(), encryptionRequired ? "required" : "not required")); answer = ep.sendMessage(cmd); } CopyCommandResult result = new CopyCommandResult("", answer); @@ -304,7 +305,7 @@ public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCa CopyCmdAnswer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new CopyCmdAnswer(errMsg); } else { answer = (CopyCmdAnswer) ep.sendMessage(cmd); @@ -348,7 +349,7 @@ public boolean canCopy(DataObject srcData, DataObject destData) { @Override public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback callback) { CreateCmdResult result = null; - s_logger.debug("Taking snapshot of "+ snapshot); + logger.debug("Taking snapshot of "+ snapshot); try { SnapshotObjectTO snapshotTO = (SnapshotObjectTO) snapshot.getTO(); Object payload = snapshot.getPayload(); @@ -362,11 +363,11 @@ public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback cal ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, endpointsToRunResize, resizeCmd); if (answer != null && answer.getResult()) { long finalSize = answer.getNewSize(); - s_logger.debug("Resize: volume started at size: " + toHumanReadableSize(vol.getSize()) + " and ended at size: " + toHumanReadableSize(finalSize)); + logger.debug("Resize: volume started at size: " + toHumanReadableSize(vol.getSize()) + " and ended at size: " + toHumanReadableSize(finalSize)); vol.setSize(finalSize); vol.update(); @@ -453,12 +454,12 @@ public void resize(DataObject data, AsyncCompletionCallback cal } else if (answer != null) { result.setResult(answer.getDetails()); } else { - s_logger.debug("return a null answer, mark it as failed for unknown reason"); + logger.debug("return a null answer, mark it as failed for unknown reason"); result.setResult("return a null answer, mark it as failed for unknown reason"); } } catch (Exception e) { - s_logger.debug("sending resize command failed", e); + logger.debug("sending resize command failed", e); result.setResult(e.toString()); } finally { resizeCmd.clearPassphrase(); @@ -475,7 +476,7 @@ private void updateVolumePathDetails(VolumeObject vol, ResizeVolumeAnswer answer if (storagePoolVO != null) { volumeVO.setPoolId(storagePoolVO.getId()); } else { - s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreUUID, vol.getId())); + logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreUUID, vol.getId())); } } diff --git a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java index 4d6fc09dc572..bc66e2ff1360 100644 --- a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java +++ b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java @@ -64,7 +64,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -73,7 +72,6 @@ import java.util.UUID; public class CloudStackPrimaryDataStoreLifeCycleImpl extends BasePrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { - private static final Logger s_logger = Logger.getLogger(CloudStackPrimaryDataStoreLifeCycleImpl.class); @Inject protected ResourceManager _resourceMgr; @Inject @@ -155,8 +153,8 @@ public DataStore initialize(Map dsInfos) { String userInfo = dsInfos.get("userInfo") != null ? dsInfos.get("userInfo").toString() : null; int port = dsInfos.get("port") != null ? Integer.parseInt(dsInfos.get("port").toString()) : -1; - if (s_logger.isDebugEnabled()) { - s_logger.debug("createPool Params @ scheme - " + scheme + " storageHost - " + storageHost + " hostPath - " + hostPath + " port - " + port); + if (logger.isDebugEnabled()) { + logger.debug("createPool Params @ scheme - " + scheme + " storageHost - " + storageHost + " hostPath - " + hostPath + " port - " + port); } if (scheme.equalsIgnoreCase("nfs")) { if (port == -1) { @@ -263,7 +261,7 @@ public DataStore initialize(Map dsInfos) { parameters.setPort(port); parameters.setPath(hostPath); } else { - StoragePoolType type = Enum.valueOf(StoragePoolType.class, scheme); + StoragePoolType type = StoragePoolType.valueOf(scheme); if (type != null) { parameters.setType(type); @@ -271,7 +269,7 @@ public DataStore initialize(Map dsInfos) { parameters.setPort(0); parameters.setPath(hostPath); } else { - s_logger.warn("Unable to figure out the scheme for URI: " + scheme); + logger.warn("Unable to figure out the scheme for URI: " + scheme); throw new IllegalArgumentException("Unable to figure out the scheme for URI: " + scheme); } } @@ -299,8 +297,8 @@ public DataStore initialize(Map dsInfos) { List spHandles = primaryDataStoreDao.findIfDuplicatePoolsExistByUUID(uuid); if ((spHandles != null) && (spHandles.size() > 0)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Another active pool with the same uuid already exists"); + if (logger.isDebugEnabled()) { + logger.debug("Another active pool with the same uuid already exists"); } throw new CloudRuntimeException("Another active pool with the same uuid already exists"); } @@ -331,14 +329,14 @@ private void validateVcenterDetails(Long zoneId, Long podId, Long clusterId, Str ValidateVcenterDetailsCommand cmd = new ValidateVcenterDetailsCommand(storageHost); final Answer answer = agentMgr.easySend(h.getId(), cmd); if (answer != null && answer.getResult()) { - s_logger.info("Successfully validated vCenter details provided"); + logger.info("Successfully validated vCenter details provided"); return; } else { if (answer != null) { throw new InvalidParameterValueException("Provided vCenter server details does not match with the existing vCenter in zone id: " + zoneId); } else { String msg = "Can not validate vCenter through host " + h.getId() + " due to ValidateVcenterDetailsCommand returns null"; - s_logger.warn(msg); + logger.warn(msg); } } } @@ -346,14 +344,14 @@ private void validateVcenterDetails(Long zoneId, Long podId, Long clusterId, Str } protected boolean createStoragePool(long hostId, StoragePool pool) { - s_logger.debug("creating pool " + pool.getName() + " on host " + hostId); + logger.debug("creating pool " + pool.getName() + " on host " + hostId); if (pool.getPoolType() != StoragePoolType.NetworkFilesystem && pool.getPoolType() != StoragePoolType.Filesystem && pool.getPoolType() != StoragePoolType.IscsiLUN && pool.getPoolType() != StoragePoolType.Iscsi && pool.getPoolType() != StoragePoolType.VMFS && pool.getPoolType() != StoragePoolType.SharedMountPoint && pool.getPoolType() != StoragePoolType.PreSetup && pool.getPoolType() != StoragePoolType.DatastoreCluster && pool.getPoolType() != StoragePoolType.OCFS2 && pool.getPoolType() != StoragePoolType.RBD && pool.getPoolType() != StoragePoolType.CLVM && pool.getPoolType() != StoragePoolType.SMB && pool.getPoolType() != StoragePoolType.Gluster) { - s_logger.warn(" Doesn't support storage pool type " + pool.getPoolType()); + logger.warn(" Doesn't support storage pool type " + pool.getPoolType()); return false; } CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool); @@ -366,10 +364,10 @@ protected boolean createStoragePool(long hostId, StoragePool pool) { String msg = ""; if (answer != null) { msg = "Can not create storage pool through host " + hostId + " due to " + answer.getDetails(); - s_logger.warn(msg); + logger.warn(msg); } else { msg = "Can not create storage pool through host " + hostId + " due to CreateStoragePoolCommand returns null"; - s_logger.warn(msg); + logger.warn(msg); } throw new CloudRuntimeException(msg); } @@ -387,7 +385,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { } if (primarystore.getPoolType() == StoragePoolType.OCFS2 && !_ocfs2Mgr.prepareNodes(allHosts, primarystore)) { - s_logger.warn("Can not create storage pool " + primarystore + " on cluster " + primarystore.getClusterId()); + logger.warn("Can not create storage pool " + primarystore + " on cluster " + primarystore.getClusterId()); primaryDataStoreDao.expunge(primarystore.getId()); return false; } @@ -400,7 +398,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { } } - s_logger.debug("In createPool Adding the pool to each of the hosts"); + logger.debug("In createPool Adding the pool to each of the hosts"); List poolHosts = new ArrayList(); for (HostVO h : allHosts) { try { @@ -410,7 +408,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { primaryDataStoreDao.expunge(primarystore.getId()); throw new CloudRuntimeException("Storage has already been added as local storage"); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e); + logger.warn("Unable to establish a connection between " + h + " and " + primarystore, e); String reason = storageMgr.getStoragePoolMountFailureReason(e.getMessage()); if (reason != null) { throw new CloudRuntimeException(reason); @@ -419,7 +417,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { } if (poolHosts.isEmpty()) { - s_logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId()); + logger.warn("No host can access storage pool " + primarystore + " on cluster " + primarystore.getClusterId()); primaryDataStoreDao.expunge(primarystore.getId()); throw new CloudRuntimeException("Failed to access storage pool"); } @@ -431,7 +429,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { List hosts = _resourceMgr.listAllUpHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId()); - s_logger.debug("In createPool. Attaching the pool to each of the hosts."); + logger.debug("In createPool. Attaching the pool to each of the hosts."); List poolHosts = new ArrayList(); for (HostVO host : hosts) { try { @@ -441,7 +439,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Storage has already been added as local storage to host: " + host.getName()); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); + logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); String reason = storageMgr.getStoragePoolMountFailureReason(e.getMessage()); if (reason != null) { throw new CloudRuntimeException(reason); @@ -449,7 +447,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h } } if (poolHosts.isEmpty()) { - s_logger.warn("No host can access storage pool " + dataStore + " in this zone."); + logger.warn("No host can access storage pool " + dataStore + " in this zone."); primaryDataStoreDao.expunge(dataStore.getId()); throw new CloudRuntimeException("Failed to create storage pool as it is not accessible to hosts."); } @@ -496,7 +494,7 @@ public boolean deleteDataStore(DataStore store) { } } else { if (answer != null) { - s_logger.debug("Failed to delete storage pool: " + answer.getResult()); + logger.debug("Failed to delete storage pool: " + answer.getResult()); } } } @@ -522,9 +520,9 @@ public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo exis try { storageMgr.connectHostToSharedPool(scope.getScopeId(), dataStore.getId()); } catch (StorageUnavailableException ex) { - s_logger.error("Storage unavailable ",ex); + logger.error("Storage unavailable ",ex); } catch (StorageConflictException ex) { - s_logger.error("Storage already exists ",ex); + logger.error("Storage already exists ",ex); } } return true; diff --git a/plugins/storage/volume/default/src/main/resources/META-INF/cloudstack/storage-volume-default/spring-storage-volume-default-context.xml b/plugins/storage/volume/default/src/main/resources/META-INF/cloudstack/storage-volume-default/spring-storage-volume-default-context.xml index f6370511b277..de97dd921792 100644 --- a/plugins/storage/volume/default/src/main/resources/META-INF/cloudstack/storage-volume-default/spring-storage-volume-default-context.xml +++ b/plugins/storage/volume/default/src/main/resources/META-INF/cloudstack/storage-volume-default/spring-storage-volume-default-context.xml @@ -31,5 +31,5 @@ class="org.apache.cloudstack.storage.datastore.provider.CloudStackPrimaryDataStoreProviderImpl" /> - + diff --git a/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java b/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java index 1939dc26db2a..924c98b7912f 100644 --- a/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java +++ b/plugins/storage/volume/default/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImplTest.java @@ -56,15 +56,15 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; /** diff --git a/plugins/storage/volume/flasharray/pom.xml b/plugins/storage/volume/flasharray/pom.xml index 5895496b741a..91c3f6add5c0 100644 --- a/plugins/storage/volume/flasharray/pom.xml +++ b/plugins/storage/volume/flasharray/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java b/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java index a4b335a260a2..715379daf86d 100644 --- a/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java +++ b/plugins/storage/volume/flasharray/src/main/java/org/apache/cloudstack/storage/datastore/adapter/flasharray/FlashArrayAdapter.java @@ -57,18 +57,19 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; import org.apache.http.ssl.SSLContextBuilder; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Array API */ public class FlashArrayAdapter implements ProviderAdapter { - private Logger logger = Logger.getLogger(FlashArrayAdapter.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final String HOSTGROUP = "hostgroup"; public static final String STORAGE_POD = "pod"; diff --git a/plugins/storage/volume/linstor/pom.xml b/plugins/storage/volume/linstor/pom.xml index 5d4a7d8244a1..ad7193255e04 100644 --- a/plugins/storage/volume/linstor/pom.xml +++ b/plugins/storage/volume/linstor/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LinstorBackupSnapshotCommandWrapper.java b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LinstorBackupSnapshotCommandWrapper.java index a210d53d7e78..663b2c7d0265 100644 --- a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LinstorBackupSnapshotCommandWrapper.java +++ b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LinstorBackupSnapshotCommandWrapper.java @@ -35,7 +35,8 @@ import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.joda.time.Duration; import org.libvirt.LibvirtException; @@ -43,7 +44,7 @@ public final class LinstorBackupSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LinstorBackupSnapshotCommandWrapper.class); + protected static Logger LOGGER = LogManager.getLogger(LinstorBackupSnapshotCommandWrapper.class); private String zfsSnapdev(boolean hide, String zfsUrl) { Script script = new Script("/usr/bin/zfs", Duration.millis(5000)); @@ -67,7 +68,7 @@ static void cleanupSecondaryPool(final KVMStoragePool secondaryPool) { try { secondaryPool.delete(); } catch (final Exception e) { - s_logger.debug("Failed to delete secondary storage", e); + LOGGER.debug("Failed to delete secondary storage", e); } } } @@ -90,7 +91,7 @@ private String convertImageToQCow2( // NOTE: the qemu img will also contain the drbd metadata at the end final QemuImg qemu = new QemuImg(waitMilliSeconds); qemu.convert(srcFile, dstFile); - s_logger.info("Backup snapshot " + srcFile + " to " + dstPath); + LOGGER.info("Backup snapshot " + srcFile + " to " + dstPath); return dstPath; } @@ -107,7 +108,7 @@ private SnapshotObjectTO setCorrectSnapshotSize(final SnapshotObjectTO dst, fina @Override public CopyCmdAnswer execute(LinstorBackupSnapshotCommand cmd, LibvirtComputingResource serverResource) { - s_logger.debug("LinstorBackupSnapshotCommandWrapper: " + cmd.getSrcTO().getPath() + " -> " + cmd.getDestTO().getPath()); + LOGGER.debug("LinstorBackupSnapshotCommandWrapper: " + cmd.getSrcTO().getPath() + " -> " + cmd.getDestTO().getPath()); final SnapshotObjectTO src = (SnapshotObjectTO) cmd.getSrcTO(); final SnapshotObjectTO dst = (SnapshotObjectTO) cmd.getDestTO(); KVMStoragePool secondaryPool = null; @@ -130,7 +131,7 @@ public CopyCmdAnswer execute(LinstorBackupSnapshotCommand cmd, LibvirtComputingR // provide the linstor snapshot block device // on lvm thin this should already be there in /dev/mapper/vg-snapshotname // on zfs we need to unhide the snapshot block device - s_logger.info("Src: " + srcPath + " | " + src.getName()); + LOGGER.info("Src: " + srcPath + " | " + src.getName()); if (srcPath.startsWith("zfs://")) { zfsHidden = true; if (zfsSnapdev(false, srcPath) != null) { @@ -148,14 +149,14 @@ public CopyCmdAnswer execute(LinstorBackupSnapshotCommand cmd, LibvirtComputingR if (result != null) { return new CopyCmdAnswer("qemu-img shrink failed: " + result); } - s_logger.info("Backup shrunk " + dstPath + " to actual size " + src.getVolume().getSize()); + LOGGER.info("Backup shrunk " + dstPath + " to actual size " + src.getVolume().getSize()); SnapshotObjectTO snapshot = setCorrectSnapshotSize(dst, dstPath); return new CopyCmdAnswer(snapshot); } catch (final Exception e) { final String error = String.format("Failed to backup snapshot with id [%s] with a pool %s, due to %s", cmd.getSrcTO().getId(), cmd.getSrcTO().getDataStore().getUuid(), e.getMessage()); - s_logger.error(error); + LOGGER.error(error); return new CopyCmdAnswer(cmd, e); } finally { cleanupSecondaryPool(secondaryPool); diff --git a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LinstorRevertBackupSnapshotCommandWrapper.java b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LinstorRevertBackupSnapshotCommandWrapper.java index 511b5a40ca83..252cb6c73271 100644 --- a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LinstorRevertBackupSnapshotCommandWrapper.java +++ b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LinstorRevertBackupSnapshotCommandWrapper.java @@ -32,15 +32,12 @@ import org.apache.cloudstack.utils.qemu.QemuImg; import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; @ResourceWrapper(handles = LinstorRevertBackupSnapshotCommand.class) public final class LinstorRevertBackupSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LinstorRevertBackupSnapshotCommandWrapper.class); - private void convertQCow2ToRAW(final String srcPath, final String dstPath, int waitMilliSeconds) throws LibvirtException, QemuImgException { @@ -54,7 +51,7 @@ private void convertQCow2ToRAW(final String srcPath, final String dstPath, int w @Override public CopyCmdAnswer execute(LinstorRevertBackupSnapshotCommand cmd, LibvirtComputingResource serverResource) { - s_logger.debug("LinstorRevertBackupSnapshotCommandWrapper: " + cmd.getSrcTO().getPath() + " -> " + cmd.getDestTO().getPath()); + logger.debug("LinstorRevertBackupSnapshotCommandWrapper: " + cmd.getSrcTO().getPath() + " -> " + cmd.getDestTO().getPath()); final SnapshotObjectTO src = (SnapshotObjectTO) cmd.getSrcTO(); final VolumeObjectTO dst = (VolumeObjectTO) cmd.getDestTO(); KVMStoragePool secondaryPool = null; @@ -83,7 +80,7 @@ public CopyCmdAnswer execute(LinstorRevertBackupSnapshotCommand cmd, LibvirtComp } catch (final Exception e) { final String error = String.format("Failed to revert snapshot with id [%s] with a pool %s, due to %s", cmd.getSrcTO().getId(), cmd.getSrcTO().getDataStore().getUuid(), e.getMessage()); - s_logger.error(error); + logger.error(error); return new CopyCmdAnswer(cmd, e); } finally { LinstorBackupSnapshotCommandWrapper.cleanupSecondaryPool(secondaryPool); diff --git a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java index 659ff7bfe539..fabe2ab35368 100644 --- a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java +++ b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java @@ -32,7 +32,8 @@ import org.apache.cloudstack.utils.qemu.QemuImg; import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.LibvirtException; import com.linbit.linstor.api.ApiClient; @@ -54,9 +55,8 @@ import com.linbit.linstor.api.model.Volume; import com.linbit.linstor.api.model.VolumeDefinition; -@StorageAdaptorInfo(storagePoolType=Storage.StoragePoolType.Linstor) public class LinstorStorageAdaptor implements StorageAdaptor { - private static final Logger s_logger = Logger.getLogger(LinstorStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final Map MapStorageUuidToStoragePool = new HashMap<>(); private final String localNodeName; @@ -66,17 +66,22 @@ private DevelopersApi getLinstorAPI(KVMStoragePool pool) { return new DevelopersApi(client); } + @Override + public Storage.StoragePoolType getStoragePoolType() { + return Storage.StoragePoolType.Linstor; + } + private static String getLinstorRscName(String name) { return LinstorUtil.RSC_PREFIX + name; } private void logLinstorAnswer(@Nonnull ApiCallRc answer) { if (answer.isError()) { - s_logger.error(answer.getMessage()); + logger.error(answer.getMessage()); } else if (answer.isWarning()) { - s_logger.warn(answer.getMessage()); + logger.warn(answer.getMessage()); } else if (answer.isInfo()) { - s_logger.info(answer.getMessage()); + logger.info(answer.getMessage()); } } @@ -114,14 +119,14 @@ public KVMStoragePool getStoragePool(String uuid) { @Override public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) { - s_logger.debug("Linstor getStoragePool: " + uuid + " -> " + refreshInfo); + logger.debug("Linstor getStoragePool: " + uuid + " -> " + refreshInfo); return MapStorageUuidToStoragePool.get(uuid); } @Override public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool) { - s_logger.debug("Linstor: getPhysicalDisk for " + name); + logger.debug("Linstor: getPhysicalDisk for " + name); if (name == null) { return null; } @@ -140,7 +145,7 @@ public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool) kvmDisk.setVirtualSize(size); return kvmDisk; } catch (ApiException apiEx) { - s_logger.error(apiEx); + logger.error(apiEx); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } @@ -149,8 +154,7 @@ public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool) public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, Storage.StoragePoolType type, Map details) { - s_logger.debug(String.format( - "Linstor createStoragePool: name: '%s', host: '%s', path: %s, userinfo: %s", name, host, path, userInfo)); + logger.debug("Linstor createStoragePool: name: '{}', host: '{}', path: {}, userinfo: {}", name, host, path, userInfo); LinstorStoragePool storagePool = new LinstorStoragePool(name, host, port, userInfo, type, this); MapStorageUuidToStoragePool.put(name, storagePool); @@ -185,7 +189,7 @@ private void makeResourceAvailable(DevelopersApi api, String rscName, boolean di public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, QemuImg.PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, byte[] passphrase) { - s_logger.debug(String.format("Linstor.createPhysicalDisk: %s;%s", name, format)); + logger.debug("Linstor.createPhysicalDisk: {};{}", name, format); final String rscName = getLinstorRscName(name); LinstorStoragePool lpool = (LinstorStoragePool) pool; final DevelopersApi api = getLinstorAPI(pool); @@ -199,7 +203,7 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Qemu rgSpawn.setResourceDefinitionName(rscName); rgSpawn.addVolumeSizesItem(size / 1024); // linstor uses KiB - s_logger.info("Linstor: Spawn resource " + rscName); + logger.info("Linstor: Spawn resource " + rscName); ApiCallRcList answers = api.resourceGroupSpawn(lpool.getResourceGroup(), rgSpawn); handleLinstorApiAnswers(answers, "Linstor: Unable to spawn resource."); } @@ -217,16 +221,16 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, Qemu if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty()) { final String devPath = resources.get(0).getVolumes().get(0).getDevicePath(); - s_logger.info("Linstor: Created drbd device: " + devPath); + logger.info("Linstor: Created drbd device: " + devPath); final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devPath, name, pool); kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW); return kvmDisk; } else { - s_logger.error("Linstor: viewResources didn't return resources or volumes."); + logger.error("Linstor: viewResources didn't return resources or volumes."); throw new CloudRuntimeException("Linstor: viewResources didn't return resources or volumes."); } } catch (ApiException apiEx) { - s_logger.error(String.format("Linstor.createPhysicalDisk: ApiException: %s", apiEx.getBestMessage())); + logger.error("Linstor.createPhysicalDisk: ApiException: {}", apiEx.getBestMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } @@ -249,9 +253,8 @@ private void allow2PrimariesIfInUse(DevelopersApi api, String rscName) throws Ap rcm.setOverrideProps(props); ApiCallRcList answers = api.resourceConnectionModify(rscName, inUseNode, localNodeName, rcm); if (answers.hasError()) { - s_logger.error(String.format( - "Unable to set protocol C and 'allow-two-primaries' on %s/%s/%s", - inUseNode, localNodeName, rscName)); + logger.error("Unable to set protocol C and 'allow-two-primaries' on {}/{}/{}", + inUseNode, localNodeName, rscName); // do not fail here as adding allow-two-primaries property is only a problem while live migrating } } @@ -260,9 +263,9 @@ private void allow2PrimariesIfInUse(DevelopersApi api, String rscName) throws Ap @Override public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map details) { - s_logger.debug(String.format("Linstor: connectPhysicalDisk %s:%s -> %s", pool.getUuid(), volumePath, details)); + logger.debug("Linstor: connectPhysicalDisk {}:{} -> {}", pool.getUuid(), volumePath, details); if (volumePath == null) { - s_logger.warn("volumePath is null, ignoring"); + logger.warn("volumePath is null, ignoring"); return false; } @@ -277,7 +280,7 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map optRsc; @@ -331,7 +333,7 @@ private boolean tryDisconnectLinstor(String volumePath, KVMStoragePool pool) optRsc = getResourceByPathOrName(resources, volumePath); } catch (ApiException apiEx) { // couldn't query linstor controller - s_logger.error(apiEx.getBestMessage()); + logger.error(apiEx.getBestMessage()); return false; } @@ -344,7 +346,7 @@ private boolean tryDisconnectLinstor(String volumePath, KVMStoragePool pool) removeTwoPrimariesRcProps(api, inUseNode, rsc.getName()); } } catch (ApiException apiEx) { - s_logger.error(apiEx.getBestMessage()); + logger.error(apiEx.getBestMessage()); // do not fail here as removing allow-two-primaries property or deleting diskless isn't fatal } @@ -357,21 +359,21 @@ private boolean tryDisconnectLinstor(String volumePath, KVMStoragePool pool) logLinstorAnswers(delAnswers); } } catch (ApiException apiEx) { - s_logger.error(apiEx.getBestMessage()); + logger.error(apiEx.getBestMessage()); // do not fail here as removing allow-two-primaries property or deleting diskless isn't fatal } return true; } - s_logger.warn("Linstor: Couldn't find resource for this path: " + volumePath); + logger.warn("Linstor: Couldn't find resource for this path: " + volumePath); return false; } @Override public boolean disconnectPhysicalDisk(String volumePath, KVMStoragePool pool) { - s_logger.debug("Linstor: disconnectPhysicalDisk " + pool.getUuid() + ":" + volumePath); + logger.debug("Linstor: disconnectPhysicalDisk {}:{}", pool.getUuid(), volumePath); if (MapStorageUuidToStoragePool.containsValue(pool)) { return tryDisconnectLinstor(volumePath, pool); } @@ -382,7 +384,7 @@ public boolean disconnectPhysicalDisk(String volumePath, KVMStoragePool pool) public boolean disconnectPhysicalDisk(Map volumeToDisconnect) { // as of now this is only relevant for iscsi targets - s_logger.info("Linstor: disconnectPhysicalDisk(Map volumeToDisconnect) called?"); + logger.info("Linstor: disconnectPhysicalDisk(Map volumeToDisconnect) called?"); return false; } @@ -408,7 +410,7 @@ public boolean disconnectPhysicalDiskByPath(String localPath) Optional optFirstPool = MapStorageUuidToStoragePool.values().stream().findFirst(); if (optFirstPool.isPresent()) { - s_logger.debug("Linstor: disconnectPhysicalDiskByPath " + localPath); + logger.debug("Linstor: disconnectPhysicalDiskByPath " + localPath); final KVMStoragePool pool = optFirstPool.get(); return tryDisconnectLinstor(localPath, pool); @@ -419,12 +421,12 @@ public boolean disconnectPhysicalDiskByPath(String localPath) @Override public boolean deletePhysicalDisk(String name, KVMStoragePool pool, Storage.ImageFormat format) { - s_logger.debug("Linstor: deletePhysicalDisk " + name); + logger.debug("Linstor: deletePhysicalDisk " + name); final DevelopersApi api = getLinstorAPI(pool); try { final String rscName = getLinstorRscName(name); - s_logger.debug("Linstor: delete resource definition " + rscName); + logger.debug("Linstor: delete resource definition " + rscName); ApiCallRcList answers = api.resourceDefinitionDelete(rscName); handleLinstorApiAnswers(answers, "Linstor: Unable to delete resource definition " + rscName); } catch (ApiException apiEx) { @@ -444,7 +446,7 @@ public KVMPhysicalDisk createDiskFromTemplate( int timeout, byte[] passphrase) { - s_logger.info("Linstor: createDiskFromTemplate"); + logger.info("Linstor: createDiskFromTemplate"); return copyPhysicalDisk(template, name, destPool, timeout); } @@ -499,7 +501,7 @@ private boolean resourceSupportZeroBlocks(KVMStoragePool destPool, String resNam } ); } } catch (ApiException apiExc) { - s_logger.error(apiExc.getMessage()); + logger.error(apiExc.getMessage()); } return false; } @@ -507,7 +509,7 @@ private boolean resourceSupportZeroBlocks(KVMStoragePool destPool, String resNam @Override public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMStoragePool destPools, int timeout, byte[] srcPassphrase, byte[] destPassphrase, Storage.ProvisioningType provisioningType) { - s_logger.debug(String.format("Linstor.copyPhysicalDisk: %s -> %s", disk.getPath(), name)); + logger.debug("Linstor.copyPhysicalDisk: {} -> {}", disk.getPath(), name); final QemuImg.PhysicalDiskFormat sourceFormat = disk.getFormat(); final String sourcePath = disk.getPath(); @@ -521,11 +523,11 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt try { LinstorUtil.applyAuxProps(api, rscName, disk.getDispName(), disk.getVmName()); } catch (ApiException apiExc) { - s_logger.error(String.format("Error setting aux properties for %s", rscName)); + logger.error("Error setting aux properties for {}", rscName); logLinstorAnswers(apiExc.getApiCallRcList()); } - s_logger.debug(String.format("Linstor.copyPhysicalDisk: dstPath: %s", dstDisk.getPath())); + logger.debug("Linstor.copyPhysicalDisk: dstPath: {}", dstDisk.getPath()); final QemuImgFile destFile = new QemuImgFile(dstDisk.getPath()); destFile.setFormat(dstDisk.getFormat()); destFile.setSize(disk.getVirtualSize()); @@ -536,7 +538,7 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt final QemuImg qemu = new QemuImg(timeout, zeroedDevice, true); qemu.convert(srcFile, destFile); } catch (QemuImgException | LibvirtException e) { - s_logger.error(e); + logger.error(e); destPools.deletePhysicalDisk(name, Storage.ImageFormat.RAW); throw new CloudRuntimeException("Failed to copy " + disk.getPath() + " to " + name); } @@ -547,7 +549,7 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt @Override public boolean refresh(KVMStoragePool pool) { - s_logger.debug("Linstor: refresh"); + logger.debug("Linstor: refresh"); return true; } @@ -570,7 +572,7 @@ public KVMPhysicalDisk createDiskFromTemplateBacking( KVMStoragePool destPool, int timeout, byte[] passphrase) { - s_logger.debug("Linstor: createDiskFromTemplateBacking"); + logger.debug("Linstor: createDiskFromTemplateBacking"); return null; } @@ -579,7 +581,7 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP KVMStoragePool destPool, Storage.ImageFormat format, int timeout) { - s_logger.debug("Linstor: createTemplateFromDirectDownloadFile"); + logger.debug("Linstor: createTemplateFromDirectDownloadFile"); return null; } @@ -598,10 +600,10 @@ public long getAvailable(LinstorStoragePool pool) { .filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS) .mapToLong(sp -> sp.getFreeCapacity() != null ? sp.getFreeCapacity() : 0L).sum() * 1024; // linstor uses KiB - s_logger.debug("Linstor: getAvailable() -> " + free); + logger.debug("Linstor: getAvailable() -> " + free); return free; } catch (ApiException apiEx) { - s_logger.error(apiEx.getMessage()); + logger.error(apiEx.getMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } @@ -617,10 +619,10 @@ public long getUsed(LinstorStoragePool pool) { .mapToLong(sp -> sp.getTotalCapacity() != null && sp.getFreeCapacity() != null ? sp.getTotalCapacity() - sp.getFreeCapacity() : 0L) .sum() * 1024; // linstor uses Kib - s_logger.debug("Linstor: getUsed() -> " + used); + logger.debug("Linstor: getUsed() -> " + used); return used; } catch (ApiException apiEx) { - s_logger.error(apiEx.getMessage()); + logger.error(apiEx.getMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } diff --git a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStoragePool.java b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStoragePool.java index 4077d5dadfd0..2d6801049a3f 100644 --- a/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStoragePool.java +++ b/plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStoragePool.java @@ -34,11 +34,12 @@ import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import org.apache.cloudstack.utils.qemu.QemuImg; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.joda.time.Duration; public class LinstorStoragePool implements KVMStoragePool { - private static final Logger s_logger = Logger.getLogger(LinstorStoragePool.class); + private static final Logger LOGGER = LogManager.getLogger(LinstorStoragePool.class); private final String _uuid; private final String _sourceHost; private final int _sourcePort; @@ -226,12 +227,12 @@ public String getHearthBeatPath() { @Override public String createHeartBeatCommand(HAStoragePool pool, String hostPrivateIp, boolean hostValidation) { - s_logger.trace(String.format("Linstor.createHeartBeatCommand: %s, %s, %b", pool.getPoolIp(), hostPrivateIp, hostValidation)); + LOGGER.trace(String.format("Linstor.createHeartBeatCommand: %s, %s, %b", pool.getPoolIp(), hostPrivateIp, hostValidation)); boolean isStorageNodeUp = checkingHeartBeat(pool, null); if (!isStorageNodeUp && !hostValidation) { //restart the host - s_logger.debug(String.format("The host [%s] will be restarted because the health check failed for the storage pool [%s]", hostPrivateIp, pool.getPool().getType())); - Script cmd = new Script(pool.getPool().getHearthBeatPath(), Duration.millis(HeartBeatUpdateTimeout), s_logger); + LOGGER.debug(String.format("The host [%s] will be restarted because the health check failed for the storage pool [%s]", hostPrivateIp, pool.getPool().getType())); + Script cmd = new Script(pool.getPool().getHearthBeatPath(), Duration.millis(HeartBeatUpdateTimeout), LOGGER); cmd.add("-c"); cmd.execute(); return "Down"; @@ -247,7 +248,7 @@ public String getStorageNodeId() { static String getHostname() { OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); - Script sc = new Script("hostname", Duration.millis(10000L), s_logger); + Script sc = new Script("hostname", Duration.millis(10000L), LOGGER); String res = sc.execute(parser); if (res != null) { throw new CloudRuntimeException(String.format("Unable to run 'hostname' command: %s", res)); @@ -264,7 +265,7 @@ public Boolean checkingHeartBeat(HAStoragePool pool, HostTO host) { } else { hostName = host.getParent(); if (hostName == null) { - s_logger.error("No hostname set in host.getParent()"); + LOGGER.error("No hostname set in host.getParent()"); return false; } } @@ -273,7 +274,7 @@ public Boolean checkingHeartBeat(HAStoragePool pool, HostTO host) { } private String executeDrbdSetupStatus(OutputInterpreter.AllLinesParser parser) { - Script sc = new Script("drbdsetup", Duration.millis(HeartBeatUpdateTimeout), s_logger); + Script sc = new Script("drbdsetup", Duration.millis(HeartBeatUpdateTimeout), LOGGER); sc.add("status"); sc.add("--json"); return sc.execute(parser); @@ -293,12 +294,12 @@ private boolean checkDrbdSetupStatusOutput(String output, String otherNodeName) } } } - s_logger.warn(String.format("checkDrbdSetupStatusOutput: no resource connected to %s.", otherNodeName)); + LOGGER.warn(String.format("checkDrbdSetupStatusOutput: no resource connected to %s.", otherNodeName)); return false; } private String executeDrbdEventsNow(OutputInterpreter.AllLinesParser parser) { - Script sc = new Script("drbdsetup", Duration.millis(HeartBeatUpdateTimeout), s_logger); + Script sc = new Script("drbdsetup", Duration.millis(HeartBeatUpdateTimeout), LOGGER); sc.add("events2"); sc.add("--now"); return sc.execute(parser); @@ -307,13 +308,13 @@ private String executeDrbdEventsNow(OutputInterpreter.AllLinesParser parser) { private boolean checkDrbdEventsNowOutput(String output) { boolean healthy = output.lines().noneMatch(line -> line.matches(".*role:Primary .* promotion_score:0.*")); if (!healthy) { - s_logger.warn("checkDrbdEventsNowOutput: primary resource with promotion score==0; HA false"); + LOGGER.warn("checkDrbdEventsNowOutput: primary resource with promotion score==0; HA false"); } return healthy; } private boolean checkHostUpToDateAndConnected(String hostName) { - s_logger.trace(String.format("checkHostUpToDateAndConnected: %s/%s", localNodeName, hostName)); + LOGGER.trace(String.format("checkHostUpToDateAndConnected: %s/%s", localNodeName, hostName)); OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); if (localNodeName.equalsIgnoreCase(hostName)) { @@ -331,7 +332,7 @@ private boolean checkHostUpToDateAndConnected(String hostName) { try { return checkDrbdSetupStatusOutput(parser.getLines(), hostName); } catch (JsonIOException | JsonSyntaxException e) { - s_logger.error("Error parsing drbdsetup status --json", e); + LOGGER.error("Error parsing drbdsetup status --json", e); } } return false; @@ -339,7 +340,7 @@ private boolean checkHostUpToDateAndConnected(String hostName) { @Override public Boolean vmActivityCheck(HAStoragePool pool, HostTO host, Duration activityScriptTimeout, String volumeUUIDListString, String vmActivityCheckPath, long duration) { - s_logger.trace(String.format("Linstor.vmActivityCheck: %s, %s", pool.getPoolIp(), host.getPrivateNetwork().getIp())); + LOGGER.trace(String.format("Linstor.vmActivityCheck: %s, %s", pool.getPoolIp(), host.getPrivateNetwork().getIp())); return checkingHeartBeat(pool, host); } } diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java index 27904ed441b7..42f7f82b24f3 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java @@ -103,10 +103,11 @@ import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.storage.volume.VolumeObject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver { - private static final Logger s_logger = Logger.getLogger(LinstorPrimaryDataStoreDriverImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private PrimaryDataStoreDao _storagePoolDao; @Inject private VolumeDao _volumeDao; @Inject private VolumeDetailsDao _volumeDetailsDao; @@ -211,14 +212,14 @@ private void deleteResourceDefinition(StoragePoolVO storagePoolVO, String rscDef { for (ApiCallRc answer : answers) { - s_logger.error(answer.getMessage()); + logger.error(answer.getMessage()); } throw new CloudRuntimeException("Linstor: Unable to delete resource definition: " + rscDefName); } - s_logger.info(String.format("Linstor: Deleted resource %s", rscDefName)); + logger.info(String.format("Linstor: Deleted resource %s", rscDefName)); } catch (ApiException apiEx) { - s_logger.error("Linstor: ApiEx - " + apiEx.getMessage()); + logger.error("Linstor: ApiEx - " + apiEx.getMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } @@ -235,14 +236,14 @@ private void deleteSnapshot(@Nonnull DataStore dataStore, @Nonnull String rscDef { for (ApiCallRc answer : answers) { - s_logger.error(answer.getMessage()); + logger.error(answer.getMessage()); } throw new CloudRuntimeException("Linstor: Unable to delete snapshot: " + rscDefName); } - s_logger.info("Linstor: Deleted snapshot " + snapshotName + " for resource " + rscDefName); + logger.info("Linstor: Deleted snapshot " + snapshotName + " for resource " + rscDefName); } catch (ApiException apiEx) { - s_logger.error("Linstor: ApiEx - " + apiEx.getMessage()); + logger.error("Linstor: ApiEx - " + apiEx.getMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } @@ -260,7 +261,7 @@ private long getCsIdForCloning(long volumeId, String cloneOf) { @Override public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback callback) { - s_logger.debug("deleteAsync: " + dataObject.getType() + ";" + dataObject.getUuid()); + logger.debug("deleteAsync: " + dataObject.getType() + ";" + dataObject.getUuid()); String errMsg = null; final long storagePoolId = dataStore.getId(); @@ -301,7 +302,7 @@ public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncComplet break; default: errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync"; - s_logger.error(errMsg); + logger.error(errMsg); } if (callback != null) { @@ -314,11 +315,11 @@ public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncComplet private void logLinstorAnswer(@Nonnull ApiCallRc answer) { if (answer.isError()) { - s_logger.error(answer.getMessage()); + logger.error(answer.getMessage()); } else if (answer.isWarning()) { - s_logger.warn(answer.getMessage()); + logger.warn(answer.getMessage()); } else if (answer.isInfo()) { - s_logger.info(answer.getMessage()); + logger.info(answer.getMessage()); } } @@ -364,11 +365,11 @@ private void applyQoSSettings(StoragePoolVO storagePool, DevelopersApi api, Stri props.put("sys/fs/blkio_throttle_read_iops", "" + maxIops); props.put("sys/fs/blkio_throttle_write_iops", "" + maxIops); vdm.overrideProps(props); - s_logger.info("Apply qos setting: " + maxIops + " to " + rscName); + logger.info("Apply qos setting: " + maxIops + " to " + rscName); } else { - s_logger.info("Remove QoS setting for " + rscName); + logger.info("Remove QoS setting for " + rscName); vdm.deleteProps(Arrays.asList("sys/fs/blkio_throttle_read_iops", "sys/fs/blkio_throttle_write_iops")); } ApiCallRcList answers = api.volumeDefinitionModify(rscName, 0, vdm); @@ -381,7 +382,7 @@ private void applyQoSSettings(StoragePoolVO storagePool, DevelopersApi api, Stri long vMaxIops = maxIops != null ? maxIops : 0; long newIops = vcIops + vMaxIops; capacityIops -= newIops; - s_logger.info("Current storagepool " + storagePool.getName() + " iops capacity: " + capacityIops); + logger.info("Current storagepool " + storagePool.getName() + " iops capacity: " + capacityIops); storagePool.setCapacityIops(Math.max(0, capacityIops)); _storagePoolDao.update(storagePool.getId(), storagePool); } @@ -401,7 +402,7 @@ private String createResourceBase( try { - s_logger.info("Linstor: Spawn resource " + rscName); + logger.info("Linstor: Spawn resource " + rscName); ApiCallRcList answers = api.resourceGroupSpawn(rscGrp, rscGrpSpawn); checkLinstorAnswersThrow(answers); @@ -411,7 +412,7 @@ private String createResourceBase( return LinstorUtil.getDevicePath(api, rscName); } catch (ApiException apiEx) { - s_logger.error("Linstor: ApiEx - " + apiEx.getMessage()); + logger.error("Linstor: ApiEx - " + apiEx.getMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } @@ -431,7 +432,7 @@ private String createResource(VolumeInfo vol, StoragePoolVO storagePoolVO) { return LinstorUtil.getDevicePath(linstorApi, rscName); } catch (ApiException apiEx) { - s_logger.error("Linstor: ApiEx - " + apiEx.getMessage()); + logger.error("Linstor: ApiEx - " + apiEx.getMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } @@ -442,10 +443,10 @@ private void resizeResource(DevelopersApi api, String resourceName, long sizeByt ApiCallRcList answers = api.volumeDefinitionModify(resourceName, 0, dfm); if (answers.hasError()) { - s_logger.error("Resize error: " + answers.get(0).getMessage()); + logger.error("Resize error: " + answers.get(0).getMessage()); throw new CloudRuntimeException(answers.get(0).getMessage()); } else { - s_logger.info(String.format("Successfully resized %s to %d kib", resourceName, dfm.getSizeKib())); + logger.info(String.format("Successfully resized %s to %d kib", resourceName, dfm.getSizeKib())); } } @@ -460,7 +461,7 @@ private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolV final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePoolVO.getHostAddress()); try { - s_logger.info("Clone resource definition " + cloneRes + " to " + rscName); + logger.info("Clone resource definition " + cloneRes + " to " + rscName); ResourceDefinitionCloneRequest cloneRequest = new ResourceDefinitionCloneRequest(); cloneRequest.setName(rscName); ResourceDefinitionCloneStarted cloneStarted = linstorApi.resourceDefinitionClone( @@ -472,7 +473,7 @@ private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolV throw new CloudRuntimeException("Clone for resource " + rscName + " failed."); } - s_logger.info("Clone resource definition " + cloneRes + " to " + rscName + " finished"); + logger.info("Clone resource definition " + cloneRes + " to " + rscName + " finished"); if (volumeInfo.getSize() != null && volumeInfo.getSize() > 0) { resizeResource(linstorApi, rscName, volumeInfo.getSize()); @@ -483,7 +484,7 @@ private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolV return LinstorUtil.getDevicePath(linstorApi, rscName); } catch (ApiException apiEx) { - s_logger.error("Linstor: ApiEx - " + apiEx.getMessage()); + logger.error("Linstor: ApiEx - " + apiEx.getMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } else { @@ -513,7 +514,7 @@ private String createResourceFromSnapshot(long csSnapshotId, String rscName, Sto try { - s_logger.debug("Create new resource definition: " + rscName); + logger.debug("Create new resource definition: " + rscName); ResourceDefinitionCreate rdCreate = createResourceDefinitionCreate(rscName, rscGrp); ApiCallRcList answers = linstorApi.resourceDefinitionCreate(rdCreate); checkLinstorAnswersThrow(answers); @@ -521,12 +522,12 @@ private String createResourceFromSnapshot(long csSnapshotId, String rscName, Sto SnapshotRestore snapshotRestore = new SnapshotRestore(); snapshotRestore.toResource(rscName); - s_logger.debug("Create new volume definition for snapshot: " + cloneRes + ":" + snapName); + logger.debug("Create new volume definition for snapshot: " + cloneRes + ":" + snapName); answers = linstorApi.resourceSnapshotsRestoreVolumeDefinition(cloneRes, snapName, snapshotRestore); checkLinstorAnswersThrow(answers); // restore snapshot to new resource - s_logger.info("Restore resource from snapshot: " + cloneRes + ":" + snapName); + logger.info("Restore resource from snapshot: " + cloneRes + ":" + snapName); answers = linstorApi.resourceSnapshotRestore(cloneRes, snapName, snapshotRestore); checkLinstorAnswersThrow(answers); @@ -535,7 +536,7 @@ private String createResourceFromSnapshot(long csSnapshotId, String rscName, Sto return LinstorUtil.getDevicePath(linstorApi, rscName); } catch (ApiException apiEx) { - s_logger.error("Linstor: ApiEx - " + apiEx.getMessage()); + logger.error("Linstor: ApiEx - " + apiEx.getMessage()); throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx); } } @@ -593,7 +594,7 @@ private void createVolumeFromSnapshot(SnapshotInfo snapshotInfo, StoragePoolVO s final String tempRscName = LinstorUtil.RSC_PREFIX + csName; createResourceFromSnapshot(csSnapshotId, tempRscName, storagePoolVO); - s_logger.debug("Temp resource created: " + tempRscName); + logger.debug("Temp resource created: " + tempRscName); addTempVolumeToDb(csSnapshotId, csName); } else if (snapshotDetails != null && snapshotDetails.getValue() != null && @@ -603,7 +604,7 @@ else if (snapshotDetails != null && snapshotDetails.getValue() != null && deleteResourceDefinition(storagePoolVO, snapshotDetails.getValue()); - s_logger.debug("Temp resource deleted: " + snapshotDetails.getValue()); + logger.debug("Temp resource deleted: " + snapshotDetails.getValue()); removeTempVolumeFromDb(csSnapshotId); } else { @@ -625,7 +626,7 @@ public void createAsync(DataStore dataStore, DataObject vol, AsyncCompletionCall case VOLUME: VolumeInfo volumeInfo = (VolumeInfo) vol; VolumeVO volume = _volumeDao.findById(volumeInfo.getId()); - s_logger.debug("createAsync - creating volume"); + logger.debug("createAsync - creating volume"); devPath = createVolume(volumeInfo, storagePool); volume.setFolder("/dev/"); volume.setPoolId(storagePool.getId()); @@ -635,22 +636,22 @@ public void createAsync(DataStore dataStore, DataObject vol, AsyncCompletionCall _volumeDao.update(volume.getId(), volume); break; case SNAPSHOT: - s_logger.debug("createAsync - SNAPSHOT"); + logger.debug("createAsync - SNAPSHOT"); createVolumeFromSnapshot((SnapshotInfo) vol, storagePool); break; case TEMPLATE: errMsg = "creating template - not supported"; - s_logger.error("createAsync - " + errMsg); + logger.error("createAsync - " + errMsg); break; default: errMsg = "Invalid DataObjectType (" + vol.getType() + ") passed to createAsync"; - s_logger.error(errMsg); + logger.error(errMsg); } } catch (Exception ex) { errMsg = ex.getMessage(); - s_logger.error("createAsync: " + errMsg); + logger.error("createAsync: " + errMsg); if (callback == null) { throw ex; @@ -715,7 +716,7 @@ private String doRevertSnapshot(final SnapshotInfo snapshot, final VolumeInfo vo resultMsg = "Linstor: Snapshot revert datastore not supported"; } } catch (ApiException apiEx) { - s_logger.error("Linstor: ApiEx - " + apiEx.getMessage()); + logger.error("Linstor: ApiEx - " + apiEx.getMessage()); resultMsg = apiEx.getBestMessage(); } @@ -728,7 +729,7 @@ public void revertSnapshot( SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback callback) { - s_logger.debug("Linstor: revertSnapshot"); + logger.debug("Linstor: revertSnapshot"); final VolumeInfo volumeInfo = snapshot.getBaseVolume(); VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId()); if (volumeVO == null || volumeVO.getRemoved() != null) { @@ -773,7 +774,7 @@ private static boolean canCopyVolumeCond(DataObject srcData, DataObject dstData) @Override public boolean canCopy(DataObject srcData, DataObject dstData) { - s_logger.debug("LinstorPrimaryDataStoreDriverImpl.canCopy: " + srcData.getType() + " -> " + dstData.getType()); + logger.debug("LinstorPrimaryDataStoreDriverImpl.canCopy: " + srcData.getType() + " -> " + dstData.getType()); if (canCopySnapshotCond(srcData, dstData)) { SnapshotInfo sinfo = (SnapshotInfo) srcData; @@ -797,7 +798,7 @@ public boolean canCopy(DataObject srcData, DataObject dstData) @Override public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCallback callback) { - s_logger.debug("LinstorPrimaryDataStoreDriverImpl.copyAsync: " + logger.debug("LinstorPrimaryDataStoreDriverImpl.copyAsync: " + srcData.getType() + " -> " + dstData.getType()); final CopyCommandResult res; @@ -847,12 +848,12 @@ private Optional getLinstorEP(DevelopersApi api, String rscN for (String nodeName : linstorNodeNames) { host = _hostDao.findByName(nodeName); if (host != null && host.getResourceState() == ResourceState.Enabled) { - s_logger.info(String.format("Linstor: Make resource %s available on node %s ...", rscName, nodeName)); + logger.info(String.format("Linstor: Make resource %s available on node %s ...", rscName, nodeName)); ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, nodeName, new ResourceMakeAvailable()); if (!answers.hasError()) { break; // found working host } else { - s_logger.error( + logger.error( String.format("Linstor: Unable to make resource %s on node %s available: %s", rscName, nodeName, @@ -863,7 +864,7 @@ private Optional getLinstorEP(DevelopersApi api, String rscN if (host == null) { - s_logger.error("Linstor: Couldn't create a resource on any cloudstack host."); + logger.error("Linstor: Couldn't create a resource on any cloudstack host."); return Optional.empty(); } else @@ -882,7 +883,7 @@ private Optional getDiskfullEP(DevelopersApi api, String rsc } } } - s_logger.error("Linstor: No diskfull host found."); + logger.error("Linstor: No diskfull host found."); return Optional.empty(); } @@ -937,7 +938,7 @@ private Answer copyTemplate(DataObject srcData, DataObject dstData) { deleteResourceDefinition(pool, rscName); } } catch (ApiException exc) { - s_logger.error("copy template failed: ", exc); + logger.error("copy template failed: ", exc); deleteResourceDefinition(pool, rscName); throw new CloudRuntimeException(exc.getBestMessage()); } @@ -975,7 +976,7 @@ private Answer copyVolume(DataObject srcData, DataObject dstData) { answer = new Answer(cmd, false, "Unable to get matching Linstor endpoint."); } } catch (ApiException exc) { - s_logger.error("copy volume failed: ", exc); + logger.error("copy volume failed: ", exc); throw new CloudRuntimeException(exc.getBestMessage()); } return answer; @@ -1076,13 +1077,13 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) { if (optEP.isPresent()) { answer = optEP.get().sendMessage(cmd); } else { - s_logger.debug("No diskfull endpoint found to copy image, creating diskless endpoint"); + logger.debug("No diskfull endpoint found to copy image, creating diskless endpoint"); answer = copyFromTemporaryResource(api, pool, rscName, snapshotName, snapshotObject, cmd); } return answer; } catch (Exception e) { - s_logger.debug("copy snapshot failed: ", e); - throw new CloudRuntimeException("Copy snapshot failed, please cleanup snapshot manually: " + e); + logger.debug("copy snapshot failed, please cleanup snapshot manually: ", e); + throw new CloudRuntimeException(e.toString()); } } @@ -1091,7 +1092,7 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) { public void copyAsync(DataObject srcData, DataObject destData, Host destHost, AsyncCompletionCallback callback) { // as long as canCopy is false, this isn't called - s_logger.debug("Linstor: copyAsync with host"); + logger.debug("Linstor: copyAsync with host"); copyAsync(srcData, destData, callback); } @@ -1109,16 +1110,16 @@ private CreateCmdResult notifyResize( try { ResizeVolumeAnswer answer = (ResizeVolumeAnswer) _storageMgr.sendToPool(pool, resizeParameter.hosts, resizeCmd); if (answer != null && answer.getResult()) { - s_logger.debug("Resize: notified hosts"); + logger.debug("Resize: notified hosts"); } else if (answer != null) { result.setResult(answer.getDetails()); } else { - s_logger.debug("return a null answer, mark it as failed for unknown reason"); + logger.debug("return a null answer, mark it as failed for unknown reason"); result.setResult("return a null answer, mark it as failed for unknown reason"); } } catch (Exception e) { - s_logger.debug("sending resize command failed", e); + logger.debug("sending resize command failed", e); result.setResult(e.toString()); } @@ -1153,7 +1154,7 @@ public void resize(DataObject data, AsyncCompletionCallback cal } } catch (ApiException apiExc) { - s_logger.error(apiExc); + logger.error(apiExc); errMsg = apiExc.getBestMessage(); } @@ -1174,7 +1175,7 @@ public void handleQualityOfServiceForVolumeMigration( VolumeInfo volumeInfo, QualityOfServiceState qualityOfServiceState) { - s_logger.debug("Linstor: handleQualityOfServiceForVolumeMigration"); + logger.debug("Linstor: handleQualityOfServiceForVolumeMigration"); } private Answer createAnswerAndPerstistDetails(DevelopersApi api, SnapshotInfo snapshotInfo, String rscName) @@ -1197,7 +1198,7 @@ private Answer createAnswerAndPerstistDetails(DevelopersApi api, SnapshotInfo sn @Override public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback callback) { - s_logger.debug("Linstor: takeSnapshot with snapshot: " + snapshotInfo.getUuid()); + logger.debug("Linstor: takeSnapshot with snapshot: " + snapshotInfo.getUuid()); final VolumeInfo volumeInfo = snapshotInfo.getBaseVolume(); final VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId()); @@ -1218,12 +1219,12 @@ public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback dsInfos) { throw new CloudRuntimeException("The Zone ID must be specified."); } ClusterVO cluster = clusterDao.findById(clusterId); - s_logger.info("Linstor: Setting Linstor cluster-wide primary storage uuid to " + uuid); + logger.info("Linstor: Setting Linstor cluster-wide primary storage uuid to " + uuid); parameters.setPodId(podId); parameters.setClusterId(clusterId); @@ -177,10 +174,10 @@ public DataStore initialize(Map dsInfos) { } protected boolean createStoragePool(long hostId, StoragePool pool) { - s_logger.debug("creating pool " + pool.getName() + " on host " + hostId); + logger.debug("creating pool " + pool.getName() + " on host " + hostId); if (pool.getPoolType() != Storage.StoragePoolType.Linstor) { - s_logger.warn(" Doesn't support storage pool type " + pool.getPoolType()); + logger.warn(" Doesn't support storage pool type " + pool.getPoolType()); return false; } CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool); @@ -192,7 +189,7 @@ protected boolean createStoragePool(long hostId, StoragePool pool) { String msg = answer != null ? "Can not create storage pool through host " + hostId + " due to " + answer.getDetails() : "Can not create storage pool through host " + hostId + " due to CreateStoragePoolCommand returns null"; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } } @@ -228,12 +225,12 @@ public boolean attachCluster(DataStore dataStore, ClusterScope scope) { poolHosts.add(host); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + primaryDataStoreInfo, e); + logger.warn("Unable to establish a connection between " + host + " and " + primaryDataStoreInfo, e); } } if (poolHosts.isEmpty()) { - s_logger.warn("No host can access storage pool '" + primaryDataStoreInfo + "' on cluster '" + logger.warn("No host can access storage pool '" + primaryDataStoreInfo + "' on cluster '" + primaryDataStoreInfo.getClusterId() + "'."); _primaryDataStoreDao.expunge(primaryDataStoreInfo.getId()); @@ -259,7 +256,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h try { _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); + logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java index 9aa6f151abc7..d3a8b97cf2a5 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java @@ -38,10 +38,11 @@ import java.util.stream.Collectors; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class LinstorUtil { - private static final Logger s_logger = Logger.getLogger(LinstorUtil.class); + protected static Logger LOGGER = LogManager.getLogger(LinstorUtil.class); public final static String PROVIDER_NAME = "Linstor"; public static final String RSC_PREFIX = "cs-"; @@ -159,7 +160,7 @@ public static List getRscGroupStoragePools(DevelopersApi api, Strin if (rscGrps.isEmpty()) { final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName); - s_logger.error(errMsg); + LOGGER.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -183,7 +184,7 @@ public static long getCapacityBytes(String linstorUrl, String rscGroupName) { .mapToLong(sp -> sp.getTotalCapacity() != null ? sp.getTotalCapacity() : 0L) .sum() * 1024; // linstor uses kiB } catch (ApiException apiEx) { - s_logger.error(apiEx.getMessage()); + LOGGER.error(apiEx.getMessage()); throw new CloudRuntimeException(apiEx); } } @@ -204,8 +205,8 @@ public static String isResourceInUse(DevelopersApi api, String rscName) throws A .map(Resource::getNodeName) .findFirst() .orElse(null); - } - s_logger.error("isResourceInUse: null returned from resourceList"); + } + LOGGER.error("isResourceInUse: null returned from resourceList"); return null; } @@ -231,14 +232,14 @@ public static String getDevicePath(DevelopersApi api, String rscName) throws Api // CloudStack resource always only have 1 volume String devicePath = rsc.getVolumes().get(0).getDevicePath(); if (devicePath != null && !devicePath.isEmpty()) { - s_logger.debug(String.format("getDevicePath: %s -> %s", rscName, devicePath)); + LOGGER.debug("getDevicePath: {} -> {}", rscName, devicePath); return devicePath; } } } final String errMsg = "viewResources didn't return resources or volumes for " + rscName; - s_logger.error(errMsg); + LOGGER.error(errMsg); throw new CloudRuntimeException("Linstor: " + errMsg); } diff --git a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/snapshot/LinstorVMSnapshotStrategy.java b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/snapshot/LinstorVMSnapshotStrategy.java index daad3d5dc574..c7fe6d211903 100644 --- a/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/snapshot/LinstorVMSnapshotStrategy.java +++ b/plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/snapshot/LinstorVMSnapshotStrategy.java @@ -54,12 +54,13 @@ import org.apache.cloudstack.storage.vmsnapshot.DefaultVMSnapshotStrategy; import org.apache.cloudstack.storage.vmsnapshot.VMSnapshotHelper; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Component; @Component public class LinstorVMSnapshotStrategy extends DefaultVMSnapshotStrategy { - private static final Logger log = Logger.getLogger(LinstorVMSnapshotStrategy.class); + private static final Logger log = LogManager.getLogger(LinstorVMSnapshotStrategy.class); @Inject private VMSnapshotHelper _vmSnapshotHelper; diff --git a/plugins/storage/volume/nexenta/pom.xml b/plugins/storage/volume/nexenta/pom.xml index 1a804f980315..0ea2c4036f22 100644 --- a/plugins/storage/volume/nexenta/pom.xml +++ b/plugins/storage/volume/nexenta/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/driver/NexentaPrimaryDataStoreDriver.java b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/driver/NexentaPrimaryDataStoreDriver.java index 6c8114160efe..60f3bd2ac8d3 100644 --- a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/driver/NexentaPrimaryDataStoreDriver.java +++ b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/driver/NexentaPrimaryDataStoreDriver.java @@ -41,7 +41,8 @@ import org.apache.cloudstack.storage.datastore.util.NexentaStorAppliance; import org.apache.cloudstack.storage.datastore.util.NexentaStorAppliance.NexentaStorZvol; import org.apache.cloudstack.storage.datastore.util.NexentaUtil; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataObjectType; @@ -58,7 +59,7 @@ import com.cloud.utils.Pair; public class NexentaPrimaryDataStoreDriver implements PrimaryDataStoreDriver { - private static final Logger logger = Logger.getLogger(NexentaPrimaryDataStoreDriver.class); + protected Logger logger = LogManager.getLogger(getClass()); @Override public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore) { diff --git a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/lifecylce/NexentaPrimaryDataStoreLifeCycle.java b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/lifecylce/NexentaPrimaryDataStoreLifeCycle.java index 922803ce9dba..62995196cace 100644 --- a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/lifecylce/NexentaPrimaryDataStoreLifeCycle.java +++ b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/lifecylce/NexentaPrimaryDataStoreLifeCycle.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.storage.datastore.lifecycle.BasePrimaryDataStoreLifeCycleImpl; import org.apache.cloudstack.storage.datastore.util.NexentaUtil; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; -import org.apache.log4j.Logger; import com.cloud.agent.api.StoragePoolInfo; import com.cloud.dc.DataCenterVO; @@ -48,8 +47,6 @@ public class NexentaPrimaryDataStoreLifeCycle extends BasePrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { - private static final Logger logger = - Logger.getLogger(NexentaPrimaryDataStoreLifeCycle.class); @Inject private DataCenterDao zoneDao; diff --git a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/provider/NexentaHostListener.java b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/provider/NexentaHostListener.java index e13a7e649e77..376cd29d2eb3 100644 --- a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/provider/NexentaHostListener.java +++ b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/provider/NexentaHostListener.java @@ -18,44 +18,45 @@ */ package org.apache.cloudstack.storage.datastore.provider; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; public class NexentaHostListener implements HypervisorHostListener { - private static final Logger s_logger = Logger.getLogger(NexentaHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); @Override public boolean hostAdded(long hostId) { - s_logger.trace("hostAdded(long) invoked"); + logger.trace("hostAdded(long) invoked"); return true; } @Override public boolean hostConnect(long hostId, long poolId) { - s_logger.trace("hostConnect(long, long) invoked"); + logger.trace("hostConnect(long, long) invoked"); return true; } @Override public boolean hostDisconnected(long hostId, long poolId) { - s_logger.trace("hostDisconnected(long, long) invoked"); + logger.trace("hostDisconnected(long, long) invoked"); return true; } @Override public boolean hostAboutToBeRemoved(long hostId) { - s_logger.trace("hostAboutToBeRemoved(long) invoked"); + logger.trace("hostAboutToBeRemoved(long) invoked"); return true; } @Override public boolean hostRemoved(long hostId, long clusterId) { - s_logger.trace("hostRemoved(long) invoked"); + logger.trace("hostRemoved(long) invoked"); return true; } diff --git a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java index e1a59f78facb..73f3fa0be78d 100644 --- a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java +++ b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java @@ -43,7 +43,8 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.BasicClientConnectionManager; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.utils.security.SSLUtils; @@ -53,7 +54,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class NexentaNmsClient { - private static final Logger logger = Logger.getLogger(NexentaNmsClient.class); + protected Logger logger = LogManager.getLogger(getClass()); protected NexentaNmsUrl nmsUrl = null; protected DefaultHttpClient httpClient = null; diff --git a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/util/NexentaStorAppliance.java b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/util/NexentaStorAppliance.java index fbb6645b8e0a..8c22908c64db 100644 --- a/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/util/NexentaStorAppliance.java +++ b/plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/util/NexentaStorAppliance.java @@ -22,14 +22,14 @@ import java.util.LinkedList; import org.apache.cloudstack.storage.datastore.util.NexentaNmsClient.NmsResponse; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.exception.CloudRuntimeException; import com.google.gson.annotations.SerializedName; public class NexentaStorAppliance { - private static final Logger logger = LogManager.getLogger(NexentaStorAppliance.class); + protected Logger logger = LogManager.getLogger(getClass()); protected NexentaNmsClient client; protected NexentaUtil.NexentaPluginParameters parameters; diff --git a/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java b/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java index 749c04b8ebe6..89b5ece576ff 100644 --- a/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java +++ b/plugins/storage/volume/nexenta/src/test/java/org/apache/cloudstack/storage/datastore/util/NexentaStorApplianceTest.java @@ -43,7 +43,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.exception.CloudRuntimeException; diff --git a/plugins/storage/volume/primera/pom.xml b/plugins/storage/volume/primera/pom.xml index 905d2cd39b81..489b81dd405e 100644 --- a/plugins/storage/volume/primera/pom.xml +++ b/plugins/storage/volume/primera/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/primera/src/main/java/org/apache/cloudstack/storage/datastore/adapter/primera/PrimeraAdapter.java b/plugins/storage/volume/primera/src/main/java/org/apache/cloudstack/storage/datastore/adapter/primera/PrimeraAdapter.java index 1fdc92feedc4..2c0fccc2131f 100644 --- a/plugins/storage/volume/primera/src/main/java/org/apache/cloudstack/storage/datastore/adapter/primera/PrimeraAdapter.java +++ b/plugins/storage/volume/primera/src/main/java/org/apache/cloudstack/storage/datastore/adapter/primera/PrimeraAdapter.java @@ -53,15 +53,16 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContextBuilder; -import org.apache.log4j.Logger; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class PrimeraAdapter implements ProviderAdapter { - static final Logger logger = Logger.getLogger(PrimeraAdapter.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final String HOSTSET = "hostset"; public static final String CPG = "cpg"; diff --git a/plugins/storage/volume/sample/pom.xml b/plugins/storage/volume/sample/pom.xml index 597ed4266736..2050a6d3edab 100644 --- a/plugins/storage/volume/sample/pom.xml +++ b/plugins/storage/volume/sample/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/sample/src/main/java/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java b/plugins/storage/volume/sample/src/main/java/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java index 0b26ce0337a6..fcaa5b4f5e19 100644 --- a/plugins/storage/volume/sample/src/main/java/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/sample/src/main/java/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java @@ -20,7 +20,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; @@ -52,7 +53,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver { - private static final Logger s_logger = Logger.getLogger(SamplePrimaryDataStoreDriverImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject EndPointSelector selector; @Inject @@ -202,7 +203,7 @@ public void createAsync(DataStore dataStore, DataObject vol, AsyncCompletionCall EndPoint ep = selector.select(vol); if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } CreateObjectCommand createCmd = new CreateObjectCommand(null); diff --git a/plugins/storage/volume/scaleio/pom.xml b/plugins/storage/volume/scaleio/pom.xml index 3761be21a024..d894cea24bdc 100644 --- a/plugins/storage/volume/scaleio/pom.xml +++ b/plugins/storage/volume/scaleio/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientConnectionPool.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientConnectionPool.java index e557e0881328..a9dc8b42cd5a 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientConnectionPool.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientConnectionPool.java @@ -23,14 +23,15 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.storage.StorageManager; import com.cloud.utils.crypt.DBEncryptionUtil; import com.google.common.base.Preconditions; public class ScaleIOGatewayClientConnectionPool { - private static final Logger LOGGER = Logger.getLogger(ScaleIOGatewayClientConnectionPool.class); + protected Logger logger = LogManager.getLogger(getClass()); private ConcurrentHashMap gatewayClients; @@ -66,7 +67,7 @@ public ScaleIOGatewayClient getClient(Long storagePoolId, StoragePoolDetailsDao client = new ScaleIOGatewayClientImpl(url, username, password, false, clientTimeout, clientMaxConnections); gatewayClients.put(storagePoolId, client); - LOGGER.debug("Added gateway client for the storage pool: " + storagePoolId); + logger.debug("Added gateway client for the storage pool: " + storagePoolId); } } @@ -82,7 +83,7 @@ public boolean removeClient(Long storagePoolId) { } if (client != null) { - LOGGER.debug("Removed gateway client for the storage pool: " + storagePoolId); + logger.debug("Removed gateway client for the storage pool: " + storagePoolId); return true; } diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientImpl.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientImpl.java index 2c044d8a0ce6..62581ca066e4 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientImpl.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/client/ScaleIOGatewayClientImpl.java @@ -68,7 +68,8 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.pool.PoolStats; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.storage.Storage; import com.cloud.utils.exception.CloudRuntimeException; @@ -81,7 +82,7 @@ import com.google.common.base.Preconditions; public class ScaleIOGatewayClientImpl implements ScaleIOGatewayClient { - private static final Logger LOG = Logger.getLogger(ScaleIOGatewayClientImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private final URI apiURI; private final HttpClient httpClient; @@ -141,7 +142,7 @@ public ScaleIOGatewayClientImpl(final String url, final String username, final S this.password = password; authenticate(); - LOG.debug("API client for the PowerFlex gateway " + apiURI.getHost() + " is created successfully, with max connections: " + logger.debug("API client for the PowerFlex gateway " + apiURI.getHost() + " is created successfully, with max connections: " + maxConnections + " and timeout: " + timeout + " secs"); } @@ -155,14 +156,14 @@ private synchronized void authenticate() { HttpResponse response = null; try { authenticating = true; - LOG.debug("Authenticating gateway " + apiURI.getHost() + " with the request: " + request.toString()); + logger.debug("Authenticating gateway " + apiURI.getHost() + " with the request: " + request.toString()); response = httpClient.execute(request); if (isNullResponse(response)) { - LOG.warn("Invalid response received while authenticating, for the request: " + request.toString()); + logger.warn("Invalid response received while authenticating, for the request: " + request.toString()); throw new CloudRuntimeException("Failed to authenticate PowerFlex API Gateway due to invalid response from the Gateway " + apiURI.getHost()); } - LOG.debug("Received response: " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase() + logger.debug("Received response: " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase() + ", for the authenticate request: " + request.toString()); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new CloudRuntimeException("PowerFlex Gateway " + apiURI.getHost() + " login failed, please check the provided settings"); @@ -173,13 +174,13 @@ private synchronized void authenticate() { throw new CloudRuntimeException("Failed to create a valid session for PowerFlex Gateway " + apiURI.getHost() + " to perform API requests"); } - LOG.info("PowerFlex API Gateway " + apiURI.getHost() + " authenticated successfully"); + logger.info("PowerFlex API Gateway " + apiURI.getHost() + " authenticated successfully"); this.sessionKey = sessionKeyInResponse.replace("\"", ""); long now = System.currentTimeMillis(); createTime = lastUsedTime = now; } catch (final IOException e) { - LOG.error("Failed to authenticate PowerFlex API Gateway " + apiURI.getHost() + " due to: " + e.getMessage() + getConnectionManagerStats()); + logger.error("Failed to authenticate PowerFlex API Gateway " + apiURI.getHost() + " due to: " + e.getMessage() + getConnectionManagerStats()); throw new CloudRuntimeException("Failed to authenticate PowerFlex API Gateway " + apiURI.getHost() + " due to: " + e.getMessage()); } finally { authenticating = false; @@ -191,7 +192,7 @@ private synchronized void authenticate() { private synchronized void renewClientSessionOnExpiry() { if (isSessionExpired()) { - LOG.debug("Session expired for the PowerFlex API Gateway " + apiURI.getHost() + ", renewing"); + logger.debug("Session expired for the PowerFlex API Gateway " + apiURI.getHost() + ", renewing"); authenticate(); } } @@ -199,13 +200,13 @@ private synchronized void renewClientSessionOnExpiry() { private boolean isSessionExpired() { long now = System.currentTimeMillis() + BUFFER_TIME_IN_MILLISECS; if ((now - createTime) > MAX_VALID_SESSION_TIME_IN_MILLISECS) { - LOG.debug("Session expired for the Gateway " + apiURI.getHost() + ", token is invalid after " + MAX_VALID_SESSION_TIME_IN_HRS + logger.debug("Session expired for the Gateway " + apiURI.getHost() + ", token is invalid after " + MAX_VALID_SESSION_TIME_IN_HRS + " hours from the time it was created"); return true; } if ((now - lastUsedTime) > MAX_IDLE_TIME_IN_MILLISECS) { - LOG.debug("Session expired for the Gateway " + apiURI.getHost() + ", as there has been no activity for " + MAX_IDLE_TIME_IN_MINS + " mins"); + logger.debug("Session expired for the Gateway " + apiURI.getHost() + ", as there has been no activity for " + MAX_IDLE_TIME_IN_MINS + " mins"); return true; } @@ -214,12 +215,12 @@ private boolean isSessionExpired() { private boolean isNullResponse(final HttpResponse response) { if (response == null) { - LOG.warn("Nil response"); + logger.warn("Nil response"); return true; } if (response.getStatusLine() == null) { - LOG.warn("No status line in the response"); + logger.warn("No status line in the response"); return true; } @@ -231,7 +232,7 @@ private boolean checkAuthFailure(final HttpResponse response, final boolean rene if (!renewAndRetryOnAuthFailure) { throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, "PowerFlex Gateway API call unauthorized, please check the provided settings"); } - LOG.debug("PowerFlex Gateway API call unauthorized. Current token might be invalid, renew the session." + getConnectionManagerStats()); + logger.debug("PowerFlex Gateway API call unauthorized. Current token might be invalid, renew the session." + getConnectionManagerStats()); return true; } return false; @@ -243,7 +244,7 @@ private void checkResponseOK(final HttpResponse response) { } if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) { - LOG.warn("Requested resource does not exist"); + logger.warn("Requested resource does not exist"); return; } @@ -258,7 +259,7 @@ private void checkResponseOK(final HttpResponse response) { responseBody = EntityUtils.toString(response.getEntity()); } catch (IOException ignored) { } - LOG.debug("HTTP request failed, status code: " + response.getStatusLine().getStatusCode() + ", response: " + logger.debug("HTTP request failed, status code: " + response.getStatusLine().getStatusCode() + ", response: " + responseBody + getConnectionManagerStats()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "API failed due to: " + responseBody); } @@ -282,10 +283,10 @@ private T get(final String path, final Class type, final boolean renewAnd while (authenticating); // wait for authentication request (if any) to complete (and to pick the new session key) final HttpGet request = new HttpGet(apiURI.toString() + path); request.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + Base64.getEncoder().encodeToString((this.username + ":" + this.sessionKey).getBytes())); - LOG.debug("Sending GET request: " + request.toString()); + logger.debug("Sending GET request: " + request.toString()); response = httpClient.execute(request); String responseStatus = (!isNullResponse(response)) ? (response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()) : "nil"; - LOG.debug("Received response: " + responseStatus + ", for the sent GET request: " + request.toString()); + logger.debug("Received response: " + responseStatus + ", for the sent GET request: " + request.toString()); if (checkAuthFailure(response, renewAndRetryOnAuthFailure)) { EntityUtils.consumeQuietly(response.getEntity()); responseConsumed = true; @@ -295,7 +296,7 @@ private T get(final String path, final Class type, final boolean renewAnd } return processResponse(response, type); } catch (final IOException e) { - LOG.error("Failed in GET method due to: " + e.getMessage() + getConnectionManagerStats(), e); + logger.error("Failed in GET method due to: " + e.getMessage() + getConnectionManagerStats(), e); checkResponseTimeOut(e); } finally { if (!responseConsumed && response != null) { @@ -328,10 +329,10 @@ private T post(final String path, final Object obj, final Class type, fin request.setEntity(new StringEntity(json)); } } - LOG.debug("Sending POST request: " + request.toString()); + logger.debug("Sending POST request: " + request.toString()); response = httpClient.execute(request); String responseStatus = (!isNullResponse(response)) ? (response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()) : "nil"; - LOG.debug("Received response: " + responseStatus + ", for the sent POST request: " + request.toString()); + logger.debug("Received response: " + responseStatus + ", for the sent POST request: " + request.toString()); if (checkAuthFailure(response, renewAndRetryOnAuthFailure)) { EntityUtils.consumeQuietly(response.getEntity()); responseConsumed = true; @@ -341,7 +342,7 @@ private T post(final String path, final Object obj, final Class type, fin } return processResponse(response, type); } catch (final IOException e) { - LOG.error("Failed in POST method due to: " + e.getMessage() + getConnectionManagerStats(), e); + logger.error("Failed in POST method due to: " + e.getMessage() + getConnectionManagerStats(), e); checkResponseTimeOut(e); } finally { if (!responseConsumed && response != null) { @@ -529,14 +530,14 @@ public boolean revertSnapshot(final String systemId, final Map s boolean revertStatus = revertSnapshot(sourceSnapshotVolumeId, destVolumeId); if (!revertStatus) { revertSnapshotResult = false; - LOG.warn("Failed to revert snapshot for volume id: " + sourceSnapshotVolumeId); + logger.warn("Failed to revert snapshot for volume id: " + sourceSnapshotVolumeId); throw new CloudRuntimeException("Failed to revert snapshot for volume id: " + sourceSnapshotVolumeId); } else { revertStatusIndex++; } } } catch (final Exception e) { - LOG.error("Failed to revert vm snapshot due to: " + e.getMessage(), e); + logger.error("Failed to revert vm snapshot due to: " + e.getMessage(), e); throw new CloudRuntimeException("Failed to revert vm snapshot due to: " + e.getMessage()); } finally { if (!revertSnapshotResult) { @@ -748,7 +749,7 @@ public boolean deleteVolume(final String volumeId) { } } catch (Exception ex) { if (ex instanceof ServerApiException && ex.getMessage().contains("Could not find the volume")) { - LOG.warn(String.format("API says deleting volume %s does not exist, handling gracefully", volumeId)); + logger.warn(String.format("API says deleting volume %s does not exist, handling gracefully", volumeId)); return true; } throw ex; @@ -765,18 +766,18 @@ public boolean migrateVolume(final String srcVolumeId, final String destPoolId, try { Volume volume = getVolume(srcVolumeId); if (volume == null || StringUtils.isEmpty(volume.getVtreeId())) { - LOG.warn("Couldn't find the volume(-tree), can not migrate the volume " + srcVolumeId); + logger.warn("Couldn't find the volume(-tree), can not migrate the volume " + srcVolumeId); return false; } String srcPoolId = volume.getStoragePoolId(); - LOG.info("Migrating the volume: " + srcVolumeId + " on the src pool: " + srcPoolId + " to the dest pool: " + destPoolId + + logger.info("Migrating the volume: " + srcVolumeId + " on the src pool: " + srcPoolId + " to the dest pool: " + destPoolId + " in the same PowerFlex cluster"); post("/instances/Volume::" + srcVolumeId + "/action/migrateVTree", String.format("{\"destSPId\":\"%s\"}", destPoolId), Boolean.class); - LOG.debug("Wait until the migration is complete for the volume: " + srcVolumeId); + logger.debug("Wait until the migration is complete for the volume: " + srcVolumeId); long migrationStartTime = System.currentTimeMillis(); boolean status = waitForVolumeMigrationToComplete(volume.getVtreeId(), timeoutInSecs); @@ -784,13 +785,13 @@ public boolean migrateVolume(final String srcVolumeId, final String destPoolId, // volume, v-tree, snapshot ids remains same after the migration volume = getVolume(srcVolumeId); if (volume == null || volume.getStoragePoolId() == null) { - LOG.warn("Couldn't get the volume: " + srcVolumeId + " details after migration"); + logger.warn("Couldn't get the volume: " + srcVolumeId + " details after migration"); return status; } else { String volumeOnPoolId = volume.getStoragePoolId(); // confirm whether the volume is on the dest storage pool or not if (status && destPoolId.equalsIgnoreCase(volumeOnPoolId)) { - LOG.debug("Migration success for the volume: " + srcVolumeId); + logger.debug("Migration success for the volume: " + srcVolumeId); return true; } else { try { @@ -813,23 +814,23 @@ public boolean migrateVolume(final String srcVolumeId, final String destPoolId, return status; } catch (Exception ex) { - LOG.warn("Exception on pause/rollback migration of the volume: " + srcVolumeId + " - " + ex.getLocalizedMessage()); + logger.warn("Exception on pause/rollback migration of the volume: " + srcVolumeId + " - " + ex.getLocalizedMessage()); } } } } catch (final Exception e) { - LOG.error("Failed to migrate PowerFlex volume due to: " + e.getMessage(), e); + logger.error("Failed to migrate PowerFlex volume due to: " + e.getMessage(), e); throw new CloudRuntimeException("Failed to migrate PowerFlex volume due to: " + e.getMessage()); } - LOG.debug("Migration failed for the volume: " + srcVolumeId); + logger.debug("Migration failed for the volume: " + srcVolumeId); return false; } private boolean waitForVolumeMigrationToComplete(final String volumeTreeId, int waitTimeoutInSecs) { - LOG.debug("Waiting for the migration to complete for the volume-tree " + volumeTreeId); + logger.debug("Waiting for the migration to complete for the volume-tree " + volumeTreeId); if (StringUtils.isEmpty(volumeTreeId)) { - LOG.warn("Invalid volume-tree id, unable to check the migration status of the volume-tree " + volumeTreeId); + logger.warn("Invalid volume-tree id, unable to check the migration status of the volume-tree " + volumeTreeId); return false; } @@ -841,24 +842,24 @@ private boolean waitForVolumeMigrationToComplete(final String volumeTreeId, int VTreeMigrationInfo.MigrationStatus migrationStatus = getVolumeTreeMigrationStatus(volumeTreeId); if (migrationStatus != null && migrationStatus == VTreeMigrationInfo.MigrationStatus.NotInMigration) { - LOG.debug("Migration completed for the volume-tree " + volumeTreeId); + logger.debug("Migration completed for the volume-tree " + volumeTreeId); return true; } } catch (Exception ex) { - LOG.warn("Exception while checking for migration status of the volume-tree: " + volumeTreeId + " - " + ex.getLocalizedMessage()); + logger.warn("Exception while checking for migration status of the volume-tree: " + volumeTreeId + " - " + ex.getLocalizedMessage()); // don't do anything } finally { waitTimeoutInSecs = waitTimeoutInSecs - delayTimeInSecs; } } - LOG.debug("Unable to complete the migration for the volume-tree " + volumeTreeId); + logger.debug("Unable to complete the migration for the volume-tree " + volumeTreeId); return false; } private VTreeMigrationInfo.MigrationStatus getVolumeTreeMigrationStatus(final String volumeTreeId) { if (StringUtils.isEmpty(volumeTreeId)) { - LOG.warn("Invalid volume-tree id, unable to get the migration status of the volume-tree " + volumeTreeId); + logger.warn("Invalid volume-tree id, unable to get the migration status of the volume-tree " + volumeTreeId); return null; } @@ -874,13 +875,13 @@ private boolean rollbackVolumeMigration(final String srcVolumeId) { Volume volume = getVolume(srcVolumeId); if (volume == null) { - LOG.warn("Unable to rollback volume migration, couldn't get details for the volume: " + srcVolumeId); + logger.warn("Unable to rollback volume migration, couldn't get details for the volume: " + srcVolumeId); return false; } VTreeMigrationInfo.MigrationStatus migrationStatus = getVolumeTreeMigrationStatus(volume.getVtreeId()); if (migrationStatus != null && migrationStatus == VTreeMigrationInfo.MigrationStatus.NotInMigration) { - LOG.debug("Volume: " + srcVolumeId + " is not migrating, no need to rollback"); + logger.debug("Volume: " + srcVolumeId + " is not migrating, no need to rollback"); return true; } @@ -893,12 +894,12 @@ private boolean rollbackVolumeMigration(final String srcVolumeId) { Thread.sleep(3000); // Try after few secs migrationStatus = getVolumeTreeMigrationStatus(volume.getVtreeId()); // Get updated migration status if (migrationStatus != null && migrationStatus == VTreeMigrationInfo.MigrationStatus.Paused) { - LOG.debug("Migration for the volume: " + srcVolumeId + " paused"); + logger.debug("Migration for the volume: " + srcVolumeId + " paused"); paused = true; break; } } catch (Exception ex) { - LOG.warn("Exception while checking for migration pause status of the volume: " + srcVolumeId + " - " + ex.getLocalizedMessage()); + logger.warn("Exception while checking for migration pause status of the volume: " + srcVolumeId + " - " + ex.getLocalizedMessage()); // don't do anything } finally { retryCount--; @@ -914,14 +915,14 @@ private boolean rollbackVolumeMigration(final String srcVolumeId) { return migrateVTreeStatus; } } else { - LOG.warn("Migration for the volume: " + srcVolumeId + " didn't pause, couldn't rollback"); + logger.warn("Migration for the volume: " + srcVolumeId + " didn't pause, couldn't rollback"); } return false; } private boolean pauseVolumeMigration(final String volumeId, final boolean forced) { if (StringUtils.isEmpty(volumeId)) { - LOG.warn("Invalid Volume Id, Unable to pause migration of the volume " + volumeId); + logger.warn("Invalid Volume Id, Unable to pause migration of the volume " + volumeId); return false; } diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java index dec6ca00ab0d..8044e787bd2d 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriver.java @@ -64,7 +64,8 @@ import org.apache.cloudstack.storage.volume.VolumeObject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.GetVolumeStatAnswer; @@ -110,7 +111,7 @@ import com.google.common.base.Preconditions; public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver { - private static final Logger LOGGER = Logger.getLogger(ScaleIOPrimaryDataStoreDriver.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject EndPointSelector selector; @@ -201,16 +202,16 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore if (DataObjectType.VOLUME.equals(dataObject.getType())) { final VolumeVO volume = volumeDao.findById(dataObject.getId()); - LOGGER.debug("Granting access for PowerFlex volume: " + volume.getPath()); + logger.debug("Granting access for PowerFlex volume: " + volume.getPath()); return setVolumeLimitsFromDetails(volume, host, dataStore); } else if (DataObjectType.TEMPLATE.equals(dataObject.getType())) { final VMTemplateStoragePoolVO templatePoolRef = vmTemplatePoolDao.findByPoolTemplate(dataStore.getId(), dataObject.getId(), null); - LOGGER.debug("Granting access for PowerFlex template volume: " + templatePoolRef.getInstallPath()); + logger.debug("Granting access for PowerFlex template volume: " + templatePoolRef.getInstallPath()); final ScaleIOGatewayClient client = getScaleIOClient(dataStore.getId()); return client.mapVolumeToSdc(ScaleIOUtil.getVolumePath(templatePoolRef.getInstallPath()), sdcId); } else if (DataObjectType.SNAPSHOT.equals(dataObject.getType())) { SnapshotInfo snapshot = (SnapshotInfo) dataObject; - LOGGER.debug("Granting access for PowerFlex volume snapshot: " + snapshot.getPath()); + logger.debug("Granting access for PowerFlex volume snapshot: " + snapshot.getPath()); final ScaleIOGatewayClient client = getScaleIOClient(dataStore.getId()); return client.mapVolumeToSdc(ScaleIOUtil.getVolumePath(snapshot.getPath()), sdcId); } @@ -229,28 +230,28 @@ private boolean grantAccess(DataObject dataObject, EndPoint ep, DataStore dataSt @Override public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) { if (host == null) { - LOGGER.info("Declining to revoke access to PowerFlex volume when a host is not provided"); + logger.info("Declining to revoke access to PowerFlex volume when a host is not provided"); return; } try { final String sdcId = getConnectedSdc(dataStore.getId(), host.getId()); if (StringUtils.isBlank(sdcId)) { - LOGGER.warn(String.format("Unable to revoke access for %s: %s, no Sdc connected with host ip: %s", dataObject.getType(), dataObject.getId(), host.getPrivateIpAddress())); + logger.warn(String.format("Unable to revoke access for %s: %s, no Sdc connected with host ip: %s", dataObject.getType(), dataObject.getId(), host.getPrivateIpAddress())); return; } final ScaleIOGatewayClient client = getScaleIOClient(dataStore.getId()); if (DataObjectType.VOLUME.equals(dataObject.getType())) { final VolumeVO volume = volumeDao.findById(dataObject.getId()); - LOGGER.debug("Revoking access for PowerFlex volume: " + volume.getPath()); + logger.debug("Revoking access for PowerFlex volume: " + volume.getPath()); client.unmapVolumeFromSdc(ScaleIOUtil.getVolumePath(volume.getPath()), sdcId); } else if (DataObjectType.TEMPLATE.equals(dataObject.getType())) { final VMTemplateStoragePoolVO templatePoolRef = vmTemplatePoolDao.findByPoolTemplate(dataStore.getId(), dataObject.getId(), null); - LOGGER.debug("Revoking access for PowerFlex template volume: " + templatePoolRef.getInstallPath()); + logger.debug("Revoking access for PowerFlex template volume: " + templatePoolRef.getInstallPath()); client.unmapVolumeFromSdc(ScaleIOUtil.getVolumePath(templatePoolRef.getInstallPath()), sdcId); } else if (DataObjectType.SNAPSHOT.equals(dataObject.getType())) { SnapshotInfo snapshot = (SnapshotInfo) dataObject; - LOGGER.debug("Revoking access for PowerFlex volume snapshot: " + snapshot.getPath()); + logger.debug("Revoking access for PowerFlex volume snapshot: " + snapshot.getPath()); client.unmapVolumeFromSdc(ScaleIOUtil.getVolumePath(snapshot.getPath()), sdcId); } if (client.listVolumesMappedToSdc(sdcId).isEmpty()) { @@ -258,22 +259,22 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) sdcManager.stopSDC(host, dataStore); } } catch (Exception e) { - LOGGER.warn("Failed to revoke access due to: " + e.getMessage(), e); + logger.warn("Failed to revoke access due to: " + e.getMessage(), e); } } public void revokeVolumeAccess(String volumePath, Host host, DataStore dataStore) { if (host == null) { - LOGGER.warn("Declining to revoke access to PowerFlex volume when a host is not provided"); + logger.warn("Declining to revoke access to PowerFlex volume when a host is not provided"); return; } try { - LOGGER.debug("Revoking access for PowerFlex volume: " + volumePath); + logger.debug("Revoking access for PowerFlex volume: " + volumePath); final String sdcId = getConnectedSdc(dataStore.getId(), host.getId()); if (StringUtils.isBlank(sdcId)) { - LOGGER.warn(String.format("Unable to revoke access for volume: %s, no Sdc connected with host ip: %s", volumePath, host.getPrivateIpAddress())); + logger.warn(String.format("Unable to revoke access for volume: %s, no Sdc connected with host ip: %s", volumePath, host.getPrivateIpAddress())); return; } @@ -284,7 +285,7 @@ public void revokeVolumeAccess(String volumePath, Host host, DataStore dataStore sdcManager.stopSDC(host, dataStore); } } catch (Exception e) { - LOGGER.warn("Failed to revoke access due to: " + e.getMessage(), e); + logger.warn("Failed to revoke access due to: " + e.getMessage(), e); } } @@ -305,7 +306,7 @@ public String getConnectedSdc(long poolId, long hostId) { return poolHostVO.getLocalPath(); } } catch (Exception e) { - LOGGER.warn("Couldn't check SDC connection for the host: " + hostId + " and storage pool: " + poolId + " due to " + e.getMessage(), e); + logger.warn("Couldn't check SDC connection for the host: " + hostId + " and storage pool: " + poolId + " due to " + e.getMessage(), e); } return null; @@ -346,7 +347,7 @@ public long getUsedBytes(StoragePool storagePool) { } } - LOGGER.debug("Used/Allocated storage space (in bytes): " + String.valueOf(usedSpaceBytes)); + logger.debug("Used/Allocated storage space (in bytes): " + String.valueOf(usedSpaceBytes)); return usedSpaceBytes; } @@ -403,7 +404,7 @@ public DataStoreTO getStoreTO(DataStore store) { @Override public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback callback) { - LOGGER.debug("Taking PowerFlex volume snapshot"); + logger.debug("Taking PowerFlex volume snapshot"); Preconditions.checkArgument(snapshotInfo != null, "snapshotInfo cannot be null"); @@ -441,7 +442,7 @@ public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback callback) { - LOGGER.debug("Reverting to PowerFlex volume snapshot"); + logger.debug("Reverting to PowerFlex volume snapshot"); Preconditions.checkArgument(snapshot != null, "snapshotInfo cannot be null"); @@ -478,7 +479,7 @@ public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimary CommandResult commandResult = new CommandResult(); callback.complete(commandResult); } catch (Exception ex) { - LOGGER.debug("Unable to revert to PowerFlex snapshot: " + snapshot.getId(), ex); + logger.debug("Unable to revert to PowerFlex snapshot: " + snapshot.getId(), ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -488,7 +489,7 @@ public CreateObjectAnswer createVolume(VolumeInfo volumeInfo, long storagePoolId } public CreateObjectAnswer createVolume(VolumeInfo volumeInfo, long storagePoolId, boolean migrationInvolved, Long usageSize) { - LOGGER.debug("Creating PowerFlex volume"); + logger.debug("Creating PowerFlex volume"); StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId); @@ -533,7 +534,7 @@ public CreateObjectAnswer createVolume(VolumeInfo volumeInfo, long storagePoolId // if volume needs to be set up with encryption, do it now if it's not a root disk (which gets done during template copy) if (anyVolumeRequiresEncryption(volumeInfo) && (!volumeInfo.getVolumeType().equals(Volume.Type.ROOT) || migrationInvolved)) { - LOGGER.debug(String.format("Setting up encryption for volume %s", volumeInfo.getId())); + logger.debug(String.format("Setting up encryption for volume %s", volumeInfo.getId())); VolumeObjectTO prepVolume = (VolumeObjectTO) createdObject.getTO(); prepVolume.setPath(volumePath); prepVolume.setUuid(volumePath); @@ -557,19 +558,19 @@ public CreateObjectAnswer createVolume(VolumeInfo volumeInfo, long storagePoolId } } } else { - LOGGER.debug(String.format("No encryption configured for data volume %s", volumeInfo)); + logger.debug(String.format("No encryption configured for data volume %s", volumeInfo)); } return answer; } catch (Exception e) { String errMsg = "Unable to create PowerFlex Volume due to " + e.getMessage(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg, e); } } private String createTemplateVolume(TemplateInfo templateInfo, long storagePoolId) { - LOGGER.debug("Creating PowerFlex template volume"); + logger.debug("Creating PowerFlex template volume"); StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId); Preconditions.checkArgument(templateInfo != null, "templateInfo cannot be null"); @@ -607,7 +608,7 @@ private String createTemplateVolume(TemplateInfo templateInfo, long storagePool return templatePath; } catch (Exception e) { String errMsg = "Unable to create PowerFlex template volume due to " + e.getMessage(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg, e); } } @@ -619,22 +620,22 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet Answer answer = new Answer(null, false, "not started"); try { if (dataObject.getType() == DataObjectType.VOLUME) { - LOGGER.debug("createAsync - creating volume"); + logger.debug("createAsync - creating volume"); CreateObjectAnswer createAnswer = createVolume((VolumeInfo) dataObject, dataStore.getId()); scaleIOVolumePath = createAnswer.getData().getPath(); answer = createAnswer; } else if (dataObject.getType() == DataObjectType.TEMPLATE) { - LOGGER.debug("createAsync - creating template"); + logger.debug("createAsync - creating template"); scaleIOVolumePath = createTemplateVolume((TemplateInfo)dataObject, dataStore.getId()); answer = new Answer(null, true, "created template"); } else { errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(null, false, errMsg); } } catch (Exception ex) { errMsg = ex.getMessage(); - LOGGER.error(errMsg); + logger.error(errMsg); if (callback == null) { throw ex; } @@ -662,17 +663,17 @@ public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncComplet try { boolean deleteResult = false; if (dataObject.getType() == DataObjectType.VOLUME) { - LOGGER.debug("deleteAsync - deleting volume"); + logger.debug("deleteAsync - deleting volume"); scaleIOVolumePath = ((VolumeInfo) dataObject).getPath(); } else if (dataObject.getType() == DataObjectType.SNAPSHOT) { - LOGGER.debug("deleteAsync - deleting snapshot"); + logger.debug("deleteAsync - deleting snapshot"); scaleIOVolumePath = ((SnapshotInfo) dataObject).getPath(); } else if (dataObject.getType() == DataObjectType.TEMPLATE) { - LOGGER.debug("deleteAsync - deleting template"); + logger.debug("deleteAsync - deleting template"); scaleIOVolumePath = ((TemplateInfo) dataObject).getInstallPath(); } else { errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync"; - LOGGER.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -690,12 +691,12 @@ public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncComplet storagePoolDao.update(storagePoolId, storagePool); } catch (Exception e) { errMsg = "Unable to delete PowerFlex volume: " + scaleIOVolumePath + " due to " + e.getMessage(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg, e); } } catch (Exception ex) { errMsg = ex.getMessage(); - LOGGER.error(errMsg); + logger.error(errMsg); if (callback == null) { throw ex; } @@ -739,16 +740,16 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As } else { errMsg = "Unsupported copy operation from src object: (" + srcData.getType() + ", " + srcData.getDataStore() + "), dest object: (" + destData.getType() + ", " + destData.getDataStore() + ")"; - LOGGER.warn(errMsg); + logger.warn(errMsg); answer = new Answer(null, false, errMsg); } } else { errMsg = "Unsupported copy operation"; - LOGGER.warn(errMsg); + logger.warn(errMsg); answer = new Answer(null, false, errMsg); } } catch (Exception e) { - LOGGER.debug("Failed to copy due to " + e.getMessage(), e); + logger.debug("Failed to copy due to " + e.getMessage(), e); errMsg = e.toString(); answer = new Answer(null, false, errMsg); } @@ -772,26 +773,26 @@ private Answer copyTemplateToVolume(DataObject srcData, DataObject destData, Hos * Data stores of file type happen automatically, but block device types have to handle it. Unfortunately for ScaleIO this means we add a whole 8GB to * the original size, but only if we are close to an 8GB boundary. */ - LOGGER.debug(String.format("Copying template %s to volume %s", srcData.getId(), destData.getId())); + logger.debug(String.format("Copying template %s to volume %s", srcData.getId(), destData.getId())); VolumeInfo destInfo = (VolumeInfo) destData; boolean encryptionRequired = anyVolumeRequiresEncryption(destData); if (encryptionRequired) { if (needsExpansionForEncryptionHeader(srcData.getSize(), destData.getSize())) { long newSize = destData.getSize() + (1<<30); - LOGGER.debug(String.format("Destination volume %s(%s) is configured for encryption. Resizing to fit headers, new size %s will be rounded up to nearest 8Gi", destInfo.getId(), destData.getSize(), newSize)); + logger.debug(String.format("Destination volume %s(%s) is configured for encryption. Resizing to fit headers, new size %s will be rounded up to nearest 8Gi", destInfo.getId(), destData.getSize(), newSize)); ResizeVolumePayload p = new ResizeVolumePayload(newSize, destInfo.getMinIops(), destInfo.getMaxIops(), destInfo.getHypervisorSnapshotReserve(), false, destInfo.getAttachedVmName(), null, true); destInfo.addPayload(p); resizeVolume(destInfo); } else { - LOGGER.debug(String.format("Template %s has size %s, ok for volume %s with size %s", srcData.getId(), srcData.getSize(), destData.getId(), destData.getSize())); + logger.debug(String.format("Template %s has size %s, ok for volume %s with size %s", srcData.getId(), srcData.getSize(), destData.getId(), destData.getSize())); } } else { - LOGGER.debug(String.format("Destination volume is not configured for encryption, skipping encryption prep. Volume: %s", destData.getId())); + logger.debug(String.format("Destination volume is not configured for encryption, skipping encryption prep. Volume: %s", destData.getId())); } // Copy PowerFlex/ScaleIO template to volume - LOGGER.debug(String.format("Initiating copy from PowerFlex template volume on host %s", destHost != null ? destHost.getId() : "")); + logger.debug(String.format("Initiating copy from PowerFlex template volume on host %s", destHost != null ? destHost.getId() : "")); int primaryStorageDownloadWait = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value(); CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value()); @@ -799,7 +800,7 @@ private Answer copyTemplateToVolume(DataObject srcData, DataObject destData, Hos EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcData, encryptionRequired); if (ep == null) { String errorMsg = String.format("No remote endpoint to send command, unable to find a valid endpoint. Requires encryption support: %s", encryptionRequired); - LOGGER.error(errorMsg); + logger.error(errorMsg); answer = new Answer(cmd, false, errorMsg); } else { VolumeVO volume = volumeDao.findById(destData.getId()); @@ -808,7 +809,7 @@ private Answer copyTemplateToVolume(DataObject srcData, DataObject destData, Hos setVolumeLimitsOnSDC(volume, host, destData.getDataStore(), 0L, 0L); answer = ep.sendMessage(cmd); } catch (Exception e) { - LOGGER.error("Failed to copy template to volume due to: " + e.getMessage(), e); + logger.error("Failed to copy template to volume due to: " + e.getMessage(), e); answer = new Answer(cmd, false, e.getMessage()); } } @@ -818,7 +819,7 @@ private Answer copyTemplateToVolume(DataObject srcData, DataObject destData, Hos protected Answer copyOfflineVolume(DataObject srcData, DataObject destData, Host destHost) { // Copy PowerFlex/ScaleIO volume - LOGGER.debug(String.format("Initiating copy from PowerFlex template volume on host %s", destHost != null ? destHost.getId() : "")); + logger.debug(String.format("Initiating copy from PowerFlex template volume on host %s", destHost != null ? destHost.getId() : "")); String value = configDao.getValue(Config.CopyVolumeWait.key()); int copyVolumeWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue())); @@ -829,7 +830,7 @@ protected Answer copyOfflineVolume(DataObject srcData, DataObject destData, Host EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcData, encryptionRequired); if (ep == null) { String errorMsg = String.format("No remote endpoint to send command, unable to find a valid endpoint. Requires encryption support: %s", encryptionRequired); - LOGGER.error(errorMsg); + logger.error(errorMsg); answer = new Answer(cmd, false, errorMsg); } else { answer = ep.sendMessage(cmd); @@ -860,7 +861,7 @@ public Answer liveMigrateVolume(DataObject srcData, DataObject destData) { GetVolumeStatCommand statCmd = new GetVolumeStatCommand(srcVolumeInfo.getPath(), srcVolumeInfo.getStoragePoolType(), srcStore.getUuid()); GetVolumeStatAnswer statAnswer = (GetVolumeStatAnswer) ep.sendMessage(statCmd); if (!statAnswer.getResult() ) { - LOGGER.warn(String.format("Unable to get volume %s stats", srcVolumeInfo.getId())); + logger.warn(String.format("Unable to get volume %s stats", srcVolumeInfo.getId())); } else if (statAnswer.getVirtualSize() > 0) { srcVolumeUsableSize = statAnswer.getVirtualSize(); } @@ -881,15 +882,15 @@ public Answer liveMigrateVolume(DataObject srcData, DataObject destData) { updateVolumeAfterCopyVolume(srcData, destData); updateSnapshotsAfterCopyVolume(srcData, destData); deleteSourceVolumeAfterSuccessfulBlockCopy(srcData, host); - LOGGER.debug(String.format("Successfully migrated migrate PowerFlex volume %d to storage pool %d", srcVolumeId, destPoolId)); + logger.debug(String.format("Successfully migrated migrate PowerFlex volume %d to storage pool %d", srcVolumeId, destPoolId)); answer = new Answer(null, true, null); } else { String errorMsg = "Failed to migrate PowerFlex volume: " + srcVolumeId + " to storage pool " + destPoolId; - LOGGER.debug(errorMsg); + logger.debug(errorMsg); answer = new Answer(null, false, errorMsg); } } catch (Exception e) { - LOGGER.error("Failed to migrate PowerFlex volume: " + srcVolumeId + " due to: " + e.getMessage()); + logger.error("Failed to migrate PowerFlex volume: " + srcVolumeId + " due to: " + e.getMessage()); answer = new Answer(null, false, e.getMessage()); } @@ -982,11 +983,11 @@ public void deleteSourceVolumeAfterSuccessfulBlockCopy(DataObject srcData, Host Boolean deleteResult = client.deleteVolume(scaleIOVolumeId); if (!deleteResult) { errMsg = "Failed to delete source PowerFlex volume with id: " + scaleIOVolumeId; - LOGGER.warn(errMsg); + logger.warn(errMsg); } } catch (Exception e) { errMsg = "Unable to delete source PowerFlex volume: " + srcVolumePath + " due to " + e.getMessage(); - LOGGER.warn(errMsg);; + logger.warn(errMsg);; } } @@ -1003,12 +1004,12 @@ public void revertBlockCopyVolumeOperations(DataObject srcData, DataObject destD Boolean deleteResult = client.deleteVolume(scaleIOVolumeId); if (!deleteResult) { errMsg = "Failed to delete PowerFlex volume with id: " + scaleIOVolumeId; - LOGGER.warn(errMsg); + logger.warn(errMsg); } } catch (Exception e) { errMsg = "Unable to delete destination PowerFlex volume: " + destVolumePath + " due to " + e.getMessage(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg, e); } @@ -1144,11 +1145,11 @@ private Answer migrateVolume(DataObject srcData, DataObject destData) { answer = new Answer(null, true, null); } else { String errorMsg = "Failed to migrate PowerFlex volume: " + srcData.getId() + " to storage pool " + destPoolId; - LOGGER.debug(errorMsg); + logger.debug(errorMsg); answer = new Answer(null, false, errorMsg); } } catch (Exception e) { - LOGGER.error("Failed to migrate PowerFlex volume: " + srcData.getId() + " due to: " + e.getMessage()); + logger.error("Failed to migrate PowerFlex volume: " + srcData.getId() + " due to: " + e.getMessage()); answer = new Answer(null, false, e.getMessage()); } @@ -1198,7 +1199,7 @@ public boolean canCopy(DataObject srcData, DataObject destData) { } private void resizeVolume(VolumeInfo volumeInfo) { - LOGGER.debug("Resizing PowerFlex volume"); + logger.debug("Resizing PowerFlex volume"); Preconditions.checkArgument(volumeInfo != null, "volumeInfo cannot be null"); @@ -1219,7 +1220,7 @@ private void resizeVolume(VolumeInfo volumeInfo) { long newSizeIn8gbBoundary = (long) (Math.ceil(newSizeInGB / 8.0) * 8.0); if (scaleIOVolume.getSizeInKb() == newSizeIn8gbBoundary << 20) { - LOGGER.debug("No resize necessary at API"); + logger.debug("No resize necessary at API"); } else { scaleIOVolume = client.resizeVolume(scaleIOVolumeId, (int) newSizeIn8gbBoundary); if (scaleIOVolume == null) { @@ -1254,7 +1255,7 @@ private void resizeVolume(VolumeInfo volumeInfo) { } if (volumeInfo.getFormat().equals(Storage.ImageFormat.QCOW2) || attachedRunning) { - LOGGER.debug("Volume needs to be resized at the hypervisor host"); + logger.debug("Volume needs to be resized at the hypervisor host"); if (hostId == 0) { hostId = selector.select(volumeInfo, true).getId(); @@ -1281,9 +1282,9 @@ private void resizeVolume(VolumeInfo volumeInfo) { } else if (!answer.getResult()) { // for non-qcow2, notifying the running VM is going to be best-effort since we can't roll back // or avoid VM seeing a successful change at the PowerFlex volume after e.g. reboot - LOGGER.warn("Resized raw volume, but failed to notify. VM will see change on reboot. Error:" + answer.getDetails()); + logger.warn("Resized raw volume, but failed to notify. VM will see change on reboot. Error:" + answer.getDetails()); } else { - LOGGER.debug("Resized volume at host: " + answer.getDetails()); + logger.debug("Resized volume at host: " + answer.getDetails()); } } finally { if (!attachedRunning) { @@ -1315,7 +1316,7 @@ private void resizeVolume(VolumeInfo volumeInfo) { storagePoolDao.update(storagePoolId, storagePool); } catch (Exception e) { String errMsg = "Unable to resize PowerFlex volume: " + volumeInfo.getId() + " due to " + e.getMessage(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg, e); } } @@ -1333,7 +1334,7 @@ public void resize(DataObject dataObject, AsyncCompletionCallback getCustomStorageStats(StoragePool pool) { customStats.put(ScaleIOUtil.CONNECTED_SDC_COUNT_STAT, String.valueOf(connectedSdcsCount)); } catch (Exception e) { String errMsg = "Unable to get custom storage stats for the pool: " + pool.getId() + " due to " + e.getMessage(); - LOGGER.error(errMsg); + logger.error(errMsg); } return customStats; @@ -1391,7 +1402,7 @@ public Pair getStorageStats(StoragePool storagePool) { } } catch (Exception e) { String errMsg = "Unable to get storage stats for the pool: " + storagePool.getId() + " due to " + e.getMessage(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg, e); } @@ -1418,7 +1429,7 @@ public Pair getVolumeStats(StoragePool storagePool, String volumePat } } catch (Exception e) { String errMsg = "Unable to get stats for the volume: " + volumePath + " in the pool: " + storagePool.getId() + " due to " + e.getMessage(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg, e); } @@ -1439,7 +1450,7 @@ public boolean canHostAccessStoragePool(Host host, StoragePool pool) { final ScaleIOGatewayClient client = getScaleIOClient(pool.getId()); return client.isSdcConnected(poolHostVO.getLocalPath()); } catch (Exception e) { - LOGGER.warn("Unable to check the host: " + host.getId() + " access to storage pool: " + pool.getId() + " due to " + e.getMessage(), e); + logger.warn("Unable to check the host: " + host.getId() + " access to storage pool: " + pool.getId() + " due to " + e.getMessage(), e); return false; } } @@ -1459,7 +1470,7 @@ private void alertHostSdcDisconnection(Host host) { return; } - LOGGER.warn("SDC not connected on the host: " + host.getId()); + logger.warn("SDC not connected on the host: " + host.getId()); String msg = "SDC not connected on the host: " + host.getId() + ", reconnect the SDC to MDM"; alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "SDC disconnected on host: " + host.getUuid(), msg); } diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java index c1a7411d29f7..7bbe0331c071 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycle.java @@ -47,7 +47,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -75,8 +74,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class ScaleIOPrimaryDataStoreLifeCycle extends BasePrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { - private static final Logger LOGGER = Logger.getLogger(ScaleIOPrimaryDataStoreLifeCycle.class); - @Inject private ClusterDao clusterDao; @Inject @@ -111,7 +108,7 @@ private org.apache.cloudstack.storage.datastore.api.StoragePool findStoragePool( List storagePools = client.listStoragePools(); for (org.apache.cloudstack.storage.datastore.api.StoragePool pool : storagePools) { if (pool.getName().equals(storagePoolName)) { - LOGGER.info("Found PowerFlex storage pool: " + storagePoolName); + logger.info("Found PowerFlex storage pool: " + storagePoolName); final org.apache.cloudstack.storage.datastore.api.StoragePoolStatistics poolStatistics = client.getStoragePoolStatistics(pool.getId()); pool.setStatistics(poolStatistics); @@ -121,7 +118,7 @@ private org.apache.cloudstack.storage.datastore.api.StoragePool findStoragePool( } } } catch (NoSuchAlgorithmException | KeyManagementException | URISyntaxException e) { - LOGGER.error("Failed to add storage pool", e); + logger.error("Failed to add storage pool", e); throw new CloudRuntimeException("Failed to establish connection with PowerFlex Gateway to find and validate storage pool: " + storagePoolName); } throw new CloudRuntimeException("Failed to find the provided storage pool name: " + storagePoolName + " in the discovered PowerFlex storage pools"); @@ -178,7 +175,7 @@ public DataStore initialize(Map dsInfos) { try { storagePoolName = URLDecoder.decode(uri.getPath(), "UTF-8"); } catch (UnsupportedEncodingException e) { - LOGGER.error("[ignored] we are on a platform not supporting \"UTF-8\"!?!", e); + logger.error("[ignored] we are on a platform not supporting \"UTF-8\"!?!", e); } if (storagePoolName == null) { // if decoding fails, use getPath() anyway storagePoolName = uri.getPath(); @@ -268,7 +265,7 @@ public boolean attachCluster(DataStore dataStore, ClusterScope scope) { throw new CloudRuntimeException("No hosts are Up to associate a storage pool with in cluster: " + primaryDataStoreInfo.getClusterId()); } - LOGGER.debug("Attaching the pool to each of the hosts in the cluster: " + primaryDataStoreInfo.getClusterId()); + logger.debug("Attaching the pool to each of the hosts in the cluster: " + primaryDataStoreInfo.getClusterId()); List poolHosts = new ArrayList(); for (HostVO host : hostsInCluster) { try { @@ -276,12 +273,12 @@ public boolean attachCluster(DataStore dataStore, ClusterScope scope) { poolHosts.add(host); } } catch (Exception e) { - LOGGER.warn("Unable to establish a connection between host: " + host + " and pool: " + dataStore + "on the cluster: " + primaryDataStoreInfo.getClusterId(), e); + logger.warn("Unable to establish a connection between host: " + host + " and pool: " + dataStore + "on the cluster: " + primaryDataStoreInfo.getClusterId(), e); } } if (poolHosts.isEmpty()) { - LOGGER.warn("No host can access storage pool '" + primaryDataStoreInfo + "' on cluster '" + primaryDataStoreInfo.getClusterId() + "'."); + logger.warn("No host can access storage pool '" + primaryDataStoreInfo + "' on cluster '" + primaryDataStoreInfo.getClusterId() + "'."); } dataStoreHelper.attachCluster(dataStore); @@ -299,7 +296,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper throw new CloudRuntimeException("Unsupported hypervisor type: " + hypervisorType.toString()); } - LOGGER.debug("Attaching the pool to each of the hosts in the zone: " + scope.getScopeId()); + logger.debug("Attaching the pool to each of the hosts in the zone: " + scope.getScopeId()); List hosts = resourceManager.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId()); List poolHosts = new ArrayList(); for (HostVO host : hosts) { @@ -308,11 +305,11 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper poolHosts.add(host); } } catch (Exception e) { - LOGGER.warn("Unable to establish a connection between host: " + host + " and pool: " + dataStore + "in the zone: " + scope.getScopeId(), e); + logger.warn("Unable to establish a connection between host: " + host + " and pool: " + dataStore + "in the zone: " + scope.getScopeId(), e); } } if (poolHosts.isEmpty()) { - LOGGER.warn("No host can access storage pool " + dataStore + " in the zone: " + scope.getScopeId()); + logger.warn("No host can access storage pool " + dataStore + " in the zone: " + scope.getScopeId()); } dataStoreHelper.attachZone(dataStore); @@ -363,12 +360,12 @@ public boolean deleteDataStore(DataStore dataStore) { DeleteStoragePoolCommand deleteStoragePoolCommand = new DeleteStoragePoolCommand(storagePool); final Answer answer = agentMgr.easySend(poolHostVO.getHostId(), deleteStoragePoolCommand); if (answer != null && answer.getResult()) { - LOGGER.info("Successfully deleted storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); + logger.info("Successfully deleted storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); } else { if (answer != null) { - LOGGER.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId() + " , result: " + answer.getResult()); + logger.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId() + " , result: " + answer.getResult()); } else { - LOGGER.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); + logger.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); } } } @@ -399,7 +396,7 @@ public void updateStoragePool(StoragePool storagePool, Map detai } primaryDataStoreDao.updateCapacityBytes(storagePool.getId(), Long.parseLong(capacityBytes)); - LOGGER.info("Storage pool successfully updated"); + logger.info("Storage pool successfully updated"); } catch (Throwable e) { throw new CloudRuntimeException("Failed to update the storage pool" + e); } diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java index b121a1da66fb..4d3a78f6875f 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/manager/ScaleIOSDCManagerImpl.java @@ -24,13 +24,16 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClient; import org.apache.cloudstack.storage.datastore.client.ScaleIOGatewayClientConnectionPool; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -50,8 +53,17 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component -public class ScaleIOSDCManagerImpl implements ScaleIOSDCManager { - private static final Logger LOGGER = Logger.getLogger(ScaleIOSDCManagerImpl.class); +public class ScaleIOSDCManagerImpl implements ScaleIOSDCManager, Configurable { + private Logger logger = LogManager.getLogger(getClass()); + + static ConfigKey ConnectOnDemand = new ConfigKey<>("Storage", + Boolean.class, + "powerflex.connect.on.demand", + Boolean.FALSE.toString(), + "Connect PowerFlex client on Host when first Volume is mapped to SDC and disconnect when last Volume is unmapped from SDC," + + " otherwise no action (that is connection remains in the same state whichever it is, connected or disconnected).", + Boolean.TRUE, + ConfigKey.Scope.Zone); @Inject AgentManager agentManager; @@ -79,20 +91,25 @@ public boolean areSDCConnectionsWithinLimit(Long storagePoolId) { int connectedSdcsCount = getScaleIOClient(storagePoolId).getConnectedSdcsCount(); if (connectedSdcsCount < connectedClientsLimit) { - LOGGER.debug(String.format("Current connected SDCs count: %d - SDC connections are within the limit (%d) on PowerFlex Storage with pool id: %d", connectedSdcsCount, connectedClientsLimit, storagePoolId)); + logger.debug(String.format("Current connected SDCs count: %d - SDC connections are within the limit (%d) on PowerFlex Storage with pool id: %d", connectedSdcsCount, connectedClientsLimit, storagePoolId)); return true; } - LOGGER.debug(String.format("Current connected SDCs count: %d - SDC connections limit (%d) reached on PowerFlex Storage with pool id: %d", connectedSdcsCount, connectedClientsLimit, storagePoolId)); + logger.debug(String.format("Current connected SDCs count: %d - SDC connections limit (%d) reached on PowerFlex Storage with pool id: %d", connectedSdcsCount, connectedClientsLimit, storagePoolId)); return false; } catch (Exception e) { String errMsg = "Unable to check SDC connections for the PowerFlex storage pool with id: " + storagePoolId + " due to " + e.getMessage(); - LOGGER.warn(errMsg, e); + logger.warn(errMsg, e); return false; } } @Override public String prepareSDC(Host host, DataStore dataStore) { + if (Boolean.FALSE.equals(ConnectOnDemand.valueIn(host.getDataCenterId()))) { + logger.debug(String.format("On-demand connect/disconnect config %s disabled in the zone %d, no need to prepare SDC (check for connected SDC)", ConnectOnDemand.key(), host.getDataCenterId())); + return getConnectedSdc(host, dataStore); + } + String systemId = storagePoolDetailsDao.findDetail(dataStore.getId(), ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue(); if (systemId == null) { throw new CloudRuntimeException("Unable to prepare SDC, failed to get the system id for PowerFlex storage pool: " + dataStore.getName()); @@ -109,33 +126,33 @@ public String prepareSDC(Host host, DataStore dataStore) { int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); if (!hostIdStorageSystemIdLock.lock(storagePoolMaxWaitSeconds)) { - LOGGER.debug("Unable to prepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString); + logger.debug("Unable to prepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString); throw new CloudRuntimeException("Unable to prepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString); } long poolId = dataStore.getId(); long hostId = host.getId(); - String sdcId = getConnectedSdc(poolId, hostId); + String sdcId = getConnectedSdc(host, dataStore); if (StringUtils.isNotBlank(sdcId)) { - LOGGER.debug(String.format("SDC %s already connected for the pool: %d on host: %d, no need to prepare/start it", sdcId, poolId, hostId)); + logger.debug(String.format("SDC %s already connected for the pool: %d on host: %d, no need to prepare/start it", sdcId, poolId, hostId)); return sdcId; } String storageSystemIdLockString = String.format(POWERFLEX_SDC_SYSTEMID_LOCK_FORMAT, systemId); storageSystemIdLock = GlobalLock.getInternLock(storageSystemIdLockString); if (storageSystemIdLock == null) { - LOGGER.error("Unable to prepare SDC, couldn't get global lock on: " + storageSystemIdLockString); + logger.error("Unable to prepare SDC, couldn't get global lock on: " + storageSystemIdLockString); throw new CloudRuntimeException("Unable to prepare SDC, couldn't get global lock on " + storageSystemIdLockString); } if (!storageSystemIdLock.lock(storagePoolMaxWaitSeconds)) { - LOGGER.error("Unable to prepare SDC, couldn't lock on " + storageSystemIdLockString); + logger.error("Unable to prepare SDC, couldn't lock on " + storageSystemIdLockString); throw new CloudRuntimeException("Unable to prepare SDC, couldn't lock on " + storageSystemIdLockString); } if (!areSDCConnectionsWithinLimit(poolId)) { String errorMsg = String.format("Unable to check SDC connections or the connections limit reached for Powerflex storage (System ID: %s)", systemId); - LOGGER.error(errorMsg); + logger.error(errorMsg); throw new CloudRuntimeException(errorMsg); } @@ -174,7 +191,7 @@ public String prepareSDC(Host host, DataStore dataStore) { } private String prepareSDCOnHost(Host host, DataStore dataStore, String systemId) { - LOGGER.debug(String.format("Preparing SDC on the host %s (%s)", host.getId(), host.getName())); + logger.debug(String.format("Preparing SDC on the host %s (%s)", host.getId(), host.getName())); Map details = new HashMap<>(); details.put(ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID, systemId); PrepareStorageClientCommand cmd = new PrepareStorageClientCommand(((PrimaryDataStore) dataStore).getPoolType(), dataStore.getUuid(), details); @@ -186,25 +203,25 @@ private String prepareSDCOnHost(Host host, DataStore dataStore, String systemId) prepareStorageClientAnswer = (PrepareStorageClientAnswer) agentManager.send(host.getId(), cmd); } catch (AgentUnavailableException | OperationTimedoutException e) { String err = String.format("Failed to prepare SDC on the host %s, due to: %s", host.getName(), e.getMessage()); - LOGGER.error(err); + logger.error(err); throw new CloudRuntimeException(err); } if (prepareStorageClientAnswer == null) { String err = String.format("Unable to prepare SDC on the host %s", host.getName()); - LOGGER.error(err); + logger.error(err); throw new CloudRuntimeException(err); } if (!prepareStorageClientAnswer.getResult()) { String err = String.format("Unable to prepare SDC on the host %s, due to: %s", host.getName(), prepareStorageClientAnswer.getDetails()); - LOGGER.error(err); + logger.error(err); throw new CloudRuntimeException(err); } Map poolDetails = prepareStorageClientAnswer.getDetailsMap(); if (MapUtils.isEmpty(poolDetails)) { - LOGGER.warn(String.format("PowerFlex storage SDC details not found on the host: %s, try (re)install SDC and restart agent", host.getId())); + logger.warn(String.format("PowerFlex storage SDC details not found on the host: %s, try (re)install SDC and restart agent", host.getId())); return null; } @@ -217,7 +234,7 @@ private String prepareSDCOnHost(Host host, DataStore dataStore, String systemId) } if (StringUtils.isBlank(sdcId)) { - LOGGER.warn(String.format("Couldn't retrieve PowerFlex storage SDC details from the host: %s, try (re)install SDC and restart agent", host.getId())); + logger.warn(String.format("Couldn't retrieve PowerFlex storage SDC details from the host: %s, try (re)install SDC and restart agent", host.getId())); return null; } @@ -226,6 +243,11 @@ private String prepareSDCOnHost(Host host, DataStore dataStore, String systemId) @Override public boolean stopSDC(Host host, DataStore dataStore) { + if (Boolean.FALSE.equals(ConnectOnDemand.valueIn(host.getDataCenterId()))) { + logger.debug(String.format("On-demand connect/disconnect config %s disabled in the zone %d, no need to unprepare SDC", ConnectOnDemand.key(), host.getDataCenterId())); + return true; + } + String systemId = storagePoolDetailsDao.findDetail(dataStore.getId(), ScaleIOGatewayClient.STORAGE_POOL_SYSTEM_ID).getValue(); if (systemId == null) { throw new CloudRuntimeException("Unable to unprepare SDC, failed to get the system id for PowerFlex storage pool: " + dataStore.getName()); @@ -241,15 +263,15 @@ public boolean stopSDC(Host host, DataStore dataStore) { int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); if (!lock.lock(storagePoolMaxWaitSeconds)) { - LOGGER.debug("Unable to unprepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString); + logger.debug("Unable to unprepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString); throw new CloudRuntimeException("Unable to unprepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString); } long poolId = dataStore.getId(); long hostId = host.getId(); - String sdcId = getConnectedSdc(poolId, hostId); + String sdcId = getConnectedSdc(host, dataStore); if (StringUtils.isBlank(sdcId)) { - LOGGER.debug("SDC not connected, no need to unprepare it"); + logger.debug("SDC not connected, no need to unprepare it"); return true; } @@ -263,7 +285,7 @@ public boolean stopSDC(Host host, DataStore dataStore) { } private boolean unprepareSDCOnHost(Host host, DataStore dataStore) { - LOGGER.debug(String.format("Unpreparing SDC on the host %s (%s)", host.getId(), host.getName())); + logger.debug(String.format("Unpreparing SDC on the host %s (%s)", host.getId(), host.getName())); UnprepareStorageClientCommand cmd = new UnprepareStorageClientCommand(((PrimaryDataStore) dataStore).getPoolType(), dataStore.getUuid()); int timeoutSeconds = 60; cmd.setWait(timeoutSeconds); @@ -273,13 +295,13 @@ private boolean unprepareSDCOnHost(Host host, DataStore dataStore) { unprepareStorageClientAnswer = agentManager.send(host.getId(), cmd); } catch (AgentUnavailableException | OperationTimedoutException e) { String err = String.format("Failed to unprepare SDC on the host %s due to: %s", host.getName(), e.getMessage()); - LOGGER.error(err); + logger.error(err); return false; } if (!unprepareStorageClientAnswer.getResult()) { String err = String.format("Unable to unprepare SDC on the the host %s due to: %s", host.getName(), unprepareStorageClientAnswer.getDetails()); - LOGGER.error(err); + logger.error(err); return false; } return true; @@ -287,16 +309,19 @@ private boolean unprepareSDCOnHost(Host host, DataStore dataStore) { private String getHostSdcId(String sdcGuid, long poolId) { try { - LOGGER.debug(String.format("Try to get host SDC Id for pool: %s, with SDC guid %s", poolId, sdcGuid)); + logger.debug(String.format("Try to get host SDC Id for pool: %s, with SDC guid %s", poolId, sdcGuid)); ScaleIOGatewayClient client = getScaleIOClient(poolId); return client.getSdcIdByGuid(sdcGuid); } catch (Exception e) { - LOGGER.error(String.format("Failed to get host SDC Id for pool: %s", poolId), e); + logger.error(String.format("Failed to get host SDC Id for pool: %s", poolId), e); throw new CloudRuntimeException(String.format("Failed to establish connection with PowerFlex Gateway to get host SDC Id for pool: %s", poolId)); } } - private String getConnectedSdc(long poolId, long hostId) { + private String getConnectedSdc(Host host, DataStore dataStore) { + long poolId = dataStore.getId(); + long hostId = host.getId(); + try { StoragePoolHostVO poolHostVO = storagePoolHostDao.findByPoolHost(poolId, hostId); if (poolHostVO == null) { @@ -308,14 +333,14 @@ private String getConnectedSdc(long poolId, long hostId) { return poolHostVO.getLocalPath(); } } catch (Exception e) { - LOGGER.warn("Unable to get connected SDC for the host: " + hostId + " and storage pool: " + poolId + " due to " + e.getMessage(), e); + logger.warn("Unable to get connected SDC for the host: " + hostId + " and storage pool: " + poolId + " due to " + e.getMessage(), e); } return null; } private boolean hostSdcConnected(String sdcId, long poolId, int waitTimeInSecs) { - LOGGER.debug(String.format("Waiting (for %d secs) for the SDC %s of the pool id: %d to connect", waitTimeInSecs, sdcId, poolId)); + logger.debug(String.format("Waiting (for %d secs) for the SDC %s of the pool id: %d to connect", waitTimeInSecs, sdcId, poolId)); int timeBetweenTries = 1000; // Try more frequently (every sec) and return early if connected while (waitTimeInSecs > 0) { if (isHostSdcConnected(sdcId, poolId)) { @@ -335,7 +360,7 @@ private boolean isHostSdcConnected(String sdcId, long poolId) { final ScaleIOGatewayClient client = getScaleIOClient(poolId); return client.isSdcConnected(sdcId); } catch (Exception e) { - LOGGER.error("Failed to check host SDC connection", e); + logger.error("Failed to check host SDC connection", e); throw new CloudRuntimeException("Failed to establish connection with PowerFlex Gateway to check host SDC connection"); } } @@ -343,4 +368,14 @@ private boolean isHostSdcConnected(String sdcId, long poolId) { private ScaleIOGatewayClient getScaleIOClient(final Long storagePoolId) throws Exception { return ScaleIOGatewayClientConnectionPool.getInstance().getClient(storagePoolId, storagePoolDetailsDao); } + + @Override + public String getConfigComponentName() { + return ScaleIOSDCManager.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[]{ConnectOnDemand}; + } } diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java index f812ed8cce25..737cc818be87 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java @@ -34,7 +34,8 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -50,7 +51,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class ScaleIOHostListener implements HypervisorHostListener { - private static final Logger s_logger = Logger.getLogger(ScaleIOHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private AgentManager _agentMgr; @Inject private AlertManager _alertMgr; @@ -69,7 +70,7 @@ public boolean hostAdded(long hostId) { public boolean hostConnect(long hostId, long poolId) { HostVO host = _hostDao.findById(hostId); if (host == null) { - s_logger.error("Failed to connect host by HostListener as host was not found with id : " + hostId); + logger.error("Failed to connect host by HostListener as host was not found with id : " + hostId); return false; } @@ -88,7 +89,7 @@ public boolean hostConnect(long hostId, long poolId) { storagePoolHost.setLocalPath(sdcId); _storagePoolHostDao.update(storagePoolHost.getId(), storagePoolHost); } - s_logger.info("Connection established between storage pool: " + storagePool + " and host: " + hostId); + logger.info("Connection established between storage pool: " + storagePool + " and host: " + hostId); } return true; } @@ -108,7 +109,7 @@ private String getSdcIdOfHost(HostVO host, StoragePool storagePool) { Map poolDetails = answer.getPoolInfo().getDetails(); if (MapUtils.isEmpty(poolDetails)) { String msg = "PowerFlex storage SDC details not found on the host: " + hostId + ", (re)install SDC and restart agent"; - s_logger.warn(msg); + logger.warn(msg); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "SDC not found on host: " + host.getUuid(), msg); return null; } @@ -123,7 +124,7 @@ private String getSdcIdOfHost(HostVO host, StoragePool storagePool) { if (StringUtils.isBlank(sdcId)) { String msg = "Couldn't retrieve PowerFlex storage SDC details from the host: " + hostId + ", (re)install SDC and restart agent"; - s_logger.warn(msg); + logger.warn(msg); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "SDC details not found on host: " + host.getUuid(), msg); return null; } @@ -133,11 +134,11 @@ private String getSdcIdOfHost(HostVO host, StoragePool storagePool) { private String getHostSdcId(String sdcGuid, long poolId) { try { - s_logger.debug(String.format("Try to get host SDC Id for pool: %s, with SDC guid %s", poolId, sdcGuid)); + logger.debug(String.format("Try to get host SDC Id for pool: %s, with SDC guid %s", poolId, sdcGuid)); ScaleIOGatewayClient client = ScaleIOGatewayClientConnectionPool.getInstance().getClient(poolId, _storagePoolDetailsDao); return client.getSdcIdByGuid(sdcGuid); } catch (NoSuchAlgorithmException | KeyManagementException | URISyntaxException e) { - s_logger.error(String.format("Failed to get host SDC Id for pool: %s", poolId), e); + logger.error(String.format("Failed to get host SDC Id for pool: %s", poolId), e); throw new CloudRuntimeException(String.format("Failed to establish connection with PowerFlex Gateway to get host SDC Id for pool: %s", poolId)); } } diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOPrimaryDatastoreProvider.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOPrimaryDatastoreProvider.java index 0cc82c0d9f1c..37d465a40c76 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOPrimaryDatastoreProvider.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOPrimaryDatastoreProvider.java @@ -28,12 +28,13 @@ import org.apache.cloudstack.storage.datastore.driver.ScaleIOPrimaryDataStoreDriver; import org.apache.cloudstack.storage.datastore.lifecycle.ScaleIOPrimaryDataStoreLifeCycle; import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.component.ComponentContext; public class ScaleIOPrimaryDatastoreProvider implements PrimaryDataStoreProvider { - private static final Logger LOGGER = Logger.getLogger(ScaleIOPrimaryDatastoreProvider.class); + protected Logger logger = LogManager.getLogger(getClass()); private DataStoreLifeCycle lifeCycle; private PrimaryDataStoreDriver driver; diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java index e7b06267a510..4bb8df9b60db 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/util/ScaleIOUtil.java @@ -17,14 +17,15 @@ package org.apache.cloudstack.storage.datastore.util; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.UuidUtils; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; public class ScaleIOUtil { - private static final Logger LOGGER = Logger.getLogger(ScaleIOUtil.class); + protected static Logger LOGGER = LogManager.getLogger(ScaleIOUtil.class); public static final String PROVIDER_NAME = "PowerFlex"; diff --git a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java index cc1823dd782d..4979fd1fa0aa 100644 --- a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java +++ b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/driver/ScaleIOPrimaryDataStoreDriverTest.java @@ -52,6 +52,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; @@ -99,6 +100,8 @@ public class ScaleIOPrimaryDataStoreDriverTest { static MockedStatic remoteHostEndPointMock; + private AutoCloseable closeable; + @BeforeClass public static void init() { remoteHostEndPointMock = mockStatic(RemoteHostEndPoint.class); @@ -111,8 +114,14 @@ public static void close() { @Before public void initMocks() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } + @Test public void testSameScaleIOStorageInstance() { DataStore srcStore = Mockito.mock(DataStore.class); @@ -548,4 +557,37 @@ public void testCopyOfflineVolumeFailureWhenNoEndpointFound() { Assert.assertEquals(false, answer.getResult()); } + + @Test + public void testGetVolumeSizeRequiredOnPool() { + Assert.assertEquals(16L * (1024 * 1024 * 1024), + scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool( + 10L * (1024 * 1024 * 1024), + null, + true)); + + Assert.assertEquals(16L * (1024 * 1024 * 1024), + scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool( + 10L * (1024 * 1024 * 1024), + null, + false)); + + Assert.assertEquals(16L * (1024 * 1024 * 1024), + scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool( + 16L * (1024 * 1024 * 1024), + null, + false)); + + Assert.assertEquals(16L * (1024 * 1024 * 1024), + scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool( + 16L * (1024 * 1024 * 1024), + 16L * (1024 * 1024 * 1024), + false)); + + Assert.assertEquals(24L * (1024 * 1024 * 1024), + scaleIOPrimaryDataStoreDriver.getVolumeSizeRequiredOnPool( + 16L * (1024 * 1024 * 1024), + 16L * (1024 * 1024 * 1024), + true)); + } } diff --git a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java index e2f850be7ff9..52dcad519421 100644 --- a/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java +++ b/plugins/storage/volume/scaleio/src/test/java/org/apache/cloudstack/storage/datastore/lifecycle/ScaleIOPrimaryDataStoreLifeCycleTest.java @@ -27,7 +27,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; import java.util.ArrayList; import java.util.List; @@ -47,6 +46,7 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -54,6 +54,7 @@ import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import com.cloud.host.Host; @@ -108,13 +109,19 @@ public class ScaleIOPrimaryDataStoreLifeCycleTest { @InjectMocks private ScaleIOPrimaryDataStoreLifeCycle scaleIOPrimaryDataStoreLifeCycleTest; + private AutoCloseable closeable; @Before public void setUp() { - initMocks(this); + closeable = MockitoAnnotations.openMocks(this); ReflectionTestUtils.setField(scaleIOPrimaryDataStoreLifeCycleTest, "storageMgr", storageMgr); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testAttachZone() throws Exception { final DataStore dataStore = mock(DataStore.class); diff --git a/plugins/storage/volume/scaleio/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/storage/volume/scaleio/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/storage/volume/scaleio/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/storage/volume/solidfire/pom.xml b/plugins/storage/volume/solidfire/pom.xml index 831cd7c59485..46c0579a69f7 100644 --- a/plugins/storage/volume/solidfire/pom.xml +++ b/plugins/storage/volume/solidfire/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java index a5d1a39a7344..04f9045f570d 100644 --- a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java +++ b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/driver/SolidFirePrimaryDataStoreDriver.java @@ -50,7 +50,8 @@ import org.apache.cloudstack.storage.datastore.util.SolidFireUtil; import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataObjectType; @@ -91,7 +92,7 @@ import com.google.common.base.Preconditions; public class SolidFirePrimaryDataStoreDriver implements PrimaryDataStoreDriver { - private static final Logger LOGGER = Logger.getLogger(SolidFirePrimaryDataStoreDriver.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int LOWEST_HYPERVISOR_SNAPSHOT_RESERVE = 10; private static final long MIN_IOPS_FOR_TEMPLATE_VOLUME = 100L; private static final long MAX_IOPS_FOR_TEMPLATE_VOLUME = 20000L; @@ -169,7 +170,7 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore if (!lock.lock(SolidFireUtil.LOCK_TIME_IN_SECONDS)) { String errMsg = "Couldn't lock the DB (in grantAccess) on the following string: " + cluster.getUuid(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -214,7 +215,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) } if (isRevokeAccessNotNeeded(dataObject)) { - LOGGER.debug("Skipping revoke access for Solidfire data object type:" + dataObject.getType() + " id:" + dataObject.getId()); + logger.debug("Skipping revoke access for Solidfire data object type:" + dataObject.getType() + " id:" + dataObject.getId()); return; } @@ -229,12 +230,12 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore) if (!lock.lock(SolidFireUtil.LOCK_TIME_IN_SECONDS)) { String errMsg = "Couldn't lock the DB (in revokeAccess) on the following string: " + cluster.getUuid(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } - LOGGER.debug("Revoking access for Solidfire data object type:" + dataObject.getType() + " id:" + dataObject.getId()); + logger.debug("Revoking access for Solidfire data object type:" + dataObject.getType() + " id:" + dataObject.getId()); try { SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, storagePoolDetailsDao); @@ -565,13 +566,13 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet } else { errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync"; - LOGGER.error(errMsg); + logger.error(errMsg); } } catch (Exception ex) { errMsg = ex.getMessage(); - LOGGER.error(errMsg); + logger.error(errMsg); if (callback == null) { throw ex; @@ -840,7 +841,7 @@ public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncComplet catch (Exception ex) { errMsg = ex.getMessage(); - LOGGER.error(errMsg); + logger.error(errMsg); } if (callback != null) { @@ -950,7 +951,7 @@ public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback dsInfos) { lClusterDefaultMinIops = Long.parseLong(clusterDefaultMinIops); } } catch (NumberFormatException ex) { - s_logger.warn("Cannot parse the setting " + SolidFireUtil.CLUSTER_DEFAULT_MIN_IOPS + + logger.warn("Cannot parse the setting " + SolidFireUtil.CLUSTER_DEFAULT_MIN_IOPS + ", using default value: " + lClusterDefaultMinIops + ". Exception: " + ex); } @@ -181,7 +177,7 @@ public DataStore initialize(Map dsInfos) { lClusterDefaultMaxIops = Long.parseLong(clusterDefaultMaxIops); } } catch (NumberFormatException ex) { - s_logger.warn("Cannot parse the setting " + SolidFireUtil.CLUSTER_DEFAULT_MAX_IOPS + + logger.warn("Cannot parse the setting " + SolidFireUtil.CLUSTER_DEFAULT_MAX_IOPS + ", using default value: " + lClusterDefaultMaxIops + ". Exception: " + ex); } @@ -193,7 +189,7 @@ public DataStore initialize(Map dsInfos) { fClusterDefaultBurstIopsPercentOfMaxIops = Float.parseFloat(clusterDefaultBurstIopsPercentOfMaxIops); } } catch (NumberFormatException ex) { - s_logger.warn("Cannot parse the setting " + SolidFireUtil.CLUSTER_DEFAULT_BURST_IOPS_PERCENT_OF_MAX_IOPS + + logger.warn("Cannot parse the setting " + SolidFireUtil.CLUSTER_DEFAULT_BURST_IOPS_PERCENT_OF_MAX_IOPS + ", using default value: " + fClusterDefaultBurstIopsPercentOfMaxIops + ". Exception: " + ex); } @@ -247,7 +243,7 @@ public boolean attachCluster(DataStore dataStore, ClusterScope scope) { try { _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); + logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } @@ -271,7 +267,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h try { _storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); } catch (Exception e) { - s_logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); + logger.warn("Unable to establish a connection between " + host + " and " + dataStore, e); } } @@ -325,7 +321,7 @@ public boolean deleteDataStore(DataStore dataStore) { SolidFireUtil.deleteVolume(sfConnection, sfTemplateVolumeId); } catch (Exception ex) { - s_logger.error(ex.getMessage() != null ? ex.getMessage() : "Error deleting SolidFire template volume"); + logger.error(ex.getMessage() != null ? ex.getMessage() : "Error deleting SolidFire template volume"); } _tmpltPoolDao.remove(templatePoolRef.getId()); diff --git a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SolidFireSharedPrimaryDataStoreLifeCycle.java b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SolidFireSharedPrimaryDataStoreLifeCycle.java index dc106d398e1e..4877e86bf9f6 100644 --- a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SolidFireSharedPrimaryDataStoreLifeCycle.java +++ b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/SolidFireSharedPrimaryDataStoreLifeCycle.java @@ -26,8 +26,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; - import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -73,8 +71,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class SolidFireSharedPrimaryDataStoreLifeCycle extends BasePrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { - private static final Logger LOGGER = Logger.getLogger(SolidFireSharedPrimaryDataStoreLifeCycle.class); - @Inject private AccountDao accountDao; @Inject private AccountDetailsDao accountDetailsDao; @Inject private AgentManager agentMgr; @@ -183,7 +179,7 @@ public DataStore initialize(Map dsInfos) { lMinIops = Long.parseLong(minIops); } } catch (Exception ex) { - LOGGER.info("[ignored] error getting Min IOPS: " + ex.getLocalizedMessage()); + logger.info("[ignored] error getting Min IOPS: " + ex.getLocalizedMessage()); } try { @@ -193,7 +189,7 @@ public DataStore initialize(Map dsInfos) { lMaxIops = Long.parseLong(maxIops); } } catch (Exception ex) { - LOGGER.info("[ignored] error getting Max IOPS: " + ex.getLocalizedMessage()); + logger.info("[ignored] error getting Max IOPS: " + ex.getLocalizedMessage()); } try { @@ -203,7 +199,7 @@ public DataStore initialize(Map dsInfos) { lBurstIops = Long.parseLong(burstIops); } } catch (Exception ex) { - LOGGER.info("[ignored] error getting Burst IOPS: " + ex.getLocalizedMessage()); + logger.info("[ignored] error getting Burst IOPS: " + ex.getLocalizedMessage()); } if (lMinIops > lMaxIops) { @@ -272,7 +268,7 @@ public DataStore initialize(Map dsInfos) { if (!lock.lock(SolidFireUtil.LOCK_TIME_IN_SECONDS)) { String errMsg = "Couldn't lock the DB on the following string: " + cluster.getUuid(); - LOGGER.debug(errMsg); + logger.debug(errMsg); throw new CloudRuntimeException(errMsg); } @@ -418,12 +414,12 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { poolHosts.add(host); } catch (Exception e) { - LOGGER.warn("Unable to establish a connection between " + host + " and " + primaryDataStoreInfo, e); + logger.warn("Unable to establish a connection between " + host + " and " + primaryDataStoreInfo, e); } } if (poolHosts.isEmpty()) { - LOGGER.warn("No host can access storage pool '" + primaryDataStoreInfo + "' on cluster '" + primaryDataStoreInfo.getClusterId() + "'."); + logger.warn("No host can access storage pool '" + primaryDataStoreInfo + "' on cluster '" + primaryDataStoreInfo.getClusterId() + "'."); primaryDataStoreDao.expunge(primaryDataStoreInfo.getId()); @@ -479,7 +475,7 @@ private boolean createStoragePool(HostVO host, StoragePool storagePool) { msg = "Cannot create storage pool through host '" + hostId + "' due to CreateStoragePoolCommand returns null"; } - LOGGER.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -562,7 +558,7 @@ public boolean deleteDataStore(DataStore dataStore) { final Answer answer = agentMgr.easySend(host.getHostId(), deleteCmd); if (answer != null && answer.getResult()) { - LOGGER.info("Successfully deleted storage pool using Host ID " + host.getHostId()); + logger.info("Successfully deleted storage pool using Host ID " + host.getHostId()); HostVO hostVO = hostDao.findById(host.getHostId()); @@ -575,10 +571,10 @@ public boolean deleteDataStore(DataStore dataStore) { } else { if (answer != null) { - LOGGER.error("Failed to delete storage pool using Host ID " + host.getHostId() + ": " + answer.getResult()); + logger.error("Failed to delete storage pool using Host ID " + host.getHostId() + ": " + answer.getResult()); } else { - LOGGER.error("Failed to delete storage pool using Host ID " + host.getHostId()); + logger.error("Failed to delete storage pool using Host ID " + host.getHostId()); } } } @@ -591,7 +587,7 @@ public boolean deleteDataStore(DataStore dataStore) { if (!lock.lock(SolidFireUtil.LOCK_TIME_IN_SECONDS)) { String errMsg = "Couldn't lock the DB on the following string: " + cluster.getUuid(); - LOGGER.debug(errMsg); + logger.debug(errMsg); throw new CloudRuntimeException(errMsg); } @@ -660,12 +656,12 @@ private void sendModifyTargetsCommand(ModifyTargetsCommand cmd, long hostId) { if (answer == null) { String msg = "Unable to get an answer to the modify targets command"; - LOGGER.warn(msg); + logger.warn(msg); } else if (!answer.getResult()) { String msg = "Unable to modify target on the following host: " + hostId; - LOGGER.warn(msg); + logger.warn(msg); } } diff --git a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireHostListener.java b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireHostListener.java index 998a3f95a533..d84734283939 100644 --- a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireHostListener.java +++ b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireHostListener.java @@ -25,7 +25,8 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; @@ -55,7 +56,7 @@ import com.cloud.vm.dao.VMInstanceDao; public class SolidFireHostListener implements HypervisorHostListener { - private static final Logger LOGGER = Logger.getLogger(SolidFireHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private AgentManager agentMgr; @Inject private AlertManager alertMgr; @@ -73,13 +74,13 @@ public boolean hostAdded(long hostId) { HostVO host = hostDao.findById(hostId); if (host == null) { - LOGGER.error(String.format("Failed to add host by SolidFireHostListener as host was not found with id = %s ", hostId)); + logger.error(String.format("Failed to add host by SolidFireHostListener as host was not found with id = %s ", hostId)); return false; } if (host.getClusterId() == null) { - LOGGER.error("Failed to add host by SolidFireHostListener as host has no associated cluster id"); + logger.error("Failed to add host by SolidFireHostListener as host has no associated cluster id"); return false; } @@ -295,6 +296,6 @@ private void sendModifyStoragePoolCommand(ModifyStoragePoolCommand cmd, StorageP assert (answer instanceof ModifyStoragePoolAnswer) : "ModifyStoragePoolAnswer expected ; Pool = " + storagePool.getId() + " Host = " + hostId; - LOGGER.info("Connection established between storage pool " + storagePool + " and host + " + hostId); + logger.info("Connection established between storage pool " + storagePool + " and host + " + hostId); } } diff --git a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireSharedHostListener.java b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireSharedHostListener.java index f111682739c5..98c8bfb51c19 100644 --- a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireSharedHostListener.java +++ b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireSharedHostListener.java @@ -32,7 +32,8 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.util.SolidFireUtil; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -51,7 +52,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class SolidFireSharedHostListener implements HypervisorHostListener { - private static final Logger LOGGER = Logger.getLogger(SolidFireSharedHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private AgentManager agentMgr; @Inject private AlertManager alertMgr; @@ -67,13 +68,13 @@ public boolean hostAdded(long hostId) { HostVO host = hostDao.findById(hostId); if (host == null) { - LOGGER.error(String.format("Failed to add host by SolidFireSharedHostListener as host was not found with id = %s ", hostId)); + logger.error(String.format("Failed to add host by SolidFireSharedHostListener as host was not found with id = %s ", hostId)); return false; } if (host.getClusterId() == null) { - LOGGER.error("Failed to add host by SolidFireSharedHostListener as host has no associated cluster id"); + logger.error("Failed to add host by SolidFireSharedHostListener as host has no associated cluster id"); return false; } @@ -228,7 +229,7 @@ private ModifyStoragePoolAnswer sendModifyStoragePoolCommand(ModifyStoragePoolCo assert (answer instanceof ModifyStoragePoolAnswer) : "ModifyStoragePoolAnswer not returned from ModifyStoragePoolCommand; Storage pool = " + storagePool.getId() + "; Host = " + hostId; - LOGGER.info("Connection established between storage pool " + storagePool + " and host " + hostId); + logger.info("Connection established between storage pool " + storagePool + " and host " + hostId); return (ModifyStoragePoolAnswer)answer; } diff --git a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java index 47f2f8819f2c..671431f41635 100644 --- a/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java +++ b/plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java @@ -28,7 +28,8 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; @@ -80,7 +81,7 @@ import static org.apache.commons.lang.ArrayUtils.toPrimitive; public class SolidFireUtil { - private static final Logger LOGGER = Logger.getLogger(SolidFireUtil.class); + protected static Logger LOGGER = LogManager.getLogger(SolidFireUtil.class); public static final String PROVIDER_NAME = "SolidFire"; public static final String SHARED_PROVIDER_NAME = "SolidFireShared"; @@ -88,7 +89,7 @@ public class SolidFireUtil { private static final Random RANDOM = new Random(System.nanoTime()); public static final int LOCK_TIME_IN_SECONDS = 300; - public static final String LOG_PREFIX = "SolidFire: "; + public static final String LOGGER_PREFIX = "SolidFire: "; public static final String MANAGEMENT_VIP = "mVip"; public static final String STORAGE_VIP = "sVip"; diff --git a/plugins/storage/volume/solidfire/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java b/plugins/storage/volume/solidfire/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java index 71bc603a1b67..08f95b15d136 100644 --- a/plugins/storage/volume/solidfire/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java +++ b/plugins/storage/volume/solidfire/src/test/java/org/apache/cloudstack/storage/test/VolumeTest.java @@ -27,7 +27,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -108,7 +108,7 @@ public void setUp() { List results = new ArrayList(); results.add(host); Mockito.when(hostDao.listAll()).thenReturn(results); - Mockito.when(hostDao.findHypervisorHostInCluster(Matchers.anyLong())).thenReturn(results); + Mockito.when(hostDao.findHypervisorHostInCluster(ArgumentMatchers.anyLong())).thenReturn(results); // CreateObjectAnswer createVolumeFromImageAnswer = new // CreateObjectAnswer(null,UUID.randomUUID().toString(), null); diff --git a/plugins/storage/volume/solidfire/src/test/resource/storageContext.xml b/plugins/storage/volume/solidfire/src/test/resource/storageContext.xml index 4090ac3ebd2e..df4fb385c2f2 100644 --- a/plugins/storage/volume/solidfire/src/test/resource/storageContext.xml +++ b/plugins/storage/volume/solidfire/src/test/resource/storageContext.xml @@ -22,7 +22,7 @@ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/tx + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd @@ -35,7 +35,7 @@ - + @@ -43,10 +43,10 @@ - + - + diff --git a/plugins/storage/volume/storpool/README.md b/plugins/storage/volume/storpool/README.md index 77522344b524..5cad0069621e 100644 --- a/plugins/storage/volume/storpool/README.md +++ b/plugins/storage/volume/storpool/README.md @@ -294,7 +294,7 @@ This is independent of StorPool as snapshots exist on secondary. ### Creating ROOT volume from templates When creating the first volume based on the given template, if snapshot of the template does not exists on StorPool it will be first downloaded (cached) to PRIMARY storage. -This is mapped to a StorPool snapshot so, creating succecutive volumes from the same template does not incur additional +This is mapped to a StorPool snapshot so, creating succecutive volumes from the same template does not incur additional copying of data to PRIMARY storage. This cached snapshot is garbage collected when the original template is deleted from CloudStack. This cleanup is done @@ -345,6 +345,46 @@ corresponding system disk offering. CloudStack has no way to specify max BW. Do they want to be able to specify max BW only is sufficient. +================================================================================ + +StorPool provides the ‘storpool_qos’ service ([QoS user guide](https://kb.storpool.com/storpool_misc/qos.html#storpool-qos-user-guide)) that tracks and configures the storage tier for all volumes based on a specifically provided `qc` tag specifying the storage tier for each volume. + +To manage the QoS limits with a `qc` tag, you have to add a `qc` tag resource detail to each disk offering to which a tier should be applied, with a key `SP_QOSCLASS` and the value from the configuration file for the `storpool_qos` service: + + add resourcedetail resourceid={diskofferingid} details[0].key=SP_QOSCLASS details[0].value={the name of the tier from the config} resourcetype=DiskOffering + +To change the tier via CloudStack, you can use the CloudStack API call `changeOfferingForVolume`. The size is required, but the user could use the current volume size. Example: + + change offeringforvolume id={The UUID of the Volume} diskofferingid={The UUID of the disk offering} size={The current or a new size for the volume} + +Users who were using the offerings to change the StorPool template via the `SP_TEMPLATE` detail, will continue to have this functionality but should use `changeOfferingForVolume` API call instead of: + - `resizeVolume` API call for DATA disk + - `scaleVirtualMachine` API call for ROOT disk + + +If the disk offering has both `SP_TEMPLATE` and `SP_QOSCLASS` defined, the `SP_QOSCLASS` detail will be prioritised, setting the volume’s QoS using the respective ‘qc’ tag value. In case the QoS for a volume is changed manually, the ‘storpool_qos’ service will automatically reset the QoS limits following the ‘qc’ tag value once per minute. + +

      Usage

      + +Creating Disk Offering for each tier. + +Go to Service Offerings > Disk Offering > Add disk offering. + +Add disk offering detail with API call in CloudStack CLI. + + add resourcedetail resourcetype=diskoffering resourceid=$UUID details[0].key=SP_QOSCLASS details[0].value=$Tier Name + + +Creating VM with QoS + +Deploy virtual machine: Go to Compute> Instances> Add Instances. + - For the ROOT volume, choose the option `Override disk offering`. This will set the required `qc` tag from the disk offering (DO) detail. + +Creating DATA disk with QoS + - Create volume via GUI/CLI and choose a disk offering which has the required `SP_QOSCLASS` detail + +To update the tier of a ROOT/DATA volume go to Storage> Volumes and select the Volume and click on the Change disk offering for the volume in the upper right corner. + ## Supported operations for Volume encryption Supported Virtual machine operations - live migration of VM to another host, virtual machine snapshots (group snapshot without memory), revert VM snapshot, delete VM snapshot diff --git a/plugins/storage/volume/storpool/pom.xml b/plugins/storage/volume/storpool/pom.xml index 8f06ec9c7efa..e1555dc8958d 100644 --- a/plugins/storage/volume/storpool/pom.xml +++ b/plugins/storage/volume/storpool/pom.xml @@ -17,7 +17,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml @@ -42,9 +42,12 @@ ${project.version} - ch.qos.reload4j - reload4j - ${cs.reload4j.version} + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api org.apache.commons @@ -54,7 +57,7 @@ org.mockito mockito-inline - 4.7.0 + ${cs.mockito.version} pl.project13.maven @@ -65,9 +68,16 @@ - org.codehaus.gmaven - gmaven-plugin - 1.5 + org.codehaus.gmavenplus + gmavenplus-plugin + ${cs.gmavenplus.version} + + + org.codehaus.groovy + groovy-all + ${cs.groovy.version} + + set-properties @@ -76,15 +86,16 @@ execute - 1.7 - - File git = new File("./.git") - if (!git.exists()) { - pom.properties['storpool.skip.git.properties'] = 'true' - } else { - pom.properties['storpool.skip.git.properties'] = 'false' - } - + + + diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolBackupSnapshotCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolBackupSnapshotCommandWrapper.java index 58264161bd63..b3f49b015d1f 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolBackupSnapshotCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolBackupSnapshotCommandWrapper.java @@ -39,7 +39,6 @@ import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.cloudstack.utils.qemu.QemuObject.EncryptFormat; import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.storage.StorPoolBackupSnapshotCommand; import com.cloud.agent.api.to.DataStoreTO; @@ -54,7 +53,6 @@ @ResourceWrapper(handles = StorPoolBackupSnapshotCommand.class) public final class StorPoolBackupSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(StorPoolBackupSnapshotCommandWrapper.class); @Override public CopyCmdAnswer execute(final StorPoolBackupSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -96,7 +94,7 @@ public CopyCmdAnswer execute(final StorPoolBackupSnapshotCommand cmd, final Libv } catch (final Exception e) { final String error = String.format("Failed to backup snapshot with id [%s] with a pool %s, due to %s", cmd.getSourceTO().getId(), cmd.getSourceTO().getDataStore().getUuid(), e.getMessage()); SP_LOG(error); - s_logger.debug(error); + logger.debug(error); return new CopyCmdAnswer(cmd, e); } finally { if (srcPath != null) { @@ -107,7 +105,7 @@ public CopyCmdAnswer execute(final StorPoolBackupSnapshotCommand cmd, final Libv try { secondaryPool.delete(); } catch (final Exception e) { - s_logger.debug("Failed to delete secondary storage", e); + logger.debug("Failed to delete secondary storage", e); } } } diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolBackupTemplateFromSnapshotCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolBackupTemplateFromSnapshotCommandWrapper.java index 518cbb8d5e5f..da9528645d59 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolBackupTemplateFromSnapshotCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolBackupTemplateFromSnapshotCommandWrapper.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.commons.io.FileUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.storage.StorPoolBackupTemplateFromSnapshotCommand; import com.cloud.agent.api.to.DataStoreTO; @@ -58,7 +57,6 @@ @ResourceWrapper(handles = StorPoolBackupTemplateFromSnapshotCommand.class) public class StorPoolBackupTemplateFromSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(StorPoolBackupTemplateFromSnapshotCommandWrapper.class); @Override public CopyCmdAnswer execute(final StorPoolBackupTemplateFromSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -142,7 +140,7 @@ public CopyCmdAnswer execute(final StorPoolBackupTemplateFromSnapshotCommand cmd } catch (final Exception e) { final String error = "failed to backup snapshot: " + e.getMessage(); SP_LOG(error); - s_logger.debug(error); + logger.debug(error); return new CopyCmdAnswer(cmd, e); } finally { if (srcPath != null) { @@ -153,7 +151,7 @@ public CopyCmdAnswer execute(final StorPoolBackupTemplateFromSnapshotCommand cmd try { secondaryPool.delete(); } catch (final Exception e) { - s_logger.debug("Failed to delete secondary storage", e); + logger.debug("Failed to delete secondary storage", e); } } } diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolCopyVolumeToSecondaryCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolCopyVolumeToSecondaryCommandWrapper.java index bd50f43025f2..113fb11ea548 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolCopyVolumeToSecondaryCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolCopyVolumeToSecondaryCommandWrapper.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.log4j.Logger; import com.cloud.agent.api.storage.StorPoolCopyVolumeToSecondaryCommand; import com.cloud.agent.api.to.DataStoreTO; @@ -45,7 +44,6 @@ @ResourceWrapper(handles = StorPoolCopyVolumeToSecondaryCommand.class) public final class StorPoolCopyVolumeToSecondaryCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(StorPoolCopyVolumeToSecondaryCommandWrapper.class); @Override public CopyCmdAnswer execute(final StorPoolCopyVolumeToSecondaryCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -104,7 +102,7 @@ public CopyCmdAnswer execute(final StorPoolCopyVolumeToSecondaryCommand cmd, fin return new CopyCmdAnswer(dst); } catch (final Exception e) { final String error = "Failed to copy volume to secondary storage: " + e.getMessage(); - s_logger.debug(error); + logger.debug(error); return new CopyCmdAnswer(error); } finally { if (srcPath != null) { @@ -116,7 +114,7 @@ public CopyCmdAnswer execute(final StorPoolCopyVolumeToSecondaryCommand cmd, fin SP_LOG("StorpoolCopyVolumeToSecondaryCommandWrapper.execute: secondaryPool=%s " , secondaryPool); secondaryPool.delete(); } catch (final Exception e) { - s_logger.debug("Failed to delete secondary storage", e); + logger.debug("Failed to delete secondary storage", e); } } } diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java index 87a46ba62c93..3e7118ab81d7 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadTemplateCommandWrapper.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.storage.StorPoolDownloadTemplateCommand; import com.cloud.agent.api.to.DataStoreTO; @@ -47,7 +46,6 @@ @ResourceWrapper(handles = StorPoolDownloadTemplateCommand.class) public final class StorPoolDownloadTemplateCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(StorPoolDownloadTemplateCommandWrapper.class); @Override public CopyCmdAnswer execute(final StorPoolDownloadTemplateCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -120,7 +118,7 @@ public CopyCmdAnswer execute(final StorPoolDownloadTemplateCommand cmd, final Li return new CopyCmdAnswer(dst); } catch (final Exception e) { final String error = "Failed to copy template to primary: " + e.getMessage(); - s_logger.debug(error); + logger.debug(error); return new CopyCmdAnswer(cmd, e); } finally { if (dstPath != null) { @@ -131,7 +129,7 @@ public CopyCmdAnswer execute(final StorPoolDownloadTemplateCommand cmd, final Li try { secondaryPool.delete(); } catch (final Exception e) { - s_logger.debug("Failed to delete secondary storage", e); + logger.debug("Failed to delete secondary storage", e); } } } diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadVolumeCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadVolumeCommandWrapper.java index d1a58a4aeb80..37284b597d2c 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadVolumeCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolDownloadVolumeCommandWrapper.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.cloudstack.utils.qemu.QemuImgFile; //import java.io.File; -import org.apache.log4j.Logger; import com.cloud.agent.api.storage.StorPoolDownloadVolumeCommand; import com.cloud.agent.api.to.DataStoreTO; @@ -48,7 +47,6 @@ @ResourceWrapper(handles = StorPoolDownloadVolumeCommand.class) public final class StorPoolDownloadVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(StorPoolDownloadVolumeCommandWrapper.class); @Override public CopyCmdAnswer execute(final StorPoolDownloadVolumeCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -143,7 +141,7 @@ public CopyCmdAnswer execute(final StorPoolDownloadVolumeCommand cmd, final Libv } catch (final Exception e) { final String error = "Failed to copy volume to primary: " + e.getMessage(); SP_LOG(error); - s_logger.debug(error); + logger.debug(error); return new CopyCmdAnswer(cmd, e); } finally { if (dstPath != null) { @@ -154,7 +152,7 @@ public CopyCmdAnswer execute(final StorPoolDownloadVolumeCommand cmd, final Libv try { secondaryPool.delete(); } catch (final Exception e) { - s_logger.debug("Failed to delete secondary storage", e); + logger.debug("Failed to delete secondary storage", e); } } } diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolModifyStorageCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolModifyStorageCommandWrapper.java index 8bd8a52b667f..a44ff5473ae5 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolModifyStorageCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolModifyStorageCommandWrapper.java @@ -24,7 +24,6 @@ import java.util.Map.Entry; import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.StorPoolModifyStoragePoolAnswer; @@ -44,13 +43,12 @@ @ResourceWrapper(handles = StorPoolModifyStoragePoolCommand.class) public final class StorPoolModifyStorageCommandWrapper extends CommandWrapper { - private static final Logger log = Logger.getLogger(StorPoolModifyStorageCommandWrapper.class); @Override public Answer execute(final StorPoolModifyStoragePoolCommand command, final LibvirtComputingResource libvirtComputingResource) { String clusterId = StorPoolStoragePool.getStorPoolConfigParam("SP_CLUSTER_ID"); if (clusterId == null) { - log.debug(String.format("Could not get StorPool cluster id for a command [%s]", command.getClass())); + logger.debug(String.format("Could not get StorPool cluster id for a command [%s]", command.getClass())); return new Answer(command, false, "spNotFound"); } try { @@ -63,14 +61,14 @@ public Answer execute(final StorPoolModifyStoragePoolCommand command, final Libv storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool() .getUserInfo(), command.getPool().getType()); if (storagepool == null) { - log.debug(String.format("Did not find a storage pool [%s]", command.getPool().getId())); + logger.debug(String.format("Did not find a storage pool [%s]", command.getPool().getId())); return new Answer(command, false, String.format("Failed to create storage pool [%s]", command.getPool().getId())); } final Map tInfo = new HashMap<>(); return new StorPoolModifyStoragePoolAnswer(command, storagepool.getCapacity(), storagepool.getAvailable(), tInfo, clusterId, storagepool.getStorageNodeId()); } catch (Exception e) { - log.debug(String.format("Could not modify storage due to %s", e.getMessage())); + logger.debug(String.format("Could not modify storage due to %s", e.getMessage())); return new Answer(command, e); } } @@ -82,7 +80,7 @@ public String attachOrDetachVolume(String command, String type, String volumeUui } String err = null; - Script sc = new Script("storpool", 300000, log); + Script sc = new Script("storpool", 300000, logger); sc.add("-M"); sc.add("-j"); sc.add(command); @@ -116,7 +114,7 @@ public String attachOrDetachVolume(String command, String type, String volumeUui } if (err != null) { - log.warn(err); + logger.warn(err); } return res; } diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolResizeVolumeCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolResizeVolumeCommandWrapper.java index 9f9277768e65..8fc6b6bbcb8f 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolResizeVolumeCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolResizeVolumeCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.storage.ResizeVolumeAnswer; import com.cloud.agent.api.storage.StorPoolResizeVolumeCommand; @@ -37,7 +36,6 @@ @ResourceWrapper(handles = StorPoolResizeVolumeCommand.class) public final class StorPoolResizeVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(StorPoolResizeVolumeCommandWrapper.class); @Override public ResizeVolumeAnswer execute(final StorPoolResizeVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -51,7 +49,7 @@ public ResizeVolumeAnswer execute(final StorPoolResizeVolumeCommand command, fin if (currentSize == newSize) { // nothing to do - s_logger.info("No need to resize volume: current size " + currentSize + " is same as new size " + newSize); + logger.info("No need to resize volume: current size " + currentSize + " is same as new size " + newSize); return new ResizeVolumeAnswer(command, true, "success", currentSize); } @@ -65,7 +63,7 @@ public ResizeVolumeAnswer execute(final StorPoolResizeVolumeCommand command, fin if (!command.isAttached()) { StorPoolStorageAdaptor.attachOrDetachVolume("attach", "volume", path); } - final Script resizecmd = new Script(libvirtComputingResource.getResizeVolumePath(), libvirtComputingResource.getCmdsTimeout(), s_logger); + final Script resizecmd = new Script(libvirtComputingResource.getResizeVolumePath(), libvirtComputingResource.getCmdsTimeout(), logger); resizecmd.add("-s", String.valueOf(newSize)); resizecmd.add("-c", String.valueOf(currentSize)); resizecmd.add("-p", path); @@ -83,11 +81,11 @@ public ResizeVolumeAnswer execute(final StorPoolResizeVolumeCommand command, fin pool.refresh(); final long finalSize = pool.getPhysicalDisk(volid).getVirtualSize(); - s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize); + logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize); return new ResizeVolumeAnswer(command, true, "success", finalSize); } catch (final Exception e) { final String error = "Failed to resize volume: " + e.getMessage(); - s_logger.debug(error); + logger.debug(error); return new ResizeVolumeAnswer(command, false, error); } finally { if (!command.isAttached() && volPath != null) { diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolSetVolumeEncryptionCommandWrapper.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolSetVolumeEncryptionCommandWrapper.java index 8fdc28efc74f..6efc118cf7e3 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolSetVolumeEncryptionCommandWrapper.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/StorPoolSetVolumeEncryptionCommandWrapper.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.Answer; @@ -54,7 +53,6 @@ @ResourceWrapper(handles = StorPoolSetVolumeEncryptionCommand.class) public class StorPoolSetVolumeEncryptionCommandWrapper extends CommandWrapper { - private static final Logger logger = Logger.getLogger(StorPoolSetVolumeEncryptionCommandWrapper.class); @Override public StorPoolSetVolumeEncryptionAnswer execute(StorPoolSetVolumeEncryptionCommand command, diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java index 273f088d77f9..c05d8b3ae08a 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java @@ -28,7 +28,8 @@ import java.util.Map; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.to.DiskTO; import com.cloud.storage.Storage; @@ -39,7 +40,6 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; -@StorageAdaptorInfo(storagePoolType=StoragePoolType.StorPool) public class StorPoolStorageAdaptor implements StorageAdaptor { public static void SP_LOG(String fmt, Object... args) { try (PrintWriter spLogFile = new PrintWriter(new BufferedWriter(new FileWriter("/var/log/cloudstack/agent/storpool-agent.log", true)))) { @@ -52,7 +52,7 @@ public static void SP_LOG(String fmt, Object... args) { } } - private static final Logger log = Logger.getLogger(StorPoolStorageAdaptor.class); + protected static Logger LOGGER = LogManager.getLogger(StorPoolStorageAdaptor.class); private static final Map storageUuidToStoragePool = new HashMap(); @@ -65,6 +65,11 @@ public KVMStoragePool createStoragePool(String uuid, String host, int port, Stri return storagePool; } + @Override + public StoragePoolType getStoragePoolType() { + return StoragePoolType.StorPool; + } + @Override public KVMStoragePool getStoragePool(String uuid) { SP_LOG("StorPoolStorageAdaptor.getStoragePool: uuid=%s", uuid); @@ -99,7 +104,7 @@ private static long getDeviceSize(final String devPath) { if (!file.exists()) { return 0; } - Script sc = new Script("blockdev", 0, log); + Script sc = new Script("blockdev", 0, LOGGER); sc.add("--getsize64", devPath); OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); @@ -108,7 +113,7 @@ private static long getDeviceSize(final String devPath) { if (res != null) { SP_LOG("Unable to retrieve device size for %s. Res: %s", devPath, res); - log.debug(String.format("Unable to retrieve device size for %s. Res: %s", devPath, res)); + LOGGER.debug(String.format("Unable to retrieve device size for %s. Res: %s", devPath, res)); return 0; } @@ -156,7 +161,7 @@ public static boolean attachOrDetachVolume(String command, String type, String v String err = null; for(int i = 0; i < numTries; i++) { - Script sc = new Script("storpool", 0, log); + Script sc = new Script("storpool", 0, LOGGER); sc.add("-M"); sc.add(command); sc.add(type, name); @@ -188,7 +193,7 @@ public static boolean attachOrDetachVolume(String command, String type, String v if (err != null) { SP_LOG(err); - log.warn(err); + LOGGER.warn(err); throw new CloudRuntimeException(err); } @@ -207,7 +212,7 @@ public static boolean resize(String newSize, String volumeUuid ) { SP_LOG("StorPoolStorageAdaptor.resize: size=%s, uuid=%s, name=%s", newSize, volumeUuid, name); - Script sc = new Script("storpool", 0, log); + Script sc = new Script("storpool", 0, LOGGER); sc.add("-M"); sc.add("volume"); sc.add(name); @@ -224,7 +229,7 @@ public static boolean resize(String newSize, String volumeUuid ) { String err = String.format("Unable to resize volume %s. Error: %s", name, res); SP_LOG(err); - log.warn(err); + LOGGER.warn(err); throw new CloudRuntimeException(err); } @@ -232,7 +237,7 @@ public static boolean resize(String newSize, String volumeUuid ) { public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) { SP_LOG("StorPoolStorageAdaptor.getPhysicalDisk: uuid=%s, pool=%s", volumeUuid, pool); - log.debug(String.format("getPhysicalDisk: uuid=%s, pool=%s", volumeUuid, pool)); + LOGGER.debug(String.format("getPhysicalDisk: uuid=%s, pool=%s", volumeUuid, pool)); final long deviceSize = getDeviceSize(volumeUuid); @@ -247,7 +252,7 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) { public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map details) { SP_LOG("StorPoolStorageAdaptor.connectPhysicalDisk: uuid=%s, pool=%s", volumeUuid, pool); - log.debug(String.format("connectPhysicalDisk: uuid=%s, pool=%s", volumeUuid, pool)); + LOGGER.debug(String.format("connectPhysicalDisk: uuid=%s, pool=%s", volumeUuid, pool)); return attachOrDetachVolume("attach", "volume", volumeUuid); } @@ -256,19 +261,19 @@ public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map volumeToDisconnect) { String volumeUuid = volumeToDisconnect.get(DiskTO.UUID); - log.debug(String.format("StorPoolStorageAdaptor.disconnectPhysicalDisk: map. uuid=%s", volumeUuid)); + LOGGER.debug(String.format("StorPoolStorageAdaptor.disconnectPhysicalDisk: map. uuid=%s", volumeUuid)); return attachOrDetachVolume("detach", "volume", volumeUuid); } @Override public boolean disconnectPhysicalDiskByPath(String localPath) { - log.debug(String.format("disconnectPhysicalDiskByPath: localPath=%s", localPath)); + LOGGER.debug(String.format("disconnectPhysicalDiskByPath: localPath=%s", localPath)); return attachOrDetachVolume("detach", "volume", localPath); } @@ -283,7 +288,7 @@ public boolean deletePhysicalDisk(String volumeUuid, KVMStoragePool pool, Storag throw new UnsupportedOperationException(err); } - Script sc = new Script("storpool", 0, log); + Script sc = new Script("storpool", 0, LOGGER); sc.add("-M"); sc.add("snapshot", name); sc.add("delete", name); @@ -294,7 +299,7 @@ public boolean deletePhysicalDisk(String volumeUuid, KVMStoragePool pool, Storag if (res != null) { final String err = String.format("Unable to delete StorPool snapshot '%s'. Error: %s", name, res); SP_LOG(err); - log.warn(err); + LOGGER.warn(err); throw new UnsupportedOperationException(err); } return true; // apparently ignored diff --git a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStoragePool.java b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStoragePool.java index 02095503c3b4..aa0a8849d90f 100644 --- a/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStoragePool.java +++ b/plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStoragePool.java @@ -21,7 +21,8 @@ import java.util.Map.Entry; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.joda.time.Duration; import com.cloud.agent.api.to.HostTO; @@ -39,7 +40,7 @@ import com.google.gson.JsonSyntaxException; public class StorPoolStoragePool implements KVMStoragePool { - private static final Logger log = Logger.getLogger(StorPoolStoragePool.class); + protected Logger logger = LogManager.getLogger(StorPoolStoragePool.class); private String _uuid; private String _sourceHost; private int _sourcePort; @@ -199,8 +200,8 @@ public String createHeartBeatCommand(HAStoragePool primaryStoragePool, String ho boolean isStorageNodeUp = checkingHeartBeat(primaryStoragePool, null); if (!isStorageNodeUp && !hostValidation) { //restart the host - log.debug(String.format("The host [%s] will be restarted because the health check failed for the storage pool [%s]", hostPrivateIp, primaryStoragePool.getPool().getType())); - Script cmd = new Script(primaryStoragePool.getPool().getHearthBeatPath(), HeartBeatUpdateTimeout, log); + logger.debug(String.format("The host [%s] will be restarted because the health check failed for the storage pool [%s]", hostPrivateIp, primaryStoragePool.getPool().getType())); + Script cmd = new Script(primaryStoragePool.getPool().getHearthBeatPath(), HeartBeatUpdateTimeout, logger); cmd.add("-c"); cmd.execute(); return "Down"; @@ -214,7 +215,7 @@ public String getStorageNodeId() { } public static final String getStorPoolConfigParam(String param) { - Script sc = new Script("storpool_confget", 0, Logger.getLogger(StorPoolStoragePool.class)); + Script sc = new Script("storpool_confget", 0, LogManager.getLogger(StorPoolStoragePool.class)); OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); String configParam = null; @@ -289,7 +290,7 @@ private boolean checkIfNodeIsRunning(String response, Integer hostStorageNodeId) } private String executeStorPoolServiceListCmd(OutputInterpreter.AllLinesParser parser) { - Script sc = new Script("storpool", 0, log); + Script sc = new Script("storpool", 0, logger); sc.add("-j"); sc.add("service"); sc.add("list"); diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/collector/StorPoolAbandonObjectsCollector.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/collector/StorPoolAbandonObjectsCollector.java index f4821e269266..6258767921d2 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/collector/StorPoolAbandonObjectsCollector.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/collector/StorPoolAbandonObjectsCollector.java @@ -37,10 +37,9 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.cloudstack.storage.datastore.util.StorPoolHelper; +//import org.apache.cloudstack.storage.datastore.util.StorPoolHelper; import org.apache.cloudstack.storage.datastore.util.StorPoolUtil; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; @@ -53,14 +52,13 @@ import com.google.gson.JsonObject; public class StorPoolAbandonObjectsCollector extends ManagerBase implements Configurable { - private static Logger log = Logger.getLogger(StorPoolAbandonObjectsCollector.class); @Inject private PrimaryDataStoreDao storagePoolDao; @Inject private StoragePoolDetailsDao storagePoolDetailsDao; private ScheduledExecutorService _volumeTagsUpdateExecutor; - private static final String ABANDON_LOG = "/var/log/cloudstack/management/storpool-abandoned-objects"; + private static final String ABANDON_LOGGER = "/var/log/cloudstack/management/storpool-abandoned-objects"; static final ConfigKey volumeCheckupTagsInterval = new ConfigKey("Advanced", Integer.class, @@ -91,7 +89,7 @@ public boolean start() { private void init() { List spPools = storagePoolDao.findPoolsByProvider(StorPoolUtil.SP_PROVIDER_NAME); if (CollectionUtils.isNotEmpty(spPools)) { - StorPoolHelper.appendLogger(log, ABANDON_LOG, "abandon"); +// StorPoolHelper.appendLogger(logger, ABANDON_LOGGER, "abandon"); } _volumeTagsUpdateExecutor = Executors.newScheduledThreadPool(2, new NamedThreadFactory("StorPoolAbandonObjectsCollector")); @@ -121,7 +119,7 @@ protected void runInContext() { JsonArray arr = StorPoolUtil.volumesList(StorPoolUtil.getSpConnection(storagePoolVO.getUuid(), storagePoolVO.getId(), storagePoolDetailsDao, storagePoolDao)); volumes.putAll(getStorPoolNamesAndCsTag(arr)); } catch (Exception e) { - log.debug(String.format("Could not collect abandon objects due to %s", e.getMessage()), e); + logger.debug(String.format("Could not collect abandon objects due to %s", e.getMessage()), e); } } Transaction.execute(new TransactionCallbackNoReturn() { @@ -139,10 +137,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) { pstmt.executeUpdate(); } catch (SQLException e) { - log.info(String.format("[ignored] SQL failed to delete vm work job: %s ", + logger.info(String.format("[ignored] SQL failed to delete vm work job: %s ", e.getLocalizedMessage())); } catch (Throwable e) { - log.info(String.format("[ignored] caught an error during delete vm work job: %s", + logger.info(String.format("[ignored] caught an error during delete vm work job: %s", e.getLocalizedMessage())); } @@ -164,10 +162,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) { String sqlVolumeOnHost = "SELECT f.* FROM `cloud`.`volumes_on_host1` f LEFT JOIN `cloud`.`storage_pool_details` v ON f.name=v.value where v.value is NULL"; findMissingRecordsInCS(txn, sqlVolumeOnHost, "volumes_on_host"); } catch (SQLException e) { - log.info(String.format("[ignored] SQL failed due to: %s ", + logger.info(String.format("[ignored] SQL failed due to: %s ", e.getLocalizedMessage())); } catch (Throwable e) { - log.info(String.format("[ignored] caught an error: %s", + logger.info(String.format("[ignored] caught an error: %s", e.getLocalizedMessage())); } finally { try { @@ -177,7 +175,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { pstmt.executeUpdate(); } catch (SQLException e) { txn.close(); - log.info(String.format("createTemporaryVolumeTable %s", e.getMessage())); + logger.info(String.format("createTemporaryVolumeTable %s", e.getMessage())); } txn.close(); } @@ -201,7 +199,7 @@ protected void runInContext() { JsonArray arr = StorPoolUtil.snapshotsList(StorPoolUtil.getSpConnection(storagePoolVO.getUuid(), storagePoolVO.getId(), storagePoolDetailsDao, storagePoolDao)); snapshots.putAll(getStorPoolNamesAndCsTag(arr)); } catch (Exception e) { - log.debug(String.format("Could not collect abandon objects due to %s", e.getMessage())); + logger.debug(String.format("Could not collect abandon objects due to %s", e.getMessage())); } } Transaction.execute(new TransactionCallbackNoReturn() { @@ -222,10 +220,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) { "CREATE TEMPORARY TABLE `cloud`.`vm_templates1`(`id` bigint unsigned NOT NULL auto_increment, `name` varchar(255) NOT NULL,`tag` varchar(255) NOT NULL, PRIMARY KEY (`id`))"); pstmt.executeUpdate(); } catch (SQLException e) { - log.info(String.format("[ignored] SQL failed to delete vm work job: %s ", + logger.info(String.format("[ignored] SQL failed to delete vm work job: %s ", e.getLocalizedMessage())); } catch (Throwable e) { - log.info(String.format("[ignored] caught an error during delete vm work job: %s", + logger.info(String.format("[ignored] caught an error during delete vm work job: %s", e.getLocalizedMessage())); } @@ -262,10 +260,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) { + " and spool.local_path is NULL"; findMissingRecordsInCS(txn, sqlTemplates, "snapshot"); } catch (SQLException e) { - log.info(String.format("[ignored] SQL failed due to: %s ", + logger.info(String.format("[ignored] SQL failed due to: %s ", e.getLocalizedMessage())); } catch (Throwable e) { - log.info(String.format("[ignored] caught an error: %s", + logger.info(String.format("[ignored] caught an error: %s", e.getLocalizedMessage())); } finally { try { @@ -277,7 +275,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) { pstmt.executeUpdate(); } catch (SQLException e) { txn.close(); - log.info(String.format("createTemporaryVolumeTable %s", e.getMessage())); + logger.info(String.format("createTemporaryVolumeTable %s", e.getMessage())); } txn.close(); } @@ -304,7 +302,7 @@ private void findMissingRecordsInCS(TransactionLegacy txn, String sql, String ob String name = null; while (rs.next()) { name = rs.getString(2); - log.info(String.format( + logger.info(String.format( "CloudStack does not know about StorPool %s %s, it had to be a %s", object, name, rs.getString(3))); } } diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/api/StorPoolVolumeDef.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/api/StorPoolVolumeDef.java new file mode 100644 index 000000000000..456f5b90639c --- /dev/null +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/api/StorPoolVolumeDef.java @@ -0,0 +1,109 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.storage.datastore.api; + +import java.io.Serializable; +import java.util.Map; + +public class StorPoolVolumeDef implements Serializable { + + private static final long serialVersionUID = 1L; + private transient String name; + private Long size; + private Map tags; + private String parent; + private Long iops; + private String template; + private String baseOn; + private String rename; + private Boolean shrinkOk; + + public StorPoolVolumeDef() { + } + + public StorPoolVolumeDef(String name, Long size, Map tags, String parent, Long iops, String template, + String baseOn, String rename, Boolean shrinkOk) { + super(); + this.name = name; + this.size = size; + this.tags = tags; + this.parent = parent; + this.iops = iops; + this.template = template; + this.baseOn = baseOn; + this.rename = rename; + this.shrinkOk = shrinkOk; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public Long getSize() { + return size; + } + public void setSize(Long size) { + this.size = size; + } + public Map getTags() { + return tags; + } + public void setTags(Map tags) { + this.tags = tags; + } + public String getParent() { + return parent; + } + public void setParent(String parent) { + this.parent = parent; + } + public Long getIops() { + return iops; + } + public void setIops(Long iops) { + this.iops = iops; + } + public String getTemplate() { + return template; + } + public void setTemplate(String template) { + this.template = template; + } + public String getBaseOn() { + return baseOn; + } + public void setBaseOn(String baseOn) { + this.baseOn = baseOn; + } + public String getRename() { + return rename; + } + public void setRename(String rename) { + this.rename = rename; + } + + public Boolean getShrinkOk() { + return shrinkOk; + } + + public void setShrinkOk(Boolean shrinkOk) { + this.shrinkOk = shrinkOk; + } +} diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java index f5fdc96cb484..631186636ca2 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolPrimaryDataStoreDriver.java @@ -39,12 +39,15 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.cloudstack.resourcedetail.DiskOfferingDetailVO; +import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao; import org.apache.cloudstack.storage.RemoteHostEndPoint; import org.apache.cloudstack.storage.command.CommandResult; import org.apache.cloudstack.storage.command.CopyCmdAnswer; import org.apache.cloudstack.storage.command.CreateObjectAnswer; import org.apache.cloudstack.storage.command.StorageSubSystemCommand; import org.apache.cloudstack.storage.datastore.api.StorPoolSnapshotDef; +import org.apache.cloudstack.storage.datastore.api.StorPoolVolumeDef; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; @@ -65,7 +68,6 @@ import org.apache.cloudstack.storage.volume.VolumeObject; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.ResizeVolumeAnswer; @@ -82,12 +84,18 @@ import com.cloud.agent.api.to.DataTO; import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.dc.dao.ClusterDao; +import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.kvm.storage.StorPoolStorageAdaptor; +import com.cloud.offering.DiskOffering; import com.cloud.server.ResourceTag; import com.cloud.server.ResourceTag.ResourceObjectType; +import com.cloud.service.ServiceOfferingDetailsVO; +import com.cloud.service.ServiceOfferingVO; +import com.cloud.service.dao.ServiceOfferingDao; +import com.cloud.service.dao.ServiceOfferingDetailsDao; import com.cloud.storage.DataStoreRole; import com.cloud.storage.ResizeVolumePayload; import com.cloud.storage.Snapshot; @@ -114,10 +122,12 @@ import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class StorPoolPrimaryDataStoreDriver implements PrimaryDataStoreDriver { - private static final Logger log = Logger.getLogger(StorPoolPrimaryDataStoreDriver.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private VolumeDao volumeDao; @@ -155,6 +165,12 @@ public class StorPoolPrimaryDataStoreDriver implements PrimaryDataStoreDriver { private StoragePoolHostDao storagePoolHostDao; @Inject DataStoreManager dataStoreManager; + @Inject + private DiskOfferingDetailsDao diskOfferingDetailsDao; + @Inject + private ServiceOfferingDetailsDao serviceOfferingDetailDao; + @Inject + private ServiceOfferingDao serviceOfferingDao; private SnapshotDataStoreVO getSnapshotImageStoreRef(long snapshotId, long zoneId) { List snaps = snapshotDataStoreDao.listReadyBySnapshot(snapshotId, DataStoreRole.Image); @@ -258,15 +274,25 @@ public ChapInfo getChapInfo(DataObject dataObject) { public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback callback) { String path = null; Answer answer; + String tier = null; + String template = null; if (data.getType() == DataObjectType.VOLUME) { try { VolumeInfo vinfo = (VolumeInfo)data; String name = vinfo.getUuid(); Long size = vinfo.getPassphraseId() == null ? vinfo.getSize() : vinfo.getSize() + 2097152; + Long vmId = vinfo.getInstanceId(); + SpConnectionDesc conn = StorPoolUtil.getSpConnection(dataStore.getUuid(), dataStore.getId(), storagePoolDetailsDao, primaryStoreDao); - StorPoolUtil.spLog("StorpoolPrimaryDataStoreDriver.createAsync volume: name=%s, uuid=%s, isAttached=%s vm=%s, payload=%s, template: %s", vinfo.getName(), vinfo.getUuid(), vinfo.isAttachedVM(), vinfo.getAttachedVmName(), vinfo.getpayload(), conn.getTemplateName()); - SpApiResponse resp = StorPoolUtil.volumeCreate(name, null, size, getVMInstanceUUID(vinfo.getInstanceId()), null, "volume", vinfo.getMaxIops(), conn); + if (vinfo.getDiskOfferingId() != null) { + tier = getTierFromOfferingDetail(vinfo.getDiskOfferingId()); + if (tier == null) { + template = getTemplateFromOfferingDetail(vinfo.getDiskOfferingId()); + } + } + + SpApiResponse resp = createStorPoolVolume(template, tier, vinfo, name, size, vmId, conn); if (resp.getError() == null) { String volumeName = StorPoolUtil.getNameFromResponse(resp, false); path = StorPoolUtil.devPath(volumeName); @@ -297,6 +323,26 @@ public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCal } } + private SpApiResponse createStorPoolVolume(String template, String tier, VolumeInfo vinfo, String name, Long size, + Long vmId, SpConnectionDesc conn) { + SpApiResponse resp = new SpApiResponse(); + Map tags = StorPoolHelper.addStorPoolTags(name, getVMInstanceUUID(vmId), "volume", getVcPolicyTag(vmId), tier); + if (tier != null || template != null) { + StorPoolUtil.spLog( + "Creating volume [%s] with template [%s] or tier tags [%s] described in disk/service offerings details", + vinfo.getUuid(), template, tier); + resp = StorPoolUtil.volumeCreate(size, null, template, tags, conn); + } else { + StorPoolUtil.spLog( + "StorpoolPrimaryDataStoreDriver.createAsync volume: name=%s, uuid=%s, isAttached=%s vm=%s, payload=%s, template: %s", + vinfo.getName(), vinfo.getUuid(), vinfo.isAttachedVM(), vinfo.getAttachedVmName(), + vinfo.getpayload(), conn.getTemplateName()); + resp = StorPoolUtil.volumeCreate(name, null, size, getVMInstanceUUID(vinfo.getInstanceId()), null, + "volume", vinfo.getMaxIops(), conn); + } + return resp; + } + private void updateVolume(DataStore dataStore, String path, VolumeInfo vinfo) { VolumeVO volume = volumeDao.findById(vinfo.getId()); volume.setPoolId(dataStore.getId()); @@ -335,66 +381,109 @@ private StorPoolSetVolumeEncryptionAnswer createEncryptedVolume(DataStore dataSt public void resize(DataObject data, AsyncCompletionCallback callback) { String path = null; String err = null; - ResizeVolumeAnswer answer = null; if (data.getType() == DataObjectType.VOLUME) { VolumeObject vol = (VolumeObject)data; - StoragePool pool = (StoragePool)data.getDataStore(); - ResizeVolumePayload payload = (ResizeVolumePayload)vol.getpayload(); + path = vol.getPath(); - final String name = StorPoolStorageAdaptor.getVolumeNameFromPath(vol.getPath(), true); - final long oldSize = vol.getSize(); - Long oldMaxIops = vol.getMaxIops(); + err = resizeVolume(data, path, vol); + } else { + err = String.format("Invalid object type \"%s\" passed to resize", data.getType()); + } - try { - SpConnectionDesc conn = StorPoolUtil.getSpConnection(data.getDataStore().getUuid(), data.getDataStore().getId(), storagePoolDetailsDao, primaryStoreDao); + CreateCmdResult res = new CreateCmdResult(path, new Answer(null, err != null, err)); + res.setResult(err); + callback.complete(res); + } - long maxIops = payload.newMaxIops == null ? Long.valueOf(0) : payload.newMaxIops; + private String resizeVolume(DataObject data, String path, VolumeObject vol) { + String err = null; + ResizeVolumePayload payload = (ResizeVolumePayload)vol.getpayload(); + boolean needResize = vol.getSize() != payload.newSize; - StorPoolUtil.spLog("StorpoolPrimaryDataStoreDriverImpl.resize: name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s", name, vol.getUuid(), oldSize, payload.newSize, payload.shrinkOk, maxIops); + final String name = StorPoolStorageAdaptor.getVolumeNameFromPath(path, true); + final long oldSize = vol.getSize(); + Long oldMaxIops = vol.getMaxIops(); - SpApiResponse resp = StorPoolUtil.volumeUpdate(name, payload.newSize, payload.shrinkOk, maxIops, conn); - if (resp.getError() != null) { - err = String.format("Could not resize StorPool volume %s. Error: %s", name, resp.getError()); - } else { - StorPoolResizeVolumeCommand resizeCmd = new StorPoolResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), payload.newSize, payload.shrinkOk, - payload.instanceName, payload.hosts == null ? false : true); - answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, payload.hosts, resizeCmd); + try { + SpConnectionDesc conn = StorPoolUtil.getSpConnection(data.getDataStore().getUuid(), data.getDataStore().getId(), storagePoolDetailsDao, primaryStoreDao); - if (answer == null || !answer.getResult()) { - err = answer != null ? answer.getDetails() : "return a null answer, resize failed for unknown reason"; - } else { - path = StorPoolUtil.devPath(StorPoolUtil.getNameFromResponse(resp, false)); - - vol.setSize(payload.newSize); - vol.update(); - if (payload.newMaxIops != null) { - VolumeVO volume = volumeDao.findById(vol.getId()); - volume.setMaxIops(payload.newMaxIops); - volumeDao.update(volume.getId(), volume); - } + err = updateStorPoolVolume(vol, payload, conn); + if (err == null && needResize) { + err = notifyQemuForTheNewSize(data, err, vol, payload); + } - updateStoragePool(vol.getPoolId(), payload.newSize - oldSize); - } - } - if (err != null) { - // try restoring volume to its initial size - resp = StorPoolUtil.volumeUpdate(name, oldSize, true, oldMaxIops, conn); - if (resp.getError() != null) { - log.debug(String.format("Could not resize StorPool volume %s back to its original size. Error: %s", name, resp.getError())); - } + if (err != null) { + // try restoring volume to its initial size + SpApiResponse response = StorPoolUtil.volumeUpdate(name, oldSize, true, oldMaxIops, conn); + if (response.getError() != null) { + logger.debug(String.format("Could not resize StorPool volume %s back to its original size. Error: %s", name, response.getError())); } - } catch (Exception e) { - log.debug("sending resize command failed", e); - err = e.toString(); } + } catch (Exception e) { + logger.debug("sending resize command failed", e); + err = e.toString(); + } + return err; + } + + private String notifyQemuForTheNewSize(DataObject data, String err, VolumeObject vol, ResizeVolumePayload payload) + throws StorageUnavailableException { + StoragePool pool = (StoragePool)data.getDataStore(); + + StorPoolResizeVolumeCommand resizeCmd = new StorPoolResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), payload.newSize, payload.shrinkOk, + payload.instanceName, payload.hosts == null ? false : true); + ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, payload.hosts, resizeCmd); + + if (answer == null || !answer.getResult()) { + err = answer != null ? answer.getDetails() : "return a null answer, resize failed for unknown reason"; + } + return err; + } + + private String updateStorPoolVolume(VolumeObject vol, ResizeVolumePayload payload, SpConnectionDesc conn) { + String err = null; + String name = StorPoolStorageAdaptor.getVolumeNameFromPath(vol.getPath(), true); + Long newDiskOfferingId = payload.getNewDiskOfferingId(); + String tier = null; + String template = null; + if (newDiskOfferingId != null) { + tier = getTierFromOfferingDetail(newDiskOfferingId); + if (tier == null) { + template = getTemplateFromOfferingDetail(newDiskOfferingId); + } + } + SpApiResponse resp = new SpApiResponse(); + if (tier != null || template != null) { + Map tags = StorPoolHelper.addStorPoolTags(null, null, null, null, tier); + StorPoolVolumeDef spVolume = new StorPoolVolumeDef(name, payload.newSize, tags, null, null, template, null, null, + payload.shrinkOk); + resp = StorPoolUtil.volumeUpdate(spVolume, conn); } else { - err = String.format("Invalid object type \"%s\" passed to resize", data.getType()); + long maxIops = payload.newMaxIops == null ? Long.valueOf(0) : payload.newMaxIops; + + StorPoolVolumeDef spVolume = new StorPoolVolumeDef(name, payload.newSize, null, null, maxIops, null, null, null, + payload.shrinkOk); + StorPoolUtil.spLog( + "StorpoolPrimaryDataStoreDriverImpl.resize: name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s", + name, vol.getUuid(), vol.getSize(), payload.newSize, payload.shrinkOk, maxIops); + + resp = StorPoolUtil.volumeUpdate(spVolume, conn); } + if (resp.getError() != null) { + err = String.format("Could not resize StorPool volume %s. Error: %s", name, resp.getError()); + } else { + vol.setSize(payload.newSize); + vol.update(); + if (payload.newMaxIops != null) { + VolumeVO volume = volumeDao.findById(vol.getId()); + volume.setMaxIops(payload.newMaxIops); + volumeDao.update(volume.getId(), volume); + } - CreateCmdResult res = new CreateCmdResult(path, answer); - res.setResult(err); - callback.complete(res); + updateStoragePool(vol.getPoolId(), payload.newSize - vol.getSize()); + } + return err; } @Override @@ -430,7 +519,7 @@ public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCal } if (err != null) { - log.error(err); + logger.error(err); StorPoolUtil.spLog(err); } @@ -632,7 +721,7 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal SpApiResponse resp = StorPoolUtil.snapshotDelete(snapName, conn); if (resp.getError() != null) { final String err2 = String.format("Failed to cleanup StorPool snapshot '%s'. Error: %s.", snapName, resp.getError()); - log.error(err2); + logger.error(err2); StorPoolUtil.spLog(err2); } } @@ -663,7 +752,7 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal if (answer != null && answer.getResult()) { SpApiResponse resSnapshot = StorPoolUtil.volumeSnapshot(volumeName, template.getUuid(), null, "template", "no", conn); if (resSnapshot.getError() != null) { - log.debug(String.format("Could not snapshot volume with ID=%s", volume.getId())); + logger.debug(String.format("Could not snapshot volume with ID=%s", volume.getId())); StorPoolUtil.spLog("Volume snapshot failed with error=%s", resSnapshot.getError().getDescr()); err = resSnapshot.getError().getDescr(); } @@ -745,7 +834,7 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal if (err != null) { resp = StorPoolUtil.volumeDelete(StorPoolUtil.getNameFromResponse(resp, true), conn); if (resp.getError() != null) { - log.warn(String.format("Could not clean-up Storpool volume %s. Error: %s", name, resp.getError())); + logger.warn(String.format("Could not clean-up Storpool volume %s. Error: %s", name, resp.getError())); } } } else if (srcType == DataObjectType.TEMPLATE && dstType == DataObjectType.VOLUME) { @@ -771,8 +860,30 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal } StorPoolUtil.spLog(String.format("volume size is: %d", size)); Long vmId = vinfo.getInstanceId(); - SpApiResponse resp = StorPoolUtil.volumeCreate(name, parentName, size, getVMInstanceUUID(vmId), getVcPolicyTag(vmId), - "volume", vinfo.getMaxIops(), conn); + + String template = null; + String tier = null; + SpApiResponse resp = new SpApiResponse(); + + if (vinfo.getDiskOfferingId() != null) { + tier = getTierFromOfferingDetail(vinfo.getDiskOfferingId()); + if (tier == null) { + template = getTemplateFromOfferingDetail(vinfo.getDiskOfferingId()); + } + } + + if (tier != null || template != null) { + Map tags = StorPoolHelper.addStorPoolTags(name, getVMInstanceUUID(vmId), "volume", getVcPolicyTag(vmId), tier); + + StorPoolUtil.spLog( + "Creating volume [%s] with template [%s] or tier tags [%s] described in disk/service offerings details", + vinfo.getUuid(), template, tier); + resp = StorPoolUtil.volumeCreate(size, parentName, template, tags, conn); + } else { + resp = StorPoolUtil.volumeCreate(name, parentName, size, getVMInstanceUUID(vmId), + getVcPolicyTag(vmId), "volume", vinfo.getMaxIops(), conn); + } + if (resp.getError() == null) { updateStoragePool(dstData.getDataStore().getId(), vinfo.getSize()); updateVolumePoolType(vinfo); @@ -838,7 +949,7 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal if (err != null) { SpApiResponse resp3 = StorPoolUtil.volumeDelete(name, conn); if (resp3.getError() != null) { - log.warn(String.format("Could not clean-up Storpool volume %s. Error: %s", name, resp3.getError())); + logger.warn(String.format("Could not clean-up Storpool volume %s. Error: %s", name, resp3.getError())); } } } @@ -887,7 +998,7 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal final SpApiResponse resp2 = StorPoolUtil.snapshotDelete(snapshotName, conn); if (resp2.getError() != null) { final String err2 = String.format("Failed to delete temporary StorPool snapshot %s. Error: %s", StorPoolUtil.getNameFromResponse(resp, true), resp2.getError()); - log.error(err2); + logger.error(err2); StorPoolUtil.spLog(err2); } } @@ -907,7 +1018,7 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal if (err != null) { StorPoolUtil.spLog("Failed due to %s", err); - log.error(err); + logger.error(err); answer = new Answer(cmd, false, err); } @@ -1124,7 +1235,7 @@ private String getVcPolicyTag(Long vmId) { } public void handleQualityOfServiceForVolumeMigration(VolumeInfo arg0, QualityOfServiceState arg1) { - log.debug(String.format("handleQualityOfServiceForVolumeMigration with volume name=%s is not supported", arg0.getName())); + logger.debug(String.format("handleQualityOfServiceForVolumeMigration with volume name=%s is not supported", arg0.getName())); } @@ -1208,10 +1319,10 @@ public void provideVmInfo(long vmId, long volumeId) { VMInstanceVO userVM = vmInstanceDao.findById(vmId); SpApiResponse resp = StorPoolUtil.volumeUpdateIopsAndTags(volName, volume.getInstanceId() != null ? userVM.getUuid() : "", null, conn, getVcPolicyTag(vmId)); if (resp.getError() != null) { - log.warn(String.format("Could not update VC policy tags of a volume with id [%s]", volume.getUuid())); + logger.warn(String.format("Could not update VC policy tags of a volume with id [%s]", volume.getUuid())); } } catch (Exception e) { - log.warn(String.format("Could not update Virtual machine tags due to %s", e.getMessage())); + logger.warn(String.format("Could not update Virtual machine tags due to %s", e.getMessage())); } } } @@ -1231,10 +1342,10 @@ public void provideVmTags(long vmId, long volumeId, String tagValue) { String volName = StorPoolStorageAdaptor.getVolumeNameFromPath(volume.getPath(), true); SpApiResponse resp = StorPoolUtil.volumeUpdateVCTags(volName, conn, getVcPolicyTag(vmId)); if (resp.getError() != null) { - log.warn(String.format("Could not update VC policy tags of a volume with id [%s]", volume.getUuid())); + logger.warn(String.format("Could not update VC policy tags of a volume with id [%s]", volume.getUuid())); } } catch (Exception e) { - log.warn(String.format("Could not update Virtual machine tags due to %s", e.getMessage())); + logger.warn(String.format("Could not update Virtual machine tags due to %s", e.getMessage())); } } } @@ -1254,4 +1365,67 @@ public void detachVolumeFromAllStorageNodes(Volume volume) { StorPoolUtil.spLog("The volume [%s] is detach from all clusters [%s]", volName, resp); } } + + @Override + public boolean informStorageForDiskOfferingChange() { + return true; + } + + @Override + public void updateStorageWithTheNewDiskOffering(Volume volume, DiskOffering newDiskOffering) { + if (newDiskOffering == null) { + return; + } + + StoragePoolVO pool = primaryStoreDao.findById(volume.getPoolId()); + if (pool == null) { + return; + } + + String tier = getTierFromOfferingDetail(newDiskOffering.getId()); + String template = null; + if (tier == null) { + template = getTemplateFromOfferingDetail(newDiskOffering.getId()); + } + if (tier == null && template == null) { + return; + } + SpConnectionDesc conn = StorPoolUtil.getSpConnection(pool.getUuid(), pool.getId(), storagePoolDetailsDao, primaryStoreDao); + StorPoolUtil.spLog("Updating volume [%s] with tier tag [%s] or template [%s] from Disk offering", volume.getId(), tier, template); + String volumeName = StorPoolStorageAdaptor.getVolumeNameFromPath(volume.getPath(), true); + Map tags = StorPoolHelper.addStorPoolTags(null, null, null, null, tier); + StorPoolVolumeDef spVolume = new StorPoolVolumeDef(volumeName, null, tags, null, null, template, null, null, null); + SpApiResponse response = StorPoolUtil.volumeUpdate(spVolume, conn); + if (response.getError() != null) { + StorPoolUtil.spLog("Could not update volume [%s] with tier tag [%s] or template [%s] from Disk offering due to [%s]", volume.getId(), tier, template, response.getError()); + } + } + + private String getTemplateFromOfferingDetail(Long diskOfferingId) { + String template = null; + DiskOfferingDetailVO diskOfferingDetail = diskOfferingDetailsDao.findDetail(diskOfferingId, StorPoolUtil.SP_TEMPLATE); + if (diskOfferingDetail == null ) { + ServiceOfferingVO serviceOffering = serviceOfferingDao.findServiceOfferingByComputeOnlyDiskOffering(diskOfferingId, true); + if (serviceOffering != null) { + ServiceOfferingDetailsVO serviceOfferingDetail = serviceOfferingDetailDao.findDetail(serviceOffering.getId(), StorPoolUtil.SP_TEMPLATE); + if (serviceOfferingDetail != null) { + template = serviceOfferingDetail.getValue(); + } + } + } else { + template = diskOfferingDetail.getValue(); + } + return template; + } + + private String getTierFromOfferingDetail(Long diskOfferingId) { + String tier = null; + DiskOfferingDetailVO diskOfferingDetail = diskOfferingDetailsDao.findDetail(diskOfferingId, StorPoolUtil.SP_TIER); + if (diskOfferingDetail == null ) { + return tier; + } else { + tier = diskOfferingDetail.getValue(); + } + return tier; + } } diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolStatsCollector.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolStatsCollector.java index 44acd1eab75e..56b150a04e63 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolStatsCollector.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/driver/StorPoolStatsCollector.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.storage.datastore.util.StorPoolUtil; import org.apache.cloudstack.storage.snapshot.StorPoolConfigurationManager; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.apache.commons.lang3.StringUtils; import com.cloud.storage.DataStoreRole; @@ -57,8 +56,6 @@ public class StorPoolStatsCollector extends ManagerBase { - private static Logger log = Logger.getLogger(StorPoolStatsCollector.class); - @Inject private PrimaryDataStoreDao storagePoolDao; @Inject @@ -116,19 +113,19 @@ public void run() { if (CollectionUtils.isNotEmpty(spPools)) { volumesStats.clear(); - log.debug("Collecting StorPool volumes used space"); + logger.debug("Collecting StorPool volumes used space"); Map onePoolforZone = new HashMap<>(); for (StoragePoolVO storagePoolVO : spPools) { onePoolforZone.put(storagePoolVO.getDataCenterId(), storagePoolVO); } for (StoragePoolVO storagePool : onePoolforZone.values()) { try { - log.debug(String.format("Collecting volumes statistics for zone [%s]", storagePool.getDataCenterId())); + logger.debug(String.format("Collecting volumes statistics for zone [%s]", storagePool.getDataCenterId())); JsonArray arr = StorPoolUtil.volumesSpace(StorPoolUtil.getSpConnection(storagePool.getUuid(), storagePool.getId(), storagePoolDetailsDao, storagePoolDao)); volumesStats.putAll(getClusterVolumeOrTemplateSpace(arr, StorPoolObject.VOLUME)); } catch (Exception e) { - log.debug(String.format("Could not collect StorPool volumes statistics due to %s", e.getMessage())); + logger.debug(String.format("Could not collect StorPool volumes statistics due to %s", e.getMessage())); } } } @@ -149,12 +146,12 @@ public void run() { } for (StoragePoolVO storagePool : onePoolforZone.values()) { try { - log.debug(String.format("Collecting templates statistics for zone [%s]", storagePool.getDataCenterId())); + logger.debug(String.format("Collecting templates statistics for zone [%s]", storagePool.getDataCenterId())); JsonArray arr = StorPoolUtil.templatesStats(StorPoolUtil.getSpConnection(storagePool.getUuid(), storagePool.getId(), storagePoolDetailsDao, storagePoolDao)); templatesStats.put(storagePool.getDataCenterId(), getClusterVolumeOrTemplateSpace(arr, StorPoolObject.TEMPLATE)); } catch (Exception e) { - log.debug(String.format("Could not collect StorPool templates statistics %s", e.getMessage())); + logger.debug(String.format("Could not collect StorPool templates statistics %s", e.getMessage())); } } } @@ -227,14 +224,14 @@ public void run() { Map snapshotsWithDelayDelete = new HashMap<>(); try { - log.debug(String.format("Collecting snapshots marked to be deleted for zone [%s]", storagePool.getDataCenterId())); + logger.debug(String.format("Collecting snapshots marked to be deleted for zone [%s]", storagePool.getDataCenterId())); JsonArray arr = StorPoolUtil.snapshotsListAllClusters(StorPoolUtil.getSpConnection(storagePool.getUuid(), storagePool.getId(), storagePoolDetailsDao, storagePoolDao)); snapshotsWithDelayDelete.putAll(getSnapshotsMarkedForDeletion(arr)); - log.debug(String.format("Found snapshot details [%s] and snapshots on StorPool with delay delete flag [%s]", snapshotsDetails, snapshotsWithDelayDelete)); + logger.debug(String.format("Found snapshot details [%s] and snapshots on StorPool with delay delete flag [%s]", snapshotsDetails, snapshotsWithDelayDelete)); syncSnapshots(snapshotsDetails, snapshotsWithDelayDelete); } catch (Exception e) { - log.debug("Could not fetch the snapshots with delay delete flag " + e.getMessage()); + logger.debug("Could not fetch the snapshots with delay delete flag " + e.getMessage()); } } } @@ -276,7 +273,7 @@ private Map getSnapshotsMarkedForDeletion(JsonArray arr) { } collectSnapshots(snapshotsWithDelayDelete, response); } - log.debug("Found snapshots on StorPool" + snapshotsWithDelayDelete); + logger.debug("Found snapshots on StorPool" + snapshotsWithDelayDelete); return snapshotsWithDelayDelete; } diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/StorPoolPrimaryDataStoreLifeCycle.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/StorPoolPrimaryDataStoreLifeCycle.java index 47f6089d7342..4f2fdef17236 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/StorPoolPrimaryDataStoreLifeCycle.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/StorPoolPrimaryDataStoreLifeCycle.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.storage.datastore.util.StorPoolUtil.SpApiResponse; import org.apache.cloudstack.storage.datastore.util.StorPoolUtil.SpConnectionDesc; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; -import org.apache.log4j.Logger; import com.cloud.agent.api.StoragePoolInfo; import com.cloud.host.HostVO; @@ -61,8 +60,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class StorPoolPrimaryDataStoreLifeCycle extends BasePrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { - private static final Logger log = Logger.getLogger(StorPoolPrimaryDataStoreLifeCycle.class); - @Inject protected PrimaryDataStoreHelper dataStoreHelper; @Inject @@ -92,7 +89,7 @@ public DataStore initialize(Map dsInfos) { } StorPoolUtil.spLog(""); - log.debug("initialize"); + logger.debug("initialize"); String name = (String)dsInfos.get("name"); String providerName = (String)dsInfos.get("providerName"); @@ -186,18 +183,18 @@ public void updateStoragePool(StoragePool storagePool, Map detai } StorPoolUtil.spLog(""); - log.debug("updateStoragePool"); + logger.debug("updateStoragePool"); return; } @Override public boolean attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) { - log.debug("attachHost"); + logger.debug("attachHost"); return true; } @Override public boolean attachCluster(DataStore store, ClusterScope scope) { - log.debug("attachCluster"); + logger.debug("attachCluster"); if (!scope.getScopeType().equals(ScopeType.ZONE)) { throw new UnsupportedOperationException("Only Zone-Wide scope is supported!"); } @@ -206,7 +203,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) { @Override public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { - log.debug("attachZone"); + logger.debug("attachZone"); if (hypervisorType != HypervisorType.KVM) { throw new UnsupportedOperationException("Only KVM hypervisors supported!"); @@ -216,7 +213,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h try { storageMgr.connectHostToSharedPool(host.getId(), dataStore.getId()); } catch (Exception e) { - log.warn(String.format("Unable to establish a connection between host %s and pool %s due to %s", host, dataStore, e)); + logger.warn(String.format("Unable to establish a connection between host %s and pool %s due to %s", host, dataStore, e)); } } dataStoreHelper.attachZone(dataStore, hypervisorType); @@ -225,7 +222,7 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType h @Override public boolean maintain(DataStore dataStore) { - log.debug("maintain"); + logger.debug("maintain"); storagePoolAutmation.maintain(dataStore); dataStoreHelper.maintain(dataStore); @@ -234,7 +231,7 @@ public boolean maintain(DataStore dataStore) { @Override public boolean cancelMaintain(DataStore store) { - log.debug("cancelMaintain"); + logger.debug("cancelMaintain"); dataStoreHelper.cancelMaintain(store); storagePoolAutmation.cancelMaintain(store); @@ -243,7 +240,7 @@ public boolean cancelMaintain(DataStore store) { @Override public boolean deleteDataStore(DataStore store) { - log.debug("deleteDataStore"); + logger.debug("deleteDataStore"); long storagePoolId = store.getId(); List lstSnapshots = snapshotDao.listAll(); @@ -303,19 +300,19 @@ public boolean deleteDataStore(DataStore store) { @Override public boolean migrateToObjectStore(DataStore store) { - log.debug("migrateToObjectStore"); + logger.debug("migrateToObjectStore"); return false; } @Override public void enableStoragePool(DataStore dataStore) { - log.debug("enableStoragePool"); + logger.debug("enableStoragePool"); dataStoreHelper.enable(dataStore); } @Override public void disableStoragePool(DataStore dataStore) { - log.debug("disableStoragePool"); + logger.debug("disableStoragePool"); dataStoreHelper.disable(dataStore); } } diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/provider/StorPoolHostListener.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/provider/StorPoolHostListener.java index bf7642b9122e..b696990c5336 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/provider/StorPoolHostListener.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/provider/StorPoolHostListener.java @@ -40,7 +40,8 @@ import org.apache.cloudstack.storage.snapshot.StorPoolConfigurationManager; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -62,7 +63,7 @@ import com.cloud.utils.exception.CloudRuntimeException; public class StorPoolHostListener implements HypervisorHostListener { - private static final Logger log = Logger.getLogger(StorPoolHostListener .class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private AgentManager agentMgr; @@ -151,7 +152,7 @@ public boolean hostConnect(long hostId, long poolId) throws StorageConflictExcep List localStoragePools = primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName); for (StoragePoolVO localStoragePool : localStoragePools) { if (datastoreName.equals(localStoragePool.getPath())) { - log.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName()); + logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName()); throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName()); } @@ -259,7 +260,7 @@ private void addModifyCommandToCommandsAllowedInMaintenanceMode() { } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { String err = "Could not add StorPoolModifyStoragePoolCommand to s_commandsAllowedInMaintenanceMode array due to: %s"; StorPoolUtil.spLog(err, e.getMessage()); - log.warn(String.format(err, e.getMessage())); + logger.warn(String.format(err, e.getMessage())); } } diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolHelper.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolHelper.java index 9395f134fe10..3113ae8fdaaf 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolHelper.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolHelper.java @@ -19,10 +19,7 @@ package org.apache.cloudstack.storage.datastore.util; -import java.io.IOException; import java.sql.PreparedStatement; -import java.sql.Timestamp; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -41,10 +38,6 @@ import org.apache.cloudstack.storage.snapshot.StorPoolConfigurationManager; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections4.CollectionUtils; -import org.apache.log4j.Appender; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.RollingFileAppender; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsVO; @@ -170,11 +163,12 @@ public static String getVMInstanceUUID(Long id, VMInstanceDao vmInstanceDao) { return null; } - public static Map addStorPoolTags(String name, String vmUuid, String csTag, String vcPolicy) { + public static Map addStorPoolTags(String name, String vmUuid, String csTag, String vcPolicy, String qcTier) { Map tags = new HashMap<>(); tags.put("uuid", name); tags.put("cvm", vmUuid); tags.put(StorPoolUtil.SP_VC_POLICY, vcPolicy); + tags.put("qc", qcTier); if (csTag != null) { tags.put("cs", csTag); } @@ -182,30 +176,30 @@ public static Map addStorPoolTags(String name, String vmUuid, St } // Initialize custom logger for updated volume and snapshots - public static void appendLogger(Logger log, String filePath, String kindOfLog) { - Appender appender = null; - PatternLayout patternLayout = new PatternLayout(); - patternLayout.setConversionPattern("%d{YYYY-MM-dd HH:mm:ss.SSS} %m%n"); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); - Timestamp timestamp = new Timestamp(System.currentTimeMillis()); - String path = filePath + "-" + sdf.format(timestamp) + ".log"; - try { - appender = new RollingFileAppender(patternLayout, path); - log.setAdditivity(false); - log.addAppender(appender); - } catch (IOException e) { - e.printStackTrace(); - } - if (kindOfLog.equals("update")) { - StorPoolUtil.spLog( - "You can find information about volumes and snapshots, which will be updated in Database with their globalIs in %s log file", - path); - } else if (kindOfLog.equals("abandon")) { - StorPoolUtil.spLog( - "You can find information about volumes and snapshots, for which CloudStack doesn't have information in %s log file", - path); - } - } +// public static void appendLogger(Logger log, String filePath, String kindOfLog) { +// Appender appender = null; +// PatternLayout patternLayout = new PatternLayout(); +// patternLayout.setConversionPattern("%d{YYYY-MM-dd HH:mm:ss.SSS} %m%n"); +// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); +// Timestamp timestamp = new Timestamp(System.currentTimeMillis()); +// String path = filePath + "-" + sdf.format(timestamp) + ".log"; +// try { +// appender = new RollingFileAppender(patternLayout, path); +// log.setAdditivity(false); +// log.addAppender(appender); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// if (kindOfLog.equals("update")) { +// StorPoolUtil.spLog( +// "You can find information about volumes and snapshots, which will be updated in Database with their globalIs in %s log file", +// path); +// } else if (kindOfLog.equals("abandon")) { +// StorPoolUtil.spLog( +// "You can find information about volumes and snapshots, for which CloudStack doesn't have information in %s log file", +// path); +// } +// } public static void setSpClusterIdIfNeeded(long hostId, String clusterId, ClusterDao clusterDao, HostDao hostDao, ClusterDetailsDao clusterDetails) { diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java index 58e87b2fba6a..97f4e2fe155a 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java @@ -30,6 +30,7 @@ import com.google.gson.JsonPrimitive; import org.apache.cloudstack.storage.datastore.api.StorPoolSnapshotDef; +import org.apache.cloudstack.storage.datastore.api.StorPoolVolumeDef; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; @@ -46,7 +47,8 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.io.BufferedReader; import java.io.File; @@ -69,7 +71,7 @@ import java.util.UUID; public class StorPoolUtil { - private static final Logger log = Logger.getLogger(StorPoolUtil.class); + protected static Logger LOGGER = LogManager.getLogger(StorPoolUtil.class); private static final File spLogFile = new File( Files.exists(Paths.get("/var/log/cloudstack/management/")) ? @@ -79,23 +81,23 @@ public class StorPoolUtil { private static PrintWriter spLogFileInitialize() { try { - log.info("INITIALIZE SP-LOG_FILE"); + LOGGER.info("INITIALIZE SP-LOGGER_FILE"); if (spLogFile.exists()) { final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); final Timestamp timestamp = new Timestamp(System.currentTimeMillis()); final File spLogFileRename = new File(spLogFile + "-" + sdf.format(timestamp)); final boolean ret = spLogFile.renameTo(spLogFileRename); if (!ret) { - log.warn("Unable to rename" + spLogFile + " to " + spLogFileRename); + LOGGER.warn("Unable to rename" + spLogFile + " to " + spLogFileRename); } else { - log.debug("Renamed " + spLogFile + " to " + spLogFileRename); + LOGGER.debug("Renamed " + spLogFile + " to " + spLogFileRename); } } else { spLogFile.getParentFile().mkdirs(); } return new PrintWriter(spLogFile); } catch (Exception e) { - log.info("INITIALIZE SP-LOG_FILE: " + e.getMessage()); + LOGGER.info("INITIALIZE SP-LOGGER_FILE: " + e.getMessage()); throw new RuntimeException(e); } } @@ -134,6 +136,7 @@ public static void spLog(String fmt, Object... args) { public static final String DELAY_DELETE = "delayDelete"; + public static final String SP_TIER = "SP_QOSCLASS"; public static enum StorpoolRights { RO("ro"), RW("rw"), DETACH("detach"); @@ -187,19 +190,19 @@ public SpConnectionDesc(String url) { extractUriParams(url); return; } catch (URISyntaxException e) { - log.debug("[ignore] the uri is not valid"); + LOGGER.debug("[ignore] the uri is not valid"); } String[] urlSplit = url.split(";"); if (urlSplit.length == 1 && !urlSplit[0].contains("=")) { this.templateName = url; - Script sc = new Script("storpool_confget", 0, log); + Script sc = new Script("storpool_confget", 0, LOGGER); OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); final String err = sc.execute(parser); if (err != null) { final String errMsg = String.format("Could not execute storpool_confget. Error: %s", err); - log.warn(errMsg); + LOGGER.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -407,7 +410,7 @@ private static SpApiResponse POST(String query, Object json, SpConnectionDesc co Gson gson = new Gson(); String js = gson.toJson(json); StringEntity input = new StringEntity(js, ContentType.APPLICATION_JSON); - log.info("Request:" + js); + LOGGER.info("Request:" + js); req.setEntity(input); } @@ -498,7 +501,19 @@ public static SpApiResponse volumeCreate(final String name, final String parentN json.put("parent", parentName); json.put("size", size); json.put("template", conn.getTemplateName()); - Map tags = StorPoolHelper.addStorPoolTags(name, vmUuid, csTag, vcPolicy); + Map tags = StorPoolHelper.addStorPoolTags(name, vmUuid, csTag, vcPolicy, null); + json.put("tags", tags); + return POST("MultiCluster/VolumeCreate", json, conn); + } + + public static SpApiResponse volumeCreate(Long size, String parentName, String template, Map tags, SpConnectionDesc conn) { + template = template != null ? template : conn.getTemplateName(); + + Map json = new LinkedHashMap<>(); + json.put("name", ""); + json.put("parent", parentName); + json.put("size", size); + json.put("template", template); json.put("tags", tags); return POST("MultiCluster/VolumeCreate", json, conn); } @@ -522,7 +537,7 @@ public static SpApiResponse volumeCopy(final String name, final String baseOn, S json.put("iops", iops); } json.put("template", conn.getTemplateName()); - Map tags = StorPoolHelper.addStorPoolTags(name, cvmTag, csTag, vcPolicyTag); + Map tags = StorPoolHelper.addStorPoolTags(name, cvmTag, csTag, vcPolicyTag, null); json.put("tags", tags); return POST("MultiCluster/VolumeCreate", json, conn); } @@ -550,7 +565,7 @@ public static SpApiResponse volumeUpdate(final String name, final Long newSize, public static SpApiResponse volumeRemoveTags(String name, SpConnectionDesc conn) { Map json = new HashMap<>(); - Map tags = StorPoolHelper.addStorPoolTags(null, "", null, ""); + Map tags = StorPoolHelper.addStorPoolTags(null, "", null, "", null); json.put("tags", tags); return POST("MultiCluster/VolumeUpdate/" + name, json, conn); } @@ -558,7 +573,7 @@ public static SpApiResponse volumeRemoveTags(String name, SpConnectionDesc conn) public static SpApiResponse volumeUpdateIopsAndTags(final String name, final String uuid, Long iops, SpConnectionDesc conn, String vcPolicy) { Map json = new HashMap<>(); - Map tags = StorPoolHelper.addStorPoolTags(null, uuid, null, vcPolicy); + Map tags = StorPoolHelper.addStorPoolTags(null, uuid, null, vcPolicy, null); json.put("iops", iops); json.put("tags", tags); return POST("MultiCluster/VolumeUpdate/" + name, json, conn); @@ -566,14 +581,14 @@ public static SpApiResponse volumeUpdateIopsAndTags(final String name, final Str public static SpApiResponse volumeUpdateCvmTags(final String name, final String uuid, SpConnectionDesc conn) { Map json = new HashMap<>(); - Map tags = StorPoolHelper.addStorPoolTags(null, uuid, null, null); + Map tags = StorPoolHelper.addStorPoolTags(null, uuid, null, null, null); json.put("tags", tags); return POST("MultiCluster/VolumeUpdate/" + name, json, conn); } public static SpApiResponse volumeUpdateVCTags(final String name, SpConnectionDesc conn, String vcPolicy) { Map json = new HashMap<>(); - Map tags = StorPoolHelper.addStorPoolTags(null, null, null, vcPolicy); + Map tags = StorPoolHelper.addStorPoolTags(null, null, null, vcPolicy, null); json.put("tags", tags); return POST("MultiCluster/VolumeUpdate/" + name, json, conn); } @@ -584,10 +599,14 @@ public static SpApiResponse volumeUpdateTemplate(final String name, SpConnection return POST("MultiCluster/VolumeUpdate/" + name, json, conn); } + public static SpApiResponse volumeUpdate(StorPoolVolumeDef volume, SpConnectionDesc conn) { + return POST("MultiCluster/VolumeUpdate/" + volume.getName(), volume, conn); + } + public static SpApiResponse volumeSnapshot(final String volumeName, final String snapshotName, String vmUuid, String csTag, String vcPolicy, SpConnectionDesc conn) { Map json = new HashMap<>(); - Map tags = StorPoolHelper.addStorPoolTags(snapshotName, vmUuid, csTag, vcPolicy); + Map tags = StorPoolHelper.addStorPoolTags(snapshotName, vmUuid, csTag, vcPolicy, null); json.put("name", ""); json.put("tags", tags); @@ -601,7 +620,7 @@ public static SpApiResponse volumeSnapshot(StorPoolSnapshotDef snapshot, SpConne public static SpApiResponse volumesGroupSnapshot(final List volumeTOs, final String vmUuid, final String snapshotName, String csTag, SpConnectionDesc conn) { Map json = new LinkedHashMap<>(); - Map tags = StorPoolHelper.addStorPoolTags(snapshotName, vmUuid, csTag, null); + Map tags = StorPoolHelper.addStorPoolTags(snapshotName, vmUuid, csTag, null, null); List> volumes = new ArrayList<>(); for (VolumeObjectTO volumeTO : volumeTOs) { Map vol = new LinkedHashMap<>(); @@ -612,7 +631,7 @@ public static SpApiResponse volumesGroupSnapshot(final List volu } json.put("tags", tags); json.put("volumes", volumes); - log.info("json:" + json); + LOGGER.info("json:" + json); return POST("MultiCluster/VolumesGroupSnapshot", json, conn); } diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java index 6cfa5ec14a2a..41e9676bb11f 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/motion/StorPoolDataMotionStrategy.java @@ -59,7 +59,8 @@ import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -99,7 +100,7 @@ @Component public class StorPoolDataMotionStrategy implements DataMotionStrategy { - private static final Logger log = Logger.getLogger(StorPoolDataMotionStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private SnapshotDataFactory _snapshotDataFactory; @@ -192,7 +193,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, CopyCmdAnswer answer = null; String err = null; if (res.getError() != null) { - log.debug(String.format("Could not create volume from snapshot with ID=%s", snapshot.getId())); + logger.debug(String.format("Could not create volume from snapshot with ID=%s", snapshot.getId())); StorPoolUtil.spLog("Volume create failed with error=%s", res.getError().getDescr()); err = res.getError().getDescr(); } else { @@ -220,7 +221,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, if (answer != null && answer.getResult()) { SpApiResponse resSnapshot = StorPoolUtil.volumeFreeze(volumeName, conn); if (resSnapshot.getError() != null) { - log.debug(String.format("Could not snapshot volume with ID=%s", snapshot.getId())); + logger.debug(String.format("Could not snapshot volume with ID=%s", snapshot.getId())); StorPoolUtil.spLog("Volume freeze failed with error=%s", resSnapshot.getError().getDescr()); err = resSnapshot.getError().getDescr(); StorPoolUtil.volumeDelete(volumeName, conn); @@ -388,7 +389,7 @@ public void copyAsync(Map volumeDataStoreMap, VirtualMach errMsg = String.format( "Copy volume(s) of VM [%s] to storage(s) [%s] and VM to host [%s] failed in StorPoolDataMotionStrategy.copyAsync. Error message: [%s].", vmTO.getId(), srcHost.getId(), destHost.getId(), ex.getMessage()); - log.error(errMsg, ex); + logger.error(errMsg, ex); throw new CloudRuntimeException(errMsg); } finally { @@ -444,7 +445,7 @@ private void handlePostMigration(boolean success, Map sr throw new AgentUnavailableException(msg, destHost.getId()); } } catch (Exception e) { - log.debug("Failed to disconnect one or more (original) dest volumes", e); + logger.debug("Failed to disconnect one or more (original) dest volumes", e); } } @@ -472,10 +473,10 @@ private void handlePostMigration(boolean success, Map sr AsyncCallFuture destroyFuture = _volumeService.expungeVolumeAsync(srcVolumeInfo); if (destroyFuture.get().isFailed()) { - log.debug("Failed to clean up source volume on storage"); + logger.debug("Failed to clean up source volume on storage"); } } catch (Exception e) { - log.debug("Failed to clean up source volume on storage", e); + logger.debug("Failed to clean up source volume on storage", e); } // Update the volume ID for snapshots on secondary storage @@ -487,13 +488,13 @@ private void handlePostMigration(boolean success, Map sr try { disconnectHostFromVolume(destHost, destVolumeInfo.getPoolId(), destVolumeInfo.getPath()); } catch (Exception e) { - log.debug("Failed to disconnect (new) dest volume", e); + logger.debug("Failed to disconnect (new) dest volume", e); } try { _volumeService.revokeAccess(destVolumeInfo, destHost, destVolumeInfo.getDataStore()); } catch (Exception e) { - log.debug("Failed to revoke access from dest volume", e); + logger.debug("Failed to revoke access from dest volume", e); } destVolumeInfo.processEvent(Event.OperationFailed); @@ -507,10 +508,10 @@ private void handlePostMigration(boolean success, Map sr AsyncCallFuture destroyFuture = _volumeService.expungeVolumeAsync(destVolumeInfo); if (destroyFuture.get().isFailed()) { - log.debug("Failed to clean up dest volume on storage"); + logger.debug("Failed to clean up dest volume on storage"); } } catch (Exception e) { - log.debug("Failed to clean up dest volume on storage", e); + logger.debug("Failed to clean up dest volume on storage", e); } } } diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolSnapshotStrategy.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolSnapshotStrategy.java index 23361bd1e5ea..5cdb7b8cda1a 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolSnapshotStrategy.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolSnapshotStrategy.java @@ -40,7 +40,8 @@ import org.apache.cloudstack.storage.datastore.util.StorPoolUtil.SpApiResponse; import org.apache.cloudstack.storage.datastore.util.StorPoolUtil.SpConnectionDesc; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.exception.InvalidParameterValueException; @@ -60,7 +61,7 @@ @Component public class StorPoolSnapshotStrategy implements SnapshotStrategy { - private static final Logger log = Logger.getLogger(StorPoolSnapshotStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private SnapshotDao _snapshotDao; @@ -90,11 +91,11 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshotInfo) { snapshotObj.processEvent(Snapshot.Event.BackupToSecondary); snapshotObj.processEvent(Snapshot.Event.OperationSucceeded); } catch (NoTransitionException ex) { - log.debug("Failed to change state: " + ex.toString()); + logger.debug("Failed to change state: " + ex.toString()); try { snapshotObj.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException ex2) { - log.debug("Failed to change state: " + ex2.toString()); + logger.debug("Failed to change state: " + ex2.toString()); } } return snapshotInfo; @@ -143,7 +144,7 @@ private void markSnapshotAsDestroyedIfAlreadyRemoved(Long snapshotId, SpApiRespo @Override public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperation op) { - log.debug(String.format("StorpoolSnapshotStrategy.canHandle: snapshot=%s, uuid=%s, op=%s", snapshot.getName(), snapshot.getUuid(), op)); + logger.debug(String.format("StorpoolSnapshotStrategy.canHandle: snapshot=%s, uuid=%s, op=%s", snapshot.getName(), snapshot.getUuid(), op)); if (op != SnapshotOperation.DELETE) { return StrategyPriority.CANT_HANDLE; @@ -172,7 +173,7 @@ public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperat } private boolean deleteSnapshotChain(SnapshotInfo snapshot) { - log.debug("delete snapshot chain for snapshot: " + snapshot.getId()); + logger.debug("delete snapshot chain for snapshot: " + snapshot.getId()); final SnapshotInfo snapOnImage = snapshot; boolean result = false; boolean resultIsSet = false; @@ -182,15 +183,15 @@ private boolean deleteSnapshotChain(SnapshotInfo snapshot) { SnapshotInfo child = snapshot.getChild(); if (child != null) { - log.debug("the snapshot has child, can't delete it on the storage"); + logger.debug("the snapshot has child, can't delete it on the storage"); break; } - log.debug("Snapshot: " + snapshot.getId() + " doesn't have children, so it's ok to delete it and its parents"); + logger.debug("Snapshot: " + snapshot.getId() + " doesn't have children, so it's ok to delete it and its parents"); SnapshotInfo parent = snapshot.getParent(); boolean deleted = false; if (parent != null) { if (parent.getPath() != null && parent.getPath().equalsIgnoreCase(snapshot.getPath())) { - log.debug("for empty delta snapshot, only mark it as destroyed in db"); + logger.debug("for empty delta snapshot, only mark it as destroyed in db"); snapshot.processEvent(Event.DestroyRequested); snapshot.processEvent(Event.OperationSuccessed); deleted = true; @@ -207,7 +208,7 @@ private boolean deleteSnapshotChain(SnapshotInfo snapshot) { if (r) { List cacheSnaps = snapshotDataFactory.listSnapshotOnCache(snapshot.getId()); for (SnapshotInfo cacheSnap : cacheSnaps) { - log.debug("Delete snapshot " + snapshot.getId() + " from image cache store: " + cacheSnap.getDataStore().getName()); + logger.debug("Delete snapshot " + snapshot.getId() + " from image cache store: " + cacheSnap.getDataStore().getName()); cacheSnap.delete(); } } @@ -216,7 +217,7 @@ private boolean deleteSnapshotChain(SnapshotInfo snapshot) { resultIsSet = true; } } catch (Exception e) { - log.debug("Failed to delete snapshot on storage. ", e); + logger.debug("Failed to delete snapshot on storage. ", e); } } } else { @@ -225,7 +226,7 @@ private boolean deleteSnapshotChain(SnapshotInfo snapshot) { snapshot = parent; } } catch (Exception e) { - log.debug("delete snapshot failed: ", e); + logger.debug("delete snapshot failed: ", e); } return result; } @@ -247,7 +248,7 @@ protected boolean deleteSnapshotOnImageAndPrimary(long snapshotId, DataStore sto obj.processEvent(Snapshot.Event.DestroyRequested); } } catch (NoTransitionException e) { - log.debug("Failed to set the state to destroying: ", e); + logger.debug("Failed to set the state to destroying: ", e); return false; } @@ -265,13 +266,13 @@ protected boolean deleteSnapshotOnImageAndPrimary(long snapshotId, DataStore sto } } } catch (Exception e) { - log.debug("Failed to delete snapshot: ", e); + logger.debug("Failed to delete snapshot: ", e); try { if (areLastSnapshotRef) { obj.processEvent(Snapshot.Event.OperationFailed); } } catch (NoTransitionException e1) { - log.debug("Failed to change snapshot state: " + e.toString()); + logger.debug("Failed to change snapshot state: " + e.toString()); } return false; } diff --git a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolVMSnapshotStrategy.java b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolVMSnapshotStrategy.java index 489f64f90257..2596b6a5bde7 100644 --- a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolVMSnapshotStrategy.java +++ b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolVMSnapshotStrategy.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.storage.vmsnapshot.DefaultVMSnapshotStrategy; import org.apache.cloudstack.storage.vmsnapshot.VMSnapshotHelper; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.api.VMSnapshotTO; @@ -66,7 +65,6 @@ @Component public class StorPoolVMSnapshotStrategy extends DefaultVMSnapshotStrategy { - private static final Logger log = Logger.getLogger(StorPoolVMSnapshotStrategy.class); @Inject private VMSnapshotHelper vmSnapshotHelper; @@ -94,7 +92,7 @@ public class StorPoolVMSnapshotStrategy extends DefaultVMSnapshotStrategy { @Override public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { - log.info("KVMVMSnapshotStrategy take snapshot"); + logger.info("KVMVMSnapshotStrategy take snapshot"); UserVm userVm = userVmDao.findById(vmSnapshot.getVmId()); VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot; @@ -163,7 +161,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { for (VolumeObjectTO volumeObjectTO : volumeTOs) { publishUsageEvents(EventTypes.EVENT_VM_SNAPSHOT_CREATE, vmSnapshot, userVm, volumeObjectTO); new_chain_size += volumeObjectTO.getSize(); - log.info("EventTypes.EVENT_VM_SNAPSHOT_CREATE publishUsageEvent" + volumeObjectTO); + logger.info("EventTypes.EVENT_VM_SNAPSHOT_CREATE publishUsageEvent" + volumeObjectTO); } publishUsageEvents(EventTypes.EVENT_VM_SNAPSHOT_ON_PRIMARY, vmSnapshot, userVm, new_chain_size - prev_chain_size, virtual_size); } else { @@ -171,15 +169,15 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { } return vmSnapshot; } catch (Exception e) { - log.debug("Could not create VM snapshot:" + e.getMessage()); + logger.debug("Could not create VM snapshot:" + e.getMessage()); throw new CloudRuntimeException("Could not create VM snapshot:" + e.getMessage()); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); - log.info(String.format("VMSnapshot.Event.OperationFailed vmSnapshot=%s", vmSnapshot)); + logger.info(String.format("VMSnapshot.Event.OperationFailed vmSnapshot=%s", vmSnapshot)); } catch (NoTransitionException nte) { - log.error("Cannot set vm state:" + nte.getMessage()); + logger.error("Cannot set vm state:" + nte.getMessage()); } } } @@ -219,7 +217,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - log.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException( "Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } @@ -241,13 +239,13 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { if (snapshotName == null) { err = String.format("Could not find StorPool's snapshot vm snapshot uuid=%s and volume uui=%s", vmSnapshot.getUuid(), volumeObjectTO.getUuid()); - log.error("Could not delete snapshot for vm:" + err); + logger.error("Could not delete snapshot for vm:" + err); } StorPoolUtil.spLog("StorpoolVMSnapshotStrategy.deleteVMSnapshot snapshotName=%s", snapshotName); resp = StorPoolUtil.snapshotDelete(snapshotName, conn); if (resp.getError() != null) { err = String.format("Could not delete storpool vm error=%s", resp.getError()); - log.error("Could not delete snapshot for vm:" + err); + logger.error("Could not delete snapshot for vm:" + err); } else { // do we need to clean database? if (snapshotDetailsVO != null) { @@ -278,7 +276,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) { @Override public boolean revertVMSnapshot(VMSnapshot vmSnapshot) { - log.debug("Revert vm snapshot"); + logger.debug("Revert vm snapshot"); VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot; UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId()); @@ -306,7 +304,7 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) { if (snapshotName == null) { err = String.format("Could not find StorPool's snapshot vm snapshot uuid=%s and volume uui=%s", vmSnapshot.getUuid(), volumeObjectTO.getUuid()); - log.error("Could not delete snapshot for vm:" + err); + logger.error("Could not delete snapshot for vm:" + err); } String volumeName = StorPoolStorageAdaptor.getVolumeNameFromPath(volumeObjectTO.getPath(), true); VolumeDetailVO detail = volumeDetailsDao.findDetail(volumeObjectTO.getId(), StorPoolUtil.SP_PROVIDER_NAME); @@ -347,14 +345,14 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) { result = vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationSucceeded); } catch (CloudRuntimeException | NoTransitionException e) { String errMsg = String.format("Error while finalize create vm snapshot [%s] due to %s", vmSnapshot.getName(), e.getMessage()); - log.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - log.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -381,7 +379,7 @@ private void publishUsageEvents(String type, VMSnapshot vmSnapshot, UserVm userV vmSnapshot.getName(), 0L, 0L, vmSnapSize, virtualSize, VMSnapshot.class.getName(), vmSnapshot.getUuid()); } catch (Exception e) { - log.error("Failed to publis usage event " + type, e); + logger.error("Failed to publis usage event " + type, e); } } } diff --git a/plugins/storage/volume/storpool/src/main/resources/META-INF/cloudstack/storage-volume-storpool/spring-storage-volume-storpool-context.xml b/plugins/storage/volume/storpool/src/main/resources/META-INF/cloudstack/storage-volume-storpool/spring-storage-volume-storpool-context.xml index 6451fc8fd398..b4e81f166f00 100644 --- a/plugins/storage/volume/storpool/src/main/resources/META-INF/cloudstack/storage-volume-storpool/spring-storage-volume-storpool-context.xml +++ b/plugins/storage/volume/storpool/src/main/resources/META-INF/cloudstack/storage-volume-storpool/spring-storage-volume-storpool-context.xml @@ -1,12 +1,12 @@ - org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml 2.0.0.AM25 - 1.5 1.3.2 1.1.3 1.1-groovy-2.4 @@ -41,18 +40,21 @@ - org.codehaus.gmaven - gmaven-plugin - ${gmaven.version} - - 1.7 - - + org.codehaus.gmavenplus + gmavenplus-plugin + ${cs.gmavenplus.version} + + + org.codehaus.groovy + groovy-all + ${cs.groovy.version} + + compile - testCompile + compileTests @@ -66,29 +68,12 @@ - - - org.codehaus.gmaven.runtime - gmaven-runtime-1.7 - ${gmaven.version} - - - org.codehaus.groovy - groovy-all - - - - - org.codehaus.groovy - groovy-all - ${cs.groovy.version} - - org.apache.maven.plugins maven-surefire-plugin + @{argLine} --add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED **/*Spec.groovy **/*Test.java @@ -162,7 +147,7 @@ net.bytebuddy byte-buddy - 1.10.5 + 1.14.5 junit diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPConfigCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPConfigCmd.java index 2a643dda76f1..f738a870053e 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPConfigCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPConfigCmd.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import org.apache.commons.lang.StringEscapeUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -53,7 +52,6 @@ requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class LDAPConfigCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LDAPConfigCmd.class.getName()); @Inject diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPRemoveCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPRemoveCmd.java index b915f97fe088..c70f84ffd699 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPRemoveCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPRemoveCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.response.LDAPRemoveResponse; import org.apache.cloudstack.ldap.LdapConfigurationVO; import org.apache.cloudstack.ldap.LdapManager; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.utils.Pair; @@ -38,7 +37,6 @@ @APICommand(name = "ldapRemove", description = "(Deprecated , use deleteLdapConfiguration) Remove the LDAP context for this site.", responseObject = LDAPConfigResponse.class, since = "3.0.1", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LDAPRemoveCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LDAPRemoveCmd.class.getName()); @Inject private LdapManager _ldapManager; diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java index 7c592888364e..1131667d98ae 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapAddConfigurationCmd.java @@ -20,7 +20,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.response.DomainResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -36,7 +35,6 @@ @APICommand(name = "addLdapConfiguration", description = "Add a new Ldap Configuration", responseObject = LdapConfigurationResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LdapAddConfigurationCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LdapAddConfigurationCmd.class.getName()); private static final String s_name = "ldapconfigurationresponse"; @Inject diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java index 2196aa8d4f51..880ecea4d13c 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapCreateAccountCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.ldap.LdapManager; import org.apache.cloudstack.ldap.LdapUser; import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException; -import org.apache.log4j.Logger; import org.bouncycastle.util.encoders.Base64; import javax.inject.Inject; @@ -47,7 +46,6 @@ @APICommand(name = "ldapCreateAccount", description = "Creates an account from an LDAP user", responseObject = AccountResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LdapCreateAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LdapCreateAccountCmd.class.getName()); private static final String s_name = "createaccountresponse"; @Inject diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java index 3ffebecfb95a..15e6c836d0db 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapDeleteConfigurationCmd.java @@ -20,7 +20,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.response.DomainResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -36,7 +35,6 @@ @APICommand(name = "deleteLdapConfiguration", description = "Remove an Ldap Configuration", responseObject = LdapConfigurationResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LdapDeleteConfigurationCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LdapDeleteConfigurationCmd.class.getName()); private static final String s_name = "ldapconfigurationresponse"; @Inject diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapImportUsersCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapImportUsersCmd.java index 96696d561cd2..087bd63c2969 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapImportUsersCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapImportUsersCmd.java @@ -42,7 +42,6 @@ import org.apache.cloudstack.ldap.LdapUser; import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.bouncycastle.util.encoders.Base64; import com.cloud.domain.Domain; @@ -61,7 +60,6 @@ @APICommand(name = "importLdapUsers", description = "Import LDAP users", responseObject = LdapUserResponse.class, since = "4.3.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LdapImportUsersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(LdapImportUsersCmd.class.getName()); private static final String s_name = "ldapuserresponse"; @@ -108,18 +106,18 @@ public LdapImportUsersCmd(final LdapManager ldapManager, final DomainService dom private void createCloudstackUserAccount(LdapUser user, String accountName, Domain domain) { Account account = _accountService.getActiveAccountByName(accountName, domain.getId()); if (account == null) { - s_logger.debug("No account exists with name: " + accountName + " creating the account and an user with name: " + user.getUsername() + " in the account"); + logger.debug("No account exists with name: " + accountName + " creating the account and an user with name: " + user.getUsername() + " in the account"); _accountService.createUserAccount(user.getUsername(), generatePassword(), user.getFirstname(), user.getLastname(), user.getEmail(), timezone, accountName, getAccountType(), getRoleId(), domain.getId(), domain.getNetworkDomain(), details, UUID.randomUUID().toString(), UUID.randomUUID().toString(), User.Source.LDAP); } else { // check if the user exists. if yes, call update UserAccount csuser = _accountService.getActiveUserAccount(user.getUsername(), domain.getId()); if (csuser == null) { - s_logger.debug("No user exists with name: " + user.getUsername() + " creating a user in the account: " + accountName); + logger.debug("No user exists with name: " + user.getUsername() + " creating a user in the account: " + accountName); _accountService.createUser(user.getUsername(), generatePassword(), user.getFirstname(), user.getLastname(), user.getEmail(), timezone, accountName, domain.getId(), UUID.randomUUID().toString(), User.Source.LDAP); } else { - s_logger.debug("Account [name=%s] and user [name=%s] already exist in CloudStack. Executing the user update."); + logger.debug("Account [name=%s] and user [name=%s] already exist in CloudStack. Executing the user update."); UpdateUserCmd updateUserCmd = new UpdateUserCmd(); updateUserCmd.setId(csuser.getId()); @@ -148,7 +146,7 @@ public void execute() } } catch (NoLdapUserMatchingQueryException ex) { users = new ArrayList(); - s_logger.info("No Ldap user matching query. " + " ::: " + ex.getMessage()); + logger.info("No Ldap user matching query. " + " ::: " + ex.getMessage()); } List addedUsers = new ArrayList(); @@ -158,7 +156,7 @@ public void execute() createCloudstackUserAccount(user, getAccountName(user), domain); addedUsers.add(user); } catch (InvalidParameterValueException ex) { - s_logger.error("Failed to create user with username: " + user.getUsername() + " ::: " + ex.getMessage()); + logger.error("Failed to create user with username: " + user.getUsername() + " ::: " + ex.getMessage()); } } ListResponse response = new ListResponse(); diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java index d12ca4ab6c1c..c34d026f89b2 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.response.DomainResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListCmd; @@ -39,7 +38,6 @@ @APICommand(name = "listLdapConfigurations", responseObject = LdapConfigurationResponse.class, description = "Lists all LDAP configurations", since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LdapListConfigurationCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(LdapListConfigurationCmd.class.getName()); private static final String s_name = "ldapconfigurationresponse"; diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListUsersCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListUsersCmd.java index 0c70c4d5b308..e5d434d38108 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListUsersCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListUsersCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListCmd; @@ -79,7 +78,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin,RoleType.DomainAdmin}) public class LdapListUsersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(LdapListUsersCmd.class.getName()); private static final String s_name = "ldapuserresponse"; @Inject private LdapManager _ldapManager; @@ -169,7 +167,7 @@ private List getCloudstackUsers() { } private void traceUserList() { - if(s_logger.isTraceEnabled()) { + if(logger.isTraceEnabled()) { StringBuilder users = new StringBuilder(); for (UserResponse user : cloudstackUsers) { if (users.length()> 0) { @@ -178,13 +176,13 @@ private void traceUserList() { users.append(user.getUsername()); } - s_logger.trace(String.format("checking against %d cloudstackusers: %s.", this.cloudstackUsers.size(), users.toString())); + logger.trace(String.format("checking against %d cloudstackusers: %s.", this.cloudstackUsers.size(), users.toString())); } } private List applyUserFilter(List ldapResponses) { - if(s_logger.isTraceEnabled()) { - s_logger.trace(String.format("applying filter: %s or %s.", this.getListTypeString(), this.getUserFilter())); + if(logger.isTraceEnabled()) { + logger.trace(String.format("applying filter: %s or %s.", this.getListTypeString(), this.getUserFilter())); } List responseList = getUserFilter().filter(this,ldapResponses); return responseList; @@ -218,14 +216,14 @@ boolean isACloudstackUser(final LdapUser ldapUser) { if (cloudstackUsers != null) { for (final UserResponse cloudstackUser : cloudstackUsers) { if (ldapUser.getUsername().equals(cloudstackUser.getUsername())) { - if(s_logger.isTraceEnabled()) { - s_logger.trace(String.format("found user %s in cloudstack", ldapUser.getUsername())); + if(logger.isTraceEnabled()) { + logger.trace(String.format("found user %s in cloudstack", ldapUser.getUsername())); } rc = true; } else { - if(s_logger.isTraceEnabled()) { - s_logger.trace(String.format("ldap user %s does not match cloudstack user %s", ldapUser.getUsername(), cloudstackUser.getUsername())); + if(logger.isTraceEnabled()) { + logger.trace(String.format("ldap user %s does not match cloudstack user %s", ldapUser.getUsername(), cloudstackUser.getUsername())); } } } @@ -234,20 +232,20 @@ boolean isACloudstackUser(final LdapUser ldapUser) { } boolean isACloudstackUser(final LdapUserResponse ldapUser) { - if(s_logger.isTraceEnabled()) { - s_logger.trace("checking response : " + ldapUser.toString()); + if(logger.isTraceEnabled()) { + logger.trace("checking response : " + ldapUser.toString()); } final List cloudstackUsers = getCloudstackUsers(); if (cloudstackUsers != null && cloudstackUsers.size() != 0) { for (final UserResponse cloudstackUser : cloudstackUsers) { if (ldapUser.getUsername().equals(cloudstackUser.getUsername())) { - if(s_logger.isTraceEnabled()) { - s_logger.trace(String.format("found user %s in cloudstack user %s", ldapUser.getUsername(), cloudstackUser.getUsername())); + if(logger.isTraceEnabled()) { + logger.trace(String.format("found user %s in cloudstack user %s", ldapUser.getUsername(), cloudstackUser.getUsername())); } return true; } else { - if(s_logger.isTraceEnabled()) { - s_logger.trace(String.format("ldap user %s does not match cloudstack user %s", ldapUser.getUsername(), cloudstackUser.getUsername())); + if(logger.isTraceEnabled()) { + logger.trace(String.format("ldap user %s does not match cloudstack user %s", ldapUser.getUsername(), cloudstackUser.getUsername())); } } } @@ -348,8 +346,8 @@ static UserFilter fromString(String val) { * @return unfiltered list of the input list of ldap users */ public List filterNoFilter(List input) { - if(s_logger.isTraceEnabled()) { - s_logger.trace("returning unfiltered list of ldap users"); + if(logger.isTraceEnabled()) { + logger.trace("returning unfiltered list of ldap users"); } annotateUserListWithSources(input); return input; @@ -361,8 +359,8 @@ public List filterNoFilter(List input) { * @return a list of ldap users not already in ACS */ public List filterAnyDomain(List input) { - if(s_logger.isTraceEnabled()) { - s_logger.trace("filtering existing users"); + if(logger.isTraceEnabled()) { + logger.trace("filtering existing users"); } final List ldapResponses = new ArrayList(); for (final LdapUserResponse user : input) { @@ -394,8 +392,8 @@ private boolean isNotAlreadyImportedInTheCurrentDomain(LdapUserResponse user) { * @return a list of ldap users not already in ACS */ public List filterLocalDomain(List input) { - if(s_logger.isTraceEnabled()) { - s_logger.trace("filtering local domain users"); + if(logger.isTraceEnabled()) { + logger.trace("filtering local domain users"); } final List ldapResponses = new ArrayList(); String domainId = getCurrentDomainId(); @@ -430,8 +428,8 @@ private String getCurrentDomainId() { * @return annotated list of the users of the input list, that will be automatically imported or synchronised */ public List filterPotentialImport(List input) { - if(s_logger.isTraceEnabled()) { - s_logger.trace("should be filtering potential imports!!!"); + if(logger.isTraceEnabled()) { + logger.trace("should be filtering potential imports!!!"); } // functional possibility do not add only users not yet in cloudstack but include users that would be moved if they are so in ldap? // this means if they are part of a account linked to an ldap group/ou diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapUserSearchCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapUserSearchCmd.java index a3c7d4f64068..b702beda1708 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapUserSearchCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapUserSearchCmd.java @@ -21,7 +21,6 @@ import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListCmd; @@ -38,7 +37,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LdapUserSearchCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(LdapUserSearchCmd.class.getName()); private static final String s_name = "ldapuserresponse"; @Inject private LdapManager _ldapManager; @@ -75,7 +73,7 @@ public void execute() { try { users = _ldapManager.searchUsers(query); } catch (final NoLdapUserMatchingQueryException e) { - s_logger.debug(e.getMessage()); + logger.debug(e.getMessage()); } final List ldapUserResponses = createLdapUserResponse(users); diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmd.java index 16f68b014688..6219fc90f810 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.ldap.LdapManager; import org.apache.cloudstack.ldap.LdapUser; import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.user.Account; @@ -47,7 +46,6 @@ @APICommand(name = "linkAccountToLdap", description = "link a cloudstack account to a group or OU in ldap", responseObject = LinkDomainToLdapResponse.class, since = "4.11.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin,RoleType.DomainAdmin}) public class LinkAccountToLdapCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(LinkAccountToLdapCmd.class.getName()); @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "The id of the domain that is to contain the linked account.") private Long domainId; @@ -83,7 +81,7 @@ public void execute() throws ServerApiException { try { ldapUser = _ldapManager.getUser(admin, type, ldapDomain, domainId); } catch (NoLdapUserMatchingQueryException e) { - LOGGER.debug("no ldap user matching username " + admin + " in the given group/ou", e); + logger.debug("no ldap user matching username " + admin + " in the given group/ou", e); } if (ldapUser != null && !ldapUser.isDisabled()) { Account account = _accountService.getActiveAccountByName(admin, domainId); @@ -93,15 +91,15 @@ public void execute() throws ServerApiException { .createUserAccount(admin, "", ldapUser.getFirstname(), ldapUser.getLastname(), ldapUser.getEmail(), null, admin, Account.Type.DOMAIN_ADMIN, RoleType.DomainAdmin.getId(), domainId, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), User.Source.LDAP); response.setAdminId(String.valueOf(userAccount.getAccountId())); - LOGGER.info("created an account with name " + admin + " in the given domain " + domainId); + logger.info("created an account with name " + admin + " in the given domain " + domainId); } catch (Exception e) { - LOGGER.info("an exception occurred while creating account with name " + admin + " in domain " + domainId, e); + logger.info("an exception occurred while creating account with name " + admin + " in domain " + domainId, e); } } else { - LOGGER.debug("an account with name " + admin + " already exists in the domain " + domainId); + logger.debug("an account with name " + admin + " already exists in the domain " + domainId); } } else { - LOGGER.debug("ldap user with username " + admin + " is disabled in the given group/ou"); + logger.debug("ldap user with username " + admin + " is disabled in the given group/ou"); } } response.setObjectName(this.getActualCommandName()); diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java index db80ff345f5b..d5187f99c995 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.ldap.LdapManager; import org.apache.cloudstack.ldap.LdapUser; import org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException; -import org.apache.log4j.Logger; import com.cloud.user.Account; @@ -44,7 +43,6 @@ @APICommand(name = "linkDomainToLdap", description = "link an existing cloudstack domain to group or OU in ldap", responseObject = LinkDomainToLdapResponse.class, since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class LinkDomainToLdapCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LinkDomainToLdapCmd.class.getName()); @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = true, entityType = DomainResponse.class, description = "The id of the domain which has to be " + "linked to LDAP.") @@ -100,7 +98,7 @@ public void execute() throws ServerApiException { try { ldapUser = _ldapManager.getUser(admin, type, getLdapDomain(), domainId); } catch (NoLdapUserMatchingQueryException e) { - s_logger.debug("no ldap user matching username " + admin + " in the given group/ou", e); + logger.debug("no ldap user matching username " + admin + " in the given group/ou", e); } if (ldapUser != null && !ldapUser.isDisabled()) { Account account = _accountService.getActiveAccountByName(admin, domainId); @@ -109,15 +107,15 @@ public void execute() throws ServerApiException { UserAccount userAccount = _accountService.createUserAccount(admin, "", ldapUser.getFirstname(), ldapUser.getLastname(), ldapUser.getEmail(), null, admin, Account.Type.DOMAIN_ADMIN, RoleType.DomainAdmin.getId(), domainId, null, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), User.Source.LDAP); response.setAdminId(String.valueOf(userAccount.getAccountId())); - s_logger.info("created an account with name " + admin + " in the given domain " + domainId); + logger.info("created an account with name " + admin + " in the given domain " + domainId); } catch (Exception e) { - s_logger.info("an exception occurred while creating account with name " + admin +" in domain " + domainId, e); + logger.info("an exception occurred while creating account with name " + admin +" in domain " + domainId, e); } } else { - s_logger.debug("an account with name " + admin + " already exists in the domain " + domainId); + logger.debug("an account with name " + admin + " already exists in the domain " + domainId); } } else { - s_logger.debug("ldap user with username "+admin+" is disabled in the given group/ou"); + logger.debug("ldap user with username "+admin+" is disabled in the given group/ou"); } } response.setObjectName("LinkDomainToLdap"); diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/ADLdapUserManagerImpl.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/ADLdapUserManagerImpl.java index 2413d718b621..552d5969a9e4 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/ADLdapUserManagerImpl.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/ADLdapUserManagerImpl.java @@ -28,10 +28,8 @@ import javax.naming.ldap.LdapContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; public class ADLdapUserManagerImpl extends OpenLdapUserManagerImpl implements LdapUserManager { - public static final Logger s_logger = Logger.getLogger(ADLdapUserManagerImpl.class.getName()); private static final String MICROSOFT_AD_NESTED_MEMBERS_FILTER = "memberOf:1.2.840.113556.1.4.1941:"; private static final String MICROSOFT_AD_MEMBERS_FILTER = "memberOf"; @@ -77,7 +75,7 @@ String generateADGroupSearchFilter(String groupName, Long domainId) { result.append(memberOfFilter); result.append(")"); - s_logger.debug("group search filter = " + result); + logger.debug("group search filter = " + result); return result.toString(); } diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapAuthenticator.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapAuthenticator.java index 41ef9573bb2d..b85098815943 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapAuthenticator.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapAuthenticator.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.auth.UserAuthenticator; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -38,7 +37,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class LdapAuthenticator extends AdapterBase implements UserAuthenticator { - private static final Logger LOGGER = Logger.getLogger(LdapAuthenticator.class.getName()); @Inject private LdapManager _ldapManager; @@ -61,15 +59,15 @@ public LdapAuthenticator(final LdapManager ldapManager, final UserAccountDao use public Pair authenticate(final String username, final String password, final Long domainId, final Map requestParameters) { Pair rc = new Pair(false, null); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Retrieving ldap user: " + username); + if (logger.isDebugEnabled()) { + logger.debug("Retrieving ldap user: " + username); } // TODO not allowing an empty password is a policy we shouldn't decide on. A private cloud may well want to allow this. if (StringUtils.isNoneEmpty(username, password)) { if (_ldapManager.isLdapEnabled(domainId) || _ldapManager.isLdapEnabled()) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("LDAP is enabled in the ldapManager"); + if (logger.isTraceEnabled()) { + logger.trace("LDAP is enabled in the ldapManager"); } final UserAccount user = _userAccountDao.getUserAccount(username, domainId); if (user != null && ! User.Source.LDAP.equals(user.getSource())) { @@ -78,25 +76,25 @@ public Pair authenticate(final String use List ldapTrustMapVOs = getLdapTrustMapVOS(domainId); if(ldapTrustMapVOs != null && ldapTrustMapVOs.size() > 0) { if(ldapTrustMapVOs.size() == 1 && ldapTrustMapVOs.get(0).getAccountId() == 0) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("We have a single mapping of a domain to an ldap group or ou"); + if (logger.isTraceEnabled()) { + logger.trace("We have a single mapping of a domain to an ldap group or ou"); } rc = authenticate(username, password, domainId, user, ldapTrustMapVOs.get(0)); } else { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("we are dealing with mapping of accounts in a domain to ldap groups"); + if (logger.isTraceEnabled()) { + logger.trace("we are dealing with mapping of accounts in a domain to ldap groups"); } rc = authenticate(username, password, domainId, user, ldapTrustMapVOs); } } else { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("'this' domain (%d) is not linked to ldap follow normal authentication", domainId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("'this' domain (%d) is not linked to ldap follow normal authentication", domainId)); } rc = authenticate(username, password, domainId, user); } } } else { - LOGGER.debug("Username or Password cannot be empty"); + logger.debug("Username or Password cannot be empty"); } return rc; @@ -175,7 +173,7 @@ Pair authenticate(String username, String } } } catch (NoLdapUserMatchingQueryException e) { - LOGGER.debug(e.getMessage()); + logger.debug(e.getMessage()); disableUserInCloudStack(userAccount); } @@ -183,7 +181,7 @@ Pair authenticate(String username, String } private void tracelist(String msg, List listToTrace) { - if (LOGGER.isTraceEnabled()) { + if (logger.isTraceEnabled()) { StringBuilder logMsg = new StringBuilder(); logMsg.append(msg); logMsg.append(':'); @@ -191,13 +189,13 @@ private void tracelist(String msg, List listToTrace) { logMsg.append(' '); logMsg.append(listMember); } - LOGGER.trace(logMsg.toString()); + logger.trace(logMsg.toString()); } } private void logAndDisable(UserAccount userAccount, String msg, boolean remove) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info(msg); + if (logger.isInfoEnabled()) { + logger.info(msg); } if(remove) { removeUserInCloudStack(userAccount); @@ -230,7 +228,7 @@ private Pair authenticate(String username final Account.Type accountType = ldapTrustMapVO.getAccountType(); processLdapUser(password, domainId, user, rc, ldapUser, accountType); } catch (NoLdapUserMatchingQueryException e) { - LOGGER.debug(e.getMessage()); + logger.debug(e.getMessage()); // no user in ldap ==>> disable user in cloudstack disableUserInCloudStack(user); } @@ -273,10 +271,10 @@ Pair authenticate(String username, String if(!ldapUser.isDisabled()) { result = _ldapManager.canAuthenticate(ldapUser.getPrincipal(), password, domainId); } else { - LOGGER.debug("user with principal "+ ldapUser.getPrincipal() + " is disabled in ldap"); + logger.debug("user with principal "+ ldapUser.getPrincipal() + " is disabled in ldap"); } } catch (NoLdapUserMatchingQueryException e) { - LOGGER.debug(e.getMessage()); + logger.debug(e.getMessage()); } } return processResultAndAction(user, result); diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapContextFactory.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapContextFactory.java index 0161adf9fda4..e6f23ef8ab3f 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapContextFactory.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapContextFactory.java @@ -26,10 +26,11 @@ import javax.naming.ldap.LdapContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class LdapContextFactory { - private static final Logger s_logger = Logger.getLogger(LdapContextFactory.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private LdapConfiguration _ldapConfiguration; @@ -58,7 +59,7 @@ private LdapContext createInitialDirContext(final String principal, final String private LdapContext createInitialDirContext(final String principal, final String password, final String providerUrl, final boolean isSystemContext, Long domainId) throws NamingException, IOException { Hashtable environment = getEnvironment(principal, password, providerUrl, isSystemContext, domainId); - s_logger.debug("initializing ldap with provider url: " + environment.get(Context.PROVIDER_URL)); + logger.debug("initializing ldap with provider url: " + environment.get(Context.PROVIDER_URL)); return new InitialLdapContext(environment, null); } @@ -70,7 +71,7 @@ private void enableSSL(final Hashtable environment, Long domainI final boolean sslStatus = _ldapConfiguration.getSSLStatus(domainId); if (sslStatus) { - s_logger.info("LDAP SSL enabled."); + logger.info("LDAP SSL enabled."); environment.put(Context.SECURITY_PROTOCOL, "ssl"); System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore(domainId)); System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword(domainId)); diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java index 6ed79a0c69ff..16914e792a6c 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java @@ -52,7 +52,6 @@ import org.apache.cloudstack.ldap.dao.LdapConfigurationDao; import org.apache.cloudstack.ldap.dao.LdapTrustMapDao; import org.apache.commons.lang.Validate; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.domain.DomainVO; @@ -65,7 +64,6 @@ @Component public class LdapManagerImpl extends ComponentLifecycleBase implements LdapManager, LdapValidator { - private static final Logger LOGGER = Logger.getLogger(LdapManagerImpl.class.getName()); @Inject private LdapConfigurationDao _ldapConfigurationDao; @@ -106,7 +104,7 @@ public LdapManagerImpl(final LdapConfigurationDao ldapConfigurationDao, final Ld @Override public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - LOGGER.debug("Configuring LDAP Manager"); + logger.debug("Configuring LDAP Manager"); addAccountRemovalListener(); addDomainRemovalListener(); @@ -126,7 +124,7 @@ public void onPublishMessage(String senderAddress, String subject, Object args) removeTrustmap(ldapTrustMapVO); } } catch (final Exception e) { - LOGGER.error("Caught exception while removing account linked to LDAP", e); + logger.error("Caught exception while removing account linked to LDAP", e); } } }); @@ -143,7 +141,7 @@ public void onPublishMessage(String senderAddress, String subject, Object args) removeTrustmap(ldapTrustMapVO); } } catch (final Exception e) { - LOGGER.error("Caught exception while removing trust-map for domain linked to LDAP", e); + logger.error("Caught exception while removing trust-map for domain linked to LDAP", e); } } }); @@ -152,7 +150,7 @@ public void onPublishMessage(String senderAddress, String subject, Object args) private void removeTrustmap(LdapTrustMapVO ldapTrustMapVO) { String msg = String.format("Removing link between LDAP: %s - type: %s and account: %s on domain: %s", ldapTrustMapVO.getName(), ldapTrustMapVO.getType().name(), ldapTrustMapVO.getAccountId(), ldapTrustMapVO.getDomainId()); - LOGGER.debug(msg); + logger.debug(msg); _ldapTrustMapDao.remove(ldapTrustMapVO.getId()); } @@ -181,10 +179,10 @@ private LdapConfigurationResponse addConfigurationInternal(final String hostname context = _ldapContextFactory.createBindContext(providerUrl,domainId); configuration = new LdapConfigurationVO(hostname, port, domainId); _ldapConfigurationDao.persist(configuration); - LOGGER.info("Added new ldap server with url: " + providerUrl + (domainId == null ? "": " for domain " + domainId)); + logger.info("Added new ldap server with url: " + providerUrl + (domainId == null ? "": " for domain " + domainId)); return createLdapConfigurationResponse(configuration); } catch (NamingException | IOException e) { - LOGGER.debug("NamingException while doing an LDAP bind", e); + logger.debug("NamingException while doing an LDAP bind", e); throw new InvalidParameterValueException("Unable to bind to the given LDAP server"); } finally { closeContext(context); @@ -207,13 +205,13 @@ public boolean canAuthenticate(final String principal, final String password, fi // TODO return the right account for this user final LdapContext context = _ldapContextFactory.createUserContext(principal, password, domainId); closeContext(context); - if(LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("User(%s) authenticated for domain(%s)", principal, domainId)); + if(logger.isTraceEnabled()) { + logger.trace(String.format("User(%s) authenticated for domain(%s)", principal, domainId)); } return true; } catch (NamingException | IOException e) {/* AuthenticationException is caught as NamingException */ - LOGGER.debug("Exception while doing an LDAP bind for user "+" "+principal, e); - LOGGER.info("Failed to authenticate user: " + principal + ". incorrect password."); + logger.debug("Exception while doing an LDAP bind for user "+" "+principal, e); + logger.info("Failed to authenticate user: " + principal + ". incorrect password."); return false; } } @@ -224,7 +222,7 @@ private void closeContext(final LdapContext context) { context.close(); } } catch (final NamingException e) { - LOGGER.warn(e.getMessage(), e); + logger.warn(e.getMessage(), e); } } @@ -268,7 +266,7 @@ private LdapConfigurationResponse deleteConfigurationInternal(final String hostn throw new InvalidParameterValueException("Cannot find configuration with hostname " + hostname); } else { _ldapConfigurationDao.remove(configuration.getId()); - LOGGER.info("Removed ldap server with url: " + hostname + ':' + port + (domainId == null ? "" : " for domain id " + domainId)); + logger.info("Removed ldap server with url: " + hostname + ':' + port + (domainId == null ? "" : " for domain id " + domainId)); return createLdapConfigurationResponse(configuration); } } @@ -300,7 +298,7 @@ public LdapUser getUser(final String username, Long domainId) throws NoLdapUserM return _ldapUserManagerFactory.getInstance(_ldapConfiguration.getLdapProvider(null)).getUser(escapedUsername, context, domainId); } catch (NamingException | IOException e) { - LOGGER.debug("ldap Exception: ",e); + logger.debug("ldap Exception: ",e); throw new NoLdapUserMatchingQueryException("No Ldap User found for username: "+username); } finally { closeContext(context); @@ -321,7 +319,7 @@ public LdapUser getUser(final String username, final String type, final String n LdapUserManager userManagerFactory = _ldapUserManagerFactory.getInstance(ldapProvider); return userManagerFactory.getUser(escapedUsername, type, name, context, domainId); } catch (NamingException | IOException e) { - LOGGER.debug("ldap Exception: ",e); + logger.debug("ldap Exception: ",e); throw new NoLdapUserMatchingQueryException("No Ldap User found for username: "+username + " in group: " + name + " of type: " + type); } finally { closeContext(context); @@ -335,7 +333,7 @@ public List getUsers(Long domainId) throws NoLdapUserMatchingQueryExce context = _ldapContextFactory.createBindContext(domainId); return _ldapUserManagerFactory.getInstance(_ldapConfiguration.getLdapProvider(domainId)).getUsers(context, domainId); } catch (NamingException | IOException e) { - LOGGER.debug("ldap Exception: ",e); + logger.debug("ldap Exception: ",e); throw new NoLdapUserMatchingQueryException("*"); } finally { closeContext(context); @@ -349,7 +347,7 @@ public List getUsersInGroup(String groupName, Long domainId) throws No context = _ldapContextFactory.createBindContext(domainId); return _ldapUserManagerFactory.getInstance(_ldapConfiguration.getLdapProvider(domainId)).getUsersInGroup(groupName, context, domainId); } catch (NamingException | IOException e) { - LOGGER.debug("ldap NamingException: ",e); + logger.debug("ldap NamingException: ",e); throw new NoLdapUserMatchingQueryException("groupName=" + groupName); } finally { closeContext(context); @@ -387,7 +385,7 @@ public List searchUsers(final String username) throws NoLdapUserMatchi final String escapedUsername = LdapUtils.escapeLDAPSearchFilter(username); return _ldapUserManagerFactory.getInstance(_ldapConfiguration.getLdapProvider(null)).getUsers("*" + escapedUsername + "*", context, null); } catch (NamingException | IOException e) { - LOGGER.debug("ldap Exception: ",e); + logger.debug("ldap Exception: ",e); throw new NoLdapUserMatchingQueryException(username); } finally { closeContext(context); @@ -416,7 +414,7 @@ private LinkDomainToLdapResponse linkDomainToLdap(Long domainId, String type, St DomainVO domain = domainDao.findById(vo.getDomainId()); String domainUuid = ""; if (domain == null) { - LOGGER.error("no domain in database for id " + vo.getDomainId()); + logger.error("no domain in database for id " + vo.getDomainId()); } else { domainUuid = domain.getUuid(); } @@ -466,7 +464,7 @@ public LinkAccountToLdapResponse linkAccountToLdap(LinkAccountToLdapCmd cmd) { DomainVO domain = domainDao.findById(vo.getDomainId()); String domainUuid = ""; if (domain == null) { - LOGGER.error("no domain in database for id " + vo.getDomainId()); + logger.error("no domain in database for id " + vo.getDomainId()); } else { domainUuid = domain.getUuid(); } @@ -485,16 +483,16 @@ private void clearOldAccountMapping(LinkAccountToLdapCmd cmd) { String msg = String.format("group %s is mapped to account %d in the current domain (%s)", cmd.getLdapDomain(), oldVo.getAccountId(), cmd.getDomainId()); if (null == oldAcount.getRemoved()) { msg += ", delete the old map before mapping a new account to the same group."; - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } else { msg += ", the old map is deleted."; - LOGGER.warn(msg); + logger.warn(msg); _ldapTrustMapDao.expunge(oldVo.getId()); } } else { String msg = String.format("group %s is mapped to the current domain (%s) for autoimport and can not be used for autosync", cmd.getLdapDomain(), cmd.getDomainId()); - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapUserManagerFactory.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapUserManagerFactory.java index a6217dcb5cb8..55d482a29b1c 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapUserManagerFactory.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapUserManagerFactory.java @@ -18,7 +18,8 @@ */ package org.apache.cloudstack.ldap; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.ApplicationContext; @@ -30,7 +31,7 @@ public class LdapUserManagerFactory implements ApplicationContextAware { - public static final Logger s_logger = Logger.getLogger(LdapUserManagerFactory.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); static Map ldapUserManagerMap = new HashMap<>(); diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/OpenLdapUserManagerImpl.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/OpenLdapUserManagerImpl.java index 12bda947f36c..4c125af2ea67 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/OpenLdapUserManagerImpl.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/OpenLdapUserManagerImpl.java @@ -36,10 +36,11 @@ import org.apache.cloudstack.ldap.dao.LdapTrustMapDao; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class OpenLdapUserManagerImpl implements LdapUserManager { - private static final Logger LOGGER = Logger.getLogger(OpenLdapUserManagerImpl.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected LdapConfiguration _ldapConfiguration; @@ -112,8 +113,8 @@ private String generateSearchFilter(final String username, Long domainId) { result.append(")"); String returnString = result.toString(); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("constructed ldap query: " + returnString); + if (logger.isTraceEnabled()) { + logger.trace("constructed ldap query: " + returnString); } return returnString; } @@ -133,8 +134,8 @@ private List getMappedLdapGroups(Long domainId) { private String getMemberOfGroupString(String group, String memberOfAttribute) { final StringBuilder memberOfFilter = new StringBuilder(); if (null != group) { - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("adding search filter for '" + group + + if(logger.isDebugEnabled()) { + logger.debug("adding search filter for '" + group + "', using '" + memberOfAttribute + "'"); } memberOfFilter.append("(" + memberOfAttribute + "="); @@ -253,7 +254,7 @@ public List getUsersInGroup(String groupName, LdapContext context, Lon try{ users.add(getUserForDn(userdn, context, domainId)); } catch (NamingException e){ - LOGGER.info("Userdn: " + userdn + " Not Found:: Exception message: " + e.getMessage()); + logger.info("Userdn: " + userdn + " Not Found:: Exception message: " + e.getMessage()); } } } @@ -292,8 +293,8 @@ public LdapUser searchUser(final String basedn, final String searchString, final searchControls.setReturningAttributes(_ldapConfiguration.getReturnAttributes(domainId)); NamingEnumeration results = context.search(basedn, searchString, searchControls); - if(LOGGER.isDebugEnabled()) { - LOGGER.debug("searching user(s) with filter: \"" + searchString + "\""); + if(logger.isDebugEnabled()) { + logger.debug("searching user(s) with filter: \"" + searchString + "\""); } final List users = new ArrayList(); while (results.hasMoreElements()) { @@ -342,7 +343,7 @@ public List searchUsers(final String username, final LdapContext conte } } } else { - LOGGER.info("No controls were sent from the ldap server"); + logger.info("No controls were sent from the ldap server"); } context.setRequestControls(new Control[] {new PagedResultsControl(pageSize, cookie, Control.CRITICAL)}); } while (cookie != null); diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapImportUsersCmdTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapImportUsersCmdTest.java index 594c23fb786d..3dc9d4054b90 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapImportUsersCmdTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapImportUsersCmdTest.java @@ -37,9 +37,9 @@ import java.util.UUID; import static junit.framework.TestCase.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapListUsersCmdTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapListUsersCmdTest.java index 11d99f58858e..bd55926e8e00 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapListUsersCmdTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LdapListUsersCmdTest.java @@ -49,7 +49,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmdTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmdTest.java index e355d77c3435..62a3a809b16f 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmdTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkAccountToLdapCmdTest.java @@ -30,12 +30,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmdTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmdTest.java index 204e9853ffec..67d0e7705226 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmdTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/api/command/LinkDomainToLdapCmdTest.java @@ -29,12 +29,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/ADLdapUserManagerImplTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/ADLdapUserManagerImplTest.java index bf9d7437446e..58b14ec3684e 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/ADLdapUserManagerImplTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/ADLdapUserManagerImplTest.java @@ -26,7 +26,7 @@ import javax.naming.ldap.LdapContext; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapAuthenticatorTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapAuthenticatorTest.java index a3b2311e2ce3..0d1d840ce22b 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapAuthenticatorTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapAuthenticatorTest.java @@ -41,7 +41,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java index 58024b752ab6..5defce948b29 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java @@ -21,7 +21,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapDirectoryServerConnectionTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapDirectoryServerConnectionTest.java index 2d2690f8e3a4..a216084aa3a0 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapDirectoryServerConnectionTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapDirectoryServerConnectionTest.java @@ -88,7 +88,7 @@ public void setup() throws Exception { ldapTestConfigTool.overrideConfigValue(configuration, "ldapBindPrincipal", "uid=admin,ou=system"); ldapTestConfigTool.overrideConfigValue(configuration, "ldapMemberOfAttribute", "memberOf"); lenient().when(userManagerFactory.getInstance(LdapUserManager.Provider.OPENLDAP)).thenReturn(new OpenLdapUserManagerImpl(configuration)); - // construct an ellaborate structure around a single object + // construct an elaborate structure around a single object Pair, Integer> vos = new Pair, Integer>( Collections.singletonList(configurationVO),1); lenient().when(configurationDao.searchConfigurations(null, 0, 1L)).thenReturn(vos); @@ -149,7 +149,7 @@ public void testEmbeddedLdapAvailable() { public void testSchemaLoading() { try { assertTrue("standard not loaded", embeddedLdapServer.addSchemaFromClasspath("other")); -// we need member of in ACS nowadays (backwards comptability broken): +// we need member of in ACS nowadays (backwards compatibility broken): // assertTrue("memberOf schema not loaded", embeddedLdapServer.addSchemaFromPath(new File("src/test/resources/memberOf"), "microsoft")); } catch (LdapException | IOException e) { fail(e.getLocalizedMessage()); diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapTestConfigTool.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapTestConfigTool.java index 47f201de4799..4197bad4f2d9 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapTestConfigTool.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapTestConfigTool.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.framework.config.ConfigKey; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; public class LdapTestConfigTool { public LdapTestConfigTool() { @@ -31,18 +30,12 @@ void overrideConfigValue(LdapConfiguration ldapConfiguration, final String confi ConfigKey key = (ConfigKey)configKey.get(ldapConfiguration); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(configKey, configKey.getModifiers() & ~Modifier.FINAL); - Field f = ConfigKey.class.getDeclaredField("_value"); f.setAccessible(true); - modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL); f.set(key, o); Field dynamic = ConfigKey.class.getDeclaredField("_isDynamic"); dynamic.setAccessible(true); - modifiersField.setInt(dynamic, dynamic.getModifiers() & ~Modifier.FINAL); dynamic.setBoolean(key, false); } } diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnboundidZapdotConnectionTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnboundidZapdotConnectionTest.java index 7e2c89e55566..85267dcbeca4 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnboundidZapdotConnectionTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnboundidZapdotConnectionTest.java @@ -24,7 +24,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.zapodot.junit.ldap.EmbeddedLdapRule; import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnitConnectionTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnitConnectionTest.java index 1bdfa9a91aa8..a1923947e948 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnitConnectionTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUnitConnectionTest.java @@ -21,7 +21,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.btmatthews.ldapunit.DirectoryTester; import com.btmatthews.ldapunit.DirectoryServerConfiguration; diff --git a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUserManagerFactoryTest.java b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUserManagerFactoryTest.java index 206526b61a01..8d6470391446 100644 --- a/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUserManagerFactoryTest.java +++ b/plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapUserManagerFactoryTest.java @@ -23,7 +23,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.ApplicationContext; diff --git a/plugins/user-authenticators/ldap/src/test/resources/log4j.xml b/plugins/user-authenticators/ldap/src/test/resources/log4j.xml index 031d2283580e..6c0ffa264e19 100755 --- a/plugins/user-authenticators/ldap/src/test/resources/log4j.xml +++ b/plugins/user-authenticators/ldap/src/test/resources/log4j.xml @@ -19,60 +19,46 @@ under the License. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + net.sf.cglib.proxy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/user-authenticators/ldap/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/user-authenticators/ldap/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f0..000000000000 --- a/plugins/user-authenticators/ldap/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/user-authenticators/md5/pom.xml b/plugins/user-authenticators/md5/pom.xml index e4a13810b1b2..e63f97743418 100644 --- a/plugins/user-authenticators/md5/pom.xml +++ b/plugins/user-authenticators/md5/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml
      diff --git a/plugins/user-authenticators/md5/src/main/java/org/apache/cloudstack/auth/MD5UserAuthenticator.java b/plugins/user-authenticators/md5/src/main/java/org/apache/cloudstack/auth/MD5UserAuthenticator.java index 3f3898f64649..7286f57d0488 100644 --- a/plugins/user-authenticators/md5/src/main/java/org/apache/cloudstack/auth/MD5UserAuthenticator.java +++ b/plugins/user-authenticators/md5/src/main/java/org/apache/cloudstack/auth/MD5UserAuthenticator.java @@ -23,7 +23,6 @@ import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.user.UserAccount; import com.cloud.user.dao.UserAccountDao; @@ -37,30 +36,29 @@ * */ public class MD5UserAuthenticator extends AdapterBase implements UserAuthenticator { - public static final Logger s_logger = Logger.getLogger(MD5UserAuthenticator.class); @Inject private UserAccountDao _userAccountDao; @Override public Pair authenticate(String username, String password, Long domainId, Map requestParameters) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Retrieving user: " + username); + if (logger.isDebugEnabled()) { + logger.debug("Retrieving user: " + username); } if (StringUtils.isAnyEmpty(username, password)) { - s_logger.debug("Username or Password cannot be empty"); + logger.debug("Username or Password cannot be empty"); return new Pair<>(false, null); } UserAccount user = _userAccountDao.getUserAccount(username, domainId); if (user == null) { - s_logger.debug("Unable to find user with " + username + " in domain " + domainId); + logger.debug("Unable to find user with " + username + " in domain " + domainId); return new Pair<>(false, null); } if (!user.getPassword().equals(encode(password))) { - s_logger.debug("Password does not match"); + logger.debug("Password does not match"); return new Pair<>(false, ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT); } return new Pair<>(true, null); diff --git a/plugins/user-authenticators/md5/src/main/resources/META-INF/cloudstack/md5/spring-md5-context.xml b/plugins/user-authenticators/md5/src/main/resources/META-INF/cloudstack/md5/spring-md5-context.xml index 132f1481bb69..a447e7317437 100644 --- a/plugins/user-authenticators/md5/src/main/resources/META-INF/cloudstack/md5/spring-md5-context.xml +++ b/plugins/user-authenticators/md5/src/main/resources/META-INF/cloudstack/md5/spring-md5-context.xml @@ -30,5 +30,5 @@ - + diff --git a/plugins/user-authenticators/md5/src/test/java/org/apache/cloudstack/auth/MD5UserAuthenticatorTest.java b/plugins/user-authenticators/md5/src/test/java/org/apache/cloudstack/auth/MD5UserAuthenticatorTest.java index 78af8e532f04..ad86b16f39e8 100644 --- a/plugins/user-authenticators/md5/src/test/java/org/apache/cloudstack/auth/MD5UserAuthenticatorTest.java +++ b/plugins/user-authenticators/md5/src/test/java/org/apache/cloudstack/auth/MD5UserAuthenticatorTest.java @@ -26,7 +26,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.UserAccountVO; import com.cloud.user.dao.UserAccountDao; diff --git a/plugins/user-authenticators/oauth2/pom.xml b/plugins/user-authenticators/oauth2/pom.xml index 26c31bcfea2e..5a1e49874a89 100644 --- a/plugins/user-authenticators/oauth2/pom.xml +++ b/plugins/user-authenticators/oauth2/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2AuthManagerImpl.java b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2AuthManagerImpl.java index b0596f0c386d..b65027d6a249 100644 --- a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2AuthManagerImpl.java +++ b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2AuthManagerImpl.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.oauth2.dao.OauthProviderDao; import org.apache.cloudstack.oauth2.vo.OauthProviderVO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -44,7 +43,6 @@ import java.util.Map; public class OAuth2AuthManagerImpl extends ManagerBase implements OAuth2AuthManager, Manager, Configurable { - private static final Logger s_logger = Logger.getLogger(OAuth2AuthManagerImpl.class); @Inject private UserDao _userDao; @@ -67,10 +65,10 @@ public List> getAuthCommands() { @Override public boolean start() { if (isOAuthPluginEnabled()) { - s_logger.info("OAUTH plugin loaded"); + logger.info("OAUTH plugin loaded"); initializeUserOAuth2AuthenticationProvidersMap(); } else { - s_logger.info("OAUTH plugin not enabled so not loading"); + logger.info("OAUTH plugin not enabled so not loading"); } return true; } diff --git a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticator.java b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticator.java index 5d721e7e0d6c..dde50c8bb34d 100644 --- a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticator.java +++ b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticator.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.auth.UserAuthenticator; import org.apache.cloudstack.auth.UserOAuth2Authenticator; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.Map; @@ -35,7 +34,6 @@ import static org.apache.cloudstack.oauth2.OAuth2AuthManager.OAuth2IsPluginEnabled; public class OAuth2UserAuthenticator extends AdapterBase implements UserAuthenticator { - public static final Logger s_logger = Logger.getLogger(OAuth2UserAuthenticator.class); @Inject private UserAccountDao userAccountDao; @@ -47,21 +45,21 @@ public class OAuth2UserAuthenticator extends AdapterBase implements UserAuthenti @Override public Pair authenticate(String username, String password, Long domainId, Map requestParameters) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Trying OAuth2 auth for user: " + username); + if (logger.isDebugEnabled()) { + logger.debug("Trying OAuth2 auth for user: " + username); } if (!isOAuthPluginEnabled()) { - s_logger.debug("OAuth2 plugin is disabled"); + logger.debug("OAuth2 plugin is disabled"); return new Pair(false, null); } else if (requestParameters == null) { - s_logger.debug("Request parameters are null"); + logger.debug("Request parameters are null"); return new Pair(false, null); } final UserAccount userAccount = userAccountDao.getUserAccount(username, domainId); if (userAccount == null) { - s_logger.debug("Unable to find user with " + username + " in domain " + domainId + ", or user source is not OAUTH2"); + logger.debug("Unable to find user with " + username + " in domain " + domainId + ", or user source is not OAUTH2"); return new Pair(false, null); } else { User user = userDao.getUser(userAccount.getId()); diff --git a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmd.java b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmd.java index 6cd3156f68a2..28f2a6362733 100644 --- a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmd.java +++ b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmd.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.oauth2.OAuth2AuthManager; import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ @APICommand(name = "deleteOauthProvider", description = "Deletes the registered OAuth provider", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0") public class DeleteOAuthProviderCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteOAuthProviderCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java index 597283ae33e1..abdbf65dbb42 100644 --- a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java +++ b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/ListOAuthProvidersCmd.java @@ -39,7 +39,6 @@ import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse; import org.apache.cloudstack.oauth2.vo.OauthProviderVO; import org.apache.commons.lang.ArrayUtils; -import org.apache.log4j.Logger; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -49,7 +48,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, since = "4.19.0") public class ListOAuthProvidersCmd extends BaseListCmd implements APIAuthenticator { - public static final Logger s_logger = Logger.getLogger(ListOAuthProvidersCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -141,7 +139,7 @@ public void setAuthenticators(List authenticators) { } } if (_oauth2mgr == null) { - s_logger.error("No suitable Pluggable Authentication Manager found for listing OAuth providers"); + logger.error("No suitable Pluggable Authentication Manager found for listing OAuth providers"); } } } diff --git a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmd.java b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmd.java index 928fa76780a3..f9a1d10d3526 100644 --- a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmd.java +++ b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.LoginCmdResponse; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; import javax.inject.Inject; @@ -54,8 +53,6 @@ requestHasSensitiveInfo = true, responseObject = LoginCmdResponse.class, entityType = {}, since = "4.19.0") public class OauthLoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthenticator { - public static final Logger s_logger = Logger.getLogger(OauthLoginAPIAuthenticatorCmd.class.getName()); - ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// @@ -169,8 +166,8 @@ private String doOauthAuthentication(HttpSession session, Long domainId, String "failed to authenticate user, check if username/password are correct"); auditTrailSb.append(" " + ApiErrorCode.ACCOUNT_ERROR + " " + msg); serializedResponse = _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), msg, params, responseType); - if (s_logger.isTraceEnabled()) { - s_logger.trace(msg); + if (logger.isTraceEnabled()) { + logger.trace(msg); } } @@ -194,7 +191,7 @@ protected Long getDomainIdFromParams(Map params, StringBuilder } auditTrailSb.append(" domainid=" + domainId);// building the params for POST call } catch (final NumberFormatException e) { - s_logger.warn("Invalid domain id entered by user"); + logger.warn("Invalid domain id entered by user"); auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "Invalid domain id entered, please enter a valid one"); throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid domain id entered, please enter a valid one", params, diff --git a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/UpdateOAuthProviderCmd.java b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/UpdateOAuthProviderCmd.java index b38423ffd485..1c79b7b144c8 100644 --- a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/UpdateOAuthProviderCmd.java +++ b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/UpdateOAuthProviderCmd.java @@ -21,7 +21,6 @@ import org.apache.cloudstack.oauth2.OAuth2AuthManager; import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse; import org.apache.cloudstack.oauth2.vo.OauthProviderVO; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ @APICommand(name = "updateOauthProvider", description = "Updates the registered OAuth provider details", responseObject = OauthProviderResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0") public final class UpdateOAuthProviderCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateOAuthProviderCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/VerifyOAuthCodeAndGetUserCmd.java b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/VerifyOAuthCodeAndGetUserCmd.java index 5dbeef10dcb4..bd49f87d6273 100644 --- a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/VerifyOAuthCodeAndGetUserCmd.java +++ b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/VerifyOAuthCodeAndGetUserCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.oauth2.OAuth2AuthManager; import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse; import org.apache.commons.lang.ArrayUtils; -import org.apache.log4j.Logger; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -46,7 +45,6 @@ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, since = "4.19.0") public class VerifyOAuthCodeAndGetUserCmd extends BaseListCmd implements APIAuthenticator { - public static final Logger s_logger = Logger.getLogger(VerifyOAuthCodeAndGetUserCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -124,7 +122,7 @@ public void setAuthenticators(List authenticators) { } } if (_oauth2mgr == null) { - s_logger.error("No suitable Pluggable Authentication Manager found for listing OAuth providers"); + logger.error("No suitable Pluggable Authentication Manager found for listing OAuth providers"); } } } diff --git a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2Provider.java b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2Provider.java index aa0fc93776dd..42ed1451ccd5 100644 --- a/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2Provider.java +++ b/plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2Provider.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.oauth2.dao.OauthProviderDao; import org.apache.cloudstack.oauth2.vo.OauthProviderVO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.io.IOException; @@ -40,7 +39,6 @@ import java.util.List; public class GoogleOAuth2Provider extends AdapterBase implements UserOAuth2Authenticator { - private static final Logger s_logger = Logger.getLogger(GoogleOAuth2Provider.class); protected String accessToken = null; protected String refreshToken = null; diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticatorTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticatorTest.java index 9a6e8812679c..d1c1889ba999 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticatorTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/OAuth2UserAuthenticatorTest.java @@ -43,11 +43,11 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.doReturn; @RunWith(MockitoJUnitRunner.class) public class OAuth2UserAuthenticatorTest { diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmdTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmdTest.java index be8670c1af96..cb99fde24103 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmdTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/DeleteOAuthProviderCmdTest.java @@ -24,13 +24,14 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.oauth2.OAuth2AuthManager; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class DeleteOAuthProviderCmdTest { @@ -41,9 +42,16 @@ public class DeleteOAuthProviderCmdTest { @InjectMocks private DeleteOAuthProviderCmd cmd; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test(expected = ServerApiException.class) diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java index 07df66f20265..ccbb53cfc80d 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java @@ -19,6 +19,7 @@ import com.cloud.api.ApiServer; import org.apache.cloudstack.api.ApiConstants; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -36,10 +37,18 @@ public class OauthLoginAPIAuthenticatorCmdTest { @InjectMocks private OauthLoginAPIAuthenticatorCmd cmd; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } + @Test public void testGetDomainNameWhenDomainNameIsNull() { StringBuilder auditTrailSb = new StringBuilder(); diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/RegisterOAuthProviderCmdTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/RegisterOAuthProviderCmdTest.java index 987c7a5d01e8..c61edd4610c3 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/RegisterOAuthProviderCmdTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/RegisterOAuthProviderCmdTest.java @@ -28,13 +28,14 @@ import org.apache.cloudstack.oauth2.OAuth2AuthManager; import org.apache.cloudstack.oauth2.api.response.OauthProviderResponse; import org.apache.cloudstack.oauth2.vo.OauthProviderVO; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class RegisterOAuthProviderCmdTest { @@ -45,9 +46,16 @@ public class RegisterOAuthProviderCmdTest { @InjectMocks private RegisterOAuthProviderCmd _cmd; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2ProviderTest.java b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2ProviderTest.java index b8b1abcc4bee..fa8a5a7c03cf 100644 --- a/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2ProviderTest.java +++ b/plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/google/GoogleOAuth2ProviderTest.java @@ -23,6 +23,7 @@ import com.google.api.services.oauth2.model.Userinfo; import org.apache.cloudstack.oauth2.dao.OauthProviderDao; import org.apache.cloudstack.oauth2.vo.OauthProviderVO; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -49,9 +50,16 @@ public class GoogleOAuth2ProviderTest { @InjectMocks private GoogleOAuth2Provider _googleOAuth2Provider; + private AutoCloseable closeable; + @Before public void setUp() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test(expected = CloudAuthenticationException.class) diff --git a/plugins/user-authenticators/pbkdf2/pom.xml b/plugins/user-authenticators/pbkdf2/pom.xml index 2ac27b8aa7ac..f030e38a6a44 100644 --- a/plugins/user-authenticators/pbkdf2/pom.xml +++ b/plugins/user-authenticators/pbkdf2/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/user-authenticators/pbkdf2/src/main/java/org/apache/cloudstack/server/auth/PBKDF2UserAuthenticator.java b/plugins/user-authenticators/pbkdf2/src/main/java/org/apache/cloudstack/server/auth/PBKDF2UserAuthenticator.java index 3c2521f34306..edb7d338db91 100644 --- a/plugins/user-authenticators/pbkdf2/src/main/java/org/apache/cloudstack/server/auth/PBKDF2UserAuthenticator.java +++ b/plugins/user-authenticators/pbkdf2/src/main/java/org/apache/cloudstack/server/auth/PBKDF2UserAuthenticator.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.auth.UserAuthenticator; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.bouncycastle.crypto.PBEParametersGenerator; import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator; import org.bouncycastle.crypto.params.KeyParameter; @@ -41,7 +40,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class PBKDF2UserAuthenticator extends AdapterBase implements UserAuthenticator { - public static final Logger s_logger = Logger.getLogger(PBKDF2UserAuthenticator.class); private static final int s_saltlen = 64; private static final int s_rounds = 100000; private static final int s_keylen = 512; @@ -51,12 +49,12 @@ public class PBKDF2UserAuthenticator extends AdapterBase implements UserAuthenti @Override public Pair authenticate(String username, String password, Long domainId, Map requestParameters) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Retrieving user: " + username); + if (logger.isDebugEnabled()) { + logger.debug("Retrieving user: " + username); } if (StringUtils.isAnyEmpty(username, password)) { - s_logger.debug("Username or Password cannot be empty"); + logger.debug("Username or Password cannot be empty"); return new Pair(false, null); } @@ -65,7 +63,7 @@ public Pair authenticat if (user != null) { isValidUser = true; } else { - s_logger.debug("Unable to find user with " + username + " in domain " + domainId); + logger.debug("Unable to find user with " + username + " in domain " + domainId); } byte[] salt = new byte[0]; @@ -74,7 +72,7 @@ public Pair authenticat if (isValidUser) { String[] storedPassword = user.getPassword().split(":"); if ((storedPassword.length != 3) || (!StringUtils.isNumeric(storedPassword[2]))) { - s_logger.warn("The stored password for " + username + " isn't in the right format for this authenticator"); + logger.warn("The stored password for " + username + " isn't in the right format for this authenticator"); isValidUser = false; } else { // Encoding format = :: @@ -114,7 +112,7 @@ public String encode(String password) } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable to hash password", e); } catch (InvalidKeySpecException e) { - s_logger.error("Exception in EncryptUtil.createKey ", e); + logger.error("Exception in EncryptUtil.createKey ", e); throw new CloudRuntimeException("Unable to hash password", e); } } diff --git a/plugins/user-authenticators/pbkdf2/src/test/java/org/apache/cloudstack/server/auth/PBKD2UserAuthenticatorTest.java b/plugins/user-authenticators/pbkdf2/src/test/java/org/apache/cloudstack/server/auth/PBKD2UserAuthenticatorTest.java index 3440f26c9057..6498608ed98b 100644 --- a/plugins/user-authenticators/pbkdf2/src/test/java/org/apache/cloudstack/server/auth/PBKD2UserAuthenticatorTest.java +++ b/plugins/user-authenticators/pbkdf2/src/test/java/org/apache/cloudstack/server/auth/PBKD2UserAuthenticatorTest.java @@ -24,7 +24,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.security.NoSuchAlgorithmException; diff --git a/plugins/user-authenticators/plain-text/pom.xml b/plugins/user-authenticators/plain-text/pom.xml index ea4097b96c11..e378ec8399b1 100644 --- a/plugins/user-authenticators/plain-text/pom.xml +++ b/plugins/user-authenticators/plain-text/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/user-authenticators/plain-text/src/main/java/org/apache/cloudstack/auth/PlainTextUserAuthenticator.java b/plugins/user-authenticators/plain-text/src/main/java/org/apache/cloudstack/auth/PlainTextUserAuthenticator.java index f38e88b76dbd..4e3d402222e7 100644 --- a/plugins/user-authenticators/plain-text/src/main/java/org/apache/cloudstack/auth/PlainTextUserAuthenticator.java +++ b/plugins/user-authenticators/plain-text/src/main/java/org/apache/cloudstack/auth/PlainTextUserAuthenticator.java @@ -20,7 +20,6 @@ import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.user.UserAccount; import com.cloud.user.dao.UserAccountDao; @@ -28,30 +27,29 @@ import com.cloud.utils.component.AdapterBase; public class PlainTextUserAuthenticator extends AdapterBase implements UserAuthenticator { - public static final Logger s_logger = Logger.getLogger(PlainTextUserAuthenticator.class); @Inject private UserAccountDao _userAccountDao; @Override public Pair authenticate(String username, String password, Long domainId, Map requestParameters) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Retrieving user: " + username); + if (logger.isDebugEnabled()) { + logger.debug("Retrieving user: " + username); } if (StringUtils.isAnyEmpty(username, password)) { - s_logger.debug("Username or Password cannot be empty"); + logger.debug("Username or Password cannot be empty"); return new Pair<>(false, null); } UserAccount user = _userAccountDao.getUserAccount(username, domainId); if (user == null) { - s_logger.debug("Unable to find user with " + username + " in domain " + domainId); + logger.debug("Unable to find user with " + username + " in domain " + domainId); return new Pair<>(false, null); } if (!user.getPassword().equals(password)) { - s_logger.debug("Password does not match"); + logger.debug("Password does not match"); return new Pair<>(false, ActionOnFailedAuthentication.INCREMENT_INCORRECT_LOGIN_ATTEMPT_COUNT); } return new Pair<>(true, null); diff --git a/plugins/user-authenticators/plain-text/src/main/resources/META-INF/cloudstack/plaintext/spring-plaintext-context.xml b/plugins/user-authenticators/plain-text/src/main/resources/META-INF/cloudstack/plaintext/spring-plaintext-context.xml index fccff88c4cb6..0b22b010e191 100644 --- a/plugins/user-authenticators/plain-text/src/main/resources/META-INF/cloudstack/plaintext/spring-plaintext-context.xml +++ b/plugins/user-authenticators/plain-text/src/main/resources/META-INF/cloudstack/plaintext/spring-plaintext-context.xml @@ -31,5 +31,5 @@
      - + diff --git a/plugins/user-authenticators/saml2/pom.xml b/plugins/user-authenticators/saml2/pom.xml index 7da7218d9f0b..7a19768fab74 100644 --- a/plugins/user-authenticators/saml2/pom.xml +++ b/plugins/user-authenticators/saml2/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/AuthorizeSAMLSSOCmd.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/AuthorizeSAMLSSOCmd.java index 9a7dadcdb8a9..c5f48d61c6fb 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/AuthorizeSAMLSSOCmd.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/AuthorizeSAMLSSOCmd.java @@ -31,13 +31,11 @@ import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.saml.SAML2AuthManager; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = "authorizeSamlSso", description = "Allow or disallow a user to use SAML SSO", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AuthorizeSAMLSSOCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AuthorizeSAMLSSOCmd.class.getName()); @Inject diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java index e462e33cbfeb..50b075b44489 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java @@ -48,7 +48,6 @@ import org.apache.cloudstack.saml.SAML2AuthManager; import org.apache.cloudstack.saml.SAMLProviderMetadata; import org.apache.cloudstack.utils.security.ParserUtils; -import org.apache.log4j.Logger; import org.opensaml.Configuration; import org.opensaml.DefaultBootstrap; import org.opensaml.common.xml.SAMLConstants; @@ -95,7 +94,6 @@ @APICommand(name = "getSPMetadata", description = "Returns SAML2 CloudStack Service Provider MetaData", responseObject = SAMLMetaDataResponse.class, entityType = {}) public class GetServiceProviderMetaDataCmd extends BaseCmd implements APIAuthenticator { - public static final Logger s_logger = Logger.getLogger(GetServiceProviderMetaDataCmd.class.getName()); private static final String s_name = "spmetadataresponse"; @Inject @@ -130,7 +128,7 @@ public String authenticate(String command, Map params, HttpSes try { DefaultBootstrap.bootstrap(); } catch (ConfigurationException | FactoryConfigurationError e) { - s_logger.error("OpenSAML Bootstrapping error: " + e.getMessage()); + logger.error("OpenSAML Bootstrapping error: " + e.getMessage()); throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), "OpenSAML Bootstrapping error while creating SP MetaData", params, responseType)); @@ -167,7 +165,7 @@ public String authenticate(String command, Map params, HttpSes spSSODescriptor.getKeyDescriptors().add(signKeyDescriptor); spSSODescriptor.getKeyDescriptors().add(encKeyDescriptor); } catch (SecurityException e) { - s_logger.warn("Unable to add SP X509 descriptors:" + e.getMessage()); + logger.warn("Unable to add SP X509 descriptors:" + e.getMessage()); } NameIDFormat nameIDFormat = new NameIDFormatBuilder().buildObject(); @@ -281,7 +279,7 @@ public void setAuthenticators(List authenticators) { } } if (_samlAuthManager == null) { - s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 getSPMetadata Cmd"); + logger.error("No suitable Pluggable Authentication Manager found for SAML2 getSPMetadata Cmd"); } } } diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java index 25f056adf686..3e6b093abe13 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java @@ -46,7 +46,6 @@ import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.saml.SAML2AuthManager; import org.apache.cloudstack.saml.SAMLUtils; -import org.apache.log4j.Logger; import com.cloud.api.response.ApiResponseSerializer; import com.cloud.domain.Domain; @@ -62,7 +61,6 @@ @APICommand(name = "listAndSwitchSamlAccount", description = "Lists and switches to other SAML accounts owned by the SAML user", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAndSwitchSAMLAccountCmd extends BaseCmd implements APIAuthenticator { - public static final Logger s_logger = Logger.getLogger(ListAndSwitchSAMLAccountCmd.class.getName()); @Inject ApiServerService _apiServer; @@ -155,7 +153,7 @@ public String authenticate(final String command, final Map par return ApiResponseSerializer.toSerializedString(loginResponse, responseType); } } catch (CloudAuthenticationException | IOException exception) { - s_logger.debug("Failed to switch to request SAML user account due to: " + exception.getMessage()); + logger.debug("Failed to switch to request SAML user account due to: " + exception.getMessage()); } } else { List switchableAccounts = _userAccountDao.getAllUsersByNameAndEntity(currentUserAccount.getUsername(), currentUserAccount.getExternalEntity()); @@ -198,7 +196,7 @@ public void setAuthenticators(List authenticators) { } } if (_samlAuthManager == null) { - s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 listAndSwitchSamlAccount Cmd"); + logger.error("No suitable Pluggable Authentication Manager found for SAML2 listAndSwitchSamlAccount Cmd"); } } diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListIdpsCmd.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListIdpsCmd.java index b61eae4382a9..09e5f1b6557e 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListIdpsCmd.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListIdpsCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.saml.SAML2AuthManager; import org.apache.cloudstack.saml.SAMLProviderMetadata; -import org.apache.log4j.Logger; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; @@ -43,7 +42,6 @@ @APICommand(name = "listIdps", description = "Returns list of discovered SAML Identity Providers", responseObject = IdpResponse.class, entityType = {}) public class ListIdpsCmd extends BaseCmd implements APIAuthenticator { - public static final Logger s_logger = Logger.getLogger(ListIdpsCmd.class.getName()); @Inject ApiServerService _apiServer; @@ -102,7 +100,7 @@ public void setAuthenticators(List authenticators) { } } if (_samlAuthManager == null) { - s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 Login Cmd"); + logger.error("No suitable Pluggable Authentication Manager found for SAML2 Login Cmd"); } } } diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListSamlAuthorizationCmd.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListSamlAuthorizationCmd.java index db08ae0cce85..d400fadf2616 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListSamlAuthorizationCmd.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/ListSamlAuthorizationCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.SamlAuthorizationResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -37,7 +36,6 @@ @APICommand(name = "listSamlAuthorization", description = "Lists authorized users who can used SAML SSO", responseObject = SamlAuthorizationResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSamlAuthorizationCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSamlAuthorizationCmd.class.getName()); private static final String s_name = "listsamlauthorizationsresponse"; @Inject diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java index 332e06027844..742680fdcc55 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java @@ -47,7 +47,6 @@ import org.apache.cloudstack.saml.SAMLTokenVO; import org.apache.cloudstack.saml.SAMLUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.opensaml.DefaultBootstrap; import org.opensaml.saml2.core.Assertion; import org.opensaml.saml2.core.EncryptedAssertion; @@ -81,7 +80,6 @@ @APICommand(name = "samlSso", description = "SP initiated SAML Single Sign On", requestHasSensitiveInfo = true, responseObject = LoginCmdResponse.class, entityType = {}) public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthenticator, Configurable { - public static final Logger s_logger = Logger.getLogger(SAML2LoginAPIAuthenticatorCmd.class.getName()); private static final String s_name = "loginresponse"; ///////////////////////////////////////////////////// @@ -139,14 +137,14 @@ public Response processSAMLResponse(String responseMessage) { responseObject = SAMLUtils.decodeSAMLResponse(responseMessage); } catch (ConfigurationException | FactoryConfigurationError | ParserConfigurationException | SAXException | IOException | UnmarshallingException e) { - s_logger.error("SAMLResponse processing error: " + e.getMessage()); + logger.error("SAMLResponse processing error: " + e.getMessage()); } return responseObject; } protected void checkAndFailOnMissingSAMLSignature(Signature signature) { if (signature == null && SAML2AuthManager.SAMLCheckSignature.value()) { - s_logger.error("Failing SAML login due to missing signature in the SAML response and signature check is enforced. " + + logger.error("Failing SAML login due to missing signature in the SAML response and signature check is enforced. " + "Please check and ensure the IDP configuration has signing certificate or relax the saml2.check.signature setting."); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Signature is missing from the SAML Response. Please contact the Administrator"); } @@ -191,7 +189,7 @@ public String authenticate(final String command, final Map par } String authnId = SAMLUtils.generateSecureRandomId(); samlAuthManager.saveToken(authnId, domainPath, idpMetadata.getEntityId()); - s_logger.debug("Sending SAMLRequest id=" + authnId); + logger.debug("Sending SAMLRequest id=" + authnId); String redirectUrl = SAMLUtils.buildAuthnRequestUrl(authnId, spMetadata, idpMetadata, SAML2AuthManager.SAMLSignatureAlgorithm.value()); resp.sendRedirect(redirectUrl); return ""; @@ -215,7 +213,7 @@ public String authenticate(final String command, final Map par SAMLProviderMetadata idpMetadata = samlAuthManager.getIdPMetadata(issuer.getValue()); String responseToId = processedSAMLResponse.getInResponseTo(); - s_logger.debug("Received SAMLResponse in response to id=" + responseToId); + logger.debug("Received SAMLResponse in response to id=" + responseToId); SAMLTokenVO token = samlAuthManager.getToken(responseToId); if (token != null) { if (!(token.getEntity().equalsIgnoreCase(issuer.getValue()))) { @@ -242,7 +240,7 @@ public String authenticate(final String command, final Map par try { validator.validate(sig); } catch (ValidationException e) { - s_logger.error("SAML Response's signature failed to be validated by IDP signing key:" + e.getMessage()); + logger.error("SAML Response's signature failed to be validated by IDP signing key:" + e.getMessage()); throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), "SAML Response's signature failed to be validated by IDP signing key", params, responseType)); @@ -275,7 +273,7 @@ public String authenticate(final String command, final Map par try { assertion = decrypter.decrypt(encryptedAssertion); } catch (DecryptionException e) { - s_logger.warn("SAML EncryptedAssertion error: " + e.toString()); + logger.warn("SAML EncryptedAssertion error: " + e.toString()); } if (assertion == null) { continue; @@ -289,7 +287,7 @@ public String authenticate(final String command, final Map par try { validator.validate(encSig); } catch (ValidationException e) { - s_logger.error("SAML Response's signature failed to be validated by IDP signing key:" + e.getMessage()); + logger.error("SAML Response's signature failed to be validated by IDP signing key:" + e.getMessage()); throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), "SAML Response's signature failed to be validated by IDP signing key", params, responseType)); @@ -334,7 +332,7 @@ public String authenticate(final String command, final Map par return ApiResponseSerializer.toSerializedString(loginResponse, responseType); } } catch (CloudAuthenticationException | IOException exception) { - s_logger.debug("SAML Login failed to log in the user due to: " + exception.getMessage()); + logger.debug("SAML Login failed to log in the user due to: " + exception.getMessage()); } } } catch (IOException e) { @@ -377,7 +375,7 @@ public void setAuthenticators(List authenticators) { } } if (samlAuthManager == null) { - s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 Login Cmd"); + logger.error("No suitable Pluggable Authentication Manager found for SAML2 Login Cmd"); } } diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmd.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmd.java index ccdc4b6bd5d8..ca46bef4b5a3 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmd.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.saml.SAMLPluginConstants; import org.apache.cloudstack.saml.SAMLProviderMetadata; import org.apache.cloudstack.saml.SAMLUtils; -import org.apache.log4j.Logger; import org.opensaml.DefaultBootstrap; import org.opensaml.saml2.core.LogoutRequest; import org.opensaml.saml2.core.Response; @@ -54,7 +53,6 @@ @APICommand(name = "samlSlo", description = "SAML Global Log Out API", responseObject = LogoutCmdResponse.class, entityType = {}) public class SAML2LogoutAPIAuthenticatorCmd extends BaseCmd implements APIAuthenticator { - public static final Logger s_logger = Logger.getLogger(SAML2LogoutAPIAuthenticatorCmd.class.getName()); private static final String s_name = "logoutresponse"; @Inject @@ -94,7 +92,7 @@ public String authenticate(String command, Map params, HttpSes try { resp.sendRedirect(SAML2AuthManager.SAMLCloudStackRedirectionUrl.value()); } catch (IOException ignored) { - s_logger.info("[ignored] sending redirected failed.", ignored); + logger.info("[ignored] sending redirected failed.", ignored); } return responseString; } @@ -102,7 +100,7 @@ public String authenticate(String command, Map params, HttpSes try { DefaultBootstrap.bootstrap(); } catch (ConfigurationException | FactoryConfigurationError e) { - s_logger.error("OpenSAML Bootstrapping error: " + e.getMessage()); + logger.error("OpenSAML Bootstrapping error: " + e.getMessage()); throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), "OpenSAML Bootstrapping error while creating SP MetaData", params, responseType)); @@ -119,12 +117,12 @@ public String authenticate(String command, Map params, HttpSes params, responseType)); } } catch (ConfigurationException | FactoryConfigurationError | ParserConfigurationException | SAXException | IOException | UnmarshallingException e) { - s_logger.error("SAMLResponse processing error: " + e.getMessage()); + logger.error("SAMLResponse processing error: " + e.getMessage()); } try { resp.sendRedirect(SAML2AuthManager.SAMLCloudStackRedirectionUrl.value()); } catch (IOException ignored) { - s_logger.info("[ignored] second redirected sending failed.", ignored); + logger.info("[ignored] second redirected sending failed.", ignored); } return responseString; } @@ -136,7 +134,7 @@ public String authenticate(String command, Map params, HttpSes try { resp.sendRedirect(SAML2AuthManager.SAMLCloudStackRedirectionUrl.value()); } catch (IOException ignored) { - s_logger.info("[ignored] final redirected failed.", ignored); + logger.info("[ignored] final redirected failed.", ignored); } return responseString; } @@ -146,7 +144,7 @@ public String authenticate(String command, Map params, HttpSes String redirectUrl = idpMetadata.getSloUrl() + "?SAMLRequest=" + SAMLUtils.encodeSAMLRequest(logoutRequest); resp.sendRedirect(redirectUrl); } catch (MarshallingException | IOException e) { - s_logger.error("SAML SLO error: " + e.getMessage()); + logger.error("SAML SLO error: " + e.getMessage()); throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), "SAML Single Logout Error", params, responseType)); @@ -167,7 +165,7 @@ public void setAuthenticators(List authenticators) { } } if (_samlAuthManager == null) { - s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 Login Cmd"); + logger.error("No suitable Pluggable Authentication Manager found for SAML2 Login Cmd"); } } } diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java index dfa76414fb74..230c53ac4a9e 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java @@ -57,7 +57,6 @@ import org.apache.cloudstack.utils.security.CertUtils; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.HttpClient; -import org.apache.log4j.Logger; import org.bouncycastle.operator.OperatorCreationException; import org.opensaml.DefaultBootstrap; import org.opensaml.common.xml.SAMLConstants; @@ -92,7 +91,6 @@ @Component public class SAML2AuthManagerImpl extends AdapterBase implements SAML2AuthManager, Configurable { - private static final Logger s_logger = Logger.getLogger(SAML2AuthManagerImpl.class); private SAMLProviderMetadata _spMetadata = new SAMLProviderMetadata(); private Map _idpMetadataMap = new HashMap(); @@ -123,10 +121,10 @@ public String getSAMLIdentityProviderMetadataURL(){ @Override public boolean start() { if (isSAMLPluginEnabled()) { - s_logger.info("SAML auth plugin loaded"); + logger.info("SAML auth plugin loaded"); return setup(); } else { - s_logger.info("SAML auth plugin not enabled so not loading"); + logger.info("SAML auth plugin not enabled so not loading"); return super.start(); } } @@ -148,9 +146,9 @@ protected boolean initSP() { SAMLUtils.encodePrivateKey(keyPair.getPrivate()), SAMLUtils.encodePublicKey(keyPair.getPublic()), "samlsp-keypair"); keyStoreVO = _ksDao.findByName(SAMLPluginConstants.SAMLSP_KEYPAIR); - s_logger.info("No SAML keystore found, created and saved a new Service Provider keypair"); + logger.info("No SAML keystore found, created and saved a new Service Provider keypair"); } catch (final NoSuchProviderException | NoSuchAlgorithmException e) { - s_logger.error("Unable to create and save SAML keypair, due to: ", e); + logger.error("Unable to create and save SAML keypair, due to: ", e); } } @@ -179,7 +177,7 @@ protected boolean initSP() { _ksDao.save(SAMLPluginConstants.SAMLSP_X509CERT, Base64.encodeBase64String(bos.toByteArray()), "", "samlsp-x509cert"); bos.close(); } catch (final NoSuchAlgorithmException | NoSuchProviderException | CertificateException | SignatureException | InvalidKeyException | IOException | OperatorCreationException e) { - s_logger.error("SAML plugin won't be able to use X509 signed authentication", e); + logger.error("SAML plugin won't be able to use X509 signed authentication", e); } } else { try { @@ -188,7 +186,7 @@ protected boolean initSP() { spX509Key = (X509Certificate) si.readObject(); bi.close(); } catch (IOException | ClassNotFoundException ignored) { - s_logger.error("SAML Plugin won't be able to use X509 signed authentication. Failed to load X509 Certificate from Database."); + logger.error("SAML Plugin won't be able to use X509 signed authentication. Failed to load X509 Certificate from Database."); } } } @@ -215,7 +213,7 @@ protected boolean initSP() { private void addIdpToMap(EntityDescriptor descriptor, Map idpMap) { SAMLProviderMetadata idpMetadata = new SAMLProviderMetadata(); idpMetadata.setEntityId(descriptor.getEntityID()); - s_logger.debug("Adding IdP to the list of discovered IdPs: " + descriptor.getEntityID()); + logger.debug("Adding IdP to the list of discovered IdPs: " + descriptor.getEntityID()); if (descriptor.getOrganization() != null) { if (descriptor.getOrganization().getDisplayNames() != null) { for (OrganizationDisplayName orgName : descriptor.getOrganization().getDisplayNames()) { @@ -289,21 +287,21 @@ private void addIdpToMap(EntityDescriptor descriptor, Map metadataMap = new HashMap(); try { discoverAndAddIdp(_idpMetaDataProvider.getMetadata(), metadataMap); _idpMetadataMap = metadataMap; expireTokens(); - s_logger.debug("Finished refreshing SAML Metadata and expiring old auth tokens"); + logger.debug("Finished refreshing SAML Metadata and expiring old auth tokens"); } catch (MetadataProviderException e) { - s_logger.warn("SAML Metadata Refresh task failed with exception: " + e.getMessage()); + logger.warn("SAML Metadata Refresh task failed with exception: " + e.getMessage()); } } @@ -363,7 +361,7 @@ public void run() { private boolean setup() { if (!initSP()) { - s_logger.error("SAML Plugin failed to initialize, please fix the configuration and restart management server"); + logger.error("SAML Plugin failed to initialize, please fix the configuration and restart management server"); return false; } _timer = new Timer(); @@ -379,11 +377,11 @@ private boolean setup() { } else { File metadataFile = PropertiesUtil.findConfigFile(idpMetaDataUrl); if (metadataFile == null) { - s_logger.error("Provided Metadata is not a URL, Unable to locate metadata file from local path: " + idpMetaDataUrl); + logger.error("Provided Metadata is not a URL, Unable to locate metadata file from local path: " + idpMetaDataUrl); return false; } else{ - s_logger.debug("Provided Metadata is not a URL, trying to read metadata file from local path: " + metadataFile.getAbsolutePath()); + logger.debug("Provided Metadata is not a URL, trying to read metadata file from local path: " + metadataFile.getAbsolutePath()); _idpMetaDataProvider = new FilesystemMetadataProvider(_timer, metadataFile); } } @@ -393,14 +391,14 @@ private boolean setup() { _timer.scheduleAtFixedRate(new MetadataRefreshTask(), 0, _refreshInterval * 1000); } catch (MetadataProviderException e) { - s_logger.error("Unable to read SAML2 IDP MetaData URL, error:" + e.getMessage()); - s_logger.error("SAML2 Authentication may be unavailable"); + logger.error("Unable to read SAML2 IDP MetaData URL, error:" + e.getMessage()); + logger.error("SAML2 Authentication may be unavailable"); return false; } catch (ConfigurationException | FactoryConfigurationError e) { - s_logger.error("OpenSAML bootstrapping failed: error: " + e.getMessage()); + logger.error("OpenSAML bootstrapping failed: error: " + e.getMessage()); return false; } catch (NullPointerException e) { - s_logger.error("Unable to setup SAML Auth Plugin due to NullPointerException" + + logger.error("Unable to setup SAML Auth Plugin due to NullPointerException" + " please check the SAML global settings: " + e.getMessage()); return false; } @@ -478,7 +476,7 @@ public void saveToken(String authnId, String domainPath, String entity) { if (_samlTokenDao.findByUuid(authnId) == null) { _samlTokenDao.persist(token); } else { - s_logger.warn("Duplicate SAML token for entity=" + entity + " token id=" + authnId + " domain=" + domainPath); + logger.warn("Duplicate SAML token for entity=" + entity + " token id=" + authnId + " domain=" + domainPath); } } diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2UserAuthenticator.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2UserAuthenticator.java index 0a33bc111d56..6f9854ad17d2 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2UserAuthenticator.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAML2UserAuthenticator.java @@ -20,7 +20,6 @@ import org.apache.cloudstack.auth.UserAuthenticator; import org.apache.cxf.common.util.StringUtils; -import org.apache.log4j.Logger; import com.cloud.user.User; import com.cloud.user.UserAccount; @@ -30,7 +29,6 @@ import com.cloud.utils.component.AdapterBase; public class SAML2UserAuthenticator extends AdapterBase implements UserAuthenticator { - public static final Logger s_logger = Logger.getLogger(SAML2UserAuthenticator.class); @Inject private UserAccountDao _userAccountDao; @@ -39,18 +37,18 @@ public class SAML2UserAuthenticator extends AdapterBase implements UserAuthentic @Override public Pair authenticate(String username, String password, Long domainId, Map requestParameters) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Trying SAML2 auth for user: " + username); + if (logger.isDebugEnabled()) { + logger.debug("Trying SAML2 auth for user: " + username); } if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { - s_logger.debug("Username or Password cannot be empty"); + logger.debug("Username or Password cannot be empty"); return new Pair(false, null); } final UserAccount userAccount = _userAccountDao.getUserAccount(username, domainId); if (userAccount == null || userAccount.getSource() != User.Source.SAML2) { - s_logger.debug("Unable to find user with " + username + " in domain " + domainId + ", or user source is not SAML2"); + logger.debug("Unable to find user with " + username + " in domain " + domainId + ", or user source is not SAML2"); return new Pair(false, null); } else { User user = _userDao.getUser(userAccount.getId()); diff --git a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAMLUtils.java b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAMLUtils.java index f10bc891368e..7ffe07a8609f 100644 --- a/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAMLUtils.java +++ b/plugins/user-authenticators/saml2/src/main/java/org/apache/cloudstack/saml/SAMLUtils.java @@ -61,7 +61,8 @@ import org.apache.cloudstack.utils.security.CertUtils; import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bouncycastle.operator.OperatorCreationException; import org.joda.time.DateTime; import org.opensaml.Configuration; @@ -104,7 +105,7 @@ import com.cloud.utils.HttpUtils; public class SAMLUtils { - public static final Logger s_logger = Logger.getLogger(SAMLUtils.class); + protected static Logger LOGGER = LogManager.getLogger(SAMLUtils.class); static final String charset = "abcdefghijklmnopqrstuvwxyz"; @@ -124,7 +125,7 @@ public static String getValueFromAttributeStatements(final List 0) { String value = attribute.getAttributeValues().get(0).getDOM().getTextContent(); - s_logger.debug("SAML attribute name: " + attribute.getName() + " friendly-name:" + attribute.getFriendlyName() + " value:" + value); + LOGGER.debug("SAML attribute name: " + attribute.getName() + " friendly-name:" + attribute.getFriendlyName() + " value:" + value); if (attributeKey.equals(attribute.getName()) || attributeKey.equals(attribute.getFriendlyName())) { return value; } @@ -159,7 +160,7 @@ public static String buildAuthnRequestUrl(final String authnId, final SAMLProvid String appendOperator = idpMetadata.getSsoUrl().contains("?") ? "&" : "?"; redirectUrl = idpMetadata.getSsoUrl() + appendOperator + SAMLUtils.generateSAMLRequestSignature("SAMLRequest=" + SAMLUtils.encodeSAMLRequest(authnRequest), privateKey, signatureAlgorithm); } catch (ConfigurationException | FactoryConfigurationError | MarshallingException | IOException | NoSuchAlgorithmException | InvalidKeyException | java.security.SignatureException e) { - s_logger.error("SAML AuthnRequest message building error: " + e.getMessage()); + LOGGER.error("SAML AuthnRequest message building error: " + e.getMessage()); } return redirectUrl; } @@ -311,7 +312,7 @@ public static String encodePublicKey(PublicKey key) { X509EncodedKeySpec spec = keyFactory.getKeySpec(key, X509EncodedKeySpec.class); return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8")); } catch (InvalidKeySpecException e) { - s_logger.error("Unable to get KeyFactory:" + e.getMessage()); + LOGGER.error("Unable to get KeyFactory:" + e.getMessage()); } return null; } @@ -329,7 +330,7 @@ public static String encodePrivateKey(PrivateKey key) { PKCS8EncodedKeySpec.class); return new String(org.bouncycastle.util.encoders.Base64.encode(spec.getEncoded()), Charset.forName("UTF-8")); } catch (InvalidKeySpecException e) { - s_logger.error("Unable to get KeyFactory:" + e.getMessage()); + LOGGER.error("Unable to get KeyFactory:" + e.getMessage()); } return null; } @@ -348,7 +349,7 @@ public static PublicKey decodePublicKey(String publicKey) { try { return keyFactory.generatePublic(x509KeySpec); } catch (InvalidKeySpecException e) { - s_logger.error("Unable to create PublicKey from PublicKey string:" + e.getMessage()); + LOGGER.error("Unable to create PublicKey from PublicKey string:" + e.getMessage()); } return null; } @@ -367,7 +368,7 @@ public static PrivateKey decodePrivateKey(String privateKey) { try { return keyFactory.generatePrivate(pkscs8KeySpec); } catch (InvalidKeySpecException e) { - s_logger.error("Unable to create PrivateKey from privateKey string:" + e.getMessage()); + LOGGER.error("Unable to create PrivateKey from privateKey string:" + e.getMessage()); } return null; } diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/GetServiceProviderMetaDataCmdTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/GetServiceProviderMetaDataCmdTest.java index 3df0fccadfad..2cddb126b1b7 100644 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/GetServiceProviderMetaDataCmdTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/GetServiceProviderMetaDataCmdTest.java @@ -40,7 +40,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.HttpUtils; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAML2AuthManagerImplTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAML2AuthManagerImplTest.java index 94bf3f066960..81594db1009f 100644 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAML2AuthManagerImplTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/SAML2AuthManagerImplTest.java @@ -30,7 +30,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.DomainManager; import com.cloud.user.User; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmdTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmdTest.java index b4d230e3cd60..9342a0c7f09d 100644 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmdTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmdTest.java @@ -44,7 +44,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmdTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmdTest.java index 09391c5d7d21..2060d0baf311 100644 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmdTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/api/command/SAML2LogoutAPIAuthenticatorCmdTest.java @@ -37,7 +37,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.HttpUtils; diff --git a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/saml/SAML2AuthManagerImplTest.java b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/saml/SAML2AuthManagerImplTest.java index 073face6e2e3..0a2955be04d9 100755 --- a/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/saml/SAML2AuthManagerImplTest.java +++ b/plugins/user-authenticators/saml2/src/test/java/org/apache/cloudstack/saml/SAML2AuthManagerImplTest.java @@ -25,7 +25,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.doReturn; diff --git a/plugins/user-authenticators/sha256salted/pom.xml b/plugins/user-authenticators/sha256salted/pom.xml index f193c9c796c8..823ab5105686 100644 --- a/plugins/user-authenticators/sha256salted/pom.xml +++ b/plugins/user-authenticators/sha256salted/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/user-authenticators/sha256salted/src/main/java/org/apache/cloudstack/auth/SHA256SaltedUserAuthenticator.java b/plugins/user-authenticators/sha256salted/src/main/java/org/apache/cloudstack/auth/SHA256SaltedUserAuthenticator.java index c6bdbe672fa0..0dbdf26f438e 100644 --- a/plugins/user-authenticators/sha256salted/src/main/java/org/apache/cloudstack/auth/SHA256SaltedUserAuthenticator.java +++ b/plugins/user-authenticators/sha256salted/src/main/java/org/apache/cloudstack/auth/SHA256SaltedUserAuthenticator.java @@ -25,7 +25,6 @@ import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.bouncycastle.util.encoders.Base64; import com.cloud.user.UserAccount; @@ -35,7 +34,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class SHA256SaltedUserAuthenticator extends AdapterBase implements UserAuthenticator { - public static final Logger s_logger = Logger.getLogger(SHA256SaltedUserAuthenticator.class); private static final String s_defaultPassword = "000000000000000000000000000="; private static final String s_defaultSalt = "0000000000000000000000000000000="; @Inject @@ -47,19 +45,19 @@ public class SHA256SaltedUserAuthenticator extends AdapterBase implements UserAu */ @Override public Pair authenticate(String username, String password, Long domainId, Map requestParameters) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Retrieving user: " + username); + if (logger.isDebugEnabled()) { + logger.debug("Retrieving user: " + username); } if (StringUtils.isAnyEmpty(username, password)) { - s_logger.debug("Username or Password cannot be empty"); + logger.debug("Username or Password cannot be empty"); return new Pair<>(false, null); } boolean realUser = true; UserAccount user = _userAccountDao.getUserAccount(username, domainId); if (user == null) { - s_logger.debug("Unable to find user with " + username + " in domain " + domainId); + logger.debug("Unable to find user with " + username + " in domain " + domainId); realUser = false; } /* Fake Data */ @@ -68,7 +66,7 @@ public Pair authenticate(String username, if (realUser) { String[] storedPassword = user.getPassword().split(":"); if (storedPassword.length != 2) { - s_logger.warn("The stored password for " + username + " isn't in the right format for this authenticator"); + logger.warn("The stored password for " + username + " isn't in the right format for this authenticator"); realUser = false; } else { realPassword = storedPassword[1]; diff --git a/plugins/user-authenticators/sha256salted/src/main/resources/META-INF/cloudstack/sha256salted/spring-sha256salted-context.xml b/plugins/user-authenticators/sha256salted/src/main/resources/META-INF/cloudstack/sha256salted/spring-sha256salted-context.xml index 3e29fd9ddba7..593c8282cb5b 100644 --- a/plugins/user-authenticators/sha256salted/src/main/resources/META-INF/cloudstack/sha256salted/spring-sha256salted-context.xml +++ b/plugins/user-authenticators/sha256salted/src/main/resources/META-INF/cloudstack/sha256salted/spring-sha256salted-context.xml @@ -30,5 +30,5 @@ - + diff --git a/plugins/user-authenticators/sha256salted/src/test/java/org/apache/cloudstack/auth/test/AuthenticatorTest.java b/plugins/user-authenticators/sha256salted/src/test/java/org/apache/cloudstack/auth/test/AuthenticatorTest.java index 7a3af9d19d40..5f7d91058565 100644 --- a/plugins/user-authenticators/sha256salted/src/test/java/org/apache/cloudstack/auth/test/AuthenticatorTest.java +++ b/plugins/user-authenticators/sha256salted/src/test/java/org/apache/cloudstack/auth/test/AuthenticatorTest.java @@ -36,7 +36,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.UserAccount; import com.cloud.user.dao.UserAccountDao; diff --git a/plugins/user-two-factor-authenticators/static-pin/pom.xml b/plugins/user-two-factor-authenticators/static-pin/pom.xml index 482a2ff396fd..bde07b6c185d 100644 --- a/plugins/user-two-factor-authenticators/static-pin/pom.xml +++ b/plugins/user-two-factor-authenticators/static-pin/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/user-two-factor-authenticators/static-pin/src/main/java/org/apache/cloudstack/auth/StaticPinUserTwoFactorAuthenticator.java b/plugins/user-two-factor-authenticators/static-pin/src/main/java/org/apache/cloudstack/auth/StaticPinUserTwoFactorAuthenticator.java index dd1b1580c351..b781f3265209 100644 --- a/plugins/user-two-factor-authenticators/static-pin/src/main/java/org/apache/cloudstack/auth/StaticPinUserTwoFactorAuthenticator.java +++ b/plugins/user-two-factor-authenticators/static-pin/src/main/java/org/apache/cloudstack/auth/StaticPinUserTwoFactorAuthenticator.java @@ -21,7 +21,6 @@ import com.cloud.user.UserAccount; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.user.dao.UserAccountDao; import com.cloud.utils.component.AdapterBase; @@ -29,7 +28,6 @@ import java.security.SecureRandom; public class StaticPinUserTwoFactorAuthenticator extends AdapterBase implements UserTwoFactorAuthenticator { - public static final Logger s_logger = Logger.getLogger(StaticPinUserTwoFactorAuthenticator.class); @Inject private UserAccountDao _userAccountDao; @@ -48,7 +46,7 @@ public String getDescription() { public void check2FA(String code, UserAccount userAccount) throws CloudTwoFactorAuthenticationException { String expectedCode = getStaticPin(userAccount); if (expectedCode.equals(code)) { - s_logger.info("2FA matches user's input"); + logger.info("2FA matches user's input"); return; } throw new CloudTwoFactorAuthenticationException("two-factor authentication code provided is invalid"); diff --git a/plugins/user-two-factor-authenticators/static-pin/src/main/resources/META-INF/cloudstack/staticpin/spring-staticpin-context.xml b/plugins/user-two-factor-authenticators/static-pin/src/main/resources/META-INF/cloudstack/staticpin/spring-staticpin-context.xml index ac27ba527db6..6b30a98ef07a 100644 --- a/plugins/user-two-factor-authenticators/static-pin/src/main/resources/META-INF/cloudstack/staticpin/spring-staticpin-context.xml +++ b/plugins/user-two-factor-authenticators/static-pin/src/main/resources/META-INF/cloudstack/staticpin/spring-staticpin-context.xml @@ -31,5 +31,5 @@
      - + diff --git a/plugins/user-two-factor-authenticators/totp/pom.xml b/plugins/user-two-factor-authenticators/totp/pom.xml index 5059df75dae3..cda383362919 100644 --- a/plugins/user-two-factor-authenticators/totp/pom.xml +++ b/plugins/user-two-factor-authenticators/totp/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/user-two-factor-authenticators/totp/src/main/java/org/apache/cloudstack/auth/TotpUserTwoFactorAuthenticator.java b/plugins/user-two-factor-authenticators/totp/src/main/java/org/apache/cloudstack/auth/TotpUserTwoFactorAuthenticator.java index bb6939ad14f4..c7c4997f1894 100644 --- a/plugins/user-two-factor-authenticators/totp/src/main/java/org/apache/cloudstack/auth/TotpUserTwoFactorAuthenticator.java +++ b/plugins/user-two-factor-authenticators/totp/src/main/java/org/apache/cloudstack/auth/TotpUserTwoFactorAuthenticator.java @@ -26,7 +26,6 @@ import org.apache.commons.codec.binary.Base32; import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.user.dao.UserAccountDao; import com.cloud.utils.component.AdapterBase; @@ -34,7 +33,6 @@ import java.security.SecureRandom; public class TotpUserTwoFactorAuthenticator extends AdapterBase implements UserTwoFactorAuthenticator { - public static final Logger s_logger = Logger.getLogger(TotpUserTwoFactorAuthenticator.class); @Inject private UserAccountDao _userAccountDao; @@ -53,7 +51,7 @@ public String getDescription() { public void check2FA(String code, UserAccount userAccount) throws CloudTwoFactorAuthenticationException { String expectedCode = get2FACode(get2FAKey(userAccount)); if (expectedCode.equals(code)) { - s_logger.info("2FA matches user's input"); + logger.info("2FA matches user's input"); return; } throw new CloudTwoFactorAuthenticationException("two-factor authentication code provided is invalid"); diff --git a/plugins/user-two-factor-authenticators/totp/src/main/resources/META-INF/cloudstack/totp/spring-google-context.xml b/plugins/user-two-factor-authenticators/totp/src/main/resources/META-INF/cloudstack/totp/spring-google-context.xml index 84a0b0cfcb7c..73ab7b636d44 100644 --- a/plugins/user-two-factor-authenticators/totp/src/main/resources/META-INF/cloudstack/totp/spring-google-context.xml +++ b/plugins/user-two-factor-authenticators/totp/src/main/resources/META-INF/cloudstack/totp/spring-google-context.xml @@ -31,5 +31,5 @@
      - + diff --git a/pom.xml b/pom.xml index da0252acbb4e..29fc939f5535 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT pom Apache CloudStack Apache CloudStack is an IaaS ("Infrastructure as a Service") cloud orchestration platform. @@ -50,7 +50,7 @@ UTF-8 UTF-8 https://download.cloudstack.org/systemvm - 4.19.1.0 + 4.20.0.0 apache https://sonarcloud.io @@ -58,7 +58,7 @@ 11 target build/replace.properties - -Djava.security.egd=file:/dev/./urandom -noverify + -Djava.security.egd=file:/dev/./urandom -noverify --add-opens=java.base/java.lang=ALL-UNNAMED --add-exports=java.base/sun.security.x509=ALL-UNNAMED --add-opens=java.base/javax.net.ssl=ALL-UNNAMED 1.8 @@ -79,17 +79,18 @@ 3.8.2 2.22.2 4.4.1 + 3.2.0 + 2.19.0 1.2.25 1.2.17 - 1.1.1 1.15 1.5.0 4.4 - 1.21 + 1.26.0 1.3 1.4 3.1 @@ -101,6 +102,7 @@ 1.10 1.3.3 2.9.0 + 5.1.0 0.5 2.6 2.9.0 @@ -114,7 +116,7 @@ 1.13.1 5.9.1 18.0 - 3.12.4 + 4.11.0 1.0-20081010.060147 1.0.1 7.1.0 @@ -137,6 +139,7 @@ 3.2.14 2.6.11 0.0.27 + 3.0.2 1.42.3 2.4.17 1.7.2 @@ -151,7 +154,9 @@ 3.1.1 1.3.2 2.3.0 - 2.3.2-1 + 2.3.9 + 2.3.3 + 2.3.7 2.26 9.4.51.v20230217 9.4.27.v20200227 @@ -164,6 +169,7 @@ 2.7.0 0.5.3 1.5.0-b01 + 0.9.14 8.0.33 2.0.4 10.1 @@ -183,7 +189,7 @@ 1.4.20 5.3.26 0.5.4 - 1.12.0 + 3.1.7 @@ -360,6 +366,7 @@ commons-daemon ${cs.daemon.version} + org.apache.commons commons-dbcp2 @@ -371,6 +378,11 @@ + + com.zaxxer + HikariCP + ${cs.hikaricp.version} + commons-discovery commons-discovery @@ -436,6 +448,27 @@ jstl ${cs.jstl.version} + + org.apache.logging.log4j + log4j-core + ${cs.log4j.version} + + + org.apache.logging.log4j + log4j-api + ${cs.log4j.version} + + + ch.qos.reload4j + reload4j + ${cs.reload4j.version} + + + mysql + mysql-connector-java + ${cs.mysql.version} + test + log4j apache-log4j-extras @@ -447,11 +480,6 @@ - - ch.qos.reload4j - reload4j - ${cs.reload4j.version} - com.mysql mysql-connector-j @@ -717,7 +745,7 @@ org.mockito - mockito-core + mockito-inline ${cs.mockito.version} test @@ -756,6 +784,11 @@ javax.inject 1 + + com.github.ben-manes.caffeine + caffeine + ${cs.caffeine.version} +
      @@ -921,20 +954,6 @@ - - - org.codehaus.gmaven - gmaven-plugin - [1.3,) - - compile - testCompile - - - - - - org.apache.maven.plugins @@ -1001,6 +1020,7 @@ .idea/ .metadata/** .git/** + .github/linters/codespell.txt .gitignore CHANGES.md CONTRIBUTING.md @@ -1030,6 +1050,7 @@ systemvm/agent/js/jquery.js systemvm/agent/js/jquery.flot.navigate.js systemvm/agent/noVNC/** + systemvm/agent/packages/** systemvm/debian/** test/integration/component/test_host_ha.sh test/systemvm/README.md diff --git a/python/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in b/python/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in index 4944fc0218e1..546ec1cff771 100755 --- a/python/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in +++ b/python/distro/centos/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/python/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in b/python/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in index 28d5a115914c..6811c2191c7b 100755 --- a/python/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in +++ b/python/distro/fedora/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/python/distro/opensuse/SYSCONFDIR/init.d/cloud-ipallocator.in b/python/distro/opensuse/SYSCONFDIR/init.d/cloud-ipallocator.in index de68534f2e43..9d201a2a13e4 100755 --- a/python/distro/opensuse/SYSCONFDIR/init.d/cloud-ipallocator.in +++ b/python/distro/opensuse/SYSCONFDIR/init.d/cloud-ipallocator.in @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/python/distro/rhel/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in b/python/distro/rhel/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in index 28d5a115914c..6811c2191c7b 100644 --- a/python/distro/rhel/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in +++ b/python/distro/rhel/SYSCONFDIR/rc.d/init.d/cloud-ipallocator.in @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/python/distro/sles/SYSCONFDIR/init.d/cloud-ipallocator.in b/python/distro/sles/SYSCONFDIR/init.d/cloud-ipallocator.in index de68534f2e43..9d201a2a13e4 100755 --- a/python/distro/sles/SYSCONFDIR/init.d/cloud-ipallocator.in +++ b/python/distro/sles/SYSCONFDIR/init.d/cloud-ipallocator.in @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/python/distro/ubuntu/SYSCONFDIR/init.d/cloud-ipallocator.in b/python/distro/ubuntu/SYSCONFDIR/init.d/cloud-ipallocator.in index 4acb11a1f4f1..f9a855b26d12 100755 --- a/python/distro/ubuntu/SYSCONFDIR/init.d/cloud-ipallocator.in +++ b/python/distro/ubuntu/SYSCONFDIR/init.d/cloud-ipallocator.in @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -52,7 +52,7 @@ start() { log_end_msg 1 exit 1 fi - + if start-stop-daemon --start --quiet \ --pidfile "$PIDFILE" \ --exec "$DAEMONIZE" -- -n "$SHORTNAME" -p "$PIDFILE" -l "$LOGFILE" "$PROG" $OPTIONS diff --git a/python/lib/cloud_utils.py b/python/lib/cloud_utils.py index d424bf1f023e..16d9f17e8b44 100644 --- a/python/lib/cloud_utils.py +++ b/python/lib/cloud_utils.py @@ -375,7 +375,7 @@ def list_zonespods(host): x = [ (zonename,podname) for pod in dom.childNodes[0].childNodes for podname in [ x.childNodes[0].wholeText for x in pod.childNodes if x.tagName == "name" ] - for zonename in [ x.childNodes[0].wholeText for x in pod.childNodes if x.tagName == "zonename" ] + for zonename in [ x.childNodes[0].wholeText for x in pod.childNodes if x.tagName == "zonename" ] ] return x @@ -433,7 +433,7 @@ def setup_agent_config(configfile, host, zone, pod, cluster, guid, pubNic, prvNi if guid != None: confopts['guid'] = guid else: - if not "guid" in confopts: + if "guid" not in confopts: stderr("Generating GUID for this Agent") confopts['guid'] = uuidgen().stdout.strip() @@ -491,7 +491,7 @@ def setup_consoleproxy_config(configfile, host, zone, pod): confopts = dict([ m.split("=",1) for m in lines if "=" in m and not m.startswith("#") ]) confposes = dict([ (m.split("=",1)[0],n) for n,m in enumerate(lines) if "=" in m and not m.startswith("#") ]) - if not "guid" in confopts: + if "guid" not in confopts: stderr("Generating GUID for this Console Proxy") confopts['guid'] = uuidgen().stdout.strip() diff --git a/python/lib/cloudutils/configFileOps.py b/python/lib/cloudutils/configFileOps.py index 41e9c7a1e8eb..c061071b96ee 100644 --- a/python/lib/cloudutils/configFileOps.py +++ b/python/lib/cloudutils/configFileOps.py @@ -63,7 +63,7 @@ def save(self): newLines = [] if os.path.exists(self.fileName) and os.path.isfile(self.fileName): fp = open(self.fileName, "r") - for line in fp.readlines(): + for line in fp.readlines(): matched = False for entry in self.entries: if entry.op == "add": diff --git a/python/lib/cloudutils/syscfg.py b/python/lib/cloudutils/syscfg.py index 19032ce4affa..fe68b02dfe8c 100755 --- a/python/lib/cloudutils/syscfg.py +++ b/python/lib/cloudutils/syscfg.py @@ -114,7 +114,7 @@ def check(self): pass if size != -1 and size < (30 * 1024 * 1024): - raise CloudRuntimeException("Need at least 30G free disk space under /var/lib/libvirt/images") + raise CloudRuntimeException("Need at least 30G free disk space under /var/lib/libvirt/images") #check memory mem = -1 @@ -124,7 +124,7 @@ def check(self): pass if mem != -1 and mem < 1: - raise CloudRuntimeException("Need at least 1G memory") + raise CloudRuntimeException("Need at least 1G memory") if os.geteuid() != 0: diff --git a/python/lib/cloudutils/utilities.py b/python/lib/cloudutils/utilities.py index 5a6114f1011f..5b07ff1eff6f 100755 --- a/python/lib/cloudutils/utilities.py +++ b/python/lib/cloudutils/utilities.py @@ -47,11 +47,11 @@ def alarm_handler(signum, frame): alarm(0) except Alarm: os.kill(self.process.pid, SIGKILL) - raise CloudRuntimeException("Timeout during command execution") + raise CloudRuntimeException("Timeout during command execution") self.success = self.process.returncode == 0 except: - raise CloudRuntimeException(formatExceptionInfo()) + raise CloudRuntimeException(formatExceptionInfo()) if not self.success: logging.debug("Failed to execute:" + self.getErrMsg()) diff --git a/quickcloud/pom.xml b/quickcloud/pom.xml index 761d0355e597..c02b4932ee7f 100644 --- a/quickcloud/pom.xml +++ b/quickcloud/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.2.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/quickcloud/src/main/resources/META-INF/cloudstack/core/spring-quickcloud-core-context-override.xml b/quickcloud/src/main/resources/META-INF/cloudstack/core/spring-quickcloud-core-context-override.xml index 6074ea1ceb2e..a434bbe24127 100644 --- a/quickcloud/src/main/resources/META-INF/cloudstack/core/spring-quickcloud-core-context-override.xml +++ b/quickcloud/src/main/resources/META-INF/cloudstack/core/spring-quickcloud-core-context-override.xml @@ -25,7 +25,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" - > + > diff --git a/scripts/installer/cloudstack-help-text b/scripts/installer/cloudstack-help-text index 1231464aa569..fbb2f0f0a7ee 100755 --- a/scripts/installer/cloudstack-help-text +++ b/scripts/installer/cloudstack-help-text @@ -40,4 +40,10 @@ printf " * Release notes: https://docs.cloudstack.apache.org/en/${ACL_MINO printf " * Join mailing lists: https://cloudstack.apache.org/mailing-lists.html\n" printf " * Take the survey: https://cloudstack.apache.org/survey.html\n" printf " * Report issues: https://github.com/apache/cloudstack/issues/new\n" + +if [ "$1" = "management" ];then + printf "\nSince Apache CloudStack 4.20.0.0, the System VMs and virtual routers require at least 512 MiB memory, please check the System Offerings." + printf "\nMore information can be found at https://docs.cloudstack.apache.org/en/${ACL_MINOR_VERSION:-latest}/upgrading/upgrade/_sysvm_restart.html\n" +fi + printf "\n" diff --git a/scripts/installer/createtmplt.sh b/scripts/installer/createtmplt.sh index 2d164304604e..db3cfd71ee19 100755 --- a/scripts/installer/createtmplt.sh +++ b/scripts/installer/createtmplt.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -51,7 +51,7 @@ verify_cksum() { esac echo "$1 $2" | $digestalgo -c --status #printf "$1\t$2" | $digestalgo -c --status - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Checksum failed, not proceeding with install\n" exit 3 @@ -92,12 +92,12 @@ uncompress() { ;; esac - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Failed to uncompress file, exiting " - exit 1 + exit 1 fi - + mv $tmpfile $imgfile printf "$imgfile" @@ -184,10 +184,10 @@ then tmpltfs=${tmpltfs:1} fi -if [ ! -d /$tmpltfs ] +if [ ! -d /$tmpltfs ] then zfs create -p $tmpltfs - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Failed to create user fs $tmpltfs\n" >&2 exit 1 @@ -203,7 +203,7 @@ fi tmpltimg2=$(uncompress $tmpltimg) tmpltimg2=$(untar $tmpltimg2 /$tmpltfs vmi-root) -if [ ! -f $tmpltimg2 ] +if [ ! -f $tmpltimg2 ] then rollback_if_needed $tmpltfs 2 "root disk file $tmpltimg doesn't exist\n" exit 3 @@ -217,15 +217,15 @@ fi #determine source file size -- it needs to be less than or equal to volsize imgsize=$(ls -lh $tmpltimg2| awk -F" " '{print $5}') -if [ ${imgsize:(-1)} == G ] +if [ ${imgsize:(-1)} == G ] then - imgsize=${imgsize%G} #strip out the G + imgsize=${imgsize%G} #strip out the G imgsize=${imgsize%.*} #...and any decimal part let imgsize=imgsize+1 # add 1 to compensate for decimal part volsizetmp=${volsize%G} if [ $volsizetmp -lt $imgsize ] then - volsize=${imgsize}G + volsize=${imgsize}G fi fi @@ -234,11 +234,11 @@ tgtfile=${tmpltfs}/vmi-root-${tmpltname} create_from_file $tmpltfs $tmpltimg2 $tgtfile $volsize $cleanup tmpltswap=$(ls -lh /$tmpltfs | grep swap) -if [ $? -eq 0 ] +if [ $? -eq 0 ] then swapsize=$(echo $tmpltswap | awk '{print $5}') tmpltswap=$(echo $tmpltswap | awk '{print $NF}') - tmpltswap=/${tmpltfs}/${tmpltswap} + tmpltswap=/${tmpltfs}/${tmpltswap} tgtfile=${tmpltfs}/vmi-swap-${tmpltname} create_from_file $tmpltfs $tmpltswap $tgtfile $swapsize $cleanup fi diff --git a/scripts/installer/createvolume.sh b/scripts/installer/createvolume.sh index 15847c52375e..52792e9fc3aa 100755 --- a/scripts/installer/createvolume.sh +++ b/scripts/installer/createvolume.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -93,12 +93,12 @@ uncompress() { ;; esac - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Failed to uncompress file, exiting " - exit 1 + exit 1 fi - + mv $tmpfile $imgfile printf "$imgfile" @@ -185,10 +185,10 @@ then volfs=${volfs:1} fi -if [ ! -d /$volfs ] +if [ ! -d /$volfs ] then zfs create -p $volfs - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Failed to create user fs $volfs\n" >&2 exit 1 @@ -204,7 +204,7 @@ fi volimg2=$(uncompress $volimg) volimg2=$(untar $volimg2 /$volfs vmi-root) -if [ ! -f $volimg2 ] +if [ ! -f $volimg2 ] then rollback_if_needed $volfs 2 "root disk file $volimg doesn't exist\n" exit 3 @@ -218,15 +218,15 @@ fi #determine source file size -- it needs to be less than or equal to volsize imgsize=$(ls -lh $volimg2| awk -F" " '{print $5}') -if [ ${imgsize:(-1)} == G ] +if [ ${imgsize:(-1)} == G ] then - imgsize=${imgsize%G} #strip out the G + imgsize=${imgsize%G} #strip out the G imgsize=${imgsize%.*} #...and any decimal part let imgsize=imgsize+1 # add 1 to compensate for decimal part volsizetmp=${volsize%G} if [ $volsizetmp -lt $imgsize ] then - volsize=${imgsize}G + volsize=${imgsize}G fi fi @@ -235,11 +235,11 @@ tgtfile=${volfs}/vmi-root-${volname} create_from_file $volfs $volimg2 $tgtfile $volsize $cleanup volswap=$(ls -lh /$volfs | grep swap) -if [ $? -eq 0 ] +if [ $? -eq 0 ] then swapsize=$(echo $volswap | awk '{print $5}') volswap=$(echo $volswap | awk '{print $NF}') - volswap=/${volfs}/${volswap} + volswap=/${volfs}/${volswap} tgtfile=${volfs}/vmi-swap-${volname} create_from_file $volfs $volswap $tgtfile $swapsize $cleanup fi diff --git a/scripts/installer/installcentos.sh b/scripts/installer/installcentos.sh index e68e0577a8e3..b16fadce0489 100755 --- a/scripts/installer/installcentos.sh +++ b/scripts/installer/installcentos.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -38,7 +38,7 @@ do ;; c) cflag=1 create_tmplt_path="$OPTARG" - ;; + ;; ?) usage exit 2 ;; @@ -47,14 +47,14 @@ done shift $(($OPTIND - 1)) -if [ "$tflag" != "1" ] || [ "$cflag" != "1" ] +if [ "$tflag" != "1" ] || [ "$cflag" != "1" ] then usage exit 2 fi tmpltfs=$template_location/public/os/centos53-x86_64 -if [ "$fflag" == "1" ] +if [ "$fflag" == "1" ] then zfs destroy -Rr $tmpltfs 2> /dev/null fi diff --git a/scripts/installer/installdomp.sh b/scripts/installer/installdomp.sh index 79ea9fda45c1..9c7ab72139e5 100755 --- a/scripts/installer/installdomp.sh +++ b/scripts/installer/installdomp.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -47,7 +47,7 @@ then fi tmpltfs=$1/private/u000000/os/consoleproxy -if [ "$fflag" == "1" ] +if [ "$fflag" == "1" ] then zfs destroy -r $tmpltfs 2> /dev/null fi diff --git a/scripts/installer/run_installer.sh b/scripts/installer/run_installer.sh index 8452e3773cb1..3a96c7975403 100755 --- a/scripts/installer/run_installer.sh +++ b/scripts/installer/run_installer.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -32,7 +32,7 @@ then fi if [ "$VMOPS_HOME" == "" ] -then +then VMOPS_HOME="/usr/local/vmops" fi diff --git a/scripts/network/domr/router_proxy.sh b/scripts/network/domr/router_proxy.sh index 945ca968d260..550ec6de91d0 100755 --- a/scripts/network/domr/router_proxy.sh +++ b/scripts/network/domr/router_proxy.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -16,7 +16,7 @@ # specific language governing permissions and limitations # under the License. -# used as a proxy to call script inside virtual router +# used as a proxy to call script inside virtual router #set -x diff --git a/scripts/network/exdhcp/dnsmasq_edithosts.sh b/scripts/network/exdhcp/dnsmasq_edithosts.sh index 7990356edc48..f0744a9a822b 100755 --- a/scripts/network/exdhcp/dnsmasq_edithosts.sh +++ b/scripts/network/exdhcp/dnsmasq_edithosts.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -41,9 +41,9 @@ no_dhcp_release=$? [ ! -f /etc/dhcphosts.txt ] && touch /etc/dhcphosts.txt [ ! -f /var/lib/misc/dnsmasq.leases ] && touch /var/lib/misc/dnsmasq.leases -sed -i /$1/d /etc/dhcphosts.txt -sed -i /$2,/d /etc/dhcphosts.txt -sed -i /$3,/d /etc/dhcphosts.txt +sed -i /$1/d /etc/dhcphosts.txt +sed -i /$2,/d /etc/dhcphosts.txt +sed -i /$3,/d /etc/dhcphosts.txt echo "$1,$2,$3,infinite" >>/etc/dhcphosts.txt @@ -54,9 +54,9 @@ then fi #delete leases to supplied mac and ip addresses -sed -i /$1/d /var/lib/misc/dnsmasq.leases -sed -i /"$2 "/d /var/lib/misc/dnsmasq.leases -sed -i /"$3 "/d /var/lib/misc/dnsmasq.leases +sed -i /$1/d /var/lib/misc/dnsmasq.leases +sed -i /"$2 "/d /var/lib/misc/dnsmasq.leases +sed -i /"$3 "/d /var/lib/misc/dnsmasq.leases #put in the new entry echo "0 $1 $2 $3 *" >> /var/lib/misc/dnsmasq.leases diff --git a/scripts/network/exdhcp/prepare_dhcpd.sh b/scripts/network/exdhcp/prepare_dhcpd.sh index e49d0fa175bd..657fdfead20f 100755 --- a/scripts/network/exdhcp/prepare_dhcpd.sh +++ b/scripts/network/exdhcp/prepare_dhcpd.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/scripts/network/exdhcp/prepare_dnsmasq.sh b/scripts/network/exdhcp/prepare_dnsmasq.sh index 70aa587e60f2..5c496345e2c6 100755 --- a/scripts/network/exdhcp/prepare_dnsmasq.sh +++ b/scripts/network/exdhcp/prepare_dnsmasq.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -129,11 +129,11 @@ config_dnsmasq domain=cloudnine.internal config_dnsmasq " # Send options to hosts which ask for a DHCP lease. # See RFC 2132 for details of available options. -# Common options can be given to dnsmasq by name: +# Common options can be given to dnsmasq by name: # run \"dnsmasq --help dhcp\" to get a list. # Note that all the common settings, such as netmask and # broadcast address, DNS server and default route, are given -# sane defaults by dnsmasq. You very likely will not need +# sane defaults by dnsmasq. You very likely will not need # any dhcp-options. If you use Windows clients and Samba, there # are some options which are recommended, they are detailed at the # end of this section. diff --git a/scripts/network/juniper/application-add.xml b/scripts/network/juniper/application-add.xml index 177329a03595..72fca676ce2b 100644 --- a/scripts/network/juniper/application-add.xml +++ b/scripts/network/juniper/application-add.xml @@ -20,11 +20,11 @@ under the License. - -%name% -%protocol% + +%name% +%protocol% %dest-port-icmp% - + diff --git a/scripts/network/juniper/application-getone.xml b/scripts/network/juniper/application-getone.xml index 4f6b5546a5cf..69e5417a58bf 100644 --- a/scripts/network/juniper/application-getone.xml +++ b/scripts/network/juniper/application-getone.xml @@ -20,9 +20,9 @@ under the License. - -%name% - + +%name% + diff --git a/scripts/network/juniper/dest-nat-rule-add.xml b/scripts/network/juniper/dest-nat-rule-add.xml index 2ef1df29accd..2f043d614f76 100644 --- a/scripts/network/juniper/dest-nat-rule-add.xml +++ b/scripts/network/juniper/dest-nat-rule-add.xml @@ -49,8 +49,4 @@ under the License. - - - - - + diff --git a/scripts/network/juniper/guest-vlan-filter-term-add.xml b/scripts/network/juniper/guest-vlan-filter-term-add.xml index d0f52a0be44d..9d4150958ccc 100644 --- a/scripts/network/juniper/guest-vlan-filter-term-add.xml +++ b/scripts/network/juniper/guest-vlan-filter-term-add.xml @@ -19,17 +19,17 @@ under the License. - - -%filter-name% - -%term-name% - -%term-name% - - - - + + +%filter-name% + +%term-name% + +%term-name% + + + + diff --git a/scripts/network/juniper/private-interface-add.xml b/scripts/network/juniper/private-interface-add.xml index f0ccb6e0e768..d291597a57af 100644 --- a/scripts/network/juniper/private-interface-add.xml +++ b/scripts/network/juniper/private-interface-add.xml @@ -20,21 +20,21 @@ under the License. - -%private-interface-name% - - -%vlan-id% -%vlan-id% - - -
      -%private-interface-ip% -
      -
      -
      -
      -
      + +%private-interface-name% + + +%vlan-id% +%vlan-id% + + +
      +%private-interface-ip% +
      +
      +
      +
      +
      diff --git a/scripts/network/juniper/private-interface-getone.xml b/scripts/network/juniper/private-interface-getone.xml index 474e67193663..bdbb19b412c1 100644 --- a/scripts/network/juniper/private-interface-getone.xml +++ b/scripts/network/juniper/private-interface-getone.xml @@ -20,13 +20,13 @@ under the License. - -%private-interface-name% - - -%vlan-id% - - + +%private-interface-name% + + +%vlan-id% + + diff --git a/scripts/network/juniper/private-interface-with-filters-add.xml b/scripts/network/juniper/private-interface-with-filters-add.xml index 3ce8c55b242b..ea6e01f6fb16 100644 --- a/scripts/network/juniper/private-interface-with-filters-add.xml +++ b/scripts/network/juniper/private-interface-with-filters-add.xml @@ -20,14 +20,14 @@ under the License. - -%private-interface-name% - - -%vlan-id% -%vlan-id% - - + +%private-interface-name% + + +%vlan-id% +%vlan-id% + + %input-filter-name% @@ -35,14 +35,14 @@ under the License. %output-filter-name% - -
      -%private-interface-ip% -
      -
      -
      -
      -
      + +
      +%private-interface-ip% +
      +
      +
      +
      +
      diff --git a/scripts/network/juniper/proxy-arp-add.xml b/scripts/network/juniper/proxy-arp-add.xml index ae6dee0f239c..118311fb6204 100644 --- a/scripts/network/juniper/proxy-arp-add.xml +++ b/scripts/network/juniper/proxy-arp-add.xml @@ -19,17 +19,17 @@ under the License. - - - - -%public-interface-name% -
      -%public-ip-address% -
      -
      -
      -
      + + + + +%public-interface-name% +
      +%public-ip-address% +
      +
      +
      +
      diff --git a/scripts/network/juniper/proxy-arp-getall.xml b/scripts/network/juniper/proxy-arp-getall.xml index 3f23a22cd5a3..3ec425c28fc1 100644 --- a/scripts/network/juniper/proxy-arp-getall.xml +++ b/scripts/network/juniper/proxy-arp-getall.xml @@ -19,12 +19,12 @@ under the License. - - - -%interface-name% - - + + + +%interface-name% + + diff --git a/scripts/network/juniper/proxy-arp-getone.xml b/scripts/network/juniper/proxy-arp-getone.xml index e43dc0bc5ea7..3299dac9d0e1 100644 --- a/scripts/network/juniper/proxy-arp-getone.xml +++ b/scripts/network/juniper/proxy-arp-getone.xml @@ -19,17 +19,17 @@ under the License. - - - - -%public-interface-name% -
      -%public-ip-address% -
      -
      -
      -
      + + + + +%public-interface-name% +
      +%public-ip-address% +
      +
      +
      +
      diff --git a/scripts/network/juniper/public-ip-filter-term-add.xml b/scripts/network/juniper/public-ip-filter-term-add.xml index 9aad4c239902..e8ffd7aad41a 100644 --- a/scripts/network/juniper/public-ip-filter-term-add.xml +++ b/scripts/network/juniper/public-ip-filter-term-add.xml @@ -19,22 +19,22 @@ under the License. - - -%filter-name% - -%term-name% - -<%address-type%> -%ip-address% - - - -%term-name% - - - - + + +%filter-name% + +%term-name% + +<%address-type%> +%ip-address% + + + +%term-name% + + + + diff --git a/scripts/network/juniper/security-policy-group.xml b/scripts/network/juniper/security-policy-group.xml index 1d0dc8cba123..46b57b0bfcbc 100644 --- a/scripts/network/juniper/security-policy-group.xml +++ b/scripts/network/juniper/security-policy-group.xml @@ -19,13 +19,13 @@ under the License. - - - -%from-zone% -%to-zone% - - + + + +%from-zone% +%to-zone% + + diff --git a/scripts/network/juniper/zone-interface-add.xml b/scripts/network/juniper/zone-interface-add.xml index 9b2d37278ac9..5f6d4c0416a6 100644 --- a/scripts/network/juniper/zone-interface-add.xml +++ b/scripts/network/juniper/zone-interface-add.xml @@ -19,15 +19,15 @@ under the License. - - - -%private-zone-name% - -%zone-interface-name% - - - + + + +%private-zone-name% + +%zone-interface-name% + + + diff --git a/scripts/network/juniper/zone-interface-getone.xml b/scripts/network/juniper/zone-interface-getone.xml index 4bc5c4bc0d28..2078c015ba42 100644 --- a/scripts/network/juniper/zone-interface-getone.xml +++ b/scripts/network/juniper/zone-interface-getone.xml @@ -19,15 +19,15 @@ under the License. - - - -%private-zone-name% - -%zone-interface-name% - - - + + + +%private-zone-name% + +%zone-interface-name% + + + diff --git a/scripts/network/ping/baremetal_user_data.py b/scripts/network/ping/baremetal_user_data.py index 5a1893534675..02fe845392c9 100755 --- a/scripts/network/ping/baremetal_user_data.py +++ b/scripts/network/ping/baremetal_user_data.py @@ -38,7 +38,7 @@ def writeIfNotHere(fileName, texts): texts = [ "%s\n" % t for t in texts ] need = False for t in texts: - if not t in entries: + if t not in entries: entries.append(t) need = True diff --git a/scripts/storage/checkchildren.sh b/scripts/storage/checkchildren.sh index 55122d4f3a04..4185a7c25dff 100755 --- a/scripts/storage/checkchildren.sh +++ b/scripts/storage/checkchildren.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/scripts/storage/installIso.sh b/scripts/storage/installIso.sh index fd301bc5ca14..89744ac3825a 100755 --- a/scripts/storage/installIso.sh +++ b/scripts/storage/installIso.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -29,7 +29,7 @@ usage() { verify_cksum() { echo "$1 $2" | md5sum -c --status - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Checksum failed, not proceeding with install\n" exit 3 @@ -44,7 +44,7 @@ install_file() { mv $isofile /$isofs/$tmpltname - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Move operation failed, iso $isofile not installed\n" exit 4 @@ -55,7 +55,7 @@ install_file() { isofs=$isofs/$file mp=${isofs%/iso/*} mp=/$mp/iso - path=${isofs:${#mp}} + path=${isofs:${#mp}} pushd $mp ln -s $path $file popd @@ -108,10 +108,10 @@ then isofs=${isofs:1} fi -if [ ! -d /$isofs ] +if [ ! -d /$isofs ] then mkdir -p /$isofs - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Failed to create iso fs $isofs\n" >&2 exit 1 diff --git a/scripts/storage/qcow2/create_private_template.sh b/scripts/storage/qcow2/create_private_template.sh index 8e9e26c41040..06bf79d44cbf 100755 --- a/scripts/storage/qcow2/create_private_template.sh +++ b/scripts/storage/qcow2/create_private_template.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -16,7 +16,7 @@ # specific language governing permissions and limitations # under the License. - + # $Id: create_private_template.sh 9804 2010-06-22 18:36:49Z alex $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/qcow2/create_private_template.sh $ # create_private_template.sh -- create a private template from a snapshot @@ -31,7 +31,7 @@ create_template() { local fspath=$1 local destpath=$2 - # if backing image exists, we need to combine them, otherwise + # if backing image exists, we need to combine them, otherwise # copy the image to preserve snapshots/compression if $qemu_img info "$tmpltimg" | grep -q backing; then qemu-img convert -O qcow2 /$fspath $destpath diff --git a/scripts/storage/qcow2/createtmplt.sh b/scripts/storage/qcow2/createtmplt.sh index b05550c14bbd..4bb955e130c7 100755 --- a/scripts/storage/qcow2/createtmplt.sh +++ b/scripts/storage/qcow2/createtmplt.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -70,12 +70,12 @@ uncompress() { ;; esac - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Failed to uncompress file, exiting " - exit 1 + exit 1 fi - + mv $tmpfile $imgfile printf "$imgfile" @@ -89,7 +89,7 @@ create_from_file() { if [ -b $tmpltimg ]; then $qemu_img convert -f raw -O qcow2 "$tmpltimg" /$tmpltfs/$tmpltname else - # if backing image exists, we need to combine them, otherwise + # if backing image exists, we need to combine them, otherwise # copy the image to preserve snapshots/compression if $qemu_img info "$tmpltimg" | grep -q backing; then $qemu_img convert -f qcow2 -O qcow2 "$tmpltimg" /$tmpltfs/$tmpltname >& /dev/null @@ -97,7 +97,7 @@ create_from_file() { cp -f $tmpltimg /$tmpltfs/$tmpltname fi fi - + if [ "$cleanup" == "true" ] then rm -f "$tmpltimg" @@ -161,17 +161,17 @@ do done -if [ ! -d /$tmpltfs ] +if [ ! -d /$tmpltfs ] then mkdir -p /$tmpltfs - if [ $? -gt 0 ] + if [ $? -gt 0 ] then printf "Failed to create user fs $tmpltfs\n" >&2 exit 1 fi fi -if [ ! -f $tmpltimg -a ! -b $tmpltimg ] +if [ ! -f $tmpltimg -a ! -b $tmpltimg ] then printf "root disk file $tmpltimg doesn't exist\n" exit 3 diff --git a/scripts/storage/qcow2/createvm.sh b/scripts/storage/qcow2/createvm.sh index 0971c9b92553..e3a83aed3bf7 100755 --- a/scripts/storage/qcow2/createvm.sh +++ b/scripts/storage/qcow2/createvm.sh @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -18,11 +18,11 @@ # $Id: createvm.sh 10292 2010-07-07 00:24:04Z edison $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/storage/qcow2/createvm.sh $ -# createvm.sh -- create a vm image +# createvm.sh -- create a vm image usage() { echo "Usage (clone VM from template): createvm.sh -t + + + + + diff --git a/ui/src/components/view/ListView.vue b/ui/src/components/view/ListView.vue index b6f35c5eeaec..032985c730e1 100644 --- a/ui/src/components/view/ListView.vue +++ b/ui/src/components/view/ListView.vue @@ -23,8 +23,9 @@ :dataSource="items" :rowKey="(record, idx) => record.id || record.name || record.usageType || idx + '-' + Math.random()" :pagination="false" - :rowSelection=" enableGroupAction() || $route.name === 'event' ? {selectedRowKeys: selectedRowKeys, onChange: onSelectChange, columnWidth: 30} : null" + :rowSelection="explicitlyAllowRowSelection || enableGroupAction() || $route.name === 'event' ? {selectedRowKeys: selectedRowKeys, onChange: onSelectChange, columnWidth: 30} : null" :rowClassName="getRowClassName" + @resizeColumn="handleResizeColumn" style="overflow-y: auto" > +
      @@ -211,6 +211,11 @@ :pagination="true" style="overflow-y: auto" > +
      @@ -420,7 +425,7 @@ @update-selected-columns="updateSelectedColumns" @selection-change="onRowSelectionChange" @refresh="fetchData" - @edit-tariff-action="(showAction, record) => $emit('edit-tariff-action', showAction, record)"/> + /> item === resource) } } - var message = action.successMessage ? this.$t(action.successMessage) : this.$t(action.label) + - (resourceName ? ' - ' + resourceName : '') - var duration = 2 - if (action.additionalMessage) { - message = message + ' - ' + this.$t(action.successMessage) - duration = 5 - } if (this.selectedItems.length === 0) { + let message = '' + let messageDuration = 2 + if ('successMessage' in action) { + message = action.successMessage + if (typeof action.successMessage === 'function') { + message = action.successMessage(action.resource) + } + message = Array.isArray(message) ? this.$t(...message) : this.$t(message) + } else { + message = this.$t(action.label) + (resourceName ? ' - ' + resourceName : '') + } + if ('additionalMessage' in action) { + message = `${message} - ${this.$t(action.additionalMessage)}` + messageDuration = 5 + } this.$message.success({ content: message, key: action.label + resourceName, - duration: duration + duration: messageDuration }) } break @@ -1553,13 +1570,16 @@ export default { continue } if (input === undefined || input === null || - (input === '' && !['updateStoragePool', 'updateHost', 'updatePhysicalNetwork', 'updateDiskOffering', 'updateNetworkOffering', 'updateServiceOffering', 'updateZone', 'updateAccount'].includes(action.api))) { + (input === '' && !['updateStoragePool', 'updateHost', 'updatePhysicalNetwork', + 'updateDiskOffering', 'updateNetworkOffering', 'updateServiceOffering', + 'updateZone', 'updateAccount', 'updateWebhook'].includes(action.api))) { if (param.type === 'boolean') { params[key] = false } break } - if (input === '' && !['tags', 'hosttags', 'storagetags', 'dns2', 'ip6dns1', 'ip6dns2', 'internaldns2', 'networkdomain'].includes(key)) { + if (input === '' && !['tags', 'hosttags', 'storagetags', 'dns2', 'ip6dns1', + 'ip6dns2', 'internaldns2', 'networkdomain', 'secretkey'].includes(key)) { break } if (action.mapping && key in action.mapping && action.mapping[key].options) { @@ -1754,6 +1774,12 @@ export default { } else if (filter === 'allocatedonly') { query.allocatedonly = 'true' } + } else if (this.$route.name === 'asnumbers') { + if (['allocatedonly', 'free'].includes(filter)) { + query.isallocated = (filter === 'allocatedonly') + } else { + delete query.isallocated + } } else if (this.$route.name === 'event') { if (filter === 'archived') { query.archived = true diff --git a/ui/src/views/auth/ForgotPassword.vue b/ui/src/views/auth/ForgotPassword.vue new file mode 100644 index 000000000000..2d45938417fb --- /dev/null +++ b/ui/src/views/auth/ForgotPassword.vue @@ -0,0 +1,260 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + + + + + + diff --git a/ui/src/views/auth/Login.vue b/ui/src/views/auth/Login.vue index 8503f71082b5..136455655577 100644 --- a/ui/src/views/auth/Login.vue +++ b/ui/src/views/auth/Login.vue @@ -152,7 +152,16 @@ @click="handleSubmit" >{{ $t('label.login') }} - + + + + + + + {{ $t('label.forgot.password') }} + + +

      or

      @@ -220,7 +229,8 @@ export default { loginBtn: false, loginType: 0 }, - server: '' + server: '', + forgotPasswordEnabled: false } }, created () { @@ -303,6 +313,15 @@ export default { }) } }) + api('forgotPassword', {}).then(response => { + this.forgotPasswordEnabled = response.forgotpasswordresponse.enabled + }).catch((err) => { + if (err?.response?.data === null) { + this.forgotPasswordEnabled = true + } else { + this.forgotPasswordEnabled = false + } + }) }, // handler async handleUsernameOrEmail (rule, value) { diff --git a/ui/src/views/auth/ResetPassword.vue b/ui/src/views/auth/ResetPassword.vue new file mode 100644 index 000000000000..8a9047c5d3eb --- /dev/null +++ b/ui/src/views/auth/ResetPassword.vue @@ -0,0 +1,318 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + + + + + + diff --git a/ui/src/views/compute/AssignInstance.vue b/ui/src/views/compute/AssignInstance.vue index 9726dc215774..873d10f57704 100644 --- a/ui/src/views/compute/AssignInstance.vue +++ b/ui/src/views/compute/AssignInstance.vue @@ -29,86 +29,7 @@ -
      -

      {{ $t('label.accounttype') }}

      - - {{ $t('label.account') }} - {{ $t('label.project') }} - -
      - -
      -

      *{{ $t('label.domain') }}

      - - - - - - {{ domain.path || domain.name || domain.description }} - - - -
      - - - - +

      {{ $t('label.network') }}

      @@ -146,6 +67,7 @@ diff --git a/ui/src/views/compute/wizard/SecurityGroupSelection.vue b/ui/src/views/compute/wizard/SecurityGroupSelection.vue index 51f96a569ad3..87bf62ddac21 100644 --- a/ui/src/views/compute/wizard/SecurityGroupSelection.vue +++ b/ui/src/views/compute/wizard/SecurityGroupSelection.vue @@ -94,7 +94,7 @@ export default { } ], items: [], - selectedRowKeys: [], + selectedRowKeys: this?.preFillContent?.securitygroupids || [], page: 1, pageSize: 10, keyword: null, diff --git a/ui/src/views/dashboard/VerifyTwoFa.vue b/ui/src/views/dashboard/VerifyTwoFa.vue index 6456bf203fc6..0d6ec52b87e8 100644 --- a/ui/src/views/dashboard/VerifyTwoFa.vue +++ b/ui/src/views/dashboard/VerifyTwoFa.vue @@ -71,6 +71,11 @@ export default { created () { this.initForm() }, + mounted () { + this.$nextTick(() => { + this.focusInput() + }) + }, methods: { initForm () { this.formRef = ref() @@ -79,6 +84,12 @@ export default { code: [{ required: true, message: this.$t('message.error.authentication.code') }] }) }, + focusInput () { + const inputElement = this.$refs.code.$el.querySelector('input[type=password]') + if (inputElement) { + inputElement.focus() + } + }, handleSubmit () { this.formRef.value.validate().then(() => { const values = toRaw(this.form) diff --git a/ui/src/views/iam/AddAccount.vue b/ui/src/views/iam/AddAccount.vue index 232dbea1a9b4..b39c8b9dab8e 100644 --- a/ui/src/views/iam/AddAccount.vue +++ b/ui/src/views/iam/AddAccount.vue @@ -307,7 +307,9 @@ export default { }, fetchRoles () { this.roleLoading = true - api('listRoles').then(response => { + const params = {} + params.state = 'enabled' + api('listRoles', params).then(response => { this.roles = response.listrolesresponse.role || [] this.form.roleid = this.roles[0].id if (this.isDomainAdmin()) { diff --git a/ui/src/views/iam/RolePermissionTab.vue b/ui/src/views/iam/RolePermissionTab.vue index 49a9e9823618..6d2bd71b2849 100644 --- a/ui/src/views/iam/RolePermissionTab.vue +++ b/ui/src/views/iam/RolePermissionTab.vue @@ -111,6 +111,7 @@ import draggable from 'vuedraggable' import PermissionEditable from './PermissionEditable' import RuleDelete from './RuleDelete' import TooltipButton from '@/components/widgets/TooltipButton' +import { toCsv } from '@/utils/util.js' export default { name: 'RolePermissionTab', @@ -249,32 +250,8 @@ export default { this.updateTable = false }) }, - rulesDataToCsv ({ data = null, columnDelimiter = ',', lineDelimiter = '\n' }) { - if (data === null || !data.length) { - return null - } - - const keys = ['rule', 'permission', 'description'] - let result = '' - result += keys.join(columnDelimiter) - result += lineDelimiter - - data.forEach(item => { - keys.forEach(key => { - if (item[key] === undefined) { - item[key] = '' - } - result += typeof item[key] === 'string' && item[key].includes(columnDelimiter) ? `"${item[key]}"` : item[key] - result += columnDelimiter - }) - result = result.slice(0, -1) - result += lineDelimiter - }) - - return result - }, exportRolePermissions () { - const rulesCsvData = this.rulesDataToCsv({ data: this.rules }) + const rulesCsvData = toCsv({ keys: ['rule', 'permission', 'description'], data: this.rules }) const hiddenElement = document.createElement('a') hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(rulesCsvData) hiddenElement.target = '_blank' diff --git a/ui/src/views/image/AddKubernetesSupportedVersion.vue b/ui/src/views/image/AddKubernetesSupportedVersion.vue index c88fc34695d5..e0cd18c8eaa5 100644 --- a/ui/src/views/image/AddKubernetesSupportedVersion.vue +++ b/ui/src/views/image/AddKubernetesSupportedVersion.vue @@ -106,6 +106,25 @@ v-model:checked="form.directdownload" :placeholder="apiParams.directdownload.description"/> + + + + + {{ opt.name || opt.description }} + + +
      {{ $t('label.cancel') }} @@ -135,7 +154,8 @@ export default { loading: false, selectedZone: {}, directDownloadDisabled: false, - lastNonEdgeDirectDownloadUserSelection: false + lastNonEdgeDirectDownloadUserSelection: false, + architectureTypes: {} } }, beforeCreate () { @@ -196,6 +216,7 @@ export default { }) }, fetchData () { + this.fetchArchitectureTypes() this.fetchZoneData() }, isValidValueForKey (obj, key) { @@ -204,6 +225,19 @@ export default { arrayHasItems (array) { return array !== null && array !== undefined && Array.isArray(array) && array.length > 0 }, + fetchArchitectureTypes () { + this.architectureTypes.opts = [] + const typesList = [] + typesList.push({ + id: 'x86_64', + description: 'AMD 64 bits (x86_64)' + }) + typesList.push({ + id: 'aarch64', + description: 'ARM 64 bits (aarch64)' + }) + this.architectureTypes.opts = typesList + }, fetchZoneData () { const params = {} params.showicon = true diff --git a/ui/src/views/image/RegisterOrUploadIso.vue b/ui/src/views/image/RegisterOrUploadIso.vue index f27676b8e7fa..2c45a4dfc30a 100644 --- a/ui/src/views/image/RegisterOrUploadIso.vue +++ b/ui/src/views/image/RegisterOrUploadIso.vue @@ -183,6 +183,26 @@ + + + + + {{ opt.name || opt.description }} + + + + + + + + @@ -316,7 +342,8 @@ export default { accounts: [], domainLoading: false, domainid: null, - account: null + account: null, + architectureTypes: {} } }, beforeCreate () { @@ -343,6 +370,7 @@ export default { bootable: true, isextractable: false, ispublic: false, + passwordenabled: false, isdynamicallyscalable: false }) this.rules = reactive({ @@ -356,6 +384,7 @@ export default { fetchData () { this.fetchZoneData() this.fetchOsType() + this.fetchArchitectureTypes() this.fetchUserData() this.fetchUserdataPolicy() if ('listDomains' in this.$store.getters.apis) { @@ -381,6 +410,19 @@ export default { this.form.zoneid = (this.zones[0].id ? this.zones[0].id : '') }) }, + fetchArchitectureTypes () { + this.architectureTypes.opts = [] + const typesList = [] + typesList.push({ + id: 'x86_64', + description: 'AMD 64 bits (x86_64)' + }) + typesList.push({ + id: 'aarch64', + description: 'ARM 64 bits (aarch64)' + }) + this.architectureTypes.opts = typesList + }, fetchOsType () { this.osTypeLoading = true diff --git a/ui/src/views/image/RegisterOrUploadTemplate.vue b/ui/src/views/image/RegisterOrUploadTemplate.vue index 999a1b8d1202..9523351ffd0c 100644 --- a/ui/src/views/image/RegisterOrUploadTemplate.vue +++ b/ui/src/views/image/RegisterOrUploadTemplate.vue @@ -343,6 +343,34 @@ + + + + + {{ opt.name || opt.description }} + + + + + + + + + + + + + + + + {{ opt.name || opt.description }} + + + +
      {{ $t('label.cancel') }} {{ $t('label.ok') }} @@ -145,7 +171,8 @@ export default { userdata: {}, userdataid: null, userdatapolicy: null, - userdatapolicylist: {} + userdatapolicylist: {}, + architectureTypes: {} } }, beforeCreate () { @@ -168,7 +195,7 @@ export default { displaytext: [{ required: true, message: this.$t('message.error.required.input') }], ostypeid: [{ required: true, message: this.$t('message.error.select') }] }) - const resourceFields = ['name', 'displaytext', 'ostypeid', 'isdynamicallyscalable', 'userdataid', 'userdatapolicy'] + const resourceFields = ['name', 'displaytext', 'passwordenabled', 'isdynamicallyscalable', 'ostypeid', 'userdataid', 'userdatapolicy'] for (var field of resourceFields) { var fieldValue = this.resource[field] @@ -189,6 +216,7 @@ export default { }, fetchData () { this.fetchOsTypes() + this.fetchArchitectureTypes() this.fetchUserdata() this.fetchUserdataPolicy() }, @@ -207,6 +235,19 @@ export default { this.osTypes.loading = false }) }, + fetchArchitectureTypes () { + this.architectureTypes.opts = [] + const typesList = [] + typesList.push({ + id: 'x86_64', + description: 'AMD 64 bits (x86_64)' + }) + typesList.push({ + id: 'aarch64', + description: 'ARM 64 bits (aarch64)' + }) + this.architectureTypes.opts = typesList + }, fetchUserdataPolicy () { const userdataPolicy = [] userdataPolicy.push({ diff --git a/ui/src/views/image/UpdateTemplate.vue b/ui/src/views/image/UpdateTemplate.vue index 0a3103f649a6..4c540772f89c 100644 --- a/ui/src/views/image/UpdateTemplate.vue +++ b/ui/src/views/image/UpdateTemplate.vue @@ -177,6 +177,34 @@ + + + + + + + + + {{ opt.name || opt.description }} + + +
      {{ $t('label.cancel') }} @@ -206,6 +234,7 @@ export default { data () { return { templatetypes: ['BUILTIN', 'USER', 'SYSTEM', 'ROUTING', 'VNF'], + emptyAllowedFields: ['templatetag'], rootDisk: {}, nicAdapterType: {}, keyboardType: {}, @@ -215,7 +244,8 @@ export default { userdata: {}, userdataid: null, userdatapolicy: null, - userdatapolicylist: {} + userdatapolicylist: {}, + architectureTypes: {} } }, beforeCreate () { @@ -244,9 +274,10 @@ export default { displaytext: [{ required: true, message: this.$t('message.error.required.input') }], ostypeid: [{ required: true, message: this.$t('message.error.select') }] }) - const resourceFields = ['name', 'displaytext', 'passwordenabled', 'ostypeid', 'isdynamicallyscalable', 'userdataid', 'userdatapolicy'] + const resourceFields = ['name', 'displaytext', 'architecture', 'passwordenabled', 'ostypeid', 'isdynamicallyscalable', 'userdataid', 'userdatapolicy'] if (this.isAdmin) { resourceFields.push('templatetype') + resourceFields.push('templatetag') } for (var field of resourceFields) { var fieldValue = this.resource[field] @@ -279,6 +310,7 @@ export default { }, fetchData () { this.fetchOsTypes() + this.fetchArchitectureTypes() this.fetchRootDiskControllerTypes(this.resource.hypervisor) this.fetchNicAdapterTypes() this.fetchKeyboardTypes() @@ -286,6 +318,9 @@ export default { this.fetchUserdataPolicy() }, isValidValueForKey (obj, key) { + if (this.emptyAllowedFields.includes(key) && obj[key] === '') { + return true + } return key in obj && obj[key] != null && obj[key] !== undefined && obj[key] !== '' }, fetchOsTypes () { @@ -300,6 +335,19 @@ export default { this.osTypes.loading = false }) }, + fetchArchitectureTypes () { + this.architectureTypes.opts = [] + const typesList = [] + typesList.push({ + id: 'x86_64', + description: 'AMD 64 bits (x86_64)' + }) + typesList.push({ + id: 'aarch64', + description: 'ARM 64 bits (aarch64)' + }) + this.architectureTypes.opts = typesList + }, fetchRootDiskControllerTypes (hyperVisor) { const controller = [] this.rootDisk.opts = [] diff --git a/ui/src/views/image/UpdateTemplateIsoPermissions.vue b/ui/src/views/image/UpdateTemplateIsoPermissions.vue index c7b0f9e5cf19..557574156b17 100644 --- a/ui/src/views/image/UpdateTemplateIsoPermissions.vue +++ b/ui/src/views/image/UpdateTemplateIsoPermissions.vue @@ -25,7 +25,7 @@

      {{ $t('label.operation') }}

      - {{ $t('label.add') }} - {{ $t('label.remove') }} - {{ $t('label.reset') }} + {{ $t('label.add') }} + {{ $t('label.remove') }} + {{ $t('label.reset') }}
      -