Search in sources :

Example 1 with CronScheduleType

use of com.tremolosecurity.config.xml.CronScheduleType in project OpenUnison by TremoloSecurity.

the class LoadJobsFromK8s method createJob.

private void createJob(JSONObject item, String name) throws ProvisioningException {
    HttpCon nonwatchHttp = null;
    JobType job = new JobType();
    job.setName(name);
    JSONObject spec = (JSONObject) item.get("spec");
    StringBuffer b = new StringBuffer();
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("className"));
    job.setClassName(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("group"));
    job.setGroup(b.toString());
    JSONArray params = (JSONArray) spec.get("params");
    for (Object o : params) {
        JSONObject param = (JSONObject) o;
        ParamWithValueType pt = new ParamWithValueType();
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("name"));
        pt.setName(b.toString());
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("value"));
        pt.setValue(b.toString());
        job.getParam().add(pt);
    }
    JSONArray secretParams = (JSONArray) spec.get("secretParams");
    if (secretParams != null) {
        try {
            nonwatchHttp = this.k8sWatch.getK8s().createClient();
            String token = this.k8sWatch.getK8s().getAuthToken();
            for (Object o : secretParams) {
                JSONObject secretParam = (JSONObject) o;
                String paramName = (String) secretParam.get("name");
                String secretName = (String) secretParam.get("secretName");
                String secretKey = (String) secretParam.get("secretKey");
                String secretValue = this.k8sWatch.getSecretValue(secretName, secretKey, token, nonwatchHttp);
                ParamWithValueType pt = new ParamWithValueType();
                pt.setName(paramName);
                pt.setValue(secretValue);
                job.getParam().add(pt);
            }
        } catch (Exception e) {
            throw new ProvisioningException("Could not load secrets for '" + name + "'");
        } finally {
            if (nonwatchHttp != null) {
                try {
                    nonwatchHttp.getHttp().close();
                } catch (IOException e) {
                }
                nonwatchHttp.getBcm().close();
            }
        }
    }
    job.setCronSchedule(new CronScheduleType());
    JSONObject cron = (JSONObject) spec.get("cronSchedule");
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) cron.get("seconds"));
    job.getCronSchedule().setSeconds(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) cron.get("minutes"));
    job.getCronSchedule().setMinutes(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) cron.get("hours"));
    job.getCronSchedule().setHours(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) cron.get("dayOfMonth"));
    job.getCronSchedule().setDayOfMonth(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) cron.get("month"));
    job.getCronSchedule().setMonth(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) cron.get("dayOfWeek"));
    job.getCronSchedule().setDayOfWeek(b.toString());
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, (String) cron.get("year"));
    job.getCronSchedule().setYear(b.toString());
    try {
        this.cfgMgr.getProvisioningEngine().addNewJob(jobKeys, job);
    } catch (ClassNotFoundException | SchedulerException | ProvisioningException e) {
        throw new ProvisioningException("Could not add job '" + name + "'", e);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JSONArray(org.json.simple.JSONArray) IOException(java.io.IOException) SchedulerException(org.quartz.SchedulerException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JobType(com.tremolosecurity.config.xml.JobType) JSONObject(org.json.simple.JSONObject) CronScheduleType(com.tremolosecurity.config.xml.CronScheduleType) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) JSONObject(org.json.simple.JSONObject) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType)

Aggregations

CronScheduleType (com.tremolosecurity.config.xml.CronScheduleType)1 JobType (com.tremolosecurity.config.xml.JobType)1 ParamWithValueType (com.tremolosecurity.config.xml.ParamWithValueType)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1 IOException (java.io.IOException)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 SchedulerException (org.quartz.SchedulerException)1