Search in sources :

Example 1 with DataSource

use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.

the class AccountBalanceManagementSbb method handleRequest.

// ---------------------------- Helper Methods ----------------------------
private void handleRequest(CreditControlInfo ccInfo) {
    if (tracer.isInfoEnabled()) {
        tracer.info("[><] SID<" + ccInfo.getSessionId() + "> Handling Credit-Control-Request...");
    }
    if (bypass) {
        if (tracer.isInfoEnabled()) {
            tracer.info("[><] SID<" + ccInfo.getSessionId() + "> Bypassing Unit Reservation...");
        }
        ccInfo.setSuccess(true);
        ((DiameterChargingServer) sbbContext.getSbbLocalObject().getParent()).resumeOnCreditControlRequest(ccInfo);
    } else {
        DataSource ds = null;
        try {
            ds = getDatasource();
            if (ccInfo.getRequestedAction() == RequestedActionType.DIRECT_DEBITING) {
                ds.directDebitUnits(ccInfo);
            } else {
                ds.requestUnits(ccInfo);
            }
        } catch (Exception e) {
            tracer.severe("[xx] Unable to obtain Datasource Child SBB", e);
        }
    }
}
Also used : SLEEException(javax.slee.SLEEException) CreateException(javax.slee.CreateException) DiameterChargingServer(org.mobicents.charging.server.DiameterChargingServer) DataSource(org.mobicents.charging.server.data.DataSource)

Example 2 with DataSource

use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.

the class AccountBalanceManagementSbb method getDatasource.

protected DataSource getDatasource() throws IllegalArgumentException, NullPointerException, SLEEException, CreateException {
    ChildRelationExt cre = (ChildRelationExt) getDatasourceChildRelation();
    SbbLocalObjectExt sbbLocalObject = cre.get(DATASOURCE_CHILD_NAME);
    if (sbbLocalObject == null) {
        sbbLocalObject = cre.create(DATASOURCE_CHILD_NAME);
    }
    return (DataSource) sbbLocalObject;
}
Also used : ChildRelationExt(org.mobicents.slee.ChildRelationExt) SbbLocalObjectExt(org.mobicents.slee.SbbLocalObjectExt) DataSource(org.mobicents.charging.server.data.DataSource)

Example 3 with DataSource

use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.

the class DiameterChargingServerSbb method getDatasource.

protected DataSource getDatasource() throws IllegalArgumentException, NullPointerException, SLEEException, CreateException {
    ChildRelationExt cre = (ChildRelationExt) getDatasourceChildRelation();
    SbbLocalObjectExt sbbLocalObject = cre.get(DATASOURCE_CHILD_NAME);
    if (sbbLocalObject == null) {
        sbbLocalObject = cre.create(DATASOURCE_CHILD_NAME);
    }
    return (DataSource) sbbLocalObject;
}
Also used : ChildRelationExt(org.mobicents.slee.ChildRelationExt) SbbLocalObjectExt(org.mobicents.slee.SbbLocalObjectExt) DataSource(org.mobicents.charging.server.data.DataSource)

Example 4 with DataSource

use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.

the class DiameterChargingServerSbb method onServiceStartedEvent.

