Re: Merging Pull Requests

2015-08-20 Thread Wido den Hollander


On 19-08-15 17:27, Remi Bergsma wrote:
> Hi all,
> 
> As it is now, additions to CloudStack need to go through a GitHub PR and, if 
> accepted, merged to the Apache remote (not in GitHub). This means that 
> merging a PR for CloudStack is a bit more involved than merging a normal 
> GitHub PR.
> 
> To help with this, Miguel, Rajani, Daan and myself, have created some 
> scripts. One is 'git-pr' to merge a PR, the second one is 'git-fwd-merge' 
> used by RM to merge branches (starting 4.6).
> 
> Links:
> [1] PR to add the scripts
> [2] Wiki 
> 
> I'd be great if we would all use these scripts to merge Pull Requests 
> (instead of applying patches).
> 

Yes, I'm using it know. The remote names were a bit confusing in the
beginning, but when I got that fixed it worked fine.

Wido

> Let me know if you need help!
> 
> Thanks & Regards,
> 
> Remi
> 
> [1] https://github.com/apache/cloudstack/pull/721
> [2] https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61311655
> 


[GitHub] cloudstack pull request: Fixing syntax error introduced in PR #717

2015-08-20 Thread miguelaferreira
GitHub user miguelaferreira opened a pull request:

https://github.com/apache/cloudstack/pull/722

Fixing syntax error introduced in PR #717

Commit 0062ff2672e257f2a4290e054e23ef4333a34983 in PR #717 introduced a new 
parameter in two constructors. However, there is a test class 
(CitrixRequestWrapperTest) that uses these constructors and the respective 
calls needed to be updated with the new parameters.

Testing:
-  ran full maven build: `mvn clean install -P developer,systemvm`

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/miguelaferreira/cloudstack fixing-pr717

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/cloudstack/pull/722.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #722


commit 2a6c7f3ad2d045ffebba4744238359a5c6dc29bb
Author: Rohit Yadav 
Date:   2015-08-19T10:01:37Z

CLOUDSTACK-8748: VM UUID accessible in CreateVMSnapshotCommand and 
RevertToVMSnapshotCommand

This patch makes it possible to expose VM UUID to subsystems, this can be
useful for implementing VM Snapshots for KVM in future.

Signed-off-by: Rohit Yadav 

commit 0bb7051b647caf95c989f1b1d3efe788262aab60
Author: Miguel Ferreira 
Date:   2015-08-20T07:56:32Z

Formatting class CitrixRequestWrapperTest

commit 551c55cef728f3add69b030b44fdcd1e892b42a0
Author: Miguel Ferreira 
Date:   2015-08-20T07:55:55Z

Add UUIDs to constructors (fixing syntax error from 2a6c7f3)




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Fixing syntax error introduced in PR #717

2015-08-20 Thread miguelaferreira
Github user miguelaferreira commented on the pull request:

https://github.com/apache/cloudstack/pull/722#issuecomment-132925325
  
ping @karuturi @bhaisaab 

Please have a look.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


Jenkins build is back to normal : build-master-slowbuild #2103

2015-08-20 Thread jenkins
See 



[GitHub] cloudstack pull request: Removed duplicate code in CitrixResourceB...

2015-08-20 Thread miguelaferreira
Github user miguelaferreira commented on the pull request:

https://github.com/apache/cloudstack/pull/700#issuecomment-132949485
  
LGTM

This PR is a great example of how to do code refactoring. Write unit tests 
that exercise the semantics, change the logic around it, run the unit tests 
again to show the semantics is the same.
Great work.

However, @anshul1886 has a point related to the tests being coupled to the 
implementation via the path string. IMHO that is not a result of having the 
tests, that is a result of having the path string hardcoded in the class. That 
was there already and @cristofolini worked with that to make the rest better.

So I would merge this now, because it is good work, and refactor the class 
XcpOssResource (and respective test) to make it parametric on the path string. 
While putting this specific string in a constants class, or in a config 
attribute (maybe in the DB, not sure about that), to make it easier to change 
and reuse.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


Re: Merging Pull Requests

2015-08-20 Thread Remi Bergsma
Hi Wido,

Nice!

The latest version should detect your Apache GitHub remote name.

Regards,
Remi

> On 20 Aug 2015, at 09:13, Wido den Hollander  wrote:
> 
> 
> 
> On 19-08-15 17:27, Remi Bergsma wrote:
>> Hi all,
>> 
>> As it is now, additions to CloudStack need to go through a GitHub PR and, if 
>> accepted, merged to the Apache remote (not in GitHub). This means that 
>> merging a PR for CloudStack is a bit more involved than merging a normal 
>> GitHub PR.
>> 
>> To help with this, Miguel, Rajani, Daan and myself, have created some 
>> scripts. One is 'git-pr' to merge a PR, the second one is 'git-fwd-merge' 
>> used by RM to merge branches (starting 4.6).
>> 
>> Links:
>> [1] PR to add the scripts
>> [2] Wiki 
>> 
>> I'd be great if we would all use these scripts to merge Pull Requests 
>> (instead of applying patches).
>> 
> 
> Yes, I'm using it know. The remote names were a bit confusing in the
> beginning, but when I got that fixed it worked fine.
> 
> Wido
> 
>> Let me know if you need help!
>> 
>> Thanks & Regards,
>> 
>> Remi
>> 
>> [1] https://github.com/apache/cloudstack/pull/721
>> [2] https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61311655
>> 



[GitHub] cloudstack pull request: Removed duplicate code in CitrixResourceB...

2015-08-20 Thread remibergsma
Github user remibergsma commented on the pull request:

https://github.com/apache/cloudstack/pull/700#issuecomment-132957093
  
Thanks all for your efforts, I'm merging this now.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Removed duplicate code in CitrixResourceB...

2015-08-20 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/cloudstack/pull/700


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Add scripts to merge PRs and release fixe...

2015-08-20 Thread wido
Github user wido commented on the pull request:

https://github.com/apache/cloudstack/pull/721#issuecomment-132962997
  
LGTM here as well. Used this script a couple of times


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


Problems with first steps of CS plugin development

2015-08-20 Thread Giebner, Sascha
Hello guys,

I'm trying to complete this tutorial for the development of a Cloudstack API 
plugin:
https://cwiki.apache.org/confluence/display/CLOUDSTACK/CloudStack+API+Development

I checked out the latest version from the cloudstack master and followed the 
tutorial to the letter, however when I try to call the API, I always get the 
following JSON response:

