protected int removeSchedulingInfo(int clientId, int serverId, int ussId, int lssId, ref StringBuilder message) { int status = 1; int result = 1; DateTime start = DateTime.UtcNow; DateTime end = DateTime.MaxValue; ProcessAgent ls = ticketing.GetProcessAgent(serverId); ProcessAgentInfo lss = ticketing.GetProcessAgentInfo(lssId); ProcessAgentInfo uss = ticketing.GetProcessAgentInfo(ussId); if (ls == null) { message.AppendLine("LabServer is not specified!<br/>"); status = 0; } if (lss == null) { message.AppendLine("LSS is not specified!<br/>"); status = 0; } if (uss == null) { message.AppendLine("USS is not specified!<br/>"); status = 0; } if (status < 1) { return status; } TicketLoadFactory tlf = TicketLoadFactory.Instance(); string payload = tlf.createRevokeReservationPayload("ISB"); Coupon coupon = ticketing.CreateTicket(TicketTypes.REVOKE_RESERVATION, lss.agentGuid, ProcessAgentDB.ServiceGuid, 300L, payload); ticketing.AddTicket(coupon, TicketTypes.REVOKE_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 300L, payload); LabSchedulingProxy lssProxy = new LabSchedulingProxy(); AgentAuthHeader agentHeader = new AgentAuthHeader(); agentHeader.agentGuid = ProcessAgentDB.ServiceGuid; agentHeader.coupon = lss.identOut; lssProxy.AgentAuthHeaderValue = agentHeader; OperationAuthHeader opHeader = new OperationAuthHeader(); opHeader.coupon = coupon; lssProxy.OperationAuthHeaderValue = opHeader; lssProxy.Url = lss.webServiceUrl; int count = lssProxy.RemoveReservation(ProcessAgentDB.ServiceGuid, "", uss.agentGuid, ls.agentGuid, labClient.clientGuid, start, end); result = lssProxy.RemoveExperimentInfo(ls.agentGuid, labClient.clientGuid); if (result > 0) { status = Math.Min(status, result); } UserSchedulingProxy ussProxy = new UserSchedulingProxy(); AgentAuthHeader header = new AgentAuthHeader(); header.agentGuid = ProcessAgentDB.ServiceGuid; header.coupon = uss.identOut; ussProxy.AgentAuthHeaderValue = header; OperationAuthHeader op2Header = new OperationAuthHeader(); op2Header.coupon = coupon; ussProxy.OperationAuthHeaderValue = op2Header; ussProxy.Url = uss.webServiceUrl; int num = ussProxy.RevokeReservation(ProcessAgentDB.ServiceGuid, "", ls.agentGuid, labClient.clientGuid, start, end, "The USS is being removed from this lab client!"); result = ussProxy.RemoveExperimentInfo(ls.agentGuid, labClient.clientGuid, lss.agentGuid); if (result > 0) { status = Math.Min(status, result); } return status; }
public static int RevokeReservation(ReservationInfo ri) { int count = 0; LssCredentialSet[] sets = DBManager.GetCredentialSets(new int[] { ri.credentialSetId }); LssExperimentInfo[] exps = DBManager.GetExperimentInfos(new int[] { ri.experimentInfoId }); if (sets != null && sets.Length > 0 && exps != null && exps.Length > 0) { USSInfo uss = DBManager.GetUSSInfo(sets[0].ussGuid); if (uss != null) { ProcessAgentDB paDB = new ProcessAgentDB(); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = paDB.GetCoupon(uss.couponId, uss.domainGuid); ussProxy.OperationAuthHeaderValue = header; ussProxy.Url = uss.ussUrl; int num = ussProxy.RevokeReservation(sets[0].serviceBrokerGuid, sets[0].groupName, exps[0].labServerGuid, exps[0].labClientGuid, ri.Start, ri.End, "The reservation time assigned to this reservation is being removed"); if (num > 0) { LSSSchedulingAPI.RemoveReservationInfoByIDs(new int[] { ri.reservationInfoId }); count += num; } } } return count; }
/* TO DO */ public int RevokeReservation(ReservationInfo ri, string message) { int count = 0; LssCredentialSet[] sets = GetCredentialSets(new int[] { ri.credentialSetId }); LssExperimentInfo[] exps = GetExperimentInfos(new int[] { ri.experimentInfoId }); if (sets != null && sets.Length > 0 && exps != null && exps.Length > 0) { USSInfo uss = GetUSSInfo(ri.ussId); if (uss != null) { UserSchedulingProxy ussProxy = new UserSchedulingProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = GetCoupon(uss.revokeCouponId, uss.domainGuid); ussProxy.OperationAuthHeaderValue = header; ussProxy.Url = uss.ussUrl; int num = ussProxy.RevokeReservation(sets[0].serviceBrokerGuid, sets[0].groupName, exps[0].labServerGuid, exps[0].labClientGuid, ri.Start, ri.End, message); if (num > 0) { RemoveReservationInfoByIDs(new int[] { ri.reservationInfoId }); count += num; } } } return count; }
protected int revokeReservations(int resourceId, int expId, int credId, DateTime start, DateTime end, ref StringBuilder message) { int status = 0; int count = 0; Dictionary<int, List<ReservationData>> reservations = new Dictionary<int, List<ReservationData>>(); try{ ReservationData[] data = dbManager.RetrieveReservationData(resourceId, expId, credId, start, end); if (data != null && data.Length > 0) { // get list for each USS foreach (ReservationData rd in data) { if (!reservations.ContainsKey(rd.ussId)) { List<ReservationData> lst = new List<ReservationData>(); reservations.Add(rd.ussId, lst); } reservations[rd.ussId].Add(rd); } foreach (int uid in reservations.Keys) { if (uid > 0) { USSInfo uss = dbManager.GetUSSInfo(uid); if (uss != null) { UserSchedulingProxy ussProxy = new UserSchedulingProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = dbManager.GetCoupon(uss.revokeCouponId, uss.domainGuid); ussProxy.OperationAuthHeaderValue = header; ussProxy.Url = uss.ussUrl; foreach (ReservationData res in reservations[uid]) { int num = ussProxy.RevokeReservation(res.sbGuid, res.groupName, res.labServerGuid, res.clientGuid, res.Start, res.End, txtMessage.Text); //if (num > 0) //{ dbManager.RemoveReservationInfoByIDs(new int[] { res.reservationID }); count += 1; //} status = 1; } } } else { foreach (ReservationData res in reservations[uid]) { dbManager.RemoveReservationInfoByIDs(new int[] { res.reservationID }); status = 1; count += 1; } } } message.AppendLine( count.ToString() + " reservations were revoked!"); } } catch(Exception e){ status = -1; message.AppendLine(e.Message); return status; } return count; }
///// <summary> ///// Save Button. ///// </summary> ///// <param name="sender"></param> ///// <param name="e"></param> //protected void btnSaveChanges_Click(object sender, System.EventArgs e) //{ // try // { // //Get the labClient ID from the dropdown // int lcID = Convert.ToInt32(ddlLabClient.SelectedValue); // //Get lab client information // LabClient[] clients = wrapper.GetLabClientsWrapper(new int[]{lcID}); // /*Update Lab Client grants*/ // //Get qualifier for labclient // int lcQualifierID = AuthorizationAPI.GetQualifierID(lcID,Qualifier.labClientQualifierTypeID); // //Get all "uselabclient" grants for this labclient // int[] lcGrantIDs = wrapper.FindGrantsWrapper(-1,Function.useLabClientFunctionType,lcQualifierID); // Grant[] lcGrants = wrapper.GetGrantsWrapper(lcGrantIDs); // //Get list of agents that can use labclient // ArrayList lcAgents = new ArrayList(); // foreach (Grant g in lcGrants) // lcAgents.Add(g.agentID); // foreach (ListItem li in lbxAssociated.Items) // { // int groupID = Convert.ToInt32(li.Value); // //if that agent doesn't already have the uselabclient permission // if (!lcAgents.Contains(groupID)) // //add lab client grant // wrapper.AddGrantWrapper(groupID, Function.useLabClientFunctionType, lcQualifierID); // else // //otherwise just remove it from the set of agents that we need to keep track of // lcAgents.Remove(groupID); // } // //Need to delete the grant for remaining agents (since they've been removed by user!) // ArrayList grantsToBeRemoved = new ArrayList(); // foreach (Grant g in lcGrants) // if (lcAgents.Contains(g.agentID)) // grantsToBeRemoved.Add(g.grantID); // /*Update Lab Servers grant*/ // //Update grants for each of the associated lab servers // foreach (int lsID in clients[0].labServerIDs) // { // //Get qualifier for labserver // int lsQualifierID = AuthorizationAPI.GetQualifierID(lsID,Qualifier.labServerQualifierTypeID); // //Get all "uselabserver" grants for this labserver // int[] lsGrantIDs = wrapper.FindGrantsWrapper(-1,Function.useLabServerFunctionType,lsQualifierID); // Grant[] lsGrants = wrapper.GetGrantsWrapper(lsGrantIDs); // //Get list of agents that can use labserver // ArrayList lsAgents = new ArrayList(); // foreach (Grant g in lsGrants) // lsAgents.Add(g.agentID); // foreach (ListItem li in lbxAssociated.Items) // { // int groupID = Convert.ToInt32(li.Value); // //if that agent doesn't already have the uselabclient permission // if (!lsAgents.Contains(groupID)) // //add lab server grant // wrapper.AddGrantWrapper(groupID, Function.useLabServerFunctionType, lsQualifierID); // else // //otherwise just remove it from the set of agents that we need to keep track of // lsAgents.Remove(groupID); // } // //Need to delete the grant for remaining agents (since they've been removed by user!) // foreach (Grant g in lsGrants) // if (lsAgents.Contains(g.agentID)) // grantsToBeRemoved.Add(g.grantID); // } // //Delete All Grants that neeed to be removed // wrapper.RemoveGrantsWrapper(Utilities.ArrayListToIntArray(grantsToBeRemoved)); // LoadListBoxes(); // lblResponse.Visible = true; // lblResponse.Text = Utilities.FormatConfirmationMessage("Lab client (& corresponding lab servers) successfully updated. "); // } // catch (Exception ex) // { // lblResponse.Visible = true; // lblResponse.Text = Utilities.FormatErrorMessage("Cannot update Lab Client. " + ex.GetBaseException()); // } //} // Save Button protected void repAdminUserGroups_ItemCommand(object source, RepeaterCommandEventArgs e) { //RefreshAdminUserGroupsRepeater(); //adminGroupUserList = GetGroupManagerUserMaps(); int labServerID = 0; try{ if (e.CommandName.Equals("Remove")) { //example:issuer.DeleteAdminURL(Int32.Parse(e.CommandArgument.ToString())) GroupManagerUserMap gm = GroupManagerUserMap.Parse(e.CommandArgument.ToString()); int userGroupID = wrapper.GetGroupIDWrapper(gm.UserGroupName); string clientFunction = Function.useLabClientFunctionType; string labFunction = Function.useLabServerFunctionType; if (theClient.clientID > 0) { if (theClient.needsScheduling) { ProcessAgentInfo[] labServers = AdministrativeAPI.GetLabServersForClient(theClient.clientID); if (labServers != null && labServers.Length > 0 && labServers[0].agentId > 0) { int lssID = ResourceMapManager.FindResourceProcessAgentID(ResourceMappingTypes.PROCESS_AGENT, labServers[0].agentId, ProcessAgentType.LAB_SCHEDULING_SERVER); ProcessAgentInfo lss = issuer.GetProcessAgentInfo(lssID); int ussID = ResourceMapManager.FindResourceProcessAgentID(ResourceMappingTypes.CLIENT, theClient.clientID, ProcessAgentType.SCHEDULING_SERVER); if (ussID > 0) { ProcessAgentInfo uss = issuer.GetProcessAgentInfo(ussID); string payload = TicketLoadFactory.Instance().createRevokeReservationPayload("ISB"); Coupon revokeCoupon = issuer.CreateTicket(TicketTypes.REVOKE_RESERVATION, uss.agentGuid, ProcessAgentDB.ServiceGuid, 600, payload); string payload2 = TicketLoadFactory.Instance().createRevokeReservationPayload("ISB"); issuer.AddTicket(revokeCoupon, TicketTypes.REVOKE_RESERVATION, lss.AgentGuid, uss.agentGuid, 600, payload2); UserSchedulingProxy ussProxy = new UserSchedulingProxy(); ussProxy.OperationAuthHeaderValue = new OperationAuthHeader(); ussProxy.OperationAuthHeaderValue.coupon = revokeCoupon; ussProxy.Url = uss.webServiceUrl; int status = ussProxy.RevokeReservation(ProcessAgentDB.ServiceGuid, gm.UserGroupName, labServers[0].AgentGuid, theClient.clientGuid, DateTime.UtcNow, DateTime.MaxValue,"Your group no longer has permission to use the experiment!"); } } } //If there is a USS Manager Group if(gm.GrantID > 0 && gm.ResourceMappingID >0){ wrapper.RemoveGrantsWrapper(new int[] { gm.GrantID }); //delete Resource Mapping [User Group] <-> [USS] issuer.DeleteResourceMapping(gm.ResourceMappingID); } // End is a USS Manager Group //delete the Grant [User Group] -> USE LAB CLIENT -> lab client int clientQualifierID = AuthorizationAPI.GetQualifierID(theClient.clientID, Qualifier.labClientQualifierTypeID); if (clientQualifierID > 0) { int [] clientGrants = wrapper.FindGrantsWrapper(userGroupID, clientFunction, clientQualifierID); if((clientGrants != null) && (clientGrants.Length >0) && (clientGrants[0] > 0)){ wrapper.RemoveGrantsWrapper(new int[] { clientGrants[0] }); } int[] labServerIDs = AdministrativeAPI.GetLabServerIDsForClient(theClient.clientID); if ((labServerIDs != null) && (labServerIDs.Length > 0) && (labServerIDs[0] > 0)) { labServerID = labServerIDs[0]; int remainingClients = AdministrativeAPI.CountServerClients(userGroupID, labServerID); if (remainingClients == 0) { //delete the Grant [User Group] -> USE LAB SERVER -> lab Server int labQualifierID = AuthorizationAPI.GetQualifierID(labServerID, Qualifier.labServerQualifierTypeID); if (labQualifierID > 0) { int [] labGrants = (wrapper.FindGrantsWrapper(userGroupID, labFunction, labQualifierID)); if((labGrants != null) && (labGrants.Length >0) && (labGrants[0] > 0)) wrapper.RemoveGrantsWrapper(new int[] { labGrants[0] }); } } } } } RefreshAdminUserGroupsRepeater(); LoadListBoxes(); } } catch (Exception exc) { lblResponse.Visible = true; lblResponse.Text = Utilities.FormatErrorMessage("Cannot Remove User Group. " + exc.GetBaseException()); Logger.WriteLine(exc.Message); } }