Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
866 mhunt 1
package com.erggroup.buildtool.ripple;
2
 
3
import org.apache.log4j.Logger;
4
 
5
import com.erggroup.buildtool.smtp.Smtpsend;
6
 
7
import java.sql.SQLException;
8
import java.util.Iterator;
9
import java.util.Vector;
10
 
11
/**entity class holding build exclusion data
12
 */
13
public class BuildExclusion
14
{
15
  /**Logger
16
   * @attribute
17
   */
18
  private static final Logger mLogger = Logger.getLogger(BuildExclusion.class);
19
 
20
  /**identifier
21
   * @attribute
22
   */
23
  private int mId;
24
 
25
  /**root identifier
26
   * @attribute
27
   */
28
  private int mRootId;
29
 
30
  /**root cause
31
   * @attribute
32
   */
33
  private String mRootCause;
34
 
35
  /**in terms of the mChangeType Package field,
36
   * when true indicates the package has not changed, its dependencies potentially have
37
   * in terms of the mRippleField Package field,
38
   * when true indicates the build number will be incremented
39
   * @attribute
40
   */
41
  private boolean mProcessed = false;
42
 
43
  /**constructor
44
   */
45
  public BuildExclusion(int identifier, int rootIdentifier, String rootCause)
46
  {
47
    mLogger.debug("BuildExclusion");
48
    mId = identifier;
49
    mRootId = rootIdentifier;
50
    mRootCause = rootCause;
51
  }
52
 
53
  /**sets mProcessed true
54
   */
55
  void process()
56
  {
57
    mLogger.debug("process " + mId);
58
    mProcessed = true;
59
  }
60
 
61
  /**accessor
62
   */
63
  boolean isProcessed()
64
  {
65
    mLogger.debug("isProcessed " + mId);
66
    mLogger.info("isProcessed returned " + mProcessed);
67
    return mProcessed;
68
  }
69
 
70
  /**return true if all attributes match
71
   */
72
  boolean compare( int identifier, int rootIdentifier, String rootCause)
73
  {
74
    mLogger.debug("compare " + mId + ", " + identifier + ", " + rootIdentifier + ", " + rootCause);
75
    boolean retVal = false;
76
 
77
    if ( mRootCause == null )
78
    {
79
      if ( mId == identifier && mRootId == rootIdentifier && rootCause == null )
80
      {
81
        retVal = true;
82
      }
83
    }
84
    else
85
    {
86
      if ( mId == identifier && mRootId == rootIdentifier && mRootCause.compareTo(rootCause) == 0 )
87
      {
88
        retVal = true;
89
      }
90
    }
91
 
92
    mLogger.debug("isProcessed");
93
    return retVal;
94
  }
95
 
96
  /**return true if mId attribute matches
97
   */
98
  boolean compare( int identifier )
99
  {
100
    mLogger.debug("compare " + mId + ", " + identifier);
101
    boolean retVal = false;
102
 
103
    if ( mId == identifier )
104
    {
105
      retVal = true;
106
    }
107
 
108
    mLogger.info("compare returned " + retVal);
109
    return retVal;
110
  }
111
 
112
  /**runs exclude from build
113
   */
114
  void excludeFromBuild( ReleaseManager rm, int rtag_id ) throws SQLException, Exception
115
  {
116
    mLogger.debug("excludeFromBuild " + mId);
117
    Integer id = mId;
118
    Integer rootId = mRootId;
119
    Integer r = rtag_id;
120
    // a null version and log file is passed to oracle
121
    // the planned version is only needed to remove a planned version from the planned version table
122
    // the ripple engine does not get this far ie it excludes pvs before claiming a version
123
    if ( rootId == -1 )
124
    {
125
      rm.excludeFromBuild(id.toString(), null, r.toString(), null, mRootCause, null);
126
    }
127
    else
128
    {
129
      rm.excludeFromBuild(id.toString(), null, r.toString(), rootId.toString(), mRootCause, null);
130
      }
131
  }
132
 
133
  /**runs exclude from build
134
   */
135
  void includeToBuild( ReleaseManager rm, int rtag_id ) throws SQLException, Exception
136
  {
137
    mLogger.debug("includeToBuild " + mId);
138
    Integer id = mId;
139
    Integer r = rtag_id;
140
    // a null version and log file is passed to oracle
141
    // the planned version is only needed to remove a planned version from the planned version table
142
    // the ripple engine does not get this far ie it excludes pvs before claiming a version
143
    rm.includeToBuild(id.toString(), r.toString());
144
  }
145
 
146
  /**
147
   * return true if the root_pv_id is null (-1) or the it points to a pv_id in the collection
148
   */
149
  boolean isRelevant(Vector<BuildExclusion> buildExclusionCollection)
150
  {
151
    mLogger.debug("isRelevant " + mId);
152
    boolean retVal = false;
153
 
154
    if ( mRootId == -1 )
155
    {
156
      retVal = true;
157
    }
158
    else
159
    {
160
      for (Iterator<BuildExclusion> it = buildExclusionCollection.iterator(); it.hasNext(); )
161
      {
162
        BuildExclusion buildExclusion = it.next();
163
 
164
        if ( buildExclusion.isRelevant( mRootId ) )
165
        {
166
          retVal = true;
167
          break;
168
        }
169
      }
170
    }
171
 
172
    mLogger.info("isRelevant " + mId + " returned " + retVal);
173
    return retVal;
174
  }
175
 
176
  /**
177
   * return true if id matches mId
178
   */
179
    private boolean isRelevant(int id)
180
    {
181
      mLogger.debug("isRelevant " + mId + ", " + id);
182
      boolean retVal = false;
183
 
184
      if ( mId == id )
185
      {
186
        retVal = true;
187
      }
188
 
189
      mLogger.info("isRelevant " + mId +  ", " + id + " returned " + retVal);
190
      return retVal;
191
    }
192
 
193
  /**
194
    * user friendly
195
    * does not trigger a storm of emails because a low level package has a build issue
196
    * limit the emails to the low level package
197
    * i.e. only send email if the build exclusion has a null root pv id
198
    * and a non null root cause
199
   */
200
    public void email(Vector<Package>packageCollection, String mailServer, String mailSender, String release)
201
    {
202
      mLogger.debug("email " + mId);
203
      if ( mRootId == -1 && mRootCause != null )
204
      {
205
        // this is a direct build failure with a ripple engine induced root cause
206
        // send email
207
        Package pkg = null;
208
 
209
        for (Iterator<Package> it = packageCollection.iterator(); it.hasNext(); )
210
        {
211
          Package p = it.next();
212
 
213
          if ( compare(p.mId) )
214
          {
215
            pkg = p;
216
            break;
217
          }
218
        }
219
 
220
        if ( pkg != null )
221
        {
222
          // has the pkg any owners
223
          String owners = pkg.emailInfoNonAntTask();
224
 
225
          if ( owners != null )
226
          {
227
            String body =
228
            "Release: " + release + "<p>" +
229
            "Package: " + pkg.mName + "<p>" + 
230
            mRootCause;
231
 
232
            try
233
            {
234
              Smtpsend.send(
235
              mailServer, // mailServer
236
              mailSender, // source
237
              owners, // target
238
              null, // cc
239
              null, // bcc
240
              "BUILD FAILURE on package " + pkg.mName, // subject
241
              body, // body
242
              null // attachment
243
              );
244
            }
245
            catch( Exception e )
246
            {
247
            }
248
          }
249
        }
250
      }
251
 
252
    }
253
}