<commit_before>/* -------------------------------------------------------------------------- */
/* Copyright 2002-2011, GridWay Project Leads (GridWay.org)                   */
/*                                                                            */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
/* not use this file except in compliance with the License. You may obtain    */
/* a copy of the License at                                                   */
/*                                                                            */
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
/*                                                                            */
/* Unless required by applicable law or agreed to in writing, software        */
/* distributed under the License is distributed on an "AS IS" BASIS,          */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
/* See the License for the specific language governing permissions and        */
/* limitations under the License.                                             */
/* -------------------------------------------------------------------------- */

#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/types.h>

#include "gw_dm_mad.h"
#include "gw_dm.h"
#include "gw_log.h"

static int gw_dm_mad_start(gw_dm_mad_t *dm_mad);

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
        
int gw_dm_mad_init(gw_dm_mad_t *dm_mad, const char *exe, const char *name, 
		const char *args)
{
    int rc;

    dm_mad->name        = strdup(name);
    dm_mad->executable  = strdup(exe);
    
    if (args != NULL)
        dm_mad->argument    = strdup(args);
	
    rc = gw_dm_mad_start(dm_mad);
    
    if (rc == -1)
        gw_dm_mad_finalize (dm_mad);  

    return rc;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_schedule(gw_dm_mad_t *dm_mad)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "SCHEDULE - - - - -\n");
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));

    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_host_monitor(gw_dm_mad_t * dm_mad, 
                            int           hid, 
                            int           uslots, 
                            int           rjobs, 
                            char *        name)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "HOST_MONITOR %i %i %i %s -\n",hid,uslots,rjobs,name);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_user_add(gw_dm_mad_t * dm_mad, 
                        int           uid, 
                        int           aslots, 
                        int           rslots, 
                        char *        name)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "USER_ADD %i %i %i %s -\n",uid,aslots,rslots,name);
	write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_user_del(gw_dm_mad_t * dm_mad, 
                        int           uid)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "USER_DEL %i - - - -\n",uid);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_job_del(gw_dm_mad_t * dm_mad, 
                       int           jid)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "JOB_DEL %i - - - -\n",jid);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}
			                       
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_job_failed(gw_dm_mad_t *         dm_mad, 
                          int                   hid,
                          int                   uid,
                          gw_migration_reason_t reason)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "JOB_FAILED %i %i %i - -\n",hid,uid,reason);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_job_success(gw_dm_mad_t * dm_mad, 
                           int           hid,
                           int           uid,
                           float         xfr,
                           float         sus,
                           float         exe)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "JOB_SUCCESS %i %i %f %f %f\n",hid,uid,xfr,sus,exe);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_job_schedule(gw_dm_mad_t *         dm_mad, 
                            int                   jid,
                            int                   aid,
                            int                   uid,
                            gw_migration_reason_t reason)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "JOB_SCHEDULE %i %i %i %i -\n",
            jid,aid,uid,reason);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_finalize (gw_dm_mad_t *dm_mad)
{
    char buf[50];
	int  status;
	pid_t pid;<commit_msg>Aesthetic change<commit_after>/* -------------------------------------------------------------------------- */
/* Copyright 2002-2011, GridWay Project Leads (GridWay.org)                   */
/*                                                                            */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
/* not use this file except in compliance with the License. You may obtain    */
/* a copy of the License at                                                   */
/*                                                                            */
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
/*                                                                            */
/* Unless required by applicable law or agreed to in writing, software        */
/* distributed under the License is distributed on an "AS IS" BASIS,          */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
/* See the License for the specific language governing permissions and        */
/* limitations under the License.                                             */
/* -------------------------------------------------------------------------- */

#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/types.h>

#include "gw_dm_mad.h"
#include "gw_dm.h"
#include "gw_log.h"

static int gw_dm_mad_start(gw_dm_mad_t *dm_mad);

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
        
int gw_dm_mad_init(gw_dm_mad_t *dm_mad, const char *exe, const char *name, 
		const char *args)
{
    int rc;

    dm_mad->name        = strdup(name);
    dm_mad->executable  = strdup(exe);
    
    if (args != NULL)
        dm_mad->argument    = strdup(args);
	
    rc = gw_dm_mad_start(dm_mad);
    
    if (rc == -1)
        gw_dm_mad_finalize (dm_mad);  

    return rc;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_schedule(gw_dm_mad_t *dm_mad)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "SCHEDULE - - - - -\n");
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));

    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_host_monitor(gw_dm_mad_t * dm_mad, 
                            int           hid, 
                            int           uslots, 
                            int           rjobs, 
                            char *        name)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "HOST_MONITOR %i %i %i %s -\n",hid,uslots,rjobs,name);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_user_add(gw_dm_mad_t * dm_mad, 
                        int           uid, 
                        int           aslots, 
                        int           rslots, 
                        char *        name)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "USER_ADD %i %i %i %s -\n",uid,aslots,rslots,name);
	write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_user_del(gw_dm_mad_t * dm_mad, 
                        int           uid)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "USER_DEL %i - - - -\n",uid);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_job_del(gw_dm_mad_t * dm_mad, 
                       int           jid)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "JOB_DEL %i - - - -\n",jid);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}
			                       
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_job_failed(gw_dm_mad_t *         dm_mad, 
                          int                   hid,
                          int                   uid,
                          gw_migration_reason_t reason)
{
    char buf[GW_DM_MAX_STRING];
	int write_result;
    sprintf(buf, "JOB_FAILED %i %i %i - -\n",hid,uid,reason);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_job_success(gw_dm_mad_t * dm_mad, 
                           int           hid,
                           int           uid,
                           float         xfr,
                           float         sus,
                           float         exe)
{
    char buf[GW_DM_MAX_STRING];
    int write_result;

    sprintf(buf, "JOB_SUCCESS %i %i %f %f %f\n",hid,uid,xfr,sus,exe);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_job_schedule(gw_dm_mad_t *         dm_mad, 
                            int                   jid,
                            int                   aid,
                            int                   uid,
                            gw_migration_reason_t reason)
{
    char buf[GW_DM_MAX_STRING];
    int write_result;

    sprintf(buf, "JOB_SCHEDULE %i %i %i %i -\n",
            jid,aid,uid,reason);
    write_result = write(dm_mad->dm_mad_pipe, buf, strlen(buf));
    
    return;
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void gw_dm_mad_finalize (gw_dm_mad_t *dm_mad)
{
    char buf[50];
	int  status;
	pid_t pid;
{'fraction_non_alphanumeric': 0.3275441578597295, 'fraction_numerical': 0.0022171310324440173, 'mean_word_length': 0.7749213011542497, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 76, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3348970', 'n_tokens_mistral': 3504, 'n_tokens_neox': 3382, 'n_words': 686}