protected int registerUSS(int ussID, ref StringBuilder message)
        {
            int status = 1;
            ProcessAgentInfo uss = null;
            try
            {
                if (labClientID <= 0)
                {
                    message.AppendLine("Please save the Lab Client information before attempting to associate it with a resource.");
                    status = 0;
                }

                if (ddlAssociatedUSS.SelectedIndex == 0)
                {
                    message.AppendLine("Please select a desired USS to be associated with the client.");
                    status = 0;
                }
                if (status < 1)
                    return status;

                if (ussID > 0)
                {
                    uss = ticketing.GetProcessAgentInfo(ussID);
                    if (uss != null)
                    {
                        if (uss.retired)
                        {
                            message.AppendLine("The specified USS is retired.<br/>");
                            return 0;
                        }

                        TicketLoadFactory factory = TicketLoadFactory.Instance();

                        //this should be in a loop
                        int[] labServerIDs = AdministrativeAPI.GetLabServerIDsForClient(labClientID);
                        if (labServerIDs != null && labServerIDs.Length > 0)
                        {
                            for (int i = 0; i < labServerIDs.Length; i++)
                            {

                                if (labServerIDs[i] > 0)
                                {
                                    ProcessAgentInfo labServer = ticketing.GetProcessAgentInfo(labServerIDs[i]);
                                    if (labServer.retired)
                                    {
                                        message.AppendLine("The lab server: " + labServer.agentName + " is retired!<br/>");
                                    }
                                    int lssId = ticketing.FindProcessAgentIdForAgent(labServerIDs[i], ProcessAgentType.LAB_SCHEDULING_SERVER);

                                    if (lssId > 0)
                                    {

                                        ProcessAgentInfo lss = ticketing.GetProcessAgentInfo(lssId);
                                        if (lss != null)
                                        {
                                            if (lss.retired)
                                            {
                                                message.AppendLine("The LSS: " + lss.agentName + " is retired!<br/>");
                                                return 0;
                                            }
                                            LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                                            lssProxy.Url = lss.webServiceUrl;
                                            lssProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                                            lssProxy.AgentAuthHeaderValue.coupon = lss.identOut;
                                            lssProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;

                                            // Is this in the domain or cross-domain
                                            //if (lss.domainGuid.Equals(ProcessAgentDB.ServiceGuid))
                                           // {
                                                lssProxy.AddExperimentInfo(labServer.agentGuid, labServer.agentName, labClient.clientGuid, labClient.clientName, labClient.version, labClient.contactEmail);
                                            //}

                                            // check for existing REVOKE_RESERVATION tickets
                                            bool needUssRevoke = true;
                                            bool needLssRevoke = true;
                                            Coupon ussRevokeCoupon = null;
                                            Coupon lssRevokeCoupon = null;
                                            Ticket ussRevoke = null;
                                            Ticket lssRevoke = null;
                                            Ticket[] ussRevokeTickets = ticketing.RetrieveIssuedTickets(-1L,
                                                    TicketTypes.REVOKE_RESERVATION, uss.agentGuid, lss.agentGuid);
                                            if (ussRevokeTickets != null && ussRevokeTickets.Length > 0)
                                            {
                                                ussRevoke = ussRevokeTickets[0];
                                                needUssRevoke = false;
                                            }

                                            Ticket[] lssRevokeTickets = ticketing.RetrieveIssuedTickets(-1L,
                                                    TicketTypes.REVOKE_RESERVATION, lss.agentGuid, uss.agentGuid);
                                            if (lssRevokeTickets != null && lssRevokeTickets.Length > 0)
                                            {
                                                lssRevoke = lssRevokeTickets[0];
                                                needLssRevoke = false;
                                            }

                                            if (ussRevoke == null && lssRevoke == null)
                                            {
                                                ussRevokeCoupon = ticketing.CreateCoupon();
                                                lssRevokeCoupon = ussRevokeCoupon;
                                            }
                                            if (needUssRevoke)
                                            {
                                                string ussRevokePayload = factory.createRevokeReservationPayload("LSS");
                                                if (ussRevokeCoupon == null)
                                                {
                                                    ussRevokeCoupon = ticketing.CreateTicket(TicketTypes.REVOKE_RESERVATION,
                                                        uss.agentGuid, lss.agentGuid, -1L, ussRevokePayload);
                                                }
                                                else
                                                {
                                                    ticketing.AddTicket(ussRevokeCoupon, TicketTypes.REVOKE_RESERVATION,
                                                        uss.agentGuid, lss.agentGuid, -1L, ussRevokePayload);
                                                }

                                                // Is this in the domain or cross-domain
                                                if (lss.domainGuid.Equals(ProcessAgentDB.ServiceGuid))
                                                { // this domain
                                                    //Add USS on LSS
                                                    int ussAdded = lssProxy.AddUSSInfo(uss.agentGuid, uss.agentName, uss.webServiceUrl, ussRevokeCoupon);
                                                    status = 1;
                                                }
                                                else
                                                {
                                                    // cross-domain
                                                    // send consumerInfo to remote SB
                                                    int remoteSbId = ticketing.GetProcessAgentID(lss.domainGuid);
                                                    message.AppendLine(RegistrationSupport.RegisterClientUSS(remoteSbId, null, lss.agentId, null, labServer.agentId,
                                                        ussRevokeCoupon, uss.agentId, null, labClient.clientID));
                                                }
                                            }
                                            UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                                            ussProxy.Url = uss.webServiceUrl;
                                            ussProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                                            ussProxy.AgentAuthHeaderValue.coupon = uss.identOut;
                                            ussProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                                            if (needLssRevoke)
                                            {
                                                //ADD LSS on USS
                                                string ussPayload = factory.createAdministerUSSPayload(Convert.ToInt32(Session["UserTZ"]));
                                                string lssRevokePayload = factory.createRevokeReservationPayload("USS");
                                                if (lssRevokeCoupon == null)
                                                {
                                                    lssRevokeCoupon = ticketing.CreateTicket(TicketTypes.REVOKE_RESERVATION, lss.agentGuid, uss.agentGuid, -1L, lssRevokePayload);
                                                }
                                                else
                                                {
                                                    ticketing.AddTicket(lssRevokeCoupon, TicketTypes.REVOKE_RESERVATION, lss.agentGuid, uss.agentGuid, -1L, lssRevokePayload);
                                                }

                                                int lssAdded = ussProxy.AddLSSInfo(lss.agentGuid, lss.agentName, lss.webServiceUrl, lssRevokeCoupon);
                                            }
                                            //Add Experiment Information on USS
                                            int expInfoAdded = ussProxy.AddExperimentInfo(labServer.agentGuid, labServer.agentName,
                                                labClient.clientGuid, labClient.clientName, labClient.version, labClient.contactEmail, lss.agentGuid);

                                            //Ceate resource Map
                                            ResourceMappingKey key = new ResourceMappingKey(ResourceMappingTypes.CLIENT, labClientID);
                                            List<ResourceMappingValue> valuesList = new List<ResourceMappingValue>();
                                            valuesList.Add(new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.SCHEDULING_SERVER));
                                            valuesList.Add(new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT, ussID));
                                            valuesList.Add(new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                                                TicketTypes.GetTicketType(TicketTypes.SCHEDULE_SESSION)));
                                            // Add the mapping to the database & cache
                                            ResourceMapping newMapping = ticketing.AddResourceMapping(key, valuesList.ToArray());

                                            // add mapping to qualifier list
                                            int qualifierType = Qualifier.resourceMappingQualifierTypeID;
                                            string name = ticketing.ResourceMappingToString(newMapping);
                                            int qualifierID = AuthorizationAPI.AddQualifier(newMapping.MappingID, qualifierType, name, Qualifier.ROOT);

                                            // Group Credentials MOVED TO THE MANAGE LAB GROUPS PAGE
                                        }
                                        else
                                        {
                                            message.AppendLine("The specified LSS was not found!<br/>");
                                            return 0;
                                        }
                                    }
                                    else
                                    {
                                        message.AppendLine("You must assign a LSS to the lab server before you may assign a USS!<br/>");
                                        return 0;
                                    }
                                }
                            }
                        }
                        else
                        {
                            message.AppendLine("You must assign a Lab Server before assigning a USS!<br/>");
                            return 0;
                        }
                        btnRegisterUSS.Visible = true;
                        btnRegisterUSS.Text = "Dissociate";
                        ddlAssociatedUSS.Visible = false;
                        txtAssociatedUSS.Visible = true;
                        txtAssociatedUSS.Text = ddlAssociatedUSS.SelectedItem.Text;
                        hdnUssID.Value = ussID.ToString();

                        message.AppendLine("User-side Scheduling Server \"" + ddlAssociatedUSS.SelectedItem.Text + "\" succesfully "
                            + "associated with client \"" + ddlLabClient.SelectedItem.Text + "\".");
                    }
                }
                else
                {
                    message.AppendLine("USS was not found!<br/>");
                    return 0;
                }
            }
            catch (Exception e)
            {
                message.AppendLine("Exception: " + e.Message);
                return -1;
            }
            return status;
        }
