@@ -58,7 +58,7 @@ Vagrant.configure("2") do |config| | |||||
s.privileged = false | s.privileged = false | ||||
s.inline = <<-SHELL | s.inline = <<-SHELL | ||||
# Copy shared bubble dir to ${HOME} | # Copy shared bubble dir to ${HOME} | ||||
rsync -a /vagrant ${HOME}/bubble | |||||
cd ${HOME} && rsync -azc --exclude="**/target/**" /vagrant . && mv vagrant bubble | |||||
# Initialize the system | # Initialize the system | ||||
cd ${HOME}/bubble && ./bin/first_time_ubuntu.sh | cd ${HOME}/bubble && ./bin/first_time_ubuntu.sh | ||||
@@ -30,7 +30,7 @@ public class DelegatedPaymentDriver extends DelegatedCloudServiceDriverBase impl | |||||
log.warn("getPaymentMethodType: delegated driver has non-delegated cloud: "+cloud.getUuid()); | log.warn("getPaymentMethodType: delegated driver has non-delegated cloud: "+cloud.getUuid()); | ||||
return cloud.getPaymentDriver(configuration).getPaymentMethodType(); | return cloud.getPaymentDriver(configuration).getPaymentMethodType(); | ||||
} | } | ||||
if (!configuration.getPaymentsEnabled()) { | |||||
if (!configuration.paymentsEnabled()) { | |||||
log.warn("getPaymentMethodType: payments not enabled, returning null"); | log.warn("getPaymentMethodType: payments not enabled, returning null"); | ||||
return null; | return null; | ||||
}; | }; | ||||
@@ -115,7 +115,7 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> { | |||||
if (errors.isInvalid()) throw invalidEx(errors); | if (errors.isInvalid()) throw invalidEx(errors); | ||||
if (errors.hasSuggestedName()) accountPlan.setName(errors.getSuggestedName()); | if (errors.hasSuggestedName()) accountPlan.setName(errors.getSuggestedName()); | ||||
if (configuration.getPaymentsEnabled()) { | |||||
if (configuration.paymentsEnabled()) { | |||||
if (!accountPlan.hasPaymentMethodObject()) throw invalidEx("err.paymentMethod.required"); | if (!accountPlan.hasPaymentMethodObject()) throw invalidEx("err.paymentMethod.required"); | ||||
if (!accountPlan.getPaymentMethodObject().hasUuid()) throw invalidEx("err.paymentMethod.required"); | if (!accountPlan.getPaymentMethodObject().hasUuid()) throw invalidEx("err.paymentMethod.required"); | ||||
@@ -149,7 +149,7 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> { | |||||
} | } | ||||
@Override public AccountPlan postCreate(AccountPlan accountPlan, Object context) { | @Override public AccountPlan postCreate(AccountPlan accountPlan, Object context) { | ||||
if (configuration.getPaymentsEnabled()) { | |||||
if (configuration.paymentsEnabled()) { | |||||
final String accountPlanUuid = accountPlan.getUuid(); | final String accountPlanUuid = accountPlan.getUuid(); | ||||
final String paymentMethodUuid = accountPlan.getPaymentMethodObject().getUuid(); | final String paymentMethodUuid = accountPlan.getPaymentMethodObject().getUuid(); | ||||
final BubblePlan plan = planDAO.findByUuid(accountPlan.getPlan()); | final BubblePlan plan = planDAO.findByUuid(accountPlan.getPlan()); | ||||
@@ -191,7 +191,7 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> { | |||||
networkDAO.delete(accountPlan.getDeletedNetwork()); | networkDAO.delete(accountPlan.getDeletedNetwork()); | ||||
} else { | } else { | ||||
networkDAO.delete(accountPlan.getNetwork()); | networkDAO.delete(accountPlan.getNetwork()); | ||||
if (configuration.getPaymentsEnabled()) { | |||||
if (configuration.paymentsEnabled()) { | |||||
refundService.processRefunds(); | refundService.processRefunds(); | ||||
} | } | ||||
} | } | ||||
@@ -95,6 +95,9 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||||
} | } | ||||
@Override public CloudService postCreate(CloudService cloud, Object context) { | @Override public CloudService postCreate(CloudService cloud, Object context) { | ||||
if (cloud.getType() == CloudServiceType.payment && !configuration.paymentsEnabled()) { | |||||
configuration.resetPaymentsEnabled(); | |||||
} | |||||
if (!cloud.delegated() && !configuration.testMode()) { | if (!cloud.delegated() && !configuration.testMode()) { | ||||
final ValidationResult errors = testDriver(cloud, configuration); | final ValidationResult errors = testDriver(cloud, configuration); | ||||
if (errors.isInvalid()) throw invalidEx(errors); | if (errors.isInvalid()) throw invalidEx(errors); | ||||
@@ -102,7 +105,7 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||||
if (cloud.getType() == CloudServiceType.payment | if (cloud.getType() == CloudServiceType.payment | ||||
&& cloud.template() | && cloud.template() | ||||
&& cloud.enabled() | && cloud.enabled() | ||||
&& !configuration.getPaymentsEnabled()) { | |||||
&& !configuration.paymentsEnabled()) { | |||||
// a public template for a payment cloud has been added, and payments were not enabled -- now they are | // a public template for a payment cloud has been added, and payments were not enabled -- now they are | ||||
configuration.refreshPublicSystemConfigs(); | configuration.refreshPublicSystemConfigs(); | ||||
} | } | ||||
@@ -164,7 +167,9 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||||
// TODO for these maybe an outside cron would be better solution. BulkDelete is used here to be fast. | // TODO for these maybe an outside cron would be better solution. BulkDelete is used here to be fast. | ||||
// For now this postServiceDelete is called within a single place where this method is used - Account Deletion. | // For now this postServiceDelete is called within a single place where this method is used - Account Deletion. | ||||
log.warn("Not calling postServiceDelete for services deleted in this way"); | log.warn("Not calling postServiceDelete for services deleted in this way"); | ||||
return super.bulkDeleteWhere(whereClause, parameters); | |||||
int count = super.bulkDeleteWhere(whereClause, parameters); | |||||
configuration.resetPaymentsEnabled(); | |||||
return count; | |||||
} | } | ||||
@Transactional @Override public void delete(String uuid) { | @Transactional @Override public void delete(String uuid) { | ||||
@@ -175,6 +180,7 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||||
cs.getDriver().postServiceDelete(this, cs); | cs.getDriver().postServiceDelete(this, cs); | ||||
super.delete(uuid); | super.delete(uuid); | ||||
configuration.resetPaymentsEnabled(); | |||||
} | } | ||||
@Override public void delete(Collection<CloudService> entities) { | @Override public void delete(Collection<CloudService> entities) { | ||||
@@ -185,5 +191,6 @@ public class CloudServiceDAO extends AccountOwnedTemplateDAO<CloudService> { | |||||
} | } | ||||
super.delete(entities); | super.delete(entities); | ||||
configuration.resetPaymentsEnabled(); | |||||
} | } | ||||
} | } |
@@ -367,7 +367,7 @@ public class AuthResource { | |||||
} | } | ||||
String currency = null; | String currency = null; | ||||
if (configuration.getPaymentsEnabled()) { | |||||
if (configuration.paymentsEnabled()) { | |||||
currency = currencyForLocale(request.getLocale(), getDEFAULT_LOCALE()); | currency = currencyForLocale(request.getLocale(), getDEFAULT_LOCALE()); | ||||
// do we have any plans with this currency? | // do we have any plans with this currency? | ||||
if (!planDAO.getSupportedCurrencies().contains(currency)) { | if (!planDAO.getSupportedCurrencies().contains(currency)) { | ||||
@@ -393,7 +393,7 @@ public class AuthResource { | |||||
final Account account = accountDAO.newAccount(req, null, request, parent); | final Account account = accountDAO.newAccount(req, null, request, parent); | ||||
SimpleViolationException promoEx = null; | SimpleViolationException promoEx = null; | ||||
if (configuration.getPaymentsEnabled()) { | |||||
if (configuration.paymentsEnabled()) { | |||||
if (request.hasPaymentMethod()) { | if (request.hasPaymentMethod()) { | ||||
final AccountPaymentMethod paymentMethodObject = request.getPaymentMethodObject(); | final AccountPaymentMethod paymentMethodObject = request.getPaymentMethodObject(); | ||||
log.info("register: found AccountPaymentMethod at registration-time: " + json(paymentMethodObject, COMPACT_MAPPER)); | log.info("register: found AccountPaymentMethod at registration-time: " + json(paymentMethodObject, COMPACT_MAPPER)); | ||||
@@ -109,12 +109,12 @@ public class AccountPlansResource extends AccountOwnedResource<AccountPlan, Acco | |||||
} | } | ||||
@Override protected Object daoCreate(AccountPlan toCreate) { | @Override protected Object daoCreate(AccountPlan toCreate) { | ||||
if (!configuration.getPaymentsEnabled()) toCreate.setEnabled(true); | |||||
if (!configuration.paymentsEnabled()) toCreate.setEnabled(true); | |||||
return super.daoCreate(toCreate); | return super.daoCreate(toCreate); | ||||
} | } | ||||
@Override protected Object daoUpdate(AccountPlan toUpdate) { | @Override protected Object daoUpdate(AccountPlan toUpdate) { | ||||
if (!configuration.getPaymentsEnabled()) toUpdate.setEnabled(true); | |||||
if (!configuration.paymentsEnabled()) toUpdate.setEnabled(true); | |||||
return super.daoUpdate(toUpdate); | return super.daoUpdate(toUpdate); | ||||
} | } | ||||
@@ -258,7 +258,7 @@ public class AccountPlansResource extends AccountOwnedResource<AccountPlan, Acco | |||||
} | } | ||||
AccountPaymentMethod paymentMethod = null; | AccountPaymentMethod paymentMethod = null; | ||||
if (configuration.getPaymentsEnabled()) { | |||||
if (configuration.paymentsEnabled()) { | |||||
if (!request.hasPaymentMethodObject()) { | if (!request.hasPaymentMethodObject()) { | ||||
final List<AccountPaymentMethod> paymentMethods = paymentMethodDAO.findByAccountAndNotPromoAndNotDeleted(caller.getUuid()); | final List<AccountPaymentMethod> paymentMethods = paymentMethodDAO.findByAccountAndNotPromoAndNotDeleted(caller.getUuid()); | ||||
if (empty(paymentMethods)) { | if (empty(paymentMethods)) { | ||||
@@ -296,7 +296,7 @@ public class AccountPlansResource extends AccountOwnedResource<AccountPlan, Acco | |||||
request.setNetwork(newNetwork.getUuid()); | request.setNetwork(newNetwork.getUuid()); | ||||
} | } | ||||
if (configuration.getPaymentsEnabled()) { | |||||
if (configuration.paymentsEnabled()) { | |||||
if (paymentMethod != null && !paymentMethod.hasUuid()) { | if (paymentMethod != null && !paymentMethod.hasUuid()) { | ||||
final AccountPaymentMethod paymentMethodToCreate = new AccountPaymentMethod(request.getPaymentMethodObject()).setAccount(request.getAccount()); | final AccountPaymentMethod paymentMethodToCreate = new AccountPaymentMethod(request.getPaymentMethodObject()).setAccount(request.getAccount()); | ||||
final AccountPaymentMethod paymentMethodCreated = paymentMethodDAO.create(paymentMethodToCreate); | final AccountPaymentMethod paymentMethodCreated = paymentMethodDAO.create(paymentMethodToCreate); | ||||
@@ -378,7 +378,7 @@ public class BubbleConfiguration extends PgRestServerConfiguration | |||||
{TAG_NETWORK_UUID, thisNetwork == null ? null : thisNetwork.getUuid()}, | {TAG_NETWORK_UUID, thisNetwork == null ? null : thisNetwork.getUuid()}, | ||||
{TAG_SAGE_LAUNCHER, thisNetwork == null || isSageLauncher()}, | {TAG_SAGE_LAUNCHER, thisNetwork == null || isSageLauncher()}, | ||||
{TAG_BUBBLE_NODE, isSageLauncher() || thisNetwork == null ? null : thisNetwork.node()}, | {TAG_BUBBLE_NODE, isSageLauncher() || thisNetwork == null ? null : thisNetwork.node()}, | ||||
{TAG_PAYMENTS_ENABLED, getPaymentsEnabled()}, | |||||
{TAG_PAYMENTS_ENABLED, paymentsEnabled()}, | |||||
{TAG_LOCAL_NETWORK, thisNetwork == null || thisNetwork.local()}, | {TAG_LOCAL_NETWORK, thisNetwork == null || thisNetwork.local()}, | ||||
{TAG_PROMO_CODE_POLICY, getPromoCodePolicy().name()}, | {TAG_PROMO_CODE_POLICY, getPromoCodePolicy().name()}, | ||||
{TAG_REQUIRE_SEND_METRICS, requireSendMetrics()}, | {TAG_REQUIRE_SEND_METRICS, requireSendMetrics()}, | ||||
@@ -416,11 +416,31 @@ public class BubbleConfiguration extends PgRestServerConfiguration | |||||
background(this::getPublicSystemConfigs, "BubbleConfiguration.refreshPublicSystemConfigs"); | background(this::getPublicSystemConfigs, "BubbleConfiguration.refreshPublicSystemConfigs"); | ||||
} | } | ||||
@Getter(lazy=true) private final Boolean paymentsEnabled = initPaymentsEnabled(); | |||||
private boolean initPaymentsEnabled () { return getBean(CloudServiceDAO.class).paymentsEnabled(); } | |||||
private final AtomicReference<Boolean> paymentsEnabled = new AtomicReference<>(null); | |||||
public boolean paymentsEnabled() { | |||||
Boolean enabled = paymentsEnabled.get(); | |||||
if (enabled == null) { | |||||
synchronized (paymentsEnabled) { | |||||
enabled = paymentsEnabled.get(); | |||||
if (enabled == null) { | |||||
enabled = getBean(CloudServiceDAO.class).paymentsEnabled(); | |||||
paymentsEnabled.set(enabled); | |||||
} | |||||
} | |||||
} | |||||
return enabled; | |||||
} | |||||
public boolean resetPaymentsEnabled () { | |||||
synchronized (paymentsEnabled) { | |||||
paymentsEnabled.set(null); | |||||
} | |||||
return paymentsEnabled(); | |||||
} | |||||
public void requiresPaymentsEnabled () { | public void requiresPaymentsEnabled () { | ||||
if (!getPaymentsEnabled()) throw invalidEx("err_noPaymentMethods"); | |||||
if (!paymentsEnabled()) { | |||||
throw invalidEx("err_noPaymentMethods"); | |||||
} | |||||
} | } | ||||
@Getter @Setter private Boolean requireSendMetrics; | @Getter @Setter private Boolean requireSendMetrics; | ||||
@@ -181,7 +181,7 @@ public class StandardSelfNodeService implements SelfNodeService { | |||||
} | } | ||||
// start RefundService if payments are enabled and this is a SageLauncher | // start RefundService if payments are enabled and this is a SageLauncher | ||||
if (c.getPaymentsEnabled() && c.isSageLauncher() && thisNode.sage()) { | |||||
if (c.paymentsEnabled() && c.isSageLauncher() && thisNode.sage()) { | |||||
log.info("onStart: starting BillingService and RefundService"); | log.info("onStart: starting BillingService and RefundService"); | ||||
c.getBean(BillingService.class).start(); | c.getBean(BillingService.class).start(); | ||||
c.getBean(StandardRefundService.class).start(); | c.getBean(StandardRefundService.class).start(); | ||||
@@ -454,7 +454,7 @@ public class StandardNetworkService implements NetworkService { | |||||
} | } | ||||
if (progressMeter != null) { | if (progressMeter != null) { | ||||
if (!progressMeter.success() && configuration.getPaymentsEnabled()) { | |||||
if (!progressMeter.success() && configuration.paymentsEnabled()) { | |||||
final AccountPlan accountPlan = accountPlanDAO.findByNetwork(nn.getNetwork()); | final AccountPlan accountPlan = accountPlanDAO.findByNetwork(nn.getNetwork()); | ||||
if (accountPlan != null) { | if (accountPlan != null) { | ||||
final BubblePlan plan = planDAO.findByUuid(accountPlan.getPlan()); | final BubblePlan plan = planDAO.findByUuid(accountPlan.getPlan()); | ||||
@@ -691,7 +691,7 @@ public class StandardNetworkService implements NetworkService { | |||||
public NewNodeNotification startNetwork(BubbleNetwork network, NetLocation netLocation) { | public NewNodeNotification startNetwork(BubbleNetwork network, NetLocation netLocation) { | ||||
final String accountUuid = network.getAccount(); | final String accountUuid = network.getAccount(); | ||||
if (configuration.getPaymentsEnabled()) { | |||||
if (configuration.paymentsEnabled()) { | |||||
AccountPlan accountPlan = accountPlanDAO.findByAccountAndNetwork(accountUuid, network.getUuid()); | AccountPlan accountPlan = accountPlanDAO.findByAccountAndNetwork(accountUuid, network.getUuid()); | ||||
if (accountPlan == null) throw invalidEx("err.accountPlan.notFound"); | if (accountPlan == null) throw invalidEx("err.accountPlan.notFound"); | ||||
final long start = now(); | final long start = now(); | ||||
@@ -62,7 +62,7 @@ public class FilteredEntityIterator extends EntityIterator { | |||||
BubbleNode node, | BubbleNode node, | ||||
List<BubblePlanApp> planApps, | List<BubblePlanApp> planApps, | ||||
AtomicReference<Exception> error) { | AtomicReference<Exception> error) { | ||||
super(error, configuration.getPaymentsEnabled()); | |||||
super(error, configuration.paymentsEnabled()); | |||||
this.configuration = configuration; | this.configuration = configuration; | ||||
this.account = account; | this.account = account; | ||||
this.network = network; | this.network = network; | ||||
@@ -31,7 +31,7 @@ public class FullEntityIterator extends EntityIterator { | |||||
BubbleNetwork network, | BubbleNetwork network, | ||||
LaunchType launchType, | LaunchType launchType, | ||||
AtomicReference<Exception> error) { | AtomicReference<Exception> error) { | ||||
super(error, configuration.getPaymentsEnabled()); | |||||
super(error, configuration.paymentsEnabled()); | |||||
this.configuration = configuration; | this.configuration = configuration; | ||||
this.network = network; | this.network = network; | ||||
this.account = account; | this.account = account; | ||||