// ---------------------------- Event Handlers ----------------------------
public void onServiceStartedEvent(ServiceStartedEvent event, ActivityContextInterface aci) {
    if (tracer.isInfoEnabled()) {
        tracer.info("==============================================================================");
        tracer.info("==                 Mobicents Charging Server v1.0 [STARTED]                 ==");
        tracer.info("==                                  - . -                                   ==");
        tracer.info("==              Thank you for running Mobicents Community code              ==");
        tracer.info("==   For Commercial Grade Support, please request a TelScale Subscription   ==");
        tracer.info("==                         http://www.telestax.com/                         ==");
        tracer.info("==============================================================================");
    }
    DataSource ds;
    try {
        ds = getDatasource();
        if (tracer.isInfoEnabled()) {
            tracer.info("[><] Got DataSource Child SBB Local Interface [" + ds + "]");
        }
        ds.init();
    } catch (Exception e) {
        tracer.severe("[xx] Unable to fetch Datasource Child SBB .");
        return;
    }
    AccountBalanceManagement am;
    try {
        am = getAccountManager();
        if (tracer.isInfoEnabled()) {
            tracer.info("[><] Got Account Balance Management Child SBB Local Interface [" + am + "]");
        }
    } catch (Exception e) {
        tracer.severe("[xx] Unable to fetch Account and Balance Management Child SBB .");
        return;
    }
    try {
        Context ctx = (Context) new InitialContext().lookup("java:comp/env");
        boolean loadUsersFromCSV = (Boolean) loadEnvEntry(ctx, "loadUsersFromCSV", false);
        performRating = (Boolean) loadEnvEntry(ctx, "performRating", false);
        generateCDR = (Boolean) loadEnvEntry(ctx, "generateCDR", false);
        String abmfAVPsProp = (String) loadEnvEntry(ctx, "ABMF_AVPs", "");
        try {
            String[] avps = abmfAVPsProp.trim().split(",");
            for (String avp : avps) {
                String[] codeName = avp.trim().split("=");
                if (tracer.isInfoEnabled()) {
                    tracer.info("[><] Mapping AVP with Code " + codeName[0] + " as '" + codeName[1] + "' on received CCRs for ABMF Data.");
                }
                abmfAVPs.put(codeName[0], codeName[1]);
            }
        } catch (Exception e) {
            tracer.warning("[!!] Error reading ABMF Data AVPs. Format should be: code=name,code2=name2,... No custom data will be passed.");
        }
        if (loadUsersFromCSV) {
            try {
                Properties props = new Properties();
                props.load(this.getClass().getClassLoader().getResourceAsStream("users.properties"));
                for (Object key : props.keySet()) {
                    String msisdn = (String) key;
                    // am.addUser(imsi, Long.valueOf(props.getProperty(imsi)));
                    // TODO: remove the properties to database mapping later on. useful for now
                    ds.updateUser(msisdn, Long.valueOf(props.getProperty(msisdn)));
                }
                if (tracer.isInfoEnabled()) {
                    tracer.info("[--] Loaded users from properties file.");
                }
            } catch (Exception e) {
                tracer.warning("[!!] Unable to load users from properties file. Allowing everything!");
                am.setBypass(true);
            } finally {
                if (tracer.isFineEnabled()) {
                    tracer.fine("[--] Dumping users state...");
                    am.dump("%");
                }
            }
        }
    } catch (Exception e) {
        tracer.warning("[!!] Unable to retrieve InitialContext. The env-entry properties were not loaded and defaults will be used.");
    }
}
Also used : InitialContext(javax.naming.InitialContext) SbbContext(javax.slee.SbbContext) Context(javax.naming.Context) AccountBalanceManagement(org.mobicents.charging.server.account.AccountBalanceManagement) Properties(java.util.Properties) CreateException(javax.slee.CreateException) IOException(java.io.IOException) SLEEException(javax.slee.SLEEException) InitialContext(javax.naming.InitialContext) DataSource(org.mobicents.charging.server.data.DataSource)

Example 5 with DataSource

use of org.mobicents.charging.server.data.DataSource in project charging-server by RestComm.

the class AccountBalanceManagementSbb method dump.

public void dump(String usersRegExp) {
    if (tracer.isInfoEnabled()) {
        DataSource ds = null;
        try {
            ds = getDatasource();
            ds.getUserAccountData(usersRegExp);
        } catch (Exception e) {
            tracer.severe("[xx] Unable to obtain Datasource Child SBB", e);
        }
    }
}
Also used : SLEEException(javax.slee.SLEEException) CreateException(javax.slee.CreateException) DataSource(org.mobicents.charging.server.data.DataSource)

Aggregations

DataSource (org.mobicents.charging.server.data.DataSource)5 CreateException (javax.slee.CreateException)3 SLEEException (javax.slee.SLEEException)3 ChildRelationExt (org.mobicents.slee.ChildRelationExt)2 SbbLocalObjectExt (org.mobicents.slee.SbbLocalObjectExt)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 SbbContext (javax.slee.SbbContext)1 DiameterChargingServer (org.mobicents.charging.server.DiameterChargingServer)1 AccountBalanceManagement (org.mobicents.charging.server.account.AccountBalanceManagement)1