Esempio n. 2
0
        protected void btnRegisterUSS_Click(object sender, EventArgs e)
        {
            lblResponse.Visible = false;
            lblResponse.Text = "";

            StringBuilder message = new StringBuilder();
            try
            {
                if (ddlLabClient.SelectedIndex == 0)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatErrorMessage("Please save the Lab Client information before attempting to dissociate it from a resource");
                    return;
                }

                if (ddlAssociatedUSS.SelectedIndex == 0)
                {
                    lblResponse.Visible = true;
                    lblResponse.Text = Utilities.FormatErrorMessage("Please select a desired USS to be associated with the client.");
                    return;
                }

                LabClient lc = new LabClient();
                lc = labClients[ddlLabClient.SelectedIndex - 1];

                Object keyObj = int.Parse(ddlLabClient.SelectedValue);
                string keyType = ResourceMappingTypes.CLIENT;

                ArrayList valuesList = new ArrayList();
                Object valueObj = null;

                ResourceMappingValue value = new ResourceMappingValue(ResourceMappingTypes.RESOURCE_TYPE, ProcessAgentType.SCHEDULING_SERVER);
                valuesList.Add(value);

                int ussId = int.Parse(ddlAssociatedUSS.SelectedValue);

                if (ussId > 0)
                {
                    value = new ResourceMappingValue(ResourceMappingTypes.PROCESS_AGENT, ussId);
                    valuesList.Add(value);

                    value = new ResourceMappingValue(ResourceMappingTypes.TICKET_TYPE,
                        TicketTypes.GetTicketType(TicketTypes.SCHEDULE_SESSION));
                    valuesList.Add(value);

                    ResourceMappingKey key = new ResourceMappingKey(keyType, keyObj);
                    ResourceMappingValue[] values = (ResourceMappingValue[])valuesList.ToArray((new ResourceMappingValue()).GetType());

                    // Add the mapping to the database & cache
                    ResourceMapping newMapping = ticketing.AddResourceMapping(key, values);

                    // add mapping to qualifier list
                    int qualifierType = Qualifier.resourceMappingQualifierTypeID;
                    string name = ticketing.ResourceMappingToString(newMapping);
                    int qualifierID = AuthorizationAPI.AddQualifier(newMapping.MappingID, qualifierType, name, Qualifier.ROOT);

                    // Moved to ManageLabGroups
                    //Give the Manager Group a Grant "MANAGE_USS_GROUP" on the created resource mapping
                    //int agentID = Convert.ToInt32(ddlAdminGroup.SelectedValue);
                    //string function = Function.manageUSSGroup;
                    //int grantID = wrapper.AddGrantWrapper(agentID, function, qualifierID);

                    Session["ClientUssMappingID"] = newMapping.MappingID;

                    btnRegisterUSS.Visible = false;
                    btnDissociateUSS.Visible = true;
                    ddlAssociatedUSS.Enabled = false;

                    message.AppendLine("User-side Scheduling Server \"" + ddlAssociatedUSS.SelectedItem.Text + "\" succesfully "
                        + "associated with client \"" + ddlLabClient.SelectedItem.Text + "\".");

                    //wrapper.ModifyLabClientWrapper(lc.clientID, lc.clientName, lc.version, lc.clientShortDescription,
                    //    lc.clientLongDescription, lc.notes, lc.loaderScript, lc.clientType,
                    //    lc.labServerIDs, lc.contactEmail, lc.contactFirstName, lc.contactLastName,
                    //    lc.needsScheduling, lc.needsESS, lc.IsReentrant, lc.clientInfos);

                    TicketLoadFactory factory = TicketLoadFactory.Instance();
                    ProcessAgentInfo uss = ticketing.GetProcessAgentInfo(ussId);
                    if (uss.retired)
                    {
                        throw new Exception("The specified USS is retired");
                    }
                    //this should be in a loop
                    for(int i = 0;i<lc.labServerIDs.Length;i++){

                        if (lc.labServerIDs[i] > 0)
                        {
                            ProcessAgentInfo labServer = ticketing.GetProcessAgentInfo(lc.labServerIDs[i]);
                            if (labServer.retired)
                            {
                                throw new Exception("The lab server is retired");
                            }
                            int lssId = ticketing.FindProcessAgentIdForAgent(lc.labServerIDs[i], ProcessAgentType.LAB_SCHEDULING_SERVER);

                            if (lssId > 0)
                            {

                                ProcessAgentInfo lss = ticketing.GetProcessAgentInfo(lssId);
                                if (lss.retired)
                                {
                                    throw new Exception("The LSS is retired");
                                }
                                // The REVOKE_RESERVATION ticket
                                string revokePayload = factory.createRevokeReservationPayload();
                                Coupon ussCoupon = ticketing.CreateTicket(TicketTypes.REVOKE_RESERVATION, uss.agentGuid,
                                    lss.agentGuid, -1L, revokePayload);

                                // Is this in the domain or cross-domain
                                if (lss.domainGuid.Equals(ProcessAgentDB.ServiceGuid))
                                {
                                    // this domain
                                    //Add USS on LSS

                                    //string lssPayload = factory.createAdministerLSSPayload(Convert.ToInt32(Session["UserTZ"]));
                                    //long duration = 60; //seconds for the LSS to redeem the ticket of this coupon and Add LSS Info
                                    //ticketing.AddTicket(lssCoupon, TicketTypes.ADMINISTER_LSS, lss.agentGuid,
                                    //    ticketing.ServiceGuid(), duration, lssPayload);

                                    LabSchedulingProxy lssProxy = new LabSchedulingProxy();
                                    lssProxy.Url = lss.webServiceUrl;
                                    lssProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                                    lssProxy.AgentAuthHeaderValue.coupon = lss.identOut;
                                    lssProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                                    int ussAdded = lssProxy.AddUSSInfo(uss.agentGuid, uss.agentName, uss.webServiceUrl, ussCoupon);
                                    lssProxy.AddExperimentInfo(labServer.agentGuid, labServer.agentName, lc.clientGuid, lc.clientName, lc.version, lc.contactEmail);
                                }
                                else
                                {
                                    // cross-domain
                                    // send consumerInfo to remote SB
                                    int remoteSbId = ticketing.GetProcessAgentID(lss.domainGuid);
                                    message.AppendLine(RegistrationSupport.RegisterClientUSS(remoteSbId, null, lss.agentId, null, labServer.agentId,
                                        ussCoupon, uss.agentId, null, lc.clientID));

                                }
                                //ADD LSS on USS
                                string ussPayload = factory.createAdministerUSSPayload(Convert.ToInt32(Session["UserTZ"]));

                                UserSchedulingProxy ussProxy = new UserSchedulingProxy();
                                ussProxy.Url = uss.webServiceUrl;
                                ussProxy.AgentAuthHeaderValue = new AgentAuthHeader();
                                ussProxy.AgentAuthHeaderValue.coupon = uss.identOut;
                                ussProxy.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid;
                                int lssAdded = ussProxy.AddLSSInfo(lss.agentGuid, lss.agentName, lss.webServiceUrl);

                                //Add Experiment Information on USS
                                int expInfoAdded = ussProxy.AddExperimentInfo(labServer.agentGuid, labServer.agentName,
                                    lc.clientGuid, lc.clientName, lc.version, lc.contactEmail, lss.agentGuid);

                                // Group Credentials MOVED TO THE MANAGE LAB GROUPS PAGE
                            }
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
            lblResponse.Visible = true;
            lblResponse.Text = Utilities.FormatConfirmationMessage(message.ToString());
        }