{"errorresponse":{"uuidList":[],"errorcode":432,"cserrorcode":,"errortext":"Unknown
 API command: getTimeOfDay"}}

I've been digging around in the cloudstack code, unfortunately with no success 
until now. Everything compiles fine, so I suspect there may be something wrong 
with the maven configuration. However since this is my first time using maven, 
I'm a bit overwhelmed.
Do you have some hints for me?

Thanks and best regards,
Sascha Giebner

-- 
This email was Virus checked by UTM 9. http://www.sophos.com


Question regarding @Local usage on CS

2015-08-20 Thread Rafael Weingärtner
Hi folks,
I noticed that CloudStack uses EJB alongside with Spring.

I am trying to understand the use of @Local, are beans of classes marked
with @Local singletons?

-- 
Rafael Weingärtner


[GitHub] cloudstack pull request: More typos

2015-08-20 Thread radu-stefanache
GitHub user radu-stefanache opened a pull request:

https://github.com/apache/cloudstack/pull/723

More typos

Some more typos that I've found .

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/radu-stefanache/cloudstack typo_fixes

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/cloudstack/pull/723.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #723


commit c7a3ad4dc047854cd73a85fedb23fd41d67c11f0
Author: radu-stefanache 
Date:   2015-08-19T15:08:42Z

More typos




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


Re: [DISCUSS] apache builds vs reviews

2015-08-20 Thread Daan Hoogland
fair points Rajani, not related to my question but worthy of attention. In
the meanwhile I am taking them as a "yes we can schedule regular (master)
build down to once a day"

On Thu, Aug 20, 2015 at 8:02 AM, Rajani Karuturi  wrote:

> pull-rat doest the rat check
> pull-analysis does a roredist build and unittests after applying the pr.
> I dont know what pull-request does. So, I am ok with disabling it :)
>
> The problem I see with these jobs is that, it only informs me of a success
> or a failure once its done. There is no inprogress indication like travis.
> sometimes the response is so slow that I get a build failure a few hours
> after the PR merge. ( there is also the aborted noise when the pr is
> getting appended with review comments)
>
> If we can solve that, it will also help reviewers in deciding to wait for
> those additional checks to complete before doing a merge.
>
> ~Rajani
>
> On Wed, Aug 19, 2015 at 4:15 PM, Daan Hoogland 
> wrote:
>
> > LS,
> >
> > I have disabled cloudstack-pull-request on builds.apache.org as we now
> > have
> > cloudstack-pull-rat and cloudstack-pull-analysis and also still have
> > jenkins.bac.o. I want to further unburdon the apache jenkins web by
> > scheduling down other jobs to once a day. noticably this is the master
> > build but also the rat-catcher. If we do so review on PRs for these
> issues
> > become more important hence looking at the output of pull request jobs.
> Can
> > we live with that?
> >
> > ​regards,​
> > --
> > Daan
> >
>



-- 
Daan


Re: Problems with first steps of CS plugin development

2015-08-20 Thread Mike Tutkowski
I don't have easy access to the code right now, but did you update the
commands.properties file with your new API commands?

On Thursday, August 20, 2015, Giebner, Sascha 
wrote:

> Hello guys,
>
> I'm trying to complete this tutorial for the development of a Cloudstack
> API plugin:
>
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/CloudStack+API+Development
>
> I checked out the latest version from the cloudstack master and followed
> the tutorial to the letter, however when I try to call the API, I always
> get the following JSON response:
>
> {"errorresponse":{"uuidList":[],"errorcode":432,"cserrorcode":,"errortext":"Unknown
> API command: getTimeOfDay"}}
>
> I've been digging around in the cloudstack code, unfortunately with no
> success until now. Everything compiles fine, so I suspect there may be
> something wrong with the maven configuration. However since this is my
> first time using maven, I'm a bit overwhelmed.
> Do you have some hints for me?
>
> Thanks and best regards,
> Sascha Giebner
>
> --
> This email was Virus checked by UTM 9. http://www.sophos.com
>


-- 
*Mike Tutkowski*
*Senior CloudStack Developer, SolidFire Inc.*
e: mike.tutkow...@solidfire.com
o: 303.746.7302
Advancing the way the world uses the cloud
*™*


Re: [VOTE] Apache Cloudstack 4.5.2 (Round 2)

2015-08-20 Thread Remi Bergsma
Hi all,

+1 (binding)

Tested:

1. Advanced zone with XenServer
- Deployed VPCs, VMs and VPNs between them
- Crashed a XenServer, watched it recover
- Tested it again and all was fine. All I had to do was reset the VPN 
connection, but maybe it'd have done it automatically if I waited longer.

2. Advanced zone with KVM (on CentOS 7 that is, after some manual tweaks)
- Advanced zone with XenServer
- Deployed VPCs, VMs and VPNs between them
- Crashed a KVM hypervisor, watched it recover
- Tested it again and all was fine. VPN recovery was automatic.

3. Upgraded 4.4.4 -> 4.5.2 
It went fine.

About KVM on CentOS 7
At work we're actually running KVM on CentOS 7, on ACS 4.4.x. Although I know 
not many people do. I tried it on 4.5.2 and encountered the issues described in 
CLOUDSTACK-8443. I checked the documentation and it said we only support CentOS 
6.3 (I assume .3 should be .x but anyway) on ACS 4.5.x so I'll just ignore this 
for now.

I have updated the Jira issue with some findings and I will investigate this 
further, so we can fix it and at least start supporting CentOS 7 as a KVM 
hypervisor out-of-the-box in 4.6.

If we feel we want to fix KVM on CentOS 7 in 4.5.2 then we need another 
4.5.2RC, in which case I'm happy to help making it happen ;-)

Regards,
Remi



> On 20 Aug 2015, at 08:26, Rajani Karuturi  wrote:
> 
> +1(binding)
> 
> tested fresh install on xenserver 6.5 advanced zone setup.
> 
> register template, create network, launch vm, view console etc. worked fine.
> 
> 
> ~Rajani
> 
> On Thu, Aug 20, 2015 at 12:04 AM, Milamber  wrote:
> 
>> Hello,
>> 
>> +1 (binding)
>> 
>> * Building CloudStack ubuntu packages from Git 4.5.2 RC2 tag.
>> 
>> * Tests migration from 4.4.4 -> 4.5.2rc2 on Ubuntu 14.04.3 (1 mgr, 2
>> nodes, 1 nfs), basic install, NFS storage, KVM, SystemVM shapeblue, After
>> migration: some tests on HA (crash node), some tests with templates,
>> account management in webui, test localization french, and CS<->cloud-init
>> on debian.
>> 
>> * Tests fresh install on Ubuntu 14.04.3 (1 mgr, 2 nodes, 1 nfs), advanced
>> network install NFS storage, KVM, SystemVM shapeblue, some tests on HA
>> (crash node), some tests with templates, and CS<->cloud-init on debian.
>> 
>> * Some tests (register template, create network, register ssh key, create
>> instance, get IP) with Ansible + ansible-cloudstack module from @resmo
>> 
>> Thanks for the RM.
>> 
>> Milamber
>> 
>> 
>> Please note this bug message in the last migration step (when I rebooted
>> all systemvm/router).
>> 
>> root@cs-mgr1:~# cloudstack-sysvmadm -d 127.0.0.1 -u cloud -p cloudPass -a
>> /usr/bin/cloudstack-sysvmadm: line 21: /etc/rc.d/init.d/functions: No such
>> file or directory
>> 
>> Stopping and starting 1 secondary storage vm(s)...
>> Done stopping and starting secondary storage vm(s)
>> 
>> Stopping and starting 1 console proxy vm(s)...
>> Done stopping and starting console proxy vm(s) .
>> 
>> Stopping and starting 1 running routing vm(s)...
>> Done restarting router(s).
>> 
>> 
>> 
>> 
>> On 19/08/2015 10:22, Rohit Yadav wrote:
>> 
>>> Hi All,
>>> 
>>> I've created a 4.5.2 release, with the following artifacts up for a vote:
>>> 
>>> Git Branch and Commit SH:
>>> 
>>> https://git-wip-us.apache.org/repos/asf?p=cloudstack.git;a=shortlog;h=refs/heads/4.5-RC20150819T1442
>>> Commit: 7385441807ba3fde3d45c226df6b1bdd2f36ae26
>>> Tag: 4.5.2-rc2
>>> 
>>> List of changes:
>>> 
>>> https://git-wip-us.apache.org/repos/asf?p=cloudstack.git;a=shortlog;h=refs/heads/4.5-RC20150819T1442
>>> 
>>> Source release (checksums and signatures are available at the same
>>> location):
>>> https://dist.apache.org/repos/dist/dev/cloudstack/4.5.2/
>>> 
>>> PGP release keys (signed using 0EE3D884):
>>> https://dist.apache.org/repos/dist/release/cloudstack/KEYS
>>> 
>>> The vote will be open for 72 hours.
>>> 
>>> For sanity in tallying the vote, can PMC members please be sure to
>>> indicate "(binding)" with their vote?
>>> 
>>> [ ] +1  approve
>>> [ ] +0  no opinion
>>> [ ] -1  disapprove (and reason why)
>>> 
>>> Regards.
>>> 
>>> 
>> 



SDN solutions in use today with CloudStack

2015-08-20 Thread Simon Weller
Hi all,

We  are currently exploring options for improving our networking setup (read 
SDN) within CS for our advanced zones.

There are a few plugins currently available for various third party SDN 
providers (Nicira, Big Switch VNS, MidoNet, Stratosphere SSP, Nuage VSP  et 
al), as well as some pre-SDN functionality using native VXLAN, OVS GRE and of 
course vlans.

Most of the organizations mentioned above appear to have drunken the OpenStack 
kool-aid and don't even mention support for CloudStack on their commercial 
websites.

It seems that some of these plugins are getting rather old now and I'd be 
interesting to know (if you're willing to share) what is in use in the 
community today.

- Si





[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37571366
  
--- Diff: engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java ---
@@ -469,4 +478,25 @@ public void removeOldUsageRecords(int days) {
 txn.close();
 }
 }
+
+@SuppressWarnings("deprecation")
+public Pair, Integer> 
getUsageRecordsPendingQuotaAggregation(final long accountId, final long 
domainId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+s_logger.debug("getting usage records for account: " + accountId + 
", domainId: " + domainId);
--- End diff --

Debug logging statements should be wrapped in a ``if 
(s_logger.isDebugEnabled())`` check to avoid the overhead of string 
concatenation when debug logging is not enabled.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37572081
  
--- Diff: engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java ---
@@ -469,4 +478,25 @@ public void removeOldUsageRecords(int days) {
 txn.close();
 }
 }
+
+@SuppressWarnings("deprecation")
+public Pair, Integer> 
getUsageRecordsPendingQuotaAggregation(final long accountId, final long 
domainId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
--- End diff --

Why do we immediately open and close a transaction here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37572286
  
--- Diff: engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java ---
@@ -469,4 +478,25 @@ public void removeOldUsageRecords(int days) {
 txn.close();
 }
 }
+
+@SuppressWarnings("deprecation")
+public Pair, Integer> 
getUsageRecordsPendingQuotaAggregation(final long accountId, final long 
domainId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+s_logger.debug("getting usage records for account: " + accountId + 
", domainId: " + domainId);
+Filter usageFilter = new Filter(UsageVO.class, "startDate", true, 
0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+if (accountId != -1) {
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+}
+if (domainId != -1) {
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+}
+sc.addAnd("quotaCalculated", SearchCriteria.Op.NULL);
+sc.addOr("quotaCalculated", SearchCriteria.Op.EQ, 0);
+s_logger.debug("Getting usage records" + usageFilter.getOrderBy());
+Pair, Integer> usageRecords = 
searchAndCountAllRecords(sc, usageFilter);
+TransactionLegacy.open(opendb).close();
--- End diff --

Why do we immediately open and close a transaction here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37572319
  
--- Diff: engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java ---
@@ -469,4 +478,25 @@ public void removeOldUsageRecords(int days) {
 txn.close();
 }
 }
+
+@SuppressWarnings("deprecation")
+public Pair, Integer> 
getUsageRecordsPendingQuotaAggregation(final long accountId, final long 
domainId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+s_logger.debug("getting usage records for account: " + accountId + 
", domainId: " + domainId);
+Filter usageFilter = new Filter(UsageVO.class, "startDate", true, 
0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+if (accountId != -1) {
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+}
+if (domainId != -1) {
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+}
+sc.addAnd("quotaCalculated", SearchCriteria.Op.NULL);
+sc.addOr("quotaCalculated", SearchCriteria.Op.EQ, 0);
+s_logger.debug("Getting usage records" + usageFilter.getOrderBy());
--- End diff --

Debug logging statements should be wrapped in a ``if 
(s_logger.isDebugEnabled())`` check to avoid the overhead of string 
concatenation when debug logging is not enabled.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37572729
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/constant/QuotaTypes.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.quota.constant;
+
+import org.apache.cloudstack.usage.UsageTypes;
+
+import java.util.HashMap;
+
+public class QuotaTypes extends UsageTypes {
+public static final int CPU_CLOCK_RATE = 15;
+public static final int CPU_NUMBER = 16;
+public static final int MEMORY = 17;
+
+private Integer quotaType;
+private String quotaName;
+private String quotaUnit;
+private String description;
+private String discriminator;
--- End diff --

Why aren't these attributes declared final?  They do not change over the 
lifecycle of the class and set in the constructor.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37573045
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/constant/QuotaTypes.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.quota.constant;
+
+import org.apache.cloudstack.usage.UsageTypes;
+
+import java.util.HashMap;
+
+public class QuotaTypes extends UsageTypes {
+public static final int CPU_CLOCK_RATE = 15;
+public static final int CPU_NUMBER = 16;
+public static final int MEMORY = 17;
+
+private Integer quotaType;
+private String quotaName;
+private String quotaUnit;
+private String description;
+private String discriminator;
+
+public QuotaTypes(Integer quotaType, String name, String unit, String 
description) {
+this.quotaType = quotaType;
+this.description = description;
+this.quotaName = name;
+this.quotaUnit = unit;
+this.discriminator = "None";
+}
+
+public static HashMap listQuotaTypes() {
+final HashMap quotaTypeList = new 
HashMap();
+quotaTypeList.put(new Integer(RUNNING_VM), new QuotaTypes(new 
Integer(RUNNING_VM), "RUNNING_VM", "Compute-Month", "Running Vm Usage"));
--- End diff --

``new Integer(...)`` bypasses the constant pool -- increasing memory and 
negatively impacting performance.  Use ``Integer.valueOf()`` instead.  

In order to avoid boilerplate, why not declare the constant values as 
Integer rather than int?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


Re: SDN solutions in use today with CloudStack

2015-08-20 Thread Chiradeep Vittal
Nuage seems to be in production in quite a few CloudStack clouds

From: Simon Weller mailto:swel...@ena.com>>
Reply-To: "dev@cloudstack.apache.org" 
mailto:dev@cloudstack.apache.org>>
Date: Thursday, August 20, 2015 at 11:41 AM
To: "dev@cloudstack.apache.org" 
mailto:dev@cloudstack.apache.org>>
Subject: SDN solutions in use today with CloudStack

Hi all,

We  are currently exploring options for improving our networking setup (read 
SDN) within CS for our advanced zones.

There are a few plugins currently available for various third party SDN 
providers (Nicira, Big Switch VNS, MidoNet, Stratosphere SSP, Nuage VSP  et 
al), as well as some pre-SDN functionality using native VXLAN, OVS GRE and of 
course vlans.

Most of the organizations mentioned above appear to have drunken the OpenStack 
kool-aid and don't even mention support for CloudStack on their commercial 
websites.

It seems that some of these plugins are getting rather old now and I'd be 
interesting to know (if you're willing to share) what is in use in the 
community today.

- Si






[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37573761
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/constant/QuotaTypes.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.quota.constant;
+
+import org.apache.cloudstack.usage.UsageTypes;
+
+import java.util.HashMap;
+
+public class QuotaTypes extends UsageTypes {
+public static final int CPU_CLOCK_RATE = 15;
+public static final int CPU_NUMBER = 16;
+public static final int MEMORY = 17;
+
+private Integer quotaType;
+private String quotaName;
+private String quotaUnit;
+private String description;
+private String discriminator;
+
+public QuotaTypes(Integer quotaType, String name, String unit, String 
description) {
+this.quotaType = quotaType;
+this.description = description;
+this.quotaName = name;
+this.quotaUnit = unit;
+this.discriminator = "None";
+}
+
+public static HashMap listQuotaTypes() {
--- End diff --

Why isn't the quotaTypes map initialized as a static constant? Each time 
``getDescription()`` method is called these values are unnecessarily 
reallocated. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37573927
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/constant/QuotaTypes.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.quota.constant;
+
+import org.apache.cloudstack.usage.UsageTypes;
+
+import java.util.HashMap;
+
+public class QuotaTypes extends UsageTypes {
+public static final int CPU_CLOCK_RATE = 15;
+public static final int CPU_NUMBER = 16;
+public static final int MEMORY = 17;
+
+private Integer quotaType;
+private String quotaName;
+private String quotaUnit;
+private String description;
+private String discriminator;
+
+public QuotaTypes(Integer quotaType, String name, String unit, String 
description) {
+this.quotaType = quotaType;
+this.description = description;
+this.quotaName = name;
+this.quotaUnit = unit;
+this.discriminator = "None";
+}
+
+public static HashMap listQuotaTypes() {
+final HashMap quotaTypeList = new 
HashMap();
+quotaTypeList.put(new Integer(RUNNING_VM), new QuotaTypes(new 
Integer(RUNNING_VM), "RUNNING_VM", "Compute-Month", "Running Vm Usage"));
+quotaTypeList.put(new Integer(ALLOCATED_VM), new QuotaTypes(new 
Integer(ALLOCATED_VM), "ALLOCATED_VM", "Compute-Month", "Allocated Vm Usage"));
+quotaTypeList.put(new Integer(IP_ADDRESS), new QuotaTypes(new 
Integer(IP_ADDRESS), "IP_ADDRESS", "IP-Month", "IP Address Usage"));
+quotaTypeList.put(new Integer(NETWORK_BYTES_SENT), new 
QuotaTypes(new Integer(NETWORK_BYTES_SENT), "NETWORK_BYTES_SENT", "GB", 
"Network Usage (Bytes Sent)"));
+quotaTypeList.put(new Integer(NETWORK_BYTES_RECEIVED), new 
QuotaTypes(new Integer(NETWORK_BYTES_RECEIVED), "NETWORK_BYTES_RECEIVED", "GB", 
"Network Usage (Bytes Received)"));
+quotaTypeList.put(new Integer(VOLUME), new QuotaTypes(new 
Integer(VOLUME), "VOLUME", "GB-Month", "Volume Usage"));
+quotaTypeList.put(new Integer(TEMPLATE), new QuotaTypes(new 
Integer(TEMPLATE), "TEMPLATE", "GB-Month", "Template Usage"));
+quotaTypeList.put(new Integer(ISO), new QuotaTypes(new 
Integer(ISO), "ISO", "GB-Month", "ISO Usage"));
+quotaTypeList.put(new Integer(SNAPSHOT), new QuotaTypes(new 
Integer(SNAPSHOT), "SNAPSHOT", "GB-Month", "Snapshot Usage"));
+quotaTypeList.put(new Integer(SECURITY_GROUP), new QuotaTypes(new 
Integer(SECURITY_GROUP), "SECURITY_GROUP", "Policy-Month", "Security Group 
Usage"));
+quotaTypeList.put(new Integer(LOAD_BALANCER_POLICY), new 
QuotaTypes(new Integer(LOAD_BALANCER_POLICY), "LOAD_BALANCER_POLICY", 
"Policy-Month", "Load Balancer Usage"));
+quotaTypeList.put(new Integer(PORT_FORWARDING_RULE), new 
QuotaTypes(new Integer(PORT_FORWARDING_RULE), "PORT_FORWARDING_RULE", 
"Policy-Month", "Port Forwarding Usage"));
+quotaTypeList.put(new Integer(NETWORK_OFFERING), new 
QuotaTypes(new Integer(NETWORK_OFFERING), "NETWORK_OFFERING", "Policy-Month", 
"Network Offering Usage"));
+quotaTypeList.put(new Integer(VPN_USERS), new QuotaTypes(new 
Integer(VPN_USERS), "VPN_USERS", "Policy-Month", "VPN users usage"));
+quotaTypeList.put(new Integer(VM_DISK_IO_READ), new QuotaTypes(new 
Integer(VM_DISK_IO_READ), "VM_DISK_IO_READ", "GB", "VM Disk usage(I/O Read)"));
+quotaTypeList.put(new Integer(VM_DISK_IO_WRITE), new 
QuotaTypes(new Integer(VM_DISK_IO_WRITE), "VM_DISK_IO_WRITE", "GB", "VM Disk 
usage(I/O Write)"));
+quotaTypeList.put(new Integer(VM_DISK_BYTES_READ), new 
QuotaTypes(new Integer(VM_DISK_BYTES_READ), "VM_DISK_BYTES_READ", "GB", "VM 
Disk usage(Bytes Read)"));
+quotaTypeList.put(new Integer(VM_DISK_BYTES_WRITE), new 
QuotaTypes(new Integer(VM_DISK_BYTES_WRITE), "VPN_USERS", "GB", "VM Disk 
usage(Bytes Write)"));
+quotaTypeList.put(new Integer(V

Re: SDN solutions in use today with CloudStack

2015-08-20 Thread Remi Bergsma
Hi Simon,

At Schuberg Philis we use Nicira (which nowadays is called VMware NSX-MH) in 
production since 2012. It works well for us. The plugin is also still 
maintained and is getting some tlc as we speak.

The Nuage plugin was introduced recently, I think in 4.5. I hear people are 
using this a lot so it’s definitely something to investigate. The others I have 
never tried. Really wondering if anyone is using GRE in CloudStack?

Regards,
Remi
 

> On 20 Aug 2015, at 20:41, Simon Weller  wrote:
> 
> Hi all,
> 
> We  are currently exploring options for improving our networking setup (read 
> SDN) within CS for our advanced zones.
> 
> There are a few plugins currently available for various third party SDN 
> providers (Nicira, Big Switch VNS, MidoNet, Stratosphere SSP, Nuage VSP  et 
> al), as well as some pre-SDN functionality using native VXLAN, OVS GRE and of 
> course vlans.
> 
> Most of the organizations mentioned above appear to have drunken the 
> OpenStack kool-aid and don't even mention support for CloudStack on their 
> commercial websites.
> 
> It seems that some of these plugins are getting rather old now and I'd be 
> interesting to know (if you're willing to share) what is in use in the 
> community today.
> 
> - Si
> 
> 
> 



Re: SDN solutions in use today with CloudStack

2015-08-20 Thread Simon Weller
Thanks guys.

We've seen a lot of reports of MidoNet as well, but I haven't seen them 
discussed much on the list.
I haven't heard of anyone using GRE. We have experimented in our lab with VXLAN 
on KVM and it seems to work.

- Si


From: Remi Bergsma 
Sent: Thursday, August 20, 2015 3:17 PM
To: dev@cloudstack.apache.org
Subject: Re: SDN solutions in use today with CloudStack

Hi Simon,

At Schuberg Philis we use Nicira (which nowadays is called VMware NSX-MH) in 
production since 2012. It works well for us. The plugin is also still 
maintained and is getting some tlc as we speak.

The Nuage plugin was introduced recently, I think in 4.5. I hear people are 
using this a lot so it’s definitely something to investigate. The others I have 
never tried. Really wondering if anyone is using GRE in CloudStack?

Regards,
Remi


> On 20 Aug 2015, at 20:41, Simon Weller  wrote:
>
> Hi all,
>
> We  are currently exploring options for improving our networking setup (read 
> SDN) within CS for our advanced zones.
>
> There are a few plugins currently available for various third party SDN 
> providers (Nicira, Big Switch VNS, MidoNet, Stratosphere SSP, Nuage VSP  et 
> al), as well as some pre-SDN functionality using native VXLAN, OVS GRE and of 
> course vlans.
>
> Most of the organizations mentioned above appear to have drunken the 
> OpenStack kool-aid and don't even mention support for CloudStack on their 
> commercial websites.
>
> It seems that some of these plugins are getting rather old now and I'd be 
> interesting to know (if you're willing to share) what is in use in the 
> community today.
>
> - Si
>
>
>



[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37580929
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDao.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.quota.dao;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface QuotaBalanceDao extends GenericDao {
+
+void saveQuotaBalance(List credits);
+
+List findCreditBalance(long accountId, long domainId, 
Date startDate, Date endDate);
--- End diff --

Why are some ``accountId``s declared as ``long`` and some as ``Long``?  It 
seems that the type should be consistent across all method declarations.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37581010
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.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.quota.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaAccountDao.class })
+public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao {
+
+@Override
+public List listAll() {
+List result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
--- End diff --

As mentioned in a previous comment, why is a transaction created and 
immediately closed?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582361
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLaterBalanceEntry(final long accountId, 
final long domainId, final Date afterThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.GT, afterThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@Override
+public void saveQuotaBalance(final List credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+for (QuotaBalanceVO credit : credits) {
+persist(credit);
+}
+} finally {
+txn.close();
+}
+TransactionLegacy.open(opendb).close();
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCreditBalance(final long accountId, 
final long domainId, final Date lastbalancedate, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", Sea

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582377
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLaterBalanceEntry(final long accountId, 
final long domainId, final Date afterThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.GT, afterThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@Override
+public void saveQuotaBalance(final List credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+for (QuotaBalanceVO credit : credits) {
+persist(credit);
+}
+} finally {
+txn.close();
+}
+TransactionLegacy.open(opendb).close();
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCreditBalance(final long accountId, 
final long domainId, final Date lastbalancedate, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", Sea

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582389
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLaterBalanceEntry(final long accountId, 
final long domainId, final Date afterThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.GT, afterThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@Override
+public void saveQuotaBalance(final List credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+for (QuotaBalanceVO credit : credits) {
+persist(credit);
+}
+} finally {
+txn.close();
+}
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582401
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLaterBalanceEntry(final long accountId, 
final long domainId, final Date afterThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.GT, afterThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582427
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582453
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.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.quota.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaAccountDao.class })
+public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao {
+
+@Override
+public List listAll() {
+List result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.listAll();
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO findById(Long id) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.findById(id);
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO persist(QuotaAccountVO entity) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.persist(entity);
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public boolean update(Long id, QuotaAccountVO entity) {
+boolean result = false;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.update(id, entity);
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582431
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582467
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.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.quota.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaAccountDao.class })
+public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao {
+
+@Override
+public List listAll() {
+List result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.listAll();
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO findById(Long id) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.findById(id);
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO persist(QuotaAccountVO entity) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.persist(entity);
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582475
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.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.quota.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaAccountDao.class })
+public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao {
+
+@Override
+public List listAll() {
+List result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.listAll();
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO findById(Long id) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.findById(id);
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582547
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaCreditsDaoImpl.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.quota.dao;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaCreditsDao.class })
+public class QuotaCreditsDaoImpl extends GenericDaoBase implements QuotaCreditsDao {
+@Inject
+QuotaBalanceDao _quotaBalanceDao;
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCredits(final long accountId, final 
long domainId, final Date startDate, final Date endDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+Filter filter = new Filter(QuotaCreditsVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+if ((startDate != null) && (endDate != null) && 
startDate.before(endDate)) {
+sc.addAnd("updatedOn", SearchCriteria.Op.BETWEEN, startDate, 
endDate);
+} else {
+return new ArrayList();
+}
+List qc = search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return qc;
+}
+
+@Override
+public QuotaCreditsVO saveCredits(final QuotaCreditsVO credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+persist(credits);
+// make an entry in the balance table
+QuotaBalanceVO bal = new QuotaBalanceVO(credits);
+_quotaBalanceDao.persist(bal);
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582530
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaCreditsDaoImpl.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.quota.dao;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaCreditsDao.class })
+public class QuotaCreditsDaoImpl extends GenericDaoBase implements QuotaCreditsDao {
+@Inject
+QuotaBalanceDao _quotaBalanceDao;
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCredits(final long accountId, final 
long domainId, final Date startDate, final Date endDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+Filter filter = new Filter(QuotaCreditsVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+if ((startDate != null) && (endDate != null) && 
startDate.before(endDate)) {
+sc.addAnd("updatedOn", SearchCriteria.Op.BETWEEN, startDate, 
endDate);
+} else {
+return new ArrayList();
+}
+List qc = search(sc, filter);
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582598
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaCreditsDaoImpl.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.quota.dao;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaCreditsDao.class })
+public class QuotaCreditsDaoImpl extends GenericDaoBase implements QuotaCreditsDao {
+@Inject
+QuotaBalanceDao _quotaBalanceDao;
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCredits(final long accountId, final 
long domainId, final Date startDate, final Date endDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+Filter filter = new Filter(QuotaCreditsVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+if ((startDate != null) && (endDate != null) && 
startDate.before(endDate)) {
+sc.addAnd("updatedOn", SearchCriteria.Op.BETWEEN, startDate, 
endDate);
+} else {
+return new ArrayList();
+}
+List qc = search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return qc;
+}
+
+@Override
+public QuotaCreditsVO saveCredits(final QuotaCreditsVO credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
--- End diff --

This transaction never appears to be closed.  Seems that a ``try { ... } 
finally { txn.close() }`` block is needed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582622
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java
 ---
@@ -0,0 +1,64 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaEmailTemplatesDao.class })
+public class QuotaEmailTemplatesDaoImpl extends 
GenericDaoBase implements QuotaEmailTemplatesDao {
+
+protected SearchBuilder 
QuotaEmailTemplateSearch;
+
+public QuotaEmailTemplatesDaoImpl() {
+super();
+
+QuotaEmailTemplateSearch = createSearchBuilder();
+QuotaEmailTemplateSearch.and("template_name", 
QuotaEmailTemplateSearch.entity().getTemplateName(), SearchCriteria.Op.EQ);
+QuotaEmailTemplateSearch.done();
+}
+
+@Override
+public List listAllQuotaEmailTemplates(String 
templateName) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+SearchCriteria sc = 
QuotaEmailTemplateSearch.create();
+if (templateName != null) {
+sc.setParameters("template_name", templateName);
+}
+List result = this.listBy(sc);
+TransactionLegacy.open(opendb).close();
--- End diff --

See previous comments regarding apparently needless open/close of a 
database transaction.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582759
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java
 ---
@@ -0,0 +1,64 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaEmailTemplatesDao.class })
+public class QuotaEmailTemplatesDaoImpl extends 
GenericDaoBase implements QuotaEmailTemplatesDao {
+
+protected SearchBuilder 
QuotaEmailTemplateSearch;
+
+public QuotaEmailTemplatesDaoImpl() {
+super();
+
+QuotaEmailTemplateSearch = createSearchBuilder();
+QuotaEmailTemplateSearch.and("template_name", 
QuotaEmailTemplateSearch.entity().getTemplateName(), SearchCriteria.Op.EQ);
+QuotaEmailTemplateSearch.done();
+}
+
+@Override
+public List listAllQuotaEmailTemplates(String 
templateName) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
--- End diff --

This transaction never appears to be closed.  Seems that a ``try { ... } 
finally { txn.close() }`` block is needed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37582819
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java
 ---
@@ -0,0 +1,64 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaEmailTemplatesDao.class })
+public class QuotaEmailTemplatesDaoImpl extends 
GenericDaoBase implements QuotaEmailTemplatesDao {
+
+protected SearchBuilder 
QuotaEmailTemplateSearch;
+
+public QuotaEmailTemplatesDaoImpl() {
+super();
+
+QuotaEmailTemplateSearch = createSearchBuilder();
+QuotaEmailTemplateSearch.and("template_name", 
QuotaEmailTemplateSearch.entity().getTemplateName(), SearchCriteria.Op.EQ);
+QuotaEmailTemplateSearch.done();
+}
+
+@Override
+public List listAllQuotaEmailTemplates(String 
templateName) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+SearchCriteria sc = 
QuotaEmailTemplateSearch.create();
+if (templateName != null) {
+sc.setParameters("template_name", templateName);
+}
+List result = this.listBy(sc);
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public boolean updateQuotaEmailTemplate(QuotaEmailTemplatesVO 
template) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+final boolean result = this.update(template.getId(), template);
+TransactionLegacy.open(opendb).close();
--- End diff --

This ``close`` call should be wrapped in a ``try { } finally { }`` block to 
ensure that transaction is closed in the event of an unchecked exception.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37583016
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
--- End diff --

Please remove commented code.  Git provides a better history of code 
changes without obscurity.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37583025
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
+return result.get(0);
+} else {
+//s_logger.info("Missing quota type " + quotaType);
--- End diff --

Please remove commented code.  Git provides a better history of code 
changes without obscurity.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37583163
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
+return result.get(0);
+} else {
+//s_logger.info("Missing quota type " + quotaType);
+return null;
+}
+}
+
+@Override
+public List listAllTariffPlans(final Date 
effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List tariffs = new ArrayList();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", 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.size() > 0) {
+tariffs.add(result.get(0));
+s_logger.info("listAllTariffPlans onorbefore" + 
effectiveDate +  "quota

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37583437
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
+return result.get(0);
+} else {
+//s_logger.info("Missing quota type " + quotaType);
+return null;
+}
+}
+
+@Override
+public List listAllTariffPlans(final Date 
effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List tariffs = new ArrayList();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", 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.size() > 0) {
+tariffs.add(result.get(0));
+s_logger.info("listAllTariffPlans onorbefore" + 
effectiveDate +  "quota

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37583449
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
+return result.get(0);
+} else {
+//s_logger.info("Missing quota type " + quotaType);
+return null;
+}
+}
+
+@Override
+public List listAllTariffPlans(final Date 
effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List tariffs = new ArrayList();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", 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.size() > 0) {
+tariffs.add(result.get(0));
+s_logger.info("listAllTariffPlans onorbefore" + 
effectiveDate +  "quota

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37583531
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.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.quota.dao;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaUsageVO;
+
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaUsageDao.class })
+public class QuotaUsageDaoImpl extends GenericDaoBase 
implements QuotaUsageDao {
+
+@Override
+public Pair, Integer> 
searchAndCountAllRecords(SearchCriteria sc, Filter filter) {
+return listAndCountIncludingRemovedBy(sc, filter);
+}
+
+@Override
+public void saveQuotaUsage(List records) {
+for (QuotaUsageVO usageRecord : records) {
+persist(usageRecord);
+}
+}
+
+@Override
+public BigDecimal findTotalQuotaUsage(final Long accountId, final Long 
domainId, final Integer usageType, final Date startDate, final Date endDate) {
+List quotaUsage = findQuotaUsage(accountId, 
domainId, null, startDate, endDate);
+BigDecimal total = new BigDecimal(0);
+for (final QuotaUsageVO quotaRecord : quotaUsage) {
+total = total.add(quotaRecord.getQuotaUsed());
+}
+return total;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public List findQuotaUsage(final Long accountId, final 
Long domainId, final Integer usageType, final Date startDate, final Date 
endDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+List quotaUsageRecords = null;
+try {
+// TODO instead of max value query with reasonable number and
+// iterate
+SearchCriteria sc = createSearchCriteria();
+if (accountId != null) {
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+}
+/*
+ * if (isDomainAdmin) { SearchCriteria sdc =
+ * _domainDao.createSearchCriteria(); sdc.addOr("path",
+ * SearchCriteria.Op.LIKE,
+ * _domainDao.findById(caller.getDomainId()).getPath() + "%");
+ * List domains = _domainDao.search(sdc, null); 
List
+ * domainIds = new ArrayList(); for (DomainVO domain :
+ * domains) domainIds.add(domain.getId()); 
sc.addAnd("domainId",
+ * SearchCriteria.Op.IN, domainIds.toArray());
+ * s_logger.debug("Account ID=" + accountId); }
+ */
--- End diff --

Please remove commented code as it is cruft that obscures the rest of the 
method. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37584764
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/ServiceOfferingDaoImpl.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.quota.dao;
+
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.ServiceOfferingVO;
+
+import com.cloud.event.UsageEventVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Component
+@Local(value = { ServiceOfferingDao.class })
+@DB()
+public class ServiceOfferingDaoImpl extends 
GenericDaoBase implements ServiceOfferingDao {
+protected static final Logger s_logger = 
Logger.getLogger(ServiceOfferingDaoImpl.class);
+
+@Inject
+UserVmDetailsDao userVmDetailsDao;
+
+@Override
+public ServiceOfferingVO findServiceOffering(final Long vmId, final 
long serviceOfferingId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
+ServiceOfferingVO result;
+try {
+result = findById(vmId, serviceOfferingId);
+} finally {
+txn.close();
+}
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+public ServiceOfferingVO findById(Long vmId, long serviceOfferingId) {
+ServiceOfferingVO offering = super.findById(serviceOfferingId);
+if (offering.isDynamic()) {
+offering.setDynamicFlag(true);
+if (vmId == null) {
+throw new CloudRuntimeException("missing argument vmId");
+}
--- End diff --

Move to the top of the method and consider using 
``com.google.common.base.Preconditions#checkArgument`` to check the argument.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37585801
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.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;
+
+import com.cloud.user.Account;
+import org.apache.cloudstack.api.APICommand;
+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.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.2.0", requestHasSensitiveInfo = false, 
responseHasSensitiveInfo = false)
--- End diff --

The ``since`` attribute says ``4.2.0``, but this API is new for ``4.6.0``.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37585845
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.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.api.command;
+
+import com.cloud.user.Account;
+
+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.DomainResponse;
+import org.apache.cloudstack.api.response.QuotaCreditsResponse;
+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;
+
+@APICommand(name = "quotaCredits", responseObject = 
QuotaCreditsResponse.class, description = "Add +-credits to an account", since 
= "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
--- End diff --

The ``since`` attribute says ``4.2.0``, but this API is new for ``4.6.0``.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37585892
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaStatementCmd.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.api.command;
+
+import java.util.Date;
+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.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.QuotaResponseBuilder;
+import org.apache.cloudstack.api.response.QuotaStatementResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.quota.vo.QuotaUsageVO;
+import org.apache.cloudstack.api.response.QuotaStatementItemResponse;
+
+import com.cloud.user.Account;
+
+@APICommand(name = "quotaStatement", responseObject = 
QuotaStatementItemResponse.class, description = "Create a quota statement", 
since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = 
false)
--- End diff --

The ``since`` attribute says ``4.2.0``, but this API is new for ``4.6.0``.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37586539
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.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.command;
+
+import com.cloud.user.Account;
+
+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.ListResponse;
+import org.apache.cloudstack.api.response.QuotaResponseBuilder;
+import org.apache.cloudstack.api.response.QuotaTariffResponse;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@APICommand(name = "quotaTariffList", responseObject = 
QuotaTariffResponse.class, description = "Lists all quota tariff plans", since 
= "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaTariffListCmd extends BaseListCmd {
+public static final Logger s_logger = 
Logger.getLogger(QuotaTariffListCmd.class.getName());
+private static final String s_name = "quotatarifflistresponse";
+
+@Inject
+QuotaResponseBuilder _responseBuilder;
+
+@Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, 
required = false, description = "Usage type of the resource")
+private Integer usageType;
+
+@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, 
required = false, description = "The effective start date on/after which the 
quota tariff is effective and older tariffs are no longer used for the usage 
type. Use -MM-dd as the date format, e.g. startDate=2009-06-03.")
+private Date effectiveDate;
+
+public QuotaTariffListCmd() {
+super();
+}
+
+@Override
+public void execute() {
+final List result = 
_responseBuilder.listQuotaTariffPlans(this);
+
+final List responses = new 
ArrayList();
+for (final QuotaTariffVO resource : result) {
+s_logger.info("Result desc=" + resource.getDescription() + " 
date=" + resource.getEffectiveOn() + " val=" + resource.getCurrencyValue());
--- End diff --

This message seems like a DEBUG rather than INFO level.  To my way of 
thinking, an INFO level message should provide information that a system 
administrator can use to understand the operation of the system.  This message 
does not appear to provide such information.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37586787
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java
 ---
@@ -0,0 +1,419 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.api.command.QuotaBalanceCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
+import org.apache.cloudstack.api.command.QuotaStatementCmd;
+import org.apache.cloudstack.api.command.QuotaTariffListCmd;
+import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
+import org.apache.cloudstack.quota.QuotaService;
+import org.apache.cloudstack.quota.constant.QuotaConfig;
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
+import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
+import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
+import org.apache.cloudstack.quota.dao.QuotaTariffDao;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+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.region.RegionManager;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+@Component
+@Local(value = QuotaResponseBuilderImpl.class)
+public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
+private static final Logger s_logger = 
Logger.getLogger(QuotaResponseBuilderImpl.class.getName());
+
+@Inject
+private QuotaTariffDao _quotaTariffDao;
+@Inject
+private QuotaBalanceDao _quotaBalanceDao;
+@Inject
+private QuotaCreditsDao _quotaCreditsDao;
+@Inject
+private QuotaEmailTemplatesDao _quotaEmailTemplateDao;
+
+@Inject
+private UserDao _userDao;
+@Inject
+private QuotaService _quotaService;
+@Inject
+AccountDao _accountDao;
+@Inject
+private RegionManager _regionMgr;
+
+@Override
+public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO 
tariff) {
+final QuotaTariffResponse response = new QuotaTariffResponse();
+response.setUsageType(tariff.getUsageType());
+response.setUsageName(tariff.getUsageName());
+response.setUsageUnit(tariff.getUsageUnit());
+response.setUsageDiscriminator(tariff.getUsageDiscriminator());
+response.setTariffValue(tariff.getCurrencyValue());
+response.setEffectiveOn(tariff.getEffectiveOn());
+response.setDescription(tariff.getDescription());
+response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
+return response;
+}
+
+@Override
+public QuotaBalanceResponse 
createQuotaBalanceResponse(List quotaBalance, Date startDate, 
Date endDate) {
+if (quotaBalance.size() == 0) {
--- End diff --

In order to avoid a ``NullPointerException``, this ``

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37586853
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java
 ---
@@ -0,0 +1,419 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.api.command.QuotaBalanceCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
+import org.apache.cloudstack.api.command.QuotaStatementCmd;
+import org.apache.cloudstack.api.command.QuotaTariffListCmd;
+import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
+import org.apache.cloudstack.quota.QuotaService;
+import org.apache.cloudstack.quota.constant.QuotaConfig;
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
+import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
+import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
+import org.apache.cloudstack.quota.dao.QuotaTariffDao;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+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.region.RegionManager;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+@Component
+@Local(value = QuotaResponseBuilderImpl.class)
+public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
+private static final Logger s_logger = 
Logger.getLogger(QuotaResponseBuilderImpl.class.getName());
+
+@Inject
+private QuotaTariffDao _quotaTariffDao;
+@Inject
+private QuotaBalanceDao _quotaBalanceDao;
+@Inject
+private QuotaCreditsDao _quotaCreditsDao;
+@Inject
+private QuotaEmailTemplatesDao _quotaEmailTemplateDao;
+
+@Inject
+private UserDao _userDao;
+@Inject
+private QuotaService _quotaService;
+@Inject
+AccountDao _accountDao;
+@Inject
+private RegionManager _regionMgr;
+
+@Override
+public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO 
tariff) {
+final QuotaTariffResponse response = new QuotaTariffResponse();
+response.setUsageType(tariff.getUsageType());
+response.setUsageName(tariff.getUsageName());
+response.setUsageUnit(tariff.getUsageUnit());
+response.setUsageDiscriminator(tariff.getUsageDiscriminator());
+response.setTariffValue(tariff.getCurrencyValue());
+response.setEffectiveOn(tariff.getEffectiveOn());
+response.setDescription(tariff.getDescription());
+response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
+return response;
+}
+
+@Override
+public QuotaBalanceResponse 
createQuotaBalanceResponse(List quotaBalance, Date startDate, 
Date endDate) {
+if (quotaBalance.size() == 0) {
+new InvalidParameterValueException("The request period does 
not 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37586898
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java
 ---
@@ -0,0 +1,419 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.api.command.QuotaBalanceCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
+import org.apache.cloudstack.api.command.QuotaStatementCmd;
+import org.apache.cloudstack.api.command.QuotaTariffListCmd;
+import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
+import org.apache.cloudstack.quota.QuotaService;
+import org.apache.cloudstack.quota.constant.QuotaConfig;
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
+import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
+import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
+import org.apache.cloudstack.quota.dao.QuotaTariffDao;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+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.region.RegionManager;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+@Component
+@Local(value = QuotaResponseBuilderImpl.class)
+public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
+private static final Logger s_logger = 
Logger.getLogger(QuotaResponseBuilderImpl.class.getName());
+
+@Inject
+private QuotaTariffDao _quotaTariffDao;
+@Inject
+private QuotaBalanceDao _quotaBalanceDao;
+@Inject
+private QuotaCreditsDao _quotaCreditsDao;
+@Inject
+private QuotaEmailTemplatesDao _quotaEmailTemplateDao;
+
+@Inject
+private UserDao _userDao;
+@Inject
+private QuotaService _quotaService;
+@Inject
+AccountDao _accountDao;
+@Inject
+private RegionManager _regionMgr;
+
+@Override
+public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO 
tariff) {
+final QuotaTariffResponse response = new QuotaTariffResponse();
+response.setUsageType(tariff.getUsageType());
+response.setUsageName(tariff.getUsageName());
+response.setUsageUnit(tariff.getUsageUnit());
+response.setUsageDiscriminator(tariff.getUsageDiscriminator());
+response.setTariffValue(tariff.getCurrencyValue());
+response.setEffectiveOn(tariff.getEffectiveOn());
+response.setDescription(tariff.getDescription());
+response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
+return response;
+}
+
+@Override
+public QuotaBalanceResponse 
createQuotaBalanceResponse(List quotaBalance, Date startDate, 
Date endDate) {
+if (quotaBalance.size() == 0) {
+new InvalidParameterValueException("The request period does 
not 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37587109
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java
 ---
@@ -0,0 +1,419 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.api.command.QuotaBalanceCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
+import org.apache.cloudstack.api.command.QuotaStatementCmd;
+import org.apache.cloudstack.api.command.QuotaTariffListCmd;
+import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
+import org.apache.cloudstack.quota.QuotaService;
+import org.apache.cloudstack.quota.constant.QuotaConfig;
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
+import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
+import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
+import org.apache.cloudstack.quota.dao.QuotaTariffDao;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+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.region.RegionManager;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+@Component
+@Local(value = QuotaResponseBuilderImpl.class)
+public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
+private static final Logger s_logger = 
Logger.getLogger(QuotaResponseBuilderImpl.class.getName());
+
+@Inject
+private QuotaTariffDao _quotaTariffDao;
+@Inject
+private QuotaBalanceDao _quotaBalanceDao;
+@Inject
+private QuotaCreditsDao _quotaCreditsDao;
+@Inject
+private QuotaEmailTemplatesDao _quotaEmailTemplateDao;
+
+@Inject
+private UserDao _userDao;
+@Inject
+private QuotaService _quotaService;
+@Inject
+AccountDao _accountDao;
+@Inject
+private RegionManager _regionMgr;
+
+@Override
+public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO 
tariff) {
+final QuotaTariffResponse response = new QuotaTariffResponse();
+response.setUsageType(tariff.getUsageType());
+response.setUsageName(tariff.getUsageName());
+response.setUsageUnit(tariff.getUsageUnit());
+response.setUsageDiscriminator(tariff.getUsageDiscriminator());
+response.setTariffValue(tariff.getCurrencyValue());
+response.setEffectiveOn(tariff.getEffectiveOn());
+response.setDescription(tariff.getDescription());
+response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
+return response;
+}
+
+@Override
+public QuotaBalanceResponse 
createQuotaBalanceResponse(List quotaBalance, Date startDate, 
Date endDate) {
+if (quotaBalance.size() == 0) {
+new InvalidParameterValueException("The request period does 
not 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37587088
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java
 ---
@@ -0,0 +1,419 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.api.command.QuotaBalanceCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
+import org.apache.cloudstack.api.command.QuotaStatementCmd;
+import org.apache.cloudstack.api.command.QuotaTariffListCmd;
+import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
+import org.apache.cloudstack.quota.QuotaService;
+import org.apache.cloudstack.quota.constant.QuotaConfig;
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
+import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
+import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
+import org.apache.cloudstack.quota.dao.QuotaTariffDao;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+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.region.RegionManager;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+@Component
+@Local(value = QuotaResponseBuilderImpl.class)
+public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
+private static final Logger s_logger = 
Logger.getLogger(QuotaResponseBuilderImpl.class.getName());
+
+@Inject
+private QuotaTariffDao _quotaTariffDao;
+@Inject
+private QuotaBalanceDao _quotaBalanceDao;
+@Inject
+private QuotaCreditsDao _quotaCreditsDao;
+@Inject
+private QuotaEmailTemplatesDao _quotaEmailTemplateDao;
+
+@Inject
+private UserDao _userDao;
+@Inject
+private QuotaService _quotaService;
+@Inject
+AccountDao _accountDao;
+@Inject
+private RegionManager _regionMgr;
+
+@Override
+public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO 
tariff) {
+final QuotaTariffResponse response = new QuotaTariffResponse();
+response.setUsageType(tariff.getUsageType());
+response.setUsageName(tariff.getUsageName());
+response.setUsageUnit(tariff.getUsageUnit());
+response.setUsageDiscriminator(tariff.getUsageDiscriminator());
+response.setTariffValue(tariff.getCurrencyValue());
+response.setEffectiveOn(tariff.getEffectiveOn());
+response.setDescription(tariff.getDescription());
+response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
+return response;
+}
+
+@Override
+public QuotaBalanceResponse 
createQuotaBalanceResponse(List quotaBalance, Date startDate, 
Date endDate) {
+if (quotaBalance.size() == 0) {
+new InvalidParameterValueException("The request period does 
not 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37587187
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java
 ---
@@ -0,0 +1,419 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.api.command.QuotaBalanceCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
+import org.apache.cloudstack.api.command.QuotaStatementCmd;
+import org.apache.cloudstack.api.command.QuotaTariffListCmd;
+import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
+import org.apache.cloudstack.quota.QuotaService;
+import org.apache.cloudstack.quota.constant.QuotaConfig;
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
+import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
+import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
+import org.apache.cloudstack.quota.dao.QuotaTariffDao;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+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.region.RegionManager;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+@Component
+@Local(value = QuotaResponseBuilderImpl.class)
+public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
+private static final Logger s_logger = 
Logger.getLogger(QuotaResponseBuilderImpl.class.getName());
+
+@Inject
+private QuotaTariffDao _quotaTariffDao;
+@Inject
+private QuotaBalanceDao _quotaBalanceDao;
+@Inject
+private QuotaCreditsDao _quotaCreditsDao;
+@Inject
+private QuotaEmailTemplatesDao _quotaEmailTemplateDao;
+
+@Inject
+private UserDao _userDao;
+@Inject
+private QuotaService _quotaService;
+@Inject
+AccountDao _accountDao;
+@Inject
+private RegionManager _regionMgr;
+
+@Override
+public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO 
tariff) {
+final QuotaTariffResponse response = new QuotaTariffResponse();
+response.setUsageType(tariff.getUsageType());
+response.setUsageName(tariff.getUsageName());
+response.setUsageUnit(tariff.getUsageUnit());
+response.setUsageDiscriminator(tariff.getUsageDiscriminator());
+response.setTariffValue(tariff.getCurrencyValue());
+response.setEffectiveOn(tariff.getEffectiveOn());
+response.setDescription(tariff.getDescription());
+response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
+return response;
+}
+
+@Override
+public QuotaBalanceResponse 
createQuotaBalanceResponse(List quotaBalance, Date startDate, 
Date endDate) {
+if (quotaBalance.size() == 0) {
+new InvalidParameterValueException("The request period does 
not 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37587233
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java
 ---
@@ -0,0 +1,419 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.api.command.QuotaBalanceCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd;
+import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd;
+import org.apache.cloudstack.api.command.QuotaStatementCmd;
+import org.apache.cloudstack.api.command.QuotaTariffListCmd;
+import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
+import org.apache.cloudstack.quota.QuotaService;
+import org.apache.cloudstack.quota.constant.QuotaConfig;
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.dao.QuotaBalanceDao;
+import org.apache.cloudstack.quota.dao.QuotaCreditsDao;
+import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao;
+import org.apache.cloudstack.quota.dao.QuotaTariffDao;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+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.region.RegionManager;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+@Component
+@Local(value = QuotaResponseBuilderImpl.class)
+public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
+private static final Logger s_logger = 
Logger.getLogger(QuotaResponseBuilderImpl.class.getName());
+
+@Inject
+private QuotaTariffDao _quotaTariffDao;
+@Inject
+private QuotaBalanceDao _quotaBalanceDao;
+@Inject
+private QuotaCreditsDao _quotaCreditsDao;
+@Inject
+private QuotaEmailTemplatesDao _quotaEmailTemplateDao;
+
+@Inject
+private UserDao _userDao;
+@Inject
+private QuotaService _quotaService;
+@Inject
+AccountDao _accountDao;
+@Inject
+private RegionManager _regionMgr;
+
+@Override
+public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO 
tariff) {
+final QuotaTariffResponse response = new QuotaTariffResponse();
+response.setUsageType(tariff.getUsageType());
+response.setUsageName(tariff.getUsageName());
+response.setUsageUnit(tariff.getUsageUnit());
+response.setUsageDiscriminator(tariff.getUsageDiscriminator());
+response.setTariffValue(tariff.getCurrencyValue());
+response.setEffectiveOn(tariff.getEffectiveOn());
+response.setDescription(tariff.getDescription());
+response.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
+return response;
+}
+
+@Override
+public QuotaBalanceResponse 
createQuotaBalanceResponse(List quotaBalance, Date startDate, 
Date endDate) {
+if (quotaBalance.size() == 0) {
+new InvalidParameterValueException("The request period does 
not 

Re: Question regarding @Local usage on CS

2015-08-20 Thread Rafael Weingärtner
I have just checked now, that annotation is not making any sense to me. Why
would you use EJB annotation on spring beans!?

On Thu, Aug 20, 2015 at 10:46 AM, Rafael Weingärtner <
rafaelweingart...@gmail.com> wrote:

> Hi folks,
> I noticed that CloudStack uses EJB alongside with Spring.
>
> I am trying to understand the use of @Local, are beans of classes marked
> with @Local singletons?
>
> --
> Rafael Weingärtner
>



-- 
Rafael Weingärtner


Re: Problems with first steps of CS plugin development

2015-08-20 Thread Abhinandan Prateek
The document is bit outdated, you need to do following three things:

1. You need to add the new cmd in ManagementServerImpl.getCommands() or your 
impl of pluggable service as:

2. Then you need to tell spring that the above is a bean and exists "”
This should be in “-context.xml” inside resources folder of your 
plugin.

3. You need to add your command in command.properties.in with proper access 
flag.

-abhi


> On 20-Aug-2015, at 5:47 pm, Giebner, Sascha  
> wrote:
>
> Hello guys,
>
> I'm trying to complete this tutorial for the development of a Cloudstack API 
> plugin:
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/CloudStack+API+Development
>
> I checked out the latest version from the cloudstack master and followed the 
> tutorial to the letter, however when I try to call the API, I always get the 
> following JSON response:
>
> {"errorresponse":{"uuidList":[],"errorcode":432,"cserrorcode":,"errortext":"Unknown
>  API command: getTimeOfDay"}}
>
> I've been digging around in the cloudstack code, unfortunately with no 
> success until now. Everything compiles fine, so I suspect there may be 
> something wrong with the maven configuration. However since this is my first 
> time using maven, I'm a bit overwhelmed.
> Do you have some hints for me?
>
> Thanks and best regards,
> Sascha Giebner
>
> --
> This email was Virus checked by UTM 9. http://www.sophos.com

Find out more about ShapeBlue and our range of CloudStack related services

IaaS Cloud Design & Build
CSForge – rapid IaaS deployment framework
CloudStack Consulting
CloudStack Software 
Engineering
CloudStack Infrastructure 
Support
CloudStack Bootcamp Training Courses

This email and any attachments to it may be confidential and are intended 
solely for the use of the individual to whom it is addressed. Any views or 
opinions expressed are solely those of the author and do not necessarily 
represent those of Shape Blue Ltd or related companies. If you are not the 
intended recipient of this email, you must neither take any action based upon 
its contents, nor copy or show it to anyone. Please contact the sender if you 
believe you have received this email in error. Shape Blue Ltd is a company 
incorporated in England & Wales. ShapeBlue Services India LLP is a company 
incorporated in India and is operated under license from Shape Blue Ltd. Shape 
Blue Brasil Consultoria Ltda is a company incorporated in Brasil and is 
operated under license from Shape Blue Ltd. ShapeBlue SA Pty Ltd is a company 
registered by The Republic of South Africa and is traded under license from 
Shape Blue Ltd. ShapeBlue is a registered trademark.


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37604919
  
--- Diff: engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java ---
@@ -469,4 +478,25 @@ public void removeOldUsageRecords(int days) {
 txn.close();
 }
 }
+
+@SuppressWarnings("deprecation")
+public Pair, Integer> 
getUsageRecordsPendingQuotaAggregation(final long accountId, final long 
domainId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+s_logger.debug("getting usage records for account: " + accountId + 
", domainId: " + domainId);
+Filter usageFilter = new Filter(UsageVO.class, "startDate", true, 
0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+if (accountId != -1) {
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+}
+if (domainId != -1) {
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+}
+sc.addAnd("quotaCalculated", SearchCriteria.Op.NULL);
+sc.addOr("quotaCalculated", SearchCriteria.Op.EQ, 0);
+s_logger.debug("Getting usage records" + usageFilter.getOrderBy());
+Pair, Integer> usageRecords = 
searchAndCountAllRecords(sc, usageFilter);
+TransactionLegacy.open(opendb).close();
--- End diff --

This is to switch database.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37604903
  
--- Diff: engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java ---
@@ -469,4 +478,25 @@ public void removeOldUsageRecords(int days) {
 txn.close();
 }
 }
+
+@SuppressWarnings("deprecation")
+public Pair, Integer> 
getUsageRecordsPendingQuotaAggregation(final long accountId, final long 
domainId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
--- End diff --

This is to switch database from CLOUD_DB to USAGE_DB.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37604908
  
--- Diff: engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java ---
@@ -469,4 +478,25 @@ public void removeOldUsageRecords(int days) {
 txn.close();
 }
 }
+
+@SuppressWarnings("deprecation")
+public Pair, Integer> 
getUsageRecordsPendingQuotaAggregation(final long accountId, final long 
domainId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+s_logger.debug("getting usage records for account: " + accountId + 
", domainId: " + domainId);
--- End diff --

Accepted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37604922
  
--- Diff: engine/schema/src/com/cloud/usage/dao/UsageDaoImpl.java ---
@@ -469,4 +478,25 @@ public void removeOldUsageRecords(int days) {
 txn.close();
 }
 }
+
+@SuppressWarnings("deprecation")
+public Pair, Integer> 
getUsageRecordsPendingQuotaAggregation(final long accountId, final long 
domainId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+s_logger.debug("getting usage records for account: " + accountId + 
", domainId: " + domainId);
+Filter usageFilter = new Filter(UsageVO.class, "startDate", true, 
0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+if (accountId != -1) {
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+}
+if (domainId != -1) {
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+}
+sc.addAnd("quotaCalculated", SearchCriteria.Op.NULL);
+sc.addOr("quotaCalculated", SearchCriteria.Op.EQ, 0);
+s_logger.debug("Getting usage records" + usageFilter.getOrderBy());
--- End diff --

Accepted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605032
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/constant/QuotaTypes.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.quota.constant;
+
+import org.apache.cloudstack.usage.UsageTypes;
+
+import java.util.HashMap;
+
+public class QuotaTypes extends UsageTypes {
+public static final int CPU_CLOCK_RATE = 15;
+public static final int CPU_NUMBER = 16;
+public static final int MEMORY = 17;
+
+private Integer quotaType;
+private String quotaName;
+private String quotaUnit;
+private String description;
+private String discriminator;
--- End diff --

Accepted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605101
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/constant/QuotaTypes.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.quota.constant;
+
+import org.apache.cloudstack.usage.UsageTypes;
+
+import java.util.HashMap;
+
+public class QuotaTypes extends UsageTypes {
+public static final int CPU_CLOCK_RATE = 15;
+public static final int CPU_NUMBER = 16;
+public static final int MEMORY = 17;
+
+private Integer quotaType;
+private String quotaName;
+private String quotaUnit;
+private String description;
+private String discriminator;
+
+public QuotaTypes(Integer quotaType, String name, String unit, String 
description) {
+this.quotaType = quotaType;
+this.description = description;
+this.quotaName = name;
+this.quotaUnit = unit;
+this.discriminator = "None";
+}
+
+public static HashMap listQuotaTypes() {
+final HashMap quotaTypeList = new 
HashMap();
+quotaTypeList.put(new Integer(RUNNING_VM), new QuotaTypes(new 
Integer(RUNNING_VM), "RUNNING_VM", "Compute-Month", "Running Vm Usage"));
--- End diff --

These are defined in usage server and the idea was to avoid changes to 
existing code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605166
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/constant/QuotaTypes.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.quota.constant;
+
+import org.apache.cloudstack.usage.UsageTypes;
+
+import java.util.HashMap;
+
+public class QuotaTypes extends UsageTypes {
+public static final int CPU_CLOCK_RATE = 15;
+public static final int CPU_NUMBER = 16;
+public static final int MEMORY = 17;
+
+private Integer quotaType;
+private String quotaName;
+private String quotaUnit;
+private String description;
+private String discriminator;
+
+public QuotaTypes(Integer quotaType, String name, String unit, String 
description) {
+this.quotaType = quotaType;
+this.description = description;
+this.quotaName = name;
+this.quotaUnit = unit;
+this.discriminator = "None";
+}
+
+public static HashMap listQuotaTypes() {
--- End diff --

Yes, should be declared static.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605231
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDao.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.quota.dao;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface QuotaBalanceDao extends GenericDao {
+
+void saveQuotaBalance(List credits);
+
+List findCreditBalance(long accountId, long domainId, 
Date startDate, Date endDate);
--- End diff --

Will check.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605238
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLaterBalanceEntry(final long accountId, 
final long domainId, final Date afterThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.GT, afterThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@Override
+public void saveQuotaBalance(final List credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+for (QuotaBalanceVO credit : credits) {
+persist(credit);
+}
+} finally {
+txn.close();
+}
+TransactionLegacy.open(opendb).close();
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCreditBalance(final long accountId, 
final long domainId, final Date lastbalancedate, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accoun

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605235
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.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.quota.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaAccountDao.class })
+public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao {
+
+@Override
+public List listAll() {
+List result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
--- End diff --

comment as above,


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605216
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/constant/QuotaTypes.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.quota.constant;
+
+import org.apache.cloudstack.usage.UsageTypes;
+
+import java.util.HashMap;
+
+public class QuotaTypes extends UsageTypes {
+public static final int CPU_CLOCK_RATE = 15;
+public static final int CPU_NUMBER = 16;
+public static final int MEMORY = 17;
+
+private Integer quotaType;
+private String quotaName;
+private String quotaUnit;
+private String description;
+private String discriminator;
+
+public QuotaTypes(Integer quotaType, String name, String unit, String 
description) {
+this.quotaType = quotaType;
+this.description = description;
+this.quotaName = name;
+this.quotaUnit = unit;
+this.discriminator = "None";
+}
+
+public static HashMap listQuotaTypes() {
+final HashMap quotaTypeList = new 
HashMap();
+quotaTypeList.put(new Integer(RUNNING_VM), new QuotaTypes(new 
Integer(RUNNING_VM), "RUNNING_VM", "Compute-Month", "Running Vm Usage"));
+quotaTypeList.put(new Integer(ALLOCATED_VM), new QuotaTypes(new 
Integer(ALLOCATED_VM), "ALLOCATED_VM", "Compute-Month", "Allocated Vm Usage"));
+quotaTypeList.put(new Integer(IP_ADDRESS), new QuotaTypes(new 
Integer(IP_ADDRESS), "IP_ADDRESS", "IP-Month", "IP Address Usage"));
+quotaTypeList.put(new Integer(NETWORK_BYTES_SENT), new 
QuotaTypes(new Integer(NETWORK_BYTES_SENT), "NETWORK_BYTES_SENT", "GB", 
"Network Usage (Bytes Sent)"));
+quotaTypeList.put(new Integer(NETWORK_BYTES_RECEIVED), new 
QuotaTypes(new Integer(NETWORK_BYTES_RECEIVED), "NETWORK_BYTES_RECEIVED", "GB", 
"Network Usage (Bytes Received)"));
+quotaTypeList.put(new Integer(VOLUME), new QuotaTypes(new 
Integer(VOLUME), "VOLUME", "GB-Month", "Volume Usage"));
+quotaTypeList.put(new Integer(TEMPLATE), new QuotaTypes(new 
Integer(TEMPLATE), "TEMPLATE", "GB-Month", "Template Usage"));
+quotaTypeList.put(new Integer(ISO), new QuotaTypes(new 
Integer(ISO), "ISO", "GB-Month", "ISO Usage"));
+quotaTypeList.put(new Integer(SNAPSHOT), new QuotaTypes(new 
Integer(SNAPSHOT), "SNAPSHOT", "GB-Month", "Snapshot Usage"));
+quotaTypeList.put(new Integer(SECURITY_GROUP), new QuotaTypes(new 
Integer(SECURITY_GROUP), "SECURITY_GROUP", "Policy-Month", "Security Group 
Usage"));
+quotaTypeList.put(new Integer(LOAD_BALANCER_POLICY), new 
QuotaTypes(new Integer(LOAD_BALANCER_POLICY), "LOAD_BALANCER_POLICY", 
"Policy-Month", "Load Balancer Usage"));
+quotaTypeList.put(new Integer(PORT_FORWARDING_RULE), new 
QuotaTypes(new Integer(PORT_FORWARDING_RULE), "PORT_FORWARDING_RULE", 
"Policy-Month", "Port Forwarding Usage"));
+quotaTypeList.put(new Integer(NETWORK_OFFERING), new 
QuotaTypes(new Integer(NETWORK_OFFERING), "NETWORK_OFFERING", "Policy-Month", 
"Network Offering Usage"));
+quotaTypeList.put(new Integer(VPN_USERS), new QuotaTypes(new 
Integer(VPN_USERS), "VPN_USERS", "Policy-Month", "VPN users usage"));
+quotaTypeList.put(new Integer(VM_DISK_IO_READ), new QuotaTypes(new 
Integer(VM_DISK_IO_READ), "VM_DISK_IO_READ", "GB", "VM Disk usage(I/O Read)"));
+quotaTypeList.put(new Integer(VM_DISK_IO_WRITE), new 
QuotaTypes(new Integer(VM_DISK_IO_WRITE), "VM_DISK_IO_WRITE", "GB", "VM Disk 
usage(I/O Write)"));
+quotaTypeList.put(new Integer(VM_DISK_BYTES_READ), new 
QuotaTypes(new Integer(VM_DISK_BYTES_READ), "VM_DISK_BYTES_READ", "GB", "VM 
Disk usage(Bytes Read)"));
+quotaTypeList.put(new Integer(VM_DISK_BYTES_WRITE), new 
QuotaTypes(new Integer(VM_DISK_BYTES_WRITE), "VPN_USERS", "GB", "VM Disk 
usage(Bytes Write)"));
+quotaTypeList.put(new 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605243
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLaterBalanceEntry(final long accountId, 
final long domainId, final Date afterThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.GT, afterThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@Override
+public void saveQuotaBalance(final List credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+for (QuotaBalanceVO credit : credits) {
+persist(credit);
+}
+} finally {
+txn.close();
+}
+TransactionLegacy.open(opendb).close();
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCreditBalance(final long accountId, 
final long domainId, final Date lastbalancedate, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accoun

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605247
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLaterBalanceEntry(final long accountId, 
final long domainId, final Date afterThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.GT, afterThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605260
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.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.quota.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaAccountDao.class })
+public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao {
+
+@Override
+public List listAll() {
+List result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.listAll();
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO findById(Long id) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.findById(id);
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO persist(QuotaAccountVO entity) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.persist(entity);
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public boolean update(Long id, QuotaAccountVO entity) {
+boolean result = false;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.update(id, entity);
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605251
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605245
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLaterBalanceEntry(final long accountId, 
final long domainId, final Date afterThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
true, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.GT, afterThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return quotab.size() > 0 ? quotab.get(0) : null;
+}
+
+@Override
+public void saveQuotaBalance(final List credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+for (QuotaBalanceVO credit : credits) {
+persist(credit);
+}
+} finally {
+txn.close();
+}
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605257
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java ---
@@ -0,0 +1,201 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaBalanceDao.class })
+public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao {
+private static final Logger s_logger = 
Logger.getLogger(QuotaBalanceDaoImpl.class.getName());
+
+@SuppressWarnings("deprecation")
+@Override
+public QuotaBalanceVO findLastBalanceEntry(final long accountId, final 
long domainId, final Date beforeThis) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", 
false, 0L, 1L);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+sc.addAnd("creditsId", SearchCriteria.Op.EQ, 0);
+sc.addAnd("updatedOn", SearchCriteria.Op.LT, beforeThis);
+List quotab = this.search(sc, filter);
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605263
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.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.quota.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaAccountDao.class })
+public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao {
+
+@Override
+public List listAll() {
+List result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.listAll();
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO findById(Long id) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.findById(id);
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO persist(QuotaAccountVO entity) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.persist(entity);
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605268
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.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.quota.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.cloudstack.quota.vo.QuotaAccountVO;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaAccountDao.class })
+public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao {
+
+@Override
+public List listAll() {
+List result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.listAll();
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public QuotaAccountVO findById(Long id) {
+QuotaAccountVO result = null;
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB).close();
+result = super.findById(id);
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605276
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaCreditsDaoImpl.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.quota.dao;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaCreditsDao.class })
+public class QuotaCreditsDaoImpl extends GenericDaoBase implements QuotaCreditsDao {
+@Inject
+QuotaBalanceDao _quotaBalanceDao;
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCredits(final long accountId, final 
long domainId, final Date startDate, final Date endDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+Filter filter = new Filter(QuotaCreditsVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+if ((startDate != null) && (endDate != null) && 
startDate.before(endDate)) {
+sc.addAnd("updatedOn", SearchCriteria.Op.BETWEEN, startDate, 
endDate);
+} else {
+return new ArrayList();
+}
+List qc = search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return qc;
+}
+
+@Override
+public QuotaCreditsVO saveCredits(final QuotaCreditsVO credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+persist(credits);
+// make an entry in the balance table
+QuotaBalanceVO bal = new QuotaBalanceVO(credits);
+_quotaBalanceDao.persist(bal);
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605271
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaCreditsDaoImpl.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.quota.dao;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaCreditsDao.class })
+public class QuotaCreditsDaoImpl extends GenericDaoBase implements QuotaCreditsDao {
+@Inject
+QuotaBalanceDao _quotaBalanceDao;
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCredits(final long accountId, final 
long domainId, final Date startDate, final Date endDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+Filter filter = new Filter(QuotaCreditsVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+if ((startDate != null) && (endDate != null) && 
startDate.before(endDate)) {
+sc.addAnd("updatedOn", SearchCriteria.Op.BETWEEN, startDate, 
endDate);
+} else {
+return new ArrayList();
+}
+List qc = search(sc, filter);
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605319
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java
 ---
@@ -0,0 +1,64 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaEmailTemplatesDao.class })
+public class QuotaEmailTemplatesDaoImpl extends 
GenericDaoBase implements QuotaEmailTemplatesDao {
+
+protected SearchBuilder 
QuotaEmailTemplateSearch;
+
+public QuotaEmailTemplatesDaoImpl() {
+super();
+
+QuotaEmailTemplateSearch = createSearchBuilder();
+QuotaEmailTemplateSearch.and("template_name", 
QuotaEmailTemplateSearch.entity().getTemplateName(), SearchCriteria.Op.EQ);
+QuotaEmailTemplateSearch.done();
+}
+
+@Override
+public List listAllQuotaEmailTemplates(String 
templateName) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+SearchCriteria sc = 
QuotaEmailTemplateSearch.create();
+if (templateName != null) {
+sc.setParameters("template_name", templateName);
+}
+List result = this.listBy(sc);
+TransactionLegacy.open(opendb).close();
--- End diff --

check above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605311
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaCreditsDaoImpl.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.quota.dao;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaBalanceVO;
+import org.apache.cloudstack.quota.vo.QuotaCreditsVO;
+
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaCreditsDao.class })
+public class QuotaCreditsDaoImpl extends GenericDaoBase implements QuotaCreditsDao {
+@Inject
+QuotaBalanceDao _quotaBalanceDao;
+
+@SuppressWarnings("deprecation")
+@Override
+public List findCredits(final long accountId, final 
long domainId, final Date startDate, final Date endDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+Filter filter = new Filter(QuotaCreditsVO.class, "updatedOn", 
true, 0L, Long.MAX_VALUE);
+SearchCriteria sc = createSearchCriteria();
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+if ((startDate != null) && (endDate != null) && 
startDate.before(endDate)) {
+sc.addAnd("updatedOn", SearchCriteria.Op.BETWEEN, startDate, 
endDate);
+} else {
+return new ArrayList();
+}
+List qc = search(sc, filter);
+TransactionLegacy.open(opendb).close();
+return qc;
+}
+
+@Override
+public QuotaCreditsVO saveCredits(final QuotaCreditsVO credits) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
--- End diff --

Accepted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605332
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java
 ---
@@ -0,0 +1,64 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaEmailTemplatesDao.class })
+public class QuotaEmailTemplatesDaoImpl extends 
GenericDaoBase implements QuotaEmailTemplatesDao {
+
+protected SearchBuilder 
QuotaEmailTemplateSearch;
+
+public QuotaEmailTemplatesDaoImpl() {
+super();
+
+QuotaEmailTemplateSearch = createSearchBuilder();
+QuotaEmailTemplateSearch.and("template_name", 
QuotaEmailTemplateSearch.entity().getTemplateName(), SearchCriteria.Op.EQ);
+QuotaEmailTemplateSearch.done();
+}
+
+@Override
+public List listAllQuotaEmailTemplates(String 
templateName) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
--- End diff --

Accepted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605350
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
+return result.get(0);
+} else {
+//s_logger.info("Missing quota type " + quotaType);
--- End diff --

ok


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605358
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
+return result.get(0);
+} else {
+//s_logger.info("Missing quota type " + quotaType);
+return null;
+}
+}
+
+@Override
+public List listAllTariffPlans(final Date 
effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List tariffs = new ArrayList();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", 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.size() > 0) {
+tariffs.add(result.get(0));
+s_logger.info("listAllTariffPlans onorbefore" + 
effectiveDate 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605339
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java
 ---
@@ -0,0 +1,64 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaEmailTemplatesDao.class })
+public class QuotaEmailTemplatesDaoImpl extends 
GenericDaoBase implements QuotaEmailTemplatesDao {
+
+protected SearchBuilder 
QuotaEmailTemplateSearch;
+
+public QuotaEmailTemplatesDaoImpl() {
+super();
+
+QuotaEmailTemplateSearch = createSearchBuilder();
+QuotaEmailTemplateSearch.and("template_name", 
QuotaEmailTemplateSearch.entity().getTemplateName(), SearchCriteria.Op.EQ);
+QuotaEmailTemplateSearch.done();
+}
+
+@Override
+public List listAllQuotaEmailTemplates(String 
templateName) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+SearchCriteria sc = 
QuotaEmailTemplateSearch.create();
+if (templateName != null) {
+sc.setParameters("template_name", templateName);
+}
+List result = this.listBy(sc);
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+@Override
+public boolean updateQuotaEmailTemplate(QuotaEmailTemplatesVO 
template) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+final boolean result = this.update(template.getId(), template);
+TransactionLegacy.open(opendb).close();
--- End diff --

Accpeted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605347
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
--- End diff --

ok


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605369
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
+return result.get(0);
+} else {
+//s_logger.info("Missing quota type " + quotaType);
+return null;
+}
+}
+
+@Override
+public List listAllTariffPlans(final Date 
effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List tariffs = new ArrayList();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", 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.size() > 0) {
+tariffs.add(result.get(0));
+s_logger.info("listAllTariffPlans onorbefore" + 
effectiveDate 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605375
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.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.quota.dao;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.QuotaUsageVO;
+
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+@Component
+@Local(value = { QuotaUsageDao.class })
+public class QuotaUsageDaoImpl extends GenericDaoBase 
implements QuotaUsageDao {
+
+@Override
+public Pair, Integer> 
searchAndCountAllRecords(SearchCriteria sc, Filter filter) {
+return listAndCountIncludingRemovedBy(sc, filter);
+}
+
+@Override
+public void saveQuotaUsage(List records) {
+for (QuotaUsageVO usageRecord : records) {
+persist(usageRecord);
+}
+}
+
+@Override
+public BigDecimal findTotalQuotaUsage(final Long accountId, final Long 
domainId, final Integer usageType, final Date startDate, final Date endDate) {
+List quotaUsage = findQuotaUsage(accountId, 
domainId, null, startDate, endDate);
+BigDecimal total = new BigDecimal(0);
+for (final QuotaUsageVO quotaRecord : quotaUsage) {
+total = total.add(quotaRecord.getQuotaUsed());
+}
+return total;
+}
+
+@SuppressWarnings("deprecation")
+@Override
+public List findQuotaUsage(final Long accountId, final 
Long domainId, final Integer usageType, final Date startDate, final Date 
endDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+List quotaUsageRecords = null;
+try {
+// TODO instead of max value query with reasonable number and
+// iterate
+SearchCriteria sc = createSearchCriteria();
+if (accountId != null) {
+sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+}
+/*
+ * if (isDomainAdmin) { SearchCriteria sdc =
+ * _domainDao.createSearchCriteria(); sdc.addOr("path",
+ * SearchCriteria.Op.LIKE,
+ * _domainDao.findById(caller.getDomainId()).getPath() + "%");
+ * List domains = _domainDao.search(sdc, null); 
List
+ * domainIds = new ArrayList(); for (DomainVO domain :
+ * domains) domainIds.add(domain.getId()); 
sc.addAnd("domainId",
+ * SearchCriteria.Op.IN, domainIds.toArray());
+ * s_logger.debug("Account ID=" + accountId); }
+ */
--- End diff --

ok


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605363
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java ---
@@ -0,0 +1,138 @@
+//Licensed to the Apache Software Foundation (ASF) under one
+//or more contributor license agreements.  See the NOTICE file
+//distributed with this work for additional information
+//regarding copyright ownership.  The ASF licenses this file
+//to you under the Apache License, Version 2.0 (the
+//"License"); you may not use this file except in compliance
+//with the License.  You may obtain a copy of the License at
+//
+//http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing,
+//software distributed under the License is distributed on an
+//"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.TransactionLegacy;
+
+import org.apache.cloudstack.quota.constant.QuotaTypes;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Local(value = { QuotaTariffDao.class })
+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;
+
+public QuotaTariffDaoImpl() {
+super();
+searchUsageType = createSearchBuilder();
+searchUsageType.and("usage_type", 
searchUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+searchUsageType.done();
+
+listAllIncludedUsageType = createSearchBuilder();
+listAllIncludedUsageType.and("onorbefore", 
listAllIncludedUsageType.entity().getEffectiveOn(), SearchCriteria.Op.LTEQ);
+listAllIncludedUsageType.and("quotatype", 
listAllIncludedUsageType.entity().getUsageType(), SearchCriteria.Op.EQ);
+listAllIncludedUsageType.done();
+}
+
+@Override
+public QuotaTariffVO findTariffPlanByUsageType(final int quotaType, 
final Date effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List result = null;
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", false, 0L, 1L);
+final SearchCriteria sc = 
listAllIncludedUsageType.create();
+sc.setParameters("onorbefore", effectiveDate);
+sc.setParameters("quotatype", quotaType);
+result = search(sc, filter);
+} finally {
+txn.close();
+}
+// Switch back
+TransactionLegacy.open(opendb).close();
+if (result.size() > 0) {
+//s_logger.info("findTariffPlanByUsageType: " + effectiveDate 
+ "quota type " + quotaType  + " val=" + result.get(0).getCurrencyValue());
+return result.get(0);
+} else {
+//s_logger.info("Missing quota type " + quotaType);
+return null;
+}
+}
+
+@Override
+public List listAllTariffPlans(final Date 
effectiveDate) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+List tariffs = new ArrayList();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.USAGE_DB);
+try {
+final Filter filter = new Filter(QuotaTariffVO.class, 
"effectiveOn", 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.size() > 0) {
+tariffs.add(result.get(0));
+s_logger.info("listAllTariffPlans onorbefore" + 
effectiveDate 

[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605389
  
--- Diff: 
framework/quota/src/org/apache/cloudstack/quota/dao/ServiceOfferingDaoImpl.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.quota.dao;
+
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+import org.apache.cloudstack.quota.vo.ServiceOfferingVO;
+
+import com.cloud.event.UsageEventVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.TransactionLegacy;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Component
+@Local(value = { ServiceOfferingDao.class })
+@DB()
+public class ServiceOfferingDaoImpl extends 
GenericDaoBase implements ServiceOfferingDao {
+protected static final Logger s_logger = 
Logger.getLogger(ServiceOfferingDaoImpl.class);
+
+@Inject
+UserVmDetailsDao userVmDetailsDao;
+
+@Override
+public ServiceOfferingVO findServiceOffering(final Long vmId, final 
long serviceOfferingId) {
+final short opendb = 
TransactionLegacy.currentTxn().getDatabaseId();
+TransactionLegacy txn = 
TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
+ServiceOfferingVO result;
+try {
+result = findById(vmId, serviceOfferingId);
+} finally {
+txn.close();
+}
+TransactionLegacy.open(opendb).close();
+return result;
+}
+
+public ServiceOfferingVO findById(Long vmId, long serviceOfferingId) {
+ServiceOfferingVO offering = super.findById(serviceOfferingId);
+if (offering.isDynamic()) {
+offering.setDynamicFlag(true);
+if (vmId == null) {
+throw new CloudRuntimeException("missing argument vmId");
+}
--- End diff --

please elaborate.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605394
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.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;
+
+import com.cloud.user.Account;
+import org.apache.cloudstack.api.APICommand;
+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.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.2.0", requestHasSensitiveInfo = false, 
responseHasSensitiveInfo = false)
--- End diff --

accepted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605399
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.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.api.command;
+
+import com.cloud.user.Account;
+
+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.DomainResponse;
+import org.apache.cloudstack.api.response.QuotaCreditsResponse;
+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;
+
+@APICommand(name = "quotaCredits", responseObject = 
QuotaCreditsResponse.class, description = "Add +-credits to an account", since 
= "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
--- End diff --

ok


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605406
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaTariffListCmd.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.command;
+
+import com.cloud.user.Account;
+
+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.ListResponse;
+import org.apache.cloudstack.api.response.QuotaResponseBuilder;
+import org.apache.cloudstack.api.response.QuotaTariffResponse;
+import org.apache.cloudstack.quota.vo.QuotaTariffVO;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@APICommand(name = "quotaTariffList", responseObject = 
QuotaTariffResponse.class, description = "Lists all quota tariff plans", since 
= "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class QuotaTariffListCmd extends BaseListCmd {
+public static final Logger s_logger = 
Logger.getLogger(QuotaTariffListCmd.class.getName());
+private static final String s_name = "quotatarifflistresponse";
+
+@Inject
+QuotaResponseBuilder _responseBuilder;
+
+@Parameter(name = ApiConstants.USAGE_TYPE, type = CommandType.INTEGER, 
required = false, description = "Usage type of the resource")
+private Integer usageType;
+
+@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, 
required = false, description = "The effective start date on/after which the 
quota tariff is effective and older tariffs are no longer used for the usage 
type. Use -MM-dd as the date format, e.g. startDate=2009-06-03.")
+private Date effectiveDate;
+
+public QuotaTariffListCmd() {
+super();
+}
+
+@Override
+public void execute() {
+final List result = 
_responseBuilder.listQuotaTariffPlans(this);
+
+final List responses = new 
ArrayList();
+for (final QuotaTariffVO resource : result) {
+s_logger.info("Result desc=" + resource.getDescription() + " 
date=" + resource.getEffectiveOn() + " val=" + resource.getCurrencyValue());
--- End diff --

will check,


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request: Quota master

2015-08-20 Thread abhinandanprateek
Github user abhinandanprateek commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/689#discussion_r37605401
  
--- Diff: 
plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaStatementCmd.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.api.command;
+
+import java.util.Date;
+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.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.AccountResponse;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.QuotaResponseBuilder;
+import org.apache.cloudstack.api.response.QuotaStatementResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.quota.vo.QuotaUsageVO;
+import org.apache.cloudstack.api.response.QuotaStatementItemResponse;
+
+import com.cloud.user.Account;
+
+@APICommand(name = "quotaStatement", responseObject = 
QuotaStatementItemResponse.class, description = "Create a quota statement", 
since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = 
false)
--- End diff --

ok


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


  1   